diff options
Diffstat (limited to 'bip39-standalone.html')
-rw-r--r-- | bip39-standalone.html | 9492 |
1 files changed, 9445 insertions, 47 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index 8361e05..35a88d7 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -6877,7 +6877,7 @@ button.close { | |||
6877 | <div class="container"> | 6877 | <div class="container"> |
6878 | 6878 | ||
6879 | <h1 class="text-center">Mnemonic Code Converter</h1> | 6879 | <h1 class="text-center">Mnemonic Code Converter</h1> |
6880 | <p class="version">v0.3.5</p> | 6880 | <p class="version">v0.3.6</p> |
6881 | <hr> | 6881 | <hr> |
6882 | <div class="row"> | 6882 | <div class="row"> |
6883 | <div class="col-md-12"> | 6883 | <div class="col-md-12"> |
@@ -7470,13 +7470,25 @@ button.close { | |||
7470 | <h2>Derived Addresses</h2> | 7470 | <h2>Derived Addresses</h2> |
7471 | <p>Note these addresses are derived from the BIP32 Extended Key</p> | 7471 | <p>Note these addresses are derived from the BIP32 Extended Key</p> |
7472 | </div> | 7472 | </div> |
7473 | <div class="col-md-12 use-bitpay-addresses-container hidden"> | 7473 | <div class="col-md-12 bch-addr-type-container hidden"> |
7474 | <div class="checkbox"> | 7474 | <div class="radio"> |
7475 | <label> | ||
7476 | <input type="radio" value="cashaddr" name="bch-addr-type" class="use-bch-cashaddr-addresses" checked="checked"> | ||
7477 | <span>Use CashAddr addresses for Bitcoin Cash (ie starting with 'q' instead of '1')</span> | ||
7478 | </label> | ||
7479 | </div> | ||
7480 | <div class="radio"> | ||
7475 | <label> | 7481 | <label> |
7476 | <input type="checkbox" class="use-bitpay-addresses"> | 7482 | <input type="radio" value="bitpay" name="bch-addr-type" class="use-bch-bitpay-addresses"> |
7477 | <span>Use BitPay-style addresses for Bitcoin Cash (ie starting with 'C' instead of '1')</span> | 7483 | <span>Use BitPay-style addresses for Bitcoin Cash (ie starting with 'C' instead of '1')</span> |
7478 | </label> | 7484 | </label> |
7479 | </div> | 7485 | </div> |
7486 | <div class="radio"> | ||
7487 | <label> | ||
7488 | <input type="radio" value="legacy" name="bch-addr-type" class="use-bch-legacy-addresses"> | ||
7489 | <span>Use legacy addresses for Bitcoin Cash (ie starting with '1')</span> | ||
7490 | </label> | ||
7491 | </div> | ||
7480 | </div> | 7492 | </div> |
7481 | <div class="col-md-12"> | 7493 | <div class="col-md-12"> |
7482 | <div class="checkbox"> | 7494 | <div class="checkbox"> |
@@ -35512,13 +35524,24 @@ function fromBech32 (address) { | |||
35512 | } | 35524 | } |
35513 | 35525 | ||
35514 | function toBase58Check (hash, version) { | 35526 | function toBase58Check (hash, version) { |
35515 | typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments) | 35527 | if (version < 256){ |
35528 | typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments) | ||
35516 | 35529 | ||
35517 | var payload = Buffer.allocUnsafe(21) | 35530 | var payload = Buffer.allocUnsafe(21) |
35518 | payload.writeUInt8(version, 0) | 35531 | payload.writeUInt8(version, 0) |
35519 | hash.copy(payload, 1) | 35532 | hash.copy(payload, 1) |
35520 | 35533 | ||
35521 | return bs58check.encode(payload) | 35534 | return bs58check.encode(payload) |
35535 | } | ||
35536 | else{ | ||
35537 | typeforce(types.tuple(types.Hash160bit, types.UInt16), arguments) | ||
35538 | |||
35539 | var payload = Buffer.allocUnsafe(22) | ||
35540 | payload.writeUInt16BE(version, 0) | ||
35541 | hash.copy(payload, 2) | ||
35542 | |||
35543 | return bs58check.encode(payload) | ||
35544 | } | ||
35522 | } | 35545 | } |
35523 | 35546 | ||
35524 | function toBech32 (data, version, prefix) { | 35547 | function toBech32 (data, version, prefix) { |
@@ -39012,8 +39035,8 @@ var Network = typeforce.compile({ | |||
39012 | public: typeforce.UInt32, | 39035 | public: typeforce.UInt32, |
39013 | private: typeforce.UInt32 | 39036 | private: typeforce.UInt32 |
39014 | }, | 39037 | }, |
39015 | pubKeyHash: typeforce.UInt8, | 39038 | pubKeyHash: typeforce.oneOf(typeforce.UInt8, typeforce.UInt16), |
39016 | scriptHash: typeforce.UInt8, | 39039 | scriptHash: typeforce.oneOf(typeforce.UInt8, typeforce.UInt16), |
39017 | wif: typeforce.UInt8 | 39040 | wif: typeforce.UInt8 |
39018 | }) | 39041 | }) |
39019 | 39042 | ||
@@ -42314,17 +42337,6 @@ bitcoinjs.bitcoin.networks.bgold = { | |||
42314 | wif: 128 | 42337 | wif: 128 |
42315 | }; | 42338 | }; |
42316 | 42339 | ||
42317 | bitcoinjs.bitcoin.networks.bitcoinCashBitbpay = { | ||
42318 | messagePrefix: '\x18Bitcoin Signed Message:\n', | ||
42319 | bip32: { | ||
42320 | public: 0x0488b21e, | ||
42321 | private: 0x0488ade4 | ||
42322 | }, | ||
42323 | pubKeyHash: 0x1c, | ||
42324 | scriptHash: 0x28, | ||
42325 | wif: 0x80 | ||
42326 | }; | ||
42327 | |||
42328 | bitcoinjs.bitcoin.networks.monacoin = { | 42340 | bitcoinjs.bitcoin.networks.monacoin = { |
42329 | messagePrefix: '\x18Monacoin Signed Message:\n', | 42341 | messagePrefix: '\x18Monacoin Signed Message:\n', |
42330 | bip32: { | 42342 | bip32: { |
@@ -42788,6 +42800,17 @@ bitcoinjs.bitcoin.networks.ixcoin = { | |||
42788 | wif: 0x80, | 42800 | wif: 0x80, |
42789 | }; | 42801 | }; |
42790 | 42802 | ||
42803 | bitcoinjs.bitcoin.networks.kobocoin = { | ||
42804 | messagePrefix: '\x18Kobocoin Signed Message:\n', | ||
42805 | bip32: { | ||
42806 | public: 0x0488B21E, | ||
42807 | private: 0x0488ADE4, | ||
42808 | }, | ||
42809 | pubKeyHash: 0x23, | ||
42810 | scriptHash: 0x1c, | ||
42811 | wif: 0xa3, | ||
42812 | }; | ||
42813 | |||
42791 | bitcoinjs.bitcoin.networks.landcoin = { | 42814 | bitcoinjs.bitcoin.networks.landcoin = { |
42792 | messagePrefix: '\x18Landcoin Signed Message:\n', | 42815 | messagePrefix: '\x18Landcoin Signed Message:\n', |
42793 | bip32: { | 42816 | bip32: { |
@@ -43138,7 +43161,7 @@ bitcoinjs.bitcoin.networks.vertcoin = { | |||
43138 | }, | 43161 | }, |
43139 | pubKeyHash: 0x47, | 43162 | pubKeyHash: 0x47, |
43140 | scriptHash: 0x05, | 43163 | scriptHash: 0x05, |
43141 | wif: 0xc7, | 43164 | wif: 0x80, |
43142 | }; | 43165 | }; |
43143 | 43166 | ||
43144 | bitcoinjs.bitcoin.networks.vivo = { | 43167 | bitcoinjs.bitcoin.networks.vivo = { |
@@ -43195,6 +43218,17 @@ bitcoinjs.bitcoin.networks.zcoin = { | |||
43195 | scriptHash: 0x07, | 43218 | scriptHash: 0x07, |
43196 | wif: 0xd2, | 43219 | wif: 0xd2, |
43197 | }; | 43220 | }; |
43221 | |||
43222 | bitcoinjs.bitcoin.networks.zcash = { | ||
43223 | messagePrefix: '\x18Zcash Signed Message:\n', | ||
43224 | bip32: { | ||
43225 | public: 0x0488B21E, | ||
43226 | private: 0x0488ADE4, | ||
43227 | }, | ||
43228 | pubKeyHash: 0x1CB8, | ||
43229 | scriptHash: 0x1CBD, | ||
43230 | wif: 0x80, | ||
43231 | }; | ||
43198 | </script> | 43232 | </script> |
43199 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bitcoinjsBip38 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | 43233 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bitcoinjsBip38 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
43200 | var asn1 = exports; | 43234 | var asn1 = exports; |
@@ -71209,6 +71243,31 @@ bitcoinjs.bitcoin.networks.fujicoin.p2wpkhInP2sh = { | |||
71209 | wif: 0xa4 | 71243 | wif: 0xa4 |
71210 | }; | 71244 | }; |
71211 | 71245 | ||
71246 | bitcoinjs.bitcoin.networks.vertcoin.p2wpkh = { | ||
71247 | baseNetwork: "vertcoin", | ||
71248 | messagePrefix: '\x18Vertcoin Signed Message:\n', | ||
71249 | bech32: 'vtc', | ||
71250 | bip32: { | ||
71251 | public: 0x0488b21e, | ||
71252 | private: 0x0488ade4 | ||
71253 | }, | ||
71254 | pubKeyHash: 71, | ||
71255 | scriptHash: 5, | ||
71256 | wif: 0x80 | ||
71257 | }; | ||
71258 | |||
71259 | bitcoinjs.bitcoin.networks.vertcoin.p2wpkhInP2sh = { | ||
71260 | baseNetwork: "vertcoin", | ||
71261 | messagePrefix: '\x18Vertcoin Signed Message:\n', | ||
71262 | bip32: { | ||
71263 | public: 0x0488b21e, | ||
71264 | private: 0x0488ade4 | ||
71265 | }, | ||
71266 | pubKeyHash: 71, | ||
71267 | scriptHash: 5, | ||
71268 | wif: 0x80 | ||
71269 | }; | ||
71270 | |||
71212 | })(); | 71271 | })(); |
71213 | </script> | 71272 | </script> |
71214 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | 71273 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
@@ -89984,6 +90043,9334 @@ function convertRipplePriv(priv) { | |||
89984 | } | 90043 | } |
89985 | 90044 | ||
89986 | </script> | 90045 | </script> |
90046 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bchaddr = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
90047 | // base-x encoding | ||
90048 | // Forked from https://github.com/cryptocoinjs/bs58 | ||
90049 | // Originally written by Mike Hearn for BitcoinJ | ||
90050 | // Copyright (c) 2011 Google Inc | ||
90051 | // Ported to JavaScript by Stefan Thomas | ||
90052 | // Merged Buffer refactorings from base58-native by Stephen Pair | ||
90053 | // Copyright (c) 2013 BitPay Inc | ||
90054 | |||
90055 | var Buffer = require('safe-buffer').Buffer | ||
90056 | |||
90057 | module.exports = function base (ALPHABET) { | ||
90058 | var ALPHABET_MAP = {} | ||
90059 | var BASE = ALPHABET.length | ||
90060 | var LEADER = ALPHABET.charAt(0) | ||
90061 | |||
90062 | // pre-compute lookup table | ||
90063 | for (var z = 0; z < ALPHABET.length; z++) { | ||
90064 | var x = ALPHABET.charAt(z) | ||
90065 | |||
90066 | if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous') | ||
90067 | ALPHABET_MAP[x] = z | ||
90068 | } | ||
90069 | |||
90070 | function encode (source) { | ||
90071 | if (source.length === 0) return '' | ||
90072 | |||
90073 | var digits = [0] | ||
90074 | for (var i = 0; i < source.length; ++i) { | ||
90075 | for (var j = 0, carry = source[i]; j < digits.length; ++j) { | ||
90076 | carry += digits[j] << 8 | ||
90077 | digits[j] = carry % BASE | ||
90078 | carry = (carry / BASE) | 0 | ||
90079 | } | ||
90080 | |||
90081 | while (carry > 0) { | ||
90082 | digits.push(carry % BASE) | ||
90083 | carry = (carry / BASE) | 0 | ||
90084 | } | ||
90085 | } | ||
90086 | |||
90087 | var string = '' | ||
90088 | |||
90089 | // deal with leading zeros | ||
90090 | for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += LEADER | ||
90091 | // convert digits to a string | ||
90092 | for (var q = digits.length - 1; q >= 0; --q) string += ALPHABET[digits[q]] | ||
90093 | |||
90094 | return string | ||
90095 | } | ||
90096 | |||
90097 | function decodeUnsafe (string) { | ||
90098 | if (typeof string !== 'string') throw new TypeError('Expected String') | ||
90099 | if (string.length === 0) return Buffer.allocUnsafe(0) | ||
90100 | |||
90101 | var bytes = [0] | ||
90102 | for (var i = 0; i < string.length; i++) { | ||
90103 | var value = ALPHABET_MAP[string[i]] | ||
90104 | if (value === undefined) return | ||
90105 | |||
90106 | for (var j = 0, carry = value; j < bytes.length; ++j) { | ||
90107 | carry += bytes[j] * BASE | ||
90108 | bytes[j] = carry & 0xff | ||
90109 | carry >>= 8 | ||
90110 | } | ||
90111 | |||
90112 | while (carry > 0) { | ||
90113 | bytes.push(carry & 0xff) | ||
90114 | carry >>= 8 | ||
90115 | } | ||
90116 | } | ||
90117 | |||
90118 | // deal with leading zeros | ||
90119 | for (var k = 0; string[k] === LEADER && k < string.length - 1; ++k) { | ||
90120 | bytes.push(0) | ||
90121 | } | ||
90122 | |||
90123 | return Buffer.from(bytes.reverse()) | ||
90124 | } | ||
90125 | |||
90126 | function decode (string) { | ||
90127 | var buffer = decodeUnsafe(string) | ||
90128 | if (buffer) return buffer | ||
90129 | |||
90130 | throw new Error('Non-base' + BASE + ' character') | ||
90131 | } | ||
90132 | |||
90133 | return { | ||
90134 | encode: encode, | ||
90135 | decodeUnsafe: decodeUnsafe, | ||
90136 | decode: decode | ||
90137 | } | ||
90138 | } | ||
90139 | |||
90140 | },{"safe-buffer":40}],2:[function(require,module,exports){ | ||
90141 | 'use strict' | ||
90142 | |||
90143 | exports.byteLength = byteLength | ||
90144 | exports.toByteArray = toByteArray | ||
90145 | exports.fromByteArray = fromByteArray | ||
90146 | |||
90147 | var lookup = [] | ||
90148 | var revLookup = [] | ||
90149 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array | ||
90150 | |||
90151 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | ||
90152 | for (var i = 0, len = code.length; i < len; ++i) { | ||
90153 | lookup[i] = code[i] | ||
90154 | revLookup[code.charCodeAt(i)] = i | ||
90155 | } | ||
90156 | |||
90157 | revLookup['-'.charCodeAt(0)] = 62 | ||
90158 | revLookup['_'.charCodeAt(0)] = 63 | ||
90159 | |||
90160 | function placeHoldersCount (b64) { | ||
90161 | var len = b64.length | ||
90162 | if (len % 4 > 0) { | ||
90163 | throw new Error('Invalid string. Length must be a multiple of 4') | ||
90164 | } | ||
90165 | |||
90166 | // the number of equal signs (place holders) | ||
90167 | // if there are two placeholders, than the two characters before it | ||
90168 | // represent one byte | ||
90169 | // if there is only one, then the three characters before it represent 2 bytes | ||
90170 | // this is just a cheap hack to not do indexOf twice | ||
90171 | return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 | ||
90172 | } | ||
90173 | |||
90174 | function byteLength (b64) { | ||
90175 | // base64 is 4/3 + up to two characters of the original data | ||
90176 | return (b64.length * 3 / 4) - placeHoldersCount(b64) | ||
90177 | } | ||
90178 | |||
90179 | function toByteArray (b64) { | ||
90180 | var i, l, tmp, placeHolders, arr | ||
90181 | var len = b64.length | ||
90182 | placeHolders = placeHoldersCount(b64) | ||
90183 | |||
90184 | arr = new Arr((len * 3 / 4) - placeHolders) | ||
90185 | |||
90186 | // if there are placeholders, only get up to the last complete 4 chars | ||
90187 | l = placeHolders > 0 ? len - 4 : len | ||
90188 | |||
90189 | var L = 0 | ||
90190 | |||
90191 | for (i = 0; i < l; i += 4) { | ||
90192 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] | ||
90193 | arr[L++] = (tmp >> 16) & 0xFF | ||
90194 | arr[L++] = (tmp >> 8) & 0xFF | ||
90195 | arr[L++] = tmp & 0xFF | ||
90196 | } | ||
90197 | |||
90198 | if (placeHolders === 2) { | ||
90199 | tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) | ||
90200 | arr[L++] = tmp & 0xFF | ||
90201 | } else if (placeHolders === 1) { | ||
90202 | tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) | ||
90203 | arr[L++] = (tmp >> 8) & 0xFF | ||
90204 | arr[L++] = tmp & 0xFF | ||
90205 | } | ||
90206 | |||
90207 | return arr | ||
90208 | } | ||
90209 | |||
90210 | function tripletToBase64 (num) { | ||
90211 | return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] | ||
90212 | } | ||
90213 | |||
90214 | function encodeChunk (uint8, start, end) { | ||
90215 | var tmp | ||
90216 | var output = [] | ||
90217 | for (var i = start; i < end; i += 3) { | ||
90218 | tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) | ||
90219 | output.push(tripletToBase64(tmp)) | ||
90220 | } | ||
90221 | return output.join('') | ||
90222 | } | ||
90223 | |||
90224 | function fromByteArray (uint8) { | ||
90225 | var tmp | ||
90226 | var len = uint8.length | ||
90227 | var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes | ||
90228 | var output = '' | ||
90229 | var parts = [] | ||
90230 | var maxChunkLength = 16383 // must be multiple of 3 | ||
90231 | |||
90232 | // go through the array every three bytes, we'll deal with trailing stuff later | ||
90233 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
90234 | parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) | ||
90235 | } | ||
90236 | |||
90237 | // pad the end with zeros, but make sure to not forget the extra bytes | ||
90238 | if (extraBytes === 1) { | ||
90239 | tmp = uint8[len - 1] | ||
90240 | output += lookup[tmp >> 2] | ||
90241 | output += lookup[(tmp << 4) & 0x3F] | ||
90242 | output += '==' | ||
90243 | } else if (extraBytes === 2) { | ||
90244 | tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) | ||
90245 | output += lookup[tmp >> 10] | ||
90246 | output += lookup[(tmp >> 4) & 0x3F] | ||
90247 | output += lookup[(tmp << 2) & 0x3F] | ||
90248 | output += '=' | ||
90249 | } | ||
90250 | |||
90251 | parts.push(output) | ||
90252 | |||
90253 | return parts.join('') | ||
90254 | } | ||
90255 | |||
90256 | },{}],3:[function(require,module,exports){ | ||
90257 | var bigInt = (function (undefined) { | ||
90258 | "use strict"; | ||
90259 | |||
90260 | var BASE = 1e7, | ||
90261 | LOG_BASE = 7, | ||
90262 | MAX_INT = 9007199254740992, | ||
90263 | MAX_INT_ARR = smallToArray(MAX_INT), | ||
90264 | LOG_MAX_INT = Math.log(MAX_INT); | ||
90265 | |||
90266 | function Integer(v, radix) { | ||
90267 | if (typeof v === "undefined") return Integer[0]; | ||
90268 | if (typeof radix !== "undefined") return +radix === 10 ? parseValue(v) : parseBase(v, radix); | ||
90269 | return parseValue(v); | ||
90270 | } | ||
90271 | |||
90272 | function BigInteger(value, sign) { | ||
90273 | this.value = value; | ||
90274 | this.sign = sign; | ||
90275 | this.isSmall = false; | ||
90276 | } | ||
90277 | BigInteger.prototype = Object.create(Integer.prototype); | ||
90278 | |||
90279 | function SmallInteger(value) { | ||
90280 | this.value = value; | ||
90281 | this.sign = value < 0; | ||
90282 | this.isSmall = true; | ||
90283 | } | ||
90284 | SmallInteger.prototype = Object.create(Integer.prototype); | ||
90285 | |||
90286 | function isPrecise(n) { | ||
90287 | return -MAX_INT < n && n < MAX_INT; | ||
90288 | } | ||
90289 | |||
90290 | function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes | ||
90291 | if (n < 1e7) | ||
90292 | return [n]; | ||
90293 | if (n < 1e14) | ||
90294 | return [n % 1e7, Math.floor(n / 1e7)]; | ||
90295 | return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)]; | ||
90296 | } | ||
90297 | |||
90298 | function arrayToSmall(arr) { // If BASE changes this function may need to change | ||
90299 | trim(arr); | ||
90300 | var length = arr.length; | ||
90301 | if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) { | ||
90302 | switch (length) { | ||
90303 | case 0: return 0; | ||
90304 | case 1: return arr[0]; | ||
90305 | case 2: return arr[0] + arr[1] * BASE; | ||
90306 | default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE; | ||
90307 | } | ||
90308 | } | ||
90309 | return arr; | ||
90310 | } | ||
90311 | |||
90312 | function trim(v) { | ||
90313 | var i = v.length; | ||
90314 | while (v[--i] === 0); | ||
90315 | v.length = i + 1; | ||
90316 | } | ||
90317 | |||
90318 | function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger | ||
90319 | var x = new Array(length); | ||
90320 | var i = -1; | ||
90321 | while (++i < length) { | ||
90322 | x[i] = 0; | ||
90323 | } | ||
90324 | return x; | ||
90325 | } | ||
90326 | |||
90327 | function truncate(n) { | ||
90328 | if (n > 0) return Math.floor(n); | ||
90329 | return Math.ceil(n); | ||
90330 | } | ||
90331 | |||
90332 | function add(a, b) { // assumes a and b are arrays with a.length >= b.length | ||
90333 | var l_a = a.length, | ||
90334 | l_b = b.length, | ||
90335 | r = new Array(l_a), | ||
90336 | carry = 0, | ||
90337 | base = BASE, | ||
90338 | sum, i; | ||
90339 | for (i = 0; i < l_b; i++) { | ||
90340 | sum = a[i] + b[i] + carry; | ||
90341 | carry = sum >= base ? 1 : 0; | ||
90342 | r[i] = sum - carry * base; | ||
90343 | } | ||
90344 | while (i < l_a) { | ||
90345 | sum = a[i] + carry; | ||
90346 | carry = sum === base ? 1 : 0; | ||
90347 | r[i++] = sum - carry * base; | ||
90348 | } | ||
90349 | if (carry > 0) r.push(carry); | ||
90350 | return r; | ||
90351 | } | ||
90352 | |||
90353 | function addAny(a, b) { | ||
90354 | if (a.length >= b.length) return add(a, b); | ||
90355 | return add(b, a); | ||
90356 | } | ||
90357 | |||
90358 | function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT | ||
90359 | var l = a.length, | ||
90360 | r = new Array(l), | ||
90361 | base = BASE, | ||
90362 | sum, i; | ||
90363 | for (i = 0; i < l; i++) { | ||
90364 | sum = a[i] - base + carry; | ||
90365 | carry = Math.floor(sum / base); | ||
90366 | r[i] = sum - carry * base; | ||
90367 | carry += 1; | ||
90368 | } | ||
90369 | while (carry > 0) { | ||
90370 | r[i++] = carry % base; | ||
90371 | carry = Math.floor(carry / base); | ||
90372 | } | ||
90373 | return r; | ||
90374 | } | ||
90375 | |||
90376 | BigInteger.prototype.add = function (v) { | ||
90377 | var n = parseValue(v); | ||
90378 | if (this.sign !== n.sign) { | ||
90379 | return this.subtract(n.negate()); | ||
90380 | } | ||
90381 | var a = this.value, b = n.value; | ||
90382 | if (n.isSmall) { | ||
90383 | return new BigInteger(addSmall(a, Math.abs(b)), this.sign); | ||
90384 | } | ||
90385 | return new BigInteger(addAny(a, b), this.sign); | ||
90386 | }; | ||
90387 | BigInteger.prototype.plus = BigInteger.prototype.add; | ||
90388 | |||
90389 | SmallInteger.prototype.add = function (v) { | ||
90390 | var n = parseValue(v); | ||
90391 | var a = this.value; | ||
90392 | if (a < 0 !== n.sign) { | ||
90393 | return this.subtract(n.negate()); | ||
90394 | } | ||
90395 | var b = n.value; | ||
90396 | if (n.isSmall) { | ||
90397 | if (isPrecise(a + b)) return new SmallInteger(a + b); | ||
90398 | b = smallToArray(Math.abs(b)); | ||
90399 | } | ||
90400 | return new BigInteger(addSmall(b, Math.abs(a)), a < 0); | ||
90401 | }; | ||
90402 | SmallInteger.prototype.plus = SmallInteger.prototype.add; | ||
90403 | |||
90404 | function subtract(a, b) { // assumes a and b are arrays with a >= b | ||
90405 | var a_l = a.length, | ||
90406 | b_l = b.length, | ||
90407 | r = new Array(a_l), | ||
90408 | borrow = 0, | ||
90409 | base = BASE, | ||
90410 | i, difference; | ||
90411 | for (i = 0; i < b_l; i++) { | ||
90412 | difference = a[i] - borrow - b[i]; | ||
90413 | if (difference < 0) { | ||
90414 | difference += base; | ||
90415 | borrow = 1; | ||
90416 | } else borrow = 0; | ||
90417 | r[i] = difference; | ||
90418 | } | ||
90419 | for (i = b_l; i < a_l; i++) { | ||
90420 | difference = a[i] - borrow; | ||
90421 | if (difference < 0) difference += base; | ||
90422 | else { | ||
90423 | r[i++] = difference; | ||
90424 | break; | ||
90425 | } | ||
90426 | r[i] = difference; | ||
90427 | } | ||
90428 | for (; i < a_l; i++) { | ||
90429 | r[i] = a[i]; | ||
90430 | } | ||
90431 | trim(r); | ||
90432 | return r; | ||
90433 | } | ||
90434 | |||
90435 | function subtractAny(a, b, sign) { | ||
90436 | var value; | ||
90437 | if (compareAbs(a, b) >= 0) { | ||
90438 | value = subtract(a,b); | ||
90439 | } else { | ||
90440 | value = subtract(b, a); | ||
90441 | sign = !sign; | ||
90442 | } | ||
90443 | value = arrayToSmall(value); | ||
90444 | if (typeof value === "number") { | ||
90445 | if (sign) value = -value; | ||
90446 | return new SmallInteger(value); | ||
90447 | } | ||
90448 | return new BigInteger(value, sign); | ||
90449 | } | ||
90450 | |||
90451 | function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT | ||
90452 | var l = a.length, | ||
90453 | r = new Array(l), | ||
90454 | carry = -b, | ||
90455 | base = BASE, | ||
90456 | i, difference; | ||
90457 | for (i = 0; i < l; i++) { | ||
90458 | difference = a[i] + carry; | ||
90459 | carry = Math.floor(difference / base); | ||
90460 | difference %= base; | ||
90461 | r[i] = difference < 0 ? difference + base : difference; | ||
90462 | } | ||
90463 | r = arrayToSmall(r); | ||
90464 | if (typeof r === "number") { | ||
90465 | if (sign) r = -r; | ||
90466 | return new SmallInteger(r); | ||
90467 | } return new BigInteger(r, sign); | ||
90468 | } | ||
90469 | |||
90470 | BigInteger.prototype.subtract = function (v) { | ||
90471 | var n = parseValue(v); | ||
90472 | if (this.sign !== n.sign) { | ||
90473 | return this.add(n.negate()); | ||
90474 | } | ||
90475 | var a = this.value, b = n.value; | ||
90476 | if (n.isSmall) | ||
90477 | return subtractSmall(a, Math.abs(b), this.sign); | ||
90478 | return subtractAny(a, b, this.sign); | ||
90479 | }; | ||
90480 | BigInteger.prototype.minus = BigInteger.prototype.subtract; | ||
90481 | |||
90482 | SmallInteger.prototype.subtract = function (v) { | ||
90483 | var n = parseValue(v); | ||
90484 | var a = this.value; | ||
90485 | if (a < 0 !== n.sign) { | ||
90486 | return this.add(n.negate()); | ||
90487 | } | ||
90488 | var b = n.value; | ||
90489 | if (n.isSmall) { | ||
90490 | return new SmallInteger(a - b); | ||
90491 | } | ||
90492 | return subtractSmall(b, Math.abs(a), a >= 0); | ||
90493 | }; | ||
90494 | SmallInteger.prototype.minus = SmallInteger.prototype.subtract; | ||
90495 | |||
90496 | BigInteger.prototype.negate = function () { | ||
90497 | return new BigInteger(this.value, !this.sign); | ||
90498 | }; | ||
90499 | SmallInteger.prototype.negate = function () { | ||
90500 | var sign = this.sign; | ||
90501 | var small = new SmallInteger(-this.value); | ||
90502 | small.sign = !sign; | ||
90503 | return small; | ||
90504 | }; | ||
90505 | |||
90506 | BigInteger.prototype.abs = function () { | ||
90507 | return new BigInteger(this.value, false); | ||
90508 | }; | ||
90509 | SmallInteger.prototype.abs = function () { | ||
90510 | return new SmallInteger(Math.abs(this.value)); | ||
90511 | }; | ||
90512 | |||
90513 | function multiplyLong(a, b) { | ||
90514 | var a_l = a.length, | ||
90515 | b_l = b.length, | ||
90516 | l = a_l + b_l, | ||
90517 | r = createArray(l), | ||
90518 | base = BASE, | ||
90519 | product, carry, i, a_i, b_j; | ||
90520 | for (i = 0; i < a_l; ++i) { | ||
90521 | a_i = a[i]; | ||
90522 | for (var j = 0; j < b_l; ++j) { | ||
90523 | b_j = b[j]; | ||
90524 | product = a_i * b_j + r[i + j]; | ||
90525 | carry = Math.floor(product / base); | ||
90526 | r[i + j] = product - carry * base; | ||
90527 | r[i + j + 1] += carry; | ||
90528 | } | ||
90529 | } | ||
90530 | trim(r); | ||
90531 | return r; | ||
90532 | } | ||
90533 | |||
90534 | function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE | ||
90535 | var l = a.length, | ||
90536 | r = new Array(l), | ||
90537 | base = BASE, | ||
90538 | carry = 0, | ||
90539 | product, i; | ||
90540 | for (i = 0; i < l; i++) { | ||
90541 | product = a[i] * b + carry; | ||
90542 | carry = Math.floor(product / base); | ||
90543 | r[i] = product - carry * base; | ||
90544 | } | ||
90545 | while (carry > 0) { | ||
90546 | r[i++] = carry % base; | ||
90547 | carry = Math.floor(carry / base); | ||
90548 | } | ||
90549 | return r; | ||
90550 | } | ||
90551 | |||
90552 | function shiftLeft(x, n) { | ||
90553 | var r = []; | ||
90554 | while (n-- > 0) r.push(0); | ||
90555 | return r.concat(x); | ||
90556 | } | ||
90557 | |||
90558 | function multiplyKaratsuba(x, y) { | ||
90559 | var n = Math.max(x.length, y.length); | ||
90560 | |||
90561 | if (n <= 30) return multiplyLong(x, y); | ||
90562 | n = Math.ceil(n / 2); | ||
90563 | |||
90564 | var b = x.slice(n), | ||
90565 | a = x.slice(0, n), | ||
90566 | d = y.slice(n), | ||
90567 | c = y.slice(0, n); | ||
90568 | |||
90569 | var ac = multiplyKaratsuba(a, c), | ||
90570 | bd = multiplyKaratsuba(b, d), | ||
90571 | abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); | ||
90572 | |||
90573 | var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); | ||
90574 | trim(product); | ||
90575 | return product; | ||
90576 | } | ||
90577 | |||
90578 | // The following function is derived from a surface fit of a graph plotting the performance difference | ||
90579 | // between long multiplication and karatsuba multiplication versus the lengths of the two arrays. | ||
90580 | function useKaratsuba(l1, l2) { | ||
90581 | return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0; | ||
90582 | } | ||
90583 | |||
90584 | BigInteger.prototype.multiply = function (v) { | ||
90585 | var n = parseValue(v), | ||
90586 | a = this.value, b = n.value, | ||
90587 | sign = this.sign !== n.sign, | ||
90588 | abs; | ||
90589 | if (n.isSmall) { | ||
90590 | if (b === 0) return Integer[0]; | ||
90591 | if (b === 1) return this; | ||
90592 | if (b === -1) return this.negate(); | ||
90593 | abs = Math.abs(b); | ||
90594 | if (abs < BASE) { | ||
90595 | return new BigInteger(multiplySmall(a, abs), sign); | ||
90596 | } | ||
90597 | b = smallToArray(abs); | ||
90598 | } | ||
90599 | if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes | ||
90600 | return new BigInteger(multiplyKaratsuba(a, b), sign); | ||
90601 | return new BigInteger(multiplyLong(a, b), sign); | ||
90602 | }; | ||
90603 | |||
90604 | BigInteger.prototype.times = BigInteger.prototype.multiply; | ||
90605 | |||
90606 | function multiplySmallAndArray(a, b, sign) { // a >= 0 | ||
90607 | if (a < BASE) { | ||
90608 | return new BigInteger(multiplySmall(b, a), sign); | ||
90609 | } | ||
90610 | return new BigInteger(multiplyLong(b, smallToArray(a)), sign); | ||
90611 | } | ||
90612 | SmallInteger.prototype._multiplyBySmall = function (a) { | ||
90613 | if (isPrecise(a.value * this.value)) { | ||
90614 | return new SmallInteger(a.value * this.value); | ||
90615 | } | ||
90616 | return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign); | ||
90617 | }; | ||
90618 | BigInteger.prototype._multiplyBySmall = function (a) { | ||
90619 | if (a.value === 0) return Integer[0]; | ||
90620 | if (a.value === 1) return this; | ||
90621 | if (a.value === -1) return this.negate(); | ||
90622 | return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign); | ||
90623 | }; | ||
90624 | SmallInteger.prototype.multiply = function (v) { | ||
90625 | return parseValue(v)._multiplyBySmall(this); | ||
90626 | }; | ||
90627 | SmallInteger.prototype.times = SmallInteger.prototype.multiply; | ||
90628 | |||
90629 | function square(a) { | ||
90630 | var l = a.length, | ||
90631 | r = createArray(l + l), | ||
90632 | base = BASE, | ||
90633 | product, carry, i, a_i, a_j; | ||
90634 | for (i = 0; i < l; i++) { | ||
90635 | a_i = a[i]; | ||
90636 | for (var j = 0; j < l; j++) { | ||
90637 | a_j = a[j]; | ||
90638 | product = a_i * a_j + r[i + j]; | ||
90639 | carry = Math.floor(product / base); | ||
90640 | r[i + j] = product - carry * base; | ||
90641 | r[i + j + 1] += carry; | ||
90642 | } | ||
90643 | } | ||
90644 | trim(r); | ||
90645 | return r; | ||
90646 | } | ||
90647 | |||
90648 | BigInteger.prototype.square = function () { | ||
90649 | return new BigInteger(square(this.value), false); | ||
90650 | }; | ||
90651 | |||
90652 | SmallInteger.prototype.square = function () { | ||
90653 | var value = this.value * this.value; | ||
90654 | if (isPrecise(value)) return new SmallInteger(value); | ||
90655 | return new BigInteger(square(smallToArray(Math.abs(this.value))), false); | ||
90656 | }; | ||
90657 | |||
90658 | function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes. | ||
90659 | var a_l = a.length, | ||
90660 | b_l = b.length, | ||
90661 | base = BASE, | ||
90662 | result = createArray(b.length), | ||
90663 | divisorMostSignificantDigit = b[b_l - 1], | ||
90664 | // normalization | ||
90665 | lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), | ||
90666 | remainder = multiplySmall(a, lambda), | ||
90667 | divisor = multiplySmall(b, lambda), | ||
90668 | quotientDigit, shift, carry, borrow, i, l, q; | ||
90669 | if (remainder.length <= a_l) remainder.push(0); | ||
90670 | divisor.push(0); | ||
90671 | divisorMostSignificantDigit = divisor[b_l - 1]; | ||
90672 | for (shift = a_l - b_l; shift >= 0; shift--) { | ||
90673 | quotientDigit = base - 1; | ||
90674 | if (remainder[shift + b_l] !== divisorMostSignificantDigit) { | ||
90675 | quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit); | ||
90676 | } | ||
90677 | // quotientDigit <= base - 1 | ||
90678 | carry = 0; | ||
90679 | borrow = 0; | ||
90680 | l = divisor.length; | ||
90681 | for (i = 0; i < l; i++) { | ||
90682 | carry += quotientDigit * divisor[i]; | ||
90683 | q = Math.floor(carry / base); | ||
90684 | borrow += remainder[shift + i] - (carry - q * base); | ||
90685 | carry = q; | ||
90686 | if (borrow < 0) { | ||
90687 | remainder[shift + i] = borrow + base; | ||
90688 | borrow = -1; | ||
90689 | } else { | ||
90690 | remainder[shift + i] = borrow; | ||
90691 | borrow = 0; | ||
90692 | } | ||
90693 | } | ||
90694 | while (borrow !== 0) { | ||
90695 | quotientDigit -= 1; | ||
90696 | carry = 0; | ||
90697 | for (i = 0; i < l; i++) { | ||
90698 | carry += remainder[shift + i] - base + divisor[i]; | ||
90699 | if (carry < 0) { | ||
90700 | remainder[shift + i] = carry + base; | ||
90701 | carry = 0; | ||
90702 | } else { | ||
90703 | remainder[shift + i] = carry; | ||
90704 | carry = 1; | ||
90705 | } | ||
90706 | } | ||
90707 | borrow += carry; | ||
90708 | } | ||
90709 | result[shift] = quotientDigit; | ||
90710 | } | ||
90711 | // denormalization | ||
90712 | remainder = divModSmall(remainder, lambda)[0]; | ||
90713 | return [arrayToSmall(result), arrayToSmall(remainder)]; | ||
90714 | } | ||
90715 | |||
90716 | function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/ | ||
90717 | // Performs faster than divMod1 on larger input sizes. | ||
90718 | var a_l = a.length, | ||
90719 | b_l = b.length, | ||
90720 | result = [], | ||
90721 | part = [], | ||
90722 | base = BASE, | ||
90723 | guess, xlen, highx, highy, check; | ||
90724 | while (a_l) { | ||
90725 | part.unshift(a[--a_l]); | ||
90726 | trim(part); | ||
90727 | if (compareAbs(part, b) < 0) { | ||
90728 | result.push(0); | ||
90729 | continue; | ||
90730 | } | ||
90731 | xlen = part.length; | ||
90732 | highx = part[xlen - 1] * base + part[xlen - 2]; | ||
90733 | highy = b[b_l - 1] * base + b[b_l - 2]; | ||
90734 | if (xlen > b_l) { | ||
90735 | highx = (highx + 1) * base; | ||
90736 | } | ||
90737 | guess = Math.ceil(highx / highy); | ||
90738 | do { | ||
90739 | check = multiplySmall(b, guess); | ||
90740 | if (compareAbs(check, part) <= 0) break; | ||
90741 | guess--; | ||
90742 | } while (guess); | ||
90743 | result.push(guess); | ||
90744 | part = subtract(part, check); | ||
90745 | } | ||
90746 | result.reverse(); | ||
90747 | return [arrayToSmall(result), arrayToSmall(part)]; | ||
90748 | } | ||
90749 | |||
90750 | function divModSmall(value, lambda) { | ||
90751 | var length = value.length, | ||
90752 | quotient = createArray(length), | ||
90753 | base = BASE, | ||
90754 | i, q, remainder, divisor; | ||
90755 | remainder = 0; | ||
90756 | for (i = length - 1; i >= 0; --i) { | ||
90757 | divisor = remainder * base + value[i]; | ||
90758 | q = truncate(divisor / lambda); | ||
90759 | remainder = divisor - q * lambda; | ||
90760 | quotient[i] = q | 0; | ||
90761 | } | ||
90762 | return [quotient, remainder | 0]; | ||
90763 | } | ||
90764 | |||
90765 | function divModAny(self, v) { | ||
90766 | var value, n = parseValue(v); | ||
90767 | var a = self.value, b = n.value; | ||
90768 | var quotient; | ||
90769 | if (b === 0) throw new Error("Cannot divide by zero"); | ||
90770 | if (self.isSmall) { | ||
90771 | if (n.isSmall) { | ||
90772 | return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)]; | ||
90773 | } | ||
90774 | return [Integer[0], self]; | ||
90775 | } | ||
90776 | if (n.isSmall) { | ||
90777 | if (b === 1) return [self, Integer[0]]; | ||
90778 | if (b == -1) return [self.negate(), Integer[0]]; | ||
90779 | var abs = Math.abs(b); | ||
90780 | if (abs < BASE) { | ||
90781 | value = divModSmall(a, abs); | ||
90782 | quotient = arrayToSmall(value[0]); | ||
90783 | var remainder = value[1]; | ||
90784 | if (self.sign) remainder = -remainder; | ||
90785 | if (typeof quotient === "number") { | ||
90786 | if (self.sign !== n.sign) quotient = -quotient; | ||
90787 | return [new SmallInteger(quotient), new SmallInteger(remainder)]; | ||
90788 | } | ||
90789 | return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)]; | ||
90790 | } | ||
90791 | b = smallToArray(abs); | ||
90792 | } | ||
90793 | var comparison = compareAbs(a, b); | ||
90794 | if (comparison === -1) return [Integer[0], self]; | ||
90795 | if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; | ||
90796 | |||
90797 | // divMod1 is faster on smaller input sizes | ||
90798 | if (a.length + b.length <= 200) | ||
90799 | value = divMod1(a, b); | ||
90800 | else value = divMod2(a, b); | ||
90801 | |||
90802 | quotient = value[0]; | ||
90803 | var qSign = self.sign !== n.sign, | ||
90804 | mod = value[1], | ||
90805 | mSign = self.sign; | ||
90806 | if (typeof quotient === "number") { | ||
90807 | if (qSign) quotient = -quotient; | ||
90808 | quotient = new SmallInteger(quotient); | ||
90809 | } else quotient = new BigInteger(quotient, qSign); | ||
90810 | if (typeof mod === "number") { | ||
90811 | if (mSign) mod = -mod; | ||
90812 | mod = new SmallInteger(mod); | ||
90813 | } else mod = new BigInteger(mod, mSign); | ||
90814 | return [quotient, mod]; | ||
90815 | } | ||
90816 | |||
90817 | BigInteger.prototype.divmod = function (v) { | ||
90818 | var result = divModAny(this, v); | ||
90819 | return { | ||
90820 | quotient: result[0], | ||
90821 | remainder: result[1] | ||
90822 | }; | ||
90823 | }; | ||
90824 | SmallInteger.prototype.divmod = BigInteger.prototype.divmod; | ||
90825 | |||
90826 | BigInteger.prototype.divide = function (v) { | ||
90827 | return divModAny(this, v)[0]; | ||
90828 | }; | ||
90829 | SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide; | ||
90830 | |||
90831 | BigInteger.prototype.mod = function (v) { | ||
90832 | return divModAny(this, v)[1]; | ||
90833 | }; | ||
90834 | SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod; | ||
90835 | |||
90836 | BigInteger.prototype.pow = function (v) { | ||
90837 | var n = parseValue(v), | ||
90838 | a = this.value, | ||
90839 | b = n.value, | ||
90840 | value, x, y; | ||
90841 | if (b === 0) return Integer[1]; | ||
90842 | if (a === 0) return Integer[0]; | ||
90843 | if (a === 1) return Integer[1]; | ||
90844 | if (a === -1) return n.isEven() ? Integer[1] : Integer[-1]; | ||
90845 | if (n.sign) { | ||
90846 | return Integer[0]; | ||
90847 | } | ||
90848 | if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large."); | ||
90849 | if (this.isSmall) { | ||
90850 | if (isPrecise(value = Math.pow(a, b))) | ||
90851 | return new SmallInteger(truncate(value)); | ||
90852 | } | ||
90853 | x = this; | ||
90854 | y = Integer[1]; | ||
90855 | while (true) { | ||
90856 | if (b & 1 === 1) { | ||
90857 | y = y.times(x); | ||
90858 | --b; | ||
90859 | } | ||
90860 | if (b === 0) break; | ||
90861 | b /= 2; | ||
90862 | x = x.square(); | ||
90863 | } | ||
90864 | return y; | ||
90865 | }; | ||
90866 | SmallInteger.prototype.pow = BigInteger.prototype.pow; | ||
90867 | |||
90868 | BigInteger.prototype.modPow = function (exp, mod) { | ||
90869 | exp = parseValue(exp); | ||
90870 | mod = parseValue(mod); | ||
90871 | if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0"); | ||
90872 | var r = Integer[1], | ||
90873 | base = this.mod(mod); | ||
90874 | while (exp.isPositive()) { | ||
90875 | if (base.isZero()) return Integer[0]; | ||
90876 | if (exp.isOdd()) r = r.multiply(base).mod(mod); | ||
90877 | exp = exp.divide(2); | ||
90878 | base = base.square().mod(mod); | ||
90879 | } | ||
90880 | return r; | ||
90881 | }; | ||
90882 | SmallInteger.prototype.modPow = BigInteger.prototype.modPow; | ||
90883 | |||
90884 | function compareAbs(a, b) { | ||
90885 | if (a.length !== b.length) { | ||
90886 | return a.length > b.length ? 1 : -1; | ||
90887 | } | ||
90888 | for (var i = a.length - 1; i >= 0; i--) { | ||
90889 | if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1; | ||
90890 | } | ||
90891 | return 0; | ||
90892 | } | ||
90893 | |||
90894 | BigInteger.prototype.compareAbs = function (v) { | ||
90895 | var n = parseValue(v), | ||
90896 | a = this.value, | ||
90897 | b = n.value; | ||
90898 | if (n.isSmall) return 1; | ||
90899 | return compareAbs(a, b); | ||
90900 | }; | ||
90901 | SmallInteger.prototype.compareAbs = function (v) { | ||
90902 | var n = parseValue(v), | ||
90903 | a = Math.abs(this.value), | ||
90904 | b = n.value; | ||
90905 | if (n.isSmall) { | ||
90906 | b = Math.abs(b); | ||
90907 | return a === b ? 0 : a > b ? 1 : -1; | ||
90908 | } | ||
90909 | return -1; | ||
90910 | }; | ||
90911 | |||
90912 | BigInteger.prototype.compare = function (v) { | ||
90913 | // See discussion about comparison with Infinity: | ||
90914 | // https://github.com/peterolson/BigInteger.js/issues/61 | ||
90915 | if (v === Infinity) { | ||
90916 | return -1; | ||
90917 | } | ||
90918 | if (v === -Infinity) { | ||
90919 | return 1; | ||
90920 | } | ||
90921 | |||
90922 | var n = parseValue(v), | ||
90923 | a = this.value, | ||
90924 | b = n.value; | ||
90925 | if (this.sign !== n.sign) { | ||
90926 | return n.sign ? 1 : -1; | ||
90927 | } | ||
90928 | if (n.isSmall) { | ||
90929 | return this.sign ? -1 : 1; | ||
90930 | } | ||
90931 | return compareAbs(a, b) * (this.sign ? -1 : 1); | ||
90932 | }; | ||
90933 | BigInteger.prototype.compareTo = BigInteger.prototype.compare; | ||
90934 | |||
90935 | SmallInteger.prototype.compare = function (v) { | ||
90936 | if (v === Infinity) { | ||
90937 | return -1; | ||
90938 | } | ||
90939 | if (v === -Infinity) { | ||
90940 | return 1; | ||
90941 | } | ||
90942 | |||
90943 | var n = parseValue(v), | ||
90944 | a = this.value, | ||
90945 | b = n.value; | ||
90946 | if (n.isSmall) { | ||
90947 | return a == b ? 0 : a > b ? 1 : -1; | ||
90948 | } | ||
90949 | if (a < 0 !== n.sign) { | ||
90950 | return a < 0 ? -1 : 1; | ||
90951 | } | ||
90952 | return a < 0 ? 1 : -1; | ||
90953 | }; | ||
90954 | SmallInteger.prototype.compareTo = SmallInteger.prototype.compare; | ||
90955 | |||
90956 | BigInteger.prototype.equals = function (v) { | ||
90957 | return this.compare(v) === 0; | ||
90958 | }; | ||
90959 | SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals; | ||
90960 | |||
90961 | BigInteger.prototype.notEquals = function (v) { | ||
90962 | return this.compare(v) !== 0; | ||
90963 | }; | ||
90964 | SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals; | ||
90965 | |||
90966 | BigInteger.prototype.greater = function (v) { | ||
90967 | return this.compare(v) > 0; | ||
90968 | }; | ||
90969 | SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater; | ||
90970 | |||
90971 | BigInteger.prototype.lesser = function (v) { | ||
90972 | return this.compare(v) < 0; | ||
90973 | }; | ||
90974 | SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser; | ||
90975 | |||
90976 | BigInteger.prototype.greaterOrEquals = function (v) { | ||
90977 | return this.compare(v) >= 0; | ||
90978 | }; | ||
90979 | SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals; | ||
90980 | |||
90981 | BigInteger.prototype.lesserOrEquals = function (v) { | ||
90982 | return this.compare(v) <= 0; | ||
90983 | }; | ||
90984 | SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals; | ||
90985 | |||
90986 | BigInteger.prototype.isEven = function () { | ||
90987 | return (this.value[0] & 1) === 0; | ||
90988 | }; | ||
90989 | SmallInteger.prototype.isEven = function () { | ||
90990 | return (this.value & 1) === 0; | ||
90991 | }; | ||
90992 | |||
90993 | BigInteger.prototype.isOdd = function () { | ||
90994 | return (this.value[0] & 1) === 1; | ||
90995 | }; | ||
90996 | SmallInteger.prototype.isOdd = function () { | ||
90997 | return (this.value & 1) === 1; | ||
90998 | }; | ||
90999 | |||
91000 | BigInteger.prototype.isPositive = function () { | ||
91001 | return !this.sign; | ||
91002 | }; | ||
91003 | SmallInteger.prototype.isPositive = function () { | ||
91004 | return this.value > 0; | ||
91005 | }; | ||
91006 | |||
91007 | BigInteger.prototype.isNegative = function () { | ||
91008 | return this.sign; | ||
91009 | }; | ||
91010 | SmallInteger.prototype.isNegative = function () { | ||
91011 | return this.value < 0; | ||
91012 | }; | ||
91013 | |||
91014 | BigInteger.prototype.isUnit = function () { | ||
91015 | return false; | ||
91016 | }; | ||
91017 | SmallInteger.prototype.isUnit = function () { | ||
91018 | return Math.abs(this.value) === 1; | ||
91019 | }; | ||
91020 | |||
91021 | BigInteger.prototype.isZero = function () { | ||
91022 | return false; | ||
91023 | }; | ||
91024 | SmallInteger.prototype.isZero = function () { | ||
91025 | return this.value === 0; | ||
91026 | }; | ||
91027 | BigInteger.prototype.isDivisibleBy = function (v) { | ||
91028 | var n = parseValue(v); | ||
91029 | var value = n.value; | ||
91030 | if (value === 0) return false; | ||
91031 | if (value === 1) return true; | ||
91032 | if (value === 2) return this.isEven(); | ||
91033 | return this.mod(n).equals(Integer[0]); | ||
91034 | }; | ||
91035 | SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy; | ||
91036 | |||
91037 | function isBasicPrime(v) { | ||
91038 | var n = v.abs(); | ||
91039 | if (n.isUnit()) return false; | ||
91040 | if (n.equals(2) || n.equals(3) || n.equals(5)) return true; | ||
91041 | if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false; | ||
91042 | if (n.lesser(25)) return true; | ||
91043 | // we don't know if it's prime: let the other functions figure it out | ||
91044 | } | ||
91045 | |||
91046 | BigInteger.prototype.isPrime = function () { | ||
91047 | var isPrime = isBasicPrime(this); | ||
91048 | if (isPrime !== undefined) return isPrime; | ||
91049 | var n = this.abs(), | ||
91050 | nPrev = n.prev(); | ||
91051 | var a = [2, 3, 5, 7, 11, 13, 17, 19], | ||
91052 | b = nPrev, | ||
91053 | d, t, i, x; | ||
91054 | while (b.isEven()) b = b.divide(2); | ||
91055 | for (i = 0; i < a.length; i++) { | ||
91056 | x = bigInt(a[i]).modPow(b, n); | ||
91057 | if (x.equals(Integer[1]) || x.equals(nPrev)) continue; | ||
91058 | for (t = true, d = b; t && d.lesser(nPrev) ; d = d.multiply(2)) { | ||
91059 | x = x.square().mod(n); | ||
91060 | if (x.equals(nPrev)) t = false; | ||
91061 | } | ||
91062 | if (t) return false; | ||
91063 | } | ||
91064 | return true; | ||
91065 | }; | ||
91066 | SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime; | ||
91067 | |||
91068 | BigInteger.prototype.isProbablePrime = function (iterations) { | ||
91069 | var isPrime = isBasicPrime(this); | ||
91070 | if (isPrime !== undefined) return isPrime; | ||
91071 | var n = this.abs(); | ||
91072 | var t = iterations === undefined ? 5 : iterations; | ||
91073 | // use the Fermat primality test | ||
91074 | for (var i = 0; i < t; i++) { | ||
91075 | var a = bigInt.randBetween(2, n.minus(2)); | ||
91076 | if (!a.modPow(n.prev(), n).isUnit()) return false; // definitely composite | ||
91077 | } | ||
91078 | return true; // large chance of being prime | ||
91079 | }; | ||
91080 | SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime; | ||
91081 | |||
91082 | BigInteger.prototype.modInv = function (n) { | ||
91083 | var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; | ||
91084 | while (!newR.equals(bigInt.zero)) { | ||
91085 | q = r.divide(newR); | ||
91086 | lastT = t; | ||
91087 | lastR = r; | ||
91088 | t = newT; | ||
91089 | r = newR; | ||
91090 | newT = lastT.subtract(q.multiply(newT)); | ||
91091 | newR = lastR.subtract(q.multiply(newR)); | ||
91092 | } | ||
91093 | if (!r.equals(1)) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); | ||
91094 | if (t.compare(0) === -1) { | ||
91095 | t = t.add(n); | ||
91096 | } | ||
91097 | if (this.isNegative()) { | ||
91098 | return t.negate(); | ||
91099 | } | ||
91100 | return t; | ||
91101 | }; | ||
91102 | |||
91103 | SmallInteger.prototype.modInv = BigInteger.prototype.modInv; | ||
91104 | |||
91105 | BigInteger.prototype.next = function () { | ||
91106 | var value = this.value; | ||
91107 | if (this.sign) { | ||
91108 | return subtractSmall(value, 1, this.sign); | ||
91109 | } | ||
91110 | return new BigInteger(addSmall(value, 1), this.sign); | ||
91111 | }; | ||
91112 | SmallInteger.prototype.next = function () { | ||
91113 | var value = this.value; | ||
91114 | if (value + 1 < MAX_INT) return new SmallInteger(value + 1); | ||
91115 | return new BigInteger(MAX_INT_ARR, false); | ||
91116 | }; | ||
91117 | |||
91118 | BigInteger.prototype.prev = function () { | ||
91119 | var value = this.value; | ||
91120 | if (this.sign) { | ||
91121 | return new BigInteger(addSmall(value, 1), true); | ||
91122 | } | ||
91123 | return subtractSmall(value, 1, this.sign); | ||
91124 | }; | ||
91125 | SmallInteger.prototype.prev = function () { | ||
91126 | var value = this.value; | ||
91127 | if (value - 1 > -MAX_INT) return new SmallInteger(value - 1); | ||
91128 | return new BigInteger(MAX_INT_ARR, true); | ||
91129 | }; | ||
91130 | |||
91131 | var powersOfTwo = [1]; | ||
91132 | while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]); | ||
91133 | var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1]; | ||
91134 | |||
91135 | function shift_isSmall(n) { | ||
91136 | return ((typeof n === "number" || typeof n === "string") && +Math.abs(n) <= BASE) || | ||
91137 | (n instanceof BigInteger && n.value.length <= 1); | ||
91138 | } | ||
91139 | |||
91140 | BigInteger.prototype.shiftLeft = function (n) { | ||
91141 | if (!shift_isSmall(n)) { | ||
91142 | throw new Error(String(n) + " is too large for shifting."); | ||
91143 | } | ||
91144 | n = +n; | ||
91145 | if (n < 0) return this.shiftRight(-n); | ||
91146 | var result = this; | ||
91147 | while (n >= powers2Length) { | ||
91148 | result = result.multiply(highestPower2); | ||
91149 | n -= powers2Length - 1; | ||
91150 | } | ||
91151 | return result.multiply(powersOfTwo[n]); | ||
91152 | }; | ||
91153 | SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft; | ||
91154 | |||
91155 | BigInteger.prototype.shiftRight = function (n) { | ||
91156 | var remQuo; | ||
91157 | if (!shift_isSmall(n)) { | ||
91158 | throw new Error(String(n) + " is too large for shifting."); | ||
91159 | } | ||
91160 | n = +n; | ||
91161 | if (n < 0) return this.shiftLeft(-n); | ||
91162 | var result = this; | ||
91163 | while (n >= powers2Length) { | ||
91164 | if (result.isZero()) return result; | ||
91165 | remQuo = divModAny(result, highestPower2); | ||
91166 | result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; | ||
91167 | n -= powers2Length - 1; | ||
91168 | } | ||
91169 | remQuo = divModAny(result, powersOfTwo[n]); | ||
91170 | return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; | ||
91171 | }; | ||
91172 | SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight; | ||
91173 | |||
91174 | function bitwise(x, y, fn) { | ||
91175 | y = parseValue(y); | ||
91176 | var xSign = x.isNegative(), ySign = y.isNegative(); | ||
91177 | var xRem = xSign ? x.not() : x, | ||
91178 | yRem = ySign ? y.not() : y; | ||
91179 | var xDigit = 0, yDigit = 0; | ||
91180 | var xDivMod = null, yDivMod = null; | ||
91181 | var result = []; | ||
91182 | while (!xRem.isZero() || !yRem.isZero()) { | ||
91183 | xDivMod = divModAny(xRem, highestPower2); | ||
91184 | xDigit = xDivMod[1].toJSNumber(); | ||
91185 | if (xSign) { | ||
91186 | xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers | ||
91187 | } | ||
91188 | |||
91189 | yDivMod = divModAny(yRem, highestPower2); | ||
91190 | yDigit = yDivMod[1].toJSNumber(); | ||
91191 | if (ySign) { | ||
91192 | yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers | ||
91193 | } | ||
91194 | |||
91195 | xRem = xDivMod[0]; | ||
91196 | yRem = yDivMod[0]; | ||
91197 | result.push(fn(xDigit, yDigit)); | ||
91198 | } | ||
91199 | var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); | ||
91200 | for (var i = result.length - 1; i >= 0; i -= 1) { | ||
91201 | sum = sum.multiply(highestPower2).add(bigInt(result[i])); | ||
91202 | } | ||
91203 | return sum; | ||
91204 | } | ||
91205 | |||
91206 | BigInteger.prototype.not = function () { | ||
91207 | return this.negate().prev(); | ||
91208 | }; | ||
91209 | SmallInteger.prototype.not = BigInteger.prototype.not; | ||
91210 | |||
91211 | BigInteger.prototype.and = function (n) { | ||
91212 | return bitwise(this, n, function (a, b) { return a & b; }); | ||
91213 | }; | ||
91214 | SmallInteger.prototype.and = BigInteger.prototype.and; | ||
91215 | |||
91216 | BigInteger.prototype.or = function (n) { | ||
91217 | return bitwise(this, n, function (a, b) { return a | b; }); | ||
91218 | }; | ||
91219 | SmallInteger.prototype.or = BigInteger.prototype.or; | ||
91220 | |||
91221 | BigInteger.prototype.xor = function (n) { | ||
91222 | return bitwise(this, n, function (a, b) { return a ^ b; }); | ||
91223 | }; | ||
91224 | SmallInteger.prototype.xor = BigInteger.prototype.xor; | ||
91225 | |||
91226 | var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I; | ||
91227 | function roughLOB(n) { // get lowestOneBit (rough) | ||
91228 | // SmallInteger: return Min(lowestOneBit(n), 1 << 30) | ||
91229 | // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7] | ||
91230 | var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : v[0] + v[1] * BASE | LOBMASK_BI; | ||
91231 | return x & -x; | ||
91232 | } | ||
91233 | |||
91234 | function max(a, b) { | ||
91235 | a = parseValue(a); | ||
91236 | b = parseValue(b); | ||
91237 | return a.greater(b) ? a : b; | ||
91238 | } | ||
91239 | function min(a, b) { | ||
91240 | a = parseValue(a); | ||
91241 | b = parseValue(b); | ||
91242 | return a.lesser(b) ? a : b; | ||
91243 | } | ||
91244 | function gcd(a, b) { | ||
91245 | a = parseValue(a).abs(); | ||
91246 | b = parseValue(b).abs(); | ||
91247 | if (a.equals(b)) return a; | ||
91248 | if (a.isZero()) return b; | ||
91249 | if (b.isZero()) return a; | ||
91250 | var c = Integer[1], d, t; | ||
91251 | while (a.isEven() && b.isEven()) { | ||
91252 | d = Math.min(roughLOB(a), roughLOB(b)); | ||
91253 | a = a.divide(d); | ||
91254 | b = b.divide(d); | ||
91255 | c = c.multiply(d); | ||
91256 | } | ||
91257 | while (a.isEven()) { | ||
91258 | a = a.divide(roughLOB(a)); | ||
91259 | } | ||
91260 | do { | ||
91261 | while (b.isEven()) { | ||
91262 | b = b.divide(roughLOB(b)); | ||
91263 | } | ||
91264 | if (a.greater(b)) { | ||
91265 | t = b; b = a; a = t; | ||
91266 | } | ||
91267 | b = b.subtract(a); | ||
91268 | } while (!b.isZero()); | ||
91269 | return c.isUnit() ? a : a.multiply(c); | ||
91270 | } | ||
91271 | function lcm(a, b) { | ||
91272 | a = parseValue(a).abs(); | ||
91273 | b = parseValue(b).abs(); | ||
91274 | return a.divide(gcd(a, b)).multiply(b); | ||
91275 | } | ||
91276 | function randBetween(a, b) { | ||
91277 | a = parseValue(a); | ||
91278 | b = parseValue(b); | ||
91279 | var low = min(a, b), high = max(a, b); | ||
91280 | var range = high.subtract(low).add(1); | ||
91281 | if (range.isSmall) return low.add(Math.floor(Math.random() * range)); | ||
91282 | var length = range.value.length - 1; | ||
91283 | var result = [], restricted = true; | ||
91284 | for (var i = length; i >= 0; i--) { | ||
91285 | var top = restricted ? range.value[i] : BASE; | ||
91286 | var digit = truncate(Math.random() * top); | ||
91287 | result.unshift(digit); | ||
91288 | if (digit < top) restricted = false; | ||
91289 | } | ||
91290 | result = arrayToSmall(result); | ||
91291 | return low.add(typeof result === "number" ? new SmallInteger(result) : new BigInteger(result, false)); | ||
91292 | } | ||
91293 | var parseBase = function (text, base) { | ||
91294 | var length = text.length; | ||
91295 | var i; | ||
91296 | var absBase = Math.abs(base); | ||
91297 | for(var i = 0; i < length; i++) { | ||
91298 | var c = text[i].toLowerCase(); | ||
91299 | if(c === "-") continue; | ||
91300 | if(/[a-z0-9]/.test(c)) { | ||
91301 | if(/[0-9]/.test(c) && +c >= absBase) { | ||
91302 | if(c === "1" && absBase === 1) continue; | ||
91303 | throw new Error(c + " is not a valid digit in base " + base + "."); | ||
91304 | } else if(c.charCodeAt(0) - 87 >= absBase) { | ||
91305 | throw new Error(c + " is not a valid digit in base " + base + "."); | ||
91306 | } | ||
91307 | } | ||
91308 | } | ||
91309 | if (2 <= base && base <= 36) { | ||
91310 | if (length <= LOG_MAX_INT / Math.log(base)) { | ||
91311 | var result = parseInt(text, base); | ||
91312 | if(isNaN(result)) { | ||
91313 | throw new Error(c + " is not a valid digit in base " + base + "."); | ||
91314 | } | ||
91315 | return new SmallInteger(parseInt(text, base)); | ||
91316 | } | ||
91317 | } | ||
91318 | base = parseValue(base); | ||
91319 | var digits = []; | ||
91320 | var isNegative = text[0] === "-"; | ||
91321 | for (i = isNegative ? 1 : 0; i < text.length; i++) { | ||
91322 | var c = text[i].toLowerCase(), | ||
91323 | charCode = c.charCodeAt(0); | ||
91324 | if (48 <= charCode && charCode <= 57) digits.push(parseValue(c)); | ||
91325 | else if (97 <= charCode && charCode <= 122) digits.push(parseValue(c.charCodeAt(0) - 87)); | ||
91326 | else if (c === "<") { | ||
91327 | var start = i; | ||
91328 | do { i++; } while (text[i] !== ">"); | ||
91329 | digits.push(parseValue(text.slice(start + 1, i))); | ||
91330 | } | ||
91331 | else throw new Error(c + " is not a valid character"); | ||
91332 | } | ||
91333 | return parseBaseFromArray(digits, base, isNegative); | ||
91334 | }; | ||
91335 | |||
91336 | function parseBaseFromArray(digits, base, isNegative) { | ||
91337 | var val = Integer[0], pow = Integer[1], i; | ||
91338 | for (i = digits.length - 1; i >= 0; i--) { | ||
91339 | val = val.add(digits[i].times(pow)); | ||
91340 | pow = pow.times(base); | ||
91341 | } | ||
91342 | return isNegative ? val.negate() : val; | ||
91343 | } | ||
91344 | |||
91345 | function stringify(digit) { | ||
91346 | var v = digit.value; | ||
91347 | if (typeof v === "number") v = [v]; | ||
91348 | if (v.length === 1 && v[0] <= 35) { | ||
91349 | return "0123456789abcdefghijklmnopqrstuvwxyz".charAt(v[0]); | ||
91350 | } | ||
91351 | return "<" + v + ">"; | ||
91352 | } | ||
91353 | function toBase(n, base) { | ||
91354 | base = bigInt(base); | ||
91355 | if (base.isZero()) { | ||
91356 | if (n.isZero()) return "0"; | ||
91357 | throw new Error("Cannot convert nonzero numbers to base 0."); | ||
91358 | } | ||
91359 | if (base.equals(-1)) { | ||
91360 | if (n.isZero()) return "0"; | ||
91361 | if (n.isNegative()) return new Array(1 - n).join("10"); | ||
91362 | return "1" + new Array(+n).join("01"); | ||
91363 | } | ||
91364 | var minusSign = ""; | ||
91365 | if (n.isNegative() && base.isPositive()) { | ||
91366 | minusSign = "-"; | ||
91367 | n = n.abs(); | ||
91368 | } | ||
91369 | if (base.equals(1)) { | ||
91370 | if (n.isZero()) return "0"; | ||
91371 | return minusSign + new Array(+n + 1).join(1); | ||
91372 | } | ||
91373 | var out = []; | ||
91374 | var left = n, divmod; | ||
91375 | while (left.isNegative() || left.compareAbs(base) >= 0) { | ||
91376 | divmod = left.divmod(base); | ||
91377 | left = divmod.quotient; | ||
91378 | var digit = divmod.remainder; | ||
91379 | if (digit.isNegative()) { | ||
91380 | digit = base.minus(digit).abs(); | ||
91381 | left = left.next(); | ||
91382 | } | ||
91383 | out.push(stringify(digit)); | ||
91384 | } | ||
91385 | out.push(stringify(left)); | ||
91386 | return minusSign + out.reverse().join(""); | ||
91387 | } | ||
91388 | |||
91389 | BigInteger.prototype.toString = function (radix) { | ||
91390 | if (radix === undefined) radix = 10; | ||
91391 | if (radix !== 10) return toBase(this, radix); | ||
91392 | var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; | ||
91393 | while (--l >= 0) { | ||
91394 | digit = String(v[l]); | ||
91395 | str += zeros.slice(digit.length) + digit; | ||
91396 | } | ||
91397 | var sign = this.sign ? "-" : ""; | ||
91398 | return sign + str; | ||
91399 | }; | ||
91400 | |||
91401 | SmallInteger.prototype.toString = function (radix) { | ||
91402 | if (radix === undefined) radix = 10; | ||
91403 | if (radix != 10) return toBase(this, radix); | ||
91404 | return String(this.value); | ||
91405 | }; | ||
91406 | BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function() { return this.toString(); } | ||
91407 | |||
91408 | BigInteger.prototype.valueOf = function () { | ||
91409 | return +this.toString(); | ||
91410 | }; | ||
91411 | BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf; | ||
91412 | |||
91413 | SmallInteger.prototype.valueOf = function () { | ||
91414 | return this.value; | ||
91415 | }; | ||
91416 | SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf; | ||
91417 | |||
91418 | function parseStringValue(v) { | ||
91419 | if (isPrecise(+v)) { | ||
91420 | var x = +v; | ||
91421 | if (x === truncate(x)) | ||
91422 | return new SmallInteger(x); | ||
91423 | throw "Invalid integer: " + v; | ||
91424 | } | ||
91425 | var sign = v[0] === "-"; | ||
91426 | if (sign) v = v.slice(1); | ||
91427 | var split = v.split(/e/i); | ||
91428 | if (split.length > 2) throw new Error("Invalid integer: " + split.join("e")); | ||
91429 | if (split.length === 2) { | ||
91430 | var exp = split[1]; | ||
91431 | if (exp[0] === "+") exp = exp.slice(1); | ||
91432 | exp = +exp; | ||
91433 | if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent."); | ||
91434 | var text = split[0]; | ||
91435 | var decimalPlace = text.indexOf("."); | ||
91436 | if (decimalPlace >= 0) { | ||
91437 | exp -= text.length - decimalPlace - 1; | ||
91438 | text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1); | ||
91439 | } | ||
91440 | if (exp < 0) throw new Error("Cannot include negative exponent part for integers"); | ||
91441 | text += (new Array(exp + 1)).join("0"); | ||
91442 | v = text; | ||
91443 | } | ||
91444 | var isValid = /^([0-9][0-9]*)$/.test(v); | ||
91445 | if (!isValid) throw new Error("Invalid integer: " + v); | ||
91446 | var r = [], max = v.length, l = LOG_BASE, min = max - l; | ||
91447 | while (max > 0) { | ||
91448 | r.push(+v.slice(min, max)); | ||
91449 | min -= l; | ||
91450 | if (min < 0) min = 0; | ||
91451 | max -= l; | ||
91452 | } | ||
91453 | trim(r); | ||
91454 | return new BigInteger(r, sign); | ||
91455 | } | ||
91456 | |||
91457 | function parseNumberValue(v) { | ||
91458 | if (isPrecise(v)) { | ||
91459 | if (v !== truncate(v)) throw new Error(v + " is not an integer."); | ||
91460 | return new SmallInteger(v); | ||
91461 | } | ||
91462 | return parseStringValue(v.toString()); | ||
91463 | } | ||
91464 | |||
91465 | function parseValue(v) { | ||
91466 | if (typeof v === "number") { | ||
91467 | return parseNumberValue(v); | ||
91468 | } | ||
91469 | if (typeof v === "string") { | ||
91470 | return parseStringValue(v); | ||
91471 | } | ||
91472 | return v; | ||
91473 | } | ||
91474 | // Pre-define numbers in range [-999,999] | ||
91475 | for (var i = 0; i < 1000; i++) { | ||
91476 | Integer[i] = new SmallInteger(i); | ||
91477 | if (i > 0) Integer[-i] = new SmallInteger(-i); | ||
91478 | } | ||
91479 | // Backwards compatibility | ||
91480 | Integer.one = Integer[1]; | ||
91481 | Integer.zero = Integer[0]; | ||
91482 | Integer.minusOne = Integer[-1]; | ||
91483 | Integer.max = max; | ||
91484 | Integer.min = min; | ||
91485 | Integer.gcd = gcd; | ||
91486 | Integer.lcm = lcm; | ||
91487 | Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger; }; | ||
91488 | Integer.randBetween = randBetween; | ||
91489 | |||
91490 | Integer.fromArray = function (digits, base, isNegative) { | ||
91491 | return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative); | ||
91492 | }; | ||
91493 | |||
91494 | return Integer; | ||
91495 | })(); | ||
91496 | |||
91497 | // Node.js check | ||
91498 | if (typeof module !== "undefined" && module.hasOwnProperty("exports")) { | ||
91499 | module.exports = bigInt; | ||
91500 | } | ||
91501 | |||
91502 | //amd check | ||
91503 | if ( typeof define === "function" && define.amd ) { | ||
91504 | define( "big-integer", [], function() { | ||
91505 | return bigInt; | ||
91506 | }); | ||
91507 | } | ||
91508 | |||
91509 | },{}],4:[function(require,module,exports){ | ||
91510 | |||
91511 | },{}],5:[function(require,module,exports){ | ||
91512 | var basex = require('base-x') | ||
91513 | var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | ||
91514 | |||
91515 | module.exports = basex(ALPHABET) | ||
91516 | |||
91517 | },{"base-x":1}],6:[function(require,module,exports){ | ||
91518 | 'use strict' | ||
91519 | |||
91520 | var base58 = require('bs58') | ||
91521 | var Buffer = require('safe-buffer').Buffer | ||
91522 | |||
91523 | module.exports = function (checksumFn) { | ||
91524 | // Encode a buffer as a base58-check encoded string | ||
91525 | function encode (payload) { | ||
91526 | var checksum = checksumFn(payload) | ||
91527 | |||
91528 | return base58.encode(Buffer.concat([ | ||
91529 | payload, | ||
91530 | checksum | ||
91531 | ], payload.length + 4)) | ||
91532 | } | ||
91533 | |||
91534 | function decodeRaw (buffer) { | ||
91535 | var payload = buffer.slice(0, -4) | ||
91536 | var checksum = buffer.slice(-4) | ||
91537 | var newChecksum = checksumFn(payload) | ||
91538 | |||
91539 | if (checksum[0] ^ newChecksum[0] | | ||
91540 | checksum[1] ^ newChecksum[1] | | ||
91541 | checksum[2] ^ newChecksum[2] | | ||
91542 | checksum[3] ^ newChecksum[3]) return | ||
91543 | |||
91544 | return payload | ||
91545 | } | ||
91546 | |||
91547 | // Decode a base58-check encoded string to a buffer, no result if checksum is wrong | ||
91548 | function decodeUnsafe (string) { | ||
91549 | var buffer = base58.decodeUnsafe(string) | ||
91550 | if (!buffer) return | ||
91551 | |||
91552 | return decodeRaw(buffer) | ||
91553 | } | ||
91554 | |||
91555 | function decode (string) { | ||
91556 | var buffer = base58.decode(string) | ||
91557 | var payload = decodeRaw(buffer, checksumFn) | ||
91558 | if (!payload) throw new Error('Invalid checksum') | ||
91559 | return payload | ||
91560 | } | ||
91561 | |||
91562 | return { | ||
91563 | encode: encode, | ||
91564 | decode: decode, | ||
91565 | decodeUnsafe: decodeUnsafe | ||
91566 | } | ||
91567 | } | ||
91568 | |||
91569 | },{"bs58":5,"safe-buffer":40}],7:[function(require,module,exports){ | ||
91570 | 'use strict' | ||
91571 | |||
91572 | var createHash = require('create-hash') | ||
91573 | var bs58checkBase = require('./base') | ||
91574 | |||
91575 | // SHA256(SHA256(buffer)) | ||
91576 | function sha256x2 (buffer) { | ||
91577 | var tmp = createHash('sha256').update(buffer).digest() | ||
91578 | return createHash('sha256').update(tmp).digest() | ||
91579 | } | ||
91580 | |||
91581 | module.exports = bs58checkBase(sha256x2) | ||
91582 | |||
91583 | },{"./base":6,"create-hash":15}],8:[function(require,module,exports){ | ||
91584 | /*! | ||
91585 | * The buffer module from node.js, for the browser. | ||
91586 | * | ||
91587 | * @author Feross Aboukhadijeh <https://feross.org> | ||
91588 | * @license MIT | ||
91589 | */ | ||
91590 | /* eslint-disable no-proto */ | ||
91591 | |||
91592 | 'use strict' | ||
91593 | |||
91594 | var base64 = require('base64-js') | ||
91595 | var ieee754 = require('ieee754') | ||
91596 | |||
91597 | exports.Buffer = Buffer | ||
91598 | exports.SlowBuffer = SlowBuffer | ||
91599 | exports.INSPECT_MAX_BYTES = 50 | ||
91600 | |||
91601 | var K_MAX_LENGTH = 0x7fffffff | ||
91602 | exports.kMaxLength = K_MAX_LENGTH | ||
91603 | |||
91604 | /** | ||
91605 | * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
91606 | * === true Use Uint8Array implementation (fastest) | ||
91607 | * === false Print warning and recommend using `buffer` v4.x which has an Object | ||
91608 | * implementation (most compatible, even IE6) | ||
91609 | * | ||
91610 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
91611 | * Opera 11.6+, iOS 4.2+. | ||
91612 | * | ||
91613 | * We report that the browser does not support typed arrays if the are not subclassable | ||
91614 | * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` | ||
91615 | * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support | ||
91616 | * for __proto__ and has a buggy typed array implementation. | ||
91617 | */ | ||
91618 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() | ||
91619 | |||
91620 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && | ||
91621 | typeof console.error === 'function') { | ||
91622 | console.error( | ||
91623 | 'This browser lacks typed array (Uint8Array) support which is required by ' + | ||
91624 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' | ||
91625 | ) | ||
91626 | } | ||
91627 | |||
91628 | function typedArraySupport () { | ||
91629 | // Can typed array instances can be augmented? | ||
91630 | try { | ||
91631 | var arr = new Uint8Array(1) | ||
91632 | arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} | ||
91633 | return arr.foo() === 42 | ||
91634 | } catch (e) { | ||
91635 | return false | ||
91636 | } | ||
91637 | } | ||
91638 | |||
91639 | function createBuffer (length) { | ||
91640 | if (length > K_MAX_LENGTH) { | ||
91641 | throw new RangeError('Invalid typed array length') | ||
91642 | } | ||
91643 | // Return an augmented `Uint8Array` instance | ||
91644 | var buf = new Uint8Array(length) | ||
91645 | buf.__proto__ = Buffer.prototype | ||
91646 | return buf | ||
91647 | } | ||
91648 | |||
91649 | /** | ||
91650 | * The Buffer constructor returns instances of `Uint8Array` that have their | ||
91651 | * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of | ||
91652 | * `Uint8Array`, so the returned instances will have all the node `Buffer` methods | ||
91653 | * and the `Uint8Array` methods. Square bracket notation works as expected -- it | ||
91654 | * returns a single octet. | ||
91655 | * | ||
91656 | * The `Uint8Array` prototype remains unmodified. | ||
91657 | */ | ||
91658 | |||
91659 | function Buffer (arg, encodingOrOffset, length) { | ||
91660 | // Common case. | ||
91661 | if (typeof arg === 'number') { | ||
91662 | if (typeof encodingOrOffset === 'string') { | ||
91663 | throw new Error( | ||
91664 | 'If encoding is specified then the first argument must be a string' | ||
91665 | ) | ||
91666 | } | ||
91667 | return allocUnsafe(arg) | ||
91668 | } | ||
91669 | return from(arg, encodingOrOffset, length) | ||
91670 | } | ||
91671 | |||
91672 | // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
91673 | if (typeof Symbol !== 'undefined' && Symbol.species && | ||
91674 | Buffer[Symbol.species] === Buffer) { | ||
91675 | Object.defineProperty(Buffer, Symbol.species, { | ||
91676 | value: null, | ||
91677 | configurable: true, | ||
91678 | enumerable: false, | ||
91679 | writable: false | ||
91680 | }) | ||
91681 | } | ||
91682 | |||
91683 | Buffer.poolSize = 8192 // not used by this implementation | ||
91684 | |||
91685 | function from (value, encodingOrOffset, length) { | ||
91686 | if (typeof value === 'number') { | ||
91687 | throw new TypeError('"value" argument must not be a number') | ||
91688 | } | ||
91689 | |||
91690 | if (isArrayBuffer(value)) { | ||
91691 | return fromArrayBuffer(value, encodingOrOffset, length) | ||
91692 | } | ||
91693 | |||
91694 | if (typeof value === 'string') { | ||
91695 | return fromString(value, encodingOrOffset) | ||
91696 | } | ||
91697 | |||
91698 | return fromObject(value) | ||
91699 | } | ||
91700 | |||
91701 | /** | ||
91702 | * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError | ||
91703 | * if value is a number. | ||
91704 | * Buffer.from(str[, encoding]) | ||
91705 | * Buffer.from(array) | ||
91706 | * Buffer.from(buffer) | ||
91707 | * Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||
91708 | **/ | ||
91709 | Buffer.from = function (value, encodingOrOffset, length) { | ||
91710 | return from(value, encodingOrOffset, length) | ||
91711 | } | ||
91712 | |||
91713 | // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: | ||
91714 | // https://github.com/feross/buffer/pull/148 | ||
91715 | Buffer.prototype.__proto__ = Uint8Array.prototype | ||
91716 | Buffer.__proto__ = Uint8Array | ||
91717 | |||
91718 | function assertSize (size) { | ||
91719 | if (typeof size !== 'number') { | ||
91720 | throw new TypeError('"size" argument must be a number') | ||
91721 | } else if (size < 0) { | ||
91722 | throw new RangeError('"size" argument must not be negative') | ||
91723 | } | ||
91724 | } | ||
91725 | |||
91726 | function alloc (size, fill, encoding) { | ||
91727 | assertSize(size) | ||
91728 | if (size <= 0) { | ||
91729 | return createBuffer(size) | ||
91730 | } | ||
91731 | if (fill !== undefined) { | ||
91732 | // Only pay attention to encoding if it's a string. This | ||
91733 | // prevents accidentally sending in a number that would | ||
91734 | // be interpretted as a start offset. | ||
91735 | return typeof encoding === 'string' | ||
91736 | ? createBuffer(size).fill(fill, encoding) | ||
91737 | : createBuffer(size).fill(fill) | ||
91738 | } | ||
91739 | return createBuffer(size) | ||
91740 | } | ||
91741 | |||
91742 | /** | ||
91743 | * Creates a new filled Buffer instance. | ||
91744 | * alloc(size[, fill[, encoding]]) | ||
91745 | **/ | ||
91746 | Buffer.alloc = function (size, fill, encoding) { | ||
91747 | return alloc(size, fill, encoding) | ||
91748 | } | ||
91749 | |||
91750 | function allocUnsafe (size) { | ||
91751 | assertSize(size) | ||
91752 | return createBuffer(size < 0 ? 0 : checked(size) | 0) | ||
91753 | } | ||
91754 | |||
91755 | /** | ||
91756 | * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. | ||
91757 | * */ | ||
91758 | Buffer.allocUnsafe = function (size) { | ||
91759 | return allocUnsafe(size) | ||
91760 | } | ||
91761 | /** | ||
91762 | * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ||
91763 | */ | ||
91764 | Buffer.allocUnsafeSlow = function (size) { | ||
91765 | return allocUnsafe(size) | ||
91766 | } | ||
91767 | |||
91768 | function fromString (string, encoding) { | ||
91769 | if (typeof encoding !== 'string' || encoding === '') { | ||
91770 | encoding = 'utf8' | ||
91771 | } | ||
91772 | |||
91773 | if (!Buffer.isEncoding(encoding)) { | ||
91774 | throw new TypeError('"encoding" must be a valid string encoding') | ||
91775 | } | ||
91776 | |||
91777 | var length = byteLength(string, encoding) | 0 | ||
91778 | var buf = createBuffer(length) | ||
91779 | |||
91780 | var actual = buf.write(string, encoding) | ||
91781 | |||
91782 | if (actual !== length) { | ||
91783 | // Writing a hex string, for example, that contains invalid characters will | ||
91784 | // cause everything after the first invalid character to be ignored. (e.g. | ||
91785 | // 'abxxcd' will be treated as 'ab') | ||
91786 | buf = buf.slice(0, actual) | ||
91787 | } | ||
91788 | |||
91789 | return buf | ||
91790 | } | ||
91791 | |||
91792 | function fromArrayLike (array) { | ||
91793 | var length = array.length < 0 ? 0 : checked(array.length) | 0 | ||
91794 | var buf = createBuffer(length) | ||
91795 | for (var i = 0; i < length; i += 1) { | ||
91796 | buf[i] = array[i] & 255 | ||
91797 | } | ||
91798 | return buf | ||
91799 | } | ||
91800 | |||
91801 | function fromArrayBuffer (array, byteOffset, length) { | ||
91802 | if (byteOffset < 0 || array.byteLength < byteOffset) { | ||
91803 | throw new RangeError('\'offset\' is out of bounds') | ||
91804 | } | ||
91805 | |||
91806 | if (array.byteLength < byteOffset + (length || 0)) { | ||
91807 | throw new RangeError('\'length\' is out of bounds') | ||
91808 | } | ||
91809 | |||
91810 | var buf | ||
91811 | if (byteOffset === undefined && length === undefined) { | ||
91812 | buf = new Uint8Array(array) | ||
91813 | } else if (length === undefined) { | ||
91814 | buf = new Uint8Array(array, byteOffset) | ||
91815 | } else { | ||
91816 | buf = new Uint8Array(array, byteOffset, length) | ||
91817 | } | ||
91818 | |||
91819 | // Return an augmented `Uint8Array` instance | ||
91820 | buf.__proto__ = Buffer.prototype | ||
91821 | return buf | ||
91822 | } | ||
91823 | |||
91824 | function fromObject (obj) { | ||
91825 | if (Buffer.isBuffer(obj)) { | ||
91826 | var len = checked(obj.length) | 0 | ||
91827 | var buf = createBuffer(len) | ||
91828 | |||
91829 | if (buf.length === 0) { | ||
91830 | return buf | ||
91831 | } | ||
91832 | |||
91833 | obj.copy(buf, 0, 0, len) | ||
91834 | return buf | ||
91835 | } | ||
91836 | |||
91837 | if (obj) { | ||
91838 | if (isArrayBufferView(obj) || 'length' in obj) { | ||
91839 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
91840 | return createBuffer(0) | ||
91841 | } | ||
91842 | return fromArrayLike(obj) | ||
91843 | } | ||
91844 | |||
91845 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
91846 | return fromArrayLike(obj.data) | ||
91847 | } | ||
91848 | } | ||
91849 | |||
91850 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') | ||
91851 | } | ||
91852 | |||
91853 | function checked (length) { | ||
91854 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when | ||
91855 | // length is NaN (which is otherwise coerced to zero.) | ||
91856 | if (length >= K_MAX_LENGTH) { | ||
91857 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
91858 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') | ||
91859 | } | ||
91860 | return length | 0 | ||
91861 | } | ||
91862 | |||
91863 | function SlowBuffer (length) { | ||
91864 | if (+length != length) { // eslint-disable-line eqeqeq | ||
91865 | length = 0 | ||
91866 | } | ||
91867 | return Buffer.alloc(+length) | ||
91868 | } | ||
91869 | |||
91870 | Buffer.isBuffer = function isBuffer (b) { | ||
91871 | return b != null && b._isBuffer === true | ||
91872 | } | ||
91873 | |||
91874 | Buffer.compare = function compare (a, b) { | ||
91875 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
91876 | throw new TypeError('Arguments must be Buffers') | ||
91877 | } | ||
91878 | |||
91879 | if (a === b) return 0 | ||
91880 | |||
91881 | var x = a.length | ||
91882 | var y = b.length | ||
91883 | |||
91884 | for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
91885 | if (a[i] !== b[i]) { | ||
91886 | x = a[i] | ||
91887 | y = b[i] | ||
91888 | break | ||
91889 | } | ||
91890 | } | ||
91891 | |||
91892 | if (x < y) return -1 | ||
91893 | if (y < x) return 1 | ||
91894 | return 0 | ||
91895 | } | ||
91896 | |||
91897 | Buffer.isEncoding = function isEncoding (encoding) { | ||
91898 | switch (String(encoding).toLowerCase()) { | ||
91899 | case 'hex': | ||
91900 | case 'utf8': | ||
91901 | case 'utf-8': | ||
91902 | case 'ascii': | ||
91903 | case 'latin1': | ||
91904 | case 'binary': | ||
91905 | case 'base64': | ||
91906 | case 'ucs2': | ||
91907 | case 'ucs-2': | ||
91908 | case 'utf16le': | ||
91909 | case 'utf-16le': | ||
91910 | return true | ||
91911 | default: | ||
91912 | return false | ||
91913 | } | ||
91914 | } | ||
91915 | |||
91916 | Buffer.concat = function concat (list, length) { | ||
91917 | if (!Array.isArray(list)) { | ||
91918 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
91919 | } | ||
91920 | |||
91921 | if (list.length === 0) { | ||
91922 | return Buffer.alloc(0) | ||
91923 | } | ||
91924 | |||
91925 | var i | ||
91926 | if (length === undefined) { | ||
91927 | length = 0 | ||
91928 | for (i = 0; i < list.length; ++i) { | ||
91929 | length += list[i].length | ||
91930 | } | ||
91931 | } | ||
91932 | |||
91933 | var buffer = Buffer.allocUnsafe(length) | ||
91934 | var pos = 0 | ||
91935 | for (i = 0; i < list.length; ++i) { | ||
91936 | var buf = list[i] | ||
91937 | if (!Buffer.isBuffer(buf)) { | ||
91938 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
91939 | } | ||
91940 | buf.copy(buffer, pos) | ||
91941 | pos += buf.length | ||
91942 | } | ||
91943 | return buffer | ||
91944 | } | ||
91945 | |||
91946 | function byteLength (string, encoding) { | ||
91947 | if (Buffer.isBuffer(string)) { | ||
91948 | return string.length | ||
91949 | } | ||
91950 | if (isArrayBufferView(string) || isArrayBuffer(string)) { | ||
91951 | return string.byteLength | ||
91952 | } | ||
91953 | if (typeof string !== 'string') { | ||
91954 | string = '' + string | ||
91955 | } | ||
91956 | |||
91957 | var len = string.length | ||
91958 | if (len === 0) return 0 | ||
91959 | |||
91960 | // Use a for loop to avoid recursion | ||
91961 | var loweredCase = false | ||
91962 | for (;;) { | ||
91963 | switch (encoding) { | ||
91964 | case 'ascii': | ||
91965 | case 'latin1': | ||
91966 | case 'binary': | ||
91967 | return len | ||
91968 | case 'utf8': | ||
91969 | case 'utf-8': | ||
91970 | case undefined: | ||
91971 | return utf8ToBytes(string).length | ||
91972 | case 'ucs2': | ||
91973 | case 'ucs-2': | ||
91974 | case 'utf16le': | ||
91975 | case 'utf-16le': | ||
91976 | return len * 2 | ||
91977 | case 'hex': | ||
91978 | return len >>> 1 | ||
91979 | case 'base64': | ||
91980 | return base64ToBytes(string).length | ||
91981 | default: | ||
91982 | if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
91983 | encoding = ('' + encoding).toLowerCase() | ||
91984 | loweredCase = true | ||
91985 | } | ||
91986 | } | ||
91987 | } | ||
91988 | Buffer.byteLength = byteLength | ||
91989 | |||
91990 | function slowToString (encoding, start, end) { | ||
91991 | var loweredCase = false | ||
91992 | |||
91993 | // No need to verify that "this.length <= MAX_UINT32" since it's a read-only | ||
91994 | // property of a typed array. | ||
91995 | |||
91996 | // This behaves neither like String nor Uint8Array in that we set start/end | ||
91997 | // to their upper/lower bounds if the value passed is out of range. | ||
91998 | // undefined is handled specially as per ECMA-262 6th Edition, | ||
91999 | // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. | ||
92000 | if (start === undefined || start < 0) { | ||
92001 | start = 0 | ||
92002 | } | ||
92003 | // Return early if start > this.length. Done here to prevent potential uint32 | ||
92004 | // coercion fail below. | ||
92005 | if (start > this.length) { | ||
92006 | return '' | ||
92007 | } | ||
92008 | |||
92009 | if (end === undefined || end > this.length) { | ||
92010 | end = this.length | ||
92011 | } | ||
92012 | |||
92013 | if (end <= 0) { | ||
92014 | return '' | ||
92015 | } | ||
92016 | |||
92017 | // Force coersion to uint32. This will also coerce falsey/NaN values to 0. | ||
92018 | end >>>= 0 | ||
92019 | start >>>= 0 | ||
92020 | |||
92021 | if (end <= start) { | ||
92022 | return '' | ||
92023 | } | ||
92024 | |||
92025 | if (!encoding) encoding = 'utf8' | ||
92026 | |||
92027 | while (true) { | ||
92028 | switch (encoding) { | ||
92029 | case 'hex': | ||
92030 | return hexSlice(this, start, end) | ||
92031 | |||
92032 | case 'utf8': | ||
92033 | case 'utf-8': | ||
92034 | return utf8Slice(this, start, end) | ||
92035 | |||
92036 | case 'ascii': | ||
92037 | return asciiSlice(this, start, end) | ||
92038 | |||
92039 | case 'latin1': | ||
92040 | case 'binary': | ||
92041 | return latin1Slice(this, start, end) | ||
92042 | |||
92043 | case 'base64': | ||
92044 | return base64Slice(this, start, end) | ||
92045 | |||
92046 | case 'ucs2': | ||
92047 | case 'ucs-2': | ||
92048 | case 'utf16le': | ||
92049 | case 'utf-16le': | ||
92050 | return utf16leSlice(this, start, end) | ||
92051 | |||
92052 | default: | ||
92053 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
92054 | encoding = (encoding + '').toLowerCase() | ||
92055 | loweredCase = true | ||
92056 | } | ||
92057 | } | ||
92058 | } | ||
92059 | |||
92060 | // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) | ||
92061 | // to detect a Buffer instance. It's not possible to use `instanceof Buffer` | ||
92062 | // reliably in a browserify context because there could be multiple different | ||
92063 | // copies of the 'buffer' package in use. This method works even for Buffer | ||
92064 | // instances that were created from another copy of the `buffer` package. | ||
92065 | // See: https://github.com/feross/buffer/issues/154 | ||
92066 | Buffer.prototype._isBuffer = true | ||
92067 | |||
92068 | function swap (b, n, m) { | ||
92069 | var i = b[n] | ||
92070 | b[n] = b[m] | ||
92071 | b[m] = i | ||
92072 | } | ||
92073 | |||
92074 | Buffer.prototype.swap16 = function swap16 () { | ||
92075 | var len = this.length | ||
92076 | if (len % 2 !== 0) { | ||
92077 | throw new RangeError('Buffer size must be a multiple of 16-bits') | ||
92078 | } | ||
92079 | for (var i = 0; i < len; i += 2) { | ||
92080 | swap(this, i, i + 1) | ||
92081 | } | ||
92082 | return this | ||
92083 | } | ||
92084 | |||
92085 | Buffer.prototype.swap32 = function swap32 () { | ||
92086 | var len = this.length | ||
92087 | if (len % 4 !== 0) { | ||
92088 | throw new RangeError('Buffer size must be a multiple of 32-bits') | ||
92089 | } | ||
92090 | for (var i = 0; i < len; i += 4) { | ||
92091 | swap(this, i, i + 3) | ||
92092 | swap(this, i + 1, i + 2) | ||
92093 | } | ||
92094 | return this | ||
92095 | } | ||
92096 | |||
92097 | Buffer.prototype.swap64 = function swap64 () { | ||
92098 | var len = this.length | ||
92099 | if (len % 8 !== 0) { | ||
92100 | throw new RangeError('Buffer size must be a multiple of 64-bits') | ||
92101 | } | ||
92102 | for (var i = 0; i < len; i += 8) { | ||
92103 | swap(this, i, i + 7) | ||
92104 | swap(this, i + 1, i + 6) | ||
92105 | swap(this, i + 2, i + 5) | ||
92106 | swap(this, i + 3, i + 4) | ||
92107 | } | ||
92108 | return this | ||
92109 | } | ||
92110 | |||
92111 | Buffer.prototype.toString = function toString () { | ||
92112 | var length = this.length | ||
92113 | if (length === 0) return '' | ||
92114 | if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
92115 | return slowToString.apply(this, arguments) | ||
92116 | } | ||
92117 | |||
92118 | Buffer.prototype.equals = function equals (b) { | ||
92119 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
92120 | if (this === b) return true | ||
92121 | return Buffer.compare(this, b) === 0 | ||
92122 | } | ||
92123 | |||
92124 | Buffer.prototype.inspect = function inspect () { | ||
92125 | var str = '' | ||
92126 | var max = exports.INSPECT_MAX_BYTES | ||
92127 | if (this.length > 0) { | ||
92128 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
92129 | if (this.length > max) str += ' ... ' | ||
92130 | } | ||
92131 | return '<Buffer ' + str + '>' | ||
92132 | } | ||
92133 | |||
92134 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { | ||
92135 | if (!Buffer.isBuffer(target)) { | ||
92136 | throw new TypeError('Argument must be a Buffer') | ||
92137 | } | ||
92138 | |||
92139 | if (start === undefined) { | ||
92140 | start = 0 | ||
92141 | } | ||
92142 | if (end === undefined) { | ||
92143 | end = target ? target.length : 0 | ||
92144 | } | ||
92145 | if (thisStart === undefined) { | ||
92146 | thisStart = 0 | ||
92147 | } | ||
92148 | if (thisEnd === undefined) { | ||
92149 | thisEnd = this.length | ||
92150 | } | ||
92151 | |||
92152 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { | ||
92153 | throw new RangeError('out of range index') | ||
92154 | } | ||
92155 | |||
92156 | if (thisStart >= thisEnd && start >= end) { | ||
92157 | return 0 | ||
92158 | } | ||
92159 | if (thisStart >= thisEnd) { | ||
92160 | return -1 | ||
92161 | } | ||
92162 | if (start >= end) { | ||
92163 | return 1 | ||
92164 | } | ||
92165 | |||
92166 | start >>>= 0 | ||
92167 | end >>>= 0 | ||
92168 | thisStart >>>= 0 | ||
92169 | thisEnd >>>= 0 | ||
92170 | |||
92171 | if (this === target) return 0 | ||
92172 | |||
92173 | var x = thisEnd - thisStart | ||
92174 | var y = end - start | ||
92175 | var len = Math.min(x, y) | ||
92176 | |||
92177 | var thisCopy = this.slice(thisStart, thisEnd) | ||
92178 | var targetCopy = target.slice(start, end) | ||
92179 | |||
92180 | for (var i = 0; i < len; ++i) { | ||
92181 | if (thisCopy[i] !== targetCopy[i]) { | ||
92182 | x = thisCopy[i] | ||
92183 | y = targetCopy[i] | ||
92184 | break | ||
92185 | } | ||
92186 | } | ||
92187 | |||
92188 | if (x < y) return -1 | ||
92189 | if (y < x) return 1 | ||
92190 | return 0 | ||
92191 | } | ||
92192 | |||
92193 | // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, | ||
92194 | // OR the last index of `val` in `buffer` at offset <= `byteOffset`. | ||
92195 | // | ||
92196 | // Arguments: | ||
92197 | // - buffer - a Buffer to search | ||
92198 | // - val - a string, Buffer, or number | ||
92199 | // - byteOffset - an index into `buffer`; will be clamped to an int32 | ||
92200 | // - encoding - an optional encoding, relevant is val is a string | ||
92201 | // - dir - true for indexOf, false for lastIndexOf | ||
92202 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { | ||
92203 | // Empty buffer means no match | ||
92204 | if (buffer.length === 0) return -1 | ||
92205 | |||
92206 | // Normalize byteOffset | ||
92207 | if (typeof byteOffset === 'string') { | ||
92208 | encoding = byteOffset | ||
92209 | byteOffset = 0 | ||
92210 | } else if (byteOffset > 0x7fffffff) { | ||
92211 | byteOffset = 0x7fffffff | ||
92212 | } else if (byteOffset < -0x80000000) { | ||
92213 | byteOffset = -0x80000000 | ||
92214 | } | ||
92215 | byteOffset = +byteOffset // Coerce to Number. | ||
92216 | if (numberIsNaN(byteOffset)) { | ||
92217 | // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
92218 | byteOffset = dir ? 0 : (buffer.length - 1) | ||
92219 | } | ||
92220 | |||
92221 | // Normalize byteOffset: negative offsets start from the end of the buffer | ||
92222 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset | ||
92223 | if (byteOffset >= buffer.length) { | ||
92224 | if (dir) return -1 | ||
92225 | else byteOffset = buffer.length - 1 | ||
92226 | } else if (byteOffset < 0) { | ||
92227 | if (dir) byteOffset = 0 | ||
92228 | else return -1 | ||
92229 | } | ||
92230 | |||
92231 | // Normalize val | ||
92232 | if (typeof val === 'string') { | ||
92233 | val = Buffer.from(val, encoding) | ||
92234 | } | ||
92235 | |||
92236 | // Finally, search either indexOf (if dir is true) or lastIndexOf | ||
92237 | if (Buffer.isBuffer(val)) { | ||
92238 | // Special case: looking for empty string/buffer always fails | ||
92239 | if (val.length === 0) { | ||
92240 | return -1 | ||
92241 | } | ||
92242 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir) | ||
92243 | } else if (typeof val === 'number') { | ||
92244 | val = val & 0xFF // Search for a byte value [0-255] | ||
92245 | if (typeof Uint8Array.prototype.indexOf === 'function') { | ||
92246 | if (dir) { | ||
92247 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) | ||
92248 | } else { | ||
92249 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) | ||
92250 | } | ||
92251 | } | ||
92252 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) | ||
92253 | } | ||
92254 | |||
92255 | throw new TypeError('val must be string, number or Buffer') | ||
92256 | } | ||
92257 | |||
92258 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) { | ||
92259 | var indexSize = 1 | ||
92260 | var arrLength = arr.length | ||
92261 | var valLength = val.length | ||
92262 | |||
92263 | if (encoding !== undefined) { | ||
92264 | encoding = String(encoding).toLowerCase() | ||
92265 | if (encoding === 'ucs2' || encoding === 'ucs-2' || | ||
92266 | encoding === 'utf16le' || encoding === 'utf-16le') { | ||
92267 | if (arr.length < 2 || val.length < 2) { | ||
92268 | return -1 | ||
92269 | } | ||
92270 | indexSize = 2 | ||
92271 | arrLength /= 2 | ||
92272 | valLength /= 2 | ||
92273 | byteOffset /= 2 | ||
92274 | } | ||
92275 | } | ||
92276 | |||
92277 | function read (buf, i) { | ||
92278 | if (indexSize === 1) { | ||
92279 | return buf[i] | ||
92280 | } else { | ||
92281 | return buf.readUInt16BE(i * indexSize) | ||
92282 | } | ||
92283 | } | ||
92284 | |||
92285 | var i | ||
92286 | if (dir) { | ||
92287 | var foundIndex = -1 | ||
92288 | for (i = byteOffset; i < arrLength; i++) { | ||
92289 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { | ||
92290 | if (foundIndex === -1) foundIndex = i | ||
92291 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize | ||
92292 | } else { | ||
92293 | if (foundIndex !== -1) i -= i - foundIndex | ||
92294 | foundIndex = -1 | ||
92295 | } | ||
92296 | } | ||
92297 | } else { | ||
92298 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength | ||
92299 | for (i = byteOffset; i >= 0; i--) { | ||
92300 | var found = true | ||
92301 | for (var j = 0; j < valLength; j++) { | ||
92302 | if (read(arr, i + j) !== read(val, j)) { | ||
92303 | found = false | ||
92304 | break | ||
92305 | } | ||
92306 | } | ||
92307 | if (found) return i | ||
92308 | } | ||
92309 | } | ||
92310 | |||
92311 | return -1 | ||
92312 | } | ||
92313 | |||
92314 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) { | ||
92315 | return this.indexOf(val, byteOffset, encoding) !== -1 | ||
92316 | } | ||
92317 | |||
92318 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { | ||
92319 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true) | ||
92320 | } | ||
92321 | |||
92322 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { | ||
92323 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false) | ||
92324 | } | ||
92325 | |||
92326 | function hexWrite (buf, string, offset, length) { | ||
92327 | offset = Number(offset) || 0 | ||
92328 | var remaining = buf.length - offset | ||
92329 | if (!length) { | ||
92330 | length = remaining | ||
92331 | } else { | ||
92332 | length = Number(length) | ||
92333 | if (length > remaining) { | ||
92334 | length = remaining | ||
92335 | } | ||
92336 | } | ||
92337 | |||
92338 | // must be an even number of digits | ||
92339 | var strLen = string.length | ||
92340 | if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') | ||
92341 | |||
92342 | if (length > strLen / 2) { | ||
92343 | length = strLen / 2 | ||
92344 | } | ||
92345 | for (var i = 0; i < length; ++i) { | ||
92346 | var parsed = parseInt(string.substr(i * 2, 2), 16) | ||
92347 | if (numberIsNaN(parsed)) return i | ||
92348 | buf[offset + i] = parsed | ||
92349 | } | ||
92350 | return i | ||
92351 | } | ||
92352 | |||
92353 | function utf8Write (buf, string, offset, length) { | ||
92354 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | ||
92355 | } | ||
92356 | |||
92357 | function asciiWrite (buf, string, offset, length) { | ||
92358 | return blitBuffer(asciiToBytes(string), buf, offset, length) | ||
92359 | } | ||
92360 | |||
92361 | function latin1Write (buf, string, offset, length) { | ||
92362 | return asciiWrite(buf, string, offset, length) | ||
92363 | } | ||
92364 | |||
92365 | function base64Write (buf, string, offset, length) { | ||
92366 | return blitBuffer(base64ToBytes(string), buf, offset, length) | ||
92367 | } | ||
92368 | |||
92369 | function ucs2Write (buf, string, offset, length) { | ||
92370 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | ||
92371 | } | ||
92372 | |||
92373 | Buffer.prototype.write = function write (string, offset, length, encoding) { | ||
92374 | // Buffer#write(string) | ||
92375 | if (offset === undefined) { | ||
92376 | encoding = 'utf8' | ||
92377 | length = this.length | ||
92378 | offset = 0 | ||
92379 | // Buffer#write(string, encoding) | ||
92380 | } else if (length === undefined && typeof offset === 'string') { | ||
92381 | encoding = offset | ||
92382 | length = this.length | ||
92383 | offset = 0 | ||
92384 | // Buffer#write(string, offset[, length][, encoding]) | ||
92385 | } else if (isFinite(offset)) { | ||
92386 | offset = offset >>> 0 | ||
92387 | if (isFinite(length)) { | ||
92388 | length = length >>> 0 | ||
92389 | if (encoding === undefined) encoding = 'utf8' | ||
92390 | } else { | ||
92391 | encoding = length | ||
92392 | length = undefined | ||
92393 | } | ||
92394 | } else { | ||
92395 | throw new Error( | ||
92396 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported' | ||
92397 | ) | ||
92398 | } | ||
92399 | |||
92400 | var remaining = this.length - offset | ||
92401 | if (length === undefined || length > remaining) length = remaining | ||
92402 | |||
92403 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | ||
92404 | throw new RangeError('Attempt to write outside buffer bounds') | ||
92405 | } | ||
92406 | |||
92407 | if (!encoding) encoding = 'utf8' | ||
92408 | |||
92409 | var loweredCase = false | ||
92410 | for (;;) { | ||
92411 | switch (encoding) { | ||
92412 | case 'hex': | ||
92413 | return hexWrite(this, string, offset, length) | ||
92414 | |||
92415 | case 'utf8': | ||
92416 | case 'utf-8': | ||
92417 | return utf8Write(this, string, offset, length) | ||
92418 | |||
92419 | case 'ascii': | ||
92420 | return asciiWrite(this, string, offset, length) | ||
92421 | |||
92422 | case 'latin1': | ||
92423 | case 'binary': | ||
92424 | return latin1Write(this, string, offset, length) | ||
92425 | |||
92426 | case 'base64': | ||
92427 | // Warning: maxLength not taken into account in base64Write | ||
92428 | return base64Write(this, string, offset, length) | ||
92429 | |||
92430 | case 'ucs2': | ||
92431 | case 'ucs-2': | ||
92432 | case 'utf16le': | ||
92433 | case 'utf-16le': | ||
92434 | return ucs2Write(this, string, offset, length) | ||
92435 | |||
92436 | default: | ||
92437 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
92438 | encoding = ('' + encoding).toLowerCase() | ||
92439 | loweredCase = true | ||
92440 | } | ||
92441 | } | ||
92442 | } | ||
92443 | |||
92444 | Buffer.prototype.toJSON = function toJSON () { | ||
92445 | return { | ||
92446 | type: 'Buffer', | ||
92447 | data: Array.prototype.slice.call(this._arr || this, 0) | ||
92448 | } | ||
92449 | } | ||
92450 | |||
92451 | function base64Slice (buf, start, end) { | ||
92452 | if (start === 0 && end === buf.length) { | ||
92453 | return base64.fromByteArray(buf) | ||
92454 | } else { | ||
92455 | return base64.fromByteArray(buf.slice(start, end)) | ||
92456 | } | ||
92457 | } | ||
92458 | |||
92459 | function utf8Slice (buf, start, end) { | ||
92460 | end = Math.min(buf.length, end) | ||
92461 | var res = [] | ||
92462 | |||
92463 | var i = start | ||
92464 | while (i < end) { | ||
92465 | var firstByte = buf[i] | ||
92466 | var codePoint = null | ||
92467 | var bytesPerSequence = (firstByte > 0xEF) ? 4 | ||
92468 | : (firstByte > 0xDF) ? 3 | ||
92469 | : (firstByte > 0xBF) ? 2 | ||
92470 | : 1 | ||
92471 | |||
92472 | if (i + bytesPerSequence <= end) { | ||
92473 | var secondByte, thirdByte, fourthByte, tempCodePoint | ||
92474 | |||
92475 | switch (bytesPerSequence) { | ||
92476 | case 1: | ||
92477 | if (firstByte < 0x80) { | ||
92478 | codePoint = firstByte | ||
92479 | } | ||
92480 | break | ||
92481 | case 2: | ||
92482 | secondByte = buf[i + 1] | ||
92483 | if ((secondByte & 0xC0) === 0x80) { | ||
92484 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | ||
92485 | if (tempCodePoint > 0x7F) { | ||
92486 | codePoint = tempCodePoint | ||
92487 | } | ||
92488 | } | ||
92489 | break | ||
92490 | case 3: | ||
92491 | secondByte = buf[i + 1] | ||
92492 | thirdByte = buf[i + 2] | ||
92493 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | ||
92494 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | ||
92495 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | ||
92496 | codePoint = tempCodePoint | ||
92497 | } | ||
92498 | } | ||
92499 | break | ||
92500 | case 4: | ||
92501 | secondByte = buf[i + 1] | ||
92502 | thirdByte = buf[i + 2] | ||
92503 | fourthByte = buf[i + 3] | ||
92504 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | ||
92505 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | ||
92506 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | ||
92507 | codePoint = tempCodePoint | ||
92508 | } | ||
92509 | } | ||
92510 | } | ||
92511 | } | ||
92512 | |||
92513 | if (codePoint === null) { | ||
92514 | // we did not generate a valid codePoint so insert a | ||
92515 | // replacement char (U+FFFD) and advance only 1 byte | ||
92516 | codePoint = 0xFFFD | ||
92517 | bytesPerSequence = 1 | ||
92518 | } else if (codePoint > 0xFFFF) { | ||
92519 | // encode to utf16 (surrogate pair dance) | ||
92520 | codePoint -= 0x10000 | ||
92521 | res.push(codePoint >>> 10 & 0x3FF | 0xD800) | ||
92522 | codePoint = 0xDC00 | codePoint & 0x3FF | ||
92523 | } | ||
92524 | |||
92525 | res.push(codePoint) | ||
92526 | i += bytesPerSequence | ||
92527 | } | ||
92528 | |||
92529 | return decodeCodePointsArray(res) | ||
92530 | } | ||
92531 | |||
92532 | // Based on http://stackoverflow.com/a/22747272/680742, the browser with | ||
92533 | // the lowest limit is Chrome, with 0x10000 args. | ||
92534 | // We go 1 magnitude less, for safety | ||
92535 | var MAX_ARGUMENTS_LENGTH = 0x1000 | ||
92536 | |||
92537 | function decodeCodePointsArray (codePoints) { | ||
92538 | var len = codePoints.length | ||
92539 | if (len <= MAX_ARGUMENTS_LENGTH) { | ||
92540 | return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | ||
92541 | } | ||
92542 | |||
92543 | // Decode in chunks to avoid "call stack size exceeded". | ||
92544 | var res = '' | ||
92545 | var i = 0 | ||
92546 | while (i < len) { | ||
92547 | res += String.fromCharCode.apply( | ||
92548 | String, | ||
92549 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | ||
92550 | ) | ||
92551 | } | ||
92552 | return res | ||
92553 | } | ||
92554 | |||
92555 | function asciiSlice (buf, start, end) { | ||
92556 | var ret = '' | ||
92557 | end = Math.min(buf.length, end) | ||
92558 | |||
92559 | for (var i = start; i < end; ++i) { | ||
92560 | ret += String.fromCharCode(buf[i] & 0x7F) | ||
92561 | } | ||
92562 | return ret | ||
92563 | } | ||
92564 | |||
92565 | function latin1Slice (buf, start, end) { | ||
92566 | var ret = '' | ||
92567 | end = Math.min(buf.length, end) | ||
92568 | |||
92569 | for (var i = start; i < end; ++i) { | ||
92570 | ret += String.fromCharCode(buf[i]) | ||
92571 | } | ||
92572 | return ret | ||
92573 | } | ||
92574 | |||
92575 | function hexSlice (buf, start, end) { | ||
92576 | var len = buf.length | ||
92577 | |||
92578 | if (!start || start < 0) start = 0 | ||
92579 | if (!end || end < 0 || end > len) end = len | ||
92580 | |||
92581 | var out = '' | ||
92582 | for (var i = start; i < end; ++i) { | ||
92583 | out += toHex(buf[i]) | ||
92584 | } | ||
92585 | return out | ||
92586 | } | ||
92587 | |||
92588 | function utf16leSlice (buf, start, end) { | ||
92589 | var bytes = buf.slice(start, end) | ||
92590 | var res = '' | ||
92591 | for (var i = 0; i < bytes.length; i += 2) { | ||
92592 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) | ||
92593 | } | ||
92594 | return res | ||
92595 | } | ||
92596 | |||
92597 | Buffer.prototype.slice = function slice (start, end) { | ||
92598 | var len = this.length | ||
92599 | start = ~~start | ||
92600 | end = end === undefined ? len : ~~end | ||
92601 | |||
92602 | if (start < 0) { | ||
92603 | start += len | ||
92604 | if (start < 0) start = 0 | ||
92605 | } else if (start > len) { | ||
92606 | start = len | ||
92607 | } | ||
92608 | |||
92609 | if (end < 0) { | ||
92610 | end += len | ||
92611 | if (end < 0) end = 0 | ||
92612 | } else if (end > len) { | ||
92613 | end = len | ||
92614 | } | ||
92615 | |||
92616 | if (end < start) end = start | ||
92617 | |||
92618 | var newBuf = this.subarray(start, end) | ||
92619 | // Return an augmented `Uint8Array` instance | ||
92620 | newBuf.__proto__ = Buffer.prototype | ||
92621 | return newBuf | ||
92622 | } | ||
92623 | |||
92624 | /* | ||
92625 | * Need to make sure that buffer isn't trying to write out of bounds. | ||
92626 | */ | ||
92627 | function checkOffset (offset, ext, length) { | ||
92628 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | ||
92629 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | ||
92630 | } | ||
92631 | |||
92632 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { | ||
92633 | offset = offset >>> 0 | ||
92634 | byteLength = byteLength >>> 0 | ||
92635 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
92636 | |||
92637 | var val = this[offset] | ||
92638 | var mul = 1 | ||
92639 | var i = 0 | ||
92640 | while (++i < byteLength && (mul *= 0x100)) { | ||
92641 | val += this[offset + i] * mul | ||
92642 | } | ||
92643 | |||
92644 | return val | ||
92645 | } | ||
92646 | |||
92647 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { | ||
92648 | offset = offset >>> 0 | ||
92649 | byteLength = byteLength >>> 0 | ||
92650 | if (!noAssert) { | ||
92651 | checkOffset(offset, byteLength, this.length) | ||
92652 | } | ||
92653 | |||
92654 | var val = this[offset + --byteLength] | ||
92655 | var mul = 1 | ||
92656 | while (byteLength > 0 && (mul *= 0x100)) { | ||
92657 | val += this[offset + --byteLength] * mul | ||
92658 | } | ||
92659 | |||
92660 | return val | ||
92661 | } | ||
92662 | |||
92663 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { | ||
92664 | offset = offset >>> 0 | ||
92665 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
92666 | return this[offset] | ||
92667 | } | ||
92668 | |||
92669 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { | ||
92670 | offset = offset >>> 0 | ||
92671 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
92672 | return this[offset] | (this[offset + 1] << 8) | ||
92673 | } | ||
92674 | |||
92675 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { | ||
92676 | offset = offset >>> 0 | ||
92677 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
92678 | return (this[offset] << 8) | this[offset + 1] | ||
92679 | } | ||
92680 | |||
92681 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { | ||
92682 | offset = offset >>> 0 | ||
92683 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92684 | |||
92685 | return ((this[offset]) | | ||
92686 | (this[offset + 1] << 8) | | ||
92687 | (this[offset + 2] << 16)) + | ||
92688 | (this[offset + 3] * 0x1000000) | ||
92689 | } | ||
92690 | |||
92691 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { | ||
92692 | offset = offset >>> 0 | ||
92693 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92694 | |||
92695 | return (this[offset] * 0x1000000) + | ||
92696 | ((this[offset + 1] << 16) | | ||
92697 | (this[offset + 2] << 8) | | ||
92698 | this[offset + 3]) | ||
92699 | } | ||
92700 | |||
92701 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { | ||
92702 | offset = offset >>> 0 | ||
92703 | byteLength = byteLength >>> 0 | ||
92704 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
92705 | |||
92706 | var val = this[offset] | ||
92707 | var mul = 1 | ||
92708 | var i = 0 | ||
92709 | while (++i < byteLength && (mul *= 0x100)) { | ||
92710 | val += this[offset + i] * mul | ||
92711 | } | ||
92712 | mul *= 0x80 | ||
92713 | |||
92714 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
92715 | |||
92716 | return val | ||
92717 | } | ||
92718 | |||
92719 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { | ||
92720 | offset = offset >>> 0 | ||
92721 | byteLength = byteLength >>> 0 | ||
92722 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
92723 | |||
92724 | var i = byteLength | ||
92725 | var mul = 1 | ||
92726 | var val = this[offset + --i] | ||
92727 | while (i > 0 && (mul *= 0x100)) { | ||
92728 | val += this[offset + --i] * mul | ||
92729 | } | ||
92730 | mul *= 0x80 | ||
92731 | |||
92732 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
92733 | |||
92734 | return val | ||
92735 | } | ||
92736 | |||
92737 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { | ||
92738 | offset = offset >>> 0 | ||
92739 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
92740 | if (!(this[offset] & 0x80)) return (this[offset]) | ||
92741 | return ((0xff - this[offset] + 1) * -1) | ||
92742 | } | ||
92743 | |||
92744 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { | ||
92745 | offset = offset >>> 0 | ||
92746 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
92747 | var val = this[offset] | (this[offset + 1] << 8) | ||
92748 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
92749 | } | ||
92750 | |||
92751 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { | ||
92752 | offset = offset >>> 0 | ||
92753 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
92754 | var val = this[offset + 1] | (this[offset] << 8) | ||
92755 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
92756 | } | ||
92757 | |||
92758 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { | ||
92759 | offset = offset >>> 0 | ||
92760 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92761 | |||
92762 | return (this[offset]) | | ||
92763 | (this[offset + 1] << 8) | | ||
92764 | (this[offset + 2] << 16) | | ||
92765 | (this[offset + 3] << 24) | ||
92766 | } | ||
92767 | |||
92768 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { | ||
92769 | offset = offset >>> 0 | ||
92770 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92771 | |||
92772 | return (this[offset] << 24) | | ||
92773 | (this[offset + 1] << 16) | | ||
92774 | (this[offset + 2] << 8) | | ||
92775 | (this[offset + 3]) | ||
92776 | } | ||
92777 | |||
92778 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { | ||
92779 | offset = offset >>> 0 | ||
92780 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92781 | return ieee754.read(this, offset, true, 23, 4) | ||
92782 | } | ||
92783 | |||
92784 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { | ||
92785 | offset = offset >>> 0 | ||
92786 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
92787 | return ieee754.read(this, offset, false, 23, 4) | ||
92788 | } | ||
92789 | |||
92790 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { | ||
92791 | offset = offset >>> 0 | ||
92792 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
92793 | return ieee754.read(this, offset, true, 52, 8) | ||
92794 | } | ||
92795 | |||
92796 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { | ||
92797 | offset = offset >>> 0 | ||
92798 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
92799 | return ieee754.read(this, offset, false, 52, 8) | ||
92800 | } | ||
92801 | |||
92802 | function checkInt (buf, value, offset, ext, max, min) { | ||
92803 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') | ||
92804 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') | ||
92805 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
92806 | } | ||
92807 | |||
92808 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { | ||
92809 | value = +value | ||
92810 | offset = offset >>> 0 | ||
92811 | byteLength = byteLength >>> 0 | ||
92812 | if (!noAssert) { | ||
92813 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
92814 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
92815 | } | ||
92816 | |||
92817 | var mul = 1 | ||
92818 | var i = 0 | ||
92819 | this[offset] = value & 0xFF | ||
92820 | while (++i < byteLength && (mul *= 0x100)) { | ||
92821 | this[offset + i] = (value / mul) & 0xFF | ||
92822 | } | ||
92823 | |||
92824 | return offset + byteLength | ||
92825 | } | ||
92826 | |||
92827 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { | ||
92828 | value = +value | ||
92829 | offset = offset >>> 0 | ||
92830 | byteLength = byteLength >>> 0 | ||
92831 | if (!noAssert) { | ||
92832 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
92833 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
92834 | } | ||
92835 | |||
92836 | var i = byteLength - 1 | ||
92837 | var mul = 1 | ||
92838 | this[offset + i] = value & 0xFF | ||
92839 | while (--i >= 0 && (mul *= 0x100)) { | ||
92840 | this[offset + i] = (value / mul) & 0xFF | ||
92841 | } | ||
92842 | |||
92843 | return offset + byteLength | ||
92844 | } | ||
92845 | |||
92846 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { | ||
92847 | value = +value | ||
92848 | offset = offset >>> 0 | ||
92849 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | ||
92850 | this[offset] = (value & 0xff) | ||
92851 | return offset + 1 | ||
92852 | } | ||
92853 | |||
92854 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { | ||
92855 | value = +value | ||
92856 | offset = offset >>> 0 | ||
92857 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
92858 | this[offset] = (value & 0xff) | ||
92859 | this[offset + 1] = (value >>> 8) | ||
92860 | return offset + 2 | ||
92861 | } | ||
92862 | |||
92863 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { | ||
92864 | value = +value | ||
92865 | offset = offset >>> 0 | ||
92866 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
92867 | this[offset] = (value >>> 8) | ||
92868 | this[offset + 1] = (value & 0xff) | ||
92869 | return offset + 2 | ||
92870 | } | ||
92871 | |||
92872 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { | ||
92873 | value = +value | ||
92874 | offset = offset >>> 0 | ||
92875 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
92876 | this[offset + 3] = (value >>> 24) | ||
92877 | this[offset + 2] = (value >>> 16) | ||
92878 | this[offset + 1] = (value >>> 8) | ||
92879 | this[offset] = (value & 0xff) | ||
92880 | return offset + 4 | ||
92881 | } | ||
92882 | |||
92883 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { | ||
92884 | value = +value | ||
92885 | offset = offset >>> 0 | ||
92886 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
92887 | this[offset] = (value >>> 24) | ||
92888 | this[offset + 1] = (value >>> 16) | ||
92889 | this[offset + 2] = (value >>> 8) | ||
92890 | this[offset + 3] = (value & 0xff) | ||
92891 | return offset + 4 | ||
92892 | } | ||
92893 | |||
92894 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { | ||
92895 | value = +value | ||
92896 | offset = offset >>> 0 | ||
92897 | if (!noAssert) { | ||
92898 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
92899 | |||
92900 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
92901 | } | ||
92902 | |||
92903 | var i = 0 | ||
92904 | var mul = 1 | ||
92905 | var sub = 0 | ||
92906 | this[offset] = value & 0xFF | ||
92907 | while (++i < byteLength && (mul *= 0x100)) { | ||
92908 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | ||
92909 | sub = 1 | ||
92910 | } | ||
92911 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
92912 | } | ||
92913 | |||
92914 | return offset + byteLength | ||
92915 | } | ||
92916 | |||
92917 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { | ||
92918 | value = +value | ||
92919 | offset = offset >>> 0 | ||
92920 | if (!noAssert) { | ||
92921 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
92922 | |||
92923 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
92924 | } | ||
92925 | |||
92926 | var i = byteLength - 1 | ||
92927 | var mul = 1 | ||
92928 | var sub = 0 | ||
92929 | this[offset + i] = value & 0xFF | ||
92930 | while (--i >= 0 && (mul *= 0x100)) { | ||
92931 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | ||
92932 | sub = 1 | ||
92933 | } | ||
92934 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
92935 | } | ||
92936 | |||
92937 | return offset + byteLength | ||
92938 | } | ||
92939 | |||
92940 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { | ||
92941 | value = +value | ||
92942 | offset = offset >>> 0 | ||
92943 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | ||
92944 | if (value < 0) value = 0xff + value + 1 | ||
92945 | this[offset] = (value & 0xff) | ||
92946 | return offset + 1 | ||
92947 | } | ||
92948 | |||
92949 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { | ||
92950 | value = +value | ||
92951 | offset = offset >>> 0 | ||
92952 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
92953 | this[offset] = (value & 0xff) | ||
92954 | this[offset + 1] = (value >>> 8) | ||
92955 | return offset + 2 | ||
92956 | } | ||
92957 | |||
92958 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { | ||
92959 | value = +value | ||
92960 | offset = offset >>> 0 | ||
92961 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
92962 | this[offset] = (value >>> 8) | ||
92963 | this[offset + 1] = (value & 0xff) | ||
92964 | return offset + 2 | ||
92965 | } | ||
92966 | |||
92967 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { | ||
92968 | value = +value | ||
92969 | offset = offset >>> 0 | ||
92970 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
92971 | this[offset] = (value & 0xff) | ||
92972 | this[offset + 1] = (value >>> 8) | ||
92973 | this[offset + 2] = (value >>> 16) | ||
92974 | this[offset + 3] = (value >>> 24) | ||
92975 | return offset + 4 | ||
92976 | } | ||
92977 | |||
92978 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { | ||
92979 | value = +value | ||
92980 | offset = offset >>> 0 | ||
92981 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
92982 | if (value < 0) value = 0xffffffff + value + 1 | ||
92983 | this[offset] = (value >>> 24) | ||
92984 | this[offset + 1] = (value >>> 16) | ||
92985 | this[offset + 2] = (value >>> 8) | ||
92986 | this[offset + 3] = (value & 0xff) | ||
92987 | return offset + 4 | ||
92988 | } | ||
92989 | |||
92990 | function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
92991 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
92992 | if (offset < 0) throw new RangeError('Index out of range') | ||
92993 | } | ||
92994 | |||
92995 | function writeFloat (buf, value, offset, littleEndian, noAssert) { | ||
92996 | value = +value | ||
92997 | offset = offset >>> 0 | ||
92998 | if (!noAssert) { | ||
92999 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | ||
93000 | } | ||
93001 | ieee754.write(buf, value, offset, littleEndian, 23, 4) | ||
93002 | return offset + 4 | ||
93003 | } | ||
93004 | |||
93005 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { | ||
93006 | return writeFloat(this, value, offset, true, noAssert) | ||
93007 | } | ||
93008 | |||
93009 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { | ||
93010 | return writeFloat(this, value, offset, false, noAssert) | ||
93011 | } | ||
93012 | |||
93013 | function writeDouble (buf, value, offset, littleEndian, noAssert) { | ||
93014 | value = +value | ||
93015 | offset = offset >>> 0 | ||
93016 | if (!noAssert) { | ||
93017 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | ||
93018 | } | ||
93019 | ieee754.write(buf, value, offset, littleEndian, 52, 8) | ||
93020 | return offset + 8 | ||
93021 | } | ||
93022 | |||
93023 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { | ||
93024 | return writeDouble(this, value, offset, true, noAssert) | ||
93025 | } | ||
93026 | |||
93027 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { | ||
93028 | return writeDouble(this, value, offset, false, noAssert) | ||
93029 | } | ||
93030 | |||
93031 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
93032 | Buffer.prototype.copy = function copy (target, targetStart, start, end) { | ||
93033 | if (!start) start = 0 | ||
93034 | if (!end && end !== 0) end = this.length | ||
93035 | if (targetStart >= target.length) targetStart = target.length | ||
93036 | if (!targetStart) targetStart = 0 | ||
93037 | if (end > 0 && end < start) end = start | ||
93038 | |||
93039 | // Copy 0 bytes; we're done | ||
93040 | if (end === start) return 0 | ||
93041 | if (target.length === 0 || this.length === 0) return 0 | ||
93042 | |||
93043 | // Fatal error conditions | ||
93044 | if (targetStart < 0) { | ||
93045 | throw new RangeError('targetStart out of bounds') | ||
93046 | } | ||
93047 | if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') | ||
93048 | if (end < 0) throw new RangeError('sourceEnd out of bounds') | ||
93049 | |||
93050 | // Are we oob? | ||
93051 | if (end > this.length) end = this.length | ||
93052 | if (target.length - targetStart < end - start) { | ||
93053 | end = target.length - targetStart + start | ||
93054 | } | ||
93055 | |||
93056 | var len = end - start | ||
93057 | var i | ||
93058 | |||
93059 | if (this === target && start < targetStart && targetStart < end) { | ||
93060 | // descending copy from end | ||
93061 | for (i = len - 1; i >= 0; --i) { | ||
93062 | target[i + targetStart] = this[i + start] | ||
93063 | } | ||
93064 | } else if (len < 1000) { | ||
93065 | // ascending copy from start | ||
93066 | for (i = 0; i < len; ++i) { | ||
93067 | target[i + targetStart] = this[i + start] | ||
93068 | } | ||
93069 | } else { | ||
93070 | Uint8Array.prototype.set.call( | ||
93071 | target, | ||
93072 | this.subarray(start, start + len), | ||
93073 | targetStart | ||
93074 | ) | ||
93075 | } | ||
93076 | |||
93077 | return len | ||
93078 | } | ||
93079 | |||
93080 | // Usage: | ||
93081 | // buffer.fill(number[, offset[, end]]) | ||
93082 | // buffer.fill(buffer[, offset[, end]]) | ||
93083 | // buffer.fill(string[, offset[, end]][, encoding]) | ||
93084 | Buffer.prototype.fill = function fill (val, start, end, encoding) { | ||
93085 | // Handle string cases: | ||
93086 | if (typeof val === 'string') { | ||
93087 | if (typeof start === 'string') { | ||
93088 | encoding = start | ||
93089 | start = 0 | ||
93090 | end = this.length | ||
93091 | } else if (typeof end === 'string') { | ||
93092 | encoding = end | ||
93093 | end = this.length | ||
93094 | } | ||
93095 | if (val.length === 1) { | ||
93096 | var code = val.charCodeAt(0) | ||
93097 | if (code < 256) { | ||
93098 | val = code | ||
93099 | } | ||
93100 | } | ||
93101 | if (encoding !== undefined && typeof encoding !== 'string') { | ||
93102 | throw new TypeError('encoding must be a string') | ||
93103 | } | ||
93104 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { | ||
93105 | throw new TypeError('Unknown encoding: ' + encoding) | ||
93106 | } | ||
93107 | } else if (typeof val === 'number') { | ||
93108 | val = val & 255 | ||
93109 | } | ||
93110 | |||
93111 | // Invalid ranges are not set to a default, so can range check early. | ||
93112 | if (start < 0 || this.length < start || this.length < end) { | ||
93113 | throw new RangeError('Out of range index') | ||
93114 | } | ||
93115 | |||
93116 | if (end <= start) { | ||
93117 | return this | ||
93118 | } | ||
93119 | |||
93120 | start = start >>> 0 | ||
93121 | end = end === undefined ? this.length : end >>> 0 | ||
93122 | |||
93123 | if (!val) val = 0 | ||
93124 | |||
93125 | var i | ||
93126 | if (typeof val === 'number') { | ||
93127 | for (i = start; i < end; ++i) { | ||
93128 | this[i] = val | ||
93129 | } | ||
93130 | } else { | ||
93131 | var bytes = Buffer.isBuffer(val) | ||
93132 | ? val | ||
93133 | : new Buffer(val, encoding) | ||
93134 | var len = bytes.length | ||
93135 | for (i = 0; i < end - start; ++i) { | ||
93136 | this[i + start] = bytes[i % len] | ||
93137 | } | ||
93138 | } | ||
93139 | |||
93140 | return this | ||
93141 | } | ||
93142 | |||
93143 | // HELPER FUNCTIONS | ||
93144 | // ================ | ||
93145 | |||
93146 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g | ||
93147 | |||
93148 | function base64clean (str) { | ||
93149 | // Node strips out invalid characters like \n and \t from the string, base64-js does not | ||
93150 | str = str.trim().replace(INVALID_BASE64_RE, '') | ||
93151 | // Node converts strings with length < 2 to '' | ||
93152 | if (str.length < 2) return '' | ||
93153 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | ||
93154 | while (str.length % 4 !== 0) { | ||
93155 | str = str + '=' | ||
93156 | } | ||
93157 | return str | ||
93158 | } | ||
93159 | |||
93160 | function toHex (n) { | ||
93161 | if (n < 16) return '0' + n.toString(16) | ||
93162 | return n.toString(16) | ||
93163 | } | ||
93164 | |||
93165 | function utf8ToBytes (string, units) { | ||
93166 | units = units || Infinity | ||
93167 | var codePoint | ||
93168 | var length = string.length | ||
93169 | var leadSurrogate = null | ||
93170 | var bytes = [] | ||
93171 | |||
93172 | for (var i = 0; i < length; ++i) { | ||
93173 | codePoint = string.charCodeAt(i) | ||
93174 | |||
93175 | // is surrogate component | ||
93176 | if (codePoint > 0xD7FF && codePoint < 0xE000) { | ||
93177 | // last char was a lead | ||
93178 | if (!leadSurrogate) { | ||
93179 | // no lead yet | ||
93180 | if (codePoint > 0xDBFF) { | ||
93181 | // unexpected trail | ||
93182 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
93183 | continue | ||
93184 | } else if (i + 1 === length) { | ||
93185 | // unpaired lead | ||
93186 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
93187 | continue | ||
93188 | } | ||
93189 | |||
93190 | // valid lead | ||
93191 | leadSurrogate = codePoint | ||
93192 | |||
93193 | continue | ||
93194 | } | ||
93195 | |||
93196 | // 2 leads in a row | ||
93197 | if (codePoint < 0xDC00) { | ||
93198 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
93199 | leadSurrogate = codePoint | ||
93200 | continue | ||
93201 | } | ||
93202 | |||
93203 | // valid surrogate pair | ||
93204 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 | ||
93205 | } else if (leadSurrogate) { | ||
93206 | // valid bmp char, but last char was a lead | ||
93207 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
93208 | } | ||
93209 | |||
93210 | leadSurrogate = null | ||
93211 | |||
93212 | // encode utf8 | ||
93213 | if (codePoint < 0x80) { | ||
93214 | if ((units -= 1) < 0) break | ||
93215 | bytes.push(codePoint) | ||
93216 | } else if (codePoint < 0x800) { | ||
93217 | if ((units -= 2) < 0) break | ||
93218 | bytes.push( | ||
93219 | codePoint >> 0x6 | 0xC0, | ||
93220 | codePoint & 0x3F | 0x80 | ||
93221 | ) | ||
93222 | } else if (codePoint < 0x10000) { | ||
93223 | if ((units -= 3) < 0) break | ||
93224 | bytes.push( | ||
93225 | codePoint >> 0xC | 0xE0, | ||
93226 | codePoint >> 0x6 & 0x3F | 0x80, | ||
93227 | codePoint & 0x3F | 0x80 | ||
93228 | ) | ||
93229 | } else if (codePoint < 0x110000) { | ||
93230 | if ((units -= 4) < 0) break | ||
93231 | bytes.push( | ||
93232 | codePoint >> 0x12 | 0xF0, | ||
93233 | codePoint >> 0xC & 0x3F | 0x80, | ||
93234 | codePoint >> 0x6 & 0x3F | 0x80, | ||
93235 | codePoint & 0x3F | 0x80 | ||
93236 | ) | ||
93237 | } else { | ||
93238 | throw new Error('Invalid code point') | ||
93239 | } | ||
93240 | } | ||
93241 | |||
93242 | return bytes | ||
93243 | } | ||
93244 | |||
93245 | function asciiToBytes (str) { | ||
93246 | var byteArray = [] | ||
93247 | for (var i = 0; i < str.length; ++i) { | ||
93248 | // Node's code seems to be doing this and not & 0x7F.. | ||
93249 | byteArray.push(str.charCodeAt(i) & 0xFF) | ||
93250 | } | ||
93251 | return byteArray | ||
93252 | } | ||
93253 | |||
93254 | function utf16leToBytes (str, units) { | ||
93255 | var c, hi, lo | ||
93256 | var byteArray = [] | ||
93257 | for (var i = 0; i < str.length; ++i) { | ||
93258 | if ((units -= 2) < 0) break | ||
93259 | |||
93260 | c = str.charCodeAt(i) | ||
93261 | hi = c >> 8 | ||
93262 | lo = c % 256 | ||
93263 | byteArray.push(lo) | ||
93264 | byteArray.push(hi) | ||
93265 | } | ||
93266 | |||
93267 | return byteArray | ||
93268 | } | ||
93269 | |||
93270 | function base64ToBytes (str) { | ||
93271 | return base64.toByteArray(base64clean(str)) | ||
93272 | } | ||
93273 | |||
93274 | function blitBuffer (src, dst, offset, length) { | ||
93275 | for (var i = 0; i < length; ++i) { | ||
93276 | if ((i + offset >= dst.length) || (i >= src.length)) break | ||
93277 | dst[i + offset] = src[i] | ||
93278 | } | ||
93279 | return i | ||
93280 | } | ||
93281 | |||
93282 | // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check | ||
93283 | // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166 | ||
93284 | function isArrayBuffer (obj) { | ||
93285 | return obj instanceof ArrayBuffer || | ||
93286 | (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' && | ||
93287 | typeof obj.byteLength === 'number') | ||
93288 | } | ||
93289 | |||
93290 | // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView` | ||
93291 | function isArrayBufferView (obj) { | ||
93292 | return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj) | ||
93293 | } | ||
93294 | |||
93295 | function numberIsNaN (obj) { | ||
93296 | return obj !== obj // eslint-disable-line no-self-compare | ||
93297 | } | ||
93298 | |||
93299 | },{"base64-js":2,"ieee754":20}],9:[function(require,module,exports){ | ||
93300 | /** | ||
93301 | * @license | ||
93302 | * https://github.com/bitcoincashjs/cashaddr | ||
93303 | * Copyright (c) 2017-2018 Emilio Almansi | ||
93304 | * Distributed under the MIT software license, see the accompanying | ||
93305 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. | ||
93306 | */ | ||
93307 | |||
93308 | 'use strict'; | ||
93309 | |||
93310 | var validate = require('./validation').validate; | ||
93311 | |||
93312 | /** | ||
93313 | * Base32 encoding and decoding. | ||
93314 | * | ||
93315 | * @module base32 | ||
93316 | */ | ||
93317 | |||
93318 | /** | ||
93319 | * Charset containing the 32 symbols used in the base32 encoding. | ||
93320 | * @private | ||
93321 | */ | ||
93322 | var CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'; | ||
93323 | |||
93324 | /** | ||
93325 | * Inverted index mapping each symbol into its index within the charset. | ||
93326 | * @private | ||
93327 | */ | ||
93328 | var CHARSET_INVERSE_INDEX = { | ||
93329 | 'q': 0, 'p': 1, 'z': 2, 'r': 3, 'y': 4, '9': 5, 'x': 6, '8': 7, | ||
93330 | 'g': 8, 'f': 9, '2': 10, 't': 11, 'v': 12, 'd': 13, 'w': 14, '0': 15, | ||
93331 | 's': 16, '3': 17, 'j': 18, 'n': 19, '5': 20, '4': 21, 'k': 22, 'h': 23, | ||
93332 | 'c': 24, 'e': 25, '6': 26, 'm': 27, 'u': 28, 'a': 29, '7': 30, 'l': 31, | ||
93333 | }; | ||
93334 | |||
93335 | /** | ||
93336 | * Encodes the given array of 5-bit integers as a base32-encoded string. | ||
93337 | * | ||
93338 | * @static | ||
93339 | * @param {Uint8Array} data Array of integers between 0 and 31 inclusive. | ||
93340 | * @returns {string} | ||
93341 | * @throws {ValidationError} | ||
93342 | */ | ||
93343 | function encode(data) { | ||
93344 | validate(data instanceof Uint8Array, 'Invalid data: ' + data + '.'); | ||
93345 | var base32 = ''; | ||
93346 | for (var i = 0; i < data.length; ++i) { | ||
93347 | var value = data[i]; | ||
93348 | validate(0 <= value && value < 32, 'Invalid value: ' + value + '.'); | ||
93349 | base32 += CHARSET[value]; | ||
93350 | } | ||
93351 | return base32; | ||
93352 | } | ||
93353 | |||
93354 | /** | ||
93355 | * Decodes the given base32-encoded string into an array of 5-bit integers. | ||
93356 | * | ||
93357 | * @static | ||
93358 | * @param {string} string | ||
93359 | * @returns {Uint8Array} | ||
93360 | * @throws {ValidationError} | ||
93361 | */ | ||
93362 | function decode(string) { | ||
93363 | validate(typeof string === 'string', 'Invalid base32-encoded string: ' + string + '.'); | ||
93364 | var data = new Uint8Array(string.length); | ||
93365 | for (var i = 0; i < string.length; ++i) { | ||
93366 | var value = string[i]; | ||
93367 | validate(value in CHARSET_INVERSE_INDEX, 'Invalid value: ' + value + '.'); | ||
93368 | data[i] = CHARSET_INVERSE_INDEX[value]; | ||
93369 | } | ||
93370 | return data; | ||
93371 | } | ||
93372 | |||
93373 | module.exports = { | ||
93374 | encode: encode, | ||
93375 | decode: decode, | ||
93376 | }; | ||
93377 | |||
93378 | },{"./validation":12}],10:[function(require,module,exports){ | ||
93379 | /** | ||
93380 | * @license | ||
93381 | * https://github.com/bitcoincashjs/cashaddr | ||
93382 | * Copyright (c) 2017-2018 Emilio Almansi | ||
93383 | * Distributed under the MIT software license, see the accompanying | ||
93384 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. | ||
93385 | */ | ||
93386 | |||
93387 | 'use strict'; | ||
93388 | |||
93389 | var base32 = require('./base32'); | ||
93390 | var bigInt = require('big-integer'); | ||
93391 | var convertBits = require('./convertBits'); | ||
93392 | var validation = require('./validation'); | ||
93393 | var validate = validation.validate; | ||
93394 | |||
93395 | /** | ||
93396 | * Encoding and decoding of the new Cash Address format for Bitcoin Cash. <br /> | ||
93397 | * Compliant with the original cashaddr specification: | ||
93398 | * {@link https://github.com/Bitcoin-UAHF/spec/blob/master/cashaddr.md} | ||
93399 | * @module cashaddr | ||
93400 | */ | ||
93401 | |||
93402 | /** | ||
93403 | * Encodes a hash from a given type into a Bitcoin Cash address with the given prefix. | ||
93404 | * | ||
93405 | * @static | ||
93406 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | ||
93407 | * @param {string} type Type of address to generate. Either 'P2PKH' or 'P2SH'. | ||
93408 | * @param {Uint8Array} hash Hash to encode represented as an array of 8-bit integers. | ||
93409 | * @returns {string} | ||
93410 | * @throws {ValidationError} | ||
93411 | */ | ||
93412 | function encode(prefix, type, hash) { | ||
93413 | validate(typeof prefix === 'string' && isValidPrefix(prefix), 'Invalid prefix: ' + prefix + '.'); | ||
93414 | validate(typeof type === 'string', 'Invalid type: ' + type + '.'); | ||
93415 | validate(hash instanceof Uint8Array, 'Invalid hash: ' + hash + '.'); | ||
93416 | var prefixData = concat(prefixToUint5Array(prefix), new Uint8Array(1)); | ||
93417 | var versionByte = getTypeBits(type) + getHashSizeBits(hash); | ||
93418 | var payloadData = toUint5Array(concat(Uint8Array.of(versionByte), hash)); | ||
93419 | var checksumData = concat(concat(prefixData, payloadData), new Uint8Array(8)); | ||
93420 | var payload = concat(payloadData, checksumToUint5Array(polymod(checksumData))); | ||
93421 | return prefix + ':' + base32.encode(payload); | ||
93422 | } | ||
93423 | |||
93424 | /** | ||
93425 | * Decodes the given address into its constituting prefix, type and hash. See [#encode()]{@link encode}. | ||
93426 | * | ||
93427 | * @static | ||
93428 | * @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'. | ||
93429 | * @returns {object} | ||
93430 | * @throws {ValidationError} | ||
93431 | */ | ||
93432 | function decode(address) { | ||
93433 | validate(typeof address === 'string' && hasSingleCase(address), 'Invalid address: ' + address + '.'); | ||
93434 | var pieces = address.toLowerCase().split(':'); | ||
93435 | validate(pieces.length === 2, 'Missing prefix: ' + address + '.'); | ||
93436 | var prefix = pieces[0]; | ||
93437 | var payload = base32.decode(pieces[1]); | ||
93438 | validate(validChecksum(prefix, payload), 'Invalid checksum: ' + address + '.'); | ||
93439 | var payloadData = fromUint5Array(payload.slice(0, -8)); | ||
93440 | var versionByte = payloadData[0]; | ||
93441 | var hash = payloadData.slice(1); | ||
93442 | validate(getHashSize(versionByte) === hash.length * 8, 'Invalid hash size: ' + address + '.'); | ||
93443 | var type = getType(versionByte); | ||
93444 | return { | ||
93445 | prefix: prefix, | ||
93446 | type: type, | ||
93447 | hash: hash, | ||
93448 | }; | ||
93449 | } | ||
93450 | |||
93451 | /** | ||
93452 | * Error thrown when encoding or decoding fail due to invalid input. | ||
93453 | * | ||
93454 | * @constructor ValidationError | ||
93455 | * @param {string} message Error description. | ||
93456 | */ | ||
93457 | var ValidationError = validation.ValidationError; | ||
93458 | |||
93459 | /** | ||
93460 | * Valid address prefixes. | ||
93461 | * | ||
93462 | * @private | ||
93463 | */ | ||
93464 | var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg']; | ||
93465 | |||
93466 | /** | ||
93467 | * Checks whether a string is a valid prefix; ie., it has a single letter case | ||
93468 | * and is one of 'bitcoincash', 'bchtest', or 'bchreg'. | ||
93469 | * | ||
93470 | * @private | ||
93471 | * @param {string} prefix | ||
93472 | * @returns {boolean} | ||
93473 | */ | ||
93474 | function isValidPrefix(prefix) { | ||
93475 | return hasSingleCase(prefix) && VALID_PREFIXES.indexOf(prefix.toLowerCase()) !== -1; | ||
93476 | } | ||
93477 | |||
93478 | /** | ||
93479 | * Derives an array from the given prefix to be used in the computation | ||
93480 | * of the address' checksum. | ||
93481 | * | ||
93482 | * @private | ||
93483 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | ||
93484 | * @returns {Uint8Array} | ||
93485 | */ | ||
93486 | function prefixToUint5Array(prefix) { | ||
93487 | var result = new Uint8Array(prefix.length); | ||
93488 | for (var i = 0; i < prefix.length; ++i) { | ||
93489 | result[i] = prefix[i].charCodeAt(0) & 31; | ||
93490 | } | ||
93491 | return result; | ||
93492 | } | ||
93493 | |||
93494 | /** | ||
93495 | * Returns an array representation of the given checksum to be encoded | ||
93496 | * within the address' payload. | ||
93497 | * | ||
93498 | * @private | ||
93499 | * @param {BigInteger} checksum Computed checksum. | ||
93500 | * @returns {Uint8Array} | ||
93501 | */ | ||
93502 | function checksumToUint5Array(checksum) { | ||
93503 | var result = new Uint8Array(8); | ||
93504 | for (var i = 0; i < 8; ++i) { | ||
93505 | result[7 - i] = checksum.and(31).toJSNumber(); | ||
93506 | checksum = checksum.shiftRight(5); | ||
93507 | } | ||
93508 | return result; | ||
93509 | } | ||
93510 | |||
93511 | /** | ||
93512 | * Returns the bit representation of the given type within the version | ||
93513 | * byte. | ||
93514 | * | ||
93515 | * @private | ||
93516 | * @param {string} type Address type. Either 'P2PKH' or 'P2SH'. | ||
93517 | * @returns {number} | ||
93518 | * @throws {ValidationError} | ||
93519 | */ | ||
93520 | function getTypeBits(type) { | ||
93521 | switch (type) { | ||
93522 | case 'P2PKH': | ||
93523 | return 0; | ||
93524 | case 'P2SH': | ||
93525 | return 8; | ||
93526 | default: | ||
93527 | throw new ValidationError('Invalid type: ' + type + '.'); | ||
93528 | } | ||
93529 | } | ||
93530 | |||
93531 | /** | ||
93532 | * Retrieves the address type from its bit representation within the | ||
93533 | * version byte. | ||
93534 | * | ||
93535 | * @private | ||
93536 | * @param {number} versionByte | ||
93537 | * @returns {string} | ||
93538 | * @throws {ValidationError} | ||
93539 | */ | ||
93540 | function getType(versionByte) { | ||
93541 | switch (versionByte & 120) { | ||
93542 | case 0: | ||
93543 | return 'P2PKH'; | ||
93544 | case 8: | ||
93545 | return 'P2SH'; | ||
93546 | default: | ||
93547 | throw new ValidationError('Invalid address type in version byte: ' + versionByte + '.'); | ||
93548 | } | ||
93549 | } | ||
93550 | |||
93551 | /** | ||
93552 | * Returns the bit representation of the length in bits of the given | ||
93553 | * hash within the version byte. | ||
93554 | * | ||
93555 | * @private | ||
93556 | * @param {Uint8Array} hash Hash to encode represented as an array of 8-bit integers. | ||
93557 | * @returns {number} | ||
93558 | * @throws {ValidationError} | ||
93559 | */ | ||
93560 | function getHashSizeBits(hash) { | ||
93561 | switch (hash.length * 8) { | ||
93562 | case 160: | ||
93563 | return 0; | ||
93564 | case 192: | ||
93565 | return 1; | ||
93566 | case 224: | ||
93567 | return 2; | ||
93568 | case 256: | ||
93569 | return 3; | ||
93570 | case 320: | ||
93571 | return 4; | ||
93572 | case 384: | ||
93573 | return 5; | ||
93574 | case 448: | ||
93575 | return 6; | ||
93576 | case 512: | ||
93577 | return 7; | ||
93578 | default: | ||
93579 | throw new ValidationError('Invalid hash size: ' + hash.length + '.'); | ||
93580 | } | ||
93581 | } | ||
93582 | |||
93583 | /** | ||
93584 | * Retrieves the the length in bits of the encoded hash from its bit | ||
93585 | * representation within the version byte. | ||
93586 | * | ||
93587 | * @private | ||
93588 | * @param {number} versionByte | ||
93589 | * @returns {number} | ||
93590 | */ | ||
93591 | function getHashSize(versionByte) { | ||
93592 | switch (versionByte & 7) { | ||
93593 | case 0: | ||
93594 | return 160; | ||
93595 | case 1: | ||
93596 | return 192; | ||
93597 | case 2: | ||
93598 | return 224; | ||
93599 | case 3: | ||
93600 | return 256; | ||
93601 | case 4: | ||
93602 | return 320; | ||
93603 | case 5: | ||
93604 | return 384; | ||
93605 | case 6: | ||
93606 | return 448; | ||
93607 | case 7: | ||
93608 | return 512; | ||
93609 | } | ||
93610 | } | ||
93611 | |||
93612 | /** | ||
93613 | * Converts an array of 8-bit integers into an array of 5-bit integers, | ||
93614 | * right-padding with zeroes if necessary. | ||
93615 | * | ||
93616 | * @private | ||
93617 | * @param {Uint8Array} data | ||
93618 | * @returns {Uint8Array} | ||
93619 | */ | ||
93620 | function toUint5Array(data) { | ||
93621 | return convertBits(data, 8, 5); | ||
93622 | } | ||
93623 | |||
93624 | /** | ||
93625 | * Converts an array of 5-bit integers back into an array of 8-bit integers, | ||
93626 | * removing extra zeroes left from padding if necessary. | ||
93627 | * Throws a {@link ValidationError} if input is not a zero-padded array of 8-bit integers. | ||
93628 | * | ||
93629 | * @private | ||
93630 | * @param {Uint8Array} data | ||
93631 | * @returns {Uint8Array} | ||
93632 | * @throws {ValidationError} | ||
93633 | */ | ||
93634 | function fromUint5Array(data) { | ||
93635 | return convertBits(data, 5, 8, true); | ||
93636 | } | ||
93637 | |||
93638 | /** | ||
93639 | * Returns the concatenation a and b. | ||
93640 | * | ||
93641 | * @private | ||
93642 | * @param {Uint8Array} a | ||
93643 | * @param {Uint8Array} b | ||
93644 | * @returns {Uint8Array} | ||
93645 | * @throws {ValidationError} | ||
93646 | */ | ||
93647 | function concat(a, b) { | ||
93648 | var ab = new Uint8Array(a.length + b.length); | ||
93649 | ab.set(a); | ||
93650 | ab.set(b, a.length); | ||
93651 | return ab; | ||
93652 | } | ||
93653 | |||
93654 | /** | ||
93655 | * Computes a checksum from the given input data as specified for the CashAddr | ||
93656 | * format: https://github.com/Bitcoin-UAHF/spec/blob/master/cashaddr.md. | ||
93657 | * | ||
93658 | * @private | ||
93659 | * @param {Uint8Array} data Array of 5-bit integers over which the checksum is to be computed. | ||
93660 | * @returns {BigInteger} | ||
93661 | */ | ||
93662 | function polymod(data) { | ||
93663 | var GENERATOR = [0x98f2bc8e61, 0x79b76d99e2, 0xf33e5fb3c4, 0xae2eabe2a8, 0x1e4f43e470]; | ||
93664 | var checksum = bigInt(1); | ||
93665 | for (var i = 0; i < data.length; ++i) { | ||
93666 | var value = data[i]; | ||
93667 | var topBits = checksum.shiftRight(35); | ||
93668 | checksum = checksum.and(0x07ffffffff).shiftLeft(5).xor(value); | ||
93669 | for (var j = 0; j < GENERATOR.length; ++j) { | ||
93670 | if (topBits.shiftRight(j).and(1).equals(1)) { | ||
93671 | checksum = checksum.xor(GENERATOR[j]); | ||
93672 | } | ||
93673 | } | ||
93674 | } | ||
93675 | return checksum.xor(1); | ||
93676 | } | ||
93677 | |||
93678 | /** | ||
93679 | * Verify that the payload has not been corrupted by checking that the | ||
93680 | * checksum is valid. | ||
93681 | * | ||
93682 | * @private | ||
93683 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | ||
93684 | * @param {Uint8Array} payload Array of 5-bit integers containing the address' payload. | ||
93685 | * @returns {boolean} | ||
93686 | */ | ||
93687 | function validChecksum(prefix, payload) { | ||
93688 | var prefixData = concat(prefixToUint5Array(prefix), new Uint8Array(1)); | ||
93689 | var checksumData = concat(prefixData, payload); | ||
93690 | return polymod(checksumData).equals(0); | ||
93691 | } | ||
93692 | |||
93693 | /** | ||
93694 | * Returns true if, and only if, the given string contains either uppercase | ||
93695 | * or lowercase letters, but not both. | ||
93696 | * | ||
93697 | * @private | ||
93698 | * @param {string} string Input string. | ||
93699 | * @returns {boolean} | ||
93700 | */ | ||
93701 | function hasSingleCase(string) { | ||
93702 | return string === string.toLowerCase() || string === string.toUpperCase(); | ||
93703 | } | ||
93704 | |||
93705 | module.exports = { | ||
93706 | encode: encode, | ||
93707 | decode: decode, | ||
93708 | ValidationError: ValidationError, | ||
93709 | }; | ||
93710 | |||
93711 | },{"./base32":9,"./convertBits":11,"./validation":12,"big-integer":3}],11:[function(require,module,exports){ | ||
93712 | // Copyright (c) 2017-2018 Emilio Almansi | ||
93713 | // Copyright (c) 2017 Pieter Wuille | ||
93714 | // | ||
93715 | // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
93716 | // of this software and associated documentation files (the "Software"), to deal | ||
93717 | // in the Software without restriction, including without limitation the rights | ||
93718 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
93719 | // copies of the Software, and to permit persons to whom the Software is | ||
93720 | // furnished to do so, subject to the following conditions: | ||
93721 | // | ||
93722 | // The above copyright notice and this permission notice shall be included in | ||
93723 | // all copies or substantial portions of the Software. | ||
93724 | // | ||
93725 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
93726 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
93727 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
93728 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
93729 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
93730 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
93731 | // THE SOFTWARE. | ||
93732 | |||
93733 | 'use strict'; | ||
93734 | |||
93735 | var validate = require('./validation').validate; | ||
93736 | |||
93737 | /** | ||
93738 | * Converts an array of integers made up of 'from' bits into an | ||
93739 | * array of integers made up of 'to' bits. The output array is | ||
93740 | * zero-padded if necessary, unless strict mode is true. | ||
93741 | * Throws a {@link ValidationError} if input is invalid. | ||
93742 | * Original by Pieter Wuille: https://github.com/sipa/bech32. | ||
93743 | * | ||
93744 | * @param {Uint8Array} data Array of integers made up of 'from' bits. | ||
93745 | * @param {number} from Length in bits of elements in the input array. | ||
93746 | * @param {number} to Length in bits of elements in the output array. | ||
93747 | * @param {bool} strictMode Require the conversion to be completed without padding. | ||
93748 | * @returns {Uint8Array} | ||
93749 | */ | ||
93750 | module.exports = function(data, from, to, strictMode) { | ||
93751 | var length = strictMode | ||
93752 | ? Math.floor(data.length * from / to) | ||
93753 | : Math.ceil(data.length * from / to); | ||
93754 | var mask = (1 << to) - 1; | ||
93755 | var result = new Uint8Array(length); | ||
93756 | var index = 0; | ||
93757 | var accumulator = 0; | ||
93758 | var bits = 0; | ||
93759 | for (var i = 0; i < data.length; ++i) { | ||
93760 | var value = data[i]; | ||
93761 | validate(0 <= value && (value >> from) === 0, 'Invalid value: ' + value + '.'); | ||
93762 | accumulator = (accumulator << from) | value; | ||
93763 | bits += from; | ||
93764 | while (bits >= to) { | ||
93765 | bits -= to; | ||
93766 | result[index] = (accumulator >> bits) & mask; | ||
93767 | ++index; | ||
93768 | } | ||
93769 | } | ||
93770 | if (!strictMode) { | ||
93771 | if (bits > 0) { | ||
93772 | result[index] = (accumulator << (to - bits)) & mask; | ||
93773 | ++index; | ||
93774 | } | ||
93775 | } else { | ||
93776 | validate( | ||
93777 | bits < from && ((accumulator << (to - bits)) & mask) === 0, | ||
93778 | 'Input cannot be converted to ' + to + ' bits without padding, but strict mode was used.' | ||
93779 | ); | ||
93780 | } | ||
93781 | return result; | ||
93782 | }; | ||
93783 | |||
93784 | },{"./validation":12}],12:[function(require,module,exports){ | ||
93785 | /** | ||
93786 | * @license | ||
93787 | * https://github.com/bitcoincashjs/cashaddr | ||
93788 | * Copyright (c) 2017-2018 Emilio Almansi | ||
93789 | * Distributed under the MIT software license, see the accompanying | ||
93790 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. | ||
93791 | */ | ||
93792 | |||
93793 | 'use strict'; | ||
93794 | |||
93795 | /** | ||
93796 | * Validation utility. | ||
93797 | * | ||
93798 | * @module validation | ||
93799 | */ | ||
93800 | |||
93801 | /** | ||
93802 | * Error thrown when encoding or decoding fail due to invalid input. | ||
93803 | * | ||
93804 | * @constructor ValidationError | ||
93805 | * @param {string} message Error description. | ||
93806 | */ | ||
93807 | function ValidationError(message) { | ||
93808 | var error = new Error(); | ||
93809 | this.name = error.name = 'ValidationError'; | ||
93810 | this.message = error.message = message; | ||
93811 | this.stack = error.stack; | ||
93812 | } | ||
93813 | |||
93814 | ValidationError.prototype = Object.create(Error.prototype); | ||
93815 | |||
93816 | /** | ||
93817 | * Validates a given condition, throwing a {@link ValidationError} if | ||
93818 | * the given condition does not hold. | ||
93819 | * | ||
93820 | * @static | ||
93821 | * @param {boolean} condition Condition to validate. | ||
93822 | * @param {string} message Error message in case the condition does not hold. | ||
93823 | */ | ||
93824 | function validate(condition, message) { | ||
93825 | if (!condition) { | ||
93826 | throw new ValidationError(message); | ||
93827 | } | ||
93828 | } | ||
93829 | |||
93830 | module.exports = { | ||
93831 | ValidationError: ValidationError, | ||
93832 | validate: validate, | ||
93833 | }; | ||
93834 | |||
93835 | },{}],13:[function(require,module,exports){ | ||
93836 | var Buffer = require('safe-buffer').Buffer | ||
93837 | var Transform = require('stream').Transform | ||
93838 | var StringDecoder = require('string_decoder').StringDecoder | ||
93839 | var inherits = require('inherits') | ||
93840 | |||
93841 | function CipherBase (hashMode) { | ||
93842 | Transform.call(this) | ||
93843 | this.hashMode = typeof hashMode === 'string' | ||
93844 | if (this.hashMode) { | ||
93845 | this[hashMode] = this._finalOrDigest | ||
93846 | } else { | ||
93847 | this.final = this._finalOrDigest | ||
93848 | } | ||
93849 | if (this._final) { | ||
93850 | this.__final = this._final | ||
93851 | this._final = null | ||
93852 | } | ||
93853 | this._decoder = null | ||
93854 | this._encoding = null | ||
93855 | } | ||
93856 | inherits(CipherBase, Transform) | ||
93857 | |||
93858 | CipherBase.prototype.update = function (data, inputEnc, outputEnc) { | ||
93859 | if (typeof data === 'string') { | ||
93860 | data = Buffer.from(data, inputEnc) | ||
93861 | } | ||
93862 | |||
93863 | var outData = this._update(data) | ||
93864 | if (this.hashMode) return this | ||
93865 | |||
93866 | if (outputEnc) { | ||
93867 | outData = this._toString(outData, outputEnc) | ||
93868 | } | ||
93869 | |||
93870 | return outData | ||
93871 | } | ||
93872 | |||
93873 | CipherBase.prototype.setAutoPadding = function () {} | ||
93874 | CipherBase.prototype.getAuthTag = function () { | ||
93875 | throw new Error('trying to get auth tag in unsupported state') | ||
93876 | } | ||
93877 | |||
93878 | CipherBase.prototype.setAuthTag = function () { | ||
93879 | throw new Error('trying to set auth tag in unsupported state') | ||
93880 | } | ||
93881 | |||
93882 | CipherBase.prototype.setAAD = function () { | ||
93883 | throw new Error('trying to set aad in unsupported state') | ||
93884 | } | ||
93885 | |||
93886 | CipherBase.prototype._transform = function (data, _, next) { | ||
93887 | var err | ||
93888 | try { | ||
93889 | if (this.hashMode) { | ||
93890 | this._update(data) | ||
93891 | } else { | ||
93892 | this.push(this._update(data)) | ||
93893 | } | ||
93894 | } catch (e) { | ||
93895 | err = e | ||
93896 | } finally { | ||
93897 | next(err) | ||
93898 | } | ||
93899 | } | ||
93900 | CipherBase.prototype._flush = function (done) { | ||
93901 | var err | ||
93902 | try { | ||
93903 | this.push(this.__final()) | ||
93904 | } catch (e) { | ||
93905 | err = e | ||
93906 | } | ||
93907 | |||
93908 | done(err) | ||
93909 | } | ||
93910 | CipherBase.prototype._finalOrDigest = function (outputEnc) { | ||
93911 | var outData = this.__final() || Buffer.alloc(0) | ||
93912 | if (outputEnc) { | ||
93913 | outData = this._toString(outData, outputEnc, true) | ||
93914 | } | ||
93915 | return outData | ||
93916 | } | ||
93917 | |||
93918 | CipherBase.prototype._toString = function (value, enc, fin) { | ||
93919 | if (!this._decoder) { | ||
93920 | this._decoder = new StringDecoder(enc) | ||
93921 | this._encoding = enc | ||
93922 | } | ||
93923 | |||
93924 | if (this._encoding !== enc) throw new Error('can\'t switch encodings') | ||
93925 | |||
93926 | var out = this._decoder.write(value) | ||
93927 | if (fin) { | ||
93928 | out += this._decoder.end() | ||
93929 | } | ||
93930 | |||
93931 | return out | ||
93932 | } | ||
93933 | |||
93934 | module.exports = CipherBase | ||
93935 | |||
93936 | },{"inherits":21,"safe-buffer":40,"stream":49,"string_decoder":50}],14:[function(require,module,exports){ | ||
93937 | (function (Buffer){ | ||
93938 | // Copyright Joyent, Inc. and other Node contributors. | ||
93939 | // | ||
93940 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
93941 | // copy of this software and associated documentation files (the | ||
93942 | // "Software"), to deal in the Software without restriction, including | ||
93943 | // without limitation the rights to use, copy, modify, merge, publish, | ||
93944 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
93945 | // persons to whom the Software is furnished to do so, subject to the | ||
93946 | // following conditions: | ||
93947 | // | ||
93948 | // The above copyright notice and this permission notice shall be included | ||
93949 | // in all copies or substantial portions of the Software. | ||
93950 | // | ||
93951 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
93952 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
93953 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
93954 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
93955 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
93956 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
93957 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
93958 | |||
93959 | // NOTE: These type checking functions intentionally don't use `instanceof` | ||
93960 | // because it is fragile and can be easily faked with `Object.create()`. | ||
93961 | |||
93962 | function isArray(arg) { | ||
93963 | if (Array.isArray) { | ||
93964 | return Array.isArray(arg); | ||
93965 | } | ||
93966 | return objectToString(arg) === '[object Array]'; | ||
93967 | } | ||
93968 | exports.isArray = isArray; | ||
93969 | |||
93970 | function isBoolean(arg) { | ||
93971 | return typeof arg === 'boolean'; | ||
93972 | } | ||
93973 | exports.isBoolean = isBoolean; | ||
93974 | |||
93975 | function isNull(arg) { | ||
93976 | return arg === null; | ||
93977 | } | ||
93978 | exports.isNull = isNull; | ||
93979 | |||
93980 | function isNullOrUndefined(arg) { | ||
93981 | return arg == null; | ||
93982 | } | ||
93983 | exports.isNullOrUndefined = isNullOrUndefined; | ||
93984 | |||
93985 | function isNumber(arg) { | ||
93986 | return typeof arg === 'number'; | ||
93987 | } | ||
93988 | exports.isNumber = isNumber; | ||
93989 | |||
93990 | function isString(arg) { | ||
93991 | return typeof arg === 'string'; | ||
93992 | } | ||
93993 | exports.isString = isString; | ||
93994 | |||
93995 | function isSymbol(arg) { | ||
93996 | return typeof arg === 'symbol'; | ||
93997 | } | ||
93998 | exports.isSymbol = isSymbol; | ||
93999 | |||
94000 | function isUndefined(arg) { | ||
94001 | return arg === void 0; | ||
94002 | } | ||
94003 | exports.isUndefined = isUndefined; | ||
94004 | |||
94005 | function isRegExp(re) { | ||
94006 | return objectToString(re) === '[object RegExp]'; | ||
94007 | } | ||
94008 | exports.isRegExp = isRegExp; | ||
94009 | |||
94010 | function isObject(arg) { | ||
94011 | return typeof arg === 'object' && arg !== null; | ||
94012 | } | ||
94013 | exports.isObject = isObject; | ||
94014 | |||
94015 | function isDate(d) { | ||
94016 | return objectToString(d) === '[object Date]'; | ||
94017 | } | ||
94018 | exports.isDate = isDate; | ||
94019 | |||
94020 | function isError(e) { | ||
94021 | return (objectToString(e) === '[object Error]' || e instanceof Error); | ||
94022 | } | ||
94023 | exports.isError = isError; | ||
94024 | |||
94025 | function isFunction(arg) { | ||
94026 | return typeof arg === 'function'; | ||
94027 | } | ||
94028 | exports.isFunction = isFunction; | ||
94029 | |||
94030 | function isPrimitive(arg) { | ||
94031 | return arg === null || | ||
94032 | typeof arg === 'boolean' || | ||
94033 | typeof arg === 'number' || | ||
94034 | typeof arg === 'string' || | ||
94035 | typeof arg === 'symbol' || // ES6 symbol | ||
94036 | typeof arg === 'undefined'; | ||
94037 | } | ||
94038 | exports.isPrimitive = isPrimitive; | ||
94039 | |||
94040 | exports.isBuffer = Buffer.isBuffer; | ||
94041 | |||
94042 | function objectToString(o) { | ||
94043 | return Object.prototype.toString.call(o); | ||
94044 | } | ||
94045 | |||
94046 | }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) | ||
94047 | },{"../../is-buffer/index.js":22}],15:[function(require,module,exports){ | ||
94048 | (function (Buffer){ | ||
94049 | 'use strict' | ||
94050 | var inherits = require('inherits') | ||
94051 | var md5 = require('./md5') | ||
94052 | var RIPEMD160 = require('ripemd160') | ||
94053 | var sha = require('sha.js') | ||
94054 | |||
94055 | var Base = require('cipher-base') | ||
94056 | |||
94057 | function HashNoConstructor (hash) { | ||
94058 | Base.call(this, 'digest') | ||
94059 | |||
94060 | this._hash = hash | ||
94061 | this.buffers = [] | ||
94062 | } | ||
94063 | |||
94064 | inherits(HashNoConstructor, Base) | ||
94065 | |||
94066 | HashNoConstructor.prototype._update = function (data) { | ||
94067 | this.buffers.push(data) | ||
94068 | } | ||
94069 | |||
94070 | HashNoConstructor.prototype._final = function () { | ||
94071 | var buf = Buffer.concat(this.buffers) | ||
94072 | var r = this._hash(buf) | ||
94073 | this.buffers = null | ||
94074 | |||
94075 | return r | ||
94076 | } | ||
94077 | |||
94078 | function Hash (hash) { | ||
94079 | Base.call(this, 'digest') | ||
94080 | |||
94081 | this._hash = hash | ||
94082 | } | ||
94083 | |||
94084 | inherits(Hash, Base) | ||
94085 | |||
94086 | Hash.prototype._update = function (data) { | ||
94087 | this._hash.update(data) | ||
94088 | } | ||
94089 | |||
94090 | Hash.prototype._final = function () { | ||
94091 | return this._hash.digest() | ||
94092 | } | ||
94093 | |||
94094 | module.exports = function createHash (alg) { | ||
94095 | alg = alg.toLowerCase() | ||
94096 | if (alg === 'md5') return new HashNoConstructor(md5) | ||
94097 | if (alg === 'rmd160' || alg === 'ripemd160') return new Hash(new RIPEMD160()) | ||
94098 | |||
94099 | return new Hash(sha(alg)) | ||
94100 | } | ||
94101 | |||
94102 | }).call(this,require("buffer").Buffer) | ||
94103 | },{"./md5":17,"buffer":8,"cipher-base":13,"inherits":21,"ripemd160":39,"sha.js":42}],16:[function(require,module,exports){ | ||
94104 | (function (Buffer){ | ||
94105 | 'use strict' | ||
94106 | var intSize = 4 | ||
94107 | var zeroBuffer = new Buffer(intSize) | ||
94108 | zeroBuffer.fill(0) | ||
94109 | |||
94110 | var charSize = 8 | ||
94111 | var hashSize = 16 | ||
94112 | |||
94113 | function toArray (buf) { | ||
94114 | if ((buf.length % intSize) !== 0) { | ||
94115 | var len = buf.length + (intSize - (buf.length % intSize)) | ||
94116 | buf = Buffer.concat([buf, zeroBuffer], len) | ||
94117 | } | ||
94118 | |||
94119 | var arr = new Array(buf.length >>> 2) | ||
94120 | for (var i = 0, j = 0; i < buf.length; i += intSize, j++) { | ||
94121 | arr[j] = buf.readInt32LE(i) | ||
94122 | } | ||
94123 | |||
94124 | return arr | ||
94125 | } | ||
94126 | |||
94127 | module.exports = function hash (buf, fn) { | ||
94128 | var arr = fn(toArray(buf), buf.length * charSize) | ||
94129 | buf = new Buffer(hashSize) | ||
94130 | for (var i = 0; i < arr.length; i++) { | ||
94131 | buf.writeInt32LE(arr[i], i << 2, true) | ||
94132 | } | ||
94133 | return buf | ||
94134 | } | ||
94135 | |||
94136 | }).call(this,require("buffer").Buffer) | ||
94137 | },{"buffer":8}],17:[function(require,module,exports){ | ||
94138 | 'use strict' | ||
94139 | /* | ||
94140 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message | ||
94141 | * Digest Algorithm, as defined in RFC 1321. | ||
94142 | * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. | ||
94143 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
94144 | * Distributed under the BSD License | ||
94145 | * See http://pajhome.org.uk/crypt/md5 for more info. | ||
94146 | */ | ||
94147 | |||
94148 | var makeHash = require('./make-hash') | ||
94149 | |||
94150 | /* | ||
94151 | * Calculate the MD5 of an array of little-endian words, and a bit length | ||
94152 | */ | ||
94153 | function core_md5 (x, len) { | ||
94154 | /* append padding */ | ||
94155 | x[len >> 5] |= 0x80 << ((len) % 32) | ||
94156 | x[(((len + 64) >>> 9) << 4) + 14] = len | ||
94157 | |||
94158 | var a = 1732584193 | ||
94159 | var b = -271733879 | ||
94160 | var c = -1732584194 | ||
94161 | var d = 271733878 | ||
94162 | |||
94163 | for (var i = 0; i < x.length; i += 16) { | ||
94164 | var olda = a | ||
94165 | var oldb = b | ||
94166 | var oldc = c | ||
94167 | var oldd = d | ||
94168 | |||
94169 | a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936) | ||
94170 | d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586) | ||
94171 | c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819) | ||
94172 | b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330) | ||
94173 | a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897) | ||
94174 | d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426) | ||
94175 | c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341) | ||
94176 | b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983) | ||
94177 | a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416) | ||
94178 | d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417) | ||
94179 | c = md5_ff(c, d, a, b, x[i + 10], 17, -42063) | ||
94180 | b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162) | ||
94181 | a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682) | ||
94182 | d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101) | ||
94183 | c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290) | ||
94184 | b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329) | ||
94185 | |||
94186 | a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510) | ||
94187 | d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632) | ||
94188 | c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713) | ||
94189 | b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302) | ||
94190 | a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691) | ||
94191 | d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083) | ||
94192 | c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335) | ||
94193 | b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848) | ||
94194 | a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438) | ||
94195 | d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690) | ||
94196 | c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961) | ||
94197 | b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501) | ||
94198 | a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467) | ||
94199 | d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784) | ||
94200 | c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473) | ||
94201 | b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734) | ||
94202 | |||
94203 | a = md5_hh(a, b, c, d, x[i + 5], 4, -378558) | ||
94204 | d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463) | ||
94205 | c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562) | ||
94206 | b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556) | ||
94207 | a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060) | ||
94208 | d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353) | ||
94209 | c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632) | ||
94210 | b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640) | ||
94211 | a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174) | ||
94212 | d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222) | ||
94213 | c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979) | ||
94214 | b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189) | ||
94215 | a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487) | ||
94216 | d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835) | ||
94217 | c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520) | ||
94218 | b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651) | ||
94219 | |||
94220 | a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844) | ||
94221 | d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415) | ||
94222 | c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905) | ||
94223 | b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055) | ||
94224 | a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571) | ||
94225 | d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606) | ||
94226 | c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523) | ||
94227 | b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799) | ||
94228 | a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359) | ||
94229 | d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744) | ||
94230 | c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380) | ||
94231 | b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649) | ||
94232 | a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070) | ||
94233 | d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379) | ||
94234 | c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259) | ||
94235 | b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551) | ||
94236 | |||
94237 | a = safe_add(a, olda) | ||
94238 | b = safe_add(b, oldb) | ||
94239 | c = safe_add(c, oldc) | ||
94240 | d = safe_add(d, oldd) | ||
94241 | } | ||
94242 | |||
94243 | return [a, b, c, d] | ||
94244 | } | ||
94245 | |||
94246 | /* | ||
94247 | * These functions implement the four basic operations the algorithm uses. | ||
94248 | */ | ||
94249 | function md5_cmn (q, a, b, x, s, t) { | ||
94250 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b) | ||
94251 | } | ||
94252 | |||
94253 | function md5_ff (a, b, c, d, x, s, t) { | ||
94254 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t) | ||
94255 | } | ||
94256 | |||
94257 | function md5_gg (a, b, c, d, x, s, t) { | ||
94258 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t) | ||
94259 | } | ||
94260 | |||
94261 | function md5_hh (a, b, c, d, x, s, t) { | ||
94262 | return md5_cmn(b ^ c ^ d, a, b, x, s, t) | ||
94263 | } | ||
94264 | |||
94265 | function md5_ii (a, b, c, d, x, s, t) { | ||
94266 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t) | ||
94267 | } | ||
94268 | |||
94269 | /* | ||
94270 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally | ||
94271 | * to work around bugs in some JS interpreters. | ||
94272 | */ | ||
94273 | function safe_add (x, y) { | ||
94274 | var lsw = (x & 0xFFFF) + (y & 0xFFFF) | ||
94275 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16) | ||
94276 | return (msw << 16) | (lsw & 0xFFFF) | ||
94277 | } | ||
94278 | |||
94279 | /* | ||
94280 | * Bitwise rotate a 32-bit number to the left. | ||
94281 | */ | ||
94282 | function bit_rol (num, cnt) { | ||
94283 | return (num << cnt) | (num >>> (32 - cnt)) | ||
94284 | } | ||
94285 | |||
94286 | module.exports = function md5 (buf) { | ||
94287 | return makeHash(buf, core_md5) | ||
94288 | } | ||
94289 | |||
94290 | },{"./make-hash":16}],18:[function(require,module,exports){ | ||
94291 | // Copyright Joyent, Inc. and other Node contributors. | ||
94292 | // | ||
94293 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
94294 | // copy of this software and associated documentation files (the | ||
94295 | // "Software"), to deal in the Software without restriction, including | ||
94296 | // without limitation the rights to use, copy, modify, merge, publish, | ||
94297 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
94298 | // persons to whom the Software is furnished to do so, subject to the | ||
94299 | // following conditions: | ||
94300 | // | ||
94301 | // The above copyright notice and this permission notice shall be included | ||
94302 | // in all copies or substantial portions of the Software. | ||
94303 | // | ||
94304 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
94305 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
94306 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
94307 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
94308 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
94309 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
94310 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
94311 | |||
94312 | function EventEmitter() { | ||
94313 | this._events = this._events || {}; | ||
94314 | this._maxListeners = this._maxListeners || undefined; | ||
94315 | } | ||
94316 | module.exports = EventEmitter; | ||
94317 | |||
94318 | // Backwards-compat with node 0.10.x | ||
94319 | EventEmitter.EventEmitter = EventEmitter; | ||
94320 | |||
94321 | EventEmitter.prototype._events = undefined; | ||
94322 | EventEmitter.prototype._maxListeners = undefined; | ||
94323 | |||
94324 | // By default EventEmitters will print a warning if more than 10 listeners are | ||
94325 | // added to it. This is a useful default which helps finding memory leaks. | ||
94326 | EventEmitter.defaultMaxListeners = 10; | ||
94327 | |||
94328 | // Obviously not all Emitters should be limited to 10. This function allows | ||
94329 | // that to be increased. Set to zero for unlimited. | ||
94330 | EventEmitter.prototype.setMaxListeners = function(n) { | ||
94331 | if (!isNumber(n) || n < 0 || isNaN(n)) | ||
94332 | throw TypeError('n must be a positive number'); | ||
94333 | this._maxListeners = n; | ||
94334 | return this; | ||
94335 | }; | ||
94336 | |||
94337 | EventEmitter.prototype.emit = function(type) { | ||
94338 | var er, handler, len, args, i, listeners; | ||
94339 | |||
94340 | if (!this._events) | ||
94341 | this._events = {}; | ||
94342 | |||
94343 | // If there is no 'error' event listener then throw. | ||
94344 | if (type === 'error') { | ||
94345 | if (!this._events.error || | ||
94346 | (isObject(this._events.error) && !this._events.error.length)) { | ||
94347 | er = arguments[1]; | ||
94348 | if (er instanceof Error) { | ||
94349 | throw er; // Unhandled 'error' event | ||
94350 | } else { | ||
94351 | // At least give some kind of context to the user | ||
94352 | var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); | ||
94353 | err.context = er; | ||
94354 | throw err; | ||
94355 | } | ||
94356 | } | ||
94357 | } | ||
94358 | |||
94359 | handler = this._events[type]; | ||
94360 | |||
94361 | if (isUndefined(handler)) | ||
94362 | return false; | ||
94363 | |||
94364 | if (isFunction(handler)) { | ||
94365 | switch (arguments.length) { | ||
94366 | // fast cases | ||
94367 | case 1: | ||
94368 | handler.call(this); | ||
94369 | break; | ||
94370 | case 2: | ||
94371 | handler.call(this, arguments[1]); | ||
94372 | break; | ||
94373 | case 3: | ||
94374 | handler.call(this, arguments[1], arguments[2]); | ||
94375 | break; | ||
94376 | // slower | ||
94377 | default: | ||
94378 | args = Array.prototype.slice.call(arguments, 1); | ||
94379 | handler.apply(this, args); | ||
94380 | } | ||
94381 | } else if (isObject(handler)) { | ||
94382 | args = Array.prototype.slice.call(arguments, 1); | ||
94383 | listeners = handler.slice(); | ||
94384 | len = listeners.length; | ||
94385 | for (i = 0; i < len; i++) | ||
94386 | listeners[i].apply(this, args); | ||
94387 | } | ||
94388 | |||
94389 | return true; | ||
94390 | }; | ||
94391 | |||
94392 | EventEmitter.prototype.addListener = function(type, listener) { | ||
94393 | var m; | ||
94394 | |||
94395 | if (!isFunction(listener)) | ||
94396 | throw TypeError('listener must be a function'); | ||
94397 | |||
94398 | if (!this._events) | ||
94399 | this._events = {}; | ||
94400 | |||
94401 | // To avoid recursion in the case that type === "newListener"! Before | ||
94402 | // adding it to the listeners, first emit "newListener". | ||
94403 | if (this._events.newListener) | ||
94404 | this.emit('newListener', type, | ||
94405 | isFunction(listener.listener) ? | ||
94406 | listener.listener : listener); | ||
94407 | |||
94408 | if (!this._events[type]) | ||
94409 | // Optimize the case of one listener. Don't need the extra array object. | ||
94410 | this._events[type] = listener; | ||
94411 | else if (isObject(this._events[type])) | ||
94412 | // If we've already got an array, just append. | ||
94413 | this._events[type].push(listener); | ||
94414 | else | ||
94415 | // Adding the second element, need to change to array. | ||
94416 | this._events[type] = [this._events[type], listener]; | ||
94417 | |||
94418 | // Check for listener leak | ||
94419 | if (isObject(this._events[type]) && !this._events[type].warned) { | ||
94420 | if (!isUndefined(this._maxListeners)) { | ||
94421 | m = this._maxListeners; | ||
94422 | } else { | ||
94423 | m = EventEmitter.defaultMaxListeners; | ||
94424 | } | ||
94425 | |||
94426 | if (m && m > 0 && this._events[type].length > m) { | ||
94427 | this._events[type].warned = true; | ||
94428 | console.error('(node) warning: possible EventEmitter memory ' + | ||
94429 | 'leak detected. %d listeners added. ' + | ||
94430 | 'Use emitter.setMaxListeners() to increase limit.', | ||
94431 | this._events[type].length); | ||
94432 | if (typeof console.trace === 'function') { | ||
94433 | // not supported in IE 10 | ||
94434 | console.trace(); | ||
94435 | } | ||
94436 | } | ||
94437 | } | ||
94438 | |||
94439 | return this; | ||
94440 | }; | ||
94441 | |||
94442 | EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
94443 | |||
94444 | EventEmitter.prototype.once = function(type, listener) { | ||
94445 | if (!isFunction(listener)) | ||
94446 | throw TypeError('listener must be a function'); | ||
94447 | |||
94448 | var fired = false; | ||
94449 | |||
94450 | function g() { | ||
94451 | this.removeListener(type, g); | ||
94452 | |||
94453 | if (!fired) { | ||
94454 | fired = true; | ||
94455 | listener.apply(this, arguments); | ||
94456 | } | ||
94457 | } | ||
94458 | |||
94459 | g.listener = listener; | ||
94460 | this.on(type, g); | ||
94461 | |||
94462 | return this; | ||
94463 | }; | ||
94464 | |||
94465 | // emits a 'removeListener' event iff the listener was removed | ||
94466 | EventEmitter.prototype.removeListener = function(type, listener) { | ||
94467 | var list, position, length, i; | ||
94468 | |||
94469 | if (!isFunction(listener)) | ||
94470 | throw TypeError('listener must be a function'); | ||
94471 | |||
94472 | if (!this._events || !this._events[type]) | ||
94473 | return this; | ||
94474 | |||
94475 | list = this._events[type]; | ||
94476 | length = list.length; | ||
94477 | position = -1; | ||
94478 | |||
94479 | if (list === listener || | ||
94480 | (isFunction(list.listener) && list.listener === listener)) { | ||
94481 | delete this._events[type]; | ||
94482 | if (this._events.removeListener) | ||
94483 | this.emit('removeListener', type, listener); | ||
94484 | |||
94485 | } else if (isObject(list)) { | ||
94486 | for (i = length; i-- > 0;) { | ||
94487 | if (list[i] === listener || | ||
94488 | (list[i].listener && list[i].listener === listener)) { | ||
94489 | position = i; | ||
94490 | break; | ||
94491 | } | ||
94492 | } | ||
94493 | |||
94494 | if (position < 0) | ||
94495 | return this; | ||
94496 | |||
94497 | if (list.length === 1) { | ||
94498 | list.length = 0; | ||
94499 | delete this._events[type]; | ||
94500 | } else { | ||
94501 | list.splice(position, 1); | ||
94502 | } | ||
94503 | |||
94504 | if (this._events.removeListener) | ||
94505 | this.emit('removeListener', type, listener); | ||
94506 | } | ||
94507 | |||
94508 | return this; | ||
94509 | }; | ||
94510 | |||
94511 | EventEmitter.prototype.removeAllListeners = function(type) { | ||
94512 | var key, listeners; | ||
94513 | |||
94514 | if (!this._events) | ||
94515 | return this; | ||
94516 | |||
94517 | // not listening for removeListener, no need to emit | ||
94518 | if (!this._events.removeListener) { | ||
94519 | if (arguments.length === 0) | ||
94520 | this._events = {}; | ||
94521 | else if (this._events[type]) | ||
94522 | delete this._events[type]; | ||
94523 | return this; | ||
94524 | } | ||
94525 | |||
94526 | // emit removeListener for all listeners on all events | ||
94527 | if (arguments.length === 0) { | ||
94528 | for (key in this._events) { | ||
94529 | if (key === 'removeListener') continue; | ||
94530 | this.removeAllListeners(key); | ||
94531 | } | ||
94532 | this.removeAllListeners('removeListener'); | ||
94533 | this._events = {}; | ||
94534 | return this; | ||
94535 | } | ||
94536 | |||
94537 | listeners = this._events[type]; | ||
94538 | |||
94539 | if (isFunction(listeners)) { | ||
94540 | this.removeListener(type, listeners); | ||
94541 | } else if (listeners) { | ||
94542 | // LIFO order | ||
94543 | while (listeners.length) | ||
94544 | this.removeListener(type, listeners[listeners.length - 1]); | ||
94545 | } | ||
94546 | delete this._events[type]; | ||
94547 | |||
94548 | return this; | ||
94549 | }; | ||
94550 | |||
94551 | EventEmitter.prototype.listeners = function(type) { | ||
94552 | var ret; | ||
94553 | if (!this._events || !this._events[type]) | ||
94554 | ret = []; | ||
94555 | else if (isFunction(this._events[type])) | ||
94556 | ret = [this._events[type]]; | ||
94557 | else | ||
94558 | ret = this._events[type].slice(); | ||
94559 | return ret; | ||
94560 | }; | ||
94561 | |||
94562 | EventEmitter.prototype.listenerCount = function(type) { | ||
94563 | if (this._events) { | ||
94564 | var evlistener = this._events[type]; | ||
94565 | |||
94566 | if (isFunction(evlistener)) | ||
94567 | return 1; | ||
94568 | else if (evlistener) | ||
94569 | return evlistener.length; | ||
94570 | } | ||
94571 | return 0; | ||
94572 | }; | ||
94573 | |||
94574 | EventEmitter.listenerCount = function(emitter, type) { | ||
94575 | return emitter.listenerCount(type); | ||
94576 | }; | ||
94577 | |||
94578 | function isFunction(arg) { | ||
94579 | return typeof arg === 'function'; | ||
94580 | } | ||
94581 | |||
94582 | function isNumber(arg) { | ||
94583 | return typeof arg === 'number'; | ||
94584 | } | ||
94585 | |||
94586 | function isObject(arg) { | ||
94587 | return typeof arg === 'object' && arg !== null; | ||
94588 | } | ||
94589 | |||
94590 | function isUndefined(arg) { | ||
94591 | return arg === void 0; | ||
94592 | } | ||
94593 | |||
94594 | },{}],19:[function(require,module,exports){ | ||
94595 | (function (Buffer){ | ||
94596 | 'use strict' | ||
94597 | var Transform = require('stream').Transform | ||
94598 | var inherits = require('inherits') | ||
94599 | |||
94600 | function HashBase (blockSize) { | ||
94601 | Transform.call(this) | ||
94602 | |||
94603 | this._block = new Buffer(blockSize) | ||
94604 | this._blockSize = blockSize | ||
94605 | this._blockOffset = 0 | ||
94606 | this._length = [0, 0, 0, 0] | ||
94607 | |||
94608 | this._finalized = false | ||
94609 | } | ||
94610 | |||
94611 | inherits(HashBase, Transform) | ||
94612 | |||
94613 | HashBase.prototype._transform = function (chunk, encoding, callback) { | ||
94614 | var error = null | ||
94615 | try { | ||
94616 | if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding) | ||
94617 | this.update(chunk) | ||
94618 | } catch (err) { | ||
94619 | error = err | ||
94620 | } | ||
94621 | |||
94622 | callback(error) | ||
94623 | } | ||
94624 | |||
94625 | HashBase.prototype._flush = function (callback) { | ||
94626 | var error = null | ||
94627 | try { | ||
94628 | this.push(this._digest()) | ||
94629 | } catch (err) { | ||
94630 | error = err | ||
94631 | } | ||
94632 | |||
94633 | callback(error) | ||
94634 | } | ||
94635 | |||
94636 | HashBase.prototype.update = function (data, encoding) { | ||
94637 | if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer') | ||
94638 | if (this._finalized) throw new Error('Digest already called') | ||
94639 | if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary') | ||
94640 | |||
94641 | // consume data | ||
94642 | var block = this._block | ||
94643 | var offset = 0 | ||
94644 | while (this._blockOffset + data.length - offset >= this._blockSize) { | ||
94645 | for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++] | ||
94646 | this._update() | ||
94647 | this._blockOffset = 0 | ||
94648 | } | ||
94649 | while (offset < data.length) block[this._blockOffset++] = data[offset++] | ||
94650 | |||
94651 | // update length | ||
94652 | for (var j = 0, carry = data.length * 8; carry > 0; ++j) { | ||
94653 | this._length[j] += carry | ||
94654 | carry = (this._length[j] / 0x0100000000) | 0 | ||
94655 | if (carry > 0) this._length[j] -= 0x0100000000 * carry | ||
94656 | } | ||
94657 | |||
94658 | return this | ||
94659 | } | ||
94660 | |||
94661 | HashBase.prototype._update = function (data) { | ||
94662 | throw new Error('_update is not implemented') | ||
94663 | } | ||
94664 | |||
94665 | HashBase.prototype.digest = function (encoding) { | ||
94666 | if (this._finalized) throw new Error('Digest already called') | ||
94667 | this._finalized = true | ||
94668 | |||
94669 | var digest = this._digest() | ||
94670 | if (encoding !== undefined) digest = digest.toString(encoding) | ||
94671 | return digest | ||
94672 | } | ||
94673 | |||
94674 | HashBase.prototype._digest = function () { | ||
94675 | throw new Error('_digest is not implemented') | ||
94676 | } | ||
94677 | |||
94678 | module.exports = HashBase | ||
94679 | |||
94680 | }).call(this,require("buffer").Buffer) | ||
94681 | },{"buffer":8,"inherits":21,"stream":49}],20:[function(require,module,exports){ | ||
94682 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { | ||
94683 | var e, m | ||
94684 | var eLen = nBytes * 8 - mLen - 1 | ||
94685 | var eMax = (1 << eLen) - 1 | ||
94686 | var eBias = eMax >> 1 | ||
94687 | var nBits = -7 | ||
94688 | var i = isLE ? (nBytes - 1) : 0 | ||
94689 | var d = isLE ? -1 : 1 | ||
94690 | var s = buffer[offset + i] | ||
94691 | |||
94692 | i += d | ||
94693 | |||
94694 | e = s & ((1 << (-nBits)) - 1) | ||
94695 | s >>= (-nBits) | ||
94696 | nBits += eLen | ||
94697 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
94698 | |||
94699 | m = e & ((1 << (-nBits)) - 1) | ||
94700 | e >>= (-nBits) | ||
94701 | nBits += mLen | ||
94702 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
94703 | |||
94704 | if (e === 0) { | ||
94705 | e = 1 - eBias | ||
94706 | } else if (e === eMax) { | ||
94707 | return m ? NaN : ((s ? -1 : 1) * Infinity) | ||
94708 | } else { | ||
94709 | m = m + Math.pow(2, mLen) | ||
94710 | e = e - eBias | ||
94711 | } | ||
94712 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | ||
94713 | } | ||
94714 | |||
94715 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | ||
94716 | var e, m, c | ||
94717 | var eLen = nBytes * 8 - mLen - 1 | ||
94718 | var eMax = (1 << eLen) - 1 | ||
94719 | var eBias = eMax >> 1 | ||
94720 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | ||
94721 | var i = isLE ? 0 : (nBytes - 1) | ||
94722 | var d = isLE ? 1 : -1 | ||
94723 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | ||
94724 | |||
94725 | value = Math.abs(value) | ||
94726 | |||
94727 | if (isNaN(value) || value === Infinity) { | ||
94728 | m = isNaN(value) ? 1 : 0 | ||
94729 | e = eMax | ||
94730 | } else { | ||
94731 | e = Math.floor(Math.log(value) / Math.LN2) | ||
94732 | if (value * (c = Math.pow(2, -e)) < 1) { | ||
94733 | e-- | ||
94734 | c *= 2 | ||
94735 | } | ||
94736 | if (e + eBias >= 1) { | ||
94737 | value += rt / c | ||
94738 | } else { | ||
94739 | value += rt * Math.pow(2, 1 - eBias) | ||
94740 | } | ||
94741 | if (value * c >= 2) { | ||
94742 | e++ | ||
94743 | c /= 2 | ||
94744 | } | ||
94745 | |||
94746 | if (e + eBias >= eMax) { | ||
94747 | m = 0 | ||
94748 | e = eMax | ||
94749 | } else if (e + eBias >= 1) { | ||
94750 | m = (value * c - 1) * Math.pow(2, mLen) | ||
94751 | e = e + eBias | ||
94752 | } else { | ||
94753 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | ||
94754 | e = 0 | ||
94755 | } | ||
94756 | } | ||
94757 | |||
94758 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | ||
94759 | |||
94760 | e = (e << mLen) | m | ||
94761 | eLen += mLen | ||
94762 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
94763 | |||
94764 | buffer[offset + i - d] |= s * 128 | ||
94765 | } | ||
94766 | |||
94767 | },{}],21:[function(require,module,exports){ | ||
94768 | if (typeof Object.create === 'function') { | ||
94769 | // implementation from standard node.js 'util' module | ||
94770 | module.exports = function inherits(ctor, superCtor) { | ||
94771 | ctor.super_ = superCtor | ||
94772 | ctor.prototype = Object.create(superCtor.prototype, { | ||
94773 | constructor: { | ||
94774 | value: ctor, | ||
94775 | enumerable: false, | ||
94776 | writable: true, | ||
94777 | configurable: true | ||
94778 | } | ||
94779 | }); | ||
94780 | }; | ||
94781 | } else { | ||
94782 | // old school shim for old browsers | ||
94783 | module.exports = function inherits(ctor, superCtor) { | ||
94784 | ctor.super_ = superCtor | ||
94785 | var TempCtor = function () {} | ||
94786 | TempCtor.prototype = superCtor.prototype | ||
94787 | ctor.prototype = new TempCtor() | ||
94788 | ctor.prototype.constructor = ctor | ||
94789 | } | ||
94790 | } | ||
94791 | |||
94792 | },{}],22:[function(require,module,exports){ | ||
94793 | /*! | ||
94794 | * Determine if an object is a Buffer | ||
94795 | * | ||
94796 | * @author Feross Aboukhadijeh <https://feross.org> | ||
94797 | * @license MIT | ||
94798 | */ | ||
94799 | |||
94800 | // The _isBuffer check is for Safari 5-7 support, because it's missing | ||
94801 | // Object.prototype.constructor. Remove this eventually | ||
94802 | module.exports = function (obj) { | ||
94803 | return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) | ||
94804 | } | ||
94805 | |||
94806 | function isBuffer (obj) { | ||
94807 | return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) | ||
94808 | } | ||
94809 | |||
94810 | // For Node v0.10 support. Remove this eventually. | ||
94811 | function isSlowBuffer (obj) { | ||
94812 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) | ||
94813 | } | ||
94814 | |||
94815 | },{}],23:[function(require,module,exports){ | ||
94816 | var toString = {}.toString; | ||
94817 | |||
94818 | module.exports = Array.isArray || function (arr) { | ||
94819 | return toString.call(arr) == '[object Array]'; | ||
94820 | }; | ||
94821 | |||
94822 | },{}],24:[function(require,module,exports){ | ||
94823 | (function (process){ | ||
94824 | 'use strict'; | ||
94825 | |||
94826 | if (!process.version || | ||
94827 | process.version.indexOf('v0.') === 0 || | ||
94828 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { | ||
94829 | module.exports = nextTick; | ||
94830 | } else { | ||
94831 | module.exports = process.nextTick; | ||
94832 | } | ||
94833 | |||
94834 | function nextTick(fn, arg1, arg2, arg3) { | ||
94835 | if (typeof fn !== 'function') { | ||
94836 | throw new TypeError('"callback" argument must be a function'); | ||
94837 | } | ||
94838 | var len = arguments.length; | ||
94839 | var args, i; | ||
94840 | switch (len) { | ||
94841 | case 0: | ||
94842 | case 1: | ||
94843 | return process.nextTick(fn); | ||
94844 | case 2: | ||
94845 | return process.nextTick(function afterTickOne() { | ||
94846 | fn.call(null, arg1); | ||
94847 | }); | ||
94848 | case 3: | ||
94849 | return process.nextTick(function afterTickTwo() { | ||
94850 | fn.call(null, arg1, arg2); | ||
94851 | }); | ||
94852 | case 4: | ||
94853 | return process.nextTick(function afterTickThree() { | ||
94854 | fn.call(null, arg1, arg2, arg3); | ||
94855 | }); | ||
94856 | default: | ||
94857 | args = new Array(len - 1); | ||
94858 | i = 0; | ||
94859 | while (i < args.length) { | ||
94860 | args[i++] = arguments[i]; | ||
94861 | } | ||
94862 | return process.nextTick(function afterTick() { | ||
94863 | fn.apply(null, args); | ||
94864 | }); | ||
94865 | } | ||
94866 | } | ||
94867 | |||
94868 | }).call(this,require('_process')) | ||
94869 | },{"_process":25}],25:[function(require,module,exports){ | ||
94870 | // shim for using process in browser | ||
94871 | var process = module.exports = {}; | ||
94872 | |||
94873 | // cached from whatever global is present so that test runners that stub it | ||
94874 | // don't break things. But we need to wrap it in a try catch in case it is | ||
94875 | // wrapped in strict mode code which doesn't define any globals. It's inside a | ||
94876 | // function because try/catches deoptimize in certain engines. | ||
94877 | |||
94878 | var cachedSetTimeout; | ||
94879 | var cachedClearTimeout; | ||
94880 | |||
94881 | function defaultSetTimout() { | ||
94882 | throw new Error('setTimeout has not been defined'); | ||
94883 | } | ||
94884 | function defaultClearTimeout () { | ||
94885 | throw new Error('clearTimeout has not been defined'); | ||
94886 | } | ||
94887 | (function () { | ||
94888 | try { | ||
94889 | if (typeof setTimeout === 'function') { | ||
94890 | cachedSetTimeout = setTimeout; | ||
94891 | } else { | ||
94892 | cachedSetTimeout = defaultSetTimout; | ||
94893 | } | ||
94894 | } catch (e) { | ||
94895 | cachedSetTimeout = defaultSetTimout; | ||
94896 | } | ||
94897 | try { | ||
94898 | if (typeof clearTimeout === 'function') { | ||
94899 | cachedClearTimeout = clearTimeout; | ||
94900 | } else { | ||
94901 | cachedClearTimeout = defaultClearTimeout; | ||
94902 | } | ||
94903 | } catch (e) { | ||
94904 | cachedClearTimeout = defaultClearTimeout; | ||
94905 | } | ||
94906 | } ()) | ||
94907 | function runTimeout(fun) { | ||
94908 | if (cachedSetTimeout === setTimeout) { | ||
94909 | //normal enviroments in sane situations | ||
94910 | return setTimeout(fun, 0); | ||
94911 | } | ||
94912 | // if setTimeout wasn't available but was latter defined | ||
94913 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | ||
94914 | cachedSetTimeout = setTimeout; | ||
94915 | return setTimeout(fun, 0); | ||
94916 | } | ||
94917 | try { | ||
94918 | // when when somebody has screwed with setTimeout but no I.E. maddness | ||
94919 | return cachedSetTimeout(fun, 0); | ||
94920 | } catch(e){ | ||
94921 | try { | ||
94922 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
94923 | return cachedSetTimeout.call(null, fun, 0); | ||
94924 | } catch(e){ | ||
94925 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error | ||
94926 | return cachedSetTimeout.call(this, fun, 0); | ||
94927 | } | ||
94928 | } | ||
94929 | |||
94930 | |||
94931 | } | ||
94932 | function runClearTimeout(marker) { | ||
94933 | if (cachedClearTimeout === clearTimeout) { | ||
94934 | //normal enviroments in sane situations | ||
94935 | return clearTimeout(marker); | ||
94936 | } | ||
94937 | // if clearTimeout wasn't available but was latter defined | ||
94938 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | ||
94939 | cachedClearTimeout = clearTimeout; | ||
94940 | return clearTimeout(marker); | ||
94941 | } | ||
94942 | try { | ||
94943 | // when when somebody has screwed with setTimeout but no I.E. maddness | ||
94944 | return cachedClearTimeout(marker); | ||
94945 | } catch (e){ | ||
94946 | try { | ||
94947 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
94948 | return cachedClearTimeout.call(null, marker); | ||
94949 | } catch (e){ | ||
94950 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. | ||
94951 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout | ||
94952 | return cachedClearTimeout.call(this, marker); | ||
94953 | } | ||
94954 | } | ||
94955 | |||
94956 | |||
94957 | |||
94958 | } | ||
94959 | var queue = []; | ||
94960 | var draining = false; | ||
94961 | var currentQueue; | ||
94962 | var queueIndex = -1; | ||
94963 | |||
94964 | function cleanUpNextTick() { | ||
94965 | if (!draining || !currentQueue) { | ||
94966 | return; | ||
94967 | } | ||
94968 | draining = false; | ||
94969 | if (currentQueue.length) { | ||
94970 | queue = currentQueue.concat(queue); | ||
94971 | } else { | ||
94972 | queueIndex = -1; | ||
94973 | } | ||
94974 | if (queue.length) { | ||
94975 | drainQueue(); | ||
94976 | } | ||
94977 | } | ||
94978 | |||
94979 | function drainQueue() { | ||
94980 | if (draining) { | ||
94981 | return; | ||
94982 | } | ||
94983 | var timeout = runTimeout(cleanUpNextTick); | ||
94984 | draining = true; | ||
94985 | |||
94986 | var len = queue.length; | ||
94987 | while(len) { | ||
94988 | currentQueue = queue; | ||
94989 | queue = []; | ||
94990 | while (++queueIndex < len) { | ||
94991 | if (currentQueue) { | ||
94992 | currentQueue[queueIndex].run(); | ||
94993 | } | ||
94994 | } | ||
94995 | queueIndex = -1; | ||
94996 | len = queue.length; | ||
94997 | } | ||
94998 | currentQueue = null; | ||
94999 | draining = false; | ||
95000 | runClearTimeout(timeout); | ||
95001 | } | ||
95002 | |||
95003 | process.nextTick = function (fun) { | ||
95004 | var args = new Array(arguments.length - 1); | ||
95005 | if (arguments.length > 1) { | ||
95006 | for (var i = 1; i < arguments.length; i++) { | ||
95007 | args[i - 1] = arguments[i]; | ||
95008 | } | ||
95009 | } | ||
95010 | queue.push(new Item(fun, args)); | ||
95011 | if (queue.length === 1 && !draining) { | ||
95012 | runTimeout(drainQueue); | ||
95013 | } | ||
95014 | }; | ||
95015 | |||
95016 | // v8 likes predictible objects | ||
95017 | function Item(fun, array) { | ||
95018 | this.fun = fun; | ||
95019 | this.array = array; | ||
95020 | } | ||
95021 | Item.prototype.run = function () { | ||
95022 | this.fun.apply(null, this.array); | ||
95023 | }; | ||
95024 | process.title = 'browser'; | ||
95025 | process.browser = true; | ||
95026 | process.env = {}; | ||
95027 | process.argv = []; | ||
95028 | process.version = ''; // empty string to avoid regexp issues | ||
95029 | process.versions = {}; | ||
95030 | |||
95031 | function noop() {} | ||
95032 | |||
95033 | process.on = noop; | ||
95034 | process.addListener = noop; | ||
95035 | process.once = noop; | ||
95036 | process.off = noop; | ||
95037 | process.removeListener = noop; | ||
95038 | process.removeAllListeners = noop; | ||
95039 | process.emit = noop; | ||
95040 | process.prependListener = noop; | ||
95041 | process.prependOnceListener = noop; | ||
95042 | |||
95043 | process.listeners = function (name) { return [] } | ||
95044 | |||
95045 | process.binding = function (name) { | ||
95046 | throw new Error('process.binding is not supported'); | ||
95047 | }; | ||
95048 | |||
95049 | process.cwd = function () { return '/' }; | ||
95050 | process.chdir = function (dir) { | ||
95051 | throw new Error('process.chdir is not supported'); | ||
95052 | }; | ||
95053 | process.umask = function() { return 0; }; | ||
95054 | |||
95055 | },{}],26:[function(require,module,exports){ | ||
95056 | module.exports = require('./lib/_stream_duplex.js'); | ||
95057 | |||
95058 | },{"./lib/_stream_duplex.js":27}],27:[function(require,module,exports){ | ||
95059 | // Copyright Joyent, Inc. and other Node contributors. | ||
95060 | // | ||
95061 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
95062 | // copy of this software and associated documentation files (the | ||
95063 | // "Software"), to deal in the Software without restriction, including | ||
95064 | // without limitation the rights to use, copy, modify, merge, publish, | ||
95065 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
95066 | // persons to whom the Software is furnished to do so, subject to the | ||
95067 | // following conditions: | ||
95068 | // | ||
95069 | // The above copyright notice and this permission notice shall be included | ||
95070 | // in all copies or substantial portions of the Software. | ||
95071 | // | ||
95072 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
95073 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
95074 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
95075 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
95076 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
95077 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
95078 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
95079 | |||
95080 | // a duplex stream is just a stream that is both readable and writable. | ||
95081 | // Since JS doesn't have multiple prototypal inheritance, this class | ||
95082 | // prototypally inherits from Readable, and then parasitically from | ||
95083 | // Writable. | ||
95084 | |||
95085 | 'use strict'; | ||
95086 | |||
95087 | /*<replacement>*/ | ||
95088 | |||
95089 | var processNextTick = require('process-nextick-args'); | ||
95090 | /*</replacement>*/ | ||
95091 | |||
95092 | /*<replacement>*/ | ||
95093 | var objectKeys = Object.keys || function (obj) { | ||
95094 | var keys = []; | ||
95095 | for (var key in obj) { | ||
95096 | keys.push(key); | ||
95097 | }return keys; | ||
95098 | }; | ||
95099 | /*</replacement>*/ | ||
95100 | |||
95101 | module.exports = Duplex; | ||
95102 | |||
95103 | /*<replacement>*/ | ||
95104 | var util = require('core-util-is'); | ||
95105 | util.inherits = require('inherits'); | ||
95106 | /*</replacement>*/ | ||
95107 | |||
95108 | var Readable = require('./_stream_readable'); | ||
95109 | var Writable = require('./_stream_writable'); | ||
95110 | |||
95111 | util.inherits(Duplex, Readable); | ||
95112 | |||
95113 | var keys = objectKeys(Writable.prototype); | ||
95114 | for (var v = 0; v < keys.length; v++) { | ||
95115 | var method = keys[v]; | ||
95116 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; | ||
95117 | } | ||
95118 | |||
95119 | function Duplex(options) { | ||
95120 | if (!(this instanceof Duplex)) return new Duplex(options); | ||
95121 | |||
95122 | Readable.call(this, options); | ||
95123 | Writable.call(this, options); | ||
95124 | |||
95125 | if (options && options.readable === false) this.readable = false; | ||
95126 | |||
95127 | if (options && options.writable === false) this.writable = false; | ||
95128 | |||
95129 | this.allowHalfOpen = true; | ||
95130 | if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; | ||
95131 | |||
95132 | this.once('end', onend); | ||
95133 | } | ||
95134 | |||
95135 | // the no-half-open enforcer | ||
95136 | function onend() { | ||
95137 | // if we allow half-open state, or if the writable side ended, | ||
95138 | // then we're ok. | ||
95139 | if (this.allowHalfOpen || this._writableState.ended) return; | ||
95140 | |||
95141 | // no more data can be written. | ||
95142 | // But allow more writes to happen in this tick. | ||
95143 | processNextTick(onEndNT, this); | ||
95144 | } | ||
95145 | |||
95146 | function onEndNT(self) { | ||
95147 | self.end(); | ||
95148 | } | ||
95149 | |||
95150 | Object.defineProperty(Duplex.prototype, 'destroyed', { | ||
95151 | get: function () { | ||
95152 | if (this._readableState === undefined || this._writableState === undefined) { | ||
95153 | return false; | ||
95154 | } | ||
95155 | return this._readableState.destroyed && this._writableState.destroyed; | ||
95156 | }, | ||
95157 | set: function (value) { | ||
95158 | // we ignore the value if the stream | ||
95159 | // has not been initialized yet | ||
95160 | if (this._readableState === undefined || this._writableState === undefined) { | ||
95161 | return; | ||
95162 | } | ||
95163 | |||
95164 | // backward compatibility, the user is explicitly | ||
95165 | // managing destroyed | ||
95166 | this._readableState.destroyed = value; | ||
95167 | this._writableState.destroyed = value; | ||
95168 | } | ||
95169 | }); | ||
95170 | |||
95171 | Duplex.prototype._destroy = function (err, cb) { | ||
95172 | this.push(null); | ||
95173 | this.end(); | ||
95174 | |||
95175 | processNextTick(cb, err); | ||
95176 | }; | ||
95177 | |||
95178 | function forEach(xs, f) { | ||
95179 | for (var i = 0, l = xs.length; i < l; i++) { | ||
95180 | f(xs[i], i); | ||
95181 | } | ||
95182 | } | ||
95183 | },{"./_stream_readable":29,"./_stream_writable":31,"core-util-is":14,"inherits":21,"process-nextick-args":24}],28:[function(require,module,exports){ | ||
95184 | // Copyright Joyent, Inc. and other Node contributors. | ||
95185 | // | ||
95186 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
95187 | // copy of this software and associated documentation files (the | ||
95188 | // "Software"), to deal in the Software without restriction, including | ||
95189 | // without limitation the rights to use, copy, modify, merge, publish, | ||
95190 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
95191 | // persons to whom the Software is furnished to do so, subject to the | ||
95192 | // following conditions: | ||
95193 | // | ||
95194 | // The above copyright notice and this permission notice shall be included | ||
95195 | // in all copies or substantial portions of the Software. | ||
95196 | // | ||
95197 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
95198 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
95199 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
95200 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
95201 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
95202 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
95203 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
95204 | |||
95205 | // a passthrough stream. | ||
95206 | // basically just the most minimal sort of Transform stream. | ||
95207 | // Every written chunk gets output as-is. | ||
95208 | |||
95209 | 'use strict'; | ||
95210 | |||
95211 | module.exports = PassThrough; | ||
95212 | |||
95213 | var Transform = require('./_stream_transform'); | ||
95214 | |||
95215 | /*<replacement>*/ | ||
95216 | var util = require('core-util-is'); | ||
95217 | util.inherits = require('inherits'); | ||
95218 | /*</replacement>*/ | ||
95219 | |||
95220 | util.inherits(PassThrough, Transform); | ||
95221 | |||
95222 | function PassThrough(options) { | ||
95223 | if (!(this instanceof PassThrough)) return new PassThrough(options); | ||
95224 | |||
95225 | Transform.call(this, options); | ||
95226 | } | ||
95227 | |||
95228 | PassThrough.prototype._transform = function (chunk, encoding, cb) { | ||
95229 | cb(null, chunk); | ||
95230 | }; | ||
95231 | },{"./_stream_transform":30,"core-util-is":14,"inherits":21}],29:[function(require,module,exports){ | ||
95232 | (function (process,global){ | ||
95233 | // Copyright Joyent, Inc. and other Node contributors. | ||
95234 | // | ||
95235 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
95236 | // copy of this software and associated documentation files (the | ||
95237 | // "Software"), to deal in the Software without restriction, including | ||
95238 | // without limitation the rights to use, copy, modify, merge, publish, | ||
95239 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
95240 | // persons to whom the Software is furnished to do so, subject to the | ||
95241 | // following conditions: | ||
95242 | // | ||
95243 | // The above copyright notice and this permission notice shall be included | ||
95244 | // in all copies or substantial portions of the Software. | ||
95245 | // | ||
95246 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
95247 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
95248 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
95249 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
95250 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
95251 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
95252 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
95253 | |||
95254 | 'use strict'; | ||
95255 | |||
95256 | /*<replacement>*/ | ||
95257 | |||
95258 | var processNextTick = require('process-nextick-args'); | ||
95259 | /*</replacement>*/ | ||
95260 | |||
95261 | module.exports = Readable; | ||
95262 | |||
95263 | /*<replacement>*/ | ||
95264 | var isArray = require('isarray'); | ||
95265 | /*</replacement>*/ | ||
95266 | |||
95267 | /*<replacement>*/ | ||
95268 | var Duplex; | ||
95269 | /*</replacement>*/ | ||
95270 | |||
95271 | Readable.ReadableState = ReadableState; | ||
95272 | |||
95273 | /*<replacement>*/ | ||
95274 | var EE = require('events').EventEmitter; | ||
95275 | |||
95276 | var EElistenerCount = function (emitter, type) { | ||
95277 | return emitter.listeners(type).length; | ||
95278 | }; | ||
95279 | /*</replacement>*/ | ||
95280 | |||
95281 | /*<replacement>*/ | ||
95282 | var Stream = require('./internal/streams/stream'); | ||
95283 | /*</replacement>*/ | ||
95284 | |||
95285 | // TODO(bmeurer): Change this back to const once hole checks are | ||
95286 | // properly optimized away early in Ignition+TurboFan. | ||
95287 | /*<replacement>*/ | ||
95288 | var Buffer = require('safe-buffer').Buffer; | ||
95289 | var OurUint8Array = global.Uint8Array || function () {}; | ||
95290 | function _uint8ArrayToBuffer(chunk) { | ||
95291 | return Buffer.from(chunk); | ||
95292 | } | ||
95293 | function _isUint8Array(obj) { | ||
95294 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; | ||
95295 | } | ||
95296 | /*</replacement>*/ | ||
95297 | |||
95298 | /*<replacement>*/ | ||
95299 | var util = require('core-util-is'); | ||
95300 | util.inherits = require('inherits'); | ||
95301 | /*</replacement>*/ | ||
95302 | |||
95303 | /*<replacement>*/ | ||
95304 | var debugUtil = require('util'); | ||
95305 | var debug = void 0; | ||
95306 | if (debugUtil && debugUtil.debuglog) { | ||
95307 | debug = debugUtil.debuglog('stream'); | ||
95308 | } else { | ||
95309 | debug = function () {}; | ||
95310 | } | ||
95311 | /*</replacement>*/ | ||
95312 | |||
95313 | var BufferList = require('./internal/streams/BufferList'); | ||
95314 | var destroyImpl = require('./internal/streams/destroy'); | ||
95315 | var StringDecoder; | ||
95316 | |||
95317 | util.inherits(Readable, Stream); | ||
95318 | |||
95319 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; | ||
95320 | |||
95321 | function prependListener(emitter, event, fn) { | ||
95322 | // Sadly this is not cacheable as some libraries bundle their own | ||
95323 | // event emitter implementation with them. | ||
95324 | if (typeof emitter.prependListener === 'function') { | ||
95325 | return emitter.prependListener(event, fn); | ||
95326 | } else { | ||
95327 | // This is a hack to make sure that our error handler is attached before any | ||
95328 | // userland ones. NEVER DO THIS. This is here only because this code needs | ||
95329 | // to continue to work with older versions of Node.js that do not include | ||
95330 | // the prependListener() method. The goal is to eventually remove this hack. | ||
95331 | if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; | ||
95332 | } | ||
95333 | } | ||
95334 | |||
95335 | function ReadableState(options, stream) { | ||
95336 | Duplex = Duplex || require('./_stream_duplex'); | ||
95337 | |||
95338 | options = options || {}; | ||
95339 | |||
95340 | // object stream flag. Used to make read(n) ignore n and to | ||
95341 | // make all the buffer merging and length checks go away | ||
95342 | this.objectMode = !!options.objectMode; | ||
95343 | |||
95344 | if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; | ||
95345 | |||
95346 | // the point at which it stops calling _read() to fill the buffer | ||
95347 | // Note: 0 is a valid value, means "don't call _read preemptively ever" | ||
95348 | var hwm = options.highWaterMark; | ||
95349 | var defaultHwm = this.objectMode ? 16 : 16 * 1024; | ||
95350 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | ||
95351 | |||
95352 | // cast to ints. | ||
95353 | this.highWaterMark = Math.floor(this.highWaterMark); | ||
95354 | |||
95355 | // A linked list is used to store data chunks instead of an array because the | ||
95356 | // linked list can remove elements from the beginning faster than | ||
95357 | // array.shift() | ||
95358 | this.buffer = new BufferList(); | ||
95359 | this.length = 0; | ||
95360 | this.pipes = null; | ||
95361 | this.pipesCount = 0; | ||
95362 | this.flowing = null; | ||
95363 | this.ended = false; | ||
95364 | this.endEmitted = false; | ||
95365 | this.reading = false; | ||
95366 | |||
95367 | // a flag to be able to tell if the event 'readable'/'data' is emitted | ||
95368 | // immediately, or on a later tick. We set this to true at first, because | ||
95369 | // any actions that shouldn't happen until "later" should generally also | ||
95370 | // not happen before the first read call. | ||
95371 | this.sync = true; | ||
95372 | |||
95373 | // whenever we return null, then we set a flag to say | ||
95374 | // that we're awaiting a 'readable' event emission. | ||
95375 | this.needReadable = false; | ||
95376 | this.emittedReadable = false; | ||
95377 | this.readableListening = false; | ||
95378 | this.resumeScheduled = false; | ||
95379 | |||
95380 | // has it been destroyed | ||
95381 | this.destroyed = false; | ||
95382 | |||
95383 | // Crypto is kind of old and crusty. Historically, its default string | ||
95384 | // encoding is 'binary' so we have to make this configurable. | ||
95385 | // Everything else in the universe uses 'utf8', though. | ||
95386 | this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
95387 | |||
95388 | // the number of writers that are awaiting a drain event in .pipe()s | ||
95389 | this.awaitDrain = 0; | ||
95390 | |||
95391 | // if true, a maybeReadMore has been scheduled | ||
95392 | this.readingMore = false; | ||
95393 | |||
95394 | this.decoder = null; | ||
95395 | this.encoding = null; | ||
95396 | if (options.encoding) { | ||
95397 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | ||
95398 | this.decoder = new StringDecoder(options.encoding); | ||
95399 | this.encoding = options.encoding; | ||
95400 | } | ||
95401 | } | ||
95402 | |||
95403 | function Readable(options) { | ||
95404 | Duplex = Duplex || require('./_stream_duplex'); | ||
95405 | |||
95406 | if (!(this instanceof Readable)) return new Readable(options); | ||
95407 | |||
95408 | this._readableState = new ReadableState(options, this); | ||
95409 | |||
95410 | // legacy | ||
95411 | this.readable = true; | ||
95412 | |||
95413 | if (options) { | ||
95414 | if (typeof options.read === 'function') this._read = options.read; | ||
95415 | |||
95416 | if (typeof options.destroy === 'function') this._destroy = options.destroy; | ||
95417 | } | ||
95418 | |||
95419 | Stream.call(this); | ||
95420 | } | ||
95421 | |||
95422 | Object.defineProperty(Readable.prototype, 'destroyed', { | ||
95423 | get: function () { | ||
95424 | if (this._readableState === undefined) { | ||
95425 | return false; | ||
95426 | } | ||
95427 | return this._readableState.destroyed; | ||
95428 | }, | ||
95429 | set: function (value) { | ||
95430 | // we ignore the value if the stream | ||
95431 | // has not been initialized yet | ||
95432 | if (!this._readableState) { | ||
95433 | return; | ||
95434 | } | ||
95435 | |||
95436 | // backward compatibility, the user is explicitly | ||
95437 | // managing destroyed | ||
95438 | this._readableState.destroyed = value; | ||
95439 | } | ||
95440 | }); | ||
95441 | |||
95442 | Readable.prototype.destroy = destroyImpl.destroy; | ||
95443 | Readable.prototype._undestroy = destroyImpl.undestroy; | ||
95444 | Readable.prototype._destroy = function (err, cb) { | ||
95445 | this.push(null); | ||
95446 | cb(err); | ||
95447 | }; | ||
95448 | |||
95449 | // Manually shove something into the read() buffer. | ||
95450 | // This returns true if the highWaterMark has not been hit yet, | ||
95451 | // similar to how Writable.write() returns true if you should | ||
95452 | // write() some more. | ||
95453 | Readable.prototype.push = function (chunk, encoding) { | ||
95454 | var state = this._readableState; | ||
95455 | var skipChunkCheck; | ||
95456 | |||
95457 | if (!state.objectMode) { | ||
95458 | if (typeof chunk === 'string') { | ||
95459 | encoding = encoding || state.defaultEncoding; | ||
95460 | if (encoding !== state.encoding) { | ||
95461 | chunk = Buffer.from(chunk, encoding); | ||
95462 | encoding = ''; | ||
95463 | } | ||
95464 | skipChunkCheck = true; | ||
95465 | } | ||
95466 | } else { | ||
95467 | skipChunkCheck = true; | ||
95468 | } | ||
95469 | |||
95470 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); | ||
95471 | }; | ||
95472 | |||
95473 | // Unshift should *always* be something directly out of read() | ||
95474 | Readable.prototype.unshift = function (chunk) { | ||
95475 | return readableAddChunk(this, chunk, null, true, false); | ||
95476 | }; | ||
95477 | |||
95478 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { | ||
95479 | var state = stream._readableState; | ||
95480 | if (chunk === null) { | ||
95481 | state.reading = false; | ||
95482 | onEofChunk(stream, state); | ||
95483 | } else { | ||
95484 | var er; | ||
95485 | if (!skipChunkCheck) er = chunkInvalid(state, chunk); | ||
95486 | if (er) { | ||
95487 | stream.emit('error', er); | ||
95488 | } else if (state.objectMode || chunk && chunk.length > 0) { | ||
95489 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { | ||
95490 | chunk = _uint8ArrayToBuffer(chunk); | ||
95491 | } | ||
95492 | |||
95493 | if (addToFront) { | ||
95494 | if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true); | ||
95495 | } else if (state.ended) { | ||
95496 | stream.emit('error', new Error('stream.push() after EOF')); | ||
95497 | } else { | ||
95498 | state.reading = false; | ||
95499 | if (state.decoder && !encoding) { | ||
95500 | chunk = state.decoder.write(chunk); | ||
95501 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); | ||
95502 | } else { | ||
95503 | addChunk(stream, state, chunk, false); | ||
95504 | } | ||
95505 | } | ||
95506 | } else if (!addToFront) { | ||
95507 | state.reading = false; | ||
95508 | } | ||
95509 | } | ||
95510 | |||
95511 | return needMoreData(state); | ||
95512 | } | ||
95513 | |||
95514 | function addChunk(stream, state, chunk, addToFront) { | ||
95515 | if (state.flowing && state.length === 0 && !state.sync) { | ||
95516 | stream.emit('data', chunk); | ||
95517 | stream.read(0); | ||
95518 | } else { | ||
95519 | // update the buffer info. | ||
95520 | state.length += state.objectMode ? 1 : chunk.length; | ||
95521 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); | ||
95522 | |||
95523 | if (state.needReadable) emitReadable(stream); | ||
95524 | } | ||
95525 | maybeReadMore(stream, state); | ||
95526 | } | ||
95527 | |||
95528 | function chunkInvalid(state, chunk) { | ||
95529 | var er; | ||
95530 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { | ||
95531 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
95532 | } | ||
95533 | return er; | ||
95534 | } | ||
95535 | |||
95536 | // if it's past the high water mark, we can push in some more. | ||
95537 | // Also, if we have no data yet, we can stand some | ||
95538 | // more bytes. This is to work around cases where hwm=0, | ||
95539 | // such as the repl. Also, if the push() triggered a | ||
95540 | // readable event, and the user called read(largeNumber) such that | ||
95541 | // needReadable was set, then we ought to push more, so that another | ||
95542 | // 'readable' event will be triggered. | ||
95543 | function needMoreData(state) { | ||
95544 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); | ||
95545 | } | ||
95546 | |||
95547 | Readable.prototype.isPaused = function () { | ||
95548 | return this._readableState.flowing === false; | ||
95549 | }; | ||
95550 | |||
95551 | // backwards compatibility. | ||
95552 | Readable.prototype.setEncoding = function (enc) { | ||
95553 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | ||
95554 | this._readableState.decoder = new StringDecoder(enc); | ||
95555 | this._readableState.encoding = enc; | ||
95556 | return this; | ||
95557 | }; | ||
95558 | |||
95559 | // Don't raise the hwm > 8MB | ||
95560 | var MAX_HWM = 0x800000; | ||
95561 | function computeNewHighWaterMark(n) { | ||
95562 | if (n >= MAX_HWM) { | ||
95563 | n = MAX_HWM; | ||
95564 | } else { | ||
95565 | // Get the next highest power of 2 to prevent increasing hwm excessively in | ||
95566 | // tiny amounts | ||
95567 | n--; | ||
95568 | n |= n >>> 1; | ||
95569 | n |= n >>> 2; | ||
95570 | n |= n >>> 4; | ||
95571 | n |= n >>> 8; | ||
95572 | n |= n >>> 16; | ||
95573 | n++; | ||
95574 | } | ||
95575 | return n; | ||
95576 | } | ||
95577 | |||
95578 | // This function is designed to be inlinable, so please take care when making | ||
95579 | // changes to the function body. | ||
95580 | function howMuchToRead(n, state) { | ||
95581 | if (n <= 0 || state.length === 0 && state.ended) return 0; | ||
95582 | if (state.objectMode) return 1; | ||
95583 | if (n !== n) { | ||
95584 | // Only flow one buffer at a time | ||
95585 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; | ||
95586 | } | ||
95587 | // If we're asking for more than the current hwm, then raise the hwm. | ||
95588 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); | ||
95589 | if (n <= state.length) return n; | ||
95590 | // Don't have enough | ||
95591 | if (!state.ended) { | ||
95592 | state.needReadable = true; | ||
95593 | return 0; | ||
95594 | } | ||
95595 | return state.length; | ||
95596 | } | ||
95597 | |||
95598 | // you can override either this method, or the async _read(n) below. | ||
95599 | Readable.prototype.read = function (n) { | ||
95600 | debug('read', n); | ||
95601 | n = parseInt(n, 10); | ||
95602 | var state = this._readableState; | ||
95603 | var nOrig = n; | ||
95604 | |||
95605 | if (n !== 0) state.emittedReadable = false; | ||
95606 | |||
95607 | // if we're doing read(0) to trigger a readable event, but we | ||
95608 | // already have a bunch of data in the buffer, then just trigger | ||
95609 | // the 'readable' event and move on. | ||
95610 | if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { | ||
95611 | debug('read: emitReadable', state.length, state.ended); | ||
95612 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); | ||
95613 | return null; | ||
95614 | } | ||
95615 | |||
95616 | n = howMuchToRead(n, state); | ||
95617 | |||
95618 | // if we've ended, and we're now clear, then finish it up. | ||
95619 | if (n === 0 && state.ended) { | ||
95620 | if (state.length === 0) endReadable(this); | ||
95621 | return null; | ||
95622 | } | ||
95623 | |||
95624 | // All the actual chunk generation logic needs to be | ||
95625 | // *below* the call to _read. The reason is that in certain | ||
95626 | // synthetic stream cases, such as passthrough streams, _read | ||
95627 | // may be a completely synchronous operation which may change | ||
95628 | // the state of the read buffer, providing enough data when | ||
95629 | // before there was *not* enough. | ||
95630 | // | ||
95631 | // So, the steps are: | ||
95632 | // 1. Figure out what the state of things will be after we do | ||
95633 | // a read from the buffer. | ||
95634 | // | ||
95635 | // 2. If that resulting state will trigger a _read, then call _read. | ||
95636 | // Note that this may be asynchronous, or synchronous. Yes, it is | ||
95637 | // deeply ugly to write APIs this way, but that still doesn't mean | ||
95638 | // that the Readable class should behave improperly, as streams are | ||
95639 | // designed to be sync/async agnostic. | ||
95640 | // Take note if the _read call is sync or async (ie, if the read call | ||
95641 | // has returned yet), so that we know whether or not it's safe to emit | ||
95642 | // 'readable' etc. | ||
95643 | // | ||
95644 | // 3. Actually pull the requested chunks out of the buffer and return. | ||
95645 | |||
95646 | // if we need a readable event, then we need to do some reading. | ||
95647 | var doRead = state.needReadable; | ||
95648 | debug('need readable', doRead); | ||
95649 | |||
95650 | // if we currently have less than the highWaterMark, then also read some | ||
95651 | if (state.length === 0 || state.length - n < state.highWaterMark) { | ||
95652 | doRead = true; | ||
95653 | debug('length less than watermark', doRead); | ||
95654 | } | ||
95655 | |||
95656 | // however, if we've ended, then there's no point, and if we're already | ||
95657 | // reading, then it's unnecessary. | ||
95658 | if (state.ended || state.reading) { | ||
95659 | doRead = false; | ||
95660 | debug('reading or ended', doRead); | ||
95661 | } else if (doRead) { | ||
95662 | debug('do read'); | ||
95663 | state.reading = true; | ||
95664 | state.sync = true; | ||
95665 | // if the length is currently zero, then we *need* a readable event. | ||
95666 | if (state.length === 0) state.needReadable = true; | ||
95667 | // call internal read method | ||
95668 | this._read(state.highWaterMark); | ||
95669 | state.sync = false; | ||
95670 | // If _read pushed data synchronously, then `reading` will be false, | ||
95671 | // and we need to re-evaluate how much data we can return to the user. | ||
95672 | if (!state.reading) n = howMuchToRead(nOrig, state); | ||
95673 | } | ||
95674 | |||
95675 | var ret; | ||
95676 | if (n > 0) ret = fromList(n, state);else ret = null; | ||
95677 | |||
95678 | if (ret === null) { | ||
95679 | state.needReadable = true; | ||
95680 | n = 0; | ||
95681 | } else { | ||
95682 | state.length -= n; | ||
95683 | } | ||
95684 | |||
95685 | if (state.length === 0) { | ||
95686 | // If we have nothing in the buffer, then we want to know | ||
95687 | // as soon as we *do* get something into the buffer. | ||
95688 | if (!state.ended) state.needReadable = true; | ||
95689 | |||
95690 | // If we tried to read() past the EOF, then emit end on the next tick. | ||
95691 | if (nOrig !== n && state.ended) endReadable(this); | ||
95692 | } | ||
95693 | |||
95694 | if (ret !== null) this.emit('data', ret); | ||
95695 | |||
95696 | return ret; | ||
95697 | }; | ||
95698 | |||
95699 | function onEofChunk(stream, state) { | ||
95700 | if (state.ended) return; | ||
95701 | if (state.decoder) { | ||
95702 | var chunk = state.decoder.end(); | ||
95703 | if (chunk && chunk.length) { | ||
95704 | state.buffer.push(chunk); | ||
95705 | state.length += state.objectMode ? 1 : chunk.length; | ||
95706 | } | ||
95707 | } | ||
95708 | state.ended = true; | ||
95709 | |||
95710 | // emit 'readable' now to make sure it gets picked up. | ||
95711 | emitReadable(stream); | ||
95712 | } | ||
95713 | |||
95714 | // Don't emit readable right away in sync mode, because this can trigger | ||
95715 | // another read() call => stack overflow. This way, it might trigger | ||
95716 | // a nextTick recursion warning, but that's not so bad. | ||
95717 | function emitReadable(stream) { | ||
95718 | var state = stream._readableState; | ||
95719 | state.needReadable = false; | ||
95720 | if (!state.emittedReadable) { | ||
95721 | debug('emitReadable', state.flowing); | ||
95722 | state.emittedReadable = true; | ||
95723 | if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); | ||
95724 | } | ||
95725 | } | ||
95726 | |||
95727 | function emitReadable_(stream) { | ||
95728 | debug('emit readable'); | ||
95729 | stream.emit('readable'); | ||
95730 | flow(stream); | ||
95731 | } | ||
95732 | |||
95733 | // at this point, the user has presumably seen the 'readable' event, | ||
95734 | // and called read() to consume some data. that may have triggered | ||
95735 | // in turn another _read(n) call, in which case reading = true if | ||
95736 | // it's in progress. | ||
95737 | // However, if we're not ended, or reading, and the length < hwm, | ||
95738 | // then go ahead and try to read some more preemptively. | ||
95739 | function maybeReadMore(stream, state) { | ||
95740 | if (!state.readingMore) { | ||
95741 | state.readingMore = true; | ||
95742 | processNextTick(maybeReadMore_, stream, state); | ||
95743 | } | ||
95744 | } | ||
95745 | |||
95746 | function maybeReadMore_(stream, state) { | ||
95747 | var len = state.length; | ||
95748 | while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { | ||
95749 | debug('maybeReadMore read 0'); | ||
95750 | stream.read(0); | ||
95751 | if (len === state.length) | ||
95752 | // didn't get any data, stop spinning. | ||
95753 | break;else len = state.length; | ||
95754 | } | ||
95755 | state.readingMore = false; | ||
95756 | } | ||
95757 | |||
95758 | // abstract method. to be overridden in specific implementation classes. | ||
95759 | // call cb(er, data) where data is <= n in length. | ||
95760 | // for virtual (non-string, non-buffer) streams, "length" is somewhat | ||
95761 | // arbitrary, and perhaps not very meaningful. | ||
95762 | Readable.prototype._read = function (n) { | ||
95763 | this.emit('error', new Error('_read() is not implemented')); | ||
95764 | }; | ||
95765 | |||
95766 | Readable.prototype.pipe = function (dest, pipeOpts) { | ||
95767 | var src = this; | ||
95768 | var state = this._readableState; | ||
95769 | |||
95770 | switch (state.pipesCount) { | ||
95771 | case 0: | ||
95772 | state.pipes = dest; | ||
95773 | break; | ||
95774 | case 1: | ||
95775 | state.pipes = [state.pipes, dest]; | ||
95776 | break; | ||
95777 | default: | ||
95778 | state.pipes.push(dest); | ||
95779 | break; | ||
95780 | } | ||
95781 | state.pipesCount += 1; | ||
95782 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); | ||
95783 | |||
95784 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; | ||
95785 | |||
95786 | var endFn = doEnd ? onend : unpipe; | ||
95787 | if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); | ||
95788 | |||
95789 | dest.on('unpipe', onunpipe); | ||
95790 | function onunpipe(readable, unpipeInfo) { | ||
95791 | debug('onunpipe'); | ||
95792 | if (readable === src) { | ||
95793 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) { | ||
95794 | unpipeInfo.hasUnpiped = true; | ||
95795 | cleanup(); | ||
95796 | } | ||
95797 | } | ||
95798 | } | ||
95799 | |||
95800 | function onend() { | ||
95801 | debug('onend'); | ||
95802 | dest.end(); | ||
95803 | } | ||
95804 | |||
95805 | // when the dest drains, it reduces the awaitDrain counter | ||
95806 | // on the source. This would be more elegant with a .once() | ||
95807 | // handler in flow(), but adding and removing repeatedly is | ||
95808 | // too slow. | ||
95809 | var ondrain = pipeOnDrain(src); | ||
95810 | dest.on('drain', ondrain); | ||
95811 | |||
95812 | var cleanedUp = false; | ||
95813 | function cleanup() { | ||
95814 | debug('cleanup'); | ||
95815 | // cleanup event handlers once the pipe is broken | ||
95816 | dest.removeListener('close', onclose); | ||
95817 | dest.removeListener('finish', onfinish); | ||
95818 | dest.removeListener('drain', ondrain); | ||
95819 | dest.removeListener('error', onerror); | ||
95820 | dest.removeListener('unpipe', onunpipe); | ||
95821 | src.removeListener('end', onend); | ||
95822 | src.removeListener('end', unpipe); | ||
95823 | src.removeListener('data', ondata); | ||
95824 | |||
95825 | cleanedUp = true; | ||
95826 | |||
95827 | // if the reader is waiting for a drain event from this | ||
95828 | // specific writer, then it would cause it to never start | ||
95829 | // flowing again. | ||
95830 | // So, if this is awaiting a drain, then we just call it now. | ||
95831 | // If we don't know, then assume that we are waiting for one. | ||
95832 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); | ||
95833 | } | ||
95834 | |||
95835 | // If the user pushes more data while we're writing to dest then we'll end up | ||
95836 | // in ondata again. However, we only want to increase awaitDrain once because | ||
95837 | // dest will only emit one 'drain' event for the multiple writes. | ||
95838 | // => Introduce a guard on increasing awaitDrain. | ||
95839 | var increasedAwaitDrain = false; | ||
95840 | src.on('data', ondata); | ||
95841 | function ondata(chunk) { | ||
95842 | debug('ondata'); | ||
95843 | increasedAwaitDrain = false; | ||
95844 | var ret = dest.write(chunk); | ||
95845 | if (false === ret && !increasedAwaitDrain) { | ||
95846 | // If the user unpiped during `dest.write()`, it is possible | ||
95847 | // to get stuck in a permanently paused state if that write | ||
95848 | // also returned false. | ||
95849 | // => Check whether `dest` is still a piping destination. | ||
95850 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { | ||
95851 | debug('false write response, pause', src._readableState.awaitDrain); | ||
95852 | src._readableState.awaitDrain++; | ||
95853 | increasedAwaitDrain = true; | ||
95854 | } | ||
95855 | src.pause(); | ||
95856 | } | ||
95857 | } | ||
95858 | |||
95859 | // if the dest has an error, then stop piping into it. | ||
95860 | // however, don't suppress the throwing behavior for this. | ||
95861 | function onerror(er) { | ||
95862 | debug('onerror', er); | ||
95863 | unpipe(); | ||
95864 | dest.removeListener('error', onerror); | ||
95865 | if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); | ||
95866 | } | ||
95867 | |||
95868 | // Make sure our error handler is attached before userland ones. | ||
95869 | prependListener(dest, 'error', onerror); | ||
95870 | |||
95871 | // Both close and finish should trigger unpipe, but only once. | ||
95872 | function onclose() { | ||
95873 | dest.removeListener('finish', onfinish); | ||
95874 | unpipe(); | ||
95875 | } | ||
95876 | dest.once('close', onclose); | ||
95877 | function onfinish() { | ||
95878 | debug('onfinish'); | ||
95879 | dest.removeListener('close', onclose); | ||
95880 | unpipe(); | ||
95881 | } | ||
95882 | dest.once('finish', onfinish); | ||
95883 | |||
95884 | function unpipe() { | ||
95885 | debug('unpipe'); | ||
95886 | src.unpipe(dest); | ||
95887 | } | ||
95888 | |||
95889 | // tell the dest that it's being piped to | ||
95890 | dest.emit('pipe', src); | ||
95891 | |||
95892 | // start the flow if it hasn't been started already. | ||
95893 | if (!state.flowing) { | ||
95894 | debug('pipe resume'); | ||
95895 | src.resume(); | ||
95896 | } | ||
95897 | |||
95898 | return dest; | ||
95899 | }; | ||
95900 | |||
95901 | function pipeOnDrain(src) { | ||
95902 | return function () { | ||
95903 | var state = src._readableState; | ||
95904 | debug('pipeOnDrain', state.awaitDrain); | ||
95905 | if (state.awaitDrain) state.awaitDrain--; | ||
95906 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { | ||
95907 | state.flowing = true; | ||
95908 | flow(src); | ||
95909 | } | ||
95910 | }; | ||
95911 | } | ||
95912 | |||
95913 | Readable.prototype.unpipe = function (dest) { | ||
95914 | var state = this._readableState; | ||
95915 | var unpipeInfo = { hasUnpiped: false }; | ||
95916 | |||
95917 | // if we're not piping anywhere, then do nothing. | ||
95918 | if (state.pipesCount === 0) return this; | ||
95919 | |||
95920 | // just one destination. most common case. | ||
95921 | if (state.pipesCount === 1) { | ||
95922 | // passed in one, but it's not the right one. | ||
95923 | if (dest && dest !== state.pipes) return this; | ||
95924 | |||
95925 | if (!dest) dest = state.pipes; | ||
95926 | |||
95927 | // got a match. | ||
95928 | state.pipes = null; | ||
95929 | state.pipesCount = 0; | ||
95930 | state.flowing = false; | ||
95931 | if (dest) dest.emit('unpipe', this, unpipeInfo); | ||
95932 | return this; | ||
95933 | } | ||
95934 | |||
95935 | // slow case. multiple pipe destinations. | ||
95936 | |||
95937 | if (!dest) { | ||
95938 | // remove all. | ||
95939 | var dests = state.pipes; | ||
95940 | var len = state.pipesCount; | ||
95941 | state.pipes = null; | ||
95942 | state.pipesCount = 0; | ||
95943 | state.flowing = false; | ||
95944 | |||
95945 | for (var i = 0; i < len; i++) { | ||
95946 | dests[i].emit('unpipe', this, unpipeInfo); | ||
95947 | }return this; | ||
95948 | } | ||
95949 | |||
95950 | // try to find the right one. | ||
95951 | var index = indexOf(state.pipes, dest); | ||
95952 | if (index === -1) return this; | ||
95953 | |||
95954 | state.pipes.splice(index, 1); | ||
95955 | state.pipesCount -= 1; | ||
95956 | if (state.pipesCount === 1) state.pipes = state.pipes[0]; | ||
95957 | |||
95958 | dest.emit('unpipe', this, unpipeInfo); | ||
95959 | |||
95960 | return this; | ||
95961 | }; | ||
95962 | |||
95963 | // set up data events if they are asked for | ||
95964 | // Ensure readable listeners eventually get something | ||
95965 | Readable.prototype.on = function (ev, fn) { | ||
95966 | var res = Stream.prototype.on.call(this, ev, fn); | ||
95967 | |||
95968 | if (ev === 'data') { | ||
95969 | // Start flowing on next tick if stream isn't explicitly paused | ||
95970 | if (this._readableState.flowing !== false) this.resume(); | ||
95971 | } else if (ev === 'readable') { | ||
95972 | var state = this._readableState; | ||
95973 | if (!state.endEmitted && !state.readableListening) { | ||
95974 | state.readableListening = state.needReadable = true; | ||
95975 | state.emittedReadable = false; | ||
95976 | if (!state.reading) { | ||
95977 | processNextTick(nReadingNextTick, this); | ||
95978 | } else if (state.length) { | ||
95979 | emitReadable(this); | ||
95980 | } | ||
95981 | } | ||
95982 | } | ||
95983 | |||
95984 | return res; | ||
95985 | }; | ||
95986 | Readable.prototype.addListener = Readable.prototype.on; | ||
95987 | |||
95988 | function nReadingNextTick(self) { | ||
95989 | debug('readable nexttick read 0'); | ||
95990 | self.read(0); | ||
95991 | } | ||
95992 | |||
95993 | // pause() and resume() are remnants of the legacy readable stream API | ||
95994 | // If the user uses them, then switch into old mode. | ||
95995 | Readable.prototype.resume = function () { | ||
95996 | var state = this._readableState; | ||
95997 | if (!state.flowing) { | ||
95998 | debug('resume'); | ||
95999 | state.flowing = true; | ||
96000 | resume(this, state); | ||
96001 | } | ||
96002 | return this; | ||
96003 | }; | ||
96004 | |||
96005 | function resume(stream, state) { | ||
96006 | if (!state.resumeScheduled) { | ||
96007 | state.resumeScheduled = true; | ||
96008 | processNextTick(resume_, stream, state); | ||
96009 | } | ||
96010 | } | ||
96011 | |||
96012 | function resume_(stream, state) { | ||
96013 | if (!state.reading) { | ||
96014 | debug('resume read 0'); | ||
96015 | stream.read(0); | ||
96016 | } | ||
96017 | |||
96018 | state.resumeScheduled = false; | ||
96019 | state.awaitDrain = 0; | ||
96020 | stream.emit('resume'); | ||
96021 | flow(stream); | ||
96022 | if (state.flowing && !state.reading) stream.read(0); | ||
96023 | } | ||
96024 | |||
96025 | Readable.prototype.pause = function () { | ||
96026 | debug('call pause flowing=%j', this._readableState.flowing); | ||
96027 | if (false !== this._readableState.flowing) { | ||
96028 | debug('pause'); | ||
96029 | this._readableState.flowing = false; | ||
96030 | this.emit('pause'); | ||
96031 | } | ||
96032 | return this; | ||
96033 | }; | ||
96034 | |||
96035 | function flow(stream) { | ||
96036 | var state = stream._readableState; | ||
96037 | debug('flow', state.flowing); | ||
96038 | while (state.flowing && stream.read() !== null) {} | ||
96039 | } | ||
96040 | |||
96041 | // wrap an old-style stream as the async data source. | ||
96042 | // This is *not* part of the readable stream interface. | ||
96043 | // It is an ugly unfortunate mess of history. | ||
96044 | Readable.prototype.wrap = function (stream) { | ||
96045 | var state = this._readableState; | ||
96046 | var paused = false; | ||
96047 | |||
96048 | var self = this; | ||
96049 | stream.on('end', function () { | ||
96050 | debug('wrapped end'); | ||
96051 | if (state.decoder && !state.ended) { | ||
96052 | var chunk = state.decoder.end(); | ||
96053 | if (chunk && chunk.length) self.push(chunk); | ||
96054 | } | ||
96055 | |||
96056 | self.push(null); | ||
96057 | }); | ||
96058 | |||
96059 | stream.on('data', function (chunk) { | ||
96060 | debug('wrapped data'); | ||
96061 | if (state.decoder) chunk = state.decoder.write(chunk); | ||
96062 | |||
96063 | // don't skip over falsy values in objectMode | ||
96064 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; | ||
96065 | |||
96066 | var ret = self.push(chunk); | ||
96067 | if (!ret) { | ||
96068 | paused = true; | ||
96069 | stream.pause(); | ||
96070 | } | ||
96071 | }); | ||
96072 | |||
96073 | // proxy all the other methods. | ||
96074 | // important when wrapping filters and duplexes. | ||
96075 | for (var i in stream) { | ||
96076 | if (this[i] === undefined && typeof stream[i] === 'function') { | ||
96077 | this[i] = function (method) { | ||
96078 | return function () { | ||
96079 | return stream[method].apply(stream, arguments); | ||
96080 | }; | ||
96081 | }(i); | ||
96082 | } | ||
96083 | } | ||
96084 | |||
96085 | // proxy certain important events. | ||
96086 | for (var n = 0; n < kProxyEvents.length; n++) { | ||
96087 | stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n])); | ||
96088 | } | ||
96089 | |||
96090 | // when we try to consume some more bytes, simply unpause the | ||
96091 | // underlying stream. | ||
96092 | self._read = function (n) { | ||
96093 | debug('wrapped _read', n); | ||
96094 | if (paused) { | ||
96095 | paused = false; | ||
96096 | stream.resume(); | ||
96097 | } | ||
96098 | }; | ||
96099 | |||
96100 | return self; | ||
96101 | }; | ||
96102 | |||
96103 | // exposed for testing purposes only. | ||
96104 | Readable._fromList = fromList; | ||
96105 | |||
96106 | // Pluck off n bytes from an array of buffers. | ||
96107 | // Length is the combined lengths of all the buffers in the list. | ||
96108 | // This function is designed to be inlinable, so please take care when making | ||
96109 | // changes to the function body. | ||
96110 | function fromList(n, state) { | ||
96111 | // nothing buffered | ||
96112 | if (state.length === 0) return null; | ||
96113 | |||
96114 | var ret; | ||
96115 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { | ||
96116 | // read it all, truncate the list | ||
96117 | if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length); | ||
96118 | state.buffer.clear(); | ||
96119 | } else { | ||
96120 | // read part of list | ||
96121 | ret = fromListPartial(n, state.buffer, state.decoder); | ||
96122 | } | ||
96123 | |||
96124 | return ret; | ||
96125 | } | ||
96126 | |||
96127 | // Extracts only enough buffered data to satisfy the amount requested. | ||
96128 | // This function is designed to be inlinable, so please take care when making | ||
96129 | // changes to the function body. | ||
96130 | function fromListPartial(n, list, hasStrings) { | ||
96131 | var ret; | ||
96132 | if (n < list.head.data.length) { | ||
96133 | // slice is the same for buffers and strings | ||
96134 | ret = list.head.data.slice(0, n); | ||
96135 | list.head.data = list.head.data.slice(n); | ||
96136 | } else if (n === list.head.data.length) { | ||
96137 | // first chunk is a perfect match | ||
96138 | ret = list.shift(); | ||
96139 | } else { | ||
96140 | // result spans more than one buffer | ||
96141 | ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); | ||
96142 | } | ||
96143 | return ret; | ||
96144 | } | ||
96145 | |||
96146 | // Copies a specified amount of characters from the list of buffered data | ||
96147 | // chunks. | ||
96148 | // This function is designed to be inlinable, so please take care when making | ||
96149 | // changes to the function body. | ||
96150 | function copyFromBufferString(n, list) { | ||
96151 | var p = list.head; | ||
96152 | var c = 1; | ||
96153 | var ret = p.data; | ||
96154 | n -= ret.length; | ||
96155 | while (p = p.next) { | ||
96156 | var str = p.data; | ||
96157 | var nb = n > str.length ? str.length : n; | ||
96158 | if (nb === str.length) ret += str;else ret += str.slice(0, n); | ||
96159 | n -= nb; | ||
96160 | if (n === 0) { | ||
96161 | if (nb === str.length) { | ||
96162 | ++c; | ||
96163 | if (p.next) list.head = p.next;else list.head = list.tail = null; | ||
96164 | } else { | ||
96165 | list.head = p; | ||
96166 | p.data = str.slice(nb); | ||
96167 | } | ||
96168 | break; | ||
96169 | } | ||
96170 | ++c; | ||
96171 | } | ||
96172 | list.length -= c; | ||
96173 | return ret; | ||
96174 | } | ||
96175 | |||
96176 | // Copies a specified amount of bytes from the list of buffered data chunks. | ||
96177 | // This function is designed to be inlinable, so please take care when making | ||
96178 | // changes to the function body. | ||
96179 | function copyFromBuffer(n, list) { | ||
96180 | var ret = Buffer.allocUnsafe(n); | ||
96181 | var p = list.head; | ||
96182 | var c = 1; | ||
96183 | p.data.copy(ret); | ||
96184 | n -= p.data.length; | ||
96185 | while (p = p.next) { | ||
96186 | var buf = p.data; | ||
96187 | var nb = n > buf.length ? buf.length : n; | ||
96188 | buf.copy(ret, ret.length - n, 0, nb); | ||
96189 | n -= nb; | ||
96190 | if (n === 0) { | ||
96191 | if (nb === buf.length) { | ||
96192 | ++c; | ||
96193 | if (p.next) list.head = p.next;else list.head = list.tail = null; | ||
96194 | } else { | ||
96195 | list.head = p; | ||
96196 | p.data = buf.slice(nb); | ||
96197 | } | ||
96198 | break; | ||
96199 | } | ||
96200 | ++c; | ||
96201 | } | ||
96202 | list.length -= c; | ||
96203 | return ret; | ||
96204 | } | ||
96205 | |||
96206 | function endReadable(stream) { | ||
96207 | var state = stream._readableState; | ||
96208 | |||
96209 | // If we get here before consuming all the bytes, then that is a | ||
96210 | // bug in node. Should never happen. | ||
96211 | if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); | ||
96212 | |||
96213 | if (!state.endEmitted) { | ||
96214 | state.ended = true; | ||
96215 | processNextTick(endReadableNT, state, stream); | ||
96216 | } | ||
96217 | } | ||
96218 | |||
96219 | function endReadableNT(state, stream) { | ||
96220 | // Check that we didn't get one last unshift. | ||
96221 | if (!state.endEmitted && state.length === 0) { | ||
96222 | state.endEmitted = true; | ||
96223 | stream.readable = false; | ||
96224 | stream.emit('end'); | ||
96225 | } | ||
96226 | } | ||
96227 | |||
96228 | function forEach(xs, f) { | ||
96229 | for (var i = 0, l = xs.length; i < l; i++) { | ||
96230 | f(xs[i], i); | ||
96231 | } | ||
96232 | } | ||
96233 | |||
96234 | function indexOf(xs, x) { | ||
96235 | for (var i = 0, l = xs.length; i < l; i++) { | ||
96236 | if (xs[i] === x) return i; | ||
96237 | } | ||
96238 | return -1; | ||
96239 | } | ||
96240 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
96241 | },{"./_stream_duplex":27,"./internal/streams/BufferList":32,"./internal/streams/destroy":33,"./internal/streams/stream":34,"_process":25,"core-util-is":14,"events":18,"inherits":21,"isarray":23,"process-nextick-args":24,"safe-buffer":40,"string_decoder/":50,"util":4}],30:[function(require,module,exports){ | ||
96242 | // Copyright Joyent, Inc. and other Node contributors. | ||
96243 | // | ||
96244 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
96245 | // copy of this software and associated documentation files (the | ||
96246 | // "Software"), to deal in the Software without restriction, including | ||
96247 | // without limitation the rights to use, copy, modify, merge, publish, | ||
96248 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
96249 | // persons to whom the Software is furnished to do so, subject to the | ||
96250 | // following conditions: | ||
96251 | // | ||
96252 | // The above copyright notice and this permission notice shall be included | ||
96253 | // in all copies or substantial portions of the Software. | ||
96254 | // | ||
96255 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
96256 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
96257 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
96258 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
96259 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
96260 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
96261 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
96262 | |||
96263 | // a transform stream is a readable/writable stream where you do | ||
96264 | // something with the data. Sometimes it's called a "filter", | ||
96265 | // but that's not a great name for it, since that implies a thing where | ||
96266 | // some bits pass through, and others are simply ignored. (That would | ||
96267 | // be a valid example of a transform, of course.) | ||
96268 | // | ||
96269 | // While the output is causally related to the input, it's not a | ||
96270 | // necessarily symmetric or synchronous transformation. For example, | ||
96271 | // a zlib stream might take multiple plain-text writes(), and then | ||
96272 | // emit a single compressed chunk some time in the future. | ||
96273 | // | ||
96274 | // Here's how this works: | ||
96275 | // | ||
96276 | // The Transform stream has all the aspects of the readable and writable | ||
96277 | // stream classes. When you write(chunk), that calls _write(chunk,cb) | ||
96278 | // internally, and returns false if there's a lot of pending writes | ||
96279 | // buffered up. When you call read(), that calls _read(n) until | ||
96280 | // there's enough pending readable data buffered up. | ||
96281 | // | ||
96282 | // In a transform stream, the written data is placed in a buffer. When | ||
96283 | // _read(n) is called, it transforms the queued up data, calling the | ||
96284 | // buffered _write cb's as it consumes chunks. If consuming a single | ||
96285 | // written chunk would result in multiple output chunks, then the first | ||
96286 | // outputted bit calls the readcb, and subsequent chunks just go into | ||
96287 | // the read buffer, and will cause it to emit 'readable' if necessary. | ||
96288 | // | ||
96289 | // This way, back-pressure is actually determined by the reading side, | ||
96290 | // since _read has to be called to start processing a new chunk. However, | ||
96291 | // a pathological inflate type of transform can cause excessive buffering | ||
96292 | // here. For example, imagine a stream where every byte of input is | ||
96293 | // interpreted as an integer from 0-255, and then results in that many | ||
96294 | // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in | ||
96295 | // 1kb of data being output. In this case, you could write a very small | ||
96296 | // amount of input, and end up with a very large amount of output. In | ||
96297 | // such a pathological inflating mechanism, there'd be no way to tell | ||
96298 | // the system to stop doing the transform. A single 4MB write could | ||
96299 | // cause the system to run out of memory. | ||
96300 | // | ||
96301 | // However, even in such a pathological case, only a single written chunk | ||
96302 | // would be consumed, and then the rest would wait (un-transformed) until | ||
96303 | // the results of the previous transformed chunk were consumed. | ||
96304 | |||
96305 | 'use strict'; | ||
96306 | |||
96307 | module.exports = Transform; | ||
96308 | |||
96309 | var Duplex = require('./_stream_duplex'); | ||
96310 | |||
96311 | /*<replacement>*/ | ||
96312 | var util = require('core-util-is'); | ||
96313 | util.inherits = require('inherits'); | ||
96314 | /*</replacement>*/ | ||
96315 | |||
96316 | util.inherits(Transform, Duplex); | ||
96317 | |||
96318 | function TransformState(stream) { | ||
96319 | this.afterTransform = function (er, data) { | ||
96320 | return afterTransform(stream, er, data); | ||
96321 | }; | ||
96322 | |||
96323 | this.needTransform = false; | ||
96324 | this.transforming = false; | ||
96325 | this.writecb = null; | ||
96326 | this.writechunk = null; | ||
96327 | this.writeencoding = null; | ||
96328 | } | ||
96329 | |||
96330 | function afterTransform(stream, er, data) { | ||
96331 | var ts = stream._transformState; | ||
96332 | ts.transforming = false; | ||
96333 | |||
96334 | var cb = ts.writecb; | ||
96335 | |||
96336 | if (!cb) { | ||
96337 | return stream.emit('error', new Error('write callback called multiple times')); | ||
96338 | } | ||
96339 | |||
96340 | ts.writechunk = null; | ||
96341 | ts.writecb = null; | ||
96342 | |||
96343 | if (data !== null && data !== undefined) stream.push(data); | ||
96344 | |||
96345 | cb(er); | ||
96346 | |||
96347 | var rs = stream._readableState; | ||
96348 | rs.reading = false; | ||
96349 | if (rs.needReadable || rs.length < rs.highWaterMark) { | ||
96350 | stream._read(rs.highWaterMark); | ||
96351 | } | ||
96352 | } | ||
96353 | |||
96354 | function Transform(options) { | ||
96355 | if (!(this instanceof Transform)) return new Transform(options); | ||
96356 | |||
96357 | Duplex.call(this, options); | ||
96358 | |||
96359 | this._transformState = new TransformState(this); | ||
96360 | |||
96361 | var stream = this; | ||
96362 | |||
96363 | // start out asking for a readable event once data is transformed. | ||
96364 | this._readableState.needReadable = true; | ||
96365 | |||
96366 | // we have implemented the _read method, and done the other things | ||
96367 | // that Readable wants before the first _read call, so unset the | ||
96368 | // sync guard flag. | ||
96369 | this._readableState.sync = false; | ||
96370 | |||
96371 | if (options) { | ||
96372 | if (typeof options.transform === 'function') this._transform = options.transform; | ||
96373 | |||
96374 | if (typeof options.flush === 'function') this._flush = options.flush; | ||
96375 | } | ||
96376 | |||
96377 | // When the writable side finishes, then flush out anything remaining. | ||
96378 | this.once('prefinish', function () { | ||
96379 | if (typeof this._flush === 'function') this._flush(function (er, data) { | ||
96380 | done(stream, er, data); | ||
96381 | });else done(stream); | ||
96382 | }); | ||
96383 | } | ||
96384 | |||
96385 | Transform.prototype.push = function (chunk, encoding) { | ||
96386 | this._transformState.needTransform = false; | ||
96387 | return Duplex.prototype.push.call(this, chunk, encoding); | ||
96388 | }; | ||
96389 | |||
96390 | // This is the part where you do stuff! | ||
96391 | // override this function in implementation classes. | ||
96392 | // 'chunk' is an input chunk. | ||
96393 | // | ||
96394 | // Call `push(newChunk)` to pass along transformed output | ||
96395 | // to the readable side. You may call 'push' zero or more times. | ||
96396 | // | ||
96397 | // Call `cb(err)` when you are done with this chunk. If you pass | ||
96398 | // an error, then that'll put the hurt on the whole operation. If you | ||
96399 | // never call cb(), then you'll never get another chunk. | ||
96400 | Transform.prototype._transform = function (chunk, encoding, cb) { | ||
96401 | throw new Error('_transform() is not implemented'); | ||
96402 | }; | ||
96403 | |||
96404 | Transform.prototype._write = function (chunk, encoding, cb) { | ||
96405 | var ts = this._transformState; | ||
96406 | ts.writecb = cb; | ||
96407 | ts.writechunk = chunk; | ||
96408 | ts.writeencoding = encoding; | ||
96409 | if (!ts.transforming) { | ||
96410 | var rs = this._readableState; | ||
96411 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); | ||
96412 | } | ||
96413 | }; | ||
96414 | |||
96415 | // Doesn't matter what the args are here. | ||
96416 | // _transform does all the work. | ||
96417 | // That we got here means that the readable side wants more data. | ||
96418 | Transform.prototype._read = function (n) { | ||
96419 | var ts = this._transformState; | ||
96420 | |||
96421 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) { | ||
96422 | ts.transforming = true; | ||
96423 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); | ||
96424 | } else { | ||
96425 | // mark that we need a transform, so that any data that comes in | ||
96426 | // will get processed, now that we've asked for it. | ||
96427 | ts.needTransform = true; | ||
96428 | } | ||
96429 | }; | ||
96430 | |||
96431 | Transform.prototype._destroy = function (err, cb) { | ||
96432 | var _this = this; | ||
96433 | |||
96434 | Duplex.prototype._destroy.call(this, err, function (err2) { | ||
96435 | cb(err2); | ||
96436 | _this.emit('close'); | ||
96437 | }); | ||
96438 | }; | ||
96439 | |||
96440 | function done(stream, er, data) { | ||
96441 | if (er) return stream.emit('error', er); | ||
96442 | |||
96443 | if (data !== null && data !== undefined) stream.push(data); | ||
96444 | |||
96445 | // if there's nothing in the write buffer, then that means | ||
96446 | // that nothing more will ever be provided | ||
96447 | var ws = stream._writableState; | ||
96448 | var ts = stream._transformState; | ||
96449 | |||
96450 | if (ws.length) throw new Error('Calling transform done when ws.length != 0'); | ||
96451 | |||
96452 | if (ts.transforming) throw new Error('Calling transform done when still transforming'); | ||
96453 | |||
96454 | return stream.push(null); | ||
96455 | } | ||
96456 | },{"./_stream_duplex":27,"core-util-is":14,"inherits":21}],31:[function(require,module,exports){ | ||
96457 | (function (process,global){ | ||
96458 | // Copyright Joyent, Inc. and other Node contributors. | ||
96459 | // | ||
96460 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
96461 | // copy of this software and associated documentation files (the | ||
96462 | // "Software"), to deal in the Software without restriction, including | ||
96463 | // without limitation the rights to use, copy, modify, merge, publish, | ||
96464 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
96465 | // persons to whom the Software is furnished to do so, subject to the | ||
96466 | // following conditions: | ||
96467 | // | ||
96468 | // The above copyright notice and this permission notice shall be included | ||
96469 | // in all copies or substantial portions of the Software. | ||
96470 | // | ||
96471 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
96472 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
96473 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
96474 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
96475 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
96476 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
96477 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
96478 | |||
96479 | // A bit simpler than readable streams. | ||
96480 | // Implement an async ._write(chunk, encoding, cb), and it'll handle all | ||
96481 | // the drain event emission and buffering. | ||
96482 | |||
96483 | 'use strict'; | ||
96484 | |||
96485 | /*<replacement>*/ | ||
96486 | |||
96487 | var processNextTick = require('process-nextick-args'); | ||
96488 | /*</replacement>*/ | ||
96489 | |||
96490 | module.exports = Writable; | ||
96491 | |||
96492 | /* <replacement> */ | ||
96493 | function WriteReq(chunk, encoding, cb) { | ||
96494 | this.chunk = chunk; | ||
96495 | this.encoding = encoding; | ||
96496 | this.callback = cb; | ||
96497 | this.next = null; | ||
96498 | } | ||
96499 | |||
96500 | // It seems a linked list but it is not | ||
96501 | // there will be only 2 of these for each stream | ||
96502 | function CorkedRequest(state) { | ||
96503 | var _this = this; | ||
96504 | |||
96505 | this.next = null; | ||
96506 | this.entry = null; | ||
96507 | this.finish = function () { | ||
96508 | onCorkedFinish(_this, state); | ||
96509 | }; | ||
96510 | } | ||
96511 | /* </replacement> */ | ||
96512 | |||
96513 | /*<replacement>*/ | ||
96514 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; | ||
96515 | /*</replacement>*/ | ||
96516 | |||
96517 | /*<replacement>*/ | ||
96518 | var Duplex; | ||
96519 | /*</replacement>*/ | ||
96520 | |||
96521 | Writable.WritableState = WritableState; | ||
96522 | |||
96523 | /*<replacement>*/ | ||
96524 | var util = require('core-util-is'); | ||
96525 | util.inherits = require('inherits'); | ||
96526 | /*</replacement>*/ | ||
96527 | |||
96528 | /*<replacement>*/ | ||
96529 | var internalUtil = { | ||
96530 | deprecate: require('util-deprecate') | ||
96531 | }; | ||
96532 | /*</replacement>*/ | ||
96533 | |||
96534 | /*<replacement>*/ | ||
96535 | var Stream = require('./internal/streams/stream'); | ||
96536 | /*</replacement>*/ | ||
96537 | |||
96538 | /*<replacement>*/ | ||
96539 | var Buffer = require('safe-buffer').Buffer; | ||
96540 | var OurUint8Array = global.Uint8Array || function () {}; | ||
96541 | function _uint8ArrayToBuffer(chunk) { | ||
96542 | return Buffer.from(chunk); | ||
96543 | } | ||
96544 | function _isUint8Array(obj) { | ||
96545 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; | ||
96546 | } | ||
96547 | /*</replacement>*/ | ||
96548 | |||
96549 | var destroyImpl = require('./internal/streams/destroy'); | ||
96550 | |||
96551 | util.inherits(Writable, Stream); | ||
96552 | |||
96553 | function nop() {} | ||
96554 | |||
96555 | function WritableState(options, stream) { | ||
96556 | Duplex = Duplex || require('./_stream_duplex'); | ||
96557 | |||
96558 | options = options || {}; | ||
96559 | |||
96560 | // object stream flag to indicate whether or not this stream | ||
96561 | // contains buffers or objects. | ||
96562 | this.objectMode = !!options.objectMode; | ||
96563 | |||
96564 | if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; | ||
96565 | |||
96566 | // the point at which write() starts returning false | ||
96567 | // Note: 0 is a valid value, means that we always return false if | ||
96568 | // the entire buffer is not flushed immediately on write() | ||
96569 | var hwm = options.highWaterMark; | ||
96570 | var defaultHwm = this.objectMode ? 16 : 16 * 1024; | ||
96571 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | ||
96572 | |||
96573 | // cast to ints. | ||
96574 | this.highWaterMark = Math.floor(this.highWaterMark); | ||
96575 | |||
96576 | // if _final has been called | ||
96577 | this.finalCalled = false; | ||
96578 | |||
96579 | // drain event flag. | ||
96580 | this.needDrain = false; | ||
96581 | // at the start of calling end() | ||
96582 | this.ending = false; | ||
96583 | // when end() has been called, and returned | ||
96584 | this.ended = false; | ||
96585 | // when 'finish' is emitted | ||
96586 | this.finished = false; | ||
96587 | |||
96588 | // has it been destroyed | ||
96589 | this.destroyed = false; | ||
96590 | |||
96591 | // should we decode strings into buffers before passing to _write? | ||
96592 | // this is here so that some node-core streams can optimize string | ||
96593 | // handling at a lower level. | ||
96594 | var noDecode = options.decodeStrings === false; | ||
96595 | this.decodeStrings = !noDecode; | ||
96596 | |||
96597 | // Crypto is kind of old and crusty. Historically, its default string | ||
96598 | // encoding is 'binary' so we have to make this configurable. | ||
96599 | // Everything else in the universe uses 'utf8', though. | ||
96600 | this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
96601 | |||
96602 | // not an actual buffer we keep track of, but a measurement | ||
96603 | // of how much we're waiting to get pushed to some underlying | ||
96604 | // socket or file. | ||
96605 | this.length = 0; | ||
96606 | |||
96607 | // a flag to see when we're in the middle of a write. | ||
96608 | this.writing = false; | ||
96609 | |||
96610 | // when true all writes will be buffered until .uncork() call | ||
96611 | this.corked = 0; | ||
96612 | |||
96613 | // a flag to be able to tell if the onwrite cb is called immediately, | ||
96614 | // or on a later tick. We set this to true at first, because any | ||
96615 | // actions that shouldn't happen until "later" should generally also | ||
96616 | // not happen before the first write call. | ||
96617 | this.sync = true; | ||
96618 | |||
96619 | // a flag to know if we're processing previously buffered items, which | ||
96620 | // may call the _write() callback in the same tick, so that we don't | ||
96621 | // end up in an overlapped onwrite situation. | ||
96622 | this.bufferProcessing = false; | ||
96623 | |||
96624 | // the callback that's passed to _write(chunk,cb) | ||
96625 | this.onwrite = function (er) { | ||
96626 | onwrite(stream, er); | ||
96627 | }; | ||
96628 | |||
96629 | // the callback that the user supplies to write(chunk,encoding,cb) | ||
96630 | this.writecb = null; | ||
96631 | |||
96632 | // the amount that is being written when _write is called. | ||
96633 | this.writelen = 0; | ||
96634 | |||
96635 | this.bufferedRequest = null; | ||
96636 | this.lastBufferedRequest = null; | ||
96637 | |||
96638 | // number of pending user-supplied write callbacks | ||
96639 | // this must be 0 before 'finish' can be emitted | ||
96640 | this.pendingcb = 0; | ||
96641 | |||
96642 | // emit prefinish if the only thing we're waiting for is _write cbs | ||
96643 | // This is relevant for synchronous Transform streams | ||
96644 | this.prefinished = false; | ||
96645 | |||
96646 | // True if the error was already emitted and should not be thrown again | ||
96647 | this.errorEmitted = false; | ||
96648 | |||
96649 | // count buffered requests | ||
96650 | this.bufferedRequestCount = 0; | ||
96651 | |||
96652 | // allocate the first CorkedRequest, there is always | ||
96653 | // one allocated and free to use, and we maintain at most two | ||
96654 | this.corkedRequestsFree = new CorkedRequest(this); | ||
96655 | } | ||
96656 | |||
96657 | WritableState.prototype.getBuffer = function getBuffer() { | ||
96658 | var current = this.bufferedRequest; | ||
96659 | var out = []; | ||
96660 | while (current) { | ||
96661 | out.push(current); | ||
96662 | current = current.next; | ||
96663 | } | ||
96664 | return out; | ||
96665 | }; | ||
96666 | |||
96667 | (function () { | ||
96668 | try { | ||
96669 | Object.defineProperty(WritableState.prototype, 'buffer', { | ||
96670 | get: internalUtil.deprecate(function () { | ||
96671 | return this.getBuffer(); | ||
96672 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003') | ||
96673 | }); | ||
96674 | } catch (_) {} | ||
96675 | })(); | ||
96676 | |||
96677 | // Test _writableState for inheritance to account for Duplex streams, | ||
96678 | // whose prototype chain only points to Readable. | ||
96679 | var realHasInstance; | ||
96680 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') { | ||
96681 | realHasInstance = Function.prototype[Symbol.hasInstance]; | ||
96682 | Object.defineProperty(Writable, Symbol.hasInstance, { | ||
96683 | value: function (object) { | ||
96684 | if (realHasInstance.call(this, object)) return true; | ||
96685 | |||
96686 | return object && object._writableState instanceof WritableState; | ||
96687 | } | ||
96688 | }); | ||
96689 | } else { | ||
96690 | realHasInstance = function (object) { | ||
96691 | return object instanceof this; | ||
96692 | }; | ||
96693 | } | ||
96694 | |||
96695 | function Writable(options) { | ||
96696 | Duplex = Duplex || require('./_stream_duplex'); | ||
96697 | |||
96698 | // Writable ctor is applied to Duplexes, too. | ||
96699 | // `realHasInstance` is necessary because using plain `instanceof` | ||
96700 | // would return false, as no `_writableState` property is attached. | ||
96701 | |||
96702 | // Trying to use the custom `instanceof` for Writable here will also break the | ||
96703 | // Node.js LazyTransform implementation, which has a non-trivial getter for | ||
96704 | // `_writableState` that would lead to infinite recursion. | ||
96705 | if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) { | ||
96706 | return new Writable(options); | ||
96707 | } | ||
96708 | |||
96709 | this._writableState = new WritableState(options, this); | ||
96710 | |||
96711 | // legacy. | ||
96712 | this.writable = true; | ||
96713 | |||
96714 | if (options) { | ||
96715 | if (typeof options.write === 'function') this._write = options.write; | ||
96716 | |||
96717 | if (typeof options.writev === 'function') this._writev = options.writev; | ||
96718 | |||
96719 | if (typeof options.destroy === 'function') this._destroy = options.destroy; | ||
96720 | |||
96721 | if (typeof options.final === 'function') this._final = options.final; | ||
96722 | } | ||
96723 | |||
96724 | Stream.call(this); | ||
96725 | } | ||
96726 | |||
96727 | // Otherwise people can pipe Writable streams, which is just wrong. | ||
96728 | Writable.prototype.pipe = function () { | ||
96729 | this.emit('error', new Error('Cannot pipe, not readable')); | ||
96730 | }; | ||
96731 | |||
96732 | function writeAfterEnd(stream, cb) { | ||
96733 | var er = new Error('write after end'); | ||
96734 | // TODO: defer error events consistently everywhere, not just the cb | ||
96735 | stream.emit('error', er); | ||
96736 | processNextTick(cb, er); | ||
96737 | } | ||
96738 | |||
96739 | // Checks that a user-supplied chunk is valid, especially for the particular | ||
96740 | // mode the stream is in. Currently this means that `null` is never accepted | ||
96741 | // and undefined/non-string values are only allowed in object mode. | ||
96742 | function validChunk(stream, state, chunk, cb) { | ||
96743 | var valid = true; | ||
96744 | var er = false; | ||
96745 | |||
96746 | if (chunk === null) { | ||
96747 | er = new TypeError('May not write null values to stream'); | ||
96748 | } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { | ||
96749 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
96750 | } | ||
96751 | if (er) { | ||
96752 | stream.emit('error', er); | ||
96753 | processNextTick(cb, er); | ||
96754 | valid = false; | ||
96755 | } | ||
96756 | return valid; | ||
96757 | } | ||
96758 | |||
96759 | Writable.prototype.write = function (chunk, encoding, cb) { | ||
96760 | var state = this._writableState; | ||
96761 | var ret = false; | ||
96762 | var isBuf = _isUint8Array(chunk) && !state.objectMode; | ||
96763 | |||
96764 | if (isBuf && !Buffer.isBuffer(chunk)) { | ||
96765 | chunk = _uint8ArrayToBuffer(chunk); | ||
96766 | } | ||
96767 | |||
96768 | if (typeof encoding === 'function') { | ||
96769 | cb = encoding; | ||
96770 | encoding = null; | ||
96771 | } | ||
96772 | |||
96773 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; | ||
96774 | |||
96775 | if (typeof cb !== 'function') cb = nop; | ||
96776 | |||
96777 | if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { | ||
96778 | state.pendingcb++; | ||
96779 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); | ||
96780 | } | ||
96781 | |||
96782 | return ret; | ||
96783 | }; | ||
96784 | |||
96785 | Writable.prototype.cork = function () { | ||
96786 | var state = this._writableState; | ||
96787 | |||
96788 | state.corked++; | ||
96789 | }; | ||
96790 | |||
96791 | Writable.prototype.uncork = function () { | ||
96792 | var state = this._writableState; | ||
96793 | |||
96794 | if (state.corked) { | ||
96795 | state.corked--; | ||
96796 | |||
96797 | if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); | ||
96798 | } | ||
96799 | }; | ||
96800 | |||
96801 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { | ||
96802 | // node::ParseEncoding() requires lower case. | ||
96803 | if (typeof encoding === 'string') encoding = encoding.toLowerCase(); | ||
96804 | if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); | ||
96805 | this._writableState.defaultEncoding = encoding; | ||
96806 | return this; | ||
96807 | }; | ||
96808 | |||
96809 | function decodeChunk(state, chunk, encoding) { | ||
96810 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { | ||
96811 | chunk = Buffer.from(chunk, encoding); | ||
96812 | } | ||
96813 | return chunk; | ||
96814 | } | ||
96815 | |||
96816 | // if we're already writing something, then just put this | ||
96817 | // in the queue, and wait our turn. Otherwise, call _write | ||
96818 | // If we return false, then we need a drain event, so set that flag. | ||
96819 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { | ||
96820 | if (!isBuf) { | ||
96821 | var newChunk = decodeChunk(state, chunk, encoding); | ||
96822 | if (chunk !== newChunk) { | ||
96823 | isBuf = true; | ||
96824 | encoding = 'buffer'; | ||
96825 | chunk = newChunk; | ||
96826 | } | ||
96827 | } | ||
96828 | var len = state.objectMode ? 1 : chunk.length; | ||
96829 | |||
96830 | state.length += len; | ||
96831 | |||
96832 | var ret = state.length < state.highWaterMark; | ||
96833 | // we must ensure that previous needDrain will not be reset to false. | ||
96834 | if (!ret) state.needDrain = true; | ||
96835 | |||
96836 | if (state.writing || state.corked) { | ||
96837 | var last = state.lastBufferedRequest; | ||
96838 | state.lastBufferedRequest = { | ||
96839 | chunk: chunk, | ||
96840 | encoding: encoding, | ||
96841 | isBuf: isBuf, | ||
96842 | callback: cb, | ||
96843 | next: null | ||
96844 | }; | ||
96845 | if (last) { | ||
96846 | last.next = state.lastBufferedRequest; | ||
96847 | } else { | ||
96848 | state.bufferedRequest = state.lastBufferedRequest; | ||
96849 | } | ||
96850 | state.bufferedRequestCount += 1; | ||
96851 | } else { | ||
96852 | doWrite(stream, state, false, len, chunk, encoding, cb); | ||
96853 | } | ||
96854 | |||
96855 | return ret; | ||
96856 | } | ||
96857 | |||
96858 | function doWrite(stream, state, writev, len, chunk, encoding, cb) { | ||
96859 | state.writelen = len; | ||
96860 | state.writecb = cb; | ||
96861 | state.writing = true; | ||
96862 | state.sync = true; | ||
96863 | if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); | ||
96864 | state.sync = false; | ||
96865 | } | ||
96866 | |||
96867 | function onwriteError(stream, state, sync, er, cb) { | ||
96868 | --state.pendingcb; | ||
96869 | |||
96870 | if (sync) { | ||
96871 | // defer the callback if we are being called synchronously | ||
96872 | // to avoid piling up things on the stack | ||
96873 | processNextTick(cb, er); | ||
96874 | // this can emit finish, and it will always happen | ||
96875 | // after error | ||
96876 | processNextTick(finishMaybe, stream, state); | ||
96877 | stream._writableState.errorEmitted = true; | ||
96878 | stream.emit('error', er); | ||
96879 | } else { | ||
96880 | // the caller expect this to happen before if | ||
96881 | // it is async | ||
96882 | cb(er); | ||
96883 | stream._writableState.errorEmitted = true; | ||
96884 | stream.emit('error', er); | ||
96885 | // this can emit finish, but finish must | ||
96886 | // always follow error | ||
96887 | finishMaybe(stream, state); | ||
96888 | } | ||
96889 | } | ||
96890 | |||
96891 | function onwriteStateUpdate(state) { | ||
96892 | state.writing = false; | ||
96893 | state.writecb = null; | ||
96894 | state.length -= state.writelen; | ||
96895 | state.writelen = 0; | ||
96896 | } | ||
96897 | |||
96898 | function onwrite(stream, er) { | ||
96899 | var state = stream._writableState; | ||
96900 | var sync = state.sync; | ||
96901 | var cb = state.writecb; | ||
96902 | |||
96903 | onwriteStateUpdate(state); | ||
96904 | |||
96905 | if (er) onwriteError(stream, state, sync, er, cb);else { | ||
96906 | // Check if we're actually ready to finish, but don't emit yet | ||
96907 | var finished = needFinish(state); | ||
96908 | |||
96909 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { | ||
96910 | clearBuffer(stream, state); | ||
96911 | } | ||
96912 | |||
96913 | if (sync) { | ||
96914 | /*<replacement>*/ | ||
96915 | asyncWrite(afterWrite, stream, state, finished, cb); | ||
96916 | /*</replacement>*/ | ||
96917 | } else { | ||
96918 | afterWrite(stream, state, finished, cb); | ||
96919 | } | ||
96920 | } | ||
96921 | } | ||
96922 | |||
96923 | function afterWrite(stream, state, finished, cb) { | ||
96924 | if (!finished) onwriteDrain(stream, state); | ||
96925 | state.pendingcb--; | ||
96926 | cb(); | ||
96927 | finishMaybe(stream, state); | ||
96928 | } | ||
96929 | |||
96930 | // Must force callback to be called on nextTick, so that we don't | ||
96931 | // emit 'drain' before the write() consumer gets the 'false' return | ||
96932 | // value, and has a chance to attach a 'drain' listener. | ||
96933 | function onwriteDrain(stream, state) { | ||
96934 | if (state.length === 0 && state.needDrain) { | ||
96935 | state.needDrain = false; | ||
96936 | stream.emit('drain'); | ||
96937 | } | ||
96938 | } | ||
96939 | |||
96940 | // if there's something in the buffer waiting, then process it | ||
96941 | function clearBuffer(stream, state) { | ||
96942 | state.bufferProcessing = true; | ||
96943 | var entry = state.bufferedRequest; | ||
96944 | |||
96945 | if (stream._writev && entry && entry.next) { | ||
96946 | // Fast case, write everything using _writev() | ||
96947 | var l = state.bufferedRequestCount; | ||
96948 | var buffer = new Array(l); | ||
96949 | var holder = state.corkedRequestsFree; | ||
96950 | holder.entry = entry; | ||
96951 | |||
96952 | var count = 0; | ||
96953 | var allBuffers = true; | ||
96954 | while (entry) { | ||
96955 | buffer[count] = entry; | ||
96956 | if (!entry.isBuf) allBuffers = false; | ||
96957 | entry = entry.next; | ||
96958 | count += 1; | ||
96959 | } | ||
96960 | buffer.allBuffers = allBuffers; | ||
96961 | |||
96962 | doWrite(stream, state, true, state.length, buffer, '', holder.finish); | ||
96963 | |||
96964 | // doWrite is almost always async, defer these to save a bit of time | ||
96965 | // as the hot path ends with doWrite | ||
96966 | state.pendingcb++; | ||
96967 | state.lastBufferedRequest = null; | ||
96968 | if (holder.next) { | ||
96969 | state.corkedRequestsFree = holder.next; | ||
96970 | holder.next = null; | ||
96971 | } else { | ||
96972 | state.corkedRequestsFree = new CorkedRequest(state); | ||
96973 | } | ||
96974 | } else { | ||
96975 | // Slow case, write chunks one-by-one | ||
96976 | while (entry) { | ||
96977 | var chunk = entry.chunk; | ||
96978 | var encoding = entry.encoding; | ||
96979 | var cb = entry.callback; | ||
96980 | var len = state.objectMode ? 1 : chunk.length; | ||
96981 | |||
96982 | doWrite(stream, state, false, len, chunk, encoding, cb); | ||
96983 | entry = entry.next; | ||
96984 | // if we didn't call the onwrite immediately, then | ||
96985 | // it means that we need to wait until it does. | ||
96986 | // also, that means that the chunk and cb are currently | ||
96987 | // being processed, so move the buffer counter past them. | ||
96988 | if (state.writing) { | ||
96989 | break; | ||
96990 | } | ||
96991 | } | ||
96992 | |||
96993 | if (entry === null) state.lastBufferedRequest = null; | ||
96994 | } | ||
96995 | |||
96996 | state.bufferedRequestCount = 0; | ||
96997 | state.bufferedRequest = entry; | ||
96998 | state.bufferProcessing = false; | ||
96999 | } | ||
97000 | |||
97001 | Writable.prototype._write = function (chunk, encoding, cb) { | ||
97002 | cb(new Error('_write() is not implemented')); | ||
97003 | }; | ||
97004 | |||
97005 | Writable.prototype._writev = null; | ||
97006 | |||
97007 | Writable.prototype.end = function (chunk, encoding, cb) { | ||
97008 | var state = this._writableState; | ||
97009 | |||
97010 | if (typeof chunk === 'function') { | ||
97011 | cb = chunk; | ||
97012 | chunk = null; | ||
97013 | encoding = null; | ||
97014 | } else if (typeof encoding === 'function') { | ||
97015 | cb = encoding; | ||
97016 | encoding = null; | ||
97017 | } | ||
97018 | |||
97019 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); | ||
97020 | |||
97021 | // .end() fully uncorks | ||
97022 | if (state.corked) { | ||
97023 | state.corked = 1; | ||
97024 | this.uncork(); | ||
97025 | } | ||
97026 | |||
97027 | // ignore unnecessary end() calls. | ||
97028 | if (!state.ending && !state.finished) endWritable(this, state, cb); | ||
97029 | }; | ||
97030 | |||
97031 | function needFinish(state) { | ||
97032 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; | ||
97033 | } | ||
97034 | function callFinal(stream, state) { | ||
97035 | stream._final(function (err) { | ||
97036 | state.pendingcb--; | ||
97037 | if (err) { | ||
97038 | stream.emit('error', err); | ||
97039 | } | ||
97040 | state.prefinished = true; | ||
97041 | stream.emit('prefinish'); | ||
97042 | finishMaybe(stream, state); | ||
97043 | }); | ||
97044 | } | ||
97045 | function prefinish(stream, state) { | ||
97046 | if (!state.prefinished && !state.finalCalled) { | ||
97047 | if (typeof stream._final === 'function') { | ||
97048 | state.pendingcb++; | ||
97049 | state.finalCalled = true; | ||
97050 | processNextTick(callFinal, stream, state); | ||
97051 | } else { | ||
97052 | state.prefinished = true; | ||
97053 | stream.emit('prefinish'); | ||
97054 | } | ||
97055 | } | ||
97056 | } | ||
97057 | |||
97058 | function finishMaybe(stream, state) { | ||
97059 | var need = needFinish(state); | ||
97060 | if (need) { | ||
97061 | prefinish(stream, state); | ||
97062 | if (state.pendingcb === 0) { | ||
97063 | state.finished = true; | ||
97064 | stream.emit('finish'); | ||
97065 | } | ||
97066 | } | ||
97067 | return need; | ||
97068 | } | ||
97069 | |||
97070 | function endWritable(stream, state, cb) { | ||
97071 | state.ending = true; | ||
97072 | finishMaybe(stream, state); | ||
97073 | if (cb) { | ||
97074 | if (state.finished) processNextTick(cb);else stream.once('finish', cb); | ||
97075 | } | ||
97076 | state.ended = true; | ||
97077 | stream.writable = false; | ||
97078 | } | ||
97079 | |||
97080 | function onCorkedFinish(corkReq, state, err) { | ||
97081 | var entry = corkReq.entry; | ||
97082 | corkReq.entry = null; | ||
97083 | while (entry) { | ||
97084 | var cb = entry.callback; | ||
97085 | state.pendingcb--; | ||
97086 | cb(err); | ||
97087 | entry = entry.next; | ||
97088 | } | ||
97089 | if (state.corkedRequestsFree) { | ||
97090 | state.corkedRequestsFree.next = corkReq; | ||
97091 | } else { | ||
97092 | state.corkedRequestsFree = corkReq; | ||
97093 | } | ||
97094 | } | ||
97095 | |||
97096 | Object.defineProperty(Writable.prototype, 'destroyed', { | ||
97097 | get: function () { | ||
97098 | if (this._writableState === undefined) { | ||
97099 | return false; | ||
97100 | } | ||
97101 | return this._writableState.destroyed; | ||
97102 | }, | ||
97103 | set: function (value) { | ||
97104 | // we ignore the value if the stream | ||
97105 | // has not been initialized yet | ||
97106 | if (!this._writableState) { | ||
97107 | return; | ||
97108 | } | ||
97109 | |||
97110 | // backward compatibility, the user is explicitly | ||
97111 | // managing destroyed | ||
97112 | this._writableState.destroyed = value; | ||
97113 | } | ||
97114 | }); | ||
97115 | |||
97116 | Writable.prototype.destroy = destroyImpl.destroy; | ||
97117 | Writable.prototype._undestroy = destroyImpl.undestroy; | ||
97118 | Writable.prototype._destroy = function (err, cb) { | ||
97119 | this.end(); | ||
97120 | cb(err); | ||
97121 | }; | ||
97122 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
97123 | },{"./_stream_duplex":27,"./internal/streams/destroy":33,"./internal/streams/stream":34,"_process":25,"core-util-is":14,"inherits":21,"process-nextick-args":24,"safe-buffer":40,"util-deprecate":51}],32:[function(require,module,exports){ | ||
97124 | 'use strict'; | ||
97125 | |||
97126 | /*<replacement>*/ | ||
97127 | |||
97128 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
97129 | |||
97130 | var Buffer = require('safe-buffer').Buffer; | ||
97131 | /*</replacement>*/ | ||
97132 | |||
97133 | function copyBuffer(src, target, offset) { | ||
97134 | src.copy(target, offset); | ||
97135 | } | ||
97136 | |||
97137 | module.exports = function () { | ||
97138 | function BufferList() { | ||
97139 | _classCallCheck(this, BufferList); | ||
97140 | |||
97141 | this.head = null; | ||
97142 | this.tail = null; | ||
97143 | this.length = 0; | ||
97144 | } | ||
97145 | |||
97146 | BufferList.prototype.push = function push(v) { | ||
97147 | var entry = { data: v, next: null }; | ||
97148 | if (this.length > 0) this.tail.next = entry;else this.head = entry; | ||
97149 | this.tail = entry; | ||
97150 | ++this.length; | ||
97151 | }; | ||
97152 | |||
97153 | BufferList.prototype.unshift = function unshift(v) { | ||
97154 | var entry = { data: v, next: this.head }; | ||
97155 | if (this.length === 0) this.tail = entry; | ||
97156 | this.head = entry; | ||
97157 | ++this.length; | ||
97158 | }; | ||
97159 | |||
97160 | BufferList.prototype.shift = function shift() { | ||
97161 | if (this.length === 0) return; | ||
97162 | var ret = this.head.data; | ||
97163 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
97164 | --this.length; | ||
97165 | return ret; | ||
97166 | }; | ||
97167 | |||
97168 | BufferList.prototype.clear = function clear() { | ||
97169 | this.head = this.tail = null; | ||
97170 | this.length = 0; | ||
97171 | }; | ||
97172 | |||
97173 | BufferList.prototype.join = function join(s) { | ||
97174 | if (this.length === 0) return ''; | ||
97175 | var p = this.head; | ||
97176 | var ret = '' + p.data; | ||
97177 | while (p = p.next) { | ||
97178 | ret += s + p.data; | ||
97179 | }return ret; | ||
97180 | }; | ||
97181 | |||
97182 | BufferList.prototype.concat = function concat(n) { | ||
97183 | if (this.length === 0) return Buffer.alloc(0); | ||
97184 | if (this.length === 1) return this.head.data; | ||
97185 | var ret = Buffer.allocUnsafe(n >>> 0); | ||
97186 | var p = this.head; | ||
97187 | var i = 0; | ||
97188 | while (p) { | ||
97189 | copyBuffer(p.data, ret, i); | ||
97190 | i += p.data.length; | ||
97191 | p = p.next; | ||
97192 | } | ||
97193 | return ret; | ||
97194 | }; | ||
97195 | |||
97196 | return BufferList; | ||
97197 | }(); | ||
97198 | },{"safe-buffer":40}],33:[function(require,module,exports){ | ||
97199 | 'use strict'; | ||
97200 | |||
97201 | /*<replacement>*/ | ||
97202 | |||
97203 | var processNextTick = require('process-nextick-args'); | ||
97204 | /*</replacement>*/ | ||
97205 | |||
97206 | // undocumented cb() API, needed for core, not for public API | ||
97207 | function destroy(err, cb) { | ||
97208 | var _this = this; | ||
97209 | |||
97210 | var readableDestroyed = this._readableState && this._readableState.destroyed; | ||
97211 | var writableDestroyed = this._writableState && this._writableState.destroyed; | ||
97212 | |||
97213 | if (readableDestroyed || writableDestroyed) { | ||
97214 | if (cb) { | ||
97215 | cb(err); | ||
97216 | } else if (err && (!this._writableState || !this._writableState.errorEmitted)) { | ||
97217 | processNextTick(emitErrorNT, this, err); | ||
97218 | } | ||
97219 | return; | ||
97220 | } | ||
97221 | |||
97222 | // we set destroyed to true before firing error callbacks in order | ||
97223 | // to make it re-entrance safe in case destroy() is called within callbacks | ||
97224 | |||
97225 | if (this._readableState) { | ||
97226 | this._readableState.destroyed = true; | ||
97227 | } | ||
97228 | |||
97229 | // if this is a duplex stream mark the writable part as destroyed as well | ||
97230 | if (this._writableState) { | ||
97231 | this._writableState.destroyed = true; | ||
97232 | } | ||
97233 | |||
97234 | this._destroy(err || null, function (err) { | ||
97235 | if (!cb && err) { | ||
97236 | processNextTick(emitErrorNT, _this, err); | ||
97237 | if (_this._writableState) { | ||
97238 | _this._writableState.errorEmitted = true; | ||
97239 | } | ||
97240 | } else if (cb) { | ||
97241 | cb(err); | ||
97242 | } | ||
97243 | }); | ||
97244 | } | ||
97245 | |||
97246 | function undestroy() { | ||
97247 | if (this._readableState) { | ||
97248 | this._readableState.destroyed = false; | ||
97249 | this._readableState.reading = false; | ||
97250 | this._readableState.ended = false; | ||
97251 | this._readableState.endEmitted = false; | ||
97252 | } | ||
97253 | |||
97254 | if (this._writableState) { | ||
97255 | this._writableState.destroyed = false; | ||
97256 | this._writableState.ended = false; | ||
97257 | this._writableState.ending = false; | ||
97258 | this._writableState.finished = false; | ||
97259 | this._writableState.errorEmitted = false; | ||
97260 | } | ||
97261 | } | ||
97262 | |||
97263 | function emitErrorNT(self, err) { | ||
97264 | self.emit('error', err); | ||
97265 | } | ||
97266 | |||
97267 | module.exports = { | ||
97268 | destroy: destroy, | ||
97269 | undestroy: undestroy | ||
97270 | }; | ||
97271 | },{"process-nextick-args":24}],34:[function(require,module,exports){ | ||
97272 | module.exports = require('events').EventEmitter; | ||
97273 | |||
97274 | },{"events":18}],35:[function(require,module,exports){ | ||
97275 | module.exports = require('./readable').PassThrough | ||
97276 | |||
97277 | },{"./readable":36}],36:[function(require,module,exports){ | ||
97278 | exports = module.exports = require('./lib/_stream_readable.js'); | ||
97279 | exports.Stream = exports; | ||
97280 | exports.Readable = exports; | ||
97281 | exports.Writable = require('./lib/_stream_writable.js'); | ||
97282 | exports.Duplex = require('./lib/_stream_duplex.js'); | ||
97283 | exports.Transform = require('./lib/_stream_transform.js'); | ||
97284 | exports.PassThrough = require('./lib/_stream_passthrough.js'); | ||
97285 | |||
97286 | },{"./lib/_stream_duplex.js":27,"./lib/_stream_passthrough.js":28,"./lib/_stream_readable.js":29,"./lib/_stream_transform.js":30,"./lib/_stream_writable.js":31}],37:[function(require,module,exports){ | ||
97287 | module.exports = require('./readable').Transform | ||
97288 | |||
97289 | },{"./readable":36}],38:[function(require,module,exports){ | ||
97290 | module.exports = require('./lib/_stream_writable.js'); | ||
97291 | |||
97292 | },{"./lib/_stream_writable.js":31}],39:[function(require,module,exports){ | ||
97293 | (function (Buffer){ | ||
97294 | 'use strict' | ||
97295 | var inherits = require('inherits') | ||
97296 | var HashBase = require('hash-base') | ||
97297 | |||
97298 | function RIPEMD160 () { | ||
97299 | HashBase.call(this, 64) | ||
97300 | |||
97301 | // state | ||
97302 | this._a = 0x67452301 | ||
97303 | this._b = 0xefcdab89 | ||
97304 | this._c = 0x98badcfe | ||
97305 | this._d = 0x10325476 | ||
97306 | this._e = 0xc3d2e1f0 | ||
97307 | } | ||
97308 | |||
97309 | inherits(RIPEMD160, HashBase) | ||
97310 | |||
97311 | RIPEMD160.prototype._update = function () { | ||
97312 | var m = new Array(16) | ||
97313 | for (var i = 0; i < 16; ++i) m[i] = this._block.readInt32LE(i * 4) | ||
97314 | |||
97315 | var al = this._a | ||
97316 | var bl = this._b | ||
97317 | var cl = this._c | ||
97318 | var dl = this._d | ||
97319 | var el = this._e | ||
97320 | |||
97321 | // Mj = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 | ||
97322 | // K = 0x00000000 | ||
97323 | // Sj = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8 | ||
97324 | al = fn1(al, bl, cl, dl, el, m[0], 0x00000000, 11); cl = rotl(cl, 10) | ||
97325 | el = fn1(el, al, bl, cl, dl, m[1], 0x00000000, 14); bl = rotl(bl, 10) | ||
97326 | dl = fn1(dl, el, al, bl, cl, m[2], 0x00000000, 15); al = rotl(al, 10) | ||
97327 | cl = fn1(cl, dl, el, al, bl, m[3], 0x00000000, 12); el = rotl(el, 10) | ||
97328 | bl = fn1(bl, cl, dl, el, al, m[4], 0x00000000, 5); dl = rotl(dl, 10) | ||
97329 | al = fn1(al, bl, cl, dl, el, m[5], 0x00000000, 8); cl = rotl(cl, 10) | ||
97330 | el = fn1(el, al, bl, cl, dl, m[6], 0x00000000, 7); bl = rotl(bl, 10) | ||
97331 | dl = fn1(dl, el, al, bl, cl, m[7], 0x00000000, 9); al = rotl(al, 10) | ||
97332 | cl = fn1(cl, dl, el, al, bl, m[8], 0x00000000, 11); el = rotl(el, 10) | ||
97333 | bl = fn1(bl, cl, dl, el, al, m[9], 0x00000000, 13); dl = rotl(dl, 10) | ||
97334 | al = fn1(al, bl, cl, dl, el, m[10], 0x00000000, 14); cl = rotl(cl, 10) | ||
97335 | el = fn1(el, al, bl, cl, dl, m[11], 0x00000000, 15); bl = rotl(bl, 10) | ||
97336 | dl = fn1(dl, el, al, bl, cl, m[12], 0x00000000, 6); al = rotl(al, 10) | ||
97337 | cl = fn1(cl, dl, el, al, bl, m[13], 0x00000000, 7); el = rotl(el, 10) | ||
97338 | bl = fn1(bl, cl, dl, el, al, m[14], 0x00000000, 9); dl = rotl(dl, 10) | ||
97339 | al = fn1(al, bl, cl, dl, el, m[15], 0x00000000, 8); cl = rotl(cl, 10) | ||
97340 | |||
97341 | // Mj = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 | ||
97342 | // K = 0x5a827999 | ||
97343 | // Sj = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12 | ||
97344 | el = fn2(el, al, bl, cl, dl, m[7], 0x5a827999, 7); bl = rotl(bl, 10) | ||
97345 | dl = fn2(dl, el, al, bl, cl, m[4], 0x5a827999, 6); al = rotl(al, 10) | ||
97346 | cl = fn2(cl, dl, el, al, bl, m[13], 0x5a827999, 8); el = rotl(el, 10) | ||
97347 | bl = fn2(bl, cl, dl, el, al, m[1], 0x5a827999, 13); dl = rotl(dl, 10) | ||
97348 | al = fn2(al, bl, cl, dl, el, m[10], 0x5a827999, 11); cl = rotl(cl, 10) | ||
97349 | el = fn2(el, al, bl, cl, dl, m[6], 0x5a827999, 9); bl = rotl(bl, 10) | ||
97350 | dl = fn2(dl, el, al, bl, cl, m[15], 0x5a827999, 7); al = rotl(al, 10) | ||
97351 | cl = fn2(cl, dl, el, al, bl, m[3], 0x5a827999, 15); el = rotl(el, 10) | ||
97352 | bl = fn2(bl, cl, dl, el, al, m[12], 0x5a827999, 7); dl = rotl(dl, 10) | ||
97353 | al = fn2(al, bl, cl, dl, el, m[0], 0x5a827999, 12); cl = rotl(cl, 10) | ||
97354 | el = fn2(el, al, bl, cl, dl, m[9], 0x5a827999, 15); bl = rotl(bl, 10) | ||
97355 | dl = fn2(dl, el, al, bl, cl, m[5], 0x5a827999, 9); al = rotl(al, 10) | ||
97356 | cl = fn2(cl, dl, el, al, bl, m[2], 0x5a827999, 11); el = rotl(el, 10) | ||
97357 | bl = fn2(bl, cl, dl, el, al, m[14], 0x5a827999, 7); dl = rotl(dl, 10) | ||
97358 | al = fn2(al, bl, cl, dl, el, m[11], 0x5a827999, 13); cl = rotl(cl, 10) | ||
97359 | el = fn2(el, al, bl, cl, dl, m[8], 0x5a827999, 12); bl = rotl(bl, 10) | ||
97360 | |||
97361 | // Mj = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12 | ||
97362 | // K = 0x6ed9eba1 | ||
97363 | // Sj = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5 | ||
97364 | dl = fn3(dl, el, al, bl, cl, m[3], 0x6ed9eba1, 11); al = rotl(al, 10) | ||
97365 | cl = fn3(cl, dl, el, al, bl, m[10], 0x6ed9eba1, 13); el = rotl(el, 10) | ||
97366 | bl = fn3(bl, cl, dl, el, al, m[14], 0x6ed9eba1, 6); dl = rotl(dl, 10) | ||
97367 | al = fn3(al, bl, cl, dl, el, m[4], 0x6ed9eba1, 7); cl = rotl(cl, 10) | ||
97368 | el = fn3(el, al, bl, cl, dl, m[9], 0x6ed9eba1, 14); bl = rotl(bl, 10) | ||
97369 | dl = fn3(dl, el, al, bl, cl, m[15], 0x6ed9eba1, 9); al = rotl(al, 10) | ||
97370 | cl = fn3(cl, dl, el, al, bl, m[8], 0x6ed9eba1, 13); el = rotl(el, 10) | ||
97371 | bl = fn3(bl, cl, dl, el, al, m[1], 0x6ed9eba1, 15); dl = rotl(dl, 10) | ||
97372 | al = fn3(al, bl, cl, dl, el, m[2], 0x6ed9eba1, 14); cl = rotl(cl, 10) | ||
97373 | el = fn3(el, al, bl, cl, dl, m[7], 0x6ed9eba1, 8); bl = rotl(bl, 10) | ||
97374 | dl = fn3(dl, el, al, bl, cl, m[0], 0x6ed9eba1, 13); al = rotl(al, 10) | ||
97375 | cl = fn3(cl, dl, el, al, bl, m[6], 0x6ed9eba1, 6); el = rotl(el, 10) | ||
97376 | bl = fn3(bl, cl, dl, el, al, m[13], 0x6ed9eba1, 5); dl = rotl(dl, 10) | ||
97377 | al = fn3(al, bl, cl, dl, el, m[11], 0x6ed9eba1, 12); cl = rotl(cl, 10) | ||
97378 | el = fn3(el, al, bl, cl, dl, m[5], 0x6ed9eba1, 7); bl = rotl(bl, 10) | ||
97379 | dl = fn3(dl, el, al, bl, cl, m[12], 0x6ed9eba1, 5); al = rotl(al, 10) | ||
97380 | |||
97381 | // Mj = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2 | ||
97382 | // K = 0x8f1bbcdc | ||
97383 | // Sj = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12 | ||
97384 | cl = fn4(cl, dl, el, al, bl, m[1], 0x8f1bbcdc, 11); el = rotl(el, 10) | ||
97385 | bl = fn4(bl, cl, dl, el, al, m[9], 0x8f1bbcdc, 12); dl = rotl(dl, 10) | ||
97386 | al = fn4(al, bl, cl, dl, el, m[11], 0x8f1bbcdc, 14); cl = rotl(cl, 10) | ||
97387 | el = fn4(el, al, bl, cl, dl, m[10], 0x8f1bbcdc, 15); bl = rotl(bl, 10) | ||
97388 | dl = fn4(dl, el, al, bl, cl, m[0], 0x8f1bbcdc, 14); al = rotl(al, 10) | ||
97389 | cl = fn4(cl, dl, el, al, bl, m[8], 0x8f1bbcdc, 15); el = rotl(el, 10) | ||
97390 | bl = fn4(bl, cl, dl, el, al, m[12], 0x8f1bbcdc, 9); dl = rotl(dl, 10) | ||
97391 | al = fn4(al, bl, cl, dl, el, m[4], 0x8f1bbcdc, 8); cl = rotl(cl, 10) | ||
97392 | el = fn4(el, al, bl, cl, dl, m[13], 0x8f1bbcdc, 9); bl = rotl(bl, 10) | ||
97393 | dl = fn4(dl, el, al, bl, cl, m[3], 0x8f1bbcdc, 14); al = rotl(al, 10) | ||
97394 | cl = fn4(cl, dl, el, al, bl, m[7], 0x8f1bbcdc, 5); el = rotl(el, 10) | ||
97395 | bl = fn4(bl, cl, dl, el, al, m[15], 0x8f1bbcdc, 6); dl = rotl(dl, 10) | ||
97396 | al = fn4(al, bl, cl, dl, el, m[14], 0x8f1bbcdc, 8); cl = rotl(cl, 10) | ||
97397 | el = fn4(el, al, bl, cl, dl, m[5], 0x8f1bbcdc, 6); bl = rotl(bl, 10) | ||
97398 | dl = fn4(dl, el, al, bl, cl, m[6], 0x8f1bbcdc, 5); al = rotl(al, 10) | ||
97399 | cl = fn4(cl, dl, el, al, bl, m[2], 0x8f1bbcdc, 12); el = rotl(el, 10) | ||
97400 | |||
97401 | // Mj = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 | ||
97402 | // K = 0xa953fd4e | ||
97403 | // Sj = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 | ||
97404 | bl = fn5(bl, cl, dl, el, al, m[4], 0xa953fd4e, 9); dl = rotl(dl, 10) | ||
97405 | al = fn5(al, bl, cl, dl, el, m[0], 0xa953fd4e, 15); cl = rotl(cl, 10) | ||
97406 | el = fn5(el, al, bl, cl, dl, m[5], 0xa953fd4e, 5); bl = rotl(bl, 10) | ||
97407 | dl = fn5(dl, el, al, bl, cl, m[9], 0xa953fd4e, 11); al = rotl(al, 10) | ||
97408 | cl = fn5(cl, dl, el, al, bl, m[7], 0xa953fd4e, 6); el = rotl(el, 10) | ||
97409 | bl = fn5(bl, cl, dl, el, al, m[12], 0xa953fd4e, 8); dl = rotl(dl, 10) | ||
97410 | al = fn5(al, bl, cl, dl, el, m[2], 0xa953fd4e, 13); cl = rotl(cl, 10) | ||
97411 | el = fn5(el, al, bl, cl, dl, m[10], 0xa953fd4e, 12); bl = rotl(bl, 10) | ||
97412 | dl = fn5(dl, el, al, bl, cl, m[14], 0xa953fd4e, 5); al = rotl(al, 10) | ||
97413 | cl = fn5(cl, dl, el, al, bl, m[1], 0xa953fd4e, 12); el = rotl(el, 10) | ||
97414 | bl = fn5(bl, cl, dl, el, al, m[3], 0xa953fd4e, 13); dl = rotl(dl, 10) | ||
97415 | al = fn5(al, bl, cl, dl, el, m[8], 0xa953fd4e, 14); cl = rotl(cl, 10) | ||
97416 | el = fn5(el, al, bl, cl, dl, m[11], 0xa953fd4e, 11); bl = rotl(bl, 10) | ||
97417 | dl = fn5(dl, el, al, bl, cl, m[6], 0xa953fd4e, 8); al = rotl(al, 10) | ||
97418 | cl = fn5(cl, dl, el, al, bl, m[15], 0xa953fd4e, 5); el = rotl(el, 10) | ||
97419 | bl = fn5(bl, cl, dl, el, al, m[13], 0xa953fd4e, 6); dl = rotl(dl, 10) | ||
97420 | |||
97421 | var ar = this._a | ||
97422 | var br = this._b | ||
97423 | var cr = this._c | ||
97424 | var dr = this._d | ||
97425 | var er = this._e | ||
97426 | |||
97427 | // M'j = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12 | ||
97428 | // K' = 0x50a28be6 | ||
97429 | // S'j = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6 | ||
97430 | ar = fn5(ar, br, cr, dr, er, m[5], 0x50a28be6, 8); cr = rotl(cr, 10) | ||
97431 | er = fn5(er, ar, br, cr, dr, m[14], 0x50a28be6, 9); br = rotl(br, 10) | ||
97432 | dr = fn5(dr, er, ar, br, cr, m[7], 0x50a28be6, 9); ar = rotl(ar, 10) | ||
97433 | cr = fn5(cr, dr, er, ar, br, m[0], 0x50a28be6, 11); er = rotl(er, 10) | ||
97434 | br = fn5(br, cr, dr, er, ar, m[9], 0x50a28be6, 13); dr = rotl(dr, 10) | ||
97435 | ar = fn5(ar, br, cr, dr, er, m[2], 0x50a28be6, 15); cr = rotl(cr, 10) | ||
97436 | er = fn5(er, ar, br, cr, dr, m[11], 0x50a28be6, 15); br = rotl(br, 10) | ||
97437 | dr = fn5(dr, er, ar, br, cr, m[4], 0x50a28be6, 5); ar = rotl(ar, 10) | ||
97438 | cr = fn5(cr, dr, er, ar, br, m[13], 0x50a28be6, 7); er = rotl(er, 10) | ||
97439 | br = fn5(br, cr, dr, er, ar, m[6], 0x50a28be6, 7); dr = rotl(dr, 10) | ||
97440 | ar = fn5(ar, br, cr, dr, er, m[15], 0x50a28be6, 8); cr = rotl(cr, 10) | ||
97441 | er = fn5(er, ar, br, cr, dr, m[8], 0x50a28be6, 11); br = rotl(br, 10) | ||
97442 | dr = fn5(dr, er, ar, br, cr, m[1], 0x50a28be6, 14); ar = rotl(ar, 10) | ||
97443 | cr = fn5(cr, dr, er, ar, br, m[10], 0x50a28be6, 14); er = rotl(er, 10) | ||
97444 | br = fn5(br, cr, dr, er, ar, m[3], 0x50a28be6, 12); dr = rotl(dr, 10) | ||
97445 | ar = fn5(ar, br, cr, dr, er, m[12], 0x50a28be6, 6); cr = rotl(cr, 10) | ||
97446 | |||
97447 | // M'j = 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2 | ||
97448 | // K' = 0x5c4dd124 | ||
97449 | // S'j = 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11 | ||
97450 | er = fn4(er, ar, br, cr, dr, m[6], 0x5c4dd124, 9); br = rotl(br, 10) | ||
97451 | dr = fn4(dr, er, ar, br, cr, m[11], 0x5c4dd124, 13); ar = rotl(ar, 10) | ||
97452 | cr = fn4(cr, dr, er, ar, br, m[3], 0x5c4dd124, 15); er = rotl(er, 10) | ||
97453 | br = fn4(br, cr, dr, er, ar, m[7], 0x5c4dd124, 7); dr = rotl(dr, 10) | ||
97454 | ar = fn4(ar, br, cr, dr, er, m[0], 0x5c4dd124, 12); cr = rotl(cr, 10) | ||
97455 | er = fn4(er, ar, br, cr, dr, m[13], 0x5c4dd124, 8); br = rotl(br, 10) | ||
97456 | dr = fn4(dr, er, ar, br, cr, m[5], 0x5c4dd124, 9); ar = rotl(ar, 10) | ||
97457 | cr = fn4(cr, dr, er, ar, br, m[10], 0x5c4dd124, 11); er = rotl(er, 10) | ||
97458 | br = fn4(br, cr, dr, er, ar, m[14], 0x5c4dd124, 7); dr = rotl(dr, 10) | ||
97459 | ar = fn4(ar, br, cr, dr, er, m[15], 0x5c4dd124, 7); cr = rotl(cr, 10) | ||
97460 | er = fn4(er, ar, br, cr, dr, m[8], 0x5c4dd124, 12); br = rotl(br, 10) | ||
97461 | dr = fn4(dr, er, ar, br, cr, m[12], 0x5c4dd124, 7); ar = rotl(ar, 10) | ||
97462 | cr = fn4(cr, dr, er, ar, br, m[4], 0x5c4dd124, 6); er = rotl(er, 10) | ||
97463 | br = fn4(br, cr, dr, er, ar, m[9], 0x5c4dd124, 15); dr = rotl(dr, 10) | ||
97464 | ar = fn4(ar, br, cr, dr, er, m[1], 0x5c4dd124, 13); cr = rotl(cr, 10) | ||
97465 | er = fn4(er, ar, br, cr, dr, m[2], 0x5c4dd124, 11); br = rotl(br, 10) | ||
97466 | |||
97467 | // M'j = 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13 | ||
97468 | // K' = 0x6d703ef3 | ||
97469 | // S'j = 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5 | ||
97470 | dr = fn3(dr, er, ar, br, cr, m[15], 0x6d703ef3, 9); ar = rotl(ar, 10) | ||
97471 | cr = fn3(cr, dr, er, ar, br, m[5], 0x6d703ef3, 7); er = rotl(er, 10) | ||
97472 | br = fn3(br, cr, dr, er, ar, m[1], 0x6d703ef3, 15); dr = rotl(dr, 10) | ||
97473 | ar = fn3(ar, br, cr, dr, er, m[3], 0x6d703ef3, 11); cr = rotl(cr, 10) | ||
97474 | er = fn3(er, ar, br, cr, dr, m[7], 0x6d703ef3, 8); br = rotl(br, 10) | ||
97475 | dr = fn3(dr, er, ar, br, cr, m[14], 0x6d703ef3, 6); ar = rotl(ar, 10) | ||
97476 | cr = fn3(cr, dr, er, ar, br, m[6], 0x6d703ef3, 6); er = rotl(er, 10) | ||
97477 | br = fn3(br, cr, dr, er, ar, m[9], 0x6d703ef3, 14); dr = rotl(dr, 10) | ||
97478 | ar = fn3(ar, br, cr, dr, er, m[11], 0x6d703ef3, 12); cr = rotl(cr, 10) | ||
97479 | er = fn3(er, ar, br, cr, dr, m[8], 0x6d703ef3, 13); br = rotl(br, 10) | ||
97480 | dr = fn3(dr, er, ar, br, cr, m[12], 0x6d703ef3, 5); ar = rotl(ar, 10) | ||
97481 | cr = fn3(cr, dr, er, ar, br, m[2], 0x6d703ef3, 14); er = rotl(er, 10) | ||
97482 | br = fn3(br, cr, dr, er, ar, m[10], 0x6d703ef3, 13); dr = rotl(dr, 10) | ||
97483 | ar = fn3(ar, br, cr, dr, er, m[0], 0x6d703ef3, 13); cr = rotl(cr, 10) | ||
97484 | er = fn3(er, ar, br, cr, dr, m[4], 0x6d703ef3, 7); br = rotl(br, 10) | ||
97485 | dr = fn3(dr, er, ar, br, cr, m[13], 0x6d703ef3, 5); ar = rotl(ar, 10) | ||
97486 | |||
97487 | // M'j = 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14 | ||
97488 | // K' = 0x7a6d76e9 | ||
97489 | // S'j = 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8 | ||
97490 | cr = fn2(cr, dr, er, ar, br, m[8], 0x7a6d76e9, 15); er = rotl(er, 10) | ||
97491 | br = fn2(br, cr, dr, er, ar, m[6], 0x7a6d76e9, 5); dr = rotl(dr, 10) | ||
97492 | ar = fn2(ar, br, cr, dr, er, m[4], 0x7a6d76e9, 8); cr = rotl(cr, 10) | ||
97493 | er = fn2(er, ar, br, cr, dr, m[1], 0x7a6d76e9, 11); br = rotl(br, 10) | ||
97494 | dr = fn2(dr, er, ar, br, cr, m[3], 0x7a6d76e9, 14); ar = rotl(ar, 10) | ||
97495 | cr = fn2(cr, dr, er, ar, br, m[11], 0x7a6d76e9, 14); er = rotl(er, 10) | ||
97496 | br = fn2(br, cr, dr, er, ar, m[15], 0x7a6d76e9, 6); dr = rotl(dr, 10) | ||
97497 | ar = fn2(ar, br, cr, dr, er, m[0], 0x7a6d76e9, 14); cr = rotl(cr, 10) | ||
97498 | er = fn2(er, ar, br, cr, dr, m[5], 0x7a6d76e9, 6); br = rotl(br, 10) | ||
97499 | dr = fn2(dr, er, ar, br, cr, m[12], 0x7a6d76e9, 9); ar = rotl(ar, 10) | ||
97500 | cr = fn2(cr, dr, er, ar, br, m[2], 0x7a6d76e9, 12); er = rotl(er, 10) | ||
97501 | br = fn2(br, cr, dr, er, ar, m[13], 0x7a6d76e9, 9); dr = rotl(dr, 10) | ||
97502 | ar = fn2(ar, br, cr, dr, er, m[9], 0x7a6d76e9, 12); cr = rotl(cr, 10) | ||
97503 | er = fn2(er, ar, br, cr, dr, m[7], 0x7a6d76e9, 5); br = rotl(br, 10) | ||
97504 | dr = fn2(dr, er, ar, br, cr, m[10], 0x7a6d76e9, 15); ar = rotl(ar, 10) | ||
97505 | cr = fn2(cr, dr, er, ar, br, m[14], 0x7a6d76e9, 8); er = rotl(er, 10) | ||
97506 | |||
97507 | // M'j = 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 | ||
97508 | // K' = 0x00000000 | ||
97509 | // S'j = 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 | ||
97510 | br = fn1(br, cr, dr, er, ar, m[12], 0x00000000, 8); dr = rotl(dr, 10) | ||
97511 | ar = fn1(ar, br, cr, dr, er, m[15], 0x00000000, 5); cr = rotl(cr, 10) | ||
97512 | er = fn1(er, ar, br, cr, dr, m[10], 0x00000000, 12); br = rotl(br, 10) | ||
97513 | dr = fn1(dr, er, ar, br, cr, m[4], 0x00000000, 9); ar = rotl(ar, 10) | ||
97514 | cr = fn1(cr, dr, er, ar, br, m[1], 0x00000000, 12); er = rotl(er, 10) | ||
97515 | br = fn1(br, cr, dr, er, ar, m[5], 0x00000000, 5); dr = rotl(dr, 10) | ||
97516 | ar = fn1(ar, br, cr, dr, er, m[8], 0x00000000, 14); cr = rotl(cr, 10) | ||
97517 | er = fn1(er, ar, br, cr, dr, m[7], 0x00000000, 6); br = rotl(br, 10) | ||
97518 | dr = fn1(dr, er, ar, br, cr, m[6], 0x00000000, 8); ar = rotl(ar, 10) | ||
97519 | cr = fn1(cr, dr, er, ar, br, m[2], 0x00000000, 13); er = rotl(er, 10) | ||
97520 | br = fn1(br, cr, dr, er, ar, m[13], 0x00000000, 6); dr = rotl(dr, 10) | ||
97521 | ar = fn1(ar, br, cr, dr, er, m[14], 0x00000000, 5); cr = rotl(cr, 10) | ||
97522 | er = fn1(er, ar, br, cr, dr, m[0], 0x00000000, 15); br = rotl(br, 10) | ||
97523 | dr = fn1(dr, er, ar, br, cr, m[3], 0x00000000, 13); ar = rotl(ar, 10) | ||
97524 | cr = fn1(cr, dr, er, ar, br, m[9], 0x00000000, 11); er = rotl(er, 10) | ||
97525 | br = fn1(br, cr, dr, er, ar, m[11], 0x00000000, 11); dr = rotl(dr, 10) | ||
97526 | |||
97527 | // change state | ||
97528 | var t = (this._b + cl + dr) | 0 | ||
97529 | this._b = (this._c + dl + er) | 0 | ||
97530 | this._c = (this._d + el + ar) | 0 | ||
97531 | this._d = (this._e + al + br) | 0 | ||
97532 | this._e = (this._a + bl + cr) | 0 | ||
97533 | this._a = t | ||
97534 | } | ||
97535 | |||
97536 | RIPEMD160.prototype._digest = function () { | ||
97537 | // create padding and handle blocks | ||
97538 | this._block[this._blockOffset++] = 0x80 | ||
97539 | if (this._blockOffset > 56) { | ||
97540 | this._block.fill(0, this._blockOffset, 64) | ||
97541 | this._update() | ||
97542 | this._blockOffset = 0 | ||
97543 | } | ||
97544 | |||
97545 | this._block.fill(0, this._blockOffset, 56) | ||
97546 | this._block.writeUInt32LE(this._length[0], 56) | ||
97547 | this._block.writeUInt32LE(this._length[1], 60) | ||
97548 | this._update() | ||
97549 | |||
97550 | // produce result | ||
97551 | var buffer = new Buffer(20) | ||
97552 | buffer.writeInt32LE(this._a, 0) | ||
97553 | buffer.writeInt32LE(this._b, 4) | ||
97554 | buffer.writeInt32LE(this._c, 8) | ||
97555 | buffer.writeInt32LE(this._d, 12) | ||
97556 | buffer.writeInt32LE(this._e, 16) | ||
97557 | return buffer | ||
97558 | } | ||
97559 | |||
97560 | function rotl (x, n) { | ||
97561 | return (x << n) | (x >>> (32 - n)) | ||
97562 | } | ||
97563 | |||
97564 | function fn1 (a, b, c, d, e, m, k, s) { | ||
97565 | return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0 | ||
97566 | } | ||
97567 | |||
97568 | function fn2 (a, b, c, d, e, m, k, s) { | ||
97569 | return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0 | ||
97570 | } | ||
97571 | |||
97572 | function fn3 (a, b, c, d, e, m, k, s) { | ||
97573 | return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0 | ||
97574 | } | ||
97575 | |||
97576 | function fn4 (a, b, c, d, e, m, k, s) { | ||
97577 | return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0 | ||
97578 | } | ||
97579 | |||
97580 | function fn5 (a, b, c, d, e, m, k, s) { | ||
97581 | return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0 | ||
97582 | } | ||
97583 | |||
97584 | module.exports = RIPEMD160 | ||
97585 | |||
97586 | }).call(this,require("buffer").Buffer) | ||
97587 | },{"buffer":8,"hash-base":19,"inherits":21}],40:[function(require,module,exports){ | ||
97588 | /* eslint-disable node/no-deprecated-api */ | ||
97589 | var buffer = require('buffer') | ||
97590 | var Buffer = buffer.Buffer | ||
97591 | |||
97592 | // alternative to using Object.keys for old browsers | ||
97593 | function copyProps (src, dst) { | ||
97594 | for (var key in src) { | ||
97595 | dst[key] = src[key] | ||
97596 | } | ||
97597 | } | ||
97598 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { | ||
97599 | module.exports = buffer | ||
97600 | } else { | ||
97601 | // Copy properties from require('buffer') | ||
97602 | copyProps(buffer, exports) | ||
97603 | exports.Buffer = SafeBuffer | ||
97604 | } | ||
97605 | |||
97606 | function SafeBuffer (arg, encodingOrOffset, length) { | ||
97607 | return Buffer(arg, encodingOrOffset, length) | ||
97608 | } | ||
97609 | |||
97610 | // Copy static methods from Buffer | ||
97611 | copyProps(Buffer, SafeBuffer) | ||
97612 | |||
97613 | SafeBuffer.from = function (arg, encodingOrOffset, length) { | ||
97614 | if (typeof arg === 'number') { | ||
97615 | throw new TypeError('Argument must not be a number') | ||
97616 | } | ||
97617 | return Buffer(arg, encodingOrOffset, length) | ||
97618 | } | ||
97619 | |||
97620 | SafeBuffer.alloc = function (size, fill, encoding) { | ||
97621 | if (typeof size !== 'number') { | ||
97622 | throw new TypeError('Argument must be a number') | ||
97623 | } | ||
97624 | var buf = Buffer(size) | ||
97625 | if (fill !== undefined) { | ||
97626 | if (typeof encoding === 'string') { | ||
97627 | buf.fill(fill, encoding) | ||
97628 | } else { | ||
97629 | buf.fill(fill) | ||
97630 | } | ||
97631 | } else { | ||
97632 | buf.fill(0) | ||
97633 | } | ||
97634 | return buf | ||
97635 | } | ||
97636 | |||
97637 | SafeBuffer.allocUnsafe = function (size) { | ||
97638 | if (typeof size !== 'number') { | ||
97639 | throw new TypeError('Argument must be a number') | ||
97640 | } | ||
97641 | return Buffer(size) | ||
97642 | } | ||
97643 | |||
97644 | SafeBuffer.allocUnsafeSlow = function (size) { | ||
97645 | if (typeof size !== 'number') { | ||
97646 | throw new TypeError('Argument must be a number') | ||
97647 | } | ||
97648 | return buffer.SlowBuffer(size) | ||
97649 | } | ||
97650 | |||
97651 | },{"buffer":8}],41:[function(require,module,exports){ | ||
97652 | var Buffer = require('safe-buffer').Buffer | ||
97653 | |||
97654 | // prototype class for hash functions | ||
97655 | function Hash (blockSize, finalSize) { | ||
97656 | this._block = Buffer.alloc(blockSize) | ||
97657 | this._finalSize = finalSize | ||
97658 | this._blockSize = blockSize | ||
97659 | this._len = 0 | ||
97660 | } | ||
97661 | |||
97662 | Hash.prototype.update = function (data, enc) { | ||
97663 | if (typeof data === 'string') { | ||
97664 | enc = enc || 'utf8' | ||
97665 | data = Buffer.from(data, enc) | ||
97666 | } | ||
97667 | |||
97668 | var block = this._block | ||
97669 | var blockSize = this._blockSize | ||
97670 | var length = data.length | ||
97671 | var accum = this._len | ||
97672 | |||
97673 | for (var offset = 0; offset < length;) { | ||
97674 | var assigned = accum % blockSize | ||
97675 | var remainder = Math.min(length - offset, blockSize - assigned) | ||
97676 | |||
97677 | for (var i = 0; i < remainder; i++) { | ||
97678 | block[assigned + i] = data[offset + i] | ||
97679 | } | ||
97680 | |||
97681 | accum += remainder | ||
97682 | offset += remainder | ||
97683 | |||
97684 | if ((accum % blockSize) === 0) { | ||
97685 | this._update(block) | ||
97686 | } | ||
97687 | } | ||
97688 | |||
97689 | this._len += length | ||
97690 | return this | ||
97691 | } | ||
97692 | |||
97693 | Hash.prototype.digest = function (enc) { | ||
97694 | var rem = this._len % this._blockSize | ||
97695 | |||
97696 | this._block[rem] = 0x80 | ||
97697 | |||
97698 | // zero (rem + 1) trailing bits, where (rem + 1) is the smallest | ||
97699 | // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize | ||
97700 | this._block.fill(0, rem + 1) | ||
97701 | |||
97702 | if (rem >= this._finalSize) { | ||
97703 | this._update(this._block) | ||
97704 | this._block.fill(0) | ||
97705 | } | ||
97706 | |||
97707 | var bits = this._len * 8 | ||
97708 | |||
97709 | // uint32 | ||
97710 | if (bits <= 0xffffffff) { | ||
97711 | this._block.writeUInt32BE(bits, this._blockSize - 4) | ||
97712 | |||
97713 | // uint64 | ||
97714 | } else { | ||
97715 | var lowBits = bits & 0xffffffff | ||
97716 | var highBits = (bits - lowBits) / 0x100000000 | ||
97717 | |||
97718 | this._block.writeUInt32BE(highBits, this._blockSize - 8) | ||
97719 | this._block.writeUInt32BE(lowBits, this._blockSize - 4) | ||
97720 | } | ||
97721 | |||
97722 | this._update(this._block) | ||
97723 | var hash = this._hash() | ||
97724 | |||
97725 | return enc ? hash.toString(enc) : hash | ||
97726 | } | ||
97727 | |||
97728 | Hash.prototype._update = function () { | ||
97729 | throw new Error('_update must be implemented by subclass') | ||
97730 | } | ||
97731 | |||
97732 | module.exports = Hash | ||
97733 | |||
97734 | },{"safe-buffer":40}],42:[function(require,module,exports){ | ||
97735 | var exports = module.exports = function SHA (algorithm) { | ||
97736 | algorithm = algorithm.toLowerCase() | ||
97737 | |||
97738 | var Algorithm = exports[algorithm] | ||
97739 | if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)') | ||
97740 | |||
97741 | return new Algorithm() | ||
97742 | } | ||
97743 | |||
97744 | exports.sha = require('./sha') | ||
97745 | exports.sha1 = require('./sha1') | ||
97746 | exports.sha224 = require('./sha224') | ||
97747 | exports.sha256 = require('./sha256') | ||
97748 | exports.sha384 = require('./sha384') | ||
97749 | exports.sha512 = require('./sha512') | ||
97750 | |||
97751 | },{"./sha":43,"./sha1":44,"./sha224":45,"./sha256":46,"./sha384":47,"./sha512":48}],43:[function(require,module,exports){ | ||
97752 | /* | ||
97753 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined | ||
97754 | * in FIPS PUB 180-1 | ||
97755 | * This source code is derived from sha1.js of the same repository. | ||
97756 | * The difference between SHA-0 and SHA-1 is just a bitwise rotate left | ||
97757 | * operation was added. | ||
97758 | */ | ||
97759 | |||
97760 | var inherits = require('inherits') | ||
97761 | var Hash = require('./hash') | ||
97762 | var Buffer = require('safe-buffer').Buffer | ||
97763 | |||
97764 | var K = [ | ||
97765 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | ||
97766 | ] | ||
97767 | |||
97768 | var W = new Array(80) | ||
97769 | |||
97770 | function Sha () { | ||
97771 | this.init() | ||
97772 | this._w = W | ||
97773 | |||
97774 | Hash.call(this, 64, 56) | ||
97775 | } | ||
97776 | |||
97777 | inherits(Sha, Hash) | ||
97778 | |||
97779 | Sha.prototype.init = function () { | ||
97780 | this._a = 0x67452301 | ||
97781 | this._b = 0xefcdab89 | ||
97782 | this._c = 0x98badcfe | ||
97783 | this._d = 0x10325476 | ||
97784 | this._e = 0xc3d2e1f0 | ||
97785 | |||
97786 | return this | ||
97787 | } | ||
97788 | |||
97789 | function rotl5 (num) { | ||
97790 | return (num << 5) | (num >>> 27) | ||
97791 | } | ||
97792 | |||
97793 | function rotl30 (num) { | ||
97794 | return (num << 30) | (num >>> 2) | ||
97795 | } | ||
97796 | |||
97797 | function ft (s, b, c, d) { | ||
97798 | if (s === 0) return (b & c) | ((~b) & d) | ||
97799 | if (s === 2) return (b & c) | (b & d) | (c & d) | ||
97800 | return b ^ c ^ d | ||
97801 | } | ||
97802 | |||
97803 | Sha.prototype._update = function (M) { | ||
97804 | var W = this._w | ||
97805 | |||
97806 | var a = this._a | 0 | ||
97807 | var b = this._b | 0 | ||
97808 | var c = this._c | 0 | ||
97809 | var d = this._d | 0 | ||
97810 | var e = this._e | 0 | ||
97811 | |||
97812 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
97813 | for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16] | ||
97814 | |||
97815 | for (var j = 0; j < 80; ++j) { | ||
97816 | var s = ~~(j / 20) | ||
97817 | var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 | ||
97818 | |||
97819 | e = d | ||
97820 | d = c | ||
97821 | c = rotl30(b) | ||
97822 | b = a | ||
97823 | a = t | ||
97824 | } | ||
97825 | |||
97826 | this._a = (a + this._a) | 0 | ||
97827 | this._b = (b + this._b) | 0 | ||
97828 | this._c = (c + this._c) | 0 | ||
97829 | this._d = (d + this._d) | 0 | ||
97830 | this._e = (e + this._e) | 0 | ||
97831 | } | ||
97832 | |||
97833 | Sha.prototype._hash = function () { | ||
97834 | var H = Buffer.allocUnsafe(20) | ||
97835 | |||
97836 | H.writeInt32BE(this._a | 0, 0) | ||
97837 | H.writeInt32BE(this._b | 0, 4) | ||
97838 | H.writeInt32BE(this._c | 0, 8) | ||
97839 | H.writeInt32BE(this._d | 0, 12) | ||
97840 | H.writeInt32BE(this._e | 0, 16) | ||
97841 | |||
97842 | return H | ||
97843 | } | ||
97844 | |||
97845 | module.exports = Sha | ||
97846 | |||
97847 | },{"./hash":41,"inherits":21,"safe-buffer":40}],44:[function(require,module,exports){ | ||
97848 | /* | ||
97849 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined | ||
97850 | * in FIPS PUB 180-1 | ||
97851 | * Version 2.1a Copyright Paul Johnston 2000 - 2002. | ||
97852 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
97853 | * Distributed under the BSD License | ||
97854 | * See http://pajhome.org.uk/crypt/md5 for details. | ||
97855 | */ | ||
97856 | |||
97857 | var inherits = require('inherits') | ||
97858 | var Hash = require('./hash') | ||
97859 | var Buffer = require('safe-buffer').Buffer | ||
97860 | |||
97861 | var K = [ | ||
97862 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | ||
97863 | ] | ||
97864 | |||
97865 | var W = new Array(80) | ||
97866 | |||
97867 | function Sha1 () { | ||
97868 | this.init() | ||
97869 | this._w = W | ||
97870 | |||
97871 | Hash.call(this, 64, 56) | ||
97872 | } | ||
97873 | |||
97874 | inherits(Sha1, Hash) | ||
97875 | |||
97876 | Sha1.prototype.init = function () { | ||
97877 | this._a = 0x67452301 | ||
97878 | this._b = 0xefcdab89 | ||
97879 | this._c = 0x98badcfe | ||
97880 | this._d = 0x10325476 | ||
97881 | this._e = 0xc3d2e1f0 | ||
97882 | |||
97883 | return this | ||
97884 | } | ||
97885 | |||
97886 | function rotl1 (num) { | ||
97887 | return (num << 1) | (num >>> 31) | ||
97888 | } | ||
97889 | |||
97890 | function rotl5 (num) { | ||
97891 | return (num << 5) | (num >>> 27) | ||
97892 | } | ||
97893 | |||
97894 | function rotl30 (num) { | ||
97895 | return (num << 30) | (num >>> 2) | ||
97896 | } | ||
97897 | |||
97898 | function ft (s, b, c, d) { | ||
97899 | if (s === 0) return (b & c) | ((~b) & d) | ||
97900 | if (s === 2) return (b & c) | (b & d) | (c & d) | ||
97901 | return b ^ c ^ d | ||
97902 | } | ||
97903 | |||
97904 | Sha1.prototype._update = function (M) { | ||
97905 | var W = this._w | ||
97906 | |||
97907 | var a = this._a | 0 | ||
97908 | var b = this._b | 0 | ||
97909 | var c = this._c | 0 | ||
97910 | var d = this._d | 0 | ||
97911 | var e = this._e | 0 | ||
97912 | |||
97913 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
97914 | for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]) | ||
97915 | |||
97916 | for (var j = 0; j < 80; ++j) { | ||
97917 | var s = ~~(j / 20) | ||
97918 | var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 | ||
97919 | |||
97920 | e = d | ||
97921 | d = c | ||
97922 | c = rotl30(b) | ||
97923 | b = a | ||
97924 | a = t | ||
97925 | } | ||
97926 | |||
97927 | this._a = (a + this._a) | 0 | ||
97928 | this._b = (b + this._b) | 0 | ||
97929 | this._c = (c + this._c) | 0 | ||
97930 | this._d = (d + this._d) | 0 | ||
97931 | this._e = (e + this._e) | 0 | ||
97932 | } | ||
97933 | |||
97934 | Sha1.prototype._hash = function () { | ||
97935 | var H = Buffer.allocUnsafe(20) | ||
97936 | |||
97937 | H.writeInt32BE(this._a | 0, 0) | ||
97938 | H.writeInt32BE(this._b | 0, 4) | ||
97939 | H.writeInt32BE(this._c | 0, 8) | ||
97940 | H.writeInt32BE(this._d | 0, 12) | ||
97941 | H.writeInt32BE(this._e | 0, 16) | ||
97942 | |||
97943 | return H | ||
97944 | } | ||
97945 | |||
97946 | module.exports = Sha1 | ||
97947 | |||
97948 | },{"./hash":41,"inherits":21,"safe-buffer":40}],45:[function(require,module,exports){ | ||
97949 | /** | ||
97950 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | ||
97951 | * in FIPS 180-2 | ||
97952 | * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. | ||
97953 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
97954 | * | ||
97955 | */ | ||
97956 | |||
97957 | var inherits = require('inherits') | ||
97958 | var Sha256 = require('./sha256') | ||
97959 | var Hash = require('./hash') | ||
97960 | var Buffer = require('safe-buffer').Buffer | ||
97961 | |||
97962 | var W = new Array(64) | ||
97963 | |||
97964 | function Sha224 () { | ||
97965 | this.init() | ||
97966 | |||
97967 | this._w = W // new Array(64) | ||
97968 | |||
97969 | Hash.call(this, 64, 56) | ||
97970 | } | ||
97971 | |||
97972 | inherits(Sha224, Sha256) | ||
97973 | |||
97974 | Sha224.prototype.init = function () { | ||
97975 | this._a = 0xc1059ed8 | ||
97976 | this._b = 0x367cd507 | ||
97977 | this._c = 0x3070dd17 | ||
97978 | this._d = 0xf70e5939 | ||
97979 | this._e = 0xffc00b31 | ||
97980 | this._f = 0x68581511 | ||
97981 | this._g = 0x64f98fa7 | ||
97982 | this._h = 0xbefa4fa4 | ||
97983 | |||
97984 | return this | ||
97985 | } | ||
97986 | |||
97987 | Sha224.prototype._hash = function () { | ||
97988 | var H = Buffer.allocUnsafe(28) | ||
97989 | |||
97990 | H.writeInt32BE(this._a, 0) | ||
97991 | H.writeInt32BE(this._b, 4) | ||
97992 | H.writeInt32BE(this._c, 8) | ||
97993 | H.writeInt32BE(this._d, 12) | ||
97994 | H.writeInt32BE(this._e, 16) | ||
97995 | H.writeInt32BE(this._f, 20) | ||
97996 | H.writeInt32BE(this._g, 24) | ||
97997 | |||
97998 | return H | ||
97999 | } | ||
98000 | |||
98001 | module.exports = Sha224 | ||
98002 | |||
98003 | },{"./hash":41,"./sha256":46,"inherits":21,"safe-buffer":40}],46:[function(require,module,exports){ | ||
98004 | /** | ||
98005 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | ||
98006 | * in FIPS 180-2 | ||
98007 | * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. | ||
98008 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
98009 | * | ||
98010 | */ | ||
98011 | |||
98012 | var inherits = require('inherits') | ||
98013 | var Hash = require('./hash') | ||
98014 | var Buffer = require('safe-buffer').Buffer | ||
98015 | |||
98016 | var K = [ | ||
98017 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, | ||
98018 | 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, | ||
98019 | 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, | ||
98020 | 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, | ||
98021 | 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, | ||
98022 | 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, | ||
98023 | 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, | ||
98024 | 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, | ||
98025 | 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, | ||
98026 | 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, | ||
98027 | 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, | ||
98028 | 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, | ||
98029 | 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, | ||
98030 | 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, | ||
98031 | 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, | ||
98032 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 | ||
98033 | ] | ||
98034 | |||
98035 | var W = new Array(64) | ||
98036 | |||
98037 | function Sha256 () { | ||
98038 | this.init() | ||
98039 | |||
98040 | this._w = W // new Array(64) | ||
98041 | |||
98042 | Hash.call(this, 64, 56) | ||
98043 | } | ||
98044 | |||
98045 | inherits(Sha256, Hash) | ||
98046 | |||
98047 | Sha256.prototype.init = function () { | ||
98048 | this._a = 0x6a09e667 | ||
98049 | this._b = 0xbb67ae85 | ||
98050 | this._c = 0x3c6ef372 | ||
98051 | this._d = 0xa54ff53a | ||
98052 | this._e = 0x510e527f | ||
98053 | this._f = 0x9b05688c | ||
98054 | this._g = 0x1f83d9ab | ||
98055 | this._h = 0x5be0cd19 | ||
98056 | |||
98057 | return this | ||
98058 | } | ||
98059 | |||
98060 | function ch (x, y, z) { | ||
98061 | return z ^ (x & (y ^ z)) | ||
98062 | } | ||
98063 | |||
98064 | function maj (x, y, z) { | ||
98065 | return (x & y) | (z & (x | y)) | ||
98066 | } | ||
98067 | |||
98068 | function sigma0 (x) { | ||
98069 | return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10) | ||
98070 | } | ||
98071 | |||
98072 | function sigma1 (x) { | ||
98073 | return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7) | ||
98074 | } | ||
98075 | |||
98076 | function gamma0 (x) { | ||
98077 | return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3) | ||
98078 | } | ||
98079 | |||
98080 | function gamma1 (x) { | ||
98081 | return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10) | ||
98082 | } | ||
98083 | |||
98084 | Sha256.prototype._update = function (M) { | ||
98085 | var W = this._w | ||
98086 | |||
98087 | var a = this._a | 0 | ||
98088 | var b = this._b | 0 | ||
98089 | var c = this._c | 0 | ||
98090 | var d = this._d | 0 | ||
98091 | var e = this._e | 0 | ||
98092 | var f = this._f | 0 | ||
98093 | var g = this._g | 0 | ||
98094 | var h = this._h | 0 | ||
98095 | |||
98096 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
98097 | for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0 | ||
98098 | |||
98099 | for (var j = 0; j < 64; ++j) { | ||
98100 | var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0 | ||
98101 | var T2 = (sigma0(a) + maj(a, b, c)) | 0 | ||
98102 | |||
98103 | h = g | ||
98104 | g = f | ||
98105 | f = e | ||
98106 | e = (d + T1) | 0 | ||
98107 | d = c | ||
98108 | c = b | ||
98109 | b = a | ||
98110 | a = (T1 + T2) | 0 | ||
98111 | } | ||
98112 | |||
98113 | this._a = (a + this._a) | 0 | ||
98114 | this._b = (b + this._b) | 0 | ||
98115 | this._c = (c + this._c) | 0 | ||
98116 | this._d = (d + this._d) | 0 | ||
98117 | this._e = (e + this._e) | 0 | ||
98118 | this._f = (f + this._f) | 0 | ||
98119 | this._g = (g + this._g) | 0 | ||
98120 | this._h = (h + this._h) | 0 | ||
98121 | } | ||
98122 | |||
98123 | Sha256.prototype._hash = function () { | ||
98124 | var H = Buffer.allocUnsafe(32) | ||
98125 | |||
98126 | H.writeInt32BE(this._a, 0) | ||
98127 | H.writeInt32BE(this._b, 4) | ||
98128 | H.writeInt32BE(this._c, 8) | ||
98129 | H.writeInt32BE(this._d, 12) | ||
98130 | H.writeInt32BE(this._e, 16) | ||
98131 | H.writeInt32BE(this._f, 20) | ||
98132 | H.writeInt32BE(this._g, 24) | ||
98133 | H.writeInt32BE(this._h, 28) | ||
98134 | |||
98135 | return H | ||
98136 | } | ||
98137 | |||
98138 | module.exports = Sha256 | ||
98139 | |||
98140 | },{"./hash":41,"inherits":21,"safe-buffer":40}],47:[function(require,module,exports){ | ||
98141 | var inherits = require('inherits') | ||
98142 | var SHA512 = require('./sha512') | ||
98143 | var Hash = require('./hash') | ||
98144 | var Buffer = require('safe-buffer').Buffer | ||
98145 | |||
98146 | var W = new Array(160) | ||
98147 | |||
98148 | function Sha384 () { | ||
98149 | this.init() | ||
98150 | this._w = W | ||
98151 | |||
98152 | Hash.call(this, 128, 112) | ||
98153 | } | ||
98154 | |||
98155 | inherits(Sha384, SHA512) | ||
98156 | |||
98157 | Sha384.prototype.init = function () { | ||
98158 | this._ah = 0xcbbb9d5d | ||
98159 | this._bh = 0x629a292a | ||
98160 | this._ch = 0x9159015a | ||
98161 | this._dh = 0x152fecd8 | ||
98162 | this._eh = 0x67332667 | ||
98163 | this._fh = 0x8eb44a87 | ||
98164 | this._gh = 0xdb0c2e0d | ||
98165 | this._hh = 0x47b5481d | ||
98166 | |||
98167 | this._al = 0xc1059ed8 | ||
98168 | this._bl = 0x367cd507 | ||
98169 | this._cl = 0x3070dd17 | ||
98170 | this._dl = 0xf70e5939 | ||
98171 | this._el = 0xffc00b31 | ||
98172 | this._fl = 0x68581511 | ||
98173 | this._gl = 0x64f98fa7 | ||
98174 | this._hl = 0xbefa4fa4 | ||
98175 | |||
98176 | return this | ||
98177 | } | ||
98178 | |||
98179 | Sha384.prototype._hash = function () { | ||
98180 | var H = Buffer.allocUnsafe(48) | ||
98181 | |||
98182 | function writeInt64BE (h, l, offset) { | ||
98183 | H.writeInt32BE(h, offset) | ||
98184 | H.writeInt32BE(l, offset + 4) | ||
98185 | } | ||
98186 | |||
98187 | writeInt64BE(this._ah, this._al, 0) | ||
98188 | writeInt64BE(this._bh, this._bl, 8) | ||
98189 | writeInt64BE(this._ch, this._cl, 16) | ||
98190 | writeInt64BE(this._dh, this._dl, 24) | ||
98191 | writeInt64BE(this._eh, this._el, 32) | ||
98192 | writeInt64BE(this._fh, this._fl, 40) | ||
98193 | |||
98194 | return H | ||
98195 | } | ||
98196 | |||
98197 | module.exports = Sha384 | ||
98198 | |||
98199 | },{"./hash":41,"./sha512":48,"inherits":21,"safe-buffer":40}],48:[function(require,module,exports){ | ||
98200 | var inherits = require('inherits') | ||
98201 | var Hash = require('./hash') | ||
98202 | var Buffer = require('safe-buffer').Buffer | ||
98203 | |||
98204 | var K = [ | ||
98205 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, | ||
98206 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, | ||
98207 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, | ||
98208 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, | ||
98209 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, | ||
98210 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, | ||
98211 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, | ||
98212 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, | ||
98213 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, | ||
98214 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, | ||
98215 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, | ||
98216 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, | ||
98217 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, | ||
98218 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, | ||
98219 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, | ||
98220 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, | ||
98221 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, | ||
98222 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, | ||
98223 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, | ||
98224 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, | ||
98225 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, | ||
98226 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, | ||
98227 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, | ||
98228 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, | ||
98229 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, | ||
98230 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, | ||
98231 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, | ||
98232 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, | ||
98233 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, | ||
98234 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, | ||
98235 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, | ||
98236 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, | ||
98237 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, | ||
98238 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, | ||
98239 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, | ||
98240 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, | ||
98241 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, | ||
98242 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, | ||
98243 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, | ||
98244 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 | ||
98245 | ] | ||
98246 | |||
98247 | var W = new Array(160) | ||
98248 | |||
98249 | function Sha512 () { | ||
98250 | this.init() | ||
98251 | this._w = W | ||
98252 | |||
98253 | Hash.call(this, 128, 112) | ||
98254 | } | ||
98255 | |||
98256 | inherits(Sha512, Hash) | ||
98257 | |||
98258 | Sha512.prototype.init = function () { | ||
98259 | this._ah = 0x6a09e667 | ||
98260 | this._bh = 0xbb67ae85 | ||
98261 | this._ch = 0x3c6ef372 | ||
98262 | this._dh = 0xa54ff53a | ||
98263 | this._eh = 0x510e527f | ||
98264 | this._fh = 0x9b05688c | ||
98265 | this._gh = 0x1f83d9ab | ||
98266 | this._hh = 0x5be0cd19 | ||
98267 | |||
98268 | this._al = 0xf3bcc908 | ||
98269 | this._bl = 0x84caa73b | ||
98270 | this._cl = 0xfe94f82b | ||
98271 | this._dl = 0x5f1d36f1 | ||
98272 | this._el = 0xade682d1 | ||
98273 | this._fl = 0x2b3e6c1f | ||
98274 | this._gl = 0xfb41bd6b | ||
98275 | this._hl = 0x137e2179 | ||
98276 | |||
98277 | return this | ||
98278 | } | ||
98279 | |||
98280 | function Ch (x, y, z) { | ||
98281 | return z ^ (x & (y ^ z)) | ||
98282 | } | ||
98283 | |||
98284 | function maj (x, y, z) { | ||
98285 | return (x & y) | (z & (x | y)) | ||
98286 | } | ||
98287 | |||
98288 | function sigma0 (x, xl) { | ||
98289 | return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25) | ||
98290 | } | ||
98291 | |||
98292 | function sigma1 (x, xl) { | ||
98293 | return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23) | ||
98294 | } | ||
98295 | |||
98296 | function Gamma0 (x, xl) { | ||
98297 | return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7) | ||
98298 | } | ||
98299 | |||
98300 | function Gamma0l (x, xl) { | ||
98301 | return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25) | ||
98302 | } | ||
98303 | |||
98304 | function Gamma1 (x, xl) { | ||
98305 | return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6) | ||
98306 | } | ||
98307 | |||
98308 | function Gamma1l (x, xl) { | ||
98309 | return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26) | ||
98310 | } | ||
98311 | |||
98312 | function getCarry (a, b) { | ||
98313 | return (a >>> 0) < (b >>> 0) ? 1 : 0 | ||
98314 | } | ||
98315 | |||
98316 | Sha512.prototype._update = function (M) { | ||
98317 | var W = this._w | ||
98318 | |||
98319 | var ah = this._ah | 0 | ||
98320 | var bh = this._bh | 0 | ||
98321 | var ch = this._ch | 0 | ||
98322 | var dh = this._dh | 0 | ||
98323 | var eh = this._eh | 0 | ||
98324 | var fh = this._fh | 0 | ||
98325 | var gh = this._gh | 0 | ||
98326 | var hh = this._hh | 0 | ||
98327 | |||
98328 | var al = this._al | 0 | ||
98329 | var bl = this._bl | 0 | ||
98330 | var cl = this._cl | 0 | ||
98331 | var dl = this._dl | 0 | ||
98332 | var el = this._el | 0 | ||
98333 | var fl = this._fl | 0 | ||
98334 | var gl = this._gl | 0 | ||
98335 | var hl = this._hl | 0 | ||
98336 | |||
98337 | for (var i = 0; i < 32; i += 2) { | ||
98338 | W[i] = M.readInt32BE(i * 4) | ||
98339 | W[i + 1] = M.readInt32BE(i * 4 + 4) | ||
98340 | } | ||
98341 | for (; i < 160; i += 2) { | ||
98342 | var xh = W[i - 15 * 2] | ||
98343 | var xl = W[i - 15 * 2 + 1] | ||
98344 | var gamma0 = Gamma0(xh, xl) | ||
98345 | var gamma0l = Gamma0l(xl, xh) | ||
98346 | |||
98347 | xh = W[i - 2 * 2] | ||
98348 | xl = W[i - 2 * 2 + 1] | ||
98349 | var gamma1 = Gamma1(xh, xl) | ||
98350 | var gamma1l = Gamma1l(xl, xh) | ||
98351 | |||
98352 | // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] | ||
98353 | var Wi7h = W[i - 7 * 2] | ||
98354 | var Wi7l = W[i - 7 * 2 + 1] | ||
98355 | |||
98356 | var Wi16h = W[i - 16 * 2] | ||
98357 | var Wi16l = W[i - 16 * 2 + 1] | ||
98358 | |||
98359 | var Wil = (gamma0l + Wi7l) | 0 | ||
98360 | var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0 | ||
98361 | Wil = (Wil + gamma1l) | 0 | ||
98362 | Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0 | ||
98363 | Wil = (Wil + Wi16l) | 0 | ||
98364 | Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0 | ||
98365 | |||
98366 | W[i] = Wih | ||
98367 | W[i + 1] = Wil | ||
98368 | } | ||
98369 | |||
98370 | for (var j = 0; j < 160; j += 2) { | ||
98371 | Wih = W[j] | ||
98372 | Wil = W[j + 1] | ||
98373 | |||
98374 | var majh = maj(ah, bh, ch) | ||
98375 | var majl = maj(al, bl, cl) | ||
98376 | |||
98377 | var sigma0h = sigma0(ah, al) | ||
98378 | var sigma0l = sigma0(al, ah) | ||
98379 | var sigma1h = sigma1(eh, el) | ||
98380 | var sigma1l = sigma1(el, eh) | ||
98381 | |||
98382 | // t1 = h + sigma1 + ch + K[j] + W[j] | ||
98383 | var Kih = K[j] | ||
98384 | var Kil = K[j + 1] | ||
98385 | |||
98386 | var chh = Ch(eh, fh, gh) | ||
98387 | var chl = Ch(el, fl, gl) | ||
98388 | |||
98389 | var t1l = (hl + sigma1l) | 0 | ||
98390 | var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0 | ||
98391 | t1l = (t1l + chl) | 0 | ||
98392 | t1h = (t1h + chh + getCarry(t1l, chl)) | 0 | ||
98393 | t1l = (t1l + Kil) | 0 | ||
98394 | t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0 | ||
98395 | t1l = (t1l + Wil) | 0 | ||
98396 | t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0 | ||
98397 | |||
98398 | // t2 = sigma0 + maj | ||
98399 | var t2l = (sigma0l + majl) | 0 | ||
98400 | var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0 | ||
98401 | |||
98402 | hh = gh | ||
98403 | hl = gl | ||
98404 | gh = fh | ||
98405 | gl = fl | ||
98406 | fh = eh | ||
98407 | fl = el | ||
98408 | el = (dl + t1l) | 0 | ||
98409 | eh = (dh + t1h + getCarry(el, dl)) | 0 | ||
98410 | dh = ch | ||
98411 | dl = cl | ||
98412 | ch = bh | ||
98413 | cl = bl | ||
98414 | bh = ah | ||
98415 | bl = al | ||
98416 | al = (t1l + t2l) | 0 | ||
98417 | ah = (t1h + t2h + getCarry(al, t1l)) | 0 | ||
98418 | } | ||
98419 | |||
98420 | this._al = (this._al + al) | 0 | ||
98421 | this._bl = (this._bl + bl) | 0 | ||
98422 | this._cl = (this._cl + cl) | 0 | ||
98423 | this._dl = (this._dl + dl) | 0 | ||
98424 | this._el = (this._el + el) | 0 | ||
98425 | this._fl = (this._fl + fl) | 0 | ||
98426 | this._gl = (this._gl + gl) | 0 | ||
98427 | this._hl = (this._hl + hl) | 0 | ||
98428 | |||
98429 | this._ah = (this._ah + ah + getCarry(this._al, al)) | 0 | ||
98430 | this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0 | ||
98431 | this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0 | ||
98432 | this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0 | ||
98433 | this._eh = (this._eh + eh + getCarry(this._el, el)) | 0 | ||
98434 | this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0 | ||
98435 | this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0 | ||
98436 | this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0 | ||
98437 | } | ||
98438 | |||
98439 | Sha512.prototype._hash = function () { | ||
98440 | var H = Buffer.allocUnsafe(64) | ||
98441 | |||
98442 | function writeInt64BE (h, l, offset) { | ||
98443 | H.writeInt32BE(h, offset) | ||
98444 | H.writeInt32BE(l, offset + 4) | ||
98445 | } | ||
98446 | |||
98447 | writeInt64BE(this._ah, this._al, 0) | ||
98448 | writeInt64BE(this._bh, this._bl, 8) | ||
98449 | writeInt64BE(this._ch, this._cl, 16) | ||
98450 | writeInt64BE(this._dh, this._dl, 24) | ||
98451 | writeInt64BE(this._eh, this._el, 32) | ||
98452 | writeInt64BE(this._fh, this._fl, 40) | ||
98453 | writeInt64BE(this._gh, this._gl, 48) | ||
98454 | writeInt64BE(this._hh, this._hl, 56) | ||
98455 | |||
98456 | return H | ||
98457 | } | ||
98458 | |||
98459 | module.exports = Sha512 | ||
98460 | |||
98461 | },{"./hash":41,"inherits":21,"safe-buffer":40}],49:[function(require,module,exports){ | ||
98462 | // Copyright Joyent, Inc. and other Node contributors. | ||
98463 | // | ||
98464 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
98465 | // copy of this software and associated documentation files (the | ||
98466 | // "Software"), to deal in the Software without restriction, including | ||
98467 | // without limitation the rights to use, copy, modify, merge, publish, | ||
98468 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
98469 | // persons to whom the Software is furnished to do so, subject to the | ||
98470 | // following conditions: | ||
98471 | // | ||
98472 | // The above copyright notice and this permission notice shall be included | ||
98473 | // in all copies or substantial portions of the Software. | ||
98474 | // | ||
98475 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
98476 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
98477 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
98478 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
98479 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
98480 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
98481 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
98482 | |||
98483 | module.exports = Stream; | ||
98484 | |||
98485 | var EE = require('events').EventEmitter; | ||
98486 | var inherits = require('inherits'); | ||
98487 | |||
98488 | inherits(Stream, EE); | ||
98489 | Stream.Readable = require('readable-stream/readable.js'); | ||
98490 | Stream.Writable = require('readable-stream/writable.js'); | ||
98491 | Stream.Duplex = require('readable-stream/duplex.js'); | ||
98492 | Stream.Transform = require('readable-stream/transform.js'); | ||
98493 | Stream.PassThrough = require('readable-stream/passthrough.js'); | ||
98494 | |||
98495 | // Backwards-compat with node 0.4.x | ||
98496 | Stream.Stream = Stream; | ||
98497 | |||
98498 | |||
98499 | |||
98500 | // old-style streams. Note that the pipe method (the only relevant | ||
98501 | // part of this class) is overridden in the Readable class. | ||
98502 | |||
98503 | function Stream() { | ||
98504 | EE.call(this); | ||
98505 | } | ||
98506 | |||
98507 | Stream.prototype.pipe = function(dest, options) { | ||
98508 | var source = this; | ||
98509 | |||
98510 | function ondata(chunk) { | ||
98511 | if (dest.writable) { | ||
98512 | if (false === dest.write(chunk) && source.pause) { | ||
98513 | source.pause(); | ||
98514 | } | ||
98515 | } | ||
98516 | } | ||
98517 | |||
98518 | source.on('data', ondata); | ||
98519 | |||
98520 | function ondrain() { | ||
98521 | if (source.readable && source.resume) { | ||
98522 | source.resume(); | ||
98523 | } | ||
98524 | } | ||
98525 | |||
98526 | dest.on('drain', ondrain); | ||
98527 | |||
98528 | // If the 'end' option is not supplied, dest.end() will be called when | ||
98529 | // source gets the 'end' or 'close' events. Only dest.end() once. | ||
98530 | if (!dest._isStdio && (!options || options.end !== false)) { | ||
98531 | source.on('end', onend); | ||
98532 | source.on('close', onclose); | ||
98533 | } | ||
98534 | |||
98535 | var didOnEnd = false; | ||
98536 | function onend() { | ||
98537 | if (didOnEnd) return; | ||
98538 | didOnEnd = true; | ||
98539 | |||
98540 | dest.end(); | ||
98541 | } | ||
98542 | |||
98543 | |||
98544 | function onclose() { | ||
98545 | if (didOnEnd) return; | ||
98546 | didOnEnd = true; | ||
98547 | |||
98548 | if (typeof dest.destroy === 'function') dest.destroy(); | ||
98549 | } | ||
98550 | |||
98551 | // don't leave dangling pipes when there are errors. | ||
98552 | function onerror(er) { | ||
98553 | cleanup(); | ||
98554 | if (EE.listenerCount(this, 'error') === 0) { | ||
98555 | throw er; // Unhandled stream error in pipe. | ||
98556 | } | ||
98557 | } | ||
98558 | |||
98559 | source.on('error', onerror); | ||
98560 | dest.on('error', onerror); | ||
98561 | |||
98562 | // remove all the event listeners that were added. | ||
98563 | function cleanup() { | ||
98564 | source.removeListener('data', ondata); | ||
98565 | dest.removeListener('drain', ondrain); | ||
98566 | |||
98567 | source.removeListener('end', onend); | ||
98568 | source.removeListener('close', onclose); | ||
98569 | |||
98570 | source.removeListener('error', onerror); | ||
98571 | dest.removeListener('error', onerror); | ||
98572 | |||
98573 | source.removeListener('end', cleanup); | ||
98574 | source.removeListener('close', cleanup); | ||
98575 | |||
98576 | dest.removeListener('close', cleanup); | ||
98577 | } | ||
98578 | |||
98579 | source.on('end', cleanup); | ||
98580 | source.on('close', cleanup); | ||
98581 | |||
98582 | dest.on('close', cleanup); | ||
98583 | |||
98584 | dest.emit('pipe', source); | ||
98585 | |||
98586 | // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
98587 | return dest; | ||
98588 | }; | ||
98589 | |||
98590 | },{"events":18,"inherits":21,"readable-stream/duplex.js":26,"readable-stream/passthrough.js":35,"readable-stream/readable.js":36,"readable-stream/transform.js":37,"readable-stream/writable.js":38}],50:[function(require,module,exports){ | ||
98591 | 'use strict'; | ||
98592 | |||
98593 | var Buffer = require('safe-buffer').Buffer; | ||
98594 | |||
98595 | var isEncoding = Buffer.isEncoding || function (encoding) { | ||
98596 | encoding = '' + encoding; | ||
98597 | switch (encoding && encoding.toLowerCase()) { | ||
98598 | case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw': | ||
98599 | return true; | ||
98600 | default: | ||
98601 | return false; | ||
98602 | } | ||
98603 | }; | ||
98604 | |||
98605 | function _normalizeEncoding(enc) { | ||
98606 | if (!enc) return 'utf8'; | ||
98607 | var retried; | ||
98608 | while (true) { | ||
98609 | switch (enc) { | ||
98610 | case 'utf8': | ||
98611 | case 'utf-8': | ||
98612 | return 'utf8'; | ||
98613 | case 'ucs2': | ||
98614 | case 'ucs-2': | ||
98615 | case 'utf16le': | ||
98616 | case 'utf-16le': | ||
98617 | return 'utf16le'; | ||
98618 | case 'latin1': | ||
98619 | case 'binary': | ||
98620 | return 'latin1'; | ||
98621 | case 'base64': | ||
98622 | case 'ascii': | ||
98623 | case 'hex': | ||
98624 | return enc; | ||
98625 | default: | ||
98626 | if (retried) return; // undefined | ||
98627 | enc = ('' + enc).toLowerCase(); | ||
98628 | retried = true; | ||
98629 | } | ||
98630 | } | ||
98631 | }; | ||
98632 | |||
98633 | // Do not cache `Buffer.isEncoding` when checking encoding names as some | ||
98634 | // modules monkey-patch it to support additional encodings | ||
98635 | function normalizeEncoding(enc) { | ||
98636 | var nenc = _normalizeEncoding(enc); | ||
98637 | if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc); | ||
98638 | return nenc || enc; | ||
98639 | } | ||
98640 | |||
98641 | // StringDecoder provides an interface for efficiently splitting a series of | ||
98642 | // buffers into a series of JS strings without breaking apart multi-byte | ||
98643 | // characters. | ||
98644 | exports.StringDecoder = StringDecoder; | ||
98645 | function StringDecoder(encoding) { | ||
98646 | this.encoding = normalizeEncoding(encoding); | ||
98647 | var nb; | ||
98648 | switch (this.encoding) { | ||
98649 | case 'utf16le': | ||
98650 | this.text = utf16Text; | ||
98651 | this.end = utf16End; | ||
98652 | nb = 4; | ||
98653 | break; | ||
98654 | case 'utf8': | ||
98655 | this.fillLast = utf8FillLast; | ||
98656 | nb = 4; | ||
98657 | break; | ||
98658 | case 'base64': | ||
98659 | this.text = base64Text; | ||
98660 | this.end = base64End; | ||
98661 | nb = 3; | ||
98662 | break; | ||
98663 | default: | ||
98664 | this.write = simpleWrite; | ||
98665 | this.end = simpleEnd; | ||
98666 | return; | ||
98667 | } | ||
98668 | this.lastNeed = 0; | ||
98669 | this.lastTotal = 0; | ||
98670 | this.lastChar = Buffer.allocUnsafe(nb); | ||
98671 | } | ||
98672 | |||
98673 | StringDecoder.prototype.write = function (buf) { | ||
98674 | if (buf.length === 0) return ''; | ||
98675 | var r; | ||
98676 | var i; | ||
98677 | if (this.lastNeed) { | ||
98678 | r = this.fillLast(buf); | ||
98679 | if (r === undefined) return ''; | ||
98680 | i = this.lastNeed; | ||
98681 | this.lastNeed = 0; | ||
98682 | } else { | ||
98683 | i = 0; | ||
98684 | } | ||
98685 | if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i); | ||
98686 | return r || ''; | ||
98687 | }; | ||
98688 | |||
98689 | StringDecoder.prototype.end = utf8End; | ||
98690 | |||
98691 | // Returns only complete characters in a Buffer | ||
98692 | StringDecoder.prototype.text = utf8Text; | ||
98693 | |||
98694 | // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer | ||
98695 | StringDecoder.prototype.fillLast = function (buf) { | ||
98696 | if (this.lastNeed <= buf.length) { | ||
98697 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); | ||
98698 | return this.lastChar.toString(this.encoding, 0, this.lastTotal); | ||
98699 | } | ||
98700 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length); | ||
98701 | this.lastNeed -= buf.length; | ||
98702 | }; | ||
98703 | |||
98704 | // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a | ||
98705 | // continuation byte. | ||
98706 | function utf8CheckByte(byte) { | ||
98707 | if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4; | ||
98708 | return -1; | ||
98709 | } | ||
98710 | |||
98711 | // Checks at most 3 bytes at the end of a Buffer in order to detect an | ||
98712 | // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4) | ||
98713 | // needed to complete the UTF-8 character (if applicable) are returned. | ||
98714 | function utf8CheckIncomplete(self, buf, i) { | ||
98715 | var j = buf.length - 1; | ||
98716 | if (j < i) return 0; | ||
98717 | var nb = utf8CheckByte(buf[j]); | ||
98718 | if (nb >= 0) { | ||
98719 | if (nb > 0) self.lastNeed = nb - 1; | ||
98720 | return nb; | ||
98721 | } | ||
98722 | if (--j < i) return 0; | ||
98723 | nb = utf8CheckByte(buf[j]); | ||
98724 | if (nb >= 0) { | ||
98725 | if (nb > 0) self.lastNeed = nb - 2; | ||
98726 | return nb; | ||
98727 | } | ||
98728 | if (--j < i) return 0; | ||
98729 | nb = utf8CheckByte(buf[j]); | ||
98730 | if (nb >= 0) { | ||
98731 | if (nb > 0) { | ||
98732 | if (nb === 2) nb = 0;else self.lastNeed = nb - 3; | ||
98733 | } | ||
98734 | return nb; | ||
98735 | } | ||
98736 | return 0; | ||
98737 | } | ||
98738 | |||
98739 | // Validates as many continuation bytes for a multi-byte UTF-8 character as | ||
98740 | // needed or are available. If we see a non-continuation byte where we expect | ||
98741 | // one, we "replace" the validated continuation bytes we've seen so far with | ||
98742 | // UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding | ||
98743 | // behavior. The continuation byte check is included three times in the case | ||
98744 | // where all of the continuation bytes for a character exist in the same buffer. | ||
98745 | // It is also done this way as a slight performance increase instead of using a | ||
98746 | // loop. | ||
98747 | function utf8CheckExtraBytes(self, buf, p) { | ||
98748 | if ((buf[0] & 0xC0) !== 0x80) { | ||
98749 | self.lastNeed = 0; | ||
98750 | return '\ufffd'.repeat(p); | ||
98751 | } | ||
98752 | if (self.lastNeed > 1 && buf.length > 1) { | ||
98753 | if ((buf[1] & 0xC0) !== 0x80) { | ||
98754 | self.lastNeed = 1; | ||
98755 | return '\ufffd'.repeat(p + 1); | ||
98756 | } | ||
98757 | if (self.lastNeed > 2 && buf.length > 2) { | ||
98758 | if ((buf[2] & 0xC0) !== 0x80) { | ||
98759 | self.lastNeed = 2; | ||
98760 | return '\ufffd'.repeat(p + 2); | ||
98761 | } | ||
98762 | } | ||
98763 | } | ||
98764 | } | ||
98765 | |||
98766 | // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer. | ||
98767 | function utf8FillLast(buf) { | ||
98768 | var p = this.lastTotal - this.lastNeed; | ||
98769 | var r = utf8CheckExtraBytes(this, buf, p); | ||
98770 | if (r !== undefined) return r; | ||
98771 | if (this.lastNeed <= buf.length) { | ||
98772 | buf.copy(this.lastChar, p, 0, this.lastNeed); | ||
98773 | return this.lastChar.toString(this.encoding, 0, this.lastTotal); | ||
98774 | } | ||
98775 | buf.copy(this.lastChar, p, 0, buf.length); | ||
98776 | this.lastNeed -= buf.length; | ||
98777 | } | ||
98778 | |||
98779 | // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a | ||
98780 | // partial character, the character's bytes are buffered until the required | ||
98781 | // number of bytes are available. | ||
98782 | function utf8Text(buf, i) { | ||
98783 | var total = utf8CheckIncomplete(this, buf, i); | ||
98784 | if (!this.lastNeed) return buf.toString('utf8', i); | ||
98785 | this.lastTotal = total; | ||
98786 | var end = buf.length - (total - this.lastNeed); | ||
98787 | buf.copy(this.lastChar, 0, end); | ||
98788 | return buf.toString('utf8', i, end); | ||
98789 | } | ||
98790 | |||
98791 | // For UTF-8, a replacement character for each buffered byte of a (partial) | ||
98792 | // character needs to be added to the output. | ||
98793 | function utf8End(buf) { | ||
98794 | var r = buf && buf.length ? this.write(buf) : ''; | ||
98795 | if (this.lastNeed) return r + '\ufffd'.repeat(this.lastTotal - this.lastNeed); | ||
98796 | return r; | ||
98797 | } | ||
98798 | |||
98799 | // UTF-16LE typically needs two bytes per character, but even if we have an even | ||
98800 | // number of bytes available, we need to check if we end on a leading/high | ||
98801 | // surrogate. In that case, we need to wait for the next two bytes in order to | ||
98802 | // decode the last character properly. | ||
98803 | function utf16Text(buf, i) { | ||
98804 | if ((buf.length - i) % 2 === 0) { | ||
98805 | var r = buf.toString('utf16le', i); | ||
98806 | if (r) { | ||
98807 | var c = r.charCodeAt(r.length - 1); | ||
98808 | if (c >= 0xD800 && c <= 0xDBFF) { | ||
98809 | this.lastNeed = 2; | ||
98810 | this.lastTotal = 4; | ||
98811 | this.lastChar[0] = buf[buf.length - 2]; | ||
98812 | this.lastChar[1] = buf[buf.length - 1]; | ||
98813 | return r.slice(0, -1); | ||
98814 | } | ||
98815 | } | ||
98816 | return r; | ||
98817 | } | ||
98818 | this.lastNeed = 1; | ||
98819 | this.lastTotal = 2; | ||
98820 | this.lastChar[0] = buf[buf.length - 1]; | ||
98821 | return buf.toString('utf16le', i, buf.length - 1); | ||
98822 | } | ||
98823 | |||
98824 | // For UTF-16LE we do not explicitly append special replacement characters if we | ||
98825 | // end on a partial character, we simply let v8 handle that. | ||
98826 | function utf16End(buf) { | ||
98827 | var r = buf && buf.length ? this.write(buf) : ''; | ||
98828 | if (this.lastNeed) { | ||
98829 | var end = this.lastTotal - this.lastNeed; | ||
98830 | return r + this.lastChar.toString('utf16le', 0, end); | ||
98831 | } | ||
98832 | return r; | ||
98833 | } | ||
98834 | |||
98835 | function base64Text(buf, i) { | ||
98836 | var n = (buf.length - i) % 3; | ||
98837 | if (n === 0) return buf.toString('base64', i); | ||
98838 | this.lastNeed = 3 - n; | ||
98839 | this.lastTotal = 3; | ||
98840 | if (n === 1) { | ||
98841 | this.lastChar[0] = buf[buf.length - 1]; | ||
98842 | } else { | ||
98843 | this.lastChar[0] = buf[buf.length - 2]; | ||
98844 | this.lastChar[1] = buf[buf.length - 1]; | ||
98845 | } | ||
98846 | return buf.toString('base64', i, buf.length - n); | ||
98847 | } | ||
98848 | |||
98849 | function base64End(buf) { | ||
98850 | var r = buf && buf.length ? this.write(buf) : ''; | ||
98851 | if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed); | ||
98852 | return r; | ||
98853 | } | ||
98854 | |||
98855 | // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex) | ||
98856 | function simpleWrite(buf) { | ||
98857 | return buf.toString(this.encoding); | ||
98858 | } | ||
98859 | |||
98860 | function simpleEnd(buf) { | ||
98861 | return buf && buf.length ? this.write(buf) : ''; | ||
98862 | } | ||
98863 | },{"safe-buffer":40}],51:[function(require,module,exports){ | ||
98864 | (function (global){ | ||
98865 | |||
98866 | /** | ||
98867 | * Module exports. | ||
98868 | */ | ||
98869 | |||
98870 | module.exports = deprecate; | ||
98871 | |||
98872 | /** | ||
98873 | * Mark that a method should not be used. | ||
98874 | * Returns a modified function which warns once by default. | ||
98875 | * | ||
98876 | * If `localStorage.noDeprecation = true` is set, then it is a no-op. | ||
98877 | * | ||
98878 | * If `localStorage.throwDeprecation = true` is set, then deprecated functions | ||
98879 | * will throw an Error when invoked. | ||
98880 | * | ||
98881 | * If `localStorage.traceDeprecation = true` is set, then deprecated functions | ||
98882 | * will invoke `console.trace()` instead of `console.error()`. | ||
98883 | * | ||
98884 | * @param {Function} fn - the function to deprecate | ||
98885 | * @param {String} msg - the string to print to the console when `fn` is invoked | ||
98886 | * @returns {Function} a new "deprecated" version of `fn` | ||
98887 | * @api public | ||
98888 | */ | ||
98889 | |||
98890 | function deprecate (fn, msg) { | ||
98891 | if (config('noDeprecation')) { | ||
98892 | return fn; | ||
98893 | } | ||
98894 | |||
98895 | var warned = false; | ||
98896 | function deprecated() { | ||
98897 | if (!warned) { | ||
98898 | if (config('throwDeprecation')) { | ||
98899 | throw new Error(msg); | ||
98900 | } else if (config('traceDeprecation')) { | ||
98901 | console.trace(msg); | ||
98902 | } else { | ||
98903 | console.warn(msg); | ||
98904 | } | ||
98905 | warned = true; | ||
98906 | } | ||
98907 | return fn.apply(this, arguments); | ||
98908 | } | ||
98909 | |||
98910 | return deprecated; | ||
98911 | } | ||
98912 | |||
98913 | /** | ||
98914 | * Checks `localStorage` for boolean values for the given `name`. | ||
98915 | * | ||
98916 | * @param {String} name | ||
98917 | * @returns {Boolean} | ||
98918 | * @api private | ||
98919 | */ | ||
98920 | |||
98921 | function config (name) { | ||
98922 | // accessing global.localStorage can trigger a DOMException in sandboxed iframes | ||
98923 | try { | ||
98924 | if (!global.localStorage) return false; | ||
98925 | } catch (_) { | ||
98926 | return false; | ||
98927 | } | ||
98928 | var val = global.localStorage[name]; | ||
98929 | if (null == val) return false; | ||
98930 | return String(val).toLowerCase() === 'true'; | ||
98931 | } | ||
98932 | |||
98933 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
98934 | },{}],52:[function(require,module,exports){ | ||
98935 | (function (Buffer){ | ||
98936 | /*** | ||
98937 | * @license | ||
98938 | * https://github.com/bitcoincashjs/bchaddr | ||
98939 | * Copyright (c) 2018 Emilio Almansi | ||
98940 | * Distributed under the MIT software license, see the accompanying | ||
98941 | * file LICENSE or http://www.opensource.org/licenses/mit-license.php. | ||
98942 | */ | ||
98943 | |||
98944 | var bs58check = require('bs58check') | ||
98945 | var cashaddr = require('cashaddrjs') | ||
98946 | |||
98947 | /** | ||
98948 | * General purpose Bitcoin Cash address detection and translation.<br /> | ||
98949 | * Supports all major Bitcoin Cash address formats.<br /> | ||
98950 | * Currently: | ||
98951 | * <ul> | ||
98952 | * <li> Legacy format </li> | ||
98953 | * <li> Bitpay format </li> | ||
98954 | * <li> Cashaddr format </li> | ||
98955 | * </ul> | ||
98956 | * @module bchaddr | ||
98957 | */ | ||
98958 | |||
98959 | /** | ||
98960 | * @static | ||
98961 | * Supported Bitcoin Cash address formats. | ||
98962 | */ | ||
98963 | var Format = {} | ||
98964 | Format.Legacy = 'legacy' | ||
98965 | Format.Bitpay = 'bitpay' | ||
98966 | Format.Cashaddr = 'cashaddr' | ||
98967 | |||
98968 | /** | ||
98969 | * @static | ||
98970 | * Supported networks. | ||
98971 | */ | ||
98972 | var Network = {} | ||
98973 | Network.Mainnet = 'mainnet' | ||
98974 | Network.Testnet = 'testnet' | ||
98975 | |||
98976 | /** | ||
98977 | * @static | ||
98978 | * Supported address types. | ||
98979 | */ | ||
98980 | var Type = {} | ||
98981 | Type.P2PKH = 'p2pkh' | ||
98982 | Type.P2SH = 'p2sh' | ||
98983 | |||
98984 | /** | ||
98985 | * Detects what is the given address' format. | ||
98986 | * @static | ||
98987 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
98988 | * @return {string} | ||
98989 | * @throws {InvalidAddressError} | ||
98990 | */ | ||
98991 | function detectAddressFormat (address) { | ||
98992 | return decodeAddress(address).format | ||
98993 | } | ||
98994 | |||
98995 | /** | ||
98996 | * Detects what is the given address' network. | ||
98997 | * @static | ||
98998 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
98999 | * @return {string} | ||
99000 | * @throws {InvalidAddressError} | ||
99001 | */ | ||
99002 | function detectAddressNetwork (address) { | ||
99003 | return decodeAddress(address).network | ||
99004 | } | ||
99005 | |||
99006 | /** | ||
99007 | * Detects what is the given address' type. | ||
99008 | * @static | ||
99009 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99010 | * @return {string} | ||
99011 | * @throws {InvalidAddressError} | ||
99012 | */ | ||
99013 | function detectAddressType (address) { | ||
99014 | return decodeAddress(address).type | ||
99015 | } | ||
99016 | |||
99017 | /** | ||
99018 | * Translates the given address into legacy format. | ||
99019 | * @static | ||
99020 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99021 | * @return {string} | ||
99022 | * @throws {InvalidAddressError} | ||
99023 | */ | ||
99024 | function toLegacyAddress (address) { | ||
99025 | var decoded = decodeAddress(address) | ||
99026 | if (decoded.format === Format.Legacy) { | ||
99027 | return address | ||
99028 | } | ||
99029 | return encodeAsLegacy(decoded) | ||
99030 | } | ||
99031 | |||
99032 | /** | ||
99033 | * Translates the given address into bitpay format. | ||
99034 | * @static | ||
99035 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99036 | * @return {string} | ||
99037 | * @throws {InvalidAddressError} | ||
99038 | */ | ||
99039 | function toBitpayAddress (address) { | ||
99040 | var decoded = decodeAddress(address) | ||
99041 | if (decoded.format === Format.Bitpay) { | ||
99042 | return address | ||
99043 | } | ||
99044 | return encodeAsBitpay(decoded) | ||
99045 | } | ||
99046 | |||
99047 | /** | ||
99048 | * Translates the given address into cashaddr format. | ||
99049 | * @static | ||
99050 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99051 | * @return {string} | ||
99052 | * @throws {InvalidAddressError} | ||
99053 | */ | ||
99054 | function toCashAddress (address) { | ||
99055 | var decoded = decodeAddress(address) | ||
99056 | return encodeAsCashaddr(decoded) | ||
99057 | } | ||
99058 | |||
99059 | /** | ||
99060 | * Version byte table for base58 formats. | ||
99061 | * @private | ||
99062 | */ | ||
99063 | var VERSION_BYTE = {} | ||
99064 | VERSION_BYTE[Format.Legacy] = {} | ||
99065 | VERSION_BYTE[Format.Legacy][Network.Mainnet] = {} | ||
99066 | VERSION_BYTE[Format.Legacy][Network.Mainnet][Type.P2PKH] = 0 | ||
99067 | VERSION_BYTE[Format.Legacy][Network.Mainnet][Type.P2SH] = 5 | ||
99068 | VERSION_BYTE[Format.Legacy][Network.Testnet] = {} | ||
99069 | VERSION_BYTE[Format.Legacy][Network.Testnet][Type.P2PKH] = 111 | ||
99070 | VERSION_BYTE[Format.Legacy][Network.Testnet][Type.P2SH] = 196 | ||
99071 | VERSION_BYTE[Format.Bitpay] = {} | ||
99072 | VERSION_BYTE[Format.Bitpay][Network.Mainnet] = {} | ||
99073 | VERSION_BYTE[Format.Bitpay][Network.Mainnet][Type.P2PKH] = 28 | ||
99074 | VERSION_BYTE[Format.Bitpay][Network.Mainnet][Type.P2SH] = 40 | ||
99075 | VERSION_BYTE[Format.Bitpay][Network.Testnet] = {} | ||
99076 | VERSION_BYTE[Format.Bitpay][Network.Testnet][Type.P2PKH] = 111 | ||
99077 | VERSION_BYTE[Format.Bitpay][Network.Testnet][Type.P2SH] = 196 | ||
99078 | |||
99079 | /** | ||
99080 | * Decodes the given address into its constituting hash, format, network and type. | ||
99081 | * @private | ||
99082 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99083 | * @return {object} | ||
99084 | * @throws {InvalidAddressError} | ||
99085 | */ | ||
99086 | function decodeAddress (address) { | ||
99087 | try { | ||
99088 | return decodeBase58Address(address) | ||
99089 | } catch (error) { | ||
99090 | } | ||
99091 | try { | ||
99092 | return decodeCashAddress(address) | ||
99093 | } catch (error) { | ||
99094 | } | ||
99095 | throw new InvalidAddressError() | ||
99096 | } | ||
99097 | |||
99098 | /** | ||
99099 | * Attempts to decode the given address assuming it is a base58 address. | ||
99100 | * @private | ||
99101 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99102 | * @return {object} | ||
99103 | * @throws {InvalidAddressError} | ||
99104 | */ | ||
99105 | function decodeBase58Address (address) { | ||
99106 | try { | ||
99107 | var payload = bs58check.decode(address) | ||
99108 | var versionByte = payload[0] | ||
99109 | var hash = Array.prototype.slice.call(payload, 1) | ||
99110 | switch (versionByte) { | ||
99111 | case VERSION_BYTE[Format.Legacy][Network.Mainnet][Type.P2PKH]: | ||
99112 | return { | ||
99113 | hash: hash, | ||
99114 | format: Format.Legacy, | ||
99115 | network: Network.Mainnet, | ||
99116 | type: Type.P2PKH | ||
99117 | } | ||
99118 | case VERSION_BYTE[Format.Legacy][Network.Mainnet][Type.P2SH]: | ||
99119 | return { | ||
99120 | hash: hash, | ||
99121 | format: Format.Legacy, | ||
99122 | network: Network.Mainnet, | ||
99123 | type: Type.P2SH | ||
99124 | } | ||
99125 | case VERSION_BYTE[Format.Legacy][Network.Testnet][Type.P2PKH]: | ||
99126 | return { | ||
99127 | hash: hash, | ||
99128 | format: Format.Legacy, | ||
99129 | network: Network.Testnet, | ||
99130 | type: Type.P2PKH | ||
99131 | } | ||
99132 | case VERSION_BYTE[Format.Legacy][Network.Testnet][Type.P2SH]: | ||
99133 | return { | ||
99134 | hash: hash, | ||
99135 | format: Format.Legacy, | ||
99136 | network: Network.Testnet, | ||
99137 | type: Type.P2SH | ||
99138 | } | ||
99139 | case VERSION_BYTE[Format.Bitpay][Network.Mainnet][Type.P2PKH]: | ||
99140 | return { | ||
99141 | hash: hash, | ||
99142 | format: Format.Bitpay, | ||
99143 | network: Network.Mainnet, | ||
99144 | type: Type.P2PKH | ||
99145 | } | ||
99146 | case VERSION_BYTE[Format.Bitpay][Network.Mainnet][Type.P2SH]: | ||
99147 | return { | ||
99148 | hash: hash, | ||
99149 | format: Format.Bitpay, | ||
99150 | network: Network.Mainnet, | ||
99151 | type: Type.P2SH | ||
99152 | } | ||
99153 | } | ||
99154 | } catch (error) { | ||
99155 | } | ||
99156 | throw new InvalidAddressError() | ||
99157 | } | ||
99158 | |||
99159 | /** | ||
99160 | * Attempts to decode the given address assuming it is a cashaddr address. | ||
99161 | * @private | ||
99162 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99163 | * @return {object} | ||
99164 | * @throws {InvalidAddressError} | ||
99165 | */ | ||
99166 | function decodeCashAddress (address) { | ||
99167 | if (address.indexOf(':') !== -1) { | ||
99168 | try { | ||
99169 | return decodeCashAddressWithPrefix(address) | ||
99170 | } catch (error) { | ||
99171 | } | ||
99172 | } else { | ||
99173 | var prefixes = ['bitcoincash', 'bchtest', 'regtest'] | ||
99174 | for (var i = 0; i < prefixes.length; ++i) { | ||
99175 | try { | ||
99176 | var prefix = prefixes[i] | ||
99177 | return decodeCashAddressWithPrefix(prefix + ':' + address) | ||
99178 | } catch (error) { | ||
99179 | } | ||
99180 | } | ||
99181 | } | ||
99182 | throw new InvalidAddressError() | ||
99183 | } | ||
99184 | |||
99185 | /** | ||
99186 | * Attempts to decode the given address assuming it is a cashaddr address with explicit prefix. | ||
99187 | * @private | ||
99188 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99189 | * @return {object} | ||
99190 | * @throws {InvalidAddressError} | ||
99191 | */ | ||
99192 | function decodeCashAddressWithPrefix (address) { | ||
99193 | try { | ||
99194 | var decoded = cashaddr.decode(address) | ||
99195 | var hash = Array.prototype.slice.call(decoded.hash, 0) | ||
99196 | var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH | ||
99197 | switch (decoded.prefix) { | ||
99198 | case 'bitcoincash': | ||
99199 | return { | ||
99200 | hash: hash, | ||
99201 | format: Format.Cashaddr, | ||
99202 | network: Network.Mainnet, | ||
99203 | type: type | ||
99204 | } | ||
99205 | case 'bchtest': | ||
99206 | case 'regtest': | ||
99207 | return { | ||
99208 | hash: hash, | ||
99209 | format: Format.Cashaddr, | ||
99210 | network: Network.Testnet, | ||
99211 | type: type | ||
99212 | } | ||
99213 | } | ||
99214 | } catch (error) { | ||
99215 | } | ||
99216 | throw new InvalidAddressError() | ||
99217 | } | ||
99218 | |||
99219 | /** | ||
99220 | * Encodes the given decoded address into legacy format. | ||
99221 | * @private | ||
99222 | * @param {object} decoded | ||
99223 | * @returns {string} | ||
99224 | */ | ||
99225 | function encodeAsLegacy (decoded) { | ||
99226 | var versionByte = VERSION_BYTE[Format.Legacy][decoded.network][decoded.type] | ||
99227 | var buffer = Buffer.alloc(1 + decoded.hash.length) | ||
99228 | buffer[0] = versionByte | ||
99229 | buffer.set(decoded.hash, 1) | ||
99230 | return bs58check.encode(buffer) | ||
99231 | } | ||
99232 | |||
99233 | /** | ||
99234 | * Encodes the given decoded address into bitpay format. | ||
99235 | * @private | ||
99236 | * @param {object} decoded | ||
99237 | * @returns {string} | ||
99238 | */ | ||
99239 | function encodeAsBitpay (decoded) { | ||
99240 | var versionByte = VERSION_BYTE[Format.Bitpay][decoded.network][decoded.type] | ||
99241 | var buffer = Buffer.alloc(1 + decoded.hash.length) | ||
99242 | buffer[0] = versionByte | ||
99243 | buffer.set(decoded.hash, 1) | ||
99244 | return bs58check.encode(buffer) | ||
99245 | } | ||
99246 | |||
99247 | /** | ||
99248 | * Encodes the given decoded address into cashaddr format. | ||
99249 | * @private | ||
99250 | * @param {object} decoded | ||
99251 | * @returns {string} | ||
99252 | */ | ||
99253 | function encodeAsCashaddr (decoded) { | ||
99254 | var prefix = decoded.network === Network.Mainnet ? 'bitcoincash' : 'bchtest' | ||
99255 | var type = decoded.type === Type.P2PKH ? 'P2PKH' : 'P2SH' | ||
99256 | var hash = Uint8Array.from(decoded.hash) | ||
99257 | return cashaddr.encode(prefix, type, hash) | ||
99258 | } | ||
99259 | |||
99260 | /** | ||
99261 | * Returns a boolean indicating whether the address is in legacy format. | ||
99262 | * @static | ||
99263 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99264 | * @returns {boolean} | ||
99265 | * @throws {InvalidAddressError} | ||
99266 | */ | ||
99267 | function isLegacyAddress (address) { | ||
99268 | return detectAddressFormat(address) === Format.Legacy | ||
99269 | } | ||
99270 | |||
99271 | /** | ||
99272 | * Returns a boolean indicating whether the address is in bitpay format. | ||
99273 | * @static | ||
99274 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99275 | * @returns {boolean} | ||
99276 | * @throws {InvalidAddressError} | ||
99277 | */ | ||
99278 | function isBitpayAddress (address) { | ||
99279 | return detectAddressFormat(address) === Format.Bitpay | ||
99280 | } | ||
99281 | |||
99282 | /** | ||
99283 | * Returns a boolean indicating whether the address is in cashaddr format. | ||
99284 | * @static | ||
99285 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99286 | * @returns {boolean} | ||
99287 | * @throws {InvalidAddressError} | ||
99288 | */ | ||
99289 | function isCashAddress (address) { | ||
99290 | return detectAddressFormat(address) === Format.Cashaddr | ||
99291 | } | ||
99292 | |||
99293 | /** | ||
99294 | * Returns a boolean indicating whether the address is a mainnet address. | ||
99295 | * @static | ||
99296 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99297 | * @returns {boolean} | ||
99298 | * @throws {InvalidAddressError} | ||
99299 | */ | ||
99300 | function isMainnetAddress (address) { | ||
99301 | return detectAddressNetwork(address) === Network.Mainnet | ||
99302 | } | ||
99303 | |||
99304 | /** | ||
99305 | * Returns a boolean indicating whether the address is a testnet address. | ||
99306 | * @static | ||
99307 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99308 | * @returns {boolean} | ||
99309 | * @throws {InvalidAddressError} | ||
99310 | */ | ||
99311 | function isTestnetAddress (address) { | ||
99312 | return detectAddressNetwork(address) === Network.Testnet | ||
99313 | } | ||
99314 | |||
99315 | /** | ||
99316 | * Returns a boolean indicating whether the address is a p2pkh address. | ||
99317 | * @static | ||
99318 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99319 | * @returns {boolean} | ||
99320 | * @throws {InvalidAddressError} | ||
99321 | */ | ||
99322 | function isP2PKHAddress (address) { | ||
99323 | return detectAddressType(address) === Type.P2PKH | ||
99324 | } | ||
99325 | |||
99326 | /** | ||
99327 | * Returns a boolean indicating whether the address is a p2sh address. | ||
99328 | * @static | ||
99329 | * @param {string} address - A valid Bitcoin Cash address in any format. | ||
99330 | * @returns {boolean} | ||
99331 | * @throws {InvalidAddressError} | ||
99332 | */ | ||
99333 | function isP2SHAddress (address) { | ||
99334 | return detectAddressType(address) === Type.P2SH | ||
99335 | } | ||
99336 | |||
99337 | /** | ||
99338 | * Error thrown when the address given as input is not a valid Bitcoin Cash address. | ||
99339 | * @constructor | ||
99340 | * InvalidAddressError | ||
99341 | */ | ||
99342 | function InvalidAddressError () { | ||
99343 | var error = new Error() | ||
99344 | this.name = error.name = 'InvalidAddressError' | ||
99345 | this.message = error.message = 'Received an invalid Bitcoin Cash address as input.' | ||
99346 | this.stack = error.stack | ||
99347 | } | ||
99348 | |||
99349 | InvalidAddressError.prototype = Object.create(Error.prototype) | ||
99350 | |||
99351 | module.exports = { | ||
99352 | Format: Format, | ||
99353 | Network: Network, | ||
99354 | Type: Type, | ||
99355 | detectAddressFormat: detectAddressFormat, | ||
99356 | detectAddressNetwork: detectAddressNetwork, | ||
99357 | detectAddressType: detectAddressType, | ||
99358 | toLegacyAddress: toLegacyAddress, | ||
99359 | toBitpayAddress: toBitpayAddress, | ||
99360 | toCashAddress: toCashAddress, | ||
99361 | isLegacyAddress: isLegacyAddress, | ||
99362 | isBitpayAddress: isBitpayAddress, | ||
99363 | isCashAddress: isCashAddress, | ||
99364 | isMainnetAddress: isMainnetAddress, | ||
99365 | isTestnetAddress: isTestnetAddress, | ||
99366 | isP2PKHAddress: isP2PKHAddress, | ||
99367 | isP2SHAddress: isP2SHAddress, | ||
99368 | InvalidAddressError: InvalidAddressError | ||
99369 | } | ||
99370 | |||
99371 | }).call(this,require("buffer").Buffer) | ||
99372 | },{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52) | ||
99373 | });</script> | ||
89987 | <script>// Select components from sjcl to suit the crypto operations bip39 requires. | 99374 | <script>// Select components from sjcl to suit the crypto operations bip39 requires. |
89988 | 99375 | ||
89989 | //// base.js | 99376 | //// base.js |
@@ -94703,7 +104090,7 @@ var Mnemonic = function(language) { | |||
94703 | // Set space correctly depending on the language | 104090 | // Set space correctly depending on the language |
94704 | // see https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese | 104091 | // see https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese |
94705 | var space = " "; | 104092 | var space = " "; |
94706 | if (language == "japanese" || language == "korean") { | 104093 | if (language == "japanese") { |
94707 | space = "\u3000"; // ideographic space | 104094 | space = "\u3000"; // ideographic space |
94708 | } | 104095 | } |
94709 | return words.join(space); | 104096 | return words.join(space); |
@@ -96859,8 +106246,8 @@ window.Entropy = new (function() { | |||
96859 | DOM.generatedStrength = $(".generate-container .strength"); | 106246 | DOM.generatedStrength = $(".generate-container .strength"); |
96860 | DOM.generatedStrengthWarning = $(".generate-container .warning"); | 106247 | DOM.generatedStrengthWarning = $(".generate-container .warning"); |
96861 | DOM.hardenedAddresses = $(".hardened-addresses"); | 106248 | DOM.hardenedAddresses = $(".hardened-addresses"); |
96862 | DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container"); | 106249 | DOM.bitcoinCashAddressTypeContainer = $(".bch-addr-type-container"); |
96863 | DOM.useBitpayAddresses = $(".use-bitpay-addresses"); | 106250 | DOM.bitcoinCashAddressType = $("[name=bch-addr-type]") |
96864 | DOM.useBip38 = $(".use-bip38"); | 106251 | DOM.useBip38 = $(".use-bip38"); |
96865 | DOM.bip38Password = $(".bip38-password"); | 106252 | DOM.bip38Password = $(".bip38-password"); |
96866 | DOM.addresses = $(".addresses"); | 106253 | DOM.addresses = $(".addresses"); |
@@ -96915,7 +106302,7 @@ window.Entropy = new (function() { | |||
96915 | DOM.privateKeyToggle.on("click", togglePrivateKeys); | 106302 | DOM.privateKeyToggle.on("click", togglePrivateKeys); |
96916 | DOM.csvTab.on("click", updateCsv); | 106303 | DOM.csvTab.on("click", updateCsv); |
96917 | DOM.languages.on("click", languageChanged); | 106304 | DOM.languages.on("click", languageChanged); |
96918 | DOM.useBitpayAddresses.on("change", useBitpayAddressesChange); | 106305 | DOM.bitcoinCashAddressType.on("change", bitcoinCashAddressTypeChange); |
96919 | setQrEvents(DOM.showQrEls); | 106306 | setQrEvents(DOM.showQrEls); |
96920 | disableForms(); | 106307 | disableForms(); |
96921 | hidePending(); | 106308 | hidePending(); |
@@ -96940,7 +106327,7 @@ window.Entropy = new (function() { | |||
96940 | clearDerivedKeys(); | 106327 | clearDerivedKeys(); |
96941 | clearAddressesList(); | 106328 | clearAddressesList(); |
96942 | DOM.litecoinLtubContainer.addClass("hidden"); | 106329 | DOM.litecoinLtubContainer.addClass("hidden"); |
96943 | DOM.useBitpayAddressesContainer.addClass("hidden"); | 106330 | DOM.bitcoinCashAddressTypeContainer.addClass("hidden"); |
96944 | var networkIndex = e.target.value; | 106331 | var networkIndex = e.target.value; |
96945 | var network = networks[networkIndex]; | 106332 | var network = networks[networkIndex]; |
96946 | network.onSelect(); | 106333 | network.onSelect(); |
@@ -97192,8 +106579,7 @@ window.Entropy = new (function() { | |||
97192 | }, 50); | 106579 | }, 50); |
97193 | } | 106580 | } |
97194 | 106581 | ||
97195 | function useBitpayAddressesChange() { | 106582 | function bitcoinCashAddressTypeChange() { |
97196 | setBitcoinCashNetworkValues(); | ||
97197 | phraseChanged(); | 106583 | phraseChanged(); |
97198 | } | 106584 | } |
97199 | 106585 | ||
@@ -97620,6 +107006,16 @@ window.Entropy = new (function() { | |||
97620 | privkey = convertRipplePriv(privkey); | 107006 | privkey = convertRipplePriv(privkey); |
97621 | address = convertRippleAdrr(address); | 107007 | address = convertRippleAdrr(address); |
97622 | } | 107008 | } |
107009 | // Bitcoin Cash address format may vary | ||
107010 | if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") { | ||
107011 | var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val(); | ||
107012 | if (bchAddrType == "cashaddr") { | ||
107013 | address = bchaddr.toCashAddress(address); | ||
107014 | } | ||
107015 | else if (bchAddrType == "bitpay") { | ||
107016 | address = bchaddr.toBitpayAddress(address); | ||
107017 | } | ||
107018 | } | ||
97623 | // Segwit addresses are different | 107019 | // Segwit addresses are different |
97624 | if (isSegwit) { | 107020 | if (isSegwit) { |
97625 | if (!segwitAvailable) { | 107021 | if (!segwitAvailable) { |
@@ -97923,7 +107319,7 @@ window.Entropy = new (function() { | |||
97923 | function wordArrayToPhrase(words) { | 107319 | function wordArrayToPhrase(words) { |
97924 | var phrase = words.join(" "); | 107320 | var phrase = words.join(" "); |
97925 | var language = getLanguageFromPhrase(phrase); | 107321 | var language = getLanguageFromPhrase(phrase); |
97926 | if (language == "japanese" || language == "korean") { | 107322 | if (language == "japanese") { |
97927 | phrase = words.join("\u3000"); | 107323 | phrase = words.join("\u3000"); |
97928 | } | 107324 | } |
97929 | return phrase; | 107325 | return phrase; |
@@ -98185,19 +107581,6 @@ window.Entropy = new (function() { | |||
98185 | DOM.bip141unavailable.removeClass("hidden"); | 107581 | DOM.bip141unavailable.removeClass("hidden"); |
98186 | } | 107582 | } |
98187 | 107583 | ||
98188 | function useBitpayAddresses() { | ||
98189 | return !(DOM.useBitpayAddresses.prop("checked")); | ||
98190 | } | ||
98191 | |||
98192 | function setBitcoinCashNetworkValues() { | ||
98193 | if (useBitpayAddresses()) { | ||
98194 | network = bitcoinjs.bitcoin.networks.bitcoin; | ||
98195 | } | ||
98196 | else { | ||
98197 | network = bitcoinjs.bitcoin.networks.bitcoinCashBitbpay; | ||
98198 | } | ||
98199 | } | ||
98200 | |||
98201 | function adjustNetworkForSegwit() { | 107584 | function adjustNetworkForSegwit() { |
98202 | // If segwit is selected the xpub/xprv prefixes need to be adjusted | 107585 | // If segwit is selected the xpub/xprv prefixes need to be adjusted |
98203 | // to avoid accidentally importing BIP49 xpub to BIP44 watch only | 107586 | // to avoid accidentally importing BIP49 xpub to BIP44 watch only |
@@ -98350,8 +107733,7 @@ window.Entropy = new (function() { | |||
98350 | name: "BCH - Bitcoin Cash", | 107733 | name: "BCH - Bitcoin Cash", |
98351 | segwitAvailable: false, | 107734 | segwitAvailable: false, |
98352 | onSelect: function() { | 107735 | onSelect: function() { |
98353 | DOM.useBitpayAddressesContainer.removeClass("hidden"); | 107736 | DOM.bitcoinCashAddressTypeContainer.removeClass("hidden"); |
98354 | setBitcoinCashNetworkValues(); | ||
98355 | setHdCoin(145); | 107737 | setHdCoin(145); |
98356 | }, | 107738 | }, |
98357 | }, | 107739 | }, |
@@ -98724,6 +108106,14 @@ window.Entropy = new (function() { | |||
98724 | }, | 108106 | }, |
98725 | }, | 108107 | }, |
98726 | { | 108108 | { |
108109 | name: "KOBO - Kobocoin", | ||
108110 | bip49available: false, | ||
108111 | onSelect: function() { | ||
108112 | network = bitcoinjs.bitcoin.networks.kobocoin; | ||
108113 | setHdCoin(196); | ||
108114 | }, | ||
108115 | }, | ||
108116 | { | ||
98727 | name: "LBC - Library Credits", | 108117 | name: "LBC - Library Credits", |
98728 | segwitAvailable: false, | 108118 | segwitAvailable: false, |
98729 | onSelect: function() { | 108119 | onSelect: function() { |
@@ -99118,7 +108508,7 @@ window.Entropy = new (function() { | |||
99118 | }, | 108508 | }, |
99119 | { | 108509 | { |
99120 | name: "VTC - Vertcoin", | 108510 | name: "VTC - Vertcoin", |
99121 | segwitAvailable: false, | 108511 | segwitAvailable: true, |
99122 | onSelect: function() { | 108512 | onSelect: function() { |
99123 | network = bitcoinjs.bitcoin.networks.vertcoin; | 108513 | network = bitcoinjs.bitcoin.networks.vertcoin; |
99124 | setHdCoin(28); | 108514 | setHdCoin(28); |
@@ -99188,6 +108578,14 @@ window.Entropy = new (function() { | |||
99188 | setHdCoin(136); | 108578 | setHdCoin(136); |
99189 | }, | 108579 | }, |
99190 | }, | 108580 | }, |
108581 | { | ||
108582 | name: "ZEC - Zcash", | ||
108583 | segwitAvailable: false, | ||
108584 | onSelect: function() { | ||
108585 | network = bitcoinjs.bitcoin.networks.zcash; | ||
108586 | setHdCoin(133); | ||
108587 | }, | ||
108588 | }, | ||
99191 | ] | 108589 | ] |
99192 | 108590 | ||
99193 | var clients = [ | 108591 | var clients = [ |