Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

22680 wiersze
676 KiB

  1. (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){
  2. 'use strict';
  3. var _lesspass = require('lesspass');
  4. var _lesspass2 = _interopRequireDefault(_lesspass);
  5. var _urlParser = require('./url-parser');
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function getStore(key, callback) {
  8. chrome.storage.local.get(key, function (result) {
  9. callback(result[key]);
  10. });
  11. }
  12. function saveStore(key, value, callback) {
  13. var newStore = {};
  14. newStore[key] = value;
  15. chrome.storage.local.set(newStore, function () {
  16. callback(value);
  17. });
  18. }
  19. function initStore(callback) {
  20. getStore('lesspassStore', function (store) {
  21. var defaultStore = Object.assign({
  22. login: '',
  23. counter: 1,
  24. password: { length: 12, settings: ['lowercase', 'uppercase', 'numbers', 'symbols'] }
  25. }, store);
  26. saveStore('lesspassStore', defaultStore, function (store) {
  27. callback(store);
  28. });
  29. });
  30. }
  31. function getCurrentTab() {
  32. return new Promise(function (resolve) {
  33. chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
  34. resolve(tabs[0]);
  35. });
  36. });
  37. }
  38. function fillForm(data) {
  39. document.getElementById('loginField').value = data.login;
  40. document.getElementById('masterPasswordField').value = '';
  41. document.getElementById('siteField').value = data.site;
  42. document.getElementById('passwordCounter').value = data.counter;
  43. var passwordInfo = data.password;
  44. document.getElementById('passwordLength').value = passwordInfo.length;
  45. document.getElementById('lowercase').checked = false;
  46. document.getElementById('uppercase').checked = false;
  47. document.getElementById('numbers').checked = false;
  48. document.getElementById('symbols').checked = false;
  49. for (var i = 0; i < passwordInfo.settings.length; i++) {
  50. document.querySelector('#' + passwordInfo.settings[i]).checked = true;
  51. }
  52. }
  53. function selectGoodField() {
  54. var loginField = document.getElementById('loginField');
  55. var passwordField = document.getElementById('masterPasswordField');
  56. if (loginField.value === '') {
  57. loginField.focus();
  58. } else {
  59. passwordField.focus();
  60. }
  61. }
  62. function displayMessage(message, field) {
  63. var messageField = document.getElementById(field);
  64. messageField.textContent = message;
  65. }
  66. function getData() {
  67. var defaultOptions = {
  68. login: document.getElementById('loginField').value,
  69. counter: document.getElementById('passwordCounter').value,
  70. password: {
  71. length: document.getElementById('passwordLength').value,
  72. settings: []
  73. }
  74. };
  75. var options = ['lowercase', 'uppercase', 'numbers', 'symbols'];
  76. for (var i = 0; i < options.length; i++) {
  77. if (document.getElementById(options[i]).checked) {
  78. defaultOptions.password.settings.push(options[i]);
  79. }
  80. }
  81. return defaultOptions;
  82. }
  83. function getFormData() {
  84. var initData = getData();
  85. initData.masterPassword = document.getElementById('masterPasswordField').value;
  86. initData.site = document.getElementById('siteField').value;
  87. return initData;
  88. }
  89. document.getElementById('saveDefaultOptionButton').addEventListener('click', function () {
  90. var options = getData();
  91. getStore('lesspassStore', function (store) {
  92. var newStore = Object.assign(store, options);
  93. saveStore('lesspassStore', newStore, function () {
  94. displayMessage('(saved)', 'messageField');
  95. });
  96. });
  97. });
  98. document.getElementById('loginField').addEventListener('blur', generatePassword);
  99. document.getElementById('masterPasswordField').addEventListener('blur', generatePassword);
  100. document.getElementById('siteField').addEventListener('blur', generatePassword);
  101. function generatePassword() {
  102. var data = getFormData();
  103. if (!data.login || !data.masterPassword || !data.site) {
  104. return;
  105. }
  106. return _lesspass2.default.generatePassword(data.login, data.masterPassword, data.site, data).then(function (password) {
  107. document.getElementById('generatedPasswordField').value = password;
  108. return password;
  109. });
  110. }
  111. function copyPassword() {
  112. var generatedPasswordField = document.getElementById('generatedPasswordField');
  113. generatedPasswordField.disabled = false;
  114. generatedPasswordField.select();
  115. document.execCommand('copy');
  116. generatedPasswordField.disabled = true;
  117. }
  118. document.getElementById('loginButton').addEventListener('click', function (event) {
  119. event.preventDefault();
  120. var data = getFormData();
  121. if (!data.login || !data.masterPassword || !data.site) {
  122. displayMessage('login, master password and site are required to generate a password', 'errorMessageField');
  123. return;
  124. }
  125. var tabPromise = getCurrentTab();
  126. var passwordPromise = _lesspass2.default.generatePassword(data.login, data.masterPassword, data.site, data);
  127. Promise.all([passwordPromise, tabPromise]).then(function (values) {
  128. if (chrome.tabs && chrome.tabs.sendMessage) {
  129. chrome.tabs.sendMessage(values[1].id, { login: data.login, password: values[0] });
  130. window.close();
  131. } else {
  132. copyPassword();
  133. }
  134. });
  135. });
  136. chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
  137. if (tabs[0]) {
  138. initStore(function (store) {
  139. store.site = (0, _urlParser.getDomainName)(tabs[0].url);
  140. fillForm(store);
  141. selectGoodField();
  142. });
  143. }
  144. });
  145. },{"./url-parser":2,"lesspass":96}],2:[function(require,module,exports){
  146. 'use strict';
  147. Object.defineProperty(exports, "__esModule", {
  148. value: true
  149. });
  150. exports._ipIsValid = exports.getDomainName = undefined;
  151. var _tldjs = require('tldjs');
  152. var _tldjs2 = _interopRequireDefault(_tldjs);
  153. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  154. function _ipIsValid(ipAddress) {
  155. return Boolean(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress));
  156. }
  157. function getDomainName(urlStr) {
  158. var domain = _tldjs2.default.getDomain(urlStr);
  159. var subDomain = _tldjs2.default.getSubdomain(urlStr);
  160. var ip = subDomain + '.' + domain;
  161. if (_ipIsValid(ip)) {
  162. return ip;
  163. }
  164. return domain;
  165. }
  166. exports.getDomainName = getDomainName;
  167. exports._ipIsValid = _ipIsValid;
  168. },{"tldjs":139}],3:[function(require,module,exports){
  169. var asn1 = exports;
  170. asn1.bignum = require('bn.js');
  171. asn1.define = require('./asn1/api').define;
  172. asn1.base = require('./asn1/base');
  173. asn1.constants = require('./asn1/constants');
  174. asn1.decoders = require('./asn1/decoders');
  175. asn1.encoders = require('./asn1/encoders');
  176. },{"./asn1/api":4,"./asn1/base":6,"./asn1/constants":10,"./asn1/decoders":12,"./asn1/encoders":15,"bn.js":18}],4:[function(require,module,exports){
  177. var asn1 = require('../asn1');
  178. var inherits = require('inherits');
  179. var api = exports;
  180. api.define = function define(name, body) {
  181. return new Entity(name, body);
  182. };
  183. function Entity(name, body) {
  184. this.name = name;
  185. this.body = body;
  186. this.decoders = {};
  187. this.encoders = {};
  188. };
  189. Entity.prototype._createNamed = function createNamed(base) {
  190. var named;
  191. try {
  192. named = require('vm').runInThisContext(
  193. '(function ' + this.name + '(entity) {\n' +
  194. ' this._initNamed(entity);\n' +
  195. '})'
  196. );
  197. } catch (e) {
  198. named = function (entity) {
  199. this._initNamed(entity);
  200. };
  201. }
  202. inherits(named, base);
  203. named.prototype._initNamed = function initnamed(entity) {
  204. base.call(this, entity);
  205. };
  206. return new named(this);
  207. };
  208. Entity.prototype._getDecoder = function _getDecoder(enc) {
  209. enc = enc || 'der';
  210. // Lazily create decoder
  211. if (!this.decoders.hasOwnProperty(enc))
  212. this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
  213. return this.decoders[enc];
  214. };
  215. Entity.prototype.decode = function decode(data, enc, options) {
  216. return this._getDecoder(enc).decode(data, options);
  217. };
  218. Entity.prototype._getEncoder = function _getEncoder(enc) {
  219. enc = enc || 'der';
  220. // Lazily create encoder
  221. if (!this.encoders.hasOwnProperty(enc))
  222. this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
  223. return this.encoders[enc];
  224. };
  225. Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
  226. return this._getEncoder(enc).encode(data, reporter);
  227. };
  228. },{"../asn1":3,"inherits":92,"vm":146}],5:[function(require,module,exports){
  229. var inherits = require('inherits');
  230. var Reporter = require('../base').Reporter;
  231. var Buffer = require('buffer').Buffer;
  232. function DecoderBuffer(base, options) {
  233. Reporter.call(this, options);
  234. if (!Buffer.isBuffer(base)) {
  235. this.error('Input not Buffer');
  236. return;
  237. }
  238. this.base = base;
  239. this.offset = 0;
  240. this.length = base.length;
  241. }
  242. inherits(DecoderBuffer, Reporter);
  243. exports.DecoderBuffer = DecoderBuffer;
  244. DecoderBuffer.prototype.save = function save() {
  245. return { offset: this.offset, reporter: Reporter.prototype.save.call(this) };
  246. };
  247. DecoderBuffer.prototype.restore = function restore(save) {
  248. // Return skipped data
  249. var res = new DecoderBuffer(this.base);
  250. res.offset = save.offset;
  251. res.length = this.offset;
  252. this.offset = save.offset;
  253. Reporter.prototype.restore.call(this, save.reporter);
  254. return res;
  255. };
  256. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  257. return this.offset === this.length;
  258. };
  259. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  260. if (this.offset + 1 <= this.length)
  261. return this.base.readUInt8(this.offset++, true);
  262. else
  263. return this.error(fail || 'DecoderBuffer overrun');
  264. }
  265. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  266. if (!(this.offset + bytes <= this.length))
  267. return this.error(fail || 'DecoderBuffer overrun');
  268. var res = new DecoderBuffer(this.base);
  269. // Share reporter state
  270. res._reporterState = this._reporterState;
  271. res.offset = this.offset;
  272. res.length = this.offset + bytes;
  273. this.offset += bytes;
  274. return res;
  275. }
  276. DecoderBuffer.prototype.raw = function raw(save) {
  277. return this.base.slice(save ? save.offset : this.offset, this.length);
  278. }
  279. function EncoderBuffer(value, reporter) {
  280. if (Array.isArray(value)) {
  281. this.length = 0;
  282. this.value = value.map(function(item) {
  283. if (!(item instanceof EncoderBuffer))
  284. item = new EncoderBuffer(item, reporter);
  285. this.length += item.length;
  286. return item;
  287. }, this);
  288. } else if (typeof value === 'number') {
  289. if (!(0 <= value && value <= 0xff))
  290. return reporter.error('non-byte EncoderBuffer value');
  291. this.value = value;
  292. this.length = 1;
  293. } else if (typeof value === 'string') {
  294. this.value = value;
  295. this.length = Buffer.byteLength(value);
  296. } else if (Buffer.isBuffer(value)) {
  297. this.value = value;
  298. this.length = value.length;
  299. } else {
  300. return reporter.error('Unsupported type: ' + typeof value);
  301. }
  302. }
  303. exports.EncoderBuffer = EncoderBuffer;
  304. EncoderBuffer.prototype.join = function join(out, offset) {
  305. if (!out)
  306. out = new Buffer(this.length);
  307. if (!offset)
  308. offset = 0;
  309. if (this.length === 0)
  310. return out;
  311. if (Array.isArray(this.value)) {
  312. this.value.forEach(function(item) {
  313. item.join(out, offset);
  314. offset += item.length;
  315. });
  316. } else {
  317. if (typeof this.value === 'number')
  318. out[offset] = this.value;
  319. else if (typeof this.value === 'string')
  320. out.write(this.value, offset);
  321. else if (Buffer.isBuffer(this.value))
  322. this.value.copy(out, offset);
  323. offset += this.length;
  324. }
  325. return out;
  326. };
  327. },{"../base":6,"buffer":46,"inherits":92}],6:[function(require,module,exports){
  328. var base = exports;
  329. base.Reporter = require('./reporter').Reporter;
  330. base.DecoderBuffer = require('./buffer').DecoderBuffer;
  331. base.EncoderBuffer = require('./buffer').EncoderBuffer;
  332. base.Node = require('./node');
  333. },{"./buffer":5,"./node":7,"./reporter":8}],7:[function(require,module,exports){
  334. var Reporter = require('../base').Reporter;
  335. var EncoderBuffer = require('../base').EncoderBuffer;
  336. var DecoderBuffer = require('../base').DecoderBuffer;
  337. var assert = require('minimalistic-assert');
  338. // Supported tags
  339. var tags = [
  340. 'seq', 'seqof', 'set', 'setof', 'objid', 'bool',
  341. 'gentime', 'utctime', 'null_', 'enum', 'int',
  342. 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str',
  343. 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr'
  344. ];
  345. // Public methods list
  346. var methods = [
  347. 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice',
  348. 'any', 'contains'
  349. ].concat(tags);
  350. // Overrided methods list
  351. var overrided = [
  352. '_peekTag', '_decodeTag', '_use',
  353. '_decodeStr', '_decodeObjid', '_decodeTime',
  354. '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList',
  355. '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime',
  356. '_encodeNull', '_encodeInt', '_encodeBool'
  357. ];
  358. function Node(enc, parent) {
  359. var state = {};
  360. this._baseState = state;
  361. state.enc = enc;
  362. state.parent = parent || null;
  363. state.children = null;
  364. // State
  365. state.tag = null;
  366. state.args = null;
  367. state.reverseArgs = null;
  368. state.choice = null;
  369. state.optional = false;
  370. state.any = false;
  371. state.obj = false;
  372. state.use = null;
  373. state.useDecoder = null;
  374. state.key = null;
  375. state['default'] = null;
  376. state.explicit = null;
  377. state.implicit = null;
  378. state.contains = null;
  379. // Should create new instance on each method
  380. if (!state.parent) {
  381. state.children = [];
  382. this._wrap();
  383. }
  384. }
  385. module.exports = Node;
  386. var stateProps = [
  387. 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice',
  388. 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit',
  389. 'implicit'
  390. ];
  391. Node.prototype.clone = function clone() {
  392. var state = this._baseState;
  393. var cstate = {};
  394. stateProps.forEach(function(prop) {
  395. cstate[prop] = state[prop];
  396. });
  397. var res = new this.constructor(cstate.parent);
  398. res._baseState = cstate;
  399. return res;
  400. };
  401. Node.prototype._wrap = function wrap() {
  402. var state = this._baseState;
  403. methods.forEach(function(method) {
  404. this[method] = function _wrappedMethod() {
  405. var clone = new this.constructor(this);
  406. state.children.push(clone);
  407. return clone[method].apply(clone, arguments);
  408. };
  409. }, this);
  410. };
  411. Node.prototype._init = function init(body) {
  412. var state = this._baseState;
  413. assert(state.parent === null);
  414. body.call(this);
  415. // Filter children
  416. state.children = state.children.filter(function(child) {
  417. return child._baseState.parent === this;
  418. }, this);
  419. assert.equal(state.children.length, 1, 'Root node can have only one child');
  420. };
  421. Node.prototype._useArgs = function useArgs(args) {
  422. var state = this._baseState;
  423. // Filter children and args
  424. var children = args.filter(function(arg) {
  425. return arg instanceof this.constructor;
  426. }, this);
  427. args = args.filter(function(arg) {
  428. return !(arg instanceof this.constructor);
  429. }, this);
  430. if (children.length !== 0) {
  431. assert(state.children === null);
  432. state.children = children;
  433. // Replace parent to maintain backward link
  434. children.forEach(function(child) {
  435. child._baseState.parent = this;
  436. }, this);
  437. }
  438. if (args.length !== 0) {
  439. assert(state.args === null);
  440. state.args = args;
  441. state.reverseArgs = args.map(function(arg) {
  442. if (typeof arg !== 'object' || arg.constructor !== Object)
  443. return arg;
  444. var res = {};
  445. Object.keys(arg).forEach(function(key) {
  446. if (key == (key | 0))
  447. key |= 0;
  448. var value = arg[key];
  449. res[value] = key;
  450. });
  451. return res;
  452. });
  453. }
  454. };
  455. //
  456. // Overrided methods
  457. //
  458. overrided.forEach(function(method) {
  459. Node.prototype[method] = function _overrided() {
  460. var state = this._baseState;
  461. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  462. };
  463. });
  464. //
  465. // Public methods
  466. //
  467. tags.forEach(function(tag) {
  468. Node.prototype[tag] = function _tagMethod() {
  469. var state = this._baseState;
  470. var args = Array.prototype.slice.call(arguments);
  471. assert(state.tag === null);
  472. state.tag = tag;
  473. this._useArgs(args);
  474. return this;
  475. };
  476. });
  477. Node.prototype.use = function use(item) {
  478. var state = this._baseState;
  479. assert(state.use === null);
  480. state.use = item;
  481. return this;
  482. };
  483. Node.prototype.optional = function optional() {
  484. var state = this._baseState;
  485. state.optional = true;
  486. return this;
  487. };
  488. Node.prototype.def = function def(val) {
  489. var state = this._baseState;
  490. assert(state['default'] === null);
  491. state['default'] = val;
  492. state.optional = true;
  493. return this;
  494. };
  495. Node.prototype.explicit = function explicit(num) {
  496. var state = this._baseState;
  497. assert(state.explicit === null && state.implicit === null);
  498. state.explicit = num;
  499. return this;
  500. };
  501. Node.prototype.implicit = function implicit(num) {
  502. var state = this._baseState;
  503. assert(state.explicit === null && state.implicit === null);
  504. state.implicit = num;
  505. return this;
  506. };
  507. Node.prototype.obj = function obj() {
  508. var state = this._baseState;
  509. var args = Array.prototype.slice.call(arguments);
  510. state.obj = true;
  511. if (args.length !== 0)
  512. this._useArgs(args);
  513. return this;
  514. };
  515. Node.prototype.key = function key(newKey) {
  516. var state = this._baseState;
  517. assert(state.key === null);
  518. state.key = newKey;
  519. return this;
  520. };
  521. Node.prototype.any = function any() {
  522. var state = this._baseState;
  523. state.any = true;
  524. return this;
  525. };
  526. Node.prototype.choice = function choice(obj) {
  527. var state = this._baseState;
  528. assert(state.choice === null);
  529. state.choice = obj;
  530. this._useArgs(Object.keys(obj).map(function(key) {
  531. return obj[key];
  532. }));
  533. return this;
  534. };
  535. Node.prototype.contains = function contains(item) {
  536. var state = this._baseState;
  537. assert(state.use === null);
  538. state.contains = item;
  539. return this;
  540. };
  541. //
  542. // Decoding
  543. //
  544. Node.prototype._decode = function decode(input) {
  545. var state = this._baseState;
  546. // Decode root node
  547. if (state.parent === null)
  548. return input.wrapResult(state.children[0]._decode(input));
  549. var result = state['default'];
  550. var present = true;
  551. var prevKey;
  552. if (state.key !== null)
  553. prevKey = input.enterKey(state.key);
  554. // Check if tag is there
  555. if (state.optional) {
  556. var tag = null;
  557. if (state.explicit !== null)
  558. tag = state.explicit;
  559. else if (state.implicit !== null)
  560. tag = state.implicit;
  561. else if (state.tag !== null)
  562. tag = state.tag;
  563. if (tag === null && !state.any) {
  564. // Trial and Error
  565. var save = input.save();
  566. try {
  567. if (state.choice === null)
  568. this._decodeGeneric(state.tag, input);
  569. else
  570. this._decodeChoice(input);
  571. present = true;
  572. } catch (e) {
  573. present = false;
  574. }
  575. input.restore(save);
  576. } else {
  577. present = this._peekTag(input, tag, state.any);
  578. if (input.isError(present))
  579. return present;
  580. }
  581. }
  582. // Push object on stack
  583. var prevObj;
  584. if (state.obj && present)
  585. prevObj = input.enterObject();
  586. if (present) {
  587. // Unwrap explicit values
  588. if (state.explicit !== null) {
  589. var explicit = this._decodeTag(input, state.explicit);
  590. if (input.isError(explicit))
  591. return explicit;
  592. input = explicit;
  593. }
  594. // Unwrap implicit and normal values
  595. if (state.use === null && state.choice === null) {
  596. if (state.any)
  597. var save = input.save();
  598. var body = this._decodeTag(
  599. input,
  600. state.implicit !== null ? state.implicit : state.tag,
  601. state.any
  602. );
  603. if (input.isError(body))
  604. return body;
  605. if (state.any)
  606. result = input.raw(save);
  607. else
  608. input = body;
  609. }
  610. // Select proper method for tag
  611. if (state.any)
  612. result = result;
  613. else if (state.choice === null)
  614. result = this._decodeGeneric(state.tag, input);
  615. else
  616. result = this._decodeChoice(input);
  617. if (input.isError(result))
  618. return result;
  619. // Decode children
  620. if (!state.any && state.choice === null && state.children !== null) {
  621. state.children.forEach(function decodeChildren(child) {
  622. // NOTE: We are ignoring errors here, to let parser continue with other
  623. // parts of encoded data
  624. child._decode(input);
  625. });
  626. }
  627. // Decode contained/encoded by schema, only in bit or octet strings
  628. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  629. var data = new DecoderBuffer(result);
  630. result = this._getUse(state.contains, input._reporterState.obj)._decode(data);
  631. }
  632. }
  633. // Pop object
  634. if (state.obj && present)
  635. result = input.leaveObject(prevObj);
  636. // Set key
  637. if (state.key !== null && (result !== null || present === true))
  638. input.leaveKey(prevKey, state.key, result);
  639. return result;
  640. };
  641. Node.prototype._decodeGeneric = function decodeGeneric(tag, input) {
  642. var state = this._baseState;
  643. if (tag === 'seq' || tag === 'set')
  644. return null;
  645. if (tag === 'seqof' || tag === 'setof')
  646. return this._decodeList(input, tag, state.args[0]);
  647. else if (/str$/.test(tag))
  648. return this._decodeStr(input, tag);
  649. else if (tag === 'objid' && state.args)
  650. return this._decodeObjid(input, state.args[0], state.args[1]);
  651. else if (tag === 'objid')
  652. return this._decodeObjid(input, null, null);
  653. else if (tag === 'gentime' || tag === 'utctime')
  654. return this._decodeTime(input, tag);
  655. else if (tag === 'null_')
  656. return this._decodeNull(input);
  657. else if (tag === 'bool')
  658. return this._decodeBool(input);
  659. else if (tag === 'int' || tag === 'enum')
  660. return this._decodeInt(input, state.args && state.args[0]);
  661. else if (state.use !== null)
  662. return this._getUse(state.use, input._reporterState.obj)._decode(input);
  663. else
  664. return input.error('unknown tag: ' + tag);
  665. };
  666. Node.prototype._getUse = function _getUse(entity, obj) {
  667. var state = this._baseState;
  668. // Create altered use decoder if implicit is set
  669. state.useDecoder = this._use(entity, obj);
  670. assert(state.useDecoder._baseState.parent === null);
  671. state.useDecoder = state.useDecoder._baseState.children[0];
  672. if (state.implicit !== state.useDecoder._baseState.implicit) {
  673. state.useDecoder = state.useDecoder.clone();
  674. state.useDecoder._baseState.implicit = state.implicit;
  675. }
  676. return state.useDecoder;
  677. };
  678. Node.prototype._decodeChoice = function decodeChoice(input) {
  679. var state = this._baseState;
  680. var result = null;
  681. var match = false;
  682. Object.keys(state.choice).some(function(key) {
  683. var save = input.save();
  684. var node = state.choice[key];
  685. try {
  686. var value = node._decode(input);
  687. if (input.isError(value))
  688. return false;
  689. result = { type: key, value: value };
  690. match = true;
  691. } catch (e) {
  692. input.restore(save);
  693. return false;
  694. }
  695. return true;
  696. }, this);
  697. if (!match)
  698. return input.error('Choice not matched');
  699. return result;
  700. };
  701. //
  702. // Encoding
  703. //
  704. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  705. return new EncoderBuffer(data, this.reporter);
  706. };
  707. Node.prototype._encode = function encode(data, reporter, parent) {
  708. var state = this._baseState;
  709. if (state['default'] !== null && state['default'] === data)
  710. return;
  711. var result = this._encodeValue(data, reporter, parent);
  712. if (result === undefined)
  713. return;
  714. if (this._skipDefault(result, reporter, parent))
  715. return;
  716. return result;
  717. };
  718. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  719. var state = this._baseState;
  720. // Decode root node
  721. if (state.parent === null)
  722. return state.children[0]._encode(data, reporter || new Reporter());
  723. var result = null;
  724. // Set reporter to share it with a child class
  725. this.reporter = reporter;
  726. // Check if data is there
  727. if (state.optional && data === undefined) {
  728. if (state['default'] !== null)
  729. data = state['default']
  730. else
  731. return;
  732. }
  733. // Encode children first
  734. var content = null;
  735. var primitive = false;
  736. if (state.any) {
  737. // Anything that was given is translated to buffer
  738. result = this._createEncoderBuffer(data);
  739. } else if (state.choice) {
  740. result = this._encodeChoice(data, reporter);
  741. } else if (state.contains) {
  742. content = this._getUse(state.contains, parent)._encode(data, reporter);
  743. primitive = true;
  744. } else if (state.children) {
  745. content = state.children.map(function(child) {
  746. if (child._baseState.tag === 'null_')
  747. return child._encode(null, reporter, data);
  748. if (child._baseState.key === null)
  749. return reporter.error('Child should have a key');
  750. var prevKey = reporter.enterKey(child._baseState.key);
  751. if (typeof data !== 'object')
  752. return reporter.error('Child expected, but input is not object');
  753. var res = child._encode(data[child._baseState.key], reporter, data);
  754. reporter.leaveKey(prevKey);
  755. return res;
  756. }, this).filter(function(child) {
  757. return child;
  758. });
  759. content = this._createEncoderBuffer(content);
  760. } else {
  761. if (state.tag === 'seqof' || state.tag === 'setof') {
  762. // TODO(indutny): this should be thrown on DSL level
  763. if (!(state.args && state.args.length === 1))
  764. return reporter.error('Too many args for : ' + state.tag);
  765. if (!Array.isArray(data))
  766. return reporter.error('seqof/setof, but data is not Array');
  767. var child = this.clone();
  768. child._baseState.implicit = null;
  769. content = this._createEncoderBuffer(data.map(function(item) {
  770. var state = this._baseState;
  771. return this._getUse(state.args[0], data)._encode(item, reporter);
  772. }, child));
  773. } else if (state.use !== null) {
  774. result = this._getUse(state.use, parent)._encode(data, reporter);
  775. } else {
  776. content = this._encodePrimitive(state.tag, data);
  777. primitive = true;
  778. }
  779. }
  780. // Encode data itself
  781. var result;
  782. if (!state.any && state.choice === null) {
  783. var tag = state.implicit !== null ? state.implicit : state.tag;
  784. var cls = state.implicit === null ? 'universal' : 'context';
  785. if (tag === null) {
  786. if (state.use === null)
  787. reporter.error('Tag could be ommited only for .use()');
  788. } else {
  789. if (state.use === null)
  790. result = this._encodeComposite(tag, primitive, cls, content);
  791. }
  792. }
  793. // Wrap in explicit
  794. if (state.explicit !== null)
  795. result = this._encodeComposite(state.explicit, false, 'context', result);
  796. return result;
  797. };
  798. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  799. var state = this._baseState;
  800. var node = state.choice[data.type];
  801. if (!node) {
  802. assert(
  803. false,
  804. data.type + ' not found in ' +
  805. JSON.stringify(Object.keys(state.choice)));
  806. }
  807. return node._encode(data.value, reporter);
  808. };
  809. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  810. var state = this._baseState;
  811. if (/str$/.test(tag))
  812. return this._encodeStr(data, tag);
  813. else if (tag === 'objid' && state.args)
  814. return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);
  815. else if (tag === 'objid')
  816. return this._encodeObjid(data, null, null);
  817. else if (tag === 'gentime' || tag === 'utctime')
  818. return this._encodeTime(data, tag);
  819. else if (tag === 'null_')
  820. return this._encodeNull();
  821. else if (tag === 'int' || tag === 'enum')
  822. return this._encodeInt(data, state.args && state.reverseArgs[0]);
  823. else if (tag === 'bool')
  824. return this._encodeBool(data);
  825. else
  826. throw new Error('Unsupported tag: ' + tag);
  827. };
  828. Node.prototype._isNumstr = function isNumstr(str) {
  829. return /^[0-9 ]*$/.test(str);
  830. };
  831. Node.prototype._isPrintstr = function isPrintstr(str) {
  832. return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str);
  833. };
  834. },{"../base":6,"minimalistic-assert":99}],8:[function(require,module,exports){
  835. var inherits = require('inherits');
  836. function Reporter(options) {
  837. this._reporterState = {
  838. obj: null,
  839. path: [],
  840. options: options || {},
  841. errors: []
  842. };
  843. }
  844. exports.Reporter = Reporter;
  845. Reporter.prototype.isError = function isError(obj) {
  846. return obj instanceof ReporterError;
  847. };
  848. Reporter.prototype.save = function save() {
  849. var state = this._reporterState;
  850. return { obj: state.obj, pathLen: state.path.length };
  851. };
  852. Reporter.prototype.restore = function restore(data) {
  853. var state = this._reporterState;
  854. state.obj = data.obj;
  855. state.path = state.path.slice(0, data.pathLen);
  856. };
  857. Reporter.prototype.enterKey = function enterKey(key) {
  858. return this._reporterState.path.push(key);
  859. };
  860. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  861. var state = this._reporterState;
  862. state.path = state.path.slice(0, index - 1);
  863. if (state.obj !== null)
  864. state.obj[key] = value;
  865. };
  866. Reporter.prototype.enterObject = function enterObject() {
  867. var state = this._reporterState;
  868. var prev = state.obj;
  869. state.obj = {};
  870. return prev;
  871. };
  872. Reporter.prototype.leaveObject = function leaveObject(prev) {
  873. var state = this._reporterState;
  874. var now = state.obj;
  875. state.obj = prev;
  876. return now;
  877. };
  878. Reporter.prototype.error = function error(msg) {
  879. var err;
  880. var state = this._reporterState;
  881. var inherited = msg instanceof ReporterError;
  882. if (inherited) {
  883. err = msg;
  884. } else {
  885. err = new ReporterError(state.path.map(function(elem) {
  886. return '[' + JSON.stringify(elem) + ']';
  887. }).join(''), msg.message || msg, msg.stack);
  888. }
  889. if (!state.options.partial)
  890. throw err;
  891. if (!inherited)
  892. state.errors.push(err);
  893. return err;
  894. };
  895. Reporter.prototype.wrapResult = function wrapResult(result) {
  896. var state = this._reporterState;
  897. if (!state.options.partial)
  898. return result;
  899. return {
  900. result: this.isError(result) ? null : result,
  901. errors: state.errors
  902. };
  903. };
  904. function ReporterError(path, msg) {
  905. this.path = path;
  906. this.rethrow(msg);
  907. };
  908. inherits(ReporterError, Error);
  909. ReporterError.prototype.rethrow = function rethrow(msg) {
  910. this.message = msg + ' at: ' + (this.path || '(shallow)');
  911. Error.captureStackTrace(this, ReporterError);
  912. return this;
  913. };
  914. },{"inherits":92}],9:[function(require,module,exports){
  915. var constants = require('../constants');
  916. exports.tagClass = {
  917. 0: 'universal',
  918. 1: 'application',
  919. 2: 'context',
  920. 3: 'private'
  921. };
  922. exports.tagClassByName = constants._reverse(exports.tagClass);
  923. exports.tag = {
  924. 0x00: 'end',
  925. 0x01: 'bool',
  926. 0x02: 'int',
  927. 0x03: 'bitstr',
  928. 0x04: 'octstr',
  929. 0x05: 'null_',
  930. 0x06: 'objid',
  931. 0x07: 'objDesc',
  932. 0x08: 'external',
  933. 0x09: 'real',
  934. 0x0a: 'enum',
  935. 0x0b: 'embed',
  936. 0x0c: 'utf8str',
  937. 0x0d: 'relativeOid',
  938. 0x10: 'seq',
  939. 0x11: 'set',
  940. 0x12: 'numstr',
  941. 0x13: 'printstr',
  942. 0x14: 't61str',
  943. 0x15: 'videostr',
  944. 0x16: 'ia5str',
  945. 0x17: 'utctime',
  946. 0x18: 'gentime',
  947. 0x19: 'graphstr',
  948. 0x1a: 'iso646str',
  949. 0x1b: 'genstr',
  950. 0x1c: 'unistr',
  951. 0x1d: 'charstr',
  952. 0x1e: 'bmpstr'
  953. };
  954. exports.tagByName = constants._reverse(exports.tag);
  955. },{"../constants":10}],10:[function(require,module,exports){
  956. var constants = exports;
  957. // Helper
  958. constants._reverse = function reverse(map) {
  959. var res = {};
  960. Object.keys(map).forEach(function(key) {
  961. // Convert key to integer if it is stringified
  962. if ((key | 0) == key)
  963. key = key | 0;
  964. var value = map[key];
  965. res[value] = key;
  966. });
  967. return res;
  968. };
  969. constants.der = require('./der');
  970. },{"./der":9}],11:[function(require,module,exports){
  971. var inherits = require('inherits');
  972. var asn1 = require('../../asn1');
  973. var base = asn1.base;
  974. var bignum = asn1.bignum;
  975. // Import DER constants
  976. var der = asn1.constants.der;
  977. function DERDecoder(entity) {
  978. this.enc = 'der';
  979. this.name = entity.name;
  980. this.entity = entity;
  981. // Construct base tree
  982. this.tree = new DERNode();
  983. this.tree._init(entity.body);
  984. };
  985. module.exports = DERDecoder;
  986. DERDecoder.prototype.decode = function decode(data, options) {
  987. if (!(data instanceof base.DecoderBuffer))
  988. data = new base.DecoderBuffer(data, options);
  989. return this.tree._decode(data, options);
  990. };
  991. // Tree methods
  992. function DERNode(parent) {
  993. base.Node.call(this, 'der', parent);
  994. }
  995. inherits(DERNode, base.Node);
  996. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  997. if (buffer.isEmpty())
  998. return false;
  999. var state = buffer.save();
  1000. var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  1001. if (buffer.isError(decodedTag))
  1002. return decodedTag;
  1003. buffer.restore(state);
  1004. return decodedTag.tag === tag || decodedTag.tagStr === tag ||
  1005. (decodedTag.tagStr + 'of') === tag || any;
  1006. };
  1007. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  1008. var decodedTag = derDecodeTag(buffer,
  1009. 'Failed to decode tag of "' + tag + '"');
  1010. if (buffer.isError(decodedTag))
  1011. return decodedTag;
  1012. var len = derDecodeLen(buffer,
  1013. decodedTag.primitive,
  1014. 'Failed to get length of "' + tag + '"');
  1015. // Failure
  1016. if (buffer.isError(len))
  1017. return len;
  1018. if (!any &&
  1019. decodedTag.tag !== tag &&
  1020. decodedTag.tagStr !== tag &&
  1021. decodedTag.tagStr + 'of' !== tag) {
  1022. return buffer.error('Failed to match tag: "' + tag + '"');
  1023. }
  1024. if (decodedTag.primitive || len !== null)
  1025. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  1026. // Indefinite length... find END tag
  1027. var state = buffer.save();
  1028. var res = this._skipUntilEnd(
  1029. buffer,
  1030. 'Failed to skip indefinite length body: "' + this.tag + '"');
  1031. if (buffer.isError(res))
  1032. return res;
  1033. len = buffer.offset - state.offset;
  1034. buffer.restore(state);
  1035. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  1036. };
  1037. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  1038. while (true) {
  1039. var tag = derDecodeTag(buffer, fail);
  1040. if (buffer.isError(tag))
  1041. return tag;
  1042. var len = derDecodeLen(buffer, tag.primitive, fail);
  1043. if (buffer.isError(len))
  1044. return len;
  1045. var res;
  1046. if (tag.primitive || len !== null)
  1047. res = buffer.skip(len)
  1048. else
  1049. res = this._skipUntilEnd(buffer, fail);
  1050. // Failure
  1051. if (buffer.isError(res))
  1052. return res;
  1053. if (tag.tagStr === 'end')
  1054. break;
  1055. }
  1056. };
  1057. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder) {
  1058. var result = [];
  1059. while (!buffer.isEmpty()) {
  1060. var possibleEnd = this._peekTag(buffer, 'end');
  1061. if (buffer.isError(possibleEnd))
  1062. return possibleEnd;
  1063. var res = decoder.decode(buffer, 'der');
  1064. if (buffer.isError(res) && possibleEnd)
  1065. break;
  1066. result.push(res);
  1067. }
  1068. return result;
  1069. };
  1070. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  1071. if (tag === 'bitstr') {
  1072. var unused = buffer.readUInt8();
  1073. if (buffer.isError(unused))
  1074. return unused;
  1075. return { unused: unused, data: buffer.raw() };
  1076. } else if (tag === 'bmpstr') {
  1077. var raw = buffer.raw();
  1078. if (raw.length % 2 === 1)
  1079. return buffer.error('Decoding of string type: bmpstr length mismatch');
  1080. var str = '';
  1081. for (var i = 0; i < raw.length / 2; i++) {
  1082. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  1083. }
  1084. return str;
  1085. } else if (tag === 'numstr') {
  1086. var numstr = buffer.raw().toString('ascii');
  1087. if (!this._isNumstr(numstr)) {
  1088. return buffer.error('Decoding of string type: ' +
  1089. 'numstr unsupported characters');
  1090. }
  1091. return numstr;
  1092. } else if (tag === 'octstr') {
  1093. return buffer.raw();
  1094. } else if (tag === 'printstr') {
  1095. var printstr = buffer.raw().toString('ascii');
  1096. if (!this._isPrintstr(printstr)) {
  1097. return buffer.error('Decoding of string type: ' +
  1098. 'printstr unsupported characters');
  1099. }
  1100. return printstr;
  1101. } else if (/str$/.test(tag)) {
  1102. return buffer.raw().toString();
  1103. } else {
  1104. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  1105. }
  1106. };
  1107. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  1108. var result;
  1109. var identifiers = [];
  1110. var ident = 0;
  1111. while (!buffer.isEmpty()) {
  1112. var subident = buffer.readUInt8();
  1113. ident <<= 7;
  1114. ident |= subident & 0x7f;
  1115. if ((subident & 0x80) === 0) {
  1116. identifiers.push(ident);
  1117. ident = 0;
  1118. }
  1119. }
  1120. if (subident & 0x80)
  1121. identifiers.push(ident);
  1122. var first = (identifiers[0] / 40) | 0;
  1123. var second = identifiers[0] % 40;
  1124. if (relative)
  1125. result = identifiers;
  1126. else
  1127. result = [first, second].concat(identifiers.slice(1));
  1128. if (values) {
  1129. var tmp = values[result.join(' ')];
  1130. if (tmp === undefined)
  1131. tmp = values[result.join('.')];
  1132. if (tmp !== undefined)
  1133. result = tmp;
  1134. }
  1135. return result;
  1136. };
  1137. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  1138. var str = buffer.raw().toString();
  1139. if (tag === 'gentime') {
  1140. var year = str.slice(0, 4) | 0;
  1141. var mon = str.slice(4, 6) | 0;
  1142. var day = str.slice(6, 8) | 0;
  1143. var hour = str.slice(8, 10) | 0;
  1144. var min = str.slice(10, 12) | 0;
  1145. var sec = str.slice(12, 14) | 0;
  1146. } else if (tag === 'utctime') {
  1147. var year = str.slice(0, 2) | 0;
  1148. var mon = str.slice(2, 4) | 0;
  1149. var day = str.slice(4, 6) | 0;
  1150. var hour = str.slice(6, 8) | 0;
  1151. var min = str.slice(8, 10) | 0;
  1152. var sec = str.slice(10, 12) | 0;
  1153. if (year < 70)
  1154. year = 2000 + year;
  1155. else
  1156. year = 1900 + year;
  1157. } else {
  1158. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  1159. }
  1160. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  1161. };
  1162. DERNode.prototype._decodeNull = function decodeNull(buffer) {
  1163. return null;
  1164. };
  1165. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  1166. var res = buffer.readUInt8();
  1167. if (buffer.isError(res))
  1168. return res;
  1169. else
  1170. return res !== 0;
  1171. };
  1172. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  1173. // Bigint, return as it is (assume big endian)
  1174. var raw = buffer.raw();
  1175. var res = new bignum(raw);
  1176. if (values)
  1177. res = values[res.toString(10)] || res;
  1178. return res;
  1179. };
  1180. DERNode.prototype._use = function use(entity, obj) {
  1181. if (typeof entity === 'function')
  1182. entity = entity(obj);
  1183. return entity._getDecoder('der').tree;
  1184. };
  1185. // Utility methods
  1186. function derDecodeTag(buf, fail) {
  1187. var tag = buf.readUInt8(fail);
  1188. if (buf.isError(tag))
  1189. return tag;
  1190. var cls = der.tagClass[tag >> 6];
  1191. var primitive = (tag & 0x20) === 0;
  1192. // Multi-octet tag - load
  1193. if ((tag & 0x1f) === 0x1f) {
  1194. var oct = tag;
  1195. tag = 0;
  1196. while ((oct & 0x80) === 0x80) {
  1197. oct = buf.readUInt8(fail);
  1198. if (buf.isError(oct))
  1199. return oct;
  1200. tag <<= 7;
  1201. tag |= oct & 0x7f;
  1202. }
  1203. } else {
  1204. tag &= 0x1f;
  1205. }
  1206. var tagStr = der.tag[tag];
  1207. return {
  1208. cls: cls,
  1209. primitive: primitive,
  1210. tag: tag,
  1211. tagStr: tagStr
  1212. };
  1213. }
  1214. function derDecodeLen(buf, primitive, fail) {
  1215. var len = buf.readUInt8(fail);
  1216. if (buf.isError(len))
  1217. return len;
  1218. // Indefinite form
  1219. if (!primitive && len === 0x80)
  1220. return null;
  1221. // Definite form
  1222. if ((len & 0x80) === 0) {
  1223. // Short form
  1224. return len;
  1225. }
  1226. // Long form
  1227. var num = len & 0x7f;
  1228. if (num >= 4)
  1229. return buf.error('length octect is too long');
  1230. len = 0;
  1231. for (var i = 0; i < num; i++) {
  1232. len <<= 8;
  1233. var j = buf.readUInt8(fail);
  1234. if (buf.isError(j))
  1235. return j;
  1236. len |= j;
  1237. }
  1238. return len;
  1239. }
  1240. },{"../../asn1":3,"inherits":92}],12:[function(require,module,exports){
  1241. var decoders = exports;
  1242. decoders.der = require('./der');
  1243. decoders.pem = require('./pem');
  1244. },{"./der":11,"./pem":13}],13:[function(require,module,exports){
  1245. var inherits = require('inherits');
  1246. var Buffer = require('buffer').Buffer;
  1247. var DERDecoder = require('./der');
  1248. function PEMDecoder(entity) {
  1249. DERDecoder.call(this, entity);
  1250. this.enc = 'pem';
  1251. };
  1252. inherits(PEMDecoder, DERDecoder);
  1253. module.exports = PEMDecoder;
  1254. PEMDecoder.prototype.decode = function decode(data, options) {
  1255. var lines = data.toString().split(/[\r\n]+/g);
  1256. var label = options.label.toUpperCase();
  1257. var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  1258. var start = -1;
  1259. var end = -1;
  1260. for (var i = 0; i < lines.length; i++) {
  1261. var match = lines[i].match(re);
  1262. if (match === null)
  1263. continue;
  1264. if (match[2] !== label)
  1265. continue;
  1266. if (start === -1) {
  1267. if (match[1] !== 'BEGIN')
  1268. break;
  1269. start = i;
  1270. } else {
  1271. if (match[1] !== 'END')
  1272. break;
  1273. end = i;
  1274. break;
  1275. }
  1276. }
  1277. if (start === -1 || end === -1)
  1278. throw new Error('PEM section not found for: ' + label);
  1279. var base64 = lines.slice(start + 1, end).join('');
  1280. // Remove excessive symbols
  1281. base64.replace(/[^a-z0-9\+\/=]+/gi, '');
  1282. var input = new Buffer(base64, 'base64');
  1283. return DERDecoder.prototype.decode.call(this, input, options);
  1284. };
  1285. },{"./der":11,"buffer":46,"inherits":92}],14:[function(require,module,exports){
  1286. var inherits = require('inherits');
  1287. var Buffer = require('buffer').Buffer;
  1288. var asn1 = require('../../asn1');
  1289. var base = asn1.base;
  1290. // Import DER constants
  1291. var der = asn1.constants.der;
  1292. function DEREncoder(entity) {
  1293. this.enc = 'der';
  1294. this.name = entity.name;
  1295. this.entity = entity;
  1296. // Construct base tree
  1297. this.tree = new DERNode();
  1298. this.tree._init(entity.body);
  1299. };
  1300. module.exports = DEREncoder;
  1301. DEREncoder.prototype.encode = function encode(data, reporter) {
  1302. return this.tree._encode(data, reporter).join();
  1303. };
  1304. // Tree methods
  1305. function DERNode(parent) {
  1306. base.Node.call(this, 'der', parent);
  1307. }
  1308. inherits(DERNode, base.Node);
  1309. DERNode.prototype._encodeComposite = function encodeComposite(tag,
  1310. primitive,
  1311. cls,
  1312. content) {
  1313. var encodedTag = encodeTag(tag, primitive, cls, this.reporter);
  1314. // Short form
  1315. if (content.length < 0x80) {
  1316. var header = new Buffer(2);
  1317. header[0] = encodedTag;
  1318. header[1] = content.length;
  1319. return this._createEncoderBuffer([ header, content ]);
  1320. }
  1321. // Long form
  1322. // Count octets required to store length
  1323. var lenOctets = 1;
  1324. for (var i = content.length; i >= 0x100; i >>= 8)
  1325. lenOctets++;
  1326. var header = new Buffer(1 + 1 + lenOctets);
  1327. header[0] = encodedTag;
  1328. header[1] = 0x80 | lenOctets;
  1329. for (var i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8)
  1330. header[i] = j & 0xff;
  1331. return this._createEncoderBuffer([ header, content ]);
  1332. };
  1333. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  1334. if (tag === 'bitstr') {
  1335. return this._createEncoderBuffer([ str.unused | 0, str.data ]);
  1336. } else if (tag === 'bmpstr') {
  1337. var buf = new Buffer(str.length * 2);
  1338. for (var i = 0; i < str.length; i++) {
  1339. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  1340. }
  1341. return this._createEncoderBuffer(buf);
  1342. } else if (tag === 'numstr') {
  1343. if (!this._isNumstr(str)) {
  1344. return this.reporter.error('Encoding of string type: numstr supports ' +
  1345. 'only digits and space');
  1346. }
  1347. return this._createEncoderBuffer(str);
  1348. } else if (tag === 'printstr') {
  1349. if (!this._isPrintstr(str)) {
  1350. return this.reporter.error('Encoding of string type: printstr supports ' +
  1351. 'only latin upper and lower case letters, ' +
  1352. 'digits, space, apostrophe, left and rigth ' +
  1353. 'parenthesis, plus sign, comma, hyphen, ' +
  1354. 'dot, slash, colon, equal sign, ' +
  1355. 'question mark');
  1356. }
  1357. return this._createEncoderBuffer(str);
  1358. } else if (/str$/.test(tag)) {
  1359. return this._createEncoderBuffer(str);
  1360. } else {
  1361. return this.reporter.error('Encoding of string type: ' + tag +
  1362. ' unsupported');
  1363. }
  1364. };
  1365. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  1366. if (typeof id === 'string') {
  1367. if (!values)
  1368. return this.reporter.error('string objid given, but no values map found');
  1369. if (!values.hasOwnProperty(id))
  1370. return this.reporter.error('objid not found in values map');
  1371. id = values[id].split(/[\s\.]+/g);
  1372. for (var i = 0; i < id.length; i++)
  1373. id[i] |= 0;
  1374. } else if (Array.isArray(id)) {
  1375. id = id.slice();
  1376. for (var i = 0; i < id.length; i++)
  1377. id[i] |= 0;
  1378. }
  1379. if (!Array.isArray(id)) {
  1380. return this.reporter.error('objid() should be either array or string, ' +
  1381. 'got: ' + JSON.stringify(id));
  1382. }
  1383. if (!relative) {
  1384. if (id[1] >= 40)
  1385. return this.reporter.error('Second objid identifier OOB');
  1386. id.splice(0, 2, id[0] * 40 + id[1]);
  1387. }
  1388. // Count number of octets
  1389. var size = 0;
  1390. for (var i = 0; i < id.length; i++) {
  1391. var ident = id[i];
  1392. for (size++; ident >= 0x80; ident >>= 7)
  1393. size++;
  1394. }
  1395. var objid = new Buffer(size);
  1396. var offset = objid.length - 1;
  1397. for (var i = id.length - 1; i >= 0; i--) {
  1398. var ident = id[i];
  1399. objid[offset--] = ident & 0x7f;
  1400. while ((ident >>= 7) > 0)
  1401. objid[offset--] = 0x80 | (ident & 0x7f);
  1402. }
  1403. return this._createEncoderBuffer(objid);
  1404. };
  1405. function two(num) {
  1406. if (num < 10)
  1407. return '0' + num;
  1408. else
  1409. return num;
  1410. }
  1411. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  1412. var str;
  1413. var date = new Date(time);
  1414. if (tag === 'gentime') {
  1415. str = [
  1416. two(date.getFullYear()),
  1417. two(date.getUTCMonth() + 1),
  1418. two(date.getUTCDate()),
  1419. two(date.getUTCHours()),
  1420. two(date.getUTCMinutes()),
  1421. two(date.getUTCSeconds()),
  1422. 'Z'
  1423. ].join('');
  1424. } else if (tag === 'utctime') {
  1425. str = [
  1426. two(date.getFullYear() % 100),
  1427. two(date.getUTCMonth() + 1),
  1428. two(date.getUTCDate()),
  1429. two(date.getUTCHours()),
  1430. two(date.getUTCMinutes()),
  1431. two(date.getUTCSeconds()),
  1432. 'Z'
  1433. ].join('');
  1434. } else {
  1435. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  1436. }
  1437. return this._encodeStr(str, 'octstr');
  1438. };
  1439. DERNode.prototype._encodeNull = function encodeNull() {
  1440. return this._createEncoderBuffer('');
  1441. };
  1442. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  1443. if (typeof num === 'string') {
  1444. if (!values)
  1445. return this.reporter.error('String int or enum given, but no values map');
  1446. if (!values.hasOwnProperty(num)) {
  1447. return this.reporter.error('Values map doesn\'t contain: ' +
  1448. JSON.stringify(num));
  1449. }
  1450. num = values[num];
  1451. }
  1452. // Bignum, assume big endian
  1453. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  1454. var numArray = num.toArray();
  1455. if (!num.sign && numArray[0] & 0x80) {
  1456. numArray.unshift(0);
  1457. }
  1458. num = new Buffer(numArray);
  1459. }
  1460. if (Buffer.isBuffer(num)) {
  1461. var size = num.length;
  1462. if (num.length === 0)
  1463. size++;
  1464. var out = new Buffer(size);
  1465. num.copy(out);
  1466. if (num.length === 0)
  1467. out[0] = 0
  1468. return this._createEncoderBuffer(out);
  1469. }
  1470. if (num < 0x80)
  1471. return this._createEncoderBuffer(num);
  1472. if (num < 0x100)
  1473. return this._createEncoderBuffer([0, num]);
  1474. var size = 1;
  1475. for (var i = num; i >= 0x100; i >>= 8)
  1476. size++;
  1477. var out = new Array(size);
  1478. for (var i = out.length - 1; i >= 0; i--) {
  1479. out[i] = num & 0xff;
  1480. num >>= 8;
  1481. }
  1482. if(out[0] & 0x80) {
  1483. out.unshift(0);
  1484. }
  1485. return this._createEncoderBuffer(new Buffer(out));
  1486. };
  1487. DERNode.prototype._encodeBool = function encodeBool(value) {
  1488. return this._createEncoderBuffer(value ? 0xff : 0);
  1489. };
  1490. DERNode.prototype._use = function use(entity, obj) {
  1491. if (typeof entity === 'function')
  1492. entity = entity(obj);
  1493. return entity._getEncoder('der').tree;
  1494. };
  1495. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  1496. var state = this._baseState;
  1497. var i;
  1498. if (state['default'] === null)
  1499. return false;
  1500. var data = dataBuffer.join();
  1501. if (state.defaultBuffer === undefined)
  1502. state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  1503. if (data.length !== state.defaultBuffer.length)
  1504. return false;
  1505. for (i=0; i < data.length; i++)
  1506. if (data[i] !== state.defaultBuffer[i])
  1507. return false;
  1508. return true;
  1509. };
  1510. // Utility methods
  1511. function encodeTag(tag, primitive, cls, reporter) {
  1512. var res;
  1513. if (tag === 'seqof')
  1514. tag = 'seq';
  1515. else if (tag === 'setof')
  1516. tag = 'set';
  1517. if (der.tagByName.hasOwnProperty(tag))
  1518. res = der.tagByName[tag];
  1519. else if (typeof tag === 'number' && (tag | 0) === tag)
  1520. res = tag;
  1521. else
  1522. return reporter.error('Unknown tag: ' + tag);
  1523. if (res >= 0x1f)
  1524. return reporter.error('Multi-octet tag encoding unsupported');
  1525. if (!primitive)
  1526. res |= 0x20;
  1527. res |= (der.tagClassByName[cls || 'universal'] << 6);
  1528. return res;
  1529. }
  1530. },{"../../asn1":3,"buffer":46,"inherits":92}],15:[function(require,module,exports){
  1531. var encoders = exports;
  1532. encoders.der = require('./der');
  1533. encoders.pem = require('./pem');
  1534. },{"./der":14,"./pem":16}],16:[function(require,module,exports){
  1535. var inherits = require('inherits');
  1536. var DEREncoder = require('./der');
  1537. function PEMEncoder(entity) {
  1538. DEREncoder.call(this, entity);
  1539. this.enc = 'pem';
  1540. };
  1541. inherits(PEMEncoder, DEREncoder);
  1542. module.exports = PEMEncoder;
  1543. PEMEncoder.prototype.encode = function encode(data, options) {
  1544. var buf = DEREncoder.prototype.encode.call(this, data);
  1545. var p = buf.toString('base64');
  1546. var out = [ '-----BEGIN ' + options.label + '-----' ];
  1547. for (var i = 0; i < p.length; i += 64)
  1548. out.push(p.slice(i, i + 64));
  1549. out.push('-----END ' + options.label + '-----');
  1550. return out.join('\n');
  1551. };
  1552. },{"./der":14,"inherits":92}],17:[function(require,module,exports){
  1553. 'use strict'
  1554. exports.toByteArray = toByteArray
  1555. exports.fromByteArray = fromByteArray
  1556. var lookup = []
  1557. var revLookup = []
  1558. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  1559. function init () {
  1560. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  1561. for (var i = 0, len = code.length; i < len; ++i) {
  1562. lookup[i] = code[i]
  1563. revLookup[code.charCodeAt(i)] = i
  1564. }
  1565. revLookup['-'.charCodeAt(0)] = 62
  1566. revLookup['_'.charCodeAt(0)] = 63
  1567. }
  1568. init()
  1569. function toByteArray (b64) {
  1570. var i, j, l, tmp, placeHolders, arr
  1571. var len = b64.length
  1572. if (len % 4 > 0) {
  1573. throw new Error('Invalid string. Length must be a multiple of 4')
  1574. }
  1575. // the number of equal signs (place holders)
  1576. // if there are two placeholders, than the two characters before it
  1577. // represent one byte
  1578. // if there is only one, then the three characters before it represent 2 bytes
  1579. // this is just a cheap hack to not do indexOf twice
  1580. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  1581. // base64 is 4/3 + up to two characters of the original data
  1582. arr = new Arr(len * 3 / 4 - placeHolders)
  1583. // if there are placeholders, only get up to the last complete 4 chars
  1584. l = placeHolders > 0 ? len - 4 : len
  1585. var L = 0
  1586. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1587. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  1588. arr[L++] = (tmp >> 16) & 0xFF
  1589. arr[L++] = (tmp >> 8) & 0xFF
  1590. arr[L++] = tmp & 0xFF
  1591. }
  1592. if (placeHolders === 2) {
  1593. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  1594. arr[L++] = tmp & 0xFF
  1595. } else if (placeHolders === 1) {
  1596. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  1597. arr[L++] = (tmp >> 8) & 0xFF
  1598. arr[L++] = tmp & 0xFF
  1599. }
  1600. return arr
  1601. }
  1602. function tripletToBase64 (num) {
  1603. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  1604. }
  1605. function encodeChunk (uint8, start, end) {
  1606. var tmp
  1607. var output = []
  1608. for (var i = start; i < end; i += 3) {
  1609. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  1610. output.push(tripletToBase64(tmp))
  1611. }
  1612. return output.join('')
  1613. }
  1614. function fromByteArray (uint8) {
  1615. var tmp
  1616. var len = uint8.length
  1617. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  1618. var output = ''
  1619. var parts = []
  1620. var maxChunkLength = 16383 // must be multiple of 3
  1621. // go through the array every three bytes, we'll deal with trailing stuff later
  1622. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  1623. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  1624. }
  1625. // pad the end with zeros, but make sure to not forget the extra bytes
  1626. if (extraBytes === 1) {
  1627. tmp = uint8[len - 1]
  1628. output += lookup[tmp >> 2]
  1629. output += lookup[(tmp << 4) & 0x3F]
  1630. output += '=='
  1631. } else if (extraBytes === 2) {
  1632. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  1633. output += lookup[tmp >> 10]
  1634. output += lookup[(tmp >> 4) & 0x3F]
  1635. output += lookup[(tmp << 2) & 0x3F]
  1636. output += '='
  1637. }
  1638. parts.push(output)
  1639. return parts.join('')
  1640. }
  1641. },{}],18:[function(require,module,exports){
  1642. (function (module, exports) {
  1643. 'use strict';
  1644. // Utils
  1645. function assert (val, msg) {
  1646. if (!val) throw new Error(msg || 'Assertion failed');
  1647. }
  1648. // Could use `inherits` module, but don't want to move from single file
  1649. // architecture yet.
  1650. function inherits (ctor, superCtor) {
  1651. ctor.super_ = superCtor;
  1652. var TempCtor = function () {};
  1653. TempCtor.prototype = superCtor.prototype;
  1654. ctor.prototype = new TempCtor();
  1655. ctor.prototype.constructor = ctor;
  1656. }
  1657. // BN
  1658. function BN (number, base, endian) {
  1659. if (BN.isBN(number)) {
  1660. return number;
  1661. }
  1662. this.negative = 0;
  1663. this.words = null;
  1664. this.length = 0;
  1665. // Reduction context
  1666. this.red = null;
  1667. if (number !== null) {
  1668. if (base === 'le' || base === 'be') {
  1669. endian = base;
  1670. base = 10;
  1671. }
  1672. this._init(number || 0, base || 10, endian || 'be');
  1673. }
  1674. }
  1675. if (typeof module === 'object') {
  1676. module.exports = BN;
  1677. } else {
  1678. exports.BN = BN;
  1679. }
  1680. BN.BN = BN;
  1681. BN.wordSize = 26;
  1682. var Buffer;
  1683. try {
  1684. Buffer = require('buf' + 'fer').Buffer;
  1685. } catch (e) {
  1686. }
  1687. BN.isBN = function isBN (num) {
  1688. return num !== null && typeof num === 'object' &&
  1689. num.constructor.name === 'BN' && Array.isArray(num.words);
  1690. };
  1691. BN.max = function max (left, right) {
  1692. if (left.cmp(right) > 0) return left;
  1693. return right;
  1694. };
  1695. BN.min = function min (left, right) {
  1696. if (left.cmp(right) < 0) return left;
  1697. return right;
  1698. };
  1699. BN.prototype._init = function init (number, base, endian) {
  1700. if (typeof number === 'number') {
  1701. return this._initNumber(number, base, endian);
  1702. }
  1703. if (typeof number === 'object') {
  1704. return this._initArray(number, base, endian);
  1705. }
  1706. if (base === 'hex') {
  1707. base = 16;
  1708. }
  1709. assert(base === (base | 0) && base >= 2 && base <= 36);
  1710. number = number.toString().replace(/\s+/g, '');
  1711. var start = 0;
  1712. if (number[0] === '-') {
  1713. start++;
  1714. }
  1715. if (base === 16) {
  1716. this._parseHex(number, start);
  1717. } else {
  1718. this._parseBase(number, base, start);
  1719. }
  1720. if (number[0] === '-') {
  1721. this.negative = 1;
  1722. }
  1723. this.strip();
  1724. if (endian !== 'le') return;
  1725. this._initArray(this.toArray(), base, endian);
  1726. };
  1727. BN.prototype._initNumber = function _initNumber (number, base, endian) {
  1728. if (number < 0) {
  1729. this.negative = 1;
  1730. number = -number;
  1731. }
  1732. if (number < 0x4000000) {
  1733. this.words = [ number & 0x3ffffff ];
  1734. this.length = 1;
  1735. } else if (number < 0x10000000000000) {
  1736. this.words = [
  1737. number & 0x3ffffff,
  1738. (number / 0x4000000) & 0x3ffffff
  1739. ];
  1740. this.length = 2;
  1741. } else {
  1742. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  1743. this.words = [
  1744. number & 0x3ffffff,
  1745. (number / 0x4000000) & 0x3ffffff,
  1746. 1
  1747. ];
  1748. this.length = 3;
  1749. }
  1750. if (endian !== 'le') return;
  1751. // Reverse the bytes
  1752. this._initArray(this.toArray(), base, endian);
  1753. };
  1754. BN.prototype._initArray = function _initArray (number, base, endian) {
  1755. // Perhaps a Uint8Array
  1756. assert(typeof number.length === 'number');
  1757. if (number.length <= 0) {
  1758. this.words = [ 0 ];
  1759. this.length = 1;
  1760. return this;
  1761. }
  1762. this.length = Math.ceil(number.length / 3);
  1763. this.words = new Array(this.length);
  1764. for (var i = 0; i < this.length; i++) {
  1765. this.words[i] = 0;
  1766. }
  1767. var j, w;
  1768. var off = 0;
  1769. if (endian === 'be') {
  1770. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  1771. w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
  1772. this.words[j] |= (w << off) & 0x3ffffff;
  1773. this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
  1774. off += 24;
  1775. if (off >= 26) {
  1776. off -= 26;
  1777. j++;
  1778. }
  1779. }
  1780. } else if (endian === 'le') {
  1781. for (i = 0, j = 0; i < number.length; i += 3) {
  1782. w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
  1783. this.words[j] |= (w << off) & 0x3ffffff;
  1784. this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
  1785. off += 24;
  1786. if (off >= 26) {
  1787. off -= 26;
  1788. j++;
  1789. }
  1790. }
  1791. }
  1792. return this.strip();
  1793. };
  1794. function parseHex (str, start, end) {
  1795. var r = 0;
  1796. var len = Math.min(str.length, end);
  1797. for (var i = start; i < len; i++) {
  1798. var c = str.charCodeAt(i) - 48;
  1799. r <<= 4;
  1800. // 'a' - 'f'
  1801. if (c >= 49 && c <= 54) {
  1802. r |= c - 49 + 0xa;
  1803. // 'A' - 'F'
  1804. } else if (c >= 17 && c <= 22) {
  1805. r |= c - 17 + 0xa;
  1806. // '0' - '9'
  1807. } else {
  1808. r |= c & 0xf;
  1809. }
  1810. }
  1811. return r;
  1812. }
  1813. BN.prototype._parseHex = function _parseHex (number, start) {
  1814. // Create possibly bigger array to ensure that it fits the number
  1815. this.length = Math.ceil((number.length - start) / 6);
  1816. this.words = new Array(this.length);
  1817. for (var i = 0; i < this.length; i++) {
  1818. this.words[i] = 0;
  1819. }
  1820. var j, w;
  1821. // Scan 24-bit chunks and add them to the number
  1822. var off = 0;
  1823. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  1824. w = parseHex(number, i, i + 6);
  1825. this.words[j] |= (w << off) & 0x3ffffff;
  1826. // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  1827. this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
  1828. off += 24;
  1829. if (off >= 26) {
  1830. off -= 26;
  1831. j++;
  1832. }
  1833. }
  1834. if (i + 6 !== start) {
  1835. w = parseHex(number, start, i + 6);
  1836. this.words[j] |= (w << off) & 0x3ffffff;
  1837. this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
  1838. }
  1839. this.strip();
  1840. };
  1841. function parseBase (str, start, end, mul) {
  1842. var r = 0;
  1843. var len = Math.min(str.length, end);
  1844. for (var i = start; i < len; i++) {
  1845. var c = str.charCodeAt(i) - 48;
  1846. r *= mul;
  1847. // 'a'
  1848. if (c >= 49) {
  1849. r += c - 49 + 0xa;
  1850. // 'A'
  1851. } else if (c >= 17) {
  1852. r += c - 17 + 0xa;
  1853. // '0' - '9'
  1854. } else {
  1855. r += c;
  1856. }
  1857. }
  1858. return r;
  1859. }
  1860. BN.prototype._parseBase = function _parseBase (number, base, start) {
  1861. // Initialize as zero
  1862. this.words = [ 0 ];
  1863. this.length = 1;
  1864. // Find length of limb in base
  1865. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  1866. limbLen++;
  1867. }
  1868. limbLen--;
  1869. limbPow = (limbPow / base) | 0;
  1870. var total = number.length - start;
  1871. var mod = total % limbLen;
  1872. var end = Math.min(total, total - mod) + start;
  1873. var word = 0;
  1874. for (var i = start; i < end; i += limbLen) {
  1875. word = parseBase(number, i, i + limbLen, base);
  1876. this.imuln(limbPow);
  1877. if (this.words[0] + word < 0x4000000) {
  1878. this.words[0] += word;
  1879. } else {
  1880. this._iaddn(word);
  1881. }
  1882. }
  1883. if (mod !== 0) {
  1884. var pow = 1;
  1885. word = parseBase(number, i, number.length, base);
  1886. for (i = 0; i < mod; i++) {
  1887. pow *= base;
  1888. }
  1889. this.imuln(pow);
  1890. if (this.words[0] + word < 0x4000000) {
  1891. this.words[0] += word;
  1892. } else {
  1893. this._iaddn(word);
  1894. }
  1895. }
  1896. };
  1897. BN.prototype.copy = function copy (dest) {
  1898. dest.words = new Array(this.length);
  1899. for (var i = 0; i < this.length; i++) {
  1900. dest.words[i] = this.words[i];
  1901. }
  1902. dest.length = this.length;
  1903. dest.negative = this.negative;
  1904. dest.red = this.red;
  1905. };
  1906. BN.prototype.clone = function clone () {
  1907. var r = new BN(null);
  1908. this.copy(r);
  1909. return r;
  1910. };
  1911. BN.prototype._expand = function _expand (size) {
  1912. while (this.length < size) {
  1913. this.words[this.length++] = 0;
  1914. }
  1915. return this;
  1916. };
  1917. // Remove leading `0` from `this`
  1918. BN.prototype.strip = function strip () {
  1919. while (this.length > 1 && this.words[this.length - 1] === 0) {
  1920. this.length--;
  1921. }
  1922. return this._normSign();
  1923. };
  1924. BN.prototype._normSign = function _normSign () {
  1925. // -0 = 0
  1926. if (this.length === 1 && this.words[0] === 0) {
  1927. this.negative = 0;
  1928. }
  1929. return this;
  1930. };
  1931. BN.prototype.inspect = function inspect () {
  1932. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  1933. };
  1934. /*
  1935. var zeros = [];
  1936. var groupSizes = [];
  1937. var groupBases = [];
  1938. var s = '';
  1939. var i = -1;
  1940. while (++i < BN.wordSize) {
  1941. zeros[i] = s;
  1942. s += '0';
  1943. }
  1944. groupSizes[0] = 0;
  1945. groupSizes[1] = 0;
  1946. groupBases[0] = 0;
  1947. groupBases[1] = 0;
  1948. var base = 2 - 1;
  1949. while (++base < 36 + 1) {
  1950. var groupSize = 0;
  1951. var groupBase = 1;
  1952. while (groupBase < (1 << BN.wordSize) / base) {
  1953. groupBase *= base;
  1954. groupSize += 1;
  1955. }
  1956. groupSizes[base] = groupSize;
  1957. groupBases[base] = groupBase;
  1958. }
  1959. */
  1960. var zeros = [
  1961. '',
  1962. '0',
  1963. '00',
  1964. '000',
  1965. '0000',
  1966. '00000',
  1967. '000000',
  1968. '0000000',
  1969. '00000000',
  1970. '000000000',
  1971. '0000000000',
  1972. '00000000000',
  1973. '000000000000',
  1974. '0000000000000',
  1975. '00000000000000',
  1976. '000000000000000',
  1977. '0000000000000000',
  1978. '00000000000000000',
  1979. '000000000000000000',
  1980. '0000000000000000000',
  1981. '00000000000000000000',
  1982. '000000000000000000000',
  1983. '0000000000000000000000',
  1984. '00000000000000000000000',
  1985. '000000000000000000000000',
  1986. '0000000000000000000000000'
  1987. ];
  1988. var groupSizes = [
  1989. 0, 0,
  1990. 25, 16, 12, 11, 10, 9, 8,
  1991. 8, 7, 7, 7, 7, 6, 6,
  1992. 6, 6, 6, 6, 6, 5, 5,
  1993. 5, 5, 5, 5, 5, 5, 5,
  1994. 5, 5, 5, 5, 5, 5, 5
  1995. ];
  1996. var groupBases = [
  1997. 0, 0,
  1998. 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
  1999. 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
  2000. 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
  2001. 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
  2002. 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
  2003. ];
  2004. BN.prototype.toString = function toString (base, padding) {
  2005. base = base || 10;
  2006. padding = padding | 0 || 1;
  2007. var out;
  2008. if (base === 16 || base === 'hex') {
  2009. out = '';
  2010. var off = 0;
  2011. var carry = 0;
  2012. for (var i = 0; i < this.length; i++) {
  2013. var w = this.words[i];
  2014. var word = (((w << off) | carry) & 0xffffff).toString(16);
  2015. carry = (w >>> (24 - off)) & 0xffffff;
  2016. if (carry !== 0 || i !== this.length - 1) {
  2017. out = zeros[6 - word.length] + word + out;
  2018. } else {
  2019. out = word + out;
  2020. }
  2021. off += 2;
  2022. if (off >= 26) {
  2023. off -= 26;
  2024. i--;
  2025. }
  2026. }
  2027. if (carry !== 0) {
  2028. out = carry.toString(16) + out;
  2029. }
  2030. while (out.length % padding !== 0) {
  2031. out = '0' + out;
  2032. }
  2033. if (this.negative !== 0) {
  2034. out = '-' + out;
  2035. }
  2036. return out;
  2037. }
  2038. if (base === (base | 0) && base >= 2 && base <= 36) {
  2039. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  2040. var groupSize = groupSizes[base];
  2041. // var groupBase = Math.pow(base, groupSize);
  2042. var groupBase = groupBases[base];
  2043. out = '';
  2044. var c = this.clone();
  2045. c.negative = 0;
  2046. while (!c.isZero()) {
  2047. var r = c.modn(groupBase).toString(base);
  2048. c = c.idivn(groupBase);
  2049. if (!c.isZero()) {
  2050. out = zeros[groupSize - r.length] + r + out;
  2051. } else {
  2052. out = r + out;
  2053. }
  2054. }
  2055. if (this.isZero()) {
  2056. out = '0' + out;
  2057. }
  2058. while (out.length % padding !== 0) {
  2059. out = '0' + out;
  2060. }
  2061. if (this.negative !== 0) {
  2062. out = '-' + out;
  2063. }
  2064. return out;
  2065. }
  2066. assert(false, 'Base should be between 2 and 36');
  2067. };
  2068. BN.prototype.toNumber = function toNumber () {
  2069. var ret = this.words[0];
  2070. if (this.length === 2) {
  2071. ret += this.words[1] * 0x4000000;
  2072. } else if (this.length === 3 && this.words[2] === 0x01) {
  2073. // NOTE: at this stage it is known that the top bit is set
  2074. ret += 0x10000000000000 + (this.words[1] * 0x4000000);
  2075. } else if (this.length > 2) {
  2076. assert(false, 'Number can only safely store up to 53 bits');
  2077. }
  2078. return (this.negative !== 0) ? -ret : ret;
  2079. };
  2080. BN.prototype.toJSON = function toJSON () {
  2081. return this.toString(16);
  2082. };
  2083. BN.prototype.toBuffer = function toBuffer (endian, length) {
  2084. assert(typeof Buffer !== 'undefined');
  2085. return this.toArrayLike(Buffer, endian, length);
  2086. };
  2087. BN.prototype.toArray = function toArray (endian, length) {
  2088. return this.toArrayLike(Array, endian, length);
  2089. };
  2090. BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
  2091. var byteLength = this.byteLength();
  2092. var reqLength = length || Math.max(1, byteLength);
  2093. assert(byteLength <= reqLength, 'byte array longer than desired length');
  2094. assert(reqLength > 0, 'Requested array length <= 0');
  2095. this.strip();
  2096. var littleEndian = endian === 'le';
  2097. var res = new ArrayType(reqLength);
  2098. var b, i;
  2099. var q = this.clone();
  2100. if (!littleEndian) {
  2101. // Assume big-endian
  2102. for (i = 0; i < reqLength - byteLength; i++) {
  2103. res[i] = 0;
  2104. }
  2105. for (i = 0; !q.isZero(); i++) {
  2106. b = q.andln(0xff);
  2107. q.iushrn(8);
  2108. res[reqLength - i - 1] = b;
  2109. }
  2110. } else {
  2111. for (i = 0; !q.isZero(); i++) {
  2112. b = q.andln(0xff);
  2113. q.iushrn(8);
  2114. res[i] = b;
  2115. }
  2116. for (; i < reqLength; i++) {
  2117. res[i] = 0;
  2118. }
  2119. }
  2120. return res;
  2121. };
  2122. if (Math.clz32) {
  2123. BN.prototype._countBits = function _countBits (w) {
  2124. return 32 - Math.clz32(w);
  2125. };
  2126. } else {
  2127. BN.prototype._countBits = function _countBits (w) {
  2128. var t = w;
  2129. var r = 0;
  2130. if (t >= 0x1000) {
  2131. r += 13;
  2132. t >>>= 13;
  2133. }
  2134. if (t >= 0x40) {
  2135. r += 7;
  2136. t >>>= 7;
  2137. }
  2138. if (t >= 0x8) {
  2139. r += 4;
  2140. t >>>= 4;
  2141. }
  2142. if (t >= 0x02) {
  2143. r += 2;
  2144. t >>>= 2;
  2145. }
  2146. return r + t;
  2147. };
  2148. }
  2149. BN.prototype._zeroBits = function _zeroBits (w) {
  2150. // Short-cut
  2151. if (w === 0) return 26;
  2152. var t = w;
  2153. var r = 0;
  2154. if ((t & 0x1fff) === 0) {
  2155. r += 13;
  2156. t >>>= 13;
  2157. }
  2158. if ((t & 0x7f) === 0) {
  2159. r += 7;
  2160. t >>>= 7;
  2161. }
  2162. if ((t & 0xf) === 0) {
  2163. r += 4;
  2164. t >>>= 4;
  2165. }
  2166. if ((t & 0x3) === 0) {
  2167. r += 2;
  2168. t >>>= 2;
  2169. }
  2170. if ((t & 0x1) === 0) {
  2171. r++;
  2172. }
  2173. return r;
  2174. };
  2175. // Return number of used bits in a BN
  2176. BN.prototype.bitLength = function bitLength () {
  2177. var w = this.words[this.length - 1];
  2178. var hi = this._countBits(w);
  2179. return (this.length - 1) * 26 + hi;
  2180. };
  2181. function toBitArray (num) {
  2182. var w = new Array(num.bitLength());
  2183. for (var bit = 0; bit < w.length; bit++) {
  2184. var off = (bit / 26) | 0;
  2185. var wbit = bit % 26;
  2186. w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
  2187. }
  2188. return w;
  2189. }
  2190. // Number of trailing zero bits
  2191. BN.prototype.zeroBits = function zeroBits () {
  2192. if (this.isZero()) return 0;
  2193. var r = 0;
  2194. for (var i = 0; i < this.length; i++) {
  2195. var b = this._zeroBits(this.words[i]);
  2196. r += b;
  2197. if (b !== 26) break;
  2198. }
  2199. return r;
  2200. };
  2201. BN.prototype.byteLength = function byteLength () {
  2202. return Math.ceil(this.bitLength() / 8);
  2203. };
  2204. BN.prototype.toTwos = function toTwos (width) {
  2205. if (this.negative !== 0) {
  2206. return this.abs().inotn(width).iaddn(1);
  2207. }
  2208. return this.clone();
  2209. };
  2210. BN.prototype.fromTwos = function fromTwos (width) {
  2211. if (this.testn(width - 1)) {
  2212. return this.notn(width).iaddn(1).ineg();
  2213. }
  2214. return this.clone();
  2215. };
  2216. BN.prototype.isNeg = function isNeg () {
  2217. return this.negative !== 0;
  2218. };
  2219. // Return negative clone of `this`
  2220. BN.prototype.neg = function neg () {
  2221. return this.clone().ineg();
  2222. };
  2223. BN.prototype.ineg = function ineg () {
  2224. if (!this.isZero()) {
  2225. this.negative ^= 1;
  2226. }
  2227. return this;
  2228. };
  2229. // Or `num` with `this` in-place
  2230. BN.prototype.iuor = function iuor (num) {
  2231. while (this.length < num.length) {
  2232. this.words[this.length++] = 0;
  2233. }
  2234. for (var i = 0; i < num.length; i++) {
  2235. this.words[i] = this.words[i] | num.words[i];
  2236. }
  2237. return this.strip();
  2238. };
  2239. BN.prototype.ior = function ior (num) {
  2240. assert((this.negative | num.negative) === 0);
  2241. return this.iuor(num);
  2242. };
  2243. // Or `num` with `this`
  2244. BN.prototype.or = function or (num) {
  2245. if (this.length > num.length) return this.clone().ior(num);
  2246. return num.clone().ior(this);
  2247. };
  2248. BN.prototype.uor = function uor (num) {
  2249. if (this.length > num.length) return this.clone().iuor(num);
  2250. return num.clone().iuor(this);
  2251. };
  2252. // And `num` with `this` in-place
  2253. BN.prototype.iuand = function iuand (num) {
  2254. // b = min-length(num, this)
  2255. var b;
  2256. if (this.length > num.length) {
  2257. b = num;
  2258. } else {
  2259. b = this;
  2260. }
  2261. for (var i = 0; i < b.length; i++) {
  2262. this.words[i] = this.words[i] & num.words[i];
  2263. }
  2264. this.length = b.length;
  2265. return this.strip();
  2266. };
  2267. BN.prototype.iand = function iand (num) {
  2268. assert((this.negative | num.negative) === 0);
  2269. return this.iuand(num);
  2270. };
  2271. // And `num` with `this`
  2272. BN.prototype.and = function and (num) {
  2273. if (this.length > num.length) return this.clone().iand(num);
  2274. return num.clone().iand(this);
  2275. };
  2276. BN.prototype.uand = function uand (num) {
  2277. if (this.length > num.length) return this.clone().iuand(num);
  2278. return num.clone().iuand(this);
  2279. };
  2280. // Xor `num` with `this` in-place
  2281. BN.prototype.iuxor = function iuxor (num) {
  2282. // a.length > b.length
  2283. var a;
  2284. var b;
  2285. if (this.length > num.length) {
  2286. a = this;
  2287. b = num;
  2288. } else {
  2289. a = num;
  2290. b = this;
  2291. }
  2292. for (var i = 0; i < b.length; i++) {
  2293. this.words[i] = a.words[i] ^ b.words[i];
  2294. }
  2295. if (this !== a) {
  2296. for (; i < a.length; i++) {
  2297. this.words[i] = a.words[i];
  2298. }
  2299. }
  2300. this.length = a.length;
  2301. return this.strip();
  2302. };
  2303. BN.prototype.ixor = function ixor (num) {
  2304. assert((this.negative | num.negative) === 0);
  2305. return this.iuxor(num);
  2306. };
  2307. // Xor `num` with `this`
  2308. BN.prototype.xor = function xor (num) {
  2309. if (this.length > num.length) return this.clone().ixor(num);
  2310. return num.clone().ixor(this);
  2311. };
  2312. BN.prototype.uxor = function uxor (num) {
  2313. if (this.length > num.length) return this.clone().iuxor(num);
  2314. return num.clone().iuxor(this);
  2315. };
  2316. // Not ``this`` with ``width`` bitwidth
  2317. BN.prototype.inotn = function inotn (width) {
  2318. assert(typeof width === 'number' && width >= 0);
  2319. var bytesNeeded = Math.ceil(width / 26) | 0;
  2320. var bitsLeft = width % 26;
  2321. // Extend the buffer with leading zeroes
  2322. this._expand(bytesNeeded);
  2323. if (bitsLeft > 0) {
  2324. bytesNeeded--;
  2325. }
  2326. // Handle complete words
  2327. for (var i = 0; i < bytesNeeded; i++) {
  2328. this.words[i] = ~this.words[i] & 0x3ffffff;
  2329. }
  2330. // Handle the residue
  2331. if (bitsLeft > 0) {
  2332. this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
  2333. }
  2334. // And remove leading zeroes
  2335. return this.strip();
  2336. };
  2337. BN.prototype.notn = function notn (width) {
  2338. return this.clone().inotn(width);
  2339. };
  2340. // Set `bit` of `this`
  2341. BN.prototype.setn = function setn (bit, val) {
  2342. assert(typeof bit === 'number' && bit >= 0);
  2343. var off = (bit / 26) | 0;
  2344. var wbit = bit % 26;
  2345. this._expand(off + 1);
  2346. if (val) {
  2347. this.words[off] = this.words[off] | (1 << wbit);
  2348. } else {
  2349. this.words[off] = this.words[off] & ~(1 << wbit);
  2350. }
  2351. return this.strip();
  2352. };
  2353. // Add `num` to `this` in-place
  2354. BN.prototype.iadd = function iadd (num) {
  2355. var r;
  2356. // negative + positive
  2357. if (this.negative !== 0 && num.negative === 0) {
  2358. this.negative = 0;
  2359. r = this.isub(num);
  2360. this.negative ^= 1;
  2361. return this._normSign();
  2362. // positive + negative
  2363. } else if (this.negative === 0 && num.negative !== 0) {
  2364. num.negative = 0;
  2365. r = this.isub(num);
  2366. num.negative = 1;
  2367. return r._normSign();
  2368. }
  2369. // a.length > b.length
  2370. var a, b;
  2371. if (this.length > num.length) {
  2372. a = this;
  2373. b = num;
  2374. } else {
  2375. a = num;
  2376. b = this;
  2377. }
  2378. var carry = 0;
  2379. for (var i = 0; i < b.length; i++) {
  2380. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  2381. this.words[i] = r & 0x3ffffff;
  2382. carry = r >>> 26;
  2383. }
  2384. for (; carry !== 0 && i < a.length; i++) {
  2385. r = (a.words[i] | 0) + carry;
  2386. this.words[i] = r & 0x3ffffff;
  2387. carry = r >>> 26;
  2388. }
  2389. this.length = a.length;
  2390. if (carry !== 0) {
  2391. this.words[this.length] = carry;
  2392. this.length++;
  2393. // Copy the rest of the words
  2394. } else if (a !== this) {
  2395. for (; i < a.length; i++) {
  2396. this.words[i] = a.words[i];
  2397. }
  2398. }
  2399. return this;
  2400. };
  2401. // Add `num` to `this`
  2402. BN.prototype.add = function add (num) {
  2403. var res;
  2404. if (num.negative !== 0 && this.negative === 0) {
  2405. num.negative = 0;
  2406. res = this.sub(num);
  2407. num.negative ^= 1;
  2408. return res;
  2409. } else if (num.negative === 0 && this.negative !== 0) {
  2410. this.negative = 0;
  2411. res = num.sub(this);
  2412. this.negative = 1;
  2413. return res;
  2414. }
  2415. if (this.length > num.length) return this.clone().iadd(num);
  2416. return num.clone().iadd(this);
  2417. };
  2418. // Subtract `num` from `this` in-place
  2419. BN.prototype.isub = function isub (num) {
  2420. // this - (-num) = this + num
  2421. if (num.negative !== 0) {
  2422. num.negative = 0;
  2423. var r = this.iadd(num);
  2424. num.negative = 1;
  2425. return r._normSign();
  2426. // -this - num = -(this + num)
  2427. } else if (this.negative !== 0) {
  2428. this.negative = 0;
  2429. this.iadd(num);
  2430. this.negative = 1;
  2431. return this._normSign();
  2432. }
  2433. // At this point both numbers are positive
  2434. var cmp = this.cmp(num);
  2435. // Optimization - zeroify
  2436. if (cmp === 0) {
  2437. this.negative = 0;
  2438. this.length = 1;
  2439. this.words[0] = 0;
  2440. return this;
  2441. }
  2442. // a > b
  2443. var a, b;
  2444. if (cmp > 0) {
  2445. a = this;
  2446. b = num;
  2447. } else {
  2448. a = num;
  2449. b = this;
  2450. }
  2451. var carry = 0;
  2452. for (var i = 0; i < b.length; i++) {
  2453. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  2454. carry = r >> 26;
  2455. this.words[i] = r & 0x3ffffff;
  2456. }
  2457. for (; carry !== 0 && i < a.length; i++) {
  2458. r = (a.words[i] | 0) + carry;
  2459. carry = r >> 26;
  2460. this.words[i] = r & 0x3ffffff;
  2461. }
  2462. // Copy rest of the words
  2463. if (carry === 0 && i < a.length && a !== this) {
  2464. for (; i < a.length; i++) {
  2465. this.words[i] = a.words[i];
  2466. }
  2467. }
  2468. this.length = Math.max(this.length, i);
  2469. if (a !== this) {
  2470. this.negative = 1;
  2471. }
  2472. return this.strip();
  2473. };
  2474. // Subtract `num` from `this`
  2475. BN.prototype.sub = function sub (num) {
  2476. return this.clone().isub(num);
  2477. };
  2478. function smallMulTo (self, num, out) {
  2479. out.negative = num.negative ^ self.negative;
  2480. var len = (self.length + num.length) | 0;
  2481. out.length = len;
  2482. len = (len - 1) | 0;
  2483. // Peel one iteration (compiler can't do it, because of code complexity)
  2484. var a = self.words[0] | 0;
  2485. var b = num.words[0] | 0;
  2486. var r = a * b;
  2487. var lo = r & 0x3ffffff;
  2488. var carry = (r / 0x4000000) | 0;
  2489. out.words[0] = lo;
  2490. for (var k = 1; k < len; k++) {
  2491. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  2492. // note that ncarry could be >= 0x3ffffff
  2493. var ncarry = carry >>> 26;
  2494. var rword = carry & 0x3ffffff;
  2495. var maxJ = Math.min(k, num.length - 1);
  2496. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  2497. var i = (k - j) | 0;
  2498. a = self.words[i] | 0;
  2499. b = num.words[j] | 0;
  2500. r = a * b + rword;
  2501. ncarry += (r / 0x4000000) | 0;
  2502. rword = r & 0x3ffffff;
  2503. }
  2504. out.words[k] = rword | 0;
  2505. carry = ncarry | 0;
  2506. }
  2507. if (carry !== 0) {
  2508. out.words[k] = carry | 0;
  2509. } else {
  2510. out.length--;
  2511. }
  2512. return out.strip();
  2513. }
  2514. // TODO(indutny): it may be reasonable to omit it for users who don't need
  2515. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  2516. // multiplication (like elliptic secp256k1).
  2517. var comb10MulTo = function comb10MulTo (self, num, out) {
  2518. var a = self.words;
  2519. var b = num.words;
  2520. var o = out.words;
  2521. var c = 0;
  2522. var lo;
  2523. var mid;
  2524. var hi;
  2525. var a0 = a[0] | 0;
  2526. var al0 = a0 & 0x1fff;
  2527. var ah0 = a0 >>> 13;
  2528. var a1 = a[1] | 0;
  2529. var al1 = a1 & 0x1fff;
  2530. var ah1 = a1 >>> 13;
  2531. var a2 = a[2] | 0;
  2532. var al2 = a2 & 0x1fff;
  2533. var ah2 = a2 >>> 13;
  2534. var a3 = a[3] | 0;
  2535. var al3 = a3 & 0x1fff;
  2536. var ah3 = a3 >>> 13;
  2537. var a4 = a[4] | 0;
  2538. var al4 = a4 & 0x1fff;
  2539. var ah4 = a4 >>> 13;
  2540. var a5 = a[5] | 0;
  2541. var al5 = a5 & 0x1fff;
  2542. var ah5 = a5 >>> 13;
  2543. var a6 = a[6] | 0;
  2544. var al6 = a6 & 0x1fff;
  2545. var ah6 = a6 >>> 13;
  2546. var a7 = a[7] | 0;
  2547. var al7 = a7 & 0x1fff;
  2548. var ah7 = a7 >>> 13;
  2549. var a8 = a[8] | 0;
  2550. var al8 = a8 & 0x1fff;
  2551. var ah8 = a8 >>> 13;
  2552. var a9 = a[9] | 0;
  2553. var al9 = a9 & 0x1fff;
  2554. var ah9 = a9 >>> 13;
  2555. var b0 = b[0] | 0;
  2556. var bl0 = b0 & 0x1fff;
  2557. var bh0 = b0 >>> 13;
  2558. var b1 = b[1] | 0;
  2559. var bl1 = b1 & 0x1fff;
  2560. var bh1 = b1 >>> 13;
  2561. var b2 = b[2] | 0;
  2562. var bl2 = b2 & 0x1fff;
  2563. var bh2 = b2 >>> 13;
  2564. var b3 = b[3] | 0;
  2565. var bl3 = b3 & 0x1fff;
  2566. var bh3 = b3 >>> 13;
  2567. var b4 = b[4] | 0;
  2568. var bl4 = b4 & 0x1fff;
  2569. var bh4 = b4 >>> 13;
  2570. var b5 = b[5] | 0;
  2571. var bl5 = b5 & 0x1fff;
  2572. var bh5 = b5 >>> 13;
  2573. var b6 = b[6] | 0;
  2574. var bl6 = b6 & 0x1fff;
  2575. var bh6 = b6 >>> 13;
  2576. var b7 = b[7] | 0;
  2577. var bl7 = b7 & 0x1fff;
  2578. var bh7 = b7 >>> 13;
  2579. var b8 = b[8] | 0;
  2580. var bl8 = b8 & 0x1fff;
  2581. var bh8 = b8 >>> 13;
  2582. var b9 = b[9] | 0;
  2583. var bl9 = b9 & 0x1fff;
  2584. var bh9 = b9 >>> 13;
  2585. out.negative = self.negative ^ num.negative;
  2586. out.length = 19;
  2587. /* k = 0 */
  2588. lo = Math.imul(al0, bl0);
  2589. mid = Math.imul(al0, bh0);
  2590. mid += Math.imul(ah0, bl0);
  2591. hi = Math.imul(ah0, bh0);
  2592. var w0 = c + lo + ((mid & 0x1fff) << 13);
  2593. c = hi + (mid >>> 13) + (w0 >>> 26);
  2594. w0 &= 0x3ffffff;
  2595. /* k = 1 */
  2596. lo = Math.imul(al1, bl0);
  2597. mid = Math.imul(al1, bh0);
  2598. mid += Math.imul(ah1, bl0);
  2599. hi = Math.imul(ah1, bh0);
  2600. lo += Math.imul(al0, bl1);
  2601. mid += Math.imul(al0, bh1);
  2602. mid += Math.imul(ah0, bl1);
  2603. hi += Math.imul(ah0, bh1);
  2604. var w1 = c + lo + ((mid & 0x1fff) << 13);
  2605. c = hi + (mid >>> 13) + (w1 >>> 26);
  2606. w1 &= 0x3ffffff;
  2607. /* k = 2 */
  2608. lo = Math.imul(al2, bl0);
  2609. mid = Math.imul(al2, bh0);
  2610. mid += Math.imul(ah2, bl0);
  2611. hi = Math.imul(ah2, bh0);
  2612. lo += Math.imul(al1, bl1);
  2613. mid += Math.imul(al1, bh1);
  2614. mid += Math.imul(ah1, bl1);
  2615. hi += Math.imul(ah1, bh1);
  2616. lo += Math.imul(al0, bl2);
  2617. mid += Math.imul(al0, bh2);
  2618. mid += Math.imul(ah0, bl2);
  2619. hi += Math.imul(ah0, bh2);
  2620. var w2 = c + lo + ((mid & 0x1fff) << 13);
  2621. c = hi + (mid >>> 13) + (w2 >>> 26);
  2622. w2 &= 0x3ffffff;
  2623. /* k = 3 */
  2624. lo = Math.imul(al3, bl0);
  2625. mid = Math.imul(al3, bh0);
  2626. mid += Math.imul(ah3, bl0);
  2627. hi = Math.imul(ah3, bh0);
  2628. lo += Math.imul(al2, bl1);
  2629. mid += Math.imul(al2, bh1);
  2630. mid += Math.imul(ah2, bl1);
  2631. hi += Math.imul(ah2, bh1);
  2632. lo += Math.imul(al1, bl2);
  2633. mid += Math.imul(al1, bh2);
  2634. mid += Math.imul(ah1, bl2);
  2635. hi += Math.imul(ah1, bh2);
  2636. lo += Math.imul(al0, bl3);
  2637. mid += Math.imul(al0, bh3);
  2638. mid += Math.imul(ah0, bl3);
  2639. hi += Math.imul(ah0, bh3);
  2640. var w3 = c + lo + ((mid & 0x1fff) << 13);
  2641. c = hi + (mid >>> 13) + (w3 >>> 26);
  2642. w3 &= 0x3ffffff;
  2643. /* k = 4 */
  2644. lo = Math.imul(al4, bl0);
  2645. mid = Math.imul(al4, bh0);
  2646. mid += Math.imul(ah4, bl0);
  2647. hi = Math.imul(ah4, bh0);
  2648. lo += Math.imul(al3, bl1);
  2649. mid += Math.imul(al3, bh1);
  2650. mid += Math.imul(ah3, bl1);
  2651. hi += Math.imul(ah3, bh1);
  2652. lo += Math.imul(al2, bl2);
  2653. mid += Math.imul(al2, bh2);
  2654. mid += Math.imul(ah2, bl2);
  2655. hi += Math.imul(ah2, bh2);
  2656. lo += Math.imul(al1, bl3);
  2657. mid += Math.imul(al1, bh3);
  2658. mid += Math.imul(ah1, bl3);
  2659. hi += Math.imul(ah1, bh3);
  2660. lo += Math.imul(al0, bl4);
  2661. mid += Math.imul(al0, bh4);
  2662. mid += Math.imul(ah0, bl4);
  2663. hi += Math.imul(ah0, bh4);
  2664. var w4 = c + lo + ((mid & 0x1fff) << 13);
  2665. c = hi + (mid >>> 13) + (w4 >>> 26);
  2666. w4 &= 0x3ffffff;
  2667. /* k = 5 */
  2668. lo = Math.imul(al5, bl0);
  2669. mid = Math.imul(al5, bh0);
  2670. mid += Math.imul(ah5, bl0);
  2671. hi = Math.imul(ah5, bh0);
  2672. lo += Math.imul(al4, bl1);
  2673. mid += Math.imul(al4, bh1);
  2674. mid += Math.imul(ah4, bl1);
  2675. hi += Math.imul(ah4, bh1);
  2676. lo += Math.imul(al3, bl2);
  2677. mid += Math.imul(al3, bh2);
  2678. mid += Math.imul(ah3, bl2);
  2679. hi += Math.imul(ah3, bh2);
  2680. lo += Math.imul(al2, bl3);
  2681. mid += Math.imul(al2, bh3);
  2682. mid += Math.imul(ah2, bl3);
  2683. hi += Math.imul(ah2, bh3);
  2684. lo += Math.imul(al1, bl4);
  2685. mid += Math.imul(al1, bh4);
  2686. mid += Math.imul(ah1, bl4);
  2687. hi += Math.imul(ah1, bh4);
  2688. lo += Math.imul(al0, bl5);
  2689. mid += Math.imul(al0, bh5);
  2690. mid += Math.imul(ah0, bl5);
  2691. hi += Math.imul(ah0, bh5);
  2692. var w5 = c + lo + ((mid & 0x1fff) << 13);
  2693. c = hi + (mid >>> 13) + (w5 >>> 26);
  2694. w5 &= 0x3ffffff;
  2695. /* k = 6 */
  2696. lo = Math.imul(al6, bl0);
  2697. mid = Math.imul(al6, bh0);
  2698. mid += Math.imul(ah6, bl0);
  2699. hi = Math.imul(ah6, bh0);
  2700. lo += Math.imul(al5, bl1);
  2701. mid += Math.imul(al5, bh1);
  2702. mid += Math.imul(ah5, bl1);
  2703. hi += Math.imul(ah5, bh1);
  2704. lo += Math.imul(al4, bl2);
  2705. mid += Math.imul(al4, bh2);
  2706. mid += Math.imul(ah4, bl2);
  2707. hi += Math.imul(ah4, bh2);
  2708. lo += Math.imul(al3, bl3);
  2709. mid += Math.imul(al3, bh3);
  2710. mid += Math.imul(ah3, bl3);
  2711. hi += Math.imul(ah3, bh3);
  2712. lo += Math.imul(al2, bl4);
  2713. mid += Math.imul(al2, bh4);
  2714. mid += Math.imul(ah2, bl4);
  2715. hi += Math.imul(ah2, bh4);
  2716. lo += Math.imul(al1, bl5);
  2717. mid += Math.imul(al1, bh5);
  2718. mid += Math.imul(ah1, bl5);
  2719. hi += Math.imul(ah1, bh5);
  2720. lo += Math.imul(al0, bl6);
  2721. mid += Math.imul(al0, bh6);
  2722. mid += Math.imul(ah0, bl6);
  2723. hi += Math.imul(ah0, bh6);
  2724. var w6 = c + lo + ((mid & 0x1fff) << 13);
  2725. c = hi + (mid >>> 13) + (w6 >>> 26);
  2726. w6 &= 0x3ffffff;
  2727. /* k = 7 */
  2728. lo = Math.imul(al7, bl0);
  2729. mid = Math.imul(al7, bh0);
  2730. mid += Math.imul(ah7, bl0);
  2731. hi = Math.imul(ah7, bh0);
  2732. lo += Math.imul(al6, bl1);
  2733. mid += Math.imul(al6, bh1);
  2734. mid += Math.imul(ah6, bl1);
  2735. hi += Math.imul(ah6, bh1);
  2736. lo += Math.imul(al5, bl2);
  2737. mid += Math.imul(al5, bh2);
  2738. mid += Math.imul(ah5, bl2);
  2739. hi += Math.imul(ah5, bh2);
  2740. lo += Math.imul(al4, bl3);
  2741. mid += Math.imul(al4, bh3);
  2742. mid += Math.imul(ah4, bl3);
  2743. hi += Math.imul(ah4, bh3);
  2744. lo += Math.imul(al3, bl4);
  2745. mid += Math.imul(al3, bh4);
  2746. mid += Math.imul(ah3, bl4);
  2747. hi += Math.imul(ah3, bh4);
  2748. lo += Math.imul(al2, bl5);
  2749. mid += Math.imul(al2, bh5);
  2750. mid += Math.imul(ah2, bl5);
  2751. hi += Math.imul(ah2, bh5);
  2752. lo += Math.imul(al1, bl6);
  2753. mid += Math.imul(al1, bh6);
  2754. mid += Math.imul(ah1, bl6);
  2755. hi += Math.imul(ah1, bh6);
  2756. lo += Math.imul(al0, bl7);
  2757. mid += Math.imul(al0, bh7);
  2758. mid += Math.imul(ah0, bl7);
  2759. hi += Math.imul(ah0, bh7);
  2760. var w7 = c + lo + ((mid & 0x1fff) << 13);
  2761. c = hi + (mid >>> 13) + (w7 >>> 26);
  2762. w7 &= 0x3ffffff;
  2763. /* k = 8 */
  2764. lo = Math.imul(al8, bl0);
  2765. mid = Math.imul(al8, bh0);
  2766. mid += Math.imul(ah8, bl0);
  2767. hi = Math.imul(ah8, bh0);
  2768. lo += Math.imul(al7, bl1);
  2769. mid += Math.imul(al7, bh1);
  2770. mid += Math.imul(ah7, bl1);
  2771. hi += Math.imul(ah7, bh1);
  2772. lo += Math.imul(al6, bl2);
  2773. mid += Math.imul(al6, bh2);
  2774. mid += Math.imul(ah6, bl2);
  2775. hi += Math.imul(ah6, bh2);
  2776. lo += Math.imul(al5, bl3);
  2777. mid += Math.imul(al5, bh3);
  2778. mid += Math.imul(ah5, bl3);
  2779. hi += Math.imul(ah5, bh3);
  2780. lo += Math.imul(al4, bl4);
  2781. mid += Math.imul(al4, bh4);
  2782. mid += Math.imul(ah4, bl4);
  2783. hi += Math.imul(ah4, bh4);
  2784. lo += Math.imul(al3, bl5);
  2785. mid += Math.imul(al3, bh5);
  2786. mid += Math.imul(ah3, bl5);
  2787. hi += Math.imul(ah3, bh5);
  2788. lo += Math.imul(al2, bl6);
  2789. mid += Math.imul(al2, bh6);
  2790. mid += Math.imul(ah2, bl6);
  2791. hi += Math.imul(ah2, bh6);
  2792. lo += Math.imul(al1, bl7);
  2793. mid += Math.imul(al1, bh7);
  2794. mid += Math.imul(ah1, bl7);
  2795. hi += Math.imul(ah1, bh7);
  2796. lo += Math.imul(al0, bl8);
  2797. mid += Math.imul(al0, bh8);
  2798. mid += Math.imul(ah0, bl8);
  2799. hi += Math.imul(ah0, bh8);
  2800. var w8 = c + lo + ((mid & 0x1fff) << 13);
  2801. c = hi + (mid >>> 13) + (w8 >>> 26);
  2802. w8 &= 0x3ffffff;
  2803. /* k = 9 */
  2804. lo = Math.imul(al9, bl0);
  2805. mid = Math.imul(al9, bh0);
  2806. mid += Math.imul(ah9, bl0);
  2807. hi = Math.imul(ah9, bh0);
  2808. lo += Math.imul(al8, bl1);
  2809. mid += Math.imul(al8, bh1);
  2810. mid += Math.imul(ah8, bl1);
  2811. hi += Math.imul(ah8, bh1);
  2812. lo += Math.imul(al7, bl2);
  2813. mid += Math.imul(al7, bh2);
  2814. mid += Math.imul(ah7, bl2);
  2815. hi += Math.imul(ah7, bh2);
  2816. lo += Math.imul(al6, bl3);
  2817. mid += Math.imul(al6, bh3);
  2818. mid += Math.imul(ah6, bl3);
  2819. hi += Math.imul(ah6, bh3);
  2820. lo += Math.imul(al5, bl4);
  2821. mid += Math.imul(al5, bh4);
  2822. mid += Math.imul(ah5, bl4);
  2823. hi += Math.imul(ah5, bh4);
  2824. lo += Math.imul(al4, bl5);
  2825. mid += Math.imul(al4, bh5);
  2826. mid += Math.imul(ah4, bl5);
  2827. hi += Math.imul(ah4, bh5);
  2828. lo += Math.imul(al3, bl6);
  2829. mid += Math.imul(al3, bh6);
  2830. mid += Math.imul(ah3, bl6);
  2831. hi += Math.imul(ah3, bh6);
  2832. lo += Math.imul(al2, bl7);
  2833. mid += Math.imul(al2, bh7);
  2834. mid += Math.imul(ah2, bl7);
  2835. hi += Math.imul(ah2, bh7);
  2836. lo += Math.imul(al1, bl8);
  2837. mid += Math.imul(al1, bh8);
  2838. mid += Math.imul(ah1, bl8);
  2839. hi += Math.imul(ah1, bh8);
  2840. lo += Math.imul(al0, bl9);
  2841. mid += Math.imul(al0, bh9);
  2842. mid += Math.imul(ah0, bl9);
  2843. hi += Math.imul(ah0, bh9);
  2844. var w9 = c + lo + ((mid & 0x1fff) << 13);
  2845. c = hi + (mid >>> 13) + (w9 >>> 26);
  2846. w9 &= 0x3ffffff;
  2847. /* k = 10 */
  2848. lo = Math.imul(al9, bl1);
  2849. mid = Math.imul(al9, bh1);
  2850. mid += Math.imul(ah9, bl1);
  2851. hi = Math.imul(ah9, bh1);
  2852. lo += Math.imul(al8, bl2);
  2853. mid += Math.imul(al8, bh2);
  2854. mid += Math.imul(ah8, bl2);
  2855. hi += Math.imul(ah8, bh2);
  2856. lo += Math.imul(al7, bl3);
  2857. mid += Math.imul(al7, bh3);
  2858. mid += Math.imul(ah7, bl3);
  2859. hi += Math.imul(ah7, bh3);
  2860. lo += Math.imul(al6, bl4);
  2861. mid += Math.imul(al6, bh4);
  2862. mid += Math.imul(ah6, bl4);
  2863. hi += Math.imul(ah6, bh4);
  2864. lo += Math.imul(al5, bl5);
  2865. mid += Math.imul(al5, bh5);
  2866. mid += Math.imul(ah5, bl5);
  2867. hi += Math.imul(ah5, bh5);
  2868. lo += Math.imul(al4, bl6);
  2869. mid += Math.imul(al4, bh6);
  2870. mid += Math.imul(ah4, bl6);
  2871. hi += Math.imul(ah4, bh6);
  2872. lo += Math.imul(al3, bl7);
  2873. mid += Math.imul(al3, bh7);
  2874. mid += Math.imul(ah3, bl7);
  2875. hi += Math.imul(ah3, bh7);
  2876. lo += Math.imul(al2, bl8);
  2877. mid += Math.imul(al2, bh8);
  2878. mid += Math.imul(ah2, bl8);
  2879. hi += Math.imul(ah2, bh8);
  2880. lo += Math.imul(al1, bl9);
  2881. mid += Math.imul(al1, bh9);
  2882. mid += Math.imul(ah1, bl9);
  2883. hi += Math.imul(ah1, bh9);
  2884. var w10 = c + lo + ((mid & 0x1fff) << 13);
  2885. c = hi + (mid >>> 13) + (w10 >>> 26);
  2886. w10 &= 0x3ffffff;
  2887. /* k = 11 */
  2888. lo = Math.imul(al9, bl2);
  2889. mid = Math.imul(al9, bh2);
  2890. mid += Math.imul(ah9, bl2);
  2891. hi = Math.imul(ah9, bh2);
  2892. lo += Math.imul(al8, bl3);
  2893. mid += Math.imul(al8, bh3);
  2894. mid += Math.imul(ah8, bl3);
  2895. hi += Math.imul(ah8, bh3);
  2896. lo += Math.imul(al7, bl4);
  2897. mid += Math.imul(al7, bh4);
  2898. mid += Math.imul(ah7, bl4);
  2899. hi += Math.imul(ah7, bh4);
  2900. lo += Math.imul(al6, bl5);
  2901. mid += Math.imul(al6, bh5);
  2902. mid += Math.imul(ah6, bl5);
  2903. hi += Math.imul(ah6, bh5);
  2904. lo += Math.imul(al5, bl6);
  2905. mid += Math.imul(al5, bh6);
  2906. mid += Math.imul(ah5, bl6);
  2907. hi += Math.imul(ah5, bh6);
  2908. lo += Math.imul(al4, bl7);
  2909. mid += Math.imul(al4, bh7);
  2910. mid += Math.imul(ah4, bl7);
  2911. hi += Math.imul(ah4, bh7);
  2912. lo += Math.imul(al3, bl8);
  2913. mid += Math.imul(al3, bh8);
  2914. mid += Math.imul(ah3, bl8);
  2915. hi += Math.imul(ah3, bh8);
  2916. lo += Math.imul(al2, bl9);
  2917. mid += Math.imul(al2, bh9);
  2918. mid += Math.imul(ah2, bl9);
  2919. hi += Math.imul(ah2, bh9);
  2920. var w11 = c + lo + ((mid & 0x1fff) << 13);
  2921. c = hi + (mid >>> 13) + (w11 >>> 26);
  2922. w11 &= 0x3ffffff;
  2923. /* k = 12 */
  2924. lo = Math.imul(al9, bl3);
  2925. mid = Math.imul(al9, bh3);
  2926. mid += Math.imul(ah9, bl3);
  2927. hi = Math.imul(ah9, bh3);
  2928. lo += Math.imul(al8, bl4);
  2929. mid += Math.imul(al8, bh4);
  2930. mid += Math.imul(ah8, bl4);
  2931. hi += Math.imul(ah8, bh4);
  2932. lo += Math.imul(al7, bl5);
  2933. mid += Math.imul(al7, bh5);
  2934. mid += Math.imul(ah7, bl5);
  2935. hi += Math.imul(ah7, bh5);
  2936. lo += Math.imul(al6, bl6);
  2937. mid += Math.imul(al6, bh6);
  2938. mid += Math.imul(ah6, bl6);
  2939. hi += Math.imul(ah6, bh6);
  2940. lo += Math.imul(al5, bl7);
  2941. mid += Math.imul(al5, bh7);
  2942. mid += Math.imul(ah5, bl7);
  2943. hi += Math.imul(ah5, bh7);
  2944. lo += Math.imul(al4, bl8);
  2945. mid += Math.imul(al4, bh8);
  2946. mid += Math.imul(ah4, bl8);
  2947. hi += Math.imul(ah4, bh8);
  2948. lo += Math.imul(al3, bl9);
  2949. mid += Math.imul(al3, bh9);
  2950. mid += Math.imul(ah3, bl9);
  2951. hi += Math.imul(ah3, bh9);
  2952. var w12 = c + lo + ((mid & 0x1fff) << 13);
  2953. c = hi + (mid >>> 13) + (w12 >>> 26);
  2954. w12 &= 0x3ffffff;
  2955. /* k = 13 */
  2956. lo = Math.imul(al9, bl4);
  2957. mid = Math.imul(al9, bh4);
  2958. mid += Math.imul(ah9, bl4);
  2959. hi = Math.imul(ah9, bh4);
  2960. lo += Math.imul(al8, bl5);
  2961. mid += Math.imul(al8, bh5);
  2962. mid += Math.imul(ah8, bl5);
  2963. hi += Math.imul(ah8, bh5);
  2964. lo += Math.imul(al7, bl6);
  2965. mid += Math.imul(al7, bh6);
  2966. mid += Math.imul(ah7, bl6);
  2967. hi += Math.imul(ah7, bh6);
  2968. lo += Math.imul(al6, bl7);
  2969. mid += Math.imul(al6, bh7);
  2970. mid += Math.imul(ah6, bl7);
  2971. hi += Math.imul(ah6, bh7);
  2972. lo += Math.imul(al5, bl8);
  2973. mid += Math.imul(al5, bh8);
  2974. mid += Math.imul(ah5, bl8);
  2975. hi += Math.imul(ah5, bh8);
  2976. lo += Math.imul(al4, bl9);
  2977. mid += Math.imul(al4, bh9);
  2978. mid += Math.imul(ah4, bl9);
  2979. hi += Math.imul(ah4, bh9);
  2980. var w13 = c + lo + ((mid & 0x1fff) << 13);
  2981. c = hi + (mid >>> 13) + (w13 >>> 26);
  2982. w13 &= 0x3ffffff;
  2983. /* k = 14 */
  2984. lo = Math.imul(al9, bl5);
  2985. mid = Math.imul(al9, bh5);
  2986. mid += Math.imul(ah9, bl5);
  2987. hi = Math.imul(ah9, bh5);
  2988. lo += Math.imul(al8, bl6);
  2989. mid += Math.imul(al8, bh6);
  2990. mid += Math.imul(ah8, bl6);
  2991. hi += Math.imul(ah8, bh6);
  2992. lo += Math.imul(al7, bl7);
  2993. mid += Math.imul(al7, bh7);
  2994. mid += Math.imul(ah7, bl7);
  2995. hi += Math.imul(ah7, bh7);
  2996. lo += Math.imul(al6, bl8);
  2997. mid += Math.imul(al6, bh8);
  2998. mid += Math.imul(ah6, bl8);
  2999. hi += Math.imul(ah6, bh8);
  3000. lo += Math.imul(al5, bl9);
  3001. mid += Math.imul(al5, bh9);
  3002. mid += Math.imul(ah5, bl9);
  3003. hi += Math.imul(ah5, bh9);
  3004. var w14 = c + lo + ((mid & 0x1fff) << 13);
  3005. c = hi + (mid >>> 13) + (w14 >>> 26);
  3006. w14 &= 0x3ffffff;
  3007. /* k = 15 */
  3008. lo = Math.imul(al9, bl6);
  3009. mid = Math.imul(al9, bh6);
  3010. mid += Math.imul(ah9, bl6);
  3011. hi = Math.imul(ah9, bh6);
  3012. lo += Math.imul(al8, bl7);
  3013. mid += Math.imul(al8, bh7);
  3014. mid += Math.imul(ah8, bl7);
  3015. hi += Math.imul(ah8, bh7);
  3016. lo += Math.imul(al7, bl8);
  3017. mid += Math.imul(al7, bh8);
  3018. mid += Math.imul(ah7, bl8);
  3019. hi += Math.imul(ah7, bh8);
  3020. lo += Math.imul(al6, bl9);
  3021. mid += Math.imul(al6, bh9);
  3022. mid += Math.imul(ah6, bl9);
  3023. hi += Math.imul(ah6, bh9);
  3024. var w15 = c + lo + ((mid & 0x1fff) << 13);
  3025. c = hi + (mid >>> 13) + (w15 >>> 26);
  3026. w15 &= 0x3ffffff;
  3027. /* k = 16 */
  3028. lo = Math.imul(al9, bl7);
  3029. mid = Math.imul(al9, bh7);
  3030. mid += Math.imul(ah9, bl7);
  3031. hi = Math.imul(ah9, bh7);
  3032. lo += Math.imul(al8, bl8);
  3033. mid += Math.imul(al8, bh8);
  3034. mid += Math.imul(ah8, bl8);
  3035. hi += Math.imul(ah8, bh8);
  3036. lo += Math.imul(al7, bl9);
  3037. mid += Math.imul(al7, bh9);
  3038. mid += Math.imul(ah7, bl9);
  3039. hi += Math.imul(ah7, bh9);
  3040. var w16 = c + lo + ((mid & 0x1fff) << 13);
  3041. c = hi + (mid >>> 13) + (w16 >>> 26);
  3042. w16 &= 0x3ffffff;
  3043. /* k = 17 */
  3044. lo = Math.imul(al9, bl8);
  3045. mid = Math.imul(al9, bh8);
  3046. mid += Math.imul(ah9, bl8);
  3047. hi = Math.imul(ah9, bh8);
  3048. lo += Math.imul(al8, bl9);
  3049. mid += Math.imul(al8, bh9);
  3050. mid += Math.imul(ah8, bl9);
  3051. hi += Math.imul(ah8, bh9);
  3052. var w17 = c + lo + ((mid & 0x1fff) << 13);
  3053. c = hi + (mid >>> 13) + (w17 >>> 26);
  3054. w17 &= 0x3ffffff;
  3055. /* k = 18 */
  3056. lo = Math.imul(al9, bl9);
  3057. mid = Math.imul(al9, bh9);
  3058. mid += Math.imul(ah9, bl9);
  3059. hi = Math.imul(ah9, bh9);
  3060. var w18 = c + lo + ((mid & 0x1fff) << 13);
  3061. c = hi + (mid >>> 13) + (w18 >>> 26);
  3062. w18 &= 0x3ffffff;
  3063. o[0] = w0;
  3064. o[1] = w1;
  3065. o[2] = w2;
  3066. o[3] = w3;
  3067. o[4] = w4;
  3068. o[5] = w5;
  3069. o[6] = w6;
  3070. o[7] = w7;
  3071. o[8] = w8;
  3072. o[9] = w9;
  3073. o[10] = w10;
  3074. o[11] = w11;
  3075. o[12] = w12;
  3076. o[13] = w13;
  3077. o[14] = w14;
  3078. o[15] = w15;
  3079. o[16] = w16;
  3080. o[17] = w17;
  3081. o[18] = w18;
  3082. if (c !== 0) {
  3083. o[19] = c;
  3084. out.length++;
  3085. }
  3086. return out;
  3087. };
  3088. // Polyfill comb
  3089. if (!Math.imul) {
  3090. comb10MulTo = smallMulTo;
  3091. }
  3092. function bigMulTo (self, num, out) {
  3093. out.negative = num.negative ^ self.negative;
  3094. out.length = self.length + num.length;
  3095. var carry = 0;
  3096. var hncarry = 0;
  3097. for (var k = 0; k < out.length - 1; k++) {
  3098. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  3099. // note that ncarry could be >= 0x3ffffff
  3100. var ncarry = hncarry;
  3101. hncarry = 0;
  3102. var rword = carry & 0x3ffffff;
  3103. var maxJ = Math.min(k, num.length - 1);
  3104. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  3105. var i = k - j;
  3106. var a = self.words[i] | 0;
  3107. var b = num.words[j] | 0;
  3108. var r = a * b;
  3109. var lo = r & 0x3ffffff;
  3110. ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
  3111. lo = (lo + rword) | 0;
  3112. rword = lo & 0x3ffffff;
  3113. ncarry = (ncarry + (lo >>> 26)) | 0;
  3114. hncarry += ncarry >>> 26;
  3115. ncarry &= 0x3ffffff;
  3116. }
  3117. out.words[k] = rword;
  3118. carry = ncarry;
  3119. ncarry = hncarry;
  3120. }
  3121. if (carry !== 0) {
  3122. out.words[k] = carry;
  3123. } else {
  3124. out.length--;
  3125. }
  3126. return out.strip();
  3127. }
  3128. function jumboMulTo (self, num, out) {
  3129. var fftm = new FFTM();
  3130. return fftm.mulp(self, num, out);
  3131. }
  3132. BN.prototype.mulTo = function mulTo (num, out) {
  3133. var res;
  3134. var len = this.length + num.length;
  3135. if (this.length === 10 && num.length === 10) {
  3136. res = comb10MulTo(this, num, out);
  3137. } else if (len < 63) {
  3138. res = smallMulTo(this, num, out);
  3139. } else if (len < 1024) {
  3140. res = bigMulTo(this, num, out);
  3141. } else {
  3142. res = jumboMulTo(this, num, out);
  3143. }
  3144. return res;
  3145. };
  3146. // Cooley-Tukey algorithm for FFT
  3147. // slightly revisited to rely on looping instead of recursion
  3148. function FFTM (x, y) {
  3149. this.x = x;
  3150. this.y = y;
  3151. }
  3152. FFTM.prototype.makeRBT = function makeRBT (N) {
  3153. var t = new Array(N);
  3154. var l = BN.prototype._countBits(N) - 1;
  3155. for (var i = 0; i < N; i++) {
  3156. t[i] = this.revBin(i, l, N);
  3157. }
  3158. return t;
  3159. };
  3160. // Returns binary-reversed representation of `x`
  3161. FFTM.prototype.revBin = function revBin (x, l, N) {
  3162. if (x === 0 || x === N - 1) return x;
  3163. var rb = 0;
  3164. for (var i = 0; i < l; i++) {
  3165. rb |= (x & 1) << (l - i - 1);
  3166. x >>= 1;
  3167. }
  3168. return rb;
  3169. };
  3170. // Performs "tweedling" phase, therefore 'emulating'
  3171. // behaviour of the recursive algorithm
  3172. FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
  3173. for (var i = 0; i < N; i++) {
  3174. rtws[i] = rws[rbt[i]];
  3175. itws[i] = iws[rbt[i]];
  3176. }
  3177. };
  3178. FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
  3179. this.permute(rbt, rws, iws, rtws, itws, N);
  3180. for (var s = 1; s < N; s <<= 1) {
  3181. var l = s << 1;
  3182. var rtwdf = Math.cos(2 * Math.PI / l);
  3183. var itwdf = Math.sin(2 * Math.PI / l);
  3184. for (var p = 0; p < N; p += l) {
  3185. var rtwdf_ = rtwdf;
  3186. var itwdf_ = itwdf;
  3187. for (var j = 0; j < s; j++) {
  3188. var re = rtws[p + j];
  3189. var ie = itws[p + j];
  3190. var ro = rtws[p + j + s];
  3191. var io = itws[p + j + s];
  3192. var rx = rtwdf_ * ro - itwdf_ * io;
  3193. io = rtwdf_ * io + itwdf_ * ro;
  3194. ro = rx;
  3195. rtws[p + j] = re + ro;
  3196. itws[p + j] = ie + io;
  3197. rtws[p + j + s] = re - ro;
  3198. itws[p + j + s] = ie - io;
  3199. /* jshint maxdepth : false */
  3200. if (j !== l) {
  3201. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  3202. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  3203. rtwdf_ = rx;
  3204. }
  3205. }
  3206. }
  3207. }
  3208. };
  3209. FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
  3210. var N = Math.max(m, n) | 1;
  3211. var odd = N & 1;
  3212. var i = 0;
  3213. for (N = N / 2 | 0; N; N = N >>> 1) {
  3214. i++;
  3215. }
  3216. return 1 << i + 1 + odd;
  3217. };
  3218. FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
  3219. if (N <= 1) return;
  3220. for (var i = 0; i < N / 2; i++) {
  3221. var t = rws[i];
  3222. rws[i] = rws[N - i - 1];
  3223. rws[N - i - 1] = t;
  3224. t = iws[i];
  3225. iws[i] = -iws[N - i - 1];
  3226. iws[N - i - 1] = -t;
  3227. }
  3228. };
  3229. FFTM.prototype.normalize13b = function normalize13b (ws, N) {
  3230. var carry = 0;
  3231. for (var i = 0; i < N / 2; i++) {
  3232. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
  3233. Math.round(ws[2 * i] / N) +
  3234. carry;
  3235. ws[i] = w & 0x3ffffff;
  3236. if (w < 0x4000000) {
  3237. carry = 0;
  3238. } else {
  3239. carry = w / 0x4000000 | 0;
  3240. }
  3241. }
  3242. return ws;
  3243. };
  3244. FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
  3245. var carry = 0;
  3246. for (var i = 0; i < len; i++) {
  3247. carry = carry + (ws[i] | 0);
  3248. rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
  3249. rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
  3250. }
  3251. // Pad with zeroes
  3252. for (i = 2 * len; i < N; ++i) {
  3253. rws[i] = 0;
  3254. }
  3255. assert(carry === 0);
  3256. assert((carry & ~0x1fff) === 0);
  3257. };
  3258. FFTM.prototype.stub = function stub (N) {
  3259. var ph = new Array(N);
  3260. for (var i = 0; i < N; i++) {
  3261. ph[i] = 0;
  3262. }
  3263. return ph;
  3264. };
  3265. FFTM.prototype.mulp = function mulp (x, y, out) {
  3266. var N = 2 * this.guessLen13b(x.length, y.length);
  3267. var rbt = this.makeRBT(N);
  3268. var _ = this.stub(N);
  3269. var rws = new Array(N);
  3270. var rwst = new Array(N);
  3271. var iwst = new Array(N);
  3272. var nrws = new Array(N);
  3273. var nrwst = new Array(N);
  3274. var niwst = new Array(N);
  3275. var rmws = out.words;
  3276. rmws.length = N;
  3277. this.convert13b(x.words, x.length, rws, N);
  3278. this.convert13b(y.words, y.length, nrws, N);
  3279. this.transform(rws, _, rwst, iwst, N, rbt);
  3280. this.transform(nrws, _, nrwst, niwst, N, rbt);
  3281. for (var i = 0; i < N; i++) {
  3282. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  3283. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  3284. rwst[i] = rx;
  3285. }
  3286. this.conjugate(rwst, iwst, N);
  3287. this.transform(rwst, iwst, rmws, _, N, rbt);
  3288. this.conjugate(rmws, _, N);
  3289. this.normalize13b(rmws, N);
  3290. out.negative = x.negative ^ y.negative;
  3291. out.length = x.length + y.length;
  3292. return out.strip();
  3293. };
  3294. // Multiply `this` by `num`
  3295. BN.prototype.mul = function mul (num) {
  3296. var out = new BN(null);
  3297. out.words = new Array(this.length + num.length);
  3298. return this.mulTo(num, out);
  3299. };
  3300. // Multiply employing FFT
  3301. BN.prototype.mulf = function mulf (num) {
  3302. var out = new BN(null);
  3303. out.words = new Array(this.length + num.length);
  3304. return jumboMulTo(this, num, out);
  3305. };
  3306. // In-place Multiplication
  3307. BN.prototype.imul = function imul (num) {
  3308. return this.clone().mulTo(num, this);
  3309. };
  3310. BN.prototype.imuln = function imuln (num) {
  3311. assert(typeof num === 'number');
  3312. assert(num < 0x4000000);
  3313. // Carry
  3314. var carry = 0;
  3315. for (var i = 0; i < this.length; i++) {
  3316. var w = (this.words[i] | 0) * num;
  3317. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  3318. carry >>= 26;
  3319. carry += (w / 0x4000000) | 0;
  3320. // NOTE: lo is 27bit maximum
  3321. carry += lo >>> 26;
  3322. this.words[i] = lo & 0x3ffffff;
  3323. }
  3324. if (carry !== 0) {
  3325. this.words[i] = carry;
  3326. this.length++;
  3327. }
  3328. return this;
  3329. };
  3330. BN.prototype.muln = function muln (num) {
  3331. return this.clone().imuln(num);
  3332. };
  3333. // `this` * `this`
  3334. BN.prototype.sqr = function sqr () {
  3335. return this.mul(this);
  3336. };
  3337. // `this` * `this` in-place
  3338. BN.prototype.isqr = function isqr () {
  3339. return this.imul(this.clone());
  3340. };
  3341. // Math.pow(`this`, `num`)
  3342. BN.prototype.pow = function pow (num) {
  3343. var w = toBitArray(num);
  3344. if (w.length === 0) return new BN(1);
  3345. // Skip leading zeroes
  3346. var res = this;
  3347. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  3348. if (w[i] !== 0) break;
  3349. }
  3350. if (++i < w.length) {
  3351. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  3352. if (w[i] === 0) continue;
  3353. res = res.mul(q);
  3354. }
  3355. }
  3356. return res;
  3357. };
  3358. // Shift-left in-place
  3359. BN.prototype.iushln = function iushln (bits) {
  3360. assert(typeof bits === 'number' && bits >= 0);
  3361. var r = bits % 26;
  3362. var s = (bits - r) / 26;
  3363. var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
  3364. var i;
  3365. if (r !== 0) {
  3366. var carry = 0;
  3367. for (i = 0; i < this.length; i++) {
  3368. var newCarry = this.words[i] & carryMask;
  3369. var c = ((this.words[i] | 0) - newCarry) << r;
  3370. this.words[i] = c | carry;
  3371. carry = newCarry >>> (26 - r);
  3372. }
  3373. if (carry) {
  3374. this.words[i] = carry;
  3375. this.length++;
  3376. }
  3377. }
  3378. if (s !== 0) {
  3379. for (i = this.length - 1; i >= 0; i--) {
  3380. this.words[i + s] = this.words[i];
  3381. }
  3382. for (i = 0; i < s; i++) {
  3383. this.words[i] = 0;
  3384. }
  3385. this.length += s;
  3386. }
  3387. return this.strip();
  3388. };
  3389. BN.prototype.ishln = function ishln (bits) {
  3390. // TODO(indutny): implement me
  3391. assert(this.negative === 0);
  3392. return this.iushln(bits);
  3393. };
  3394. // Shift-right in-place
  3395. // NOTE: `hint` is a lowest bit before trailing zeroes
  3396. // NOTE: if `extended` is present - it will be filled with destroyed bits
  3397. BN.prototype.iushrn = function iushrn (bits, hint, extended) {
  3398. assert(typeof bits === 'number' && bits >= 0);
  3399. var h;
  3400. if (hint) {
  3401. h = (hint - (hint % 26)) / 26;
  3402. } else {
  3403. h = 0;
  3404. }
  3405. var r = bits % 26;
  3406. var s = Math.min((bits - r) / 26, this.length);
  3407. var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
  3408. var maskedWords = extended;
  3409. h -= s;
  3410. h = Math.max(0, h);
  3411. // Extended mode, copy masked part
  3412. if (maskedWords) {
  3413. for (var i = 0; i < s; i++) {
  3414. maskedWords.words[i] = this.words[i];
  3415. }
  3416. maskedWords.length = s;
  3417. }
  3418. if (s === 0) {
  3419. // No-op, we should not move anything at all
  3420. } else if (this.length > s) {
  3421. this.length -= s;
  3422. for (i = 0; i < this.length; i++) {
  3423. this.words[i] = this.words[i + s];
  3424. }
  3425. } else {
  3426. this.words[0] = 0;
  3427. this.length = 1;
  3428. }
  3429. var carry = 0;
  3430. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  3431. var word = this.words[i] | 0;
  3432. this.words[i] = (carry << (26 - r)) | (word >>> r);
  3433. carry = word & mask;
  3434. }
  3435. // Push carried bits as a mask
  3436. if (maskedWords && carry !== 0) {
  3437. maskedWords.words[maskedWords.length++] = carry;
  3438. }
  3439. if (this.length === 0) {
  3440. this.words[0] = 0;
  3441. this.length = 1;
  3442. }
  3443. return this.strip();
  3444. };
  3445. BN.prototype.ishrn = function ishrn (bits, hint, extended) {
  3446. // TODO(indutny): implement me
  3447. assert(this.negative === 0);
  3448. return this.iushrn(bits, hint, extended);
  3449. };
  3450. // Shift-left
  3451. BN.prototype.shln = function shln (bits) {
  3452. return this.clone().ishln(bits);
  3453. };
  3454. BN.prototype.ushln = function ushln (bits) {
  3455. return this.clone().iushln(bits);
  3456. };
  3457. // Shift-right
  3458. BN.prototype.shrn = function shrn (bits) {
  3459. return this.clone().ishrn(bits);
  3460. };
  3461. BN.prototype.ushrn = function ushrn (bits) {
  3462. return this.clone().iushrn(bits);
  3463. };
  3464. // Test if n bit is set
  3465. BN.prototype.testn = function testn (bit) {
  3466. assert(typeof bit === 'number' && bit >= 0);
  3467. var r = bit % 26;
  3468. var s = (bit - r) / 26;
  3469. var q = 1 << r;
  3470. // Fast case: bit is much higher than all existing words
  3471. if (this.length <= s) return false;
  3472. // Check bit and return
  3473. var w = this.words[s];
  3474. return !!(w & q);
  3475. };
  3476. // Return only lowers bits of number (in-place)
  3477. BN.prototype.imaskn = function imaskn (bits) {
  3478. assert(typeof bits === 'number' && bits >= 0);
  3479. var r = bits % 26;
  3480. var s = (bits - r) / 26;
  3481. assert(this.negative === 0, 'imaskn works only with positive numbers');
  3482. if (r !== 0) {
  3483. s++;
  3484. }
  3485. this.length = Math.min(s, this.length);
  3486. if (r !== 0) {
  3487. var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
  3488. this.words[this.length - 1] &= mask;
  3489. }
  3490. return this.strip();
  3491. };
  3492. // Return only lowers bits of number
  3493. BN.prototype.maskn = function maskn (bits) {
  3494. return this.clone().imaskn(bits);
  3495. };
  3496. // Add plain number `num` to `this`
  3497. BN.prototype.iaddn = function iaddn (num) {
  3498. assert(typeof num === 'number');
  3499. assert(num < 0x4000000);
  3500. if (num < 0) return this.isubn(-num);
  3501. // Possible sign change
  3502. if (this.negative !== 0) {
  3503. if (this.length === 1 && (this.words[0] | 0) < num) {
  3504. this.words[0] = num - (this.words[0] | 0);
  3505. this.negative = 0;
  3506. return this;
  3507. }
  3508. this.negative = 0;
  3509. this.isubn(num);
  3510. this.negative = 1;
  3511. return this;
  3512. }
  3513. // Add without checks
  3514. return this._iaddn(num);
  3515. };
  3516. BN.prototype._iaddn = function _iaddn (num) {
  3517. this.words[0] += num;
  3518. // Carry
  3519. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  3520. this.words[i] -= 0x4000000;
  3521. if (i === this.length - 1) {
  3522. this.words[i + 1] = 1;
  3523. } else {
  3524. this.words[i + 1]++;
  3525. }
  3526. }
  3527. this.length = Math.max(this.length, i + 1);
  3528. return this;
  3529. };
  3530. // Subtract plain number `num` from `this`
  3531. BN.prototype.isubn = function isubn (num) {
  3532. assert(typeof num === 'number');
  3533. assert(num < 0x4000000);
  3534. if (num < 0) return this.iaddn(-num);
  3535. if (this.negative !== 0) {
  3536. this.negative = 0;
  3537. this.iaddn(num);
  3538. this.negative = 1;
  3539. return this;
  3540. }
  3541. this.words[0] -= num;
  3542. if (this.length === 1 && this.words[0] < 0) {
  3543. this.words[0] = -this.words[0];
  3544. this.negative = 1;
  3545. } else {
  3546. // Carry
  3547. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  3548. this.words[i] += 0x4000000;
  3549. this.words[i + 1] -= 1;
  3550. }
  3551. }
  3552. return this.strip();
  3553. };
  3554. BN.prototype.addn = function addn (num) {
  3555. return this.clone().iaddn(num);
  3556. };
  3557. BN.prototype.subn = function subn (num) {
  3558. return this.clone().isubn(num);
  3559. };
  3560. BN.prototype.iabs = function iabs () {
  3561. this.negative = 0;
  3562. return this;
  3563. };
  3564. BN.prototype.abs = function abs () {
  3565. return this.clone().iabs();
  3566. };
  3567. BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
  3568. var len = num.length + shift;
  3569. var i;
  3570. this._expand(len);
  3571. var w;
  3572. var carry = 0;
  3573. for (i = 0; i < num.length; i++) {
  3574. w = (this.words[i + shift] | 0) + carry;
  3575. var right = (num.words[i] | 0) * mul;
  3576. w -= right & 0x3ffffff;
  3577. carry = (w >> 26) - ((right / 0x4000000) | 0);
  3578. this.words[i + shift] = w & 0x3ffffff;
  3579. }
  3580. for (; i < this.length - shift; i++) {
  3581. w = (this.words[i + shift] | 0) + carry;
  3582. carry = w >> 26;
  3583. this.words[i + shift] = w & 0x3ffffff;
  3584. }
  3585. if (carry === 0) return this.strip();
  3586. // Subtraction overflow
  3587. assert(carry === -1);
  3588. carry = 0;
  3589. for (i = 0; i < this.length; i++) {
  3590. w = -(this.words[i] | 0) + carry;
  3591. carry = w >> 26;
  3592. this.words[i] = w & 0x3ffffff;
  3593. }
  3594. this.negative = 1;
  3595. return this.strip();
  3596. };
  3597. BN.prototype._wordDiv = function _wordDiv (num, mode) {
  3598. var shift = this.length - num.length;
  3599. var a = this.clone();
  3600. var b = num;
  3601. // Normalize
  3602. var bhi = b.words[b.length - 1] | 0;
  3603. var bhiBits = this._countBits(bhi);
  3604. shift = 26 - bhiBits;
  3605. if (shift !== 0) {
  3606. b = b.ushln(shift);
  3607. a.iushln(shift);
  3608. bhi = b.words[b.length - 1] | 0;
  3609. }
  3610. // Initialize quotient
  3611. var m = a.length - b.length;
  3612. var q;
  3613. if (mode !== 'mod') {
  3614. q = new BN(null);
  3615. q.length = m + 1;
  3616. q.words = new Array(q.length);
  3617. for (var i = 0; i < q.length; i++) {
  3618. q.words[i] = 0;
  3619. }
  3620. }
  3621. var diff = a.clone()._ishlnsubmul(b, 1, m);
  3622. if (diff.negative === 0) {
  3623. a = diff;
  3624. if (q) {
  3625. q.words[m] = 1;
  3626. }
  3627. }
  3628. for (var j = m - 1; j >= 0; j--) {
  3629. var qj = (a.words[b.length + j] | 0) * 0x4000000 +
  3630. (a.words[b.length + j - 1] | 0);
  3631. // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  3632. // (0x7ffffff)
  3633. qj = Math.min((qj / bhi) | 0, 0x3ffffff);
  3634. a._ishlnsubmul(b, qj, j);
  3635. while (a.negative !== 0) {
  3636. qj--;
  3637. a.negative = 0;
  3638. a._ishlnsubmul(b, 1, j);
  3639. if (!a.isZero()) {
  3640. a.negative ^= 1;
  3641. }
  3642. }
  3643. if (q) {
  3644. q.words[j] = qj;
  3645. }
  3646. }
  3647. if (q) {
  3648. q.strip();
  3649. }
  3650. a.strip();
  3651. // Denormalize
  3652. if (mode !== 'div' && shift !== 0) {
  3653. a.iushrn(shift);
  3654. }
  3655. return {
  3656. div: q || null,
  3657. mod: a
  3658. };
  3659. };
  3660. // NOTE: 1) `mode` can be set to `mod` to request mod only,
  3661. // to `div` to request div only, or be absent to
  3662. // request both div & mod
  3663. // 2) `positive` is true if unsigned mod is requested
  3664. BN.prototype.divmod = function divmod (num, mode, positive) {
  3665. assert(!num.isZero());
  3666. if (this.isZero()) {
  3667. return {
  3668. div: new BN(0),
  3669. mod: new BN(0)
  3670. };
  3671. }
  3672. var div, mod, res;
  3673. if (this.negative !== 0 && num.negative === 0) {
  3674. res = this.neg().divmod(num, mode);
  3675. if (mode !== 'mod') {
  3676. div = res.div.neg();
  3677. }
  3678. if (mode !== 'div') {
  3679. mod = res.mod.neg();
  3680. if (positive && mod.negative !== 0) {
  3681. mod.iadd(num);
  3682. }
  3683. }
  3684. return {
  3685. div: div,
  3686. mod: mod
  3687. };
  3688. }
  3689. if (this.negative === 0 && num.negative !== 0) {
  3690. res = this.divmod(num.neg(), mode);
  3691. if (mode !== 'mod') {
  3692. div = res.div.neg();
  3693. }
  3694. return {
  3695. div: div,
  3696. mod: res.mod
  3697. };
  3698. }
  3699. if ((this.negative & num.negative) !== 0) {
  3700. res = this.neg().divmod(num.neg(), mode);
  3701. if (mode !== 'div') {
  3702. mod = res.mod.neg();
  3703. if (positive && mod.negative !== 0) {
  3704. mod.isub(num);
  3705. }
  3706. }
  3707. return {
  3708. div: res.div,
  3709. mod: mod
  3710. };
  3711. }
  3712. // Both numbers are positive at this point
  3713. // Strip both numbers to approximate shift value
  3714. if (num.length > this.length || this.cmp(num) < 0) {
  3715. return {
  3716. div: new BN(0),
  3717. mod: this
  3718. };
  3719. }
  3720. // Very short reduction
  3721. if (num.length === 1) {
  3722. if (mode === 'div') {
  3723. return {
  3724. div: this.divn(num.words[0]),
  3725. mod: null
  3726. };
  3727. }
  3728. if (mode === 'mod') {
  3729. return {
  3730. div: null,
  3731. mod: new BN(this.modn(num.words[0]))
  3732. };
  3733. }
  3734. return {
  3735. div: this.divn(num.words[0]),
  3736. mod: new BN(this.modn(num.words[0]))
  3737. };
  3738. }
  3739. return this._wordDiv(num, mode);
  3740. };
  3741. // Find `this` / `num`
  3742. BN.prototype.div = function div (num) {
  3743. return this.divmod(num, 'div', false).div;
  3744. };
  3745. // Find `this` % `num`
  3746. BN.prototype.mod = function mod (num) {
  3747. return this.divmod(num, 'mod', false).mod;
  3748. };
  3749. BN.prototype.umod = function umod (num) {
  3750. return this.divmod(num, 'mod', true).mod;
  3751. };
  3752. // Find Round(`this` / `num`)
  3753. BN.prototype.divRound = function divRound (num) {
  3754. var dm = this.divmod(num);
  3755. // Fast case - exact division
  3756. if (dm.mod.isZero()) return dm.div;
  3757. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  3758. var half = num.ushrn(1);
  3759. var r2 = num.andln(1);
  3760. var cmp = mod.cmp(half);
  3761. // Round down
  3762. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
  3763. // Round up
  3764. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  3765. };
  3766. BN.prototype.modn = function modn (num) {
  3767. assert(num <= 0x3ffffff);
  3768. var p = (1 << 26) % num;
  3769. var acc = 0;
  3770. for (var i = this.length - 1; i >= 0; i--) {
  3771. acc = (p * acc + (this.words[i] | 0)) % num;
  3772. }
  3773. return acc;
  3774. };
  3775. // In-place division by number
  3776. BN.prototype.idivn = function idivn (num) {
  3777. assert(num <= 0x3ffffff);
  3778. var carry = 0;
  3779. for (var i = this.length - 1; i >= 0; i--) {
  3780. var w = (this.words[i] | 0) + carry * 0x4000000;
  3781. this.words[i] = (w / num) | 0;
  3782. carry = w % num;
  3783. }
  3784. return this.strip();
  3785. };
  3786. BN.prototype.divn = function divn (num) {
  3787. return this.clone().idivn(num);
  3788. };
  3789. BN.prototype.egcd = function egcd (p) {
  3790. assert(p.negative === 0);
  3791. assert(!p.isZero());
  3792. var x = this;
  3793. var y = p.clone();
  3794. if (x.negative !== 0) {
  3795. x = x.umod(p);
  3796. } else {
  3797. x = x.clone();
  3798. }
  3799. // A * x + B * y = x
  3800. var A = new BN(1);
  3801. var B = new BN(0);
  3802. // C * x + D * y = y
  3803. var C = new BN(0);
  3804. var D = new BN(1);
  3805. var g = 0;
  3806. while (x.isEven() && y.isEven()) {
  3807. x.iushrn(1);
  3808. y.iushrn(1);
  3809. ++g;
  3810. }
  3811. var yp = y.clone();
  3812. var xp = x.clone();
  3813. while (!x.isZero()) {
  3814. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  3815. if (i > 0) {
  3816. x.iushrn(i);
  3817. while (i-- > 0) {
  3818. if (A.isOdd() || B.isOdd()) {
  3819. A.iadd(yp);
  3820. B.isub(xp);
  3821. }
  3822. A.iushrn(1);
  3823. B.iushrn(1);
  3824. }
  3825. }
  3826. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  3827. if (j > 0) {
  3828. y.iushrn(j);
  3829. while (j-- > 0) {
  3830. if (C.isOdd() || D.isOdd()) {
  3831. C.iadd(yp);
  3832. D.isub(xp);
  3833. }
  3834. C.iushrn(1);
  3835. D.iushrn(1);
  3836. }
  3837. }
  3838. if (x.cmp(y) >= 0) {
  3839. x.isub(y);
  3840. A.isub(C);
  3841. B.isub(D);
  3842. } else {
  3843. y.isub(x);
  3844. C.isub(A);
  3845. D.isub(B);
  3846. }
  3847. }
  3848. return {
  3849. a: C,
  3850. b: D,
  3851. gcd: y.iushln(g)
  3852. };
  3853. };
  3854. // This is reduced incarnation of the binary EEA
  3855. // above, designated to invert members of the
  3856. // _prime_ fields F(p) at a maximal speed
  3857. BN.prototype._invmp = function _invmp (p) {
  3858. assert(p.negative === 0);
  3859. assert(!p.isZero());
  3860. var a = this;
  3861. var b = p.clone();
  3862. if (a.negative !== 0) {
  3863. a = a.umod(p);
  3864. } else {
  3865. a = a.clone();
  3866. }
  3867. var x1 = new BN(1);
  3868. var x2 = new BN(0);
  3869. var delta = b.clone();
  3870. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  3871. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  3872. if (i > 0) {
  3873. a.iushrn(i);
  3874. while (i-- > 0) {
  3875. if (x1.isOdd()) {
  3876. x1.iadd(delta);
  3877. }
  3878. x1.iushrn(1);
  3879. }
  3880. }
  3881. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  3882. if (j > 0) {
  3883. b.iushrn(j);
  3884. while (j-- > 0) {
  3885. if (x2.isOdd()) {
  3886. x2.iadd(delta);
  3887. }
  3888. x2.iushrn(1);
  3889. }
  3890. }
  3891. if (a.cmp(b) >= 0) {
  3892. a.isub(b);
  3893. x1.isub(x2);
  3894. } else {
  3895. b.isub(a);
  3896. x2.isub(x1);
  3897. }
  3898. }
  3899. var res;
  3900. if (a.cmpn(1) === 0) {
  3901. res = x1;
  3902. } else {
  3903. res = x2;
  3904. }
  3905. if (res.cmpn(0) < 0) {
  3906. res.iadd(p);
  3907. }
  3908. return res;
  3909. };
  3910. BN.prototype.gcd = function gcd (num) {
  3911. if (this.isZero()) return num.abs();
  3912. if (num.isZero()) return this.abs();
  3913. var a = this.clone();
  3914. var b = num.clone();
  3915. a.negative = 0;
  3916. b.negative = 0;
  3917. // Remove common factor of two
  3918. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  3919. a.iushrn(1);
  3920. b.iushrn(1);
  3921. }
  3922. do {
  3923. while (a.isEven()) {
  3924. a.iushrn(1);
  3925. }
  3926. while (b.isEven()) {
  3927. b.iushrn(1);
  3928. }
  3929. var r = a.cmp(b);
  3930. if (r < 0) {
  3931. // Swap `a` and `b` to make `a` always bigger than `b`
  3932. var t = a;
  3933. a = b;
  3934. b = t;
  3935. } else if (r === 0 || b.cmpn(1) === 0) {
  3936. break;
  3937. }
  3938. a.isub(b);
  3939. } while (true);
  3940. return b.iushln(shift);
  3941. };
  3942. // Invert number in the field F(num)
  3943. BN.prototype.invm = function invm (num) {
  3944. return this.egcd(num).a.umod(num);
  3945. };
  3946. BN.prototype.isEven = function isEven () {
  3947. return (this.words[0] & 1) === 0;
  3948. };
  3949. BN.prototype.isOdd = function isOdd () {
  3950. return (this.words[0] & 1) === 1;
  3951. };
  3952. // And first word and num
  3953. BN.prototype.andln = function andln (num) {
  3954. return this.words[0] & num;
  3955. };
  3956. // Increment at the bit position in-line
  3957. BN.prototype.bincn = function bincn (bit) {
  3958. assert(typeof bit === 'number');
  3959. var r = bit % 26;
  3960. var s = (bit - r) / 26;
  3961. var q = 1 << r;
  3962. // Fast case: bit is much higher than all existing words
  3963. if (this.length <= s) {
  3964. this._expand(s + 1);
  3965. this.words[s] |= q;
  3966. return this;
  3967. }
  3968. // Add bit and propagate, if needed
  3969. var carry = q;
  3970. for (var i = s; carry !== 0 && i < this.length; i++) {
  3971. var w = this.words[i] | 0;
  3972. w += carry;
  3973. carry = w >>> 26;
  3974. w &= 0x3ffffff;
  3975. this.words[i] = w;
  3976. }
  3977. if (carry !== 0) {
  3978. this.words[i] = carry;
  3979. this.length++;
  3980. }
  3981. return this;
  3982. };
  3983. BN.prototype.isZero = function isZero () {
  3984. return this.length === 1 && this.words[0] === 0;
  3985. };
  3986. BN.prototype.cmpn = function cmpn (num) {
  3987. var negative = num < 0;
  3988. if (this.negative !== 0 && !negative) return -1;
  3989. if (this.negative === 0 && negative) return 1;
  3990. this.strip();
  3991. var res;
  3992. if (this.length > 1) {
  3993. res = 1;
  3994. } else {
  3995. if (negative) {
  3996. num = -num;
  3997. }
  3998. assert(num <= 0x3ffffff, 'Number is too big');
  3999. var w = this.words[0] | 0;
  4000. res = w === num ? 0 : w < num ? -1 : 1;
  4001. }
  4002. if (this.negative !== 0) return -res | 0;
  4003. return res;
  4004. };
  4005. // Compare two numbers and return:
  4006. // 1 - if `this` > `num`
  4007. // 0 - if `this` == `num`
  4008. // -1 - if `this` < `num`
  4009. BN.prototype.cmp = function cmp (num) {
  4010. if (this.negative !== 0 && num.negative === 0) return -1;
  4011. if (this.negative === 0 && num.negative !== 0) return 1;
  4012. var res = this.ucmp(num);
  4013. if (this.negative !== 0) return -res | 0;
  4014. return res;
  4015. };
  4016. // Unsigned comparison
  4017. BN.prototype.ucmp = function ucmp (num) {
  4018. // At this point both numbers have the same sign
  4019. if (this.length > num.length) return 1;
  4020. if (this.length < num.length) return -1;
  4021. var res = 0;
  4022. for (var i = this.length - 1; i >= 0; i--) {
  4023. var a = this.words[i] | 0;
  4024. var b = num.words[i] | 0;
  4025. if (a === b) continue;
  4026. if (a < b) {
  4027. res = -1;
  4028. } else if (a > b) {
  4029. res = 1;
  4030. }
  4031. break;
  4032. }
  4033. return res;
  4034. };
  4035. BN.prototype.gtn = function gtn (num) {
  4036. return this.cmpn(num) === 1;
  4037. };
  4038. BN.prototype.gt = function gt (num) {
  4039. return this.cmp(num) === 1;
  4040. };
  4041. BN.prototype.gten = function gten (num) {
  4042. return this.cmpn(num) >= 0;
  4043. };
  4044. BN.prototype.gte = function gte (num) {
  4045. return this.cmp(num) >= 0;
  4046. };
  4047. BN.prototype.ltn = function ltn (num) {
  4048. return this.cmpn(num) === -1;
  4049. };
  4050. BN.prototype.lt = function lt (num) {
  4051. return this.cmp(num) === -1;
  4052. };
  4053. BN.prototype.lten = function lten (num) {
  4054. return this.cmpn(num) <= 0;
  4055. };
  4056. BN.prototype.lte = function lte (num) {
  4057. return this.cmp(num) <= 0;
  4058. };
  4059. BN.prototype.eqn = function eqn (num) {
  4060. return this.cmpn(num) === 0;
  4061. };
  4062. BN.prototype.eq = function eq (num) {
  4063. return this.cmp(num) === 0;
  4064. };
  4065. //
  4066. // A reduce context, could be using montgomery or something better, depending
  4067. // on the `m` itself.
  4068. //
  4069. BN.red = function red (num) {
  4070. return new Red(num);
  4071. };
  4072. BN.prototype.toRed = function toRed (ctx) {
  4073. assert(!this.red, 'Already a number in reduction context');
  4074. assert(this.negative === 0, 'red works only with positives');
  4075. return ctx.convertTo(this)._forceRed(ctx);
  4076. };
  4077. BN.prototype.fromRed = function fromRed () {
  4078. assert(this.red, 'fromRed works only with numbers in reduction context');
  4079. return this.red.convertFrom(this);
  4080. };
  4081. BN.prototype._forceRed = function _forceRed (ctx) {
  4082. this.red = ctx;
  4083. return this;
  4084. };
  4085. BN.prototype.forceRed = function forceRed (ctx) {
  4086. assert(!this.red, 'Already a number in reduction context');
  4087. return this._forceRed(ctx);
  4088. };
  4089. BN.prototype.redAdd = function redAdd (num) {
  4090. assert(this.red, 'redAdd works only with red numbers');
  4091. return this.red.add(this, num);
  4092. };
  4093. BN.prototype.redIAdd = function redIAdd (num) {
  4094. assert(this.red, 'redIAdd works only with red numbers');
  4095. return this.red.iadd(this, num);
  4096. };
  4097. BN.prototype.redSub = function redSub (num) {
  4098. assert(this.red, 'redSub works only with red numbers');
  4099. return this.red.sub(this, num);
  4100. };
  4101. BN.prototype.redISub = function redISub (num) {
  4102. assert(this.red, 'redISub works only with red numbers');
  4103. return this.red.isub(this, num);
  4104. };
  4105. BN.prototype.redShl = function redShl (num) {
  4106. assert(this.red, 'redShl works only with red numbers');
  4107. return this.red.shl(this, num);
  4108. };
  4109. BN.prototype.redMul = function redMul (num) {
  4110. assert(this.red, 'redMul works only with red numbers');
  4111. this.red._verify2(this, num);
  4112. return this.red.mul(this, num);
  4113. };
  4114. BN.prototype.redIMul = function redIMul (num) {
  4115. assert(this.red, 'redMul works only with red numbers');
  4116. this.red._verify2(this, num);
  4117. return this.red.imul(this, num);
  4118. };
  4119. BN.prototype.redSqr = function redSqr () {
  4120. assert(this.red, 'redSqr works only with red numbers');
  4121. this.red._verify1(this);
  4122. return this.red.sqr(this);
  4123. };
  4124. BN.prototype.redISqr = function redISqr () {
  4125. assert(this.red, 'redISqr works only with red numbers');
  4126. this.red._verify1(this);
  4127. return this.red.isqr(this);
  4128. };
  4129. // Square root over p
  4130. BN.prototype.redSqrt = function redSqrt () {
  4131. assert(this.red, 'redSqrt works only with red numbers');
  4132. this.red._verify1(this);
  4133. return this.red.sqrt(this);
  4134. };
  4135. BN.prototype.redInvm = function redInvm () {
  4136. assert(this.red, 'redInvm works only with red numbers');
  4137. this.red._verify1(this);
  4138. return this.red.invm(this);
  4139. };
  4140. // Return negative clone of `this` % `red modulo`
  4141. BN.prototype.redNeg = function redNeg () {
  4142. assert(this.red, 'redNeg works only with red numbers');
  4143. this.red._verify1(this);
  4144. return this.red.neg(this);
  4145. };
  4146. BN.prototype.redPow = function redPow (num) {
  4147. assert(this.red && !num.red, 'redPow(normalNum)');
  4148. this.red._verify1(this);
  4149. return this.red.pow(this, num);
  4150. };
  4151. // Prime numbers with efficient reduction
  4152. var primes = {
  4153. k256: null,
  4154. p224: null,
  4155. p192: null,
  4156. p25519: null
  4157. };
  4158. // Pseudo-Mersenne prime
  4159. function MPrime (name, p) {
  4160. // P = 2 ^ N - K
  4161. this.name = name;
  4162. this.p = new BN(p, 16);
  4163. this.n = this.p.bitLength();
  4164. this.k = new BN(1).iushln(this.n).isub(this.p);
  4165. this.tmp = this._tmp();
  4166. }
  4167. MPrime.prototype._tmp = function _tmp () {
  4168. var tmp = new BN(null);
  4169. tmp.words = new Array(Math.ceil(this.n / 13));
  4170. return tmp;
  4171. };
  4172. MPrime.prototype.ireduce = function ireduce (num) {
  4173. // Assumes that `num` is less than `P^2`
  4174. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  4175. var r = num;
  4176. var rlen;
  4177. do {
  4178. this.split(r, this.tmp);
  4179. r = this.imulK(r);
  4180. r = r.iadd(this.tmp);
  4181. rlen = r.bitLength();
  4182. } while (rlen > this.n);
  4183. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  4184. if (cmp === 0) {
  4185. r.words[0] = 0;
  4186. r.length = 1;
  4187. } else if (cmp > 0) {
  4188. r.isub(this.p);
  4189. } else {
  4190. r.strip();
  4191. }
  4192. return r;
  4193. };
  4194. MPrime.prototype.split = function split (input, out) {
  4195. input.iushrn(this.n, 0, out);
  4196. };
  4197. MPrime.prototype.imulK = function imulK (num) {
  4198. return num.imul(this.k);
  4199. };
  4200. function K256 () {
  4201. MPrime.call(
  4202. this,
  4203. 'k256',
  4204. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  4205. }
  4206. inherits(K256, MPrime);
  4207. K256.prototype.split = function split (input, output) {
  4208. // 256 = 9 * 26 + 22
  4209. var mask = 0x3fffff;
  4210. var outLen = Math.min(input.length, 9);
  4211. for (var i = 0; i < outLen; i++) {
  4212. output.words[i] = input.words[i];
  4213. }
  4214. output.length = outLen;
  4215. if (input.length <= 9) {
  4216. input.words[0] = 0;
  4217. input.length = 1;
  4218. return;
  4219. }
  4220. // Shift by 9 limbs
  4221. var prev = input.words[9];
  4222. output.words[output.length++] = prev & mask;
  4223. for (i = 10; i < input.length; i++) {
  4224. var next = input.words[i] | 0;
  4225. input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
  4226. prev = next;
  4227. }
  4228. prev >>>= 22;
  4229. input.words[i - 10] = prev;
  4230. if (prev === 0 && input.length > 10) {
  4231. input.length -= 10;
  4232. } else {
  4233. input.length -= 9;
  4234. }
  4235. };
  4236. K256.prototype.imulK = function imulK (num) {
  4237. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  4238. num.words[num.length] = 0;
  4239. num.words[num.length + 1] = 0;
  4240. num.length += 2;
  4241. // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  4242. var lo = 0;
  4243. for (var i = 0; i < num.length; i++) {
  4244. var w = num.words[i] | 0;
  4245. lo += w * 0x3d1;
  4246. num.words[i] = lo & 0x3ffffff;
  4247. lo = w * 0x40 + ((lo / 0x4000000) | 0);
  4248. }
  4249. // Fast length reduction
  4250. if (num.words[num.length - 1] === 0) {
  4251. num.length--;
  4252. if (num.words[num.length - 1] === 0) {
  4253. num.length--;
  4254. }
  4255. }
  4256. return num;
  4257. };
  4258. function P224 () {
  4259. MPrime.call(
  4260. this,
  4261. 'p224',
  4262. 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  4263. }
  4264. inherits(P224, MPrime);
  4265. function P192 () {
  4266. MPrime.call(
  4267. this,
  4268. 'p192',
  4269. 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  4270. }
  4271. inherits(P192, MPrime);
  4272. function P25519 () {
  4273. // 2 ^ 255 - 19
  4274. MPrime.call(
  4275. this,
  4276. '25519',
  4277. '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  4278. }
  4279. inherits(P25519, MPrime);
  4280. P25519.prototype.imulK = function imulK (num) {
  4281. // K = 0x13
  4282. var carry = 0;
  4283. for (var i = 0; i < num.length; i++) {
  4284. var hi = (num.words[i] | 0) * 0x13 + carry;
  4285. var lo = hi & 0x3ffffff;
  4286. hi >>>= 26;
  4287. num.words[i] = lo;
  4288. carry = hi;
  4289. }
  4290. if (carry !== 0) {
  4291. num.words[num.length++] = carry;
  4292. }
  4293. return num;
  4294. };
  4295. // Exported mostly for testing purposes, use plain name instead
  4296. BN._prime = function prime (name) {
  4297. // Cached version of prime
  4298. if (primes[name]) return primes[name];
  4299. var prime;
  4300. if (name === 'k256') {
  4301. prime = new K256();
  4302. } else if (name === 'p224') {
  4303. prime = new P224();
  4304. } else if (name === 'p192') {
  4305. prime = new P192();
  4306. } else if (name === 'p25519') {
  4307. prime = new P25519();
  4308. } else {
  4309. throw new Error('Unknown prime ' + name);
  4310. }
  4311. primes[name] = prime;
  4312. return prime;
  4313. };
  4314. //
  4315. // Base reduction engine
  4316. //
  4317. function Red (m) {
  4318. if (typeof m === 'string') {
  4319. var prime = BN._prime(m);
  4320. this.m = prime.p;
  4321. this.prime = prime;
  4322. } else {
  4323. assert(m.gtn(1), 'modulus must be greater than 1');
  4324. this.m = m;
  4325. this.prime = null;
  4326. }
  4327. }
  4328. Red.prototype._verify1 = function _verify1 (a) {
  4329. assert(a.negative === 0, 'red works only with positives');
  4330. assert(a.red, 'red works only with red numbers');
  4331. };
  4332. Red.prototype._verify2 = function _verify2 (a, b) {
  4333. assert((a.negative | b.negative) === 0, 'red works only with positives');
  4334. assert(a.red && a.red === b.red,
  4335. 'red works only with red numbers');
  4336. };
  4337. Red.prototype.imod = function imod (a) {
  4338. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  4339. return a.umod(this.m)._forceRed(this);
  4340. };
  4341. Red.prototype.neg = function neg (a) {
  4342. if (a.isZero()) {
  4343. return a.clone();
  4344. }
  4345. return this.m.sub(a)._forceRed(this);
  4346. };
  4347. Red.prototype.add = function add (a, b) {
  4348. this._verify2(a, b);
  4349. var res = a.add(b);
  4350. if (res.cmp(this.m) >= 0) {
  4351. res.isub(this.m);
  4352. }
  4353. return res._forceRed(this);
  4354. };
  4355. Red.prototype.iadd = function iadd (a, b) {
  4356. this._verify2(a, b);
  4357. var res = a.iadd(b);
  4358. if (res.cmp(this.m) >= 0) {
  4359. res.isub(this.m);
  4360. }
  4361. return res;
  4362. };
  4363. Red.prototype.sub = function sub (a, b) {
  4364. this._verify2(a, b);
  4365. var res = a.sub(b);
  4366. if (res.cmpn(0) < 0) {
  4367. res.iadd(this.m);
  4368. }
  4369. return res._forceRed(this);
  4370. };
  4371. Red.prototype.isub = function isub (a, b) {
  4372. this._verify2(a, b);
  4373. var res = a.isub(b);
  4374. if (res.cmpn(0) < 0) {
  4375. res.iadd(this.m);
  4376. }
  4377. return res;
  4378. };
  4379. Red.prototype.shl = function shl (a, num) {
  4380. this._verify1(a);
  4381. return this.imod(a.ushln(num));
  4382. };
  4383. Red.prototype.imul = function imul (a, b) {
  4384. this._verify2(a, b);
  4385. return this.imod(a.imul(b));
  4386. };
  4387. Red.prototype.mul = function mul (a, b) {
  4388. this._verify2(a, b);
  4389. return this.imod(a.mul(b));
  4390. };
  4391. Red.prototype.isqr = function isqr (a) {
  4392. return this.imul(a, a.clone());
  4393. };
  4394. Red.prototype.sqr = function sqr (a) {
  4395. return this.mul(a, a);
  4396. };
  4397. Red.prototype.sqrt = function sqrt (a) {
  4398. if (a.isZero()) return a.clone();
  4399. var mod3 = this.m.andln(3);
  4400. assert(mod3 % 2 === 1);
  4401. // Fast case
  4402. if (mod3 === 3) {
  4403. var pow = this.m.add(new BN(1)).iushrn(2);
  4404. return this.pow(a, pow);
  4405. }
  4406. // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  4407. //
  4408. // Find Q and S, that Q * 2 ^ S = (P - 1)
  4409. var q = this.m.subn(1);
  4410. var s = 0;
  4411. while (!q.isZero() && q.andln(1) === 0) {
  4412. s++;
  4413. q.iushrn(1);
  4414. }
  4415. assert(!q.isZero());
  4416. var one = new BN(1).toRed(this);
  4417. var nOne = one.redNeg();
  4418. // Find quadratic non-residue
  4419. // NOTE: Max is such because of generalized Riemann hypothesis.
  4420. var lpow = this.m.subn(1).iushrn(1);
  4421. var z = this.m.bitLength();
  4422. z = new BN(2 * z * z).toRed(this);
  4423. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  4424. z.redIAdd(nOne);
  4425. }
  4426. var c = this.pow(z, q);
  4427. var r = this.pow(a, q.addn(1).iushrn(1));
  4428. var t = this.pow(a, q);
  4429. var m = s;
  4430. while (t.cmp(one) !== 0) {
  4431. var tmp = t;
  4432. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  4433. tmp = tmp.redSqr();
  4434. }
  4435. assert(i < m);
  4436. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  4437. r = r.redMul(b);
  4438. c = b.redSqr();
  4439. t = t.redMul(c);
  4440. m = i;
  4441. }
  4442. return r;
  4443. };
  4444. Red.prototype.invm = function invm (a) {
  4445. var inv = a._invmp(this.m);
  4446. if (inv.negative !== 0) {
  4447. inv.negative = 0;
  4448. return this.imod(inv).redNeg();
  4449. } else {
  4450. return this.imod(inv);
  4451. }
  4452. };
  4453. Red.prototype.pow = function pow (a, num) {
  4454. if (num.isZero()) return new BN(1);
  4455. if (num.cmpn(1) === 0) return a.clone();
  4456. var windowSize = 4;
  4457. var wnd = new Array(1 << windowSize);
  4458. wnd[0] = new BN(1).toRed(this);
  4459. wnd[1] = a;
  4460. for (var i = 2; i < wnd.length; i++) {
  4461. wnd[i] = this.mul(wnd[i - 1], a);
  4462. }
  4463. var res = wnd[0];
  4464. var current = 0;
  4465. var currentLen = 0;
  4466. var start = num.bitLength() % 26;
  4467. if (start === 0) {
  4468. start = 26;
  4469. }
  4470. for (i = num.length - 1; i >= 0; i--) {
  4471. var word = num.words[i];
  4472. for (var j = start - 1; j >= 0; j--) {
  4473. var bit = (word >> j) & 1;
  4474. if (res !== wnd[0]) {
  4475. res = this.sqr(res);
  4476. }
  4477. if (bit === 0 && current === 0) {
  4478. currentLen = 0;
  4479. continue;
  4480. }
  4481. current <<= 1;
  4482. current |= bit;
  4483. currentLen++;
  4484. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  4485. res = this.mul(res, wnd[current]);
  4486. currentLen = 0;
  4487. current = 0;
  4488. }
  4489. start = 26;
  4490. }
  4491. return res;
  4492. };
  4493. Red.prototype.convertTo = function convertTo (num) {
  4494. var r = num.umod(this.m);
  4495. return r === num ? r.clone() : r;
  4496. };
  4497. Red.prototype.convertFrom = function convertFrom (num) {
  4498. var res = num.clone();
  4499. res.red = null;
  4500. return res;
  4501. };
  4502. //
  4503. // Montgomery method engine
  4504. //
  4505. BN.mont = function mont (num) {
  4506. return new Mont(num);
  4507. };
  4508. function Mont (m) {
  4509. Red.call(this, m);
  4510. this.shift = this.m.bitLength();
  4511. if (this.shift % 26 !== 0) {
  4512. this.shift += 26 - (this.shift % 26);
  4513. }
  4514. this.r = new BN(1).iushln(this.shift);
  4515. this.r2 = this.imod(this.r.sqr());
  4516. this.rinv = this.r._invmp(this.m);
  4517. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  4518. this.minv = this.minv.umod(this.r);
  4519. this.minv = this.r.sub(this.minv);
  4520. }
  4521. inherits(Mont, Red);
  4522. Mont.prototype.convertTo = function convertTo (num) {
  4523. return this.imod(num.ushln(this.shift));
  4524. };
  4525. Mont.prototype.convertFrom = function convertFrom (num) {
  4526. var r = this.imod(num.mul(this.rinv));
  4527. r.red = null;
  4528. return r;
  4529. };
  4530. Mont.prototype.imul = function imul (a, b) {
  4531. if (a.isZero() || b.isZero()) {
  4532. a.words[0] = 0;
  4533. a.length = 1;
  4534. return a;
  4535. }
  4536. var t = a.imul(b);
  4537. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  4538. var u = t.isub(c).iushrn(this.shift);
  4539. var res = u;
  4540. if (u.cmp(this.m) >= 0) {
  4541. res = u.isub(this.m);
  4542. } else if (u.cmpn(0) < 0) {
  4543. res = u.iadd(this.m);
  4544. }
  4545. return res._forceRed(this);
  4546. };
  4547. Mont.prototype.mul = function mul (a, b) {
  4548. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  4549. var t = a.mul(b);
  4550. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  4551. var u = t.isub(c).iushrn(this.shift);
  4552. var res = u;
  4553. if (u.cmp(this.m) >= 0) {
  4554. res = u.isub(this.m);
  4555. } else if (u.cmpn(0) < 0) {
  4556. res = u.iadd(this.m);
  4557. }
  4558. return res._forceRed(this);
  4559. };
  4560. Mont.prototype.invm = function invm (a) {
  4561. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  4562. var res = this.imod(a._invmp(this.m).mul(this.r2));
  4563. return res._forceRed(this);
  4564. };
  4565. })(typeof module === 'undefined' || module, this);
  4566. },{}],19:[function(require,module,exports){
  4567. var r;
  4568. module.exports = function rand(len) {
  4569. if (!r)
  4570. r = new Rand(null);
  4571. return r.generate(len);
  4572. };
  4573. function Rand(rand) {
  4574. this.rand = rand;
  4575. }
  4576. module.exports.Rand = Rand;
  4577. Rand.prototype.generate = function generate(len) {
  4578. return this._rand(len);
  4579. };
  4580. if (typeof window === 'object') {
  4581. if (window.crypto && window.crypto.getRandomValues) {
  4582. // Modern browsers
  4583. Rand.prototype._rand = function _rand(n) {
  4584. var arr = new Uint8Array(n);
  4585. window.crypto.getRandomValues(arr);
  4586. return arr;
  4587. };
  4588. } else if (window.msCrypto && window.msCrypto.getRandomValues) {
  4589. // IE
  4590. Rand.prototype._rand = function _rand(n) {
  4591. var arr = new Uint8Array(n);
  4592. window.msCrypto.getRandomValues(arr);
  4593. return arr;
  4594. };
  4595. } else {
  4596. // Old junk
  4597. Rand.prototype._rand = function() {
  4598. throw new Error('Not implemented yet');
  4599. };
  4600. }
  4601. } else {
  4602. // Node.js or Web worker
  4603. try {
  4604. var crypto = require('cry' + 'pto');
  4605. Rand.prototype._rand = function _rand(n) {
  4606. return crypto.randomBytes(n);
  4607. };
  4608. } catch (e) {
  4609. // Emulate crypto API using randy
  4610. Rand.prototype._rand = function _rand(n) {
  4611. var res = new Uint8Array(n);
  4612. for (var i = 0; i < res.length; i++)
  4613. res[i] = this.rand.getByte();
  4614. return res;
  4615. };
  4616. }
  4617. }
  4618. },{}],20:[function(require,module,exports){
  4619. },{}],21:[function(require,module,exports){
  4620. (function (Buffer){
  4621. // based on the aes implimentation in triple sec
  4622. // https://github.com/keybase/triplesec
  4623. // which is in turn based on the one from crypto-js
  4624. // https://code.google.com/p/crypto-js/
  4625. var uint_max = Math.pow(2, 32)
  4626. function fixup_uint32 (x) {
  4627. var ret, x_pos
  4628. ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x
  4629. return ret
  4630. }
  4631. function scrub_vec (v) {
  4632. for (var i = 0; i < v.length; v++) {
  4633. v[i] = 0
  4634. }
  4635. return false
  4636. }
  4637. function Global () {
  4638. this.SBOX = []
  4639. this.INV_SBOX = []
  4640. this.SUB_MIX = [[], [], [], []]
  4641. this.INV_SUB_MIX = [[], [], [], []]
  4642. this.init()
  4643. this.RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
  4644. }
  4645. Global.prototype.init = function () {
  4646. var d, i, sx, t, x, x2, x4, x8, xi, _i
  4647. d = (function () {
  4648. var _i, _results
  4649. _results = []
  4650. for (i = _i = 0; _i < 256; i = ++_i) {
  4651. if (i < 128) {
  4652. _results.push(i << 1)
  4653. } else {
  4654. _results.push((i << 1) ^ 0x11b)
  4655. }
  4656. }
  4657. return _results
  4658. })()
  4659. x = 0
  4660. xi = 0
  4661. for (i = _i = 0; _i < 256; i = ++_i) {
  4662. sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
  4663. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63
  4664. this.SBOX[x] = sx
  4665. this.INV_SBOX[sx] = x
  4666. x2 = d[x]
  4667. x4 = d[x2]
  4668. x8 = d[x4]
  4669. t = (d[sx] * 0x101) ^ (sx * 0x1010100)
  4670. this.SUB_MIX[0][x] = (t << 24) | (t >>> 8)
  4671. this.SUB_MIX[1][x] = (t << 16) | (t >>> 16)
  4672. this.SUB_MIX[2][x] = (t << 8) | (t >>> 24)
  4673. this.SUB_MIX[3][x] = t
  4674. t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100)
  4675. this.INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
  4676. this.INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
  4677. this.INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
  4678. this.INV_SUB_MIX[3][sx] = t
  4679. if (x === 0) {
  4680. x = xi = 1
  4681. } else {
  4682. x = x2 ^ d[d[d[x8 ^ x2]]]
  4683. xi ^= d[d[xi]]
  4684. }
  4685. }
  4686. return true
  4687. }
  4688. var G = new Global()
  4689. AES.blockSize = 4 * 4
  4690. AES.prototype.blockSize = AES.blockSize
  4691. AES.keySize = 256 / 8
  4692. AES.prototype.keySize = AES.keySize
  4693. function bufferToArray (buf) {
  4694. var len = buf.length / 4
  4695. var out = new Array(len)
  4696. var i = -1
  4697. while (++i < len) {
  4698. out[i] = buf.readUInt32BE(i * 4)
  4699. }
  4700. return out
  4701. }
  4702. function AES (key) {
  4703. this._key = bufferToArray(key)
  4704. this._doReset()
  4705. }
  4706. AES.prototype._doReset = function () {
  4707. var invKsRow, keySize, keyWords, ksRow, ksRows, t
  4708. keyWords = this._key
  4709. keySize = keyWords.length
  4710. this._nRounds = keySize + 6
  4711. ksRows = (this._nRounds + 1) * 4
  4712. this._keySchedule = []
  4713. for (ksRow = 0; ksRow < ksRows; ksRow++) {
  4714. this._keySchedule[ksRow] = ksRow < keySize ? keyWords[ksRow] : (t = this._keySchedule[ksRow - 1], (ksRow % keySize) === 0 ? (t = (t << 8) | (t >>> 24), t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff], t ^= G.RCON[(ksRow / keySize) | 0] << 24) : keySize > 6 && ksRow % keySize === 4 ? t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff] : void 0, this._keySchedule[ksRow - keySize] ^ t)
  4715. }
  4716. this._invKeySchedule = []
  4717. for (invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  4718. ksRow = ksRows - invKsRow
  4719. t = this._keySchedule[ksRow - (invKsRow % 4 ? 0 : 4)]
  4720. this._invKeySchedule[invKsRow] = invKsRow < 4 || ksRow <= 4 ? t : G.INV_SUB_MIX[0][G.SBOX[t >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[(t >>> 16) & 0xff]] ^ G.INV_SUB_MIX[2][G.SBOX[(t >>> 8) & 0xff]] ^ G.INV_SUB_MIX[3][G.SBOX[t & 0xff]]
  4721. }
  4722. return true
  4723. }
  4724. AES.prototype.encryptBlock = function (M) {
  4725. M = bufferToArray(new Buffer(M))
  4726. var out = this._doCryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX)
  4727. var buf = new Buffer(16)
  4728. buf.writeUInt32BE(out[0], 0)
  4729. buf.writeUInt32BE(out[1], 4)
  4730. buf.writeUInt32BE(out[2], 8)
  4731. buf.writeUInt32BE(out[3], 12)
  4732. return buf
  4733. }
  4734. AES.prototype.decryptBlock = function (M) {
  4735. M = bufferToArray(new Buffer(M))
  4736. var temp = [M[3], M[1]]
  4737. M[1] = temp[0]
  4738. M[3] = temp[1]
  4739. var out = this._doCryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX)
  4740. var buf = new Buffer(16)
  4741. buf.writeUInt32BE(out[0], 0)
  4742. buf.writeUInt32BE(out[3], 4)
  4743. buf.writeUInt32BE(out[2], 8)
  4744. buf.writeUInt32BE(out[1], 12)
  4745. return buf
  4746. }
  4747. AES.prototype.scrub = function () {
  4748. scrub_vec(this._keySchedule)
  4749. scrub_vec(this._invKeySchedule)
  4750. scrub_vec(this._key)
  4751. }
  4752. AES.prototype._doCryptBlock = function (M, keySchedule, SUB_MIX, SBOX) {
  4753. var ksRow, s0, s1, s2, s3, t0, t1, t2, t3
  4754. s0 = M[0] ^ keySchedule[0]
  4755. s1 = M[1] ^ keySchedule[1]
  4756. s2 = M[2] ^ keySchedule[2]
  4757. s3 = M[3] ^ keySchedule[3]
  4758. ksRow = 4
  4759. for (var round = 1; round < this._nRounds; round++) {
  4760. t0 = SUB_MIX[0][s0 >>> 24] ^ SUB_MIX[1][(s1 >>> 16) & 0xff] ^ SUB_MIX[2][(s2 >>> 8) & 0xff] ^ SUB_MIX[3][s3 & 0xff] ^ keySchedule[ksRow++]
  4761. t1 = SUB_MIX[0][s1 >>> 24] ^ SUB_MIX[1][(s2 >>> 16) & 0xff] ^ SUB_MIX[2][(s3 >>> 8) & 0xff] ^ SUB_MIX[3][s0 & 0xff] ^ keySchedule[ksRow++]
  4762. t2 = SUB_MIX[0][s2 >>> 24] ^ SUB_MIX[1][(s3 >>> 16) & 0xff] ^ SUB_MIX[2][(s0 >>> 8) & 0xff] ^ SUB_MIX[3][s1 & 0xff] ^ keySchedule[ksRow++]
  4763. t3 = SUB_MIX[0][s3 >>> 24] ^ SUB_MIX[1][(s0 >>> 16) & 0xff] ^ SUB_MIX[2][(s1 >>> 8) & 0xff] ^ SUB_MIX[3][s2 & 0xff] ^ keySchedule[ksRow++]
  4764. s0 = t0
  4765. s1 = t1
  4766. s2 = t2
  4767. s3 = t3
  4768. }
  4769. t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]
  4770. t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]
  4771. t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]
  4772. t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]
  4773. return [
  4774. fixup_uint32(t0),
  4775. fixup_uint32(t1),
  4776. fixup_uint32(t2),
  4777. fixup_uint32(t3)
  4778. ]
  4779. }
  4780. exports.AES = AES
  4781. }).call(this,require("buffer").Buffer)
  4782. },{"buffer":46}],22:[function(require,module,exports){
  4783. (function (Buffer){
  4784. var aes = require('./aes')
  4785. var Transform = require('cipher-base')
  4786. var inherits = require('inherits')
  4787. var GHASH = require('./ghash')
  4788. var xor = require('buffer-xor')
  4789. inherits(StreamCipher, Transform)
  4790. module.exports = StreamCipher
  4791. function StreamCipher (mode, key, iv, decrypt) {
  4792. if (!(this instanceof StreamCipher)) {
  4793. return new StreamCipher(mode, key, iv)
  4794. }
  4795. Transform.call(this)
  4796. this._finID = Buffer.concat([iv, new Buffer([0, 0, 0, 1])])
  4797. iv = Buffer.concat([iv, new Buffer([0, 0, 0, 2])])
  4798. this._cipher = new aes.AES(key)
  4799. this._prev = new Buffer(iv.length)
  4800. this._cache = new Buffer('')
  4801. this._secCache = new Buffer('')
  4802. this._decrypt = decrypt
  4803. this._alen = 0
  4804. this._len = 0
  4805. iv.copy(this._prev)
  4806. this._mode = mode
  4807. var h = new Buffer(4)
  4808. h.fill(0)
  4809. this._ghash = new GHASH(this._cipher.encryptBlock(h))
  4810. this._authTag = null
  4811. this._called = false
  4812. }
  4813. StreamCipher.prototype._update = function (chunk) {
  4814. if (!this._called && this._alen) {
  4815. var rump = 16 - (this._alen % 16)
  4816. if (rump < 16) {
  4817. rump = new Buffer(rump)
  4818. rump.fill(0)
  4819. this._ghash.update(rump)
  4820. }
  4821. }
  4822. this._called = true
  4823. var out = this._mode.encrypt(this, chunk)
  4824. if (this._decrypt) {
  4825. this._ghash.update(chunk)
  4826. } else {
  4827. this._ghash.update(out)
  4828. }
  4829. this._len += chunk.length
  4830. return out
  4831. }
  4832. StreamCipher.prototype._final = function () {
  4833. if (this._decrypt && !this._authTag) {
  4834. throw new Error('Unsupported state or unable to authenticate data')
  4835. }
  4836. var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID))
  4837. if (this._decrypt) {
  4838. if (xorTest(tag, this._authTag)) {
  4839. throw new Error('Unsupported state or unable to authenticate data')
  4840. }
  4841. } else {
  4842. this._authTag = tag
  4843. }
  4844. this._cipher.scrub()
  4845. }
  4846. StreamCipher.prototype.getAuthTag = function getAuthTag () {
  4847. if (!this._decrypt && Buffer.isBuffer(this._authTag)) {
  4848. return this._authTag
  4849. } else {
  4850. throw new Error('Attempting to get auth tag in unsupported state')
  4851. }
  4852. }
  4853. StreamCipher.prototype.setAuthTag = function setAuthTag (tag) {
  4854. if (this._decrypt) {
  4855. this._authTag = tag
  4856. } else {
  4857. throw new Error('Attempting to set auth tag in unsupported state')
  4858. }
  4859. }
  4860. StreamCipher.prototype.setAAD = function setAAD (buf) {
  4861. if (!this._called) {
  4862. this._ghash.update(buf)
  4863. this._alen += buf.length
  4864. } else {
  4865. throw new Error('Attempting to set AAD in unsupported state')
  4866. }
  4867. }
  4868. function xorTest (a, b) {
  4869. var out = 0
  4870. if (a.length !== b.length) {
  4871. out++
  4872. }
  4873. var len = Math.min(a.length, b.length)
  4874. var i = -1
  4875. while (++i < len) {
  4876. out += (a[i] ^ b[i])
  4877. }
  4878. return out
  4879. }
  4880. }).call(this,require("buffer").Buffer)
  4881. },{"./aes":21,"./ghash":26,"buffer":46,"buffer-xor":45,"cipher-base":47,"inherits":92}],23:[function(require,module,exports){
  4882. var ciphers = require('./encrypter')
  4883. exports.createCipher = exports.Cipher = ciphers.createCipher
  4884. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv
  4885. var deciphers = require('./decrypter')
  4886. exports.createDecipher = exports.Decipher = deciphers.createDecipher
  4887. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv
  4888. var modes = require('./modes')
  4889. function getCiphers () {
  4890. return Object.keys(modes)
  4891. }
  4892. exports.listCiphers = exports.getCiphers = getCiphers
  4893. },{"./decrypter":24,"./encrypter":25,"./modes":27}],24:[function(require,module,exports){
  4894. (function (Buffer){
  4895. var aes = require('./aes')
  4896. var Transform = require('cipher-base')
  4897. var inherits = require('inherits')
  4898. var modes = require('./modes')
  4899. var StreamCipher = require('./streamCipher')
  4900. var AuthCipher = require('./authCipher')
  4901. var ebtk = require('evp_bytestokey')
  4902. inherits(Decipher, Transform)
  4903. function Decipher (mode, key, iv) {
  4904. if (!(this instanceof Decipher)) {
  4905. return new Decipher(mode, key, iv)
  4906. }
  4907. Transform.call(this)
  4908. this._cache = new Splitter()
  4909. this._last = void 0
  4910. this._cipher = new aes.AES(key)
  4911. this._prev = new Buffer(iv.length)
  4912. iv.copy(this._prev)
  4913. this._mode = mode
  4914. this._autopadding = true
  4915. }
  4916. Decipher.prototype._update = function (data) {
  4917. this._cache.add(data)
  4918. var chunk
  4919. var thing
  4920. var out = []
  4921. while ((chunk = this._cache.get(this._autopadding))) {
  4922. thing = this._mode.decrypt(this, chunk)
  4923. out.push(thing)
  4924. }
  4925. return Buffer.concat(out)
  4926. }
  4927. Decipher.prototype._final = function () {
  4928. var chunk = this._cache.flush()
  4929. if (this._autopadding) {
  4930. return unpad(this._mode.decrypt(this, chunk))
  4931. } else if (chunk) {
  4932. throw new Error('data not multiple of block length')
  4933. }
  4934. }
  4935. Decipher.prototype.setAutoPadding = function (setTo) {
  4936. this._autopadding = !!setTo
  4937. return this
  4938. }
  4939. function Splitter () {
  4940. if (!(this instanceof Splitter)) {
  4941. return new Splitter()
  4942. }
  4943. this.cache = new Buffer('')
  4944. }
  4945. Splitter.prototype.add = function (data) {
  4946. this.cache = Buffer.concat([this.cache, data])
  4947. }
  4948. Splitter.prototype.get = function (autoPadding) {
  4949. var out
  4950. if (autoPadding) {
  4951. if (this.cache.length > 16) {
  4952. out = this.cache.slice(0, 16)
  4953. this.cache = this.cache.slice(16)
  4954. return out
  4955. }
  4956. } else {
  4957. if (this.cache.length >= 16) {
  4958. out = this.cache.slice(0, 16)
  4959. this.cache = this.cache.slice(16)
  4960. return out
  4961. }
  4962. }
  4963. return null
  4964. }
  4965. Splitter.prototype.flush = function () {
  4966. if (this.cache.length) {
  4967. return this.cache
  4968. }
  4969. }
  4970. function unpad (last) {
  4971. var padded = last[15]
  4972. var i = -1
  4973. while (++i < padded) {
  4974. if (last[(i + (16 - padded))] !== padded) {
  4975. throw new Error('unable to decrypt data')
  4976. }
  4977. }
  4978. if (padded === 16) {
  4979. return
  4980. }
  4981. return last.slice(0, 16 - padded)
  4982. }
  4983. var modelist = {
  4984. ECB: require('./modes/ecb'),
  4985. CBC: require('./modes/cbc'),
  4986. CFB: require('./modes/cfb'),
  4987. CFB8: require('./modes/cfb8'),
  4988. CFB1: require('./modes/cfb1'),
  4989. OFB: require('./modes/ofb'),
  4990. CTR: require('./modes/ctr'),
  4991. GCM: require('./modes/ctr')
  4992. }
  4993. function createDecipheriv (suite, password, iv) {
  4994. var config = modes[suite.toLowerCase()]
  4995. if (!config) {
  4996. throw new TypeError('invalid suite type')
  4997. }
  4998. if (typeof iv === 'string') {
  4999. iv = new Buffer(iv)
  5000. }
  5001. if (typeof password === 'string') {
  5002. password = new Buffer(password)
  5003. }
  5004. if (password.length !== config.key / 8) {
  5005. throw new TypeError('invalid key length ' + password.length)
  5006. }
  5007. if (iv.length !== config.iv) {
  5008. throw new TypeError('invalid iv length ' + iv.length)
  5009. }
  5010. if (config.type === 'stream') {
  5011. return new StreamCipher(modelist[config.mode], password, iv, true)
  5012. } else if (config.type === 'auth') {
  5013. return new AuthCipher(modelist[config.mode], password, iv, true)
  5014. }
  5015. return new Decipher(modelist[config.mode], password, iv)
  5016. }
  5017. function createDecipher (suite, password) {
  5018. var config = modes[suite.toLowerCase()]
  5019. if (!config) {
  5020. throw new TypeError('invalid suite type')
  5021. }
  5022. var keys = ebtk(password, false, config.key, config.iv)
  5023. return createDecipheriv(suite, keys.key, keys.iv)
  5024. }
  5025. exports.createDecipher = createDecipher
  5026. exports.createDecipheriv = createDecipheriv
  5027. }).call(this,require("buffer").Buffer)
  5028. },{"./aes":21,"./authCipher":22,"./modes":27,"./modes/cbc":28,"./modes/cfb":29,"./modes/cfb1":30,"./modes/cfb8":31,"./modes/ctr":32,"./modes/ecb":33,"./modes/ofb":34,"./streamCipher":35,"buffer":46,"cipher-base":47,"evp_bytestokey":83,"inherits":92}],25:[function(require,module,exports){
  5029. (function (Buffer){
  5030. var aes = require('./aes')
  5031. var Transform = require('cipher-base')
  5032. var inherits = require('inherits')
  5033. var modes = require('./modes')
  5034. var ebtk = require('evp_bytestokey')
  5035. var StreamCipher = require('./streamCipher')
  5036. var AuthCipher = require('./authCipher')
  5037. inherits(Cipher, Transform)
  5038. function Cipher (mode, key, iv) {
  5039. if (!(this instanceof Cipher)) {
  5040. return new Cipher(mode, key, iv)
  5041. }
  5042. Transform.call(this)
  5043. this._cache = new Splitter()
  5044. this._cipher = new aes.AES(key)
  5045. this._prev = new Buffer(iv.length)
  5046. iv.copy(this._prev)
  5047. this._mode = mode
  5048. this._autopadding = true
  5049. }
  5050. Cipher.prototype._update = function (data) {
  5051. this._cache.add(data)
  5052. var chunk
  5053. var thing
  5054. var out = []
  5055. while ((chunk = this._cache.get())) {
  5056. thing = this._mode.encrypt(this, chunk)
  5057. out.push(thing)
  5058. }
  5059. return Buffer.concat(out)
  5060. }
  5061. Cipher.prototype._final = function () {
  5062. var chunk = this._cache.flush()
  5063. if (this._autopadding) {
  5064. chunk = this._mode.encrypt(this, chunk)
  5065. this._cipher.scrub()
  5066. return chunk
  5067. } else if (chunk.toString('hex') !== '10101010101010101010101010101010') {
  5068. this._cipher.scrub()
  5069. throw new Error('data not multiple of block length')
  5070. }
  5071. }
  5072. Cipher.prototype.setAutoPadding = function (setTo) {
  5073. this._autopadding = !!setTo
  5074. return this
  5075. }
  5076. function Splitter () {
  5077. if (!(this instanceof Splitter)) {
  5078. return new Splitter()
  5079. }
  5080. this.cache = new Buffer('')
  5081. }
  5082. Splitter.prototype.add = function (data) {
  5083. this.cache = Buffer.concat([this.cache, data])
  5084. }
  5085. Splitter.prototype.get = function () {
  5086. if (this.cache.length > 15) {
  5087. var out = this.cache.slice(0, 16)
  5088. this.cache = this.cache.slice(16)
  5089. return out
  5090. }
  5091. return null
  5092. }
  5093. Splitter.prototype.flush = function () {
  5094. var len = 16 - this.cache.length
  5095. var padBuff = new Buffer(len)
  5096. var i = -1
  5097. while (++i < len) {
  5098. padBuff.writeUInt8(len, i)
  5099. }
  5100. var out = Buffer.concat([this.cache, padBuff])
  5101. return out
  5102. }
  5103. var modelist = {
  5104. ECB: require('./modes/ecb'),
  5105. CBC: require('./modes/cbc'),
  5106. CFB: require('./modes/cfb'),
  5107. CFB8: require('./modes/cfb8'),
  5108. CFB1: require('./modes/cfb1'),
  5109. OFB: require('./modes/ofb'),
  5110. CTR: require('./modes/ctr'),
  5111. GCM: require('./modes/ctr')
  5112. }
  5113. function createCipheriv (suite, password, iv) {
  5114. var config = modes[suite.toLowerCase()]
  5115. if (!config) {
  5116. throw new TypeError('invalid suite type')
  5117. }
  5118. if (typeof iv === 'string') {
  5119. iv = new Buffer(iv)
  5120. }
  5121. if (typeof password === 'string') {
  5122. password = new Buffer(password)
  5123. }
  5124. if (password.length !== config.key / 8) {
  5125. throw new TypeError('invalid key length ' + password.length)
  5126. }
  5127. if (iv.length !== config.iv) {
  5128. throw new TypeError('invalid iv length ' + iv.length)
  5129. }
  5130. if (config.type === 'stream') {
  5131. return new StreamCipher(modelist[config.mode], password, iv)
  5132. } else if (config.type === 'auth') {
  5133. return new AuthCipher(modelist[config.mode], password, iv)
  5134. }
  5135. return new Cipher(modelist[config.mode], password, iv)
  5136. }
  5137. function createCipher (suite, password) {
  5138. var config = modes[suite.toLowerCase()]
  5139. if (!config) {
  5140. throw new TypeError('invalid suite type')
  5141. }
  5142. var keys = ebtk(password, false, config.key, config.iv)
  5143. return createCipheriv(suite, keys.key, keys.iv)
  5144. }
  5145. exports.createCipheriv = createCipheriv
  5146. exports.createCipher = createCipher
  5147. }).call(this,require("buffer").Buffer)
  5148. },{"./aes":21,"./authCipher":22,"./modes":27,"./modes/cbc":28,"./modes/cfb":29,"./modes/cfb1":30,"./modes/cfb8":31,"./modes/ctr":32,"./modes/ecb":33,"./modes/ofb":34,"./streamCipher":35,"buffer":46,"cipher-base":47,"evp_bytestokey":83,"inherits":92}],26:[function(require,module,exports){
  5149. (function (Buffer){
  5150. var zeros = new Buffer(16)
  5151. zeros.fill(0)
  5152. module.exports = GHASH
  5153. function GHASH (key) {
  5154. this.h = key
  5155. this.state = new Buffer(16)
  5156. this.state.fill(0)
  5157. this.cache = new Buffer('')
  5158. }
  5159. // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  5160. // by Juho Vähä-Herttua
  5161. GHASH.prototype.ghash = function (block) {
  5162. var i = -1
  5163. while (++i < block.length) {
  5164. this.state[i] ^= block[i]
  5165. }
  5166. this._multiply()
  5167. }
  5168. GHASH.prototype._multiply = function () {
  5169. var Vi = toArray(this.h)
  5170. var Zi = [0, 0, 0, 0]
  5171. var j, xi, lsb_Vi
  5172. var i = -1
  5173. while (++i < 128) {
  5174. xi = (this.state[~~(i / 8)] & (1 << (7 - i % 8))) !== 0
  5175. if (xi) {
  5176. // Z_i+1 = Z_i ^ V_i
  5177. Zi = xor(Zi, Vi)
  5178. }
  5179. // Store the value of LSB(V_i)
  5180. lsb_Vi = (Vi[3] & 1) !== 0
  5181. // V_i+1 = V_i >> 1
  5182. for (j = 3; j > 0; j--) {
  5183. Vi[j] = (Vi[j] >>> 1) | ((Vi[j - 1] & 1) << 31)
  5184. }
  5185. Vi[0] = Vi[0] >>> 1
  5186. // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  5187. if (lsb_Vi) {
  5188. Vi[0] = Vi[0] ^ (0xe1 << 24)
  5189. }
  5190. }
  5191. this.state = fromArray(Zi)
  5192. }
  5193. GHASH.prototype.update = function (buf) {
  5194. this.cache = Buffer.concat([this.cache, buf])
  5195. var chunk
  5196. while (this.cache.length >= 16) {
  5197. chunk = this.cache.slice(0, 16)
  5198. this.cache = this.cache.slice(16)
  5199. this.ghash(chunk)
  5200. }
  5201. }
  5202. GHASH.prototype.final = function (abl, bl) {
  5203. if (this.cache.length) {
  5204. this.ghash(Buffer.concat([this.cache, zeros], 16))
  5205. }
  5206. this.ghash(fromArray([
  5207. 0, abl,
  5208. 0, bl
  5209. ]))
  5210. return this.state
  5211. }
  5212. function toArray (buf) {
  5213. return [
  5214. buf.readUInt32BE(0),
  5215. buf.readUInt32BE(4),
  5216. buf.readUInt32BE(8),
  5217. buf.readUInt32BE(12)
  5218. ]
  5219. }
  5220. function fromArray (out) {
  5221. out = out.map(fixup_uint32)
  5222. var buf = new Buffer(16)
  5223. buf.writeUInt32BE(out[0], 0)
  5224. buf.writeUInt32BE(out[1], 4)
  5225. buf.writeUInt32BE(out[2], 8)
  5226. buf.writeUInt32BE(out[3], 12)
  5227. return buf
  5228. }
  5229. var uint_max = Math.pow(2, 32)
  5230. function fixup_uint32 (x) {
  5231. var ret, x_pos
  5232. ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x
  5233. return ret
  5234. }
  5235. function xor (a, b) {
  5236. return [
  5237. a[0] ^ b[0],
  5238. a[1] ^ b[1],
  5239. a[2] ^ b[2],
  5240. a[3] ^ b[3]
  5241. ]
  5242. }
  5243. }).call(this,require("buffer").Buffer)
  5244. },{"buffer":46}],27:[function(require,module,exports){
  5245. exports['aes-128-ecb'] = {
  5246. cipher: 'AES',
  5247. key: 128,
  5248. iv: 0,
  5249. mode: 'ECB',
  5250. type: 'block'
  5251. }
  5252. exports['aes-192-ecb'] = {
  5253. cipher: 'AES',
  5254. key: 192,
  5255. iv: 0,
  5256. mode: 'ECB',
  5257. type: 'block'
  5258. }
  5259. exports['aes-256-ecb'] = {
  5260. cipher: 'AES',
  5261. key: 256,
  5262. iv: 0,
  5263. mode: 'ECB',
  5264. type: 'block'
  5265. }
  5266. exports['aes-128-cbc'] = {
  5267. cipher: 'AES',
  5268. key: 128,
  5269. iv: 16,
  5270. mode: 'CBC',
  5271. type: 'block'
  5272. }
  5273. exports['aes-192-cbc'] = {
  5274. cipher: 'AES',
  5275. key: 192,
  5276. iv: 16,
  5277. mode: 'CBC',
  5278. type: 'block'
  5279. }
  5280. exports['aes-256-cbc'] = {
  5281. cipher: 'AES',
  5282. key: 256,
  5283. iv: 16,
  5284. mode: 'CBC',
  5285. type: 'block'
  5286. }
  5287. exports['aes128'] = exports['aes-128-cbc']
  5288. exports['aes192'] = exports['aes-192-cbc']
  5289. exports['aes256'] = exports['aes-256-cbc']
  5290. exports['aes-128-cfb'] = {
  5291. cipher: 'AES',
  5292. key: 128,
  5293. iv: 16,
  5294. mode: 'CFB',
  5295. type: 'stream'
  5296. }
  5297. exports['aes-192-cfb'] = {
  5298. cipher: 'AES',
  5299. key: 192,
  5300. iv: 16,
  5301. mode: 'CFB',
  5302. type: 'stream'
  5303. }
  5304. exports['aes-256-cfb'] = {
  5305. cipher: 'AES',
  5306. key: 256,
  5307. iv: 16,
  5308. mode: 'CFB',
  5309. type: 'stream'
  5310. }
  5311. exports['aes-128-cfb8'] = {
  5312. cipher: 'AES',
  5313. key: 128,
  5314. iv: 16,
  5315. mode: 'CFB8',
  5316. type: 'stream'
  5317. }
  5318. exports['aes-192-cfb8'] = {
  5319. cipher: 'AES',
  5320. key: 192,
  5321. iv: 16,
  5322. mode: 'CFB8',
  5323. type: 'stream'
  5324. }
  5325. exports['aes-256-cfb8'] = {
  5326. cipher: 'AES',
  5327. key: 256,
  5328. iv: 16,
  5329. mode: 'CFB8',
  5330. type: 'stream'
  5331. }
  5332. exports['aes-128-cfb1'] = {
  5333. cipher: 'AES',
  5334. key: 128,
  5335. iv: 16,
  5336. mode: 'CFB1',
  5337. type: 'stream'
  5338. }
  5339. exports['aes-192-cfb1'] = {
  5340. cipher: 'AES',
  5341. key: 192,
  5342. iv: 16,
  5343. mode: 'CFB1',
  5344. type: 'stream'
  5345. }
  5346. exports['aes-256-cfb1'] = {
  5347. cipher: 'AES',
  5348. key: 256,
  5349. iv: 16,
  5350. mode: 'CFB1',
  5351. type: 'stream'
  5352. }
  5353. exports['aes-128-ofb'] = {
  5354. cipher: 'AES',
  5355. key: 128,
  5356. iv: 16,
  5357. mode: 'OFB',
  5358. type: 'stream'
  5359. }
  5360. exports['aes-192-ofb'] = {
  5361. cipher: 'AES',
  5362. key: 192,
  5363. iv: 16,
  5364. mode: 'OFB',
  5365. type: 'stream'
  5366. }
  5367. exports['aes-256-ofb'] = {
  5368. cipher: 'AES',
  5369. key: 256,
  5370. iv: 16,
  5371. mode: 'OFB',
  5372. type: 'stream'
  5373. }
  5374. exports['aes-128-ctr'] = {
  5375. cipher: 'AES',
  5376. key: 128,
  5377. iv: 16,
  5378. mode: 'CTR',
  5379. type: 'stream'
  5380. }
  5381. exports['aes-192-ctr'] = {
  5382. cipher: 'AES',
  5383. key: 192,
  5384. iv: 16,
  5385. mode: 'CTR',
  5386. type: 'stream'
  5387. }
  5388. exports['aes-256-ctr'] = {
  5389. cipher: 'AES',
  5390. key: 256,
  5391. iv: 16,
  5392. mode: 'CTR',
  5393. type: 'stream'
  5394. }
  5395. exports['aes-128-gcm'] = {
  5396. cipher: 'AES',
  5397. key: 128,
  5398. iv: 12,
  5399. mode: 'GCM',
  5400. type: 'auth'
  5401. }
  5402. exports['aes-192-gcm'] = {
  5403. cipher: 'AES',
  5404. key: 192,
  5405. iv: 12,
  5406. mode: 'GCM',
  5407. type: 'auth'
  5408. }
  5409. exports['aes-256-gcm'] = {
  5410. cipher: 'AES',
  5411. key: 256,
  5412. iv: 12,
  5413. mode: 'GCM',
  5414. type: 'auth'
  5415. }
  5416. },{}],28:[function(require,module,exports){
  5417. var xor = require('buffer-xor')
  5418. exports.encrypt = function (self, block) {
  5419. var data = xor(block, self._prev)
  5420. self._prev = self._cipher.encryptBlock(data)
  5421. return self._prev
  5422. }
  5423. exports.decrypt = function (self, block) {
  5424. var pad = self._prev
  5425. self._prev = block
  5426. var out = self._cipher.decryptBlock(block)
  5427. return xor(out, pad)
  5428. }
  5429. },{"buffer-xor":45}],29:[function(require,module,exports){
  5430. (function (Buffer){
  5431. var xor = require('buffer-xor')
  5432. exports.encrypt = function (self, data, decrypt) {
  5433. var out = new Buffer('')
  5434. var len
  5435. while (data.length) {
  5436. if (self._cache.length === 0) {
  5437. self._cache = self._cipher.encryptBlock(self._prev)
  5438. self._prev = new Buffer('')
  5439. }
  5440. if (self._cache.length <= data.length) {
  5441. len = self._cache.length
  5442. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
  5443. data = data.slice(len)
  5444. } else {
  5445. out = Buffer.concat([out, encryptStart(self, data, decrypt)])
  5446. break
  5447. }
  5448. }
  5449. return out
  5450. }
  5451. function encryptStart (self, data, decrypt) {
  5452. var len = data.length
  5453. var out = xor(data, self._cache)
  5454. self._cache = self._cache.slice(len)
  5455. self._prev = Buffer.concat([self._prev, decrypt ? data : out])
  5456. return out
  5457. }
  5458. }).call(this,require("buffer").Buffer)
  5459. },{"buffer":46,"buffer-xor":45}],30:[function(require,module,exports){
  5460. (function (Buffer){
  5461. function encryptByte (self, byteParam, decrypt) {
  5462. var pad
  5463. var i = -1
  5464. var len = 8
  5465. var out = 0
  5466. var bit, value
  5467. while (++i < len) {
  5468. pad = self._cipher.encryptBlock(self._prev)
  5469. bit = (byteParam & (1 << (7 - i))) ? 0x80 : 0
  5470. value = pad[0] ^ bit
  5471. out += ((value & 0x80) >> (i % 8))
  5472. self._prev = shiftIn(self._prev, decrypt ? bit : value)
  5473. }
  5474. return out
  5475. }
  5476. exports.encrypt = function (self, chunk, decrypt) {
  5477. var len = chunk.length
  5478. var out = new Buffer(len)
  5479. var i = -1
  5480. while (++i < len) {
  5481. out[i] = encryptByte(self, chunk[i], decrypt)
  5482. }
  5483. return out
  5484. }
  5485. function shiftIn (buffer, value) {
  5486. var len = buffer.length
  5487. var i = -1
  5488. var out = new Buffer(buffer.length)
  5489. buffer = Buffer.concat([buffer, new Buffer([value])])
  5490. while (++i < len) {
  5491. out[i] = buffer[i] << 1 | buffer[i + 1] >> (7)
  5492. }
  5493. return out
  5494. }
  5495. }).call(this,require("buffer").Buffer)
  5496. },{"buffer":46}],31:[function(require,module,exports){
  5497. (function (Buffer){
  5498. function encryptByte (self, byteParam, decrypt) {
  5499. var pad = self._cipher.encryptBlock(self._prev)
  5500. var out = pad[0] ^ byteParam
  5501. self._prev = Buffer.concat([self._prev.slice(1), new Buffer([decrypt ? byteParam : out])])
  5502. return out
  5503. }
  5504. exports.encrypt = function (self, chunk, decrypt) {
  5505. var len = chunk.length
  5506. var out = new Buffer(len)
  5507. var i = -1
  5508. while (++i < len) {
  5509. out[i] = encryptByte(self, chunk[i], decrypt)
  5510. }
  5511. return out
  5512. }
  5513. }).call(this,require("buffer").Buffer)
  5514. },{"buffer":46}],32:[function(require,module,exports){
  5515. (function (Buffer){
  5516. var xor = require('buffer-xor')
  5517. function incr32 (iv) {
  5518. var len = iv.length
  5519. var item
  5520. while (len--) {
  5521. item = iv.readUInt8(len)
  5522. if (item === 255) {
  5523. iv.writeUInt8(0, len)
  5524. } else {
  5525. item++
  5526. iv.writeUInt8(item, len)
  5527. break
  5528. }
  5529. }
  5530. }
  5531. function getBlock (self) {
  5532. var out = self._cipher.encryptBlock(self._prev)
  5533. incr32(self._prev)
  5534. return out
  5535. }
  5536. exports.encrypt = function (self, chunk) {
  5537. while (self._cache.length < chunk.length) {
  5538. self._cache = Buffer.concat([self._cache, getBlock(self)])
  5539. }
  5540. var pad = self._cache.slice(0, chunk.length)
  5541. self._cache = self._cache.slice(chunk.length)
  5542. return xor(chunk, pad)
  5543. }
  5544. }).call(this,require("buffer").Buffer)
  5545. },{"buffer":46,"buffer-xor":45}],33:[function(require,module,exports){
  5546. exports.encrypt = function (self, block) {
  5547. return self._cipher.encryptBlock(block)
  5548. }
  5549. exports.decrypt = function (self, block) {
  5550. return self._cipher.decryptBlock(block)
  5551. }
  5552. },{}],34:[function(require,module,exports){
  5553. (function (Buffer){
  5554. var xor = require('buffer-xor')
  5555. function getBlock (self) {
  5556. self._prev = self._cipher.encryptBlock(self._prev)
  5557. return self._prev
  5558. }
  5559. exports.encrypt = function (self, chunk) {
  5560. while (self._cache.length < chunk.length) {
  5561. self._cache = Buffer.concat([self._cache, getBlock(self)])
  5562. }
  5563. var pad = self._cache.slice(0, chunk.length)
  5564. self._cache = self._cache.slice(chunk.length)
  5565. return xor(chunk, pad)
  5566. }
  5567. }).call(this,require("buffer").Buffer)
  5568. },{"buffer":46,"buffer-xor":45}],35:[function(require,module,exports){
  5569. (function (Buffer){
  5570. var aes = require('./aes')
  5571. var Transform = require('cipher-base')
  5572. var inherits = require('inherits')
  5573. inherits(StreamCipher, Transform)
  5574. module.exports = StreamCipher
  5575. function StreamCipher (mode, key, iv, decrypt) {
  5576. if (!(this instanceof StreamCipher)) {
  5577. return new StreamCipher(mode, key, iv)
  5578. }
  5579. Transform.call(this)
  5580. this._cipher = new aes.AES(key)
  5581. this._prev = new Buffer(iv.length)
  5582. this._cache = new Buffer('')
  5583. this._secCache = new Buffer('')
  5584. this._decrypt = decrypt
  5585. iv.copy(this._prev)
  5586. this._mode = mode
  5587. }
  5588. StreamCipher.prototype._update = function (chunk) {
  5589. return this._mode.encrypt(this, chunk, this._decrypt)
  5590. }
  5591. StreamCipher.prototype._final = function () {
  5592. this._cipher.scrub()
  5593. }
  5594. }).call(this,require("buffer").Buffer)
  5595. },{"./aes":21,"buffer":46,"cipher-base":47,"inherits":92}],36:[function(require,module,exports){
  5596. var ebtk = require('evp_bytestokey')
  5597. var aes = require('browserify-aes/browser')
  5598. var DES = require('browserify-des')
  5599. var desModes = require('browserify-des/modes')
  5600. var aesModes = require('browserify-aes/modes')
  5601. function createCipher (suite, password) {
  5602. var keyLen, ivLen
  5603. suite = suite.toLowerCase()
  5604. if (aesModes[suite]) {
  5605. keyLen = aesModes[suite].key
  5606. ivLen = aesModes[suite].iv
  5607. } else if (desModes[suite]) {
  5608. keyLen = desModes[suite].key * 8
  5609. ivLen = desModes[suite].iv
  5610. } else {
  5611. throw new TypeError('invalid suite type')
  5612. }
  5613. var keys = ebtk(password, false, keyLen, ivLen)
  5614. return createCipheriv(suite, keys.key, keys.iv)
  5615. }
  5616. function createDecipher (suite, password) {
  5617. var keyLen, ivLen
  5618. suite = suite.toLowerCase()
  5619. if (aesModes[suite]) {
  5620. keyLen = aesModes[suite].key
  5621. ivLen = aesModes[suite].iv
  5622. } else if (desModes[suite]) {
  5623. keyLen = desModes[suite].key * 8
  5624. ivLen = desModes[suite].iv
  5625. } else {
  5626. throw new TypeError('invalid suite type')
  5627. }
  5628. var keys = ebtk(password, false, keyLen, ivLen)
  5629. return createDecipheriv(suite, keys.key, keys.iv)
  5630. }
  5631. function createCipheriv (suite, key, iv) {
  5632. suite = suite.toLowerCase()
  5633. if (aesModes[suite]) {
  5634. return aes.createCipheriv(suite, key, iv)
  5635. } else if (desModes[suite]) {
  5636. return new DES({
  5637. key: key,
  5638. iv: iv,
  5639. mode: suite
  5640. })
  5641. } else {
  5642. throw new TypeError('invalid suite type')
  5643. }
  5644. }
  5645. function createDecipheriv (suite, key, iv) {
  5646. suite = suite.toLowerCase()
  5647. if (aesModes[suite]) {
  5648. return aes.createDecipheriv(suite, key, iv)
  5649. } else if (desModes[suite]) {
  5650. return new DES({
  5651. key: key,
  5652. iv: iv,
  5653. mode: suite,
  5654. decrypt: true
  5655. })
  5656. } else {
  5657. throw new TypeError('invalid suite type')
  5658. }
  5659. }
  5660. exports.createCipher = exports.Cipher = createCipher
  5661. exports.createCipheriv = exports.Cipheriv = createCipheriv
  5662. exports.createDecipher = exports.Decipher = createDecipher
  5663. exports.createDecipheriv = exports.Decipheriv = createDecipheriv
  5664. function getCiphers () {
  5665. return Object.keys(desModes).concat(aes.getCiphers())
  5666. }
  5667. exports.listCiphers = exports.getCiphers = getCiphers
  5668. },{"browserify-aes/browser":23,"browserify-aes/modes":27,"browserify-des":37,"browserify-des/modes":38,"evp_bytestokey":83}],37:[function(require,module,exports){
  5669. (function (Buffer){
  5670. var CipherBase = require('cipher-base')
  5671. var des = require('des.js')
  5672. var inherits = require('inherits')
  5673. var modes = {
  5674. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  5675. 'des-ede3': des.EDE,
  5676. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  5677. 'des-ede': des.EDE,
  5678. 'des-cbc': des.CBC.instantiate(des.DES),
  5679. 'des-ecb': des.DES
  5680. }
  5681. modes.des = modes['des-cbc']
  5682. modes.des3 = modes['des-ede3-cbc']
  5683. module.exports = DES
  5684. inherits(DES, CipherBase)
  5685. function DES (opts) {
  5686. CipherBase.call(this)
  5687. var modeName = opts.mode.toLowerCase()
  5688. var mode = modes[modeName]
  5689. var type
  5690. if (opts.decrypt) {
  5691. type = 'decrypt'
  5692. } else {
  5693. type = 'encrypt'
  5694. }
  5695. var key = opts.key
  5696. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  5697. key = Buffer.concat([key, key.slice(0, 8)])
  5698. }
  5699. var iv = opts.iv
  5700. this._des = mode.create({
  5701. key: key,
  5702. iv: iv,
  5703. type: type
  5704. })
  5705. }
  5706. DES.prototype._update = function (data) {
  5707. return new Buffer(this._des.update(data))
  5708. }
  5709. DES.prototype._final = function () {
  5710. return new Buffer(this._des.final())
  5711. }
  5712. }).call(this,require("buffer").Buffer)
  5713. },{"buffer":46,"cipher-base":47,"des.js":55,"inherits":92}],38:[function(require,module,exports){
  5714. exports['des-ecb'] = {
  5715. key: 8,
  5716. iv: 0
  5717. }
  5718. exports['des-cbc'] = exports.des = {
  5719. key: 8,
  5720. iv: 8
  5721. }
  5722. exports['des-ede3-cbc'] = exports.des3 = {
  5723. key: 24,
  5724. iv: 8
  5725. }
  5726. exports['des-ede3'] = {
  5727. key: 24,
  5728. iv: 0
  5729. }
  5730. exports['des-ede-cbc'] = {
  5731. key: 16,
  5732. iv: 8
  5733. }
  5734. exports['des-ede'] = {
  5735. key: 16,
  5736. iv: 0
  5737. }
  5738. },{}],39:[function(require,module,exports){
  5739. (function (Buffer){
  5740. var bn = require('bn.js');
  5741. var randomBytes = require('randombytes');
  5742. module.exports = crt;
  5743. function blind(priv) {
  5744. var r = getr(priv);
  5745. var blinder = r.toRed(bn.mont(priv.modulus))
  5746. .redPow(new bn(priv.publicExponent)).fromRed();
  5747. return {
  5748. blinder: blinder,
  5749. unblinder:r.invm(priv.modulus)
  5750. };
  5751. }
  5752. function crt(msg, priv) {
  5753. var blinds = blind(priv);
  5754. var len = priv.modulus.byteLength();
  5755. var mod = bn.mont(priv.modulus);
  5756. var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
  5757. var c1 = blinded.toRed(bn.mont(priv.prime1));
  5758. var c2 = blinded.toRed(bn.mont(priv.prime2));
  5759. var qinv = priv.coefficient;
  5760. var p = priv.prime1;
  5761. var q = priv.prime2;
  5762. var m1 = c1.redPow(priv.exponent1);
  5763. var m2 = c2.redPow(priv.exponent2);
  5764. m1 = m1.fromRed();
  5765. m2 = m2.fromRed();
  5766. var h = m1.isub(m2).imul(qinv).umod(p);
  5767. h.imul(q);
  5768. m2.iadd(h);
  5769. return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
  5770. }
  5771. crt.getr = getr;
  5772. function getr(priv) {
  5773. var len = priv.modulus.byteLength();
  5774. var r = new bn(randomBytes(len));
  5775. while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
  5776. r = new bn(randomBytes(len));
  5777. }
  5778. return r;
  5779. }
  5780. }).call(this,require("buffer").Buffer)
  5781. },{"bn.js":18,"buffer":46,"randombytes":117}],40:[function(require,module,exports){
  5782. (function (Buffer){
  5783. 'use strict'
  5784. exports['RSA-SHA224'] = exports.sha224WithRSAEncryption = {
  5785. sign: 'rsa',
  5786. hash: 'sha224',
  5787. id: new Buffer('302d300d06096086480165030402040500041c', 'hex')
  5788. }
  5789. exports['RSA-SHA256'] = exports.sha256WithRSAEncryption = {
  5790. sign: 'rsa',
  5791. hash: 'sha256',
  5792. id: new Buffer('3031300d060960864801650304020105000420', 'hex')
  5793. }
  5794. exports['RSA-SHA384'] = exports.sha384WithRSAEncryption = {
  5795. sign: 'rsa',
  5796. hash: 'sha384',
  5797. id: new Buffer('3041300d060960864801650304020205000430', 'hex')
  5798. }
  5799. exports['RSA-SHA512'] = exports.sha512WithRSAEncryption = {
  5800. sign: 'rsa',
  5801. hash: 'sha512',
  5802. id: new Buffer('3051300d060960864801650304020305000440', 'hex')
  5803. }
  5804. exports['RSA-SHA1'] = {
  5805. sign: 'rsa',
  5806. hash: 'sha1',
  5807. id: new Buffer('3021300906052b0e03021a05000414', 'hex')
  5808. }
  5809. exports['ecdsa-with-SHA1'] = {
  5810. sign: 'ecdsa',
  5811. hash: 'sha1',
  5812. id: new Buffer('', 'hex')
  5813. }
  5814. exports.DSA = exports['DSA-SHA1'] = exports['DSA-SHA'] = {
  5815. sign: 'dsa',
  5816. hash: 'sha1',
  5817. id: new Buffer('', 'hex')
  5818. }
  5819. exports['DSA-SHA224'] = exports['DSA-WITH-SHA224'] = {
  5820. sign: 'dsa',
  5821. hash: 'sha224',
  5822. id: new Buffer('', 'hex')
  5823. }
  5824. exports['DSA-SHA256'] = exports['DSA-WITH-SHA256'] = {
  5825. sign: 'dsa',
  5826. hash: 'sha256',
  5827. id: new Buffer('', 'hex')
  5828. }
  5829. exports['DSA-SHA384'] = exports['DSA-WITH-SHA384'] = {
  5830. sign: 'dsa',
  5831. hash: 'sha384',
  5832. id: new Buffer('', 'hex')
  5833. }
  5834. exports['DSA-SHA512'] = exports['DSA-WITH-SHA512'] = {
  5835. sign: 'dsa',
  5836. hash: 'sha512',
  5837. id: new Buffer('', 'hex')
  5838. }
  5839. exports['DSA-RIPEMD160'] = {
  5840. sign: 'dsa',
  5841. hash: 'rmd160',
  5842. id: new Buffer('', 'hex')
  5843. }
  5844. exports['RSA-RIPEMD160'] = exports.ripemd160WithRSA = {
  5845. sign: 'rsa',
  5846. hash: 'rmd160',
  5847. id: new Buffer('3021300906052b2403020105000414', 'hex')
  5848. }
  5849. exports['RSA-MD5'] = exports.md5WithRSAEncryption = {
  5850. sign: 'rsa',
  5851. hash: 'md5',
  5852. id: new Buffer('3020300c06082a864886f70d020505000410', 'hex')
  5853. }
  5854. }).call(this,require("buffer").Buffer)
  5855. },{"buffer":46}],41:[function(require,module,exports){
  5856. (function (Buffer){
  5857. var _algos = require('./algos')
  5858. var createHash = require('create-hash')
  5859. var inherits = require('inherits')
  5860. var sign = require('./sign')
  5861. var stream = require('stream')
  5862. var verify = require('./verify')
  5863. var algos = {}
  5864. Object.keys(_algos).forEach(function (key) {
  5865. algos[key] = algos[key.toLowerCase()] = _algos[key]
  5866. })
  5867. function Sign (algorithm) {
  5868. stream.Writable.call(this)
  5869. var data = algos[algorithm]
  5870. if (!data) {
  5871. throw new Error('Unknown message digest')
  5872. }
  5873. this._hashType = data.hash
  5874. this._hash = createHash(data.hash)
  5875. this._tag = data.id
  5876. this._signType = data.sign
  5877. }
  5878. inherits(Sign, stream.Writable)
  5879. Sign.prototype._write = function _write (data, _, done) {
  5880. this._hash.update(data)
  5881. done()
  5882. }
  5883. Sign.prototype.update = function update (data, enc) {
  5884. if (typeof data === 'string') {
  5885. data = new Buffer(data, enc)
  5886. }
  5887. this._hash.update(data)
  5888. return this
  5889. }
  5890. Sign.prototype.sign = function signMethod (key, enc) {
  5891. this.end()
  5892. var hash = this._hash.digest()
  5893. var sig = sign(Buffer.concat([this._tag, hash]), key, this._hashType, this._signType)
  5894. return enc ? sig.toString(enc) : sig
  5895. }
  5896. function Verify (algorithm) {
  5897. stream.Writable.call(this)
  5898. var data = algos[algorithm]
  5899. if (!data) {
  5900. throw new Error('Unknown message digest')
  5901. }
  5902. this._hash = createHash(data.hash)
  5903. this._tag = data.id
  5904. this._signType = data.sign
  5905. }
  5906. inherits(Verify, stream.Writable)
  5907. Verify.prototype._write = function _write (data, _, done) {
  5908. this._hash.update(data)
  5909. done()
  5910. }
  5911. Verify.prototype.update = function update (data, enc) {
  5912. if (typeof data === 'string') {
  5913. data = new Buffer(data, enc)
  5914. }
  5915. this._hash.update(data)
  5916. return this
  5917. }
  5918. Verify.prototype.verify = function verifyMethod (key, sig, enc) {
  5919. if (typeof sig === 'string') {
  5920. sig = new Buffer(sig, enc)
  5921. }
  5922. this.end()
  5923. var hash = this._hash.digest()
  5924. return verify(sig, Buffer.concat([this._tag, hash]), key, this._signType)
  5925. }
  5926. function createSign (algorithm) {
  5927. return new Sign(algorithm)
  5928. }
  5929. function createVerify (algorithm) {
  5930. return new Verify(algorithm)
  5931. }
  5932. module.exports = {
  5933. Sign: createSign,
  5934. Verify: createVerify,
  5935. createSign: createSign,
  5936. createVerify: createVerify
  5937. }
  5938. }).call(this,require("buffer").Buffer)
  5939. },{"./algos":40,"./sign":43,"./verify":44,"buffer":46,"create-hash":50,"inherits":92,"stream":137}],42:[function(require,module,exports){
  5940. 'use strict'
  5941. exports['1.3.132.0.10'] = 'secp256k1'
  5942. exports['1.3.132.0.33'] = 'p224'
  5943. exports['1.2.840.10045.3.1.1'] = 'p192'
  5944. exports['1.2.840.10045.3.1.7'] = 'p256'
  5945. exports['1.3.132.0.34'] = 'p384'
  5946. exports['1.3.132.0.35'] = 'p521'
  5947. },{}],43:[function(require,module,exports){
  5948. (function (Buffer){
  5949. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  5950. var createHmac = require('create-hmac')
  5951. var crt = require('browserify-rsa')
  5952. var curves = require('./curves')
  5953. var elliptic = require('elliptic')
  5954. var parseKeys = require('parse-asn1')
  5955. var BN = require('bn.js')
  5956. var EC = elliptic.ec
  5957. function sign (hash, key, hashType, signType) {
  5958. var priv = parseKeys(key)
  5959. if (priv.curve) {
  5960. if (signType !== 'ecdsa') throw new Error('wrong private key type')
  5961. return ecSign(hash, priv)
  5962. } else if (priv.type === 'dsa') {
  5963. if (signType !== 'dsa') {
  5964. throw new Error('wrong private key type')
  5965. }
  5966. return dsaSign(hash, priv, hashType)
  5967. } else {
  5968. if (signType !== 'rsa') throw new Error('wrong private key type')
  5969. }
  5970. var len = priv.modulus.byteLength()
  5971. var pad = [ 0, 1 ]
  5972. while (hash.length + pad.length + 1 < len) {
  5973. pad.push(0xff)
  5974. }
  5975. pad.push(0x00)
  5976. var i = -1
  5977. while (++i < hash.length) {
  5978. pad.push(hash[i])
  5979. }
  5980. var out = crt(pad, priv)
  5981. return out
  5982. }
  5983. function ecSign (hash, priv) {
  5984. var curveId = curves[priv.curve.join('.')]
  5985. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'))
  5986. var curve = new EC(curveId)
  5987. var key = curve.genKeyPair()
  5988. key._importPrivate(priv.privateKey)
  5989. var out = key.sign(hash)
  5990. return new Buffer(out.toDER())
  5991. }
  5992. function dsaSign (hash, priv, algo) {
  5993. var x = priv.params.priv_key
  5994. var p = priv.params.p
  5995. var q = priv.params.q
  5996. var g = priv.params.g
  5997. var r = new BN(0)
  5998. var k
  5999. var H = bits2int(hash, q).mod(q)
  6000. var s = false
  6001. var kv = getKey(x, q, hash, algo)
  6002. while (s === false) {
  6003. k = makeKey(q, kv, algo)
  6004. r = makeR(g, k, p, q)
  6005. s = k.invm(q).imul(H.add(x.mul(r))).mod(q)
  6006. if (!s.cmpn(0)) {
  6007. s = false
  6008. r = new BN(0)
  6009. }
  6010. }
  6011. return toDER(r, s)
  6012. }
  6013. function toDER (r, s) {
  6014. r = r.toArray()
  6015. s = s.toArray()
  6016. // Pad values
  6017. if (r[0] & 0x80) {
  6018. r = [ 0 ].concat(r)
  6019. }
  6020. // Pad values
  6021. if (s[0] & 0x80) {
  6022. s = [0].concat(s)
  6023. }
  6024. var total = r.length + s.length + 4
  6025. var res = [ 0x30, total, 0x02, r.length ]
  6026. res = res.concat(r, [ 0x02, s.length ], s)
  6027. return new Buffer(res)
  6028. }
  6029. function getKey (x, q, hash, algo) {
  6030. x = new Buffer(x.toArray())
  6031. if (x.length < q.byteLength()) {
  6032. var zeros = new Buffer(q.byteLength() - x.length)
  6033. zeros.fill(0)
  6034. x = Buffer.concat([zeros, x])
  6035. }
  6036. var hlen = hash.length
  6037. var hbits = bits2octets(hash, q)
  6038. var v = new Buffer(hlen)
  6039. v.fill(1)
  6040. var k = new Buffer(hlen)
  6041. k.fill(0)
  6042. k = createHmac(algo, k)
  6043. .update(v)
  6044. .update(new Buffer([0]))
  6045. .update(x)
  6046. .update(hbits)
  6047. .digest()
  6048. v = createHmac(algo, k)
  6049. .update(v)
  6050. .digest()
  6051. k = createHmac(algo, k)
  6052. .update(v)
  6053. .update(new Buffer([1]))
  6054. .update(x)
  6055. .update(hbits)
  6056. .digest()
  6057. v = createHmac(algo, k)
  6058. .update(v)
  6059. .digest()
  6060. return {
  6061. k: k,
  6062. v: v
  6063. }
  6064. }
  6065. function bits2int (obits, q) {
  6066. var bits = new BN(obits)
  6067. var shift = (obits.length << 3) - q.bitLength()
  6068. if (shift > 0) {
  6069. bits.ishrn(shift)
  6070. }
  6071. return bits
  6072. }
  6073. function bits2octets (bits, q) {
  6074. bits = bits2int(bits, q)
  6075. bits = bits.mod(q)
  6076. var out = new Buffer(bits.toArray())
  6077. if (out.length < q.byteLength()) {
  6078. var zeros = new Buffer(q.byteLength() - out.length)
  6079. zeros.fill(0)
  6080. out = Buffer.concat([zeros, out])
  6081. }
  6082. return out
  6083. }
  6084. function makeKey (q, kv, algo) {
  6085. var t, k
  6086. do {
  6087. t = new Buffer('')
  6088. while (t.length * 8 < q.bitLength()) {
  6089. kv.v = createHmac(algo, kv.k)
  6090. .update(kv.v)
  6091. .digest()
  6092. t = Buffer.concat([t, kv.v])
  6093. }
  6094. k = bits2int(t, q)
  6095. kv.k = createHmac(algo, kv.k)
  6096. .update(kv.v)
  6097. .update(new Buffer([0]))
  6098. .digest()
  6099. kv.v = createHmac(algo, kv.k)
  6100. .update(kv.v)
  6101. .digest()
  6102. } while (k.cmp(q) !== -1)
  6103. return k
  6104. }
  6105. function makeR (g, k, p, q) {
  6106. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q)
  6107. }
  6108. module.exports = sign
  6109. module.exports.getKey = getKey
  6110. module.exports.makeKey = makeKey
  6111. }).call(this,require("buffer").Buffer)
  6112. },{"./curves":42,"bn.js":18,"browserify-rsa":39,"buffer":46,"create-hmac":53,"elliptic":65,"parse-asn1":103}],44:[function(require,module,exports){
  6113. (function (Buffer){
  6114. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  6115. var curves = require('./curves')
  6116. var elliptic = require('elliptic')
  6117. var parseKeys = require('parse-asn1')
  6118. var BN = require('bn.js')
  6119. var EC = elliptic.ec
  6120. function verify (sig, hash, key, signType) {
  6121. var pub = parseKeys(key)
  6122. if (pub.type === 'ec') {
  6123. if (signType !== 'ecdsa') {
  6124. throw new Error('wrong public key type')
  6125. }
  6126. return ecVerify(sig, hash, pub)
  6127. } else if (pub.type === 'dsa') {
  6128. if (signType !== 'dsa') {
  6129. throw new Error('wrong public key type')
  6130. }
  6131. return dsaVerify(sig, hash, pub)
  6132. } else {
  6133. if (signType !== 'rsa') {
  6134. throw new Error('wrong public key type')
  6135. }
  6136. }
  6137. var len = pub.modulus.byteLength()
  6138. var pad = [ 1 ]
  6139. var padNum = 0
  6140. while (hash.length + pad.length + 2 < len) {
  6141. pad.push(0xff)
  6142. padNum++
  6143. }
  6144. pad.push(0x00)
  6145. var i = -1
  6146. while (++i < hash.length) {
  6147. pad.push(hash[i])
  6148. }
  6149. pad = new Buffer(pad)
  6150. var red = BN.mont(pub.modulus)
  6151. sig = new BN(sig).toRed(red)
  6152. sig = sig.redPow(new BN(pub.publicExponent))
  6153. sig = new Buffer(sig.fromRed().toArray())
  6154. var out = 0
  6155. if (padNum < 8) {
  6156. out = 1
  6157. }
  6158. len = Math.min(sig.length, pad.length)
  6159. if (sig.length !== pad.length) {
  6160. out = 1
  6161. }
  6162. i = -1
  6163. while (++i < len) {
  6164. out |= (sig[i] ^ pad[i])
  6165. }
  6166. return out === 0
  6167. }
  6168. function ecVerify (sig, hash, pub) {
  6169. var curveId = curves[pub.data.algorithm.curve.join('.')]
  6170. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'))
  6171. var curve = new EC(curveId)
  6172. var pubkey = pub.data.subjectPrivateKey.data
  6173. return curve.verify(hash, sig, pubkey)
  6174. }
  6175. function dsaVerify (sig, hash, pub) {
  6176. var p = pub.data.p
  6177. var q = pub.data.q
  6178. var g = pub.data.g
  6179. var y = pub.data.pub_key
  6180. var unpacked = parseKeys.signature.decode(sig, 'der')
  6181. var s = unpacked.s
  6182. var r = unpacked.r
  6183. checkValue(s, q)
  6184. checkValue(r, q)
  6185. var montp = BN.mont(p)
  6186. var w = s.invm(q)
  6187. var v = g.toRed(montp)
  6188. .redPow(new BN(hash).mul(w).mod(q))
  6189. .fromRed()
  6190. .mul(
  6191. y.toRed(montp)
  6192. .redPow(r.mul(w).mod(q))
  6193. .fromRed()
  6194. ).mod(p).mod(q)
  6195. return !v.cmp(r)
  6196. }
  6197. function checkValue (b, q) {
  6198. if (b.cmpn(0) <= 0) {
  6199. throw new Error('invalid sig')
  6200. }
  6201. if (b.cmp(q) >= q) {
  6202. throw new Error('invalid sig')
  6203. }
  6204. }
  6205. module.exports = verify
  6206. }).call(this,require("buffer").Buffer)
  6207. },{"./curves":42,"bn.js":18,"buffer":46,"elliptic":65,"parse-asn1":103}],45:[function(require,module,exports){
  6208. (function (Buffer){
  6209. module.exports = function xor (a, b) {
  6210. var length = Math.min(a.length, b.length)
  6211. var buffer = new Buffer(length)
  6212. for (var i = 0; i < length; ++i) {
  6213. buffer[i] = a[i] ^ b[i]
  6214. }
  6215. return buffer
  6216. }
  6217. }).call(this,require("buffer").Buffer)
  6218. },{"buffer":46}],46:[function(require,module,exports){
  6219. (function (global){
  6220. /*!
  6221. * The buffer module from node.js, for the browser.
  6222. *
  6223. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6224. * @license MIT
  6225. */
  6226. /* eslint-disable no-proto */
  6227. 'use strict'
  6228. var base64 = require('base64-js')
  6229. var ieee754 = require('ieee754')
  6230. var isArray = require('isarray')
  6231. exports.Buffer = Buffer
  6232. exports.SlowBuffer = SlowBuffer
  6233. exports.INSPECT_MAX_BYTES = 50
  6234. /**
  6235. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6236. * === true Use Uint8Array implementation (fastest)
  6237. * === false Use Object implementation (most compatible, even IE6)
  6238. *
  6239. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6240. * Opera 11.6+, iOS 4.2+.
  6241. *
  6242. * Due to various browser bugs, sometimes the Object implementation will be used even
  6243. * when the browser supports typed arrays.
  6244. *
  6245. * Note:
  6246. *
  6247. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6248. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6249. *
  6250. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6251. *
  6252. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6253. * incorrect length in some situations.
  6254. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6255. * get the Object implementation, which is slower but behaves correctly.
  6256. */
  6257. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6258. ? global.TYPED_ARRAY_SUPPORT
  6259. : typedArraySupport()
  6260. /*
  6261. * Export kMaxLength after typed array support is determined.
  6262. */
  6263. exports.kMaxLength = kMaxLength()
  6264. function typedArraySupport () {
  6265. try {
  6266. var arr = new Uint8Array(1)
  6267. arr.foo = function () { return 42 }
  6268. return arr.foo() === 42 && // typed array instances can be augmented
  6269. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6270. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6271. } catch (e) {
  6272. return false
  6273. }
  6274. }
  6275. function kMaxLength () {
  6276. return Buffer.TYPED_ARRAY_SUPPORT
  6277. ? 0x7fffffff
  6278. : 0x3fffffff
  6279. }
  6280. function createBuffer (that, length) {
  6281. if (kMaxLength() < length) {
  6282. throw new RangeError('Invalid typed array length')
  6283. }
  6284. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6285. // Return an augmented `Uint8Array` instance, for best performance
  6286. that = new Uint8Array(length)
  6287. that.__proto__ = Buffer.prototype
  6288. } else {
  6289. // Fallback: Return an object instance of the Buffer class
  6290. if (that === null) {
  6291. that = new Buffer(length)
  6292. }
  6293. that.length = length
  6294. }
  6295. return that
  6296. }
  6297. /**
  6298. * The Buffer constructor returns instances of `Uint8Array` that have their
  6299. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6300. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6301. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6302. * returns a single octet.
  6303. *
  6304. * The `Uint8Array` prototype remains unmodified.
  6305. */
  6306. function Buffer (arg, encodingOrOffset, length) {
  6307. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6308. return new Buffer(arg, encodingOrOffset, length)
  6309. }
  6310. // Common case.
  6311. if (typeof arg === 'number') {
  6312. if (typeof encodingOrOffset === 'string') {
  6313. throw new Error(
  6314. 'If encoding is specified then the first argument must be a string'
  6315. )
  6316. }
  6317. return allocUnsafe(this, arg)
  6318. }
  6319. return from(this, arg, encodingOrOffset, length)
  6320. }
  6321. Buffer.poolSize = 8192 // not used by this implementation
  6322. // TODO: Legacy, not needed anymore. Remove in next major version.
  6323. Buffer._augment = function (arr) {
  6324. arr.__proto__ = Buffer.prototype
  6325. return arr
  6326. }
  6327. function from (that, value, encodingOrOffset, length) {
  6328. if (typeof value === 'number') {
  6329. throw new TypeError('"value" argument must not be a number')
  6330. }
  6331. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6332. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6333. }
  6334. if (typeof value === 'string') {
  6335. return fromString(that, value, encodingOrOffset)
  6336. }
  6337. return fromObject(that, value)
  6338. }
  6339. /**
  6340. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6341. * if value is a number.
  6342. * Buffer.from(str[, encoding])
  6343. * Buffer.from(array)
  6344. * Buffer.from(buffer)
  6345. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6346. **/
  6347. Buffer.from = function (value, encodingOrOffset, length) {
  6348. return from(null, value, encodingOrOffset, length)
  6349. }
  6350. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6351. Buffer.prototype.__proto__ = Uint8Array.prototype
  6352. Buffer.__proto__ = Uint8Array
  6353. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6354. Buffer[Symbol.species] === Buffer) {
  6355. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6356. Object.defineProperty(Buffer, Symbol.species, {
  6357. value: null,
  6358. configurable: true
  6359. })
  6360. }
  6361. }
  6362. function assertSize (size) {
  6363. if (typeof size !== 'number') {
  6364. throw new TypeError('"size" argument must be a number')
  6365. }
  6366. }
  6367. function alloc (that, size, fill, encoding) {
  6368. assertSize(size)
  6369. if (size <= 0) {
  6370. return createBuffer(that, size)
  6371. }
  6372. if (fill !== undefined) {
  6373. // Only pay attention to encoding if it's a string. This
  6374. // prevents accidentally sending in a number that would
  6375. // be interpretted as a start offset.
  6376. return typeof encoding === 'string'
  6377. ? createBuffer(that, size).fill(fill, encoding)
  6378. : createBuffer(that, size).fill(fill)
  6379. }
  6380. return createBuffer(that, size)
  6381. }
  6382. /**
  6383. * Creates a new filled Buffer instance.
  6384. * alloc(size[, fill[, encoding]])
  6385. **/
  6386. Buffer.alloc = function (size, fill, encoding) {
  6387. return alloc(null, size, fill, encoding)
  6388. }
  6389. function allocUnsafe (that, size) {
  6390. assertSize(size)
  6391. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6392. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6393. for (var i = 0; i < size; i++) {
  6394. that[i] = 0
  6395. }
  6396. }
  6397. return that
  6398. }
  6399. /**
  6400. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6401. * */
  6402. Buffer.allocUnsafe = function (size) {
  6403. return allocUnsafe(null, size)
  6404. }
  6405. /**
  6406. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6407. */
  6408. Buffer.allocUnsafeSlow = function (size) {
  6409. return allocUnsafe(null, size)
  6410. }
  6411. function fromString (that, string, encoding) {
  6412. if (typeof encoding !== 'string' || encoding === '') {
  6413. encoding = 'utf8'
  6414. }
  6415. if (!Buffer.isEncoding(encoding)) {
  6416. throw new TypeError('"encoding" must be a valid string encoding')
  6417. }
  6418. var length = byteLength(string, encoding) | 0
  6419. that = createBuffer(that, length)
  6420. that.write(string, encoding)
  6421. return that
  6422. }
  6423. function fromArrayLike (that, array) {
  6424. var length = checked(array.length) | 0
  6425. that = createBuffer(that, length)
  6426. for (var i = 0; i < length; i += 1) {
  6427. that[i] = array[i] & 255
  6428. }
  6429. return that
  6430. }
  6431. function fromArrayBuffer (that, array, byteOffset, length) {
  6432. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6433. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6434. throw new RangeError('\'offset\' is out of bounds')
  6435. }
  6436. if (array.byteLength < byteOffset + (length || 0)) {
  6437. throw new RangeError('\'length\' is out of bounds')
  6438. }
  6439. if (length === undefined) {
  6440. array = new Uint8Array(array, byteOffset)
  6441. } else {
  6442. array = new Uint8Array(array, byteOffset, length)
  6443. }
  6444. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6445. // Return an augmented `Uint8Array` instance, for best performance
  6446. that = array
  6447. that.__proto__ = Buffer.prototype
  6448. } else {
  6449. // Fallback: Return an object instance of the Buffer class
  6450. that = fromArrayLike(that, array)
  6451. }
  6452. return that
  6453. }
  6454. function fromObject (that, obj) {
  6455. if (Buffer.isBuffer(obj)) {
  6456. var len = checked(obj.length) | 0
  6457. that = createBuffer(that, len)
  6458. if (that.length === 0) {
  6459. return that
  6460. }
  6461. obj.copy(that, 0, 0, len)
  6462. return that
  6463. }
  6464. if (obj) {
  6465. if ((typeof ArrayBuffer !== 'undefined' &&
  6466. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6467. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6468. return createBuffer(that, 0)
  6469. }
  6470. return fromArrayLike(that, obj)
  6471. }
  6472. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6473. return fromArrayLike(that, obj.data)
  6474. }
  6475. }
  6476. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6477. }
  6478. function checked (length) {
  6479. // Note: cannot use `length < kMaxLength` here because that fails when
  6480. // length is NaN (which is otherwise coerced to zero.)
  6481. if (length >= kMaxLength()) {
  6482. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6483. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6484. }
  6485. return length | 0
  6486. }
  6487. function SlowBuffer (length) {
  6488. if (+length != length) { // eslint-disable-line eqeqeq
  6489. length = 0
  6490. }
  6491. return Buffer.alloc(+length)
  6492. }
  6493. Buffer.isBuffer = function isBuffer (b) {
  6494. return !!(b != null && b._isBuffer)
  6495. }
  6496. Buffer.compare = function compare (a, b) {
  6497. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6498. throw new TypeError('Arguments must be Buffers')
  6499. }
  6500. if (a === b) return 0
  6501. var x = a.length
  6502. var y = b.length
  6503. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6504. if (a[i] !== b[i]) {
  6505. x = a[i]
  6506. y = b[i]
  6507. break
  6508. }
  6509. }
  6510. if (x < y) return -1
  6511. if (y < x) return 1
  6512. return 0
  6513. }
  6514. Buffer.isEncoding = function isEncoding (encoding) {
  6515. switch (String(encoding).toLowerCase()) {
  6516. case 'hex':
  6517. case 'utf8':
  6518. case 'utf-8':
  6519. case 'ascii':
  6520. case 'binary':
  6521. case 'base64':
  6522. case 'raw':
  6523. case 'ucs2':
  6524. case 'ucs-2':
  6525. case 'utf16le':
  6526. case 'utf-16le':
  6527. return true
  6528. default:
  6529. return false
  6530. }
  6531. }
  6532. Buffer.concat = function concat (list, length) {
  6533. if (!isArray(list)) {
  6534. throw new TypeError('"list" argument must be an Array of Buffers')
  6535. }
  6536. if (list.length === 0) {
  6537. return Buffer.alloc(0)
  6538. }
  6539. var i
  6540. if (length === undefined) {
  6541. length = 0
  6542. for (i = 0; i < list.length; i++) {
  6543. length += list[i].length
  6544. }
  6545. }
  6546. var buffer = Buffer.allocUnsafe(length)
  6547. var pos = 0
  6548. for (i = 0; i < list.length; i++) {
  6549. var buf = list[i]
  6550. if (!Buffer.isBuffer(buf)) {
  6551. throw new TypeError('"list" argument must be an Array of Buffers')
  6552. }
  6553. buf.copy(buffer, pos)
  6554. pos += buf.length
  6555. }
  6556. return buffer
  6557. }
  6558. function byteLength (string, encoding) {
  6559. if (Buffer.isBuffer(string)) {
  6560. return string.length
  6561. }
  6562. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6563. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6564. return string.byteLength
  6565. }
  6566. if (typeof string !== 'string') {
  6567. string = '' + string
  6568. }
  6569. var len = string.length
  6570. if (len === 0) return 0
  6571. // Use a for loop to avoid recursion
  6572. var loweredCase = false
  6573. for (;;) {
  6574. switch (encoding) {
  6575. case 'ascii':
  6576. case 'binary':
  6577. // Deprecated
  6578. case 'raw':
  6579. case 'raws':
  6580. return len
  6581. case 'utf8':
  6582. case 'utf-8':
  6583. case undefined:
  6584. return utf8ToBytes(string).length
  6585. case 'ucs2':
  6586. case 'ucs-2':
  6587. case 'utf16le':
  6588. case 'utf-16le':
  6589. return len * 2
  6590. case 'hex':
  6591. return len >>> 1
  6592. case 'base64':
  6593. return base64ToBytes(string).length
  6594. default:
  6595. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6596. encoding = ('' + encoding).toLowerCase()
  6597. loweredCase = true
  6598. }
  6599. }
  6600. }
  6601. Buffer.byteLength = byteLength
  6602. function slowToString (encoding, start, end) {
  6603. var loweredCase = false
  6604. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6605. // property of a typed array.
  6606. // This behaves neither like String nor Uint8Array in that we set start/end
  6607. // to their upper/lower bounds if the value passed is out of range.
  6608. // undefined is handled specially as per ECMA-262 6th Edition,
  6609. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6610. if (start === undefined || start < 0) {
  6611. start = 0
  6612. }
  6613. // Return early if start > this.length. Done here to prevent potential uint32
  6614. // coercion fail below.
  6615. if (start > this.length) {
  6616. return ''
  6617. }
  6618. if (end === undefined || end > this.length) {
  6619. end = this.length
  6620. }
  6621. if (end <= 0) {
  6622. return ''
  6623. }
  6624. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6625. end >>>= 0
  6626. start >>>= 0
  6627. if (end <= start) {
  6628. return ''
  6629. }
  6630. if (!encoding) encoding = 'utf8'
  6631. while (true) {
  6632. switch (encoding) {
  6633. case 'hex':
  6634. return hexSlice(this, start, end)
  6635. case 'utf8':
  6636. case 'utf-8':
  6637. return utf8Slice(this, start, end)
  6638. case 'ascii':
  6639. return asciiSlice(this, start, end)
  6640. case 'binary':
  6641. return binarySlice(this, start, end)
  6642. case 'base64':
  6643. return base64Slice(this, start, end)
  6644. case 'ucs2':
  6645. case 'ucs-2':
  6646. case 'utf16le':
  6647. case 'utf-16le':
  6648. return utf16leSlice(this, start, end)
  6649. default:
  6650. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6651. encoding = (encoding + '').toLowerCase()
  6652. loweredCase = true
  6653. }
  6654. }
  6655. }
  6656. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6657. // Buffer instances.
  6658. Buffer.prototype._isBuffer = true
  6659. function swap (b, n, m) {
  6660. var i = b[n]
  6661. b[n] = b[m]
  6662. b[m] = i
  6663. }
  6664. Buffer.prototype.swap16 = function swap16 () {
  6665. var len = this.length
  6666. if (len % 2 !== 0) {
  6667. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6668. }
  6669. for (var i = 0; i < len; i += 2) {
  6670. swap(this, i, i + 1)
  6671. }
  6672. return this
  6673. }
  6674. Buffer.prototype.swap32 = function swap32 () {
  6675. var len = this.length
  6676. if (len % 4 !== 0) {
  6677. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6678. }
  6679. for (var i = 0; i < len; i += 4) {
  6680. swap(this, i, i + 3)
  6681. swap(this, i + 1, i + 2)
  6682. }
  6683. return this
  6684. }
  6685. Buffer.prototype.toString = function toString () {
  6686. var length = this.length | 0
  6687. if (length === 0) return ''
  6688. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6689. return slowToString.apply(this, arguments)
  6690. }
  6691. Buffer.prototype.equals = function equals (b) {
  6692. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6693. if (this === b) return true
  6694. return Buffer.compare(this, b) === 0
  6695. }
  6696. Buffer.prototype.inspect = function inspect () {
  6697. var str = ''
  6698. var max = exports.INSPECT_MAX_BYTES
  6699. if (this.length > 0) {
  6700. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6701. if (this.length > max) str += ' ... '
  6702. }
  6703. return '<Buffer ' + str + '>'
  6704. }
  6705. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6706. if (!Buffer.isBuffer(target)) {
  6707. throw new TypeError('Argument must be a Buffer')
  6708. }
  6709. if (start === undefined) {
  6710. start = 0
  6711. }
  6712. if (end === undefined) {
  6713. end = target ? target.length : 0
  6714. }
  6715. if (thisStart === undefined) {
  6716. thisStart = 0
  6717. }
  6718. if (thisEnd === undefined) {
  6719. thisEnd = this.length
  6720. }
  6721. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6722. throw new RangeError('out of range index')
  6723. }
  6724. if (thisStart >= thisEnd && start >= end) {
  6725. return 0
  6726. }
  6727. if (thisStart >= thisEnd) {
  6728. return -1
  6729. }
  6730. if (start >= end) {
  6731. return 1
  6732. }
  6733. start >>>= 0
  6734. end >>>= 0
  6735. thisStart >>>= 0
  6736. thisEnd >>>= 0
  6737. if (this === target) return 0
  6738. var x = thisEnd - thisStart
  6739. var y = end - start
  6740. var len = Math.min(x, y)
  6741. var thisCopy = this.slice(thisStart, thisEnd)
  6742. var targetCopy = target.slice(start, end)
  6743. for (var i = 0; i < len; ++i) {
  6744. if (thisCopy[i] !== targetCopy[i]) {
  6745. x = thisCopy[i]
  6746. y = targetCopy[i]
  6747. break
  6748. }
  6749. }
  6750. if (x < y) return -1
  6751. if (y < x) return 1
  6752. return 0
  6753. }
  6754. function arrayIndexOf (arr, val, byteOffset, encoding) {
  6755. var indexSize = 1
  6756. var arrLength = arr.length
  6757. var valLength = val.length
  6758. if (encoding !== undefined) {
  6759. encoding = String(encoding).toLowerCase()
  6760. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6761. encoding === 'utf16le' || encoding === 'utf-16le') {
  6762. if (arr.length < 2 || val.length < 2) {
  6763. return -1
  6764. }
  6765. indexSize = 2
  6766. arrLength /= 2
  6767. valLength /= 2
  6768. byteOffset /= 2
  6769. }
  6770. }
  6771. function read (buf, i) {
  6772. if (indexSize === 1) {
  6773. return buf[i]
  6774. } else {
  6775. return buf.readUInt16BE(i * indexSize)
  6776. }
  6777. }
  6778. var foundIndex = -1
  6779. for (var i = 0; byteOffset + i < arrLength; i++) {
  6780. if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6781. if (foundIndex === -1) foundIndex = i
  6782. if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
  6783. } else {
  6784. if (foundIndex !== -1) i -= i - foundIndex
  6785. foundIndex = -1
  6786. }
  6787. }
  6788. return -1
  6789. }
  6790. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6791. if (typeof byteOffset === 'string') {
  6792. encoding = byteOffset
  6793. byteOffset = 0
  6794. } else if (byteOffset > 0x7fffffff) {
  6795. byteOffset = 0x7fffffff
  6796. } else if (byteOffset < -0x80000000) {
  6797. byteOffset = -0x80000000
  6798. }
  6799. byteOffset >>= 0
  6800. if (this.length === 0) return -1
  6801. if (byteOffset >= this.length) return -1
  6802. // Negative offsets start from the end of the buffer
  6803. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  6804. if (typeof val === 'string') {
  6805. val = Buffer.from(val, encoding)
  6806. }
  6807. if (Buffer.isBuffer(val)) {
  6808. // special case: looking for empty string/buffer always fails
  6809. if (val.length === 0) {
  6810. return -1
  6811. }
  6812. return arrayIndexOf(this, val, byteOffset, encoding)
  6813. }
  6814. if (typeof val === 'number') {
  6815. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  6816. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  6817. }
  6818. return arrayIndexOf(this, [ val ], byteOffset, encoding)
  6819. }
  6820. throw new TypeError('val must be string, number or Buffer')
  6821. }
  6822. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6823. return this.indexOf(val, byteOffset, encoding) !== -1
  6824. }
  6825. function hexWrite (buf, string, offset, length) {
  6826. offset = Number(offset) || 0
  6827. var remaining = buf.length - offset
  6828. if (!length) {
  6829. length = remaining
  6830. } else {
  6831. length = Number(length)
  6832. if (length > remaining) {
  6833. length = remaining
  6834. }
  6835. }
  6836. // must be an even number of digits
  6837. var strLen = string.length
  6838. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  6839. if (length > strLen / 2) {
  6840. length = strLen / 2
  6841. }
  6842. for (var i = 0; i < length; i++) {
  6843. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6844. if (isNaN(parsed)) return i
  6845. buf[offset + i] = parsed
  6846. }
  6847. return i
  6848. }
  6849. function utf8Write (buf, string, offset, length) {
  6850. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6851. }
  6852. function asciiWrite (buf, string, offset, length) {
  6853. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6854. }
  6855. function binaryWrite (buf, string, offset, length) {
  6856. return asciiWrite(buf, string, offset, length)
  6857. }
  6858. function base64Write (buf, string, offset, length) {
  6859. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6860. }
  6861. function ucs2Write (buf, string, offset, length) {
  6862. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6863. }
  6864. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6865. // Buffer#write(string)
  6866. if (offset === undefined) {
  6867. encoding = 'utf8'
  6868. length = this.length
  6869. offset = 0
  6870. // Buffer#write(string, encoding)
  6871. } else if (length === undefined && typeof offset === 'string') {
  6872. encoding = offset
  6873. length = this.length
  6874. offset = 0
  6875. // Buffer#write(string, offset[, length][, encoding])
  6876. } else if (isFinite(offset)) {
  6877. offset = offset | 0
  6878. if (isFinite(length)) {
  6879. length = length | 0
  6880. if (encoding === undefined) encoding = 'utf8'
  6881. } else {
  6882. encoding = length
  6883. length = undefined
  6884. }
  6885. // legacy write(string, encoding, offset, length) - remove in v0.13
  6886. } else {
  6887. throw new Error(
  6888. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6889. )
  6890. }
  6891. var remaining = this.length - offset
  6892. if (length === undefined || length > remaining) length = remaining
  6893. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6894. throw new RangeError('Attempt to write outside buffer bounds')
  6895. }
  6896. if (!encoding) encoding = 'utf8'
  6897. var loweredCase = false
  6898. for (;;) {
  6899. switch (encoding) {
  6900. case 'hex':
  6901. return hexWrite(this, string, offset, length)
  6902. case 'utf8':
  6903. case 'utf-8':
  6904. return utf8Write(this, string, offset, length)
  6905. case 'ascii':
  6906. return asciiWrite(this, string, offset, length)
  6907. case 'binary':
  6908. return binaryWrite(this, string, offset, length)
  6909. case 'base64':
  6910. // Warning: maxLength not taken into account in base64Write
  6911. return base64Write(this, string, offset, length)
  6912. case 'ucs2':
  6913. case 'ucs-2':
  6914. case 'utf16le':
  6915. case 'utf-16le':
  6916. return ucs2Write(this, string, offset, length)
  6917. default:
  6918. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6919. encoding = ('' + encoding).toLowerCase()
  6920. loweredCase = true
  6921. }
  6922. }
  6923. }
  6924. Buffer.prototype.toJSON = function toJSON () {
  6925. return {
  6926. type: 'Buffer',
  6927. data: Array.prototype.slice.call(this._arr || this, 0)
  6928. }
  6929. }
  6930. function base64Slice (buf, start, end) {
  6931. if (start === 0 && end === buf.length) {
  6932. return base64.fromByteArray(buf)
  6933. } else {
  6934. return base64.fromByteArray(buf.slice(start, end))
  6935. }
  6936. }
  6937. function utf8Slice (buf, start, end) {
  6938. end = Math.min(buf.length, end)
  6939. var res = []
  6940. var i = start
  6941. while (i < end) {
  6942. var firstByte = buf[i]
  6943. var codePoint = null
  6944. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6945. : (firstByte > 0xDF) ? 3
  6946. : (firstByte > 0xBF) ? 2
  6947. : 1
  6948. if (i + bytesPerSequence <= end) {
  6949. var secondByte, thirdByte, fourthByte, tempCodePoint
  6950. switch (bytesPerSequence) {
  6951. case 1:
  6952. if (firstByte < 0x80) {
  6953. codePoint = firstByte
  6954. }
  6955. break
  6956. case 2:
  6957. secondByte = buf[i + 1]
  6958. if ((secondByte & 0xC0) === 0x80) {
  6959. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6960. if (tempCodePoint > 0x7F) {
  6961. codePoint = tempCodePoint
  6962. }
  6963. }
  6964. break
  6965. case 3:
  6966. secondByte = buf[i + 1]
  6967. thirdByte = buf[i + 2]
  6968. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6969. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6970. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6971. codePoint = tempCodePoint
  6972. }
  6973. }
  6974. break
  6975. case 4:
  6976. secondByte = buf[i + 1]
  6977. thirdByte = buf[i + 2]
  6978. fourthByte = buf[i + 3]
  6979. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6980. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6981. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6982. codePoint = tempCodePoint
  6983. }
  6984. }
  6985. }
  6986. }
  6987. if (codePoint === null) {
  6988. // we did not generate a valid codePoint so insert a
  6989. // replacement char (U+FFFD) and advance only 1 byte
  6990. codePoint = 0xFFFD
  6991. bytesPerSequence = 1
  6992. } else if (codePoint > 0xFFFF) {
  6993. // encode to utf16 (surrogate pair dance)
  6994. codePoint -= 0x10000
  6995. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6996. codePoint = 0xDC00 | codePoint & 0x3FF
  6997. }
  6998. res.push(codePoint)
  6999. i += bytesPerSequence
  7000. }
  7001. return decodeCodePointsArray(res)
  7002. }
  7003. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  7004. // the lowest limit is Chrome, with 0x10000 args.
  7005. // We go 1 magnitude less, for safety
  7006. var MAX_ARGUMENTS_LENGTH = 0x1000
  7007. function decodeCodePointsArray (codePoints) {
  7008. var len = codePoints.length
  7009. if (len <= MAX_ARGUMENTS_LENGTH) {
  7010. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  7011. }
  7012. // Decode in chunks to avoid "call stack size exceeded".
  7013. var res = ''
  7014. var i = 0
  7015. while (i < len) {
  7016. res += String.fromCharCode.apply(
  7017. String,
  7018. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  7019. )
  7020. }
  7021. return res
  7022. }
  7023. function asciiSlice (buf, start, end) {
  7024. var ret = ''
  7025. end = Math.min(buf.length, end)
  7026. for (var i = start; i < end; i++) {
  7027. ret += String.fromCharCode(buf[i] & 0x7F)
  7028. }
  7029. return ret
  7030. }
  7031. function binarySlice (buf, start, end) {
  7032. var ret = ''
  7033. end = Math.min(buf.length, end)
  7034. for (var i = start; i < end; i++) {
  7035. ret += String.fromCharCode(buf[i])
  7036. }
  7037. return ret
  7038. }
  7039. function hexSlice (buf, start, end) {
  7040. var len = buf.length
  7041. if (!start || start < 0) start = 0
  7042. if (!end || end < 0 || end > len) end = len
  7043. var out = ''
  7044. for (var i = start; i < end; i++) {
  7045. out += toHex(buf[i])
  7046. }
  7047. return out
  7048. }
  7049. function utf16leSlice (buf, start, end) {
  7050. var bytes = buf.slice(start, end)
  7051. var res = ''
  7052. for (var i = 0; i < bytes.length; i += 2) {
  7053. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7054. }
  7055. return res
  7056. }
  7057. Buffer.prototype.slice = function slice (start, end) {
  7058. var len = this.length
  7059. start = ~~start
  7060. end = end === undefined ? len : ~~end
  7061. if (start < 0) {
  7062. start += len
  7063. if (start < 0) start = 0
  7064. } else if (start > len) {
  7065. start = len
  7066. }
  7067. if (end < 0) {
  7068. end += len
  7069. if (end < 0) end = 0
  7070. } else if (end > len) {
  7071. end = len
  7072. }
  7073. if (end < start) end = start
  7074. var newBuf
  7075. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7076. newBuf = this.subarray(start, end)
  7077. newBuf.__proto__ = Buffer.prototype
  7078. } else {
  7079. var sliceLen = end - start
  7080. newBuf = new Buffer(sliceLen, undefined)
  7081. for (var i = 0; i < sliceLen; i++) {
  7082. newBuf[i] = this[i + start]
  7083. }
  7084. }
  7085. return newBuf
  7086. }
  7087. /*
  7088. * Need to make sure that buffer isn't trying to write out of bounds.
  7089. */
  7090. function checkOffset (offset, ext, length) {
  7091. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7092. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7093. }
  7094. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7095. offset = offset | 0
  7096. byteLength = byteLength | 0
  7097. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7098. var val = this[offset]
  7099. var mul = 1
  7100. var i = 0
  7101. while (++i < byteLength && (mul *= 0x100)) {
  7102. val += this[offset + i] * mul
  7103. }
  7104. return val
  7105. }
  7106. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7107. offset = offset | 0
  7108. byteLength = byteLength | 0
  7109. if (!noAssert) {
  7110. checkOffset(offset, byteLength, this.length)
  7111. }
  7112. var val = this[offset + --byteLength]
  7113. var mul = 1
  7114. while (byteLength > 0 && (mul *= 0x100)) {
  7115. val += this[offset + --byteLength] * mul
  7116. }
  7117. return val
  7118. }
  7119. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7120. if (!noAssert) checkOffset(offset, 1, this.length)
  7121. return this[offset]
  7122. }
  7123. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7124. if (!noAssert) checkOffset(offset, 2, this.length)
  7125. return this[offset] | (this[offset + 1] << 8)
  7126. }
  7127. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7128. if (!noAssert) checkOffset(offset, 2, this.length)
  7129. return (this[offset] << 8) | this[offset + 1]
  7130. }
  7131. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7132. if (!noAssert) checkOffset(offset, 4, this.length)
  7133. return ((this[offset]) |
  7134. (this[offset + 1] << 8) |
  7135. (this[offset + 2] << 16)) +
  7136. (this[offset + 3] * 0x1000000)
  7137. }
  7138. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7139. if (!noAssert) checkOffset(offset, 4, this.length)
  7140. return (this[offset] * 0x1000000) +
  7141. ((this[offset + 1] << 16) |
  7142. (this[offset + 2] << 8) |
  7143. this[offset + 3])
  7144. }
  7145. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7146. offset = offset | 0
  7147. byteLength = byteLength | 0
  7148. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7149. var val = this[offset]
  7150. var mul = 1
  7151. var i = 0
  7152. while (++i < byteLength && (mul *= 0x100)) {
  7153. val += this[offset + i] * mul
  7154. }
  7155. mul *= 0x80
  7156. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7157. return val
  7158. }
  7159. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7160. offset = offset | 0
  7161. byteLength = byteLength | 0
  7162. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7163. var i = byteLength
  7164. var mul = 1
  7165. var val = this[offset + --i]
  7166. while (i > 0 && (mul *= 0x100)) {
  7167. val += this[offset + --i] * mul
  7168. }
  7169. mul *= 0x80
  7170. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7171. return val
  7172. }
  7173. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7174. if (!noAssert) checkOffset(offset, 1, this.length)
  7175. if (!(this[offset] & 0x80)) return (this[offset])
  7176. return ((0xff - this[offset] + 1) * -1)
  7177. }
  7178. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7179. if (!noAssert) checkOffset(offset, 2, this.length)
  7180. var val = this[offset] | (this[offset + 1] << 8)
  7181. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7182. }
  7183. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7184. if (!noAssert) checkOffset(offset, 2, this.length)
  7185. var val = this[offset + 1] | (this[offset] << 8)
  7186. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7187. }
  7188. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7189. if (!noAssert) checkOffset(offset, 4, this.length)
  7190. return (this[offset]) |
  7191. (this[offset + 1] << 8) |
  7192. (this[offset + 2] << 16) |
  7193. (this[offset + 3] << 24)
  7194. }
  7195. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7196. if (!noAssert) checkOffset(offset, 4, this.length)
  7197. return (this[offset] << 24) |
  7198. (this[offset + 1] << 16) |
  7199. (this[offset + 2] << 8) |
  7200. (this[offset + 3])
  7201. }
  7202. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7203. if (!noAssert) checkOffset(offset, 4, this.length)
  7204. return ieee754.read(this, offset, true, 23, 4)
  7205. }
  7206. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7207. if (!noAssert) checkOffset(offset, 4, this.length)
  7208. return ieee754.read(this, offset, false, 23, 4)
  7209. }
  7210. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7211. if (!noAssert) checkOffset(offset, 8, this.length)
  7212. return ieee754.read(this, offset, true, 52, 8)
  7213. }
  7214. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7215. if (!noAssert) checkOffset(offset, 8, this.length)
  7216. return ieee754.read(this, offset, false, 52, 8)
  7217. }
  7218. function checkInt (buf, value, offset, ext, max, min) {
  7219. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7220. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7221. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7222. }
  7223. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7224. value = +value
  7225. offset = offset | 0
  7226. byteLength = byteLength | 0
  7227. if (!noAssert) {
  7228. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7229. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7230. }
  7231. var mul = 1
  7232. var i = 0
  7233. this[offset] = value & 0xFF
  7234. while (++i < byteLength && (mul *= 0x100)) {
  7235. this[offset + i] = (value / mul) & 0xFF
  7236. }
  7237. return offset + byteLength
  7238. }
  7239. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7240. value = +value
  7241. offset = offset | 0
  7242. byteLength = byteLength | 0
  7243. if (!noAssert) {
  7244. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7245. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7246. }
  7247. var i = byteLength - 1
  7248. var mul = 1
  7249. this[offset + i] = value & 0xFF
  7250. while (--i >= 0 && (mul *= 0x100)) {
  7251. this[offset + i] = (value / mul) & 0xFF
  7252. }
  7253. return offset + byteLength
  7254. }
  7255. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7256. value = +value
  7257. offset = offset | 0
  7258. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7259. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7260. this[offset] = (value & 0xff)
  7261. return offset + 1
  7262. }
  7263. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7264. if (value < 0) value = 0xffff + value + 1
  7265. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  7266. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7267. (littleEndian ? i : 1 - i) * 8
  7268. }
  7269. }
  7270. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7271. value = +value
  7272. offset = offset | 0
  7273. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7274. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7275. this[offset] = (value & 0xff)
  7276. this[offset + 1] = (value >>> 8)
  7277. } else {
  7278. objectWriteUInt16(this, value, offset, true)
  7279. }
  7280. return offset + 2
  7281. }
  7282. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7283. value = +value
  7284. offset = offset | 0
  7285. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7286. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7287. this[offset] = (value >>> 8)
  7288. this[offset + 1] = (value & 0xff)
  7289. } else {
  7290. objectWriteUInt16(this, value, offset, false)
  7291. }
  7292. return offset + 2
  7293. }
  7294. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7295. if (value < 0) value = 0xffffffff + value + 1
  7296. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  7297. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7298. }
  7299. }
  7300. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7301. value = +value
  7302. offset = offset | 0
  7303. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7304. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7305. this[offset + 3] = (value >>> 24)
  7306. this[offset + 2] = (value >>> 16)
  7307. this[offset + 1] = (value >>> 8)
  7308. this[offset] = (value & 0xff)
  7309. } else {
  7310. objectWriteUInt32(this, value, offset, true)
  7311. }
  7312. return offset + 4
  7313. }
  7314. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7315. value = +value
  7316. offset = offset | 0
  7317. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7318. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7319. this[offset] = (value >>> 24)
  7320. this[offset + 1] = (value >>> 16)
  7321. this[offset + 2] = (value >>> 8)
  7322. this[offset + 3] = (value & 0xff)
  7323. } else {
  7324. objectWriteUInt32(this, value, offset, false)
  7325. }
  7326. return offset + 4
  7327. }
  7328. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7329. value = +value
  7330. offset = offset | 0
  7331. if (!noAssert) {
  7332. var limit = Math.pow(2, 8 * byteLength - 1)
  7333. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7334. }
  7335. var i = 0
  7336. var mul = 1
  7337. var sub = 0
  7338. this[offset] = value & 0xFF
  7339. while (++i < byteLength && (mul *= 0x100)) {
  7340. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7341. sub = 1
  7342. }
  7343. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7344. }
  7345. return offset + byteLength
  7346. }
  7347. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7348. value = +value
  7349. offset = offset | 0
  7350. if (!noAssert) {
  7351. var limit = Math.pow(2, 8 * byteLength - 1)
  7352. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7353. }
  7354. var i = byteLength - 1
  7355. var mul = 1
  7356. var sub = 0
  7357. this[offset + i] = value & 0xFF
  7358. while (--i >= 0 && (mul *= 0x100)) {
  7359. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7360. sub = 1
  7361. }
  7362. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7363. }
  7364. return offset + byteLength
  7365. }
  7366. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7367. value = +value
  7368. offset = offset | 0
  7369. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7370. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7371. if (value < 0) value = 0xff + value + 1
  7372. this[offset] = (value & 0xff)
  7373. return offset + 1
  7374. }
  7375. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7376. value = +value
  7377. offset = offset | 0
  7378. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7379. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7380. this[offset] = (value & 0xff)
  7381. this[offset + 1] = (value >>> 8)
  7382. } else {
  7383. objectWriteUInt16(this, value, offset, true)
  7384. }
  7385. return offset + 2
  7386. }
  7387. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7388. value = +value
  7389. offset = offset | 0
  7390. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7391. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7392. this[offset] = (value >>> 8)
  7393. this[offset + 1] = (value & 0xff)
  7394. } else {
  7395. objectWriteUInt16(this, value, offset, false)
  7396. }
  7397. return offset + 2
  7398. }
  7399. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7400. value = +value
  7401. offset = offset | 0
  7402. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7403. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7404. this[offset] = (value & 0xff)
  7405. this[offset + 1] = (value >>> 8)
  7406. this[offset + 2] = (value >>> 16)
  7407. this[offset + 3] = (value >>> 24)
  7408. } else {
  7409. objectWriteUInt32(this, value, offset, true)
  7410. }
  7411. return offset + 4
  7412. }
  7413. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7414. value = +value
  7415. offset = offset | 0
  7416. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7417. if (value < 0) value = 0xffffffff + value + 1
  7418. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7419. this[offset] = (value >>> 24)
  7420. this[offset + 1] = (value >>> 16)
  7421. this[offset + 2] = (value >>> 8)
  7422. this[offset + 3] = (value & 0xff)
  7423. } else {
  7424. objectWriteUInt32(this, value, offset, false)
  7425. }
  7426. return offset + 4
  7427. }
  7428. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7429. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7430. if (offset < 0) throw new RangeError('Index out of range')
  7431. }
  7432. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7433. if (!noAssert) {
  7434. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7435. }
  7436. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7437. return offset + 4
  7438. }
  7439. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7440. return writeFloat(this, value, offset, true, noAssert)
  7441. }
  7442. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7443. return writeFloat(this, value, offset, false, noAssert)
  7444. }
  7445. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7446. if (!noAssert) {
  7447. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7448. }
  7449. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7450. return offset + 8
  7451. }
  7452. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7453. return writeDouble(this, value, offset, true, noAssert)
  7454. }
  7455. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7456. return writeDouble(this, value, offset, false, noAssert)
  7457. }
  7458. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7459. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7460. if (!start) start = 0
  7461. if (!end && end !== 0) end = this.length
  7462. if (targetStart >= target.length) targetStart = target.length
  7463. if (!targetStart) targetStart = 0
  7464. if (end > 0 && end < start) end = start
  7465. // Copy 0 bytes; we're done
  7466. if (end === start) return 0
  7467. if (target.length === 0 || this.length === 0) return 0
  7468. // Fatal error conditions
  7469. if (targetStart < 0) {
  7470. throw new RangeError('targetStart out of bounds')
  7471. }
  7472. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7473. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7474. // Are we oob?
  7475. if (end > this.length) end = this.length
  7476. if (target.length - targetStart < end - start) {
  7477. end = target.length - targetStart + start
  7478. }
  7479. var len = end - start
  7480. var i
  7481. if (this === target && start < targetStart && targetStart < end) {
  7482. // descending copy from end
  7483. for (i = len - 1; i >= 0; i--) {
  7484. target[i + targetStart] = this[i + start]
  7485. }
  7486. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7487. // ascending copy from start
  7488. for (i = 0; i < len; i++) {
  7489. target[i + targetStart] = this[i + start]
  7490. }
  7491. } else {
  7492. Uint8Array.prototype.set.call(
  7493. target,
  7494. this.subarray(start, start + len),
  7495. targetStart
  7496. )
  7497. }
  7498. return len
  7499. }
  7500. // Usage:
  7501. // buffer.fill(number[, offset[, end]])
  7502. // buffer.fill(buffer[, offset[, end]])
  7503. // buffer.fill(string[, offset[, end]][, encoding])
  7504. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7505. // Handle string cases:
  7506. if (typeof val === 'string') {
  7507. if (typeof start === 'string') {
  7508. encoding = start
  7509. start = 0
  7510. end = this.length
  7511. } else if (typeof end === 'string') {
  7512. encoding = end
  7513. end = this.length
  7514. }
  7515. if (val.length === 1) {
  7516. var code = val.charCodeAt(0)
  7517. if (code < 256) {
  7518. val = code
  7519. }
  7520. }
  7521. if (encoding !== undefined && typeof encoding !== 'string') {
  7522. throw new TypeError('encoding must be a string')
  7523. }
  7524. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7525. throw new TypeError('Unknown encoding: ' + encoding)
  7526. }
  7527. } else if (typeof val === 'number') {
  7528. val = val & 255
  7529. }
  7530. // Invalid ranges are not set to a default, so can range check early.
  7531. if (start < 0 || this.length < start || this.length < end) {
  7532. throw new RangeError('Out of range index')
  7533. }
  7534. if (end <= start) {
  7535. return this
  7536. }
  7537. start = start >>> 0
  7538. end = end === undefined ? this.length : end >>> 0
  7539. if (!val) val = 0
  7540. var i
  7541. if (typeof val === 'number') {
  7542. for (i = start; i < end; i++) {
  7543. this[i] = val
  7544. }
  7545. } else {
  7546. var bytes = Buffer.isBuffer(val)
  7547. ? val
  7548. : utf8ToBytes(new Buffer(val, encoding).toString())
  7549. var len = bytes.length
  7550. for (i = 0; i < end - start; i++) {
  7551. this[i + start] = bytes[i % len]
  7552. }
  7553. }
  7554. return this
  7555. }
  7556. // HELPER FUNCTIONS
  7557. // ================
  7558. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7559. function base64clean (str) {
  7560. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7561. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7562. // Node converts strings with length < 2 to ''
  7563. if (str.length < 2) return ''
  7564. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7565. while (str.length % 4 !== 0) {
  7566. str = str + '='
  7567. }
  7568. return str
  7569. }
  7570. function stringtrim (str) {
  7571. if (str.trim) return str.trim()
  7572. return str.replace(/^\s+|\s+$/g, '')
  7573. }
  7574. function toHex (n) {
  7575. if (n < 16) return '0' + n.toString(16)
  7576. return n.toString(16)
  7577. }
  7578. function utf8ToBytes (string, units) {
  7579. units = units || Infinity
  7580. var codePoint
  7581. var length = string.length
  7582. var leadSurrogate = null
  7583. var bytes = []
  7584. for (var i = 0; i < length; i++) {
  7585. codePoint = string.charCodeAt(i)
  7586. // is surrogate component
  7587. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7588. // last char was a lead
  7589. if (!leadSurrogate) {
  7590. // no lead yet
  7591. if (codePoint > 0xDBFF) {
  7592. // unexpected trail
  7593. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7594. continue
  7595. } else if (i + 1 === length) {
  7596. // unpaired lead
  7597. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7598. continue
  7599. }
  7600. // valid lead
  7601. leadSurrogate = codePoint
  7602. continue
  7603. }
  7604. // 2 leads in a row
  7605. if (codePoint < 0xDC00) {
  7606. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7607. leadSurrogate = codePoint
  7608. continue
  7609. }
  7610. // valid surrogate pair
  7611. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7612. } else if (leadSurrogate) {
  7613. // valid bmp char, but last char was a lead
  7614. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7615. }
  7616. leadSurrogate = null
  7617. // encode utf8
  7618. if (codePoint < 0x80) {
  7619. if ((units -= 1) < 0) break
  7620. bytes.push(codePoint)
  7621. } else if (codePoint < 0x800) {
  7622. if ((units -= 2) < 0) break
  7623. bytes.push(
  7624. codePoint >> 0x6 | 0xC0,
  7625. codePoint & 0x3F | 0x80
  7626. )
  7627. } else if (codePoint < 0x10000) {
  7628. if ((units -= 3) < 0) break
  7629. bytes.push(
  7630. codePoint >> 0xC | 0xE0,
  7631. codePoint >> 0x6 & 0x3F | 0x80,
  7632. codePoint & 0x3F | 0x80
  7633. )
  7634. } else if (codePoint < 0x110000) {
  7635. if ((units -= 4) < 0) break
  7636. bytes.push(
  7637. codePoint >> 0x12 | 0xF0,
  7638. codePoint >> 0xC & 0x3F | 0x80,
  7639. codePoint >> 0x6 & 0x3F | 0x80,
  7640. codePoint & 0x3F | 0x80
  7641. )
  7642. } else {
  7643. throw new Error('Invalid code point')
  7644. }
  7645. }
  7646. return bytes
  7647. }
  7648. function asciiToBytes (str) {
  7649. var byteArray = []
  7650. for (var i = 0; i < str.length; i++) {
  7651. // Node's code seems to be doing this and not & 0x7F..
  7652. byteArray.push(str.charCodeAt(i) & 0xFF)
  7653. }
  7654. return byteArray
  7655. }
  7656. function utf16leToBytes (str, units) {
  7657. var c, hi, lo
  7658. var byteArray = []
  7659. for (var i = 0; i < str.length; i++) {
  7660. if ((units -= 2) < 0) break
  7661. c = str.charCodeAt(i)
  7662. hi = c >> 8
  7663. lo = c % 256
  7664. byteArray.push(lo)
  7665. byteArray.push(hi)
  7666. }
  7667. return byteArray
  7668. }
  7669. function base64ToBytes (str) {
  7670. return base64.toByteArray(base64clean(str))
  7671. }
  7672. function blitBuffer (src, dst, offset, length) {
  7673. for (var i = 0; i < length; i++) {
  7674. if ((i + offset >= dst.length) || (i >= src.length)) break
  7675. dst[i + offset] = src[i]
  7676. }
  7677. return i
  7678. }
  7679. function isnan (val) {
  7680. return val !== val // eslint-disable-line no-self-compare
  7681. }
  7682. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7683. },{"base64-js":17,"ieee754":90,"isarray":94}],47:[function(require,module,exports){
  7684. (function (Buffer){
  7685. var Transform = require('stream').Transform
  7686. var inherits = require('inherits')
  7687. var StringDecoder = require('string_decoder').StringDecoder
  7688. module.exports = CipherBase
  7689. inherits(CipherBase, Transform)
  7690. function CipherBase (hashMode) {
  7691. Transform.call(this)
  7692. this.hashMode = typeof hashMode === 'string'
  7693. if (this.hashMode) {
  7694. this[hashMode] = this._finalOrDigest
  7695. } else {
  7696. this.final = this._finalOrDigest
  7697. }
  7698. this._decoder = null
  7699. this._encoding = null
  7700. }
  7701. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  7702. if (typeof data === 'string') {
  7703. data = new Buffer(data, inputEnc)
  7704. }
  7705. var outData = this._update(data)
  7706. if (this.hashMode) {
  7707. return this
  7708. }
  7709. if (outputEnc) {
  7710. outData = this._toString(outData, outputEnc)
  7711. }
  7712. return outData
  7713. }
  7714. CipherBase.prototype.setAutoPadding = function () {}
  7715. CipherBase.prototype.getAuthTag = function () {
  7716. throw new Error('trying to get auth tag in unsupported state')
  7717. }
  7718. CipherBase.prototype.setAuthTag = function () {
  7719. throw new Error('trying to set auth tag in unsupported state')
  7720. }
  7721. CipherBase.prototype.setAAD = function () {
  7722. throw new Error('trying to set aad in unsupported state')
  7723. }
  7724. CipherBase.prototype._transform = function (data, _, next) {
  7725. var err
  7726. try {
  7727. if (this.hashMode) {
  7728. this._update(data)
  7729. } else {
  7730. this.push(this._update(data))
  7731. }
  7732. } catch (e) {
  7733. err = e
  7734. } finally {
  7735. next(err)
  7736. }
  7737. }
  7738. CipherBase.prototype._flush = function (done) {
  7739. var err
  7740. try {
  7741. this.push(this._final())
  7742. } catch (e) {
  7743. err = e
  7744. } finally {
  7745. done(err)
  7746. }
  7747. }
  7748. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  7749. var outData = this._final() || new Buffer('')
  7750. if (outputEnc) {
  7751. outData = this._toString(outData, outputEnc, true)
  7752. }
  7753. return outData
  7754. }
  7755. CipherBase.prototype._toString = function (value, enc, final) {
  7756. if (!this._decoder) {
  7757. this._decoder = new StringDecoder(enc)
  7758. this._encoding = enc
  7759. }
  7760. if (this._encoding !== enc) {
  7761. throw new Error('can\'t switch encodings')
  7762. }
  7763. var out = this._decoder.write(value)
  7764. if (final) {
  7765. out += this._decoder.end()
  7766. }
  7767. return out
  7768. }
  7769. }).call(this,require("buffer").Buffer)
  7770. },{"buffer":46,"inherits":92,"stream":137,"string_decoder":138}],48:[function(require,module,exports){
  7771. (function (Buffer){
  7772. // Copyright Joyent, Inc. and other Node contributors.
  7773. //
  7774. // Permission is hereby granted, free of charge, to any person obtaining a
  7775. // copy of this software and associated documentation files (the
  7776. // "Software"), to deal in the Software without restriction, including
  7777. // without limitation the rights to use, copy, modify, merge, publish,
  7778. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7779. // persons to whom the Software is furnished to do so, subject to the
  7780. // following conditions:
  7781. //
  7782. // The above copyright notice and this permission notice shall be included
  7783. // in all copies or substantial portions of the Software.
  7784. //
  7785. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7786. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7787. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7788. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7789. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7790. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7791. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7792. // NOTE: These type checking functions intentionally don't use `instanceof`
  7793. // because it is fragile and can be easily faked with `Object.create()`.
  7794. function isArray(arg) {
  7795. if (Array.isArray) {
  7796. return Array.isArray(arg);
  7797. }
  7798. return objectToString(arg) === '[object Array]';
  7799. }
  7800. exports.isArray = isArray;
  7801. function isBoolean(arg) {
  7802. return typeof arg === 'boolean';
  7803. }
  7804. exports.isBoolean = isBoolean;
  7805. function isNull(arg) {
  7806. return arg === null;
  7807. }
  7808. exports.isNull = isNull;
  7809. function isNullOrUndefined(arg) {
  7810. return arg == null;
  7811. }
  7812. exports.isNullOrUndefined = isNullOrUndefined;
  7813. function isNumber(arg) {
  7814. return typeof arg === 'number';
  7815. }
  7816. exports.isNumber = isNumber;
  7817. function isString(arg) {
  7818. return typeof arg === 'string';
  7819. }
  7820. exports.isString = isString;
  7821. function isSymbol(arg) {
  7822. return typeof arg === 'symbol';
  7823. }
  7824. exports.isSymbol = isSymbol;
  7825. function isUndefined(arg) {
  7826. return arg === void 0;
  7827. }
  7828. exports.isUndefined = isUndefined;
  7829. function isRegExp(re) {
  7830. return objectToString(re) === '[object RegExp]';
  7831. }
  7832. exports.isRegExp = isRegExp;
  7833. function isObject(arg) {
  7834. return typeof arg === 'object' && arg !== null;
  7835. }
  7836. exports.isObject = isObject;
  7837. function isDate(d) {
  7838. return objectToString(d) === '[object Date]';
  7839. }
  7840. exports.isDate = isDate;
  7841. function isError(e) {
  7842. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7843. }
  7844. exports.isError = isError;
  7845. function isFunction(arg) {
  7846. return typeof arg === 'function';
  7847. }
  7848. exports.isFunction = isFunction;
  7849. function isPrimitive(arg) {
  7850. return arg === null ||
  7851. typeof arg === 'boolean' ||
  7852. typeof arg === 'number' ||
  7853. typeof arg === 'string' ||
  7854. typeof arg === 'symbol' || // ES6 symbol
  7855. typeof arg === 'undefined';
  7856. }
  7857. exports.isPrimitive = isPrimitive;
  7858. exports.isBuffer = Buffer.isBuffer;
  7859. function objectToString(o) {
  7860. return Object.prototype.toString.call(o);
  7861. }
  7862. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7863. },{"../../is-buffer/index.js":93}],49:[function(require,module,exports){
  7864. (function (Buffer){
  7865. var elliptic = require('elliptic');
  7866. var BN = require('bn.js');
  7867. module.exports = function createECDH(curve) {
  7868. return new ECDH(curve);
  7869. };
  7870. var aliases = {
  7871. secp256k1: {
  7872. name: 'secp256k1',
  7873. byteLength: 32
  7874. },
  7875. secp224r1: {
  7876. name: 'p224',
  7877. byteLength: 28
  7878. },
  7879. prime256v1: {
  7880. name: 'p256',
  7881. byteLength: 32
  7882. },
  7883. prime192v1: {
  7884. name: 'p192',
  7885. byteLength: 24
  7886. },
  7887. ed25519: {
  7888. name: 'ed25519',
  7889. byteLength: 32
  7890. },
  7891. secp384r1: {
  7892. name: 'p384',
  7893. byteLength: 48
  7894. },
  7895. secp521r1: {
  7896. name: 'p521',
  7897. byteLength: 66
  7898. }
  7899. };
  7900. aliases.p224 = aliases.secp224r1;
  7901. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  7902. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  7903. aliases.p384 = aliases.secp384r1;
  7904. aliases.p521 = aliases.secp521r1;
  7905. function ECDH(curve) {
  7906. this.curveType = aliases[curve];
  7907. if (!this.curveType ) {
  7908. this.curveType = {
  7909. name: curve
  7910. };
  7911. }
  7912. this.curve = new elliptic.ec(this.curveType.name);
  7913. this.keys = void 0;
  7914. }
  7915. ECDH.prototype.generateKeys = function (enc, format) {
  7916. this.keys = this.curve.genKeyPair();
  7917. return this.getPublicKey(enc, format);
  7918. };
  7919. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  7920. inenc = inenc || 'utf8';
  7921. if (!Buffer.isBuffer(other)) {
  7922. other = new Buffer(other, inenc);
  7923. }
  7924. var otherPub = this.curve.keyFromPublic(other).getPublic();
  7925. var out = otherPub.mul(this.keys.getPrivate()).getX();
  7926. return formatReturnValue(out, enc, this.curveType.byteLength);
  7927. };
  7928. ECDH.prototype.getPublicKey = function (enc, format) {
  7929. var key = this.keys.getPublic(format === 'compressed', true);
  7930. if (format === 'hybrid') {
  7931. if (key[key.length - 1] % 2) {
  7932. key[0] = 7;
  7933. } else {
  7934. key [0] = 6;
  7935. }
  7936. }
  7937. return formatReturnValue(key, enc);
  7938. };
  7939. ECDH.prototype.getPrivateKey = function (enc) {
  7940. return formatReturnValue(this.keys.getPrivate(), enc);
  7941. };
  7942. ECDH.prototype.setPublicKey = function (pub, enc) {
  7943. enc = enc || 'utf8';
  7944. if (!Buffer.isBuffer(pub)) {
  7945. pub = new Buffer(pub, enc);
  7946. }
  7947. this.keys._importPublic(pub);
  7948. return this;
  7949. };
  7950. ECDH.prototype.setPrivateKey = function (priv, enc) {
  7951. enc = enc || 'utf8';
  7952. if (!Buffer.isBuffer(priv)) {
  7953. priv = new Buffer(priv, enc);
  7954. }
  7955. var _priv = new BN(priv);
  7956. _priv = _priv.toString(16);
  7957. this.keys._importPrivate(_priv);
  7958. return this;
  7959. };
  7960. function formatReturnValue(bn, enc, len) {
  7961. if (!Array.isArray(bn)) {
  7962. bn = bn.toArray();
  7963. }
  7964. var buf = new Buffer(bn);
  7965. if (len && buf.length < len) {
  7966. var zeros = new Buffer(len - buf.length);
  7967. zeros.fill(0);
  7968. buf = Buffer.concat([zeros, buf]);
  7969. }
  7970. if (!enc) {
  7971. return buf;
  7972. } else {
  7973. return buf.toString(enc);
  7974. }
  7975. }
  7976. }).call(this,require("buffer").Buffer)
  7977. },{"bn.js":18,"buffer":46,"elliptic":65}],50:[function(require,module,exports){
  7978. (function (Buffer){
  7979. 'use strict';
  7980. var inherits = require('inherits')
  7981. var md5 = require('./md5')
  7982. var rmd160 = require('ripemd160')
  7983. var sha = require('sha.js')
  7984. var Base = require('cipher-base')
  7985. function HashNoConstructor(hash) {
  7986. Base.call(this, 'digest')
  7987. this._hash = hash
  7988. this.buffers = []
  7989. }
  7990. inherits(HashNoConstructor, Base)
  7991. HashNoConstructor.prototype._update = function (data) {
  7992. this.buffers.push(data)
  7993. }
  7994. HashNoConstructor.prototype._final = function () {
  7995. var buf = Buffer.concat(this.buffers)
  7996. var r = this._hash(buf)
  7997. this.buffers = null
  7998. return r
  7999. }
  8000. function Hash(hash) {
  8001. Base.call(this, 'digest')
  8002. this._hash = hash
  8003. }
  8004. inherits(Hash, Base)
  8005. Hash.prototype._update = function (data) {
  8006. this._hash.update(data)
  8007. }
  8008. Hash.prototype._final = function () {
  8009. return this._hash.digest()
  8010. }
  8011. module.exports = function createHash (alg) {
  8012. alg = alg.toLowerCase()
  8013. if ('md5' === alg) return new HashNoConstructor(md5)
  8014. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  8015. return new Hash(sha(alg))
  8016. }
  8017. }).call(this,require("buffer").Buffer)
  8018. },{"./md5":52,"buffer":46,"cipher-base":47,"inherits":92,"ripemd160":128,"sha.js":130}],51:[function(require,module,exports){
  8019. (function (Buffer){
  8020. 'use strict';
  8021. var intSize = 4;
  8022. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  8023. var chrsz = 8;
  8024. function toArray(buf, bigEndian) {
  8025. if ((buf.length % intSize) !== 0) {
  8026. var len = buf.length + (intSize - (buf.length % intSize));
  8027. buf = Buffer.concat([buf, zeroBuffer], len);
  8028. }
  8029. var arr = [];
  8030. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  8031. for (var i = 0; i < buf.length; i += intSize) {
  8032. arr.push(fn.call(buf, i));
  8033. }
  8034. return arr;
  8035. }
  8036. function toBuffer(arr, size, bigEndian) {
  8037. var buf = new Buffer(size);
  8038. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  8039. for (var i = 0; i < arr.length; i++) {
  8040. fn.call(buf, arr[i], i * 4, true);
  8041. }
  8042. return buf;
  8043. }
  8044. function hash(buf, fn, hashSize, bigEndian) {
  8045. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  8046. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  8047. return toBuffer(arr, hashSize, bigEndian);
  8048. }
  8049. exports.hash = hash;
  8050. }).call(this,require("buffer").Buffer)
  8051. },{"buffer":46}],52:[function(require,module,exports){
  8052. 'use strict';
  8053. /*
  8054. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  8055. * Digest Algorithm, as defined in RFC 1321.
  8056. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  8057. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  8058. * Distributed under the BSD License
  8059. * See http://pajhome.org.uk/crypt/md5 for more info.
  8060. */
  8061. var helpers = require('./helpers');
  8062. /*
  8063. * Calculate the MD5 of an array of little-endian words, and a bit length
  8064. */
  8065. function core_md5(x, len)
  8066. {
  8067. /* append padding */
  8068. x[len >> 5] |= 0x80 << ((len) % 32);
  8069. x[(((len + 64) >>> 9) << 4) + 14] = len;
  8070. var a = 1732584193;
  8071. var b = -271733879;
  8072. var c = -1732584194;
  8073. var d = 271733878;
  8074. for(var i = 0; i < x.length; i += 16)
  8075. {
  8076. var olda = a;
  8077. var oldb = b;
  8078. var oldc = c;
  8079. var oldd = d;
  8080. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  8081. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  8082. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  8083. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  8084. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  8085. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  8086. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  8087. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  8088. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  8089. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  8090. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  8091. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  8092. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  8093. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  8094. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  8095. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  8096. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  8097. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  8098. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  8099. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  8100. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  8101. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  8102. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  8103. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  8104. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  8105. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  8106. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  8107. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  8108. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  8109. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  8110. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  8111. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  8112. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  8113. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  8114. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  8115. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  8116. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  8117. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  8118. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  8119. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  8120. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  8121. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  8122. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  8123. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  8124. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  8125. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  8126. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  8127. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  8128. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  8129. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  8130. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  8131. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  8132. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  8133. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  8134. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  8135. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  8136. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  8137. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  8138. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  8139. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  8140. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  8141. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  8142. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  8143. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  8144. a = safe_add(a, olda);
  8145. b = safe_add(b, oldb);
  8146. c = safe_add(c, oldc);
  8147. d = safe_add(d, oldd);
  8148. }
  8149. return Array(a, b, c, d);
  8150. }
  8151. /*
  8152. * These functions implement the four basic operations the algorithm uses.
  8153. */
  8154. function md5_cmn(q, a, b, x, s, t)
  8155. {
  8156. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  8157. }
  8158. function md5_ff(a, b, c, d, x, s, t)
  8159. {
  8160. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  8161. }
  8162. function md5_gg(a, b, c, d, x, s, t)
  8163. {
  8164. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  8165. }
  8166. function md5_hh(a, b, c, d, x, s, t)
  8167. {
  8168. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  8169. }
  8170. function md5_ii(a, b, c, d, x, s, t)
  8171. {
  8172. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  8173. }
  8174. /*
  8175. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  8176. * to work around bugs in some JS interpreters.
  8177. */
  8178. function safe_add(x, y)
  8179. {
  8180. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  8181. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  8182. return (msw << 16) | (lsw & 0xFFFF);
  8183. }
  8184. /*
  8185. * Bitwise rotate a 32-bit number to the left.
  8186. */
  8187. function bit_rol(num, cnt)
  8188. {
  8189. return (num << cnt) | (num >>> (32 - cnt));
  8190. }
  8191. module.exports = function md5(buf) {
  8192. return helpers.hash(buf, core_md5, 16);
  8193. };
  8194. },{"./helpers":51}],53:[function(require,module,exports){
  8195. (function (Buffer){
  8196. 'use strict';
  8197. var createHash = require('create-hash/browser');
  8198. var inherits = require('inherits')
  8199. var Transform = require('stream').Transform
  8200. var ZEROS = new Buffer(128)
  8201. ZEROS.fill(0)
  8202. function Hmac(alg, key) {
  8203. Transform.call(this)
  8204. alg = alg.toLowerCase()
  8205. if (typeof key === 'string') {
  8206. key = new Buffer(key)
  8207. }
  8208. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  8209. this._alg = alg
  8210. this._key = key
  8211. if (key.length > blocksize) {
  8212. key = createHash(alg).update(key).digest()
  8213. } else if (key.length < blocksize) {
  8214. key = Buffer.concat([key, ZEROS], blocksize)
  8215. }
  8216. var ipad = this._ipad = new Buffer(blocksize)
  8217. var opad = this._opad = new Buffer(blocksize)
  8218. for (var i = 0; i < blocksize; i++) {
  8219. ipad[i] = key[i] ^ 0x36
  8220. opad[i] = key[i] ^ 0x5C
  8221. }
  8222. this._hash = createHash(alg).update(ipad)
  8223. }
  8224. inherits(Hmac, Transform)
  8225. Hmac.prototype.update = function (data, enc) {
  8226. this._hash.update(data, enc)
  8227. return this
  8228. }
  8229. Hmac.prototype._transform = function (data, _, next) {
  8230. this._hash.update(data)
  8231. next()
  8232. }
  8233. Hmac.prototype._flush = function (next) {
  8234. this.push(this.digest())
  8235. next()
  8236. }
  8237. Hmac.prototype.digest = function (enc) {
  8238. var h = this._hash.digest()
  8239. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  8240. }
  8241. module.exports = function createHmac(alg, key) {
  8242. return new Hmac(alg, key)
  8243. }
  8244. }).call(this,require("buffer").Buffer)
  8245. },{"buffer":46,"create-hash/browser":50,"inherits":92,"stream":137}],54:[function(require,module,exports){
  8246. 'use strict'
  8247. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
  8248. exports.createHash = exports.Hash = require('create-hash')
  8249. exports.createHmac = exports.Hmac = require('create-hmac')
  8250. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos')))
  8251. exports.getHashes = function () {
  8252. return hashes
  8253. }
  8254. var p = require('pbkdf2')
  8255. exports.pbkdf2 = p.pbkdf2
  8256. exports.pbkdf2Sync = p.pbkdf2Sync
  8257. var aes = require('browserify-cipher')
  8258. ;[
  8259. 'Cipher',
  8260. 'createCipher',
  8261. 'Cipheriv',
  8262. 'createCipheriv',
  8263. 'Decipher',
  8264. 'createDecipher',
  8265. 'Decipheriv',
  8266. 'createDecipheriv',
  8267. 'getCiphers',
  8268. 'listCiphers'
  8269. ].forEach(function (key) {
  8270. exports[key] = aes[key]
  8271. })
  8272. var dh = require('diffie-hellman')
  8273. ;[
  8274. 'DiffieHellmanGroup',
  8275. 'createDiffieHellmanGroup',
  8276. 'getDiffieHellman',
  8277. 'createDiffieHellman',
  8278. 'DiffieHellman'
  8279. ].forEach(function (key) {
  8280. exports[key] = dh[key]
  8281. })
  8282. var sign = require('browserify-sign')
  8283. ;[
  8284. 'createSign',
  8285. 'Sign',
  8286. 'createVerify',
  8287. 'Verify'
  8288. ].forEach(function (key) {
  8289. exports[key] = sign[key]
  8290. })
  8291. exports.createECDH = require('create-ecdh')
  8292. var publicEncrypt = require('public-encrypt')
  8293. ;[
  8294. 'publicEncrypt',
  8295. 'privateEncrypt',
  8296. 'publicDecrypt',
  8297. 'privateDecrypt'
  8298. ].forEach(function (key) {
  8299. exports[key] = publicEncrypt[key]
  8300. })
  8301. // the least I can do is make error messages for the rest of the node.js/crypto api.
  8302. ;[
  8303. 'createCredentials'
  8304. ].forEach(function (name) {
  8305. exports[name] = function () {
  8306. throw new Error([
  8307. 'sorry, ' + name + ' is not implemented yet',
  8308. 'we accept pull requests',
  8309. 'https://github.com/crypto-browserify/crypto-browserify'
  8310. ].join('\n'))
  8311. }
  8312. })
  8313. },{"browserify-cipher":36,"browserify-sign":41,"browserify-sign/algos":40,"create-ecdh":49,"create-hash":50,"create-hmac":53,"diffie-hellman":61,"pbkdf2":104,"public-encrypt":107,"randombytes":117}],55:[function(require,module,exports){
  8314. 'use strict';
  8315. exports.utils = require('./des/utils');
  8316. exports.Cipher = require('./des/cipher');
  8317. exports.DES = require('./des/des');
  8318. exports.CBC = require('./des/cbc');
  8319. exports.EDE = require('./des/ede');
  8320. },{"./des/cbc":56,"./des/cipher":57,"./des/des":58,"./des/ede":59,"./des/utils":60}],56:[function(require,module,exports){
  8321. 'use strict';
  8322. var assert = require('minimalistic-assert');
  8323. var inherits = require('inherits');
  8324. var proto = {};
  8325. function CBCState(iv) {
  8326. assert.equal(iv.length, 8, 'Invalid IV length');
  8327. this.iv = new Array(8);
  8328. for (var i = 0; i < this.iv.length; i++)
  8329. this.iv[i] = iv[i];
  8330. }
  8331. function instantiate(Base) {
  8332. function CBC(options) {
  8333. Base.call(this, options);
  8334. this._cbcInit();
  8335. }
  8336. inherits(CBC, Base);
  8337. var keys = Object.keys(proto);
  8338. for (var i = 0; i < keys.length; i++) {
  8339. var key = keys[i];
  8340. CBC.prototype[key] = proto[key];
  8341. }
  8342. CBC.create = function create(options) {
  8343. return new CBC(options);
  8344. };
  8345. return CBC;
  8346. }
  8347. exports.instantiate = instantiate;
  8348. proto._cbcInit = function _cbcInit() {
  8349. var state = new CBCState(this.options.iv);
  8350. this._cbcState = state;
  8351. };
  8352. proto._update = function _update(inp, inOff, out, outOff) {
  8353. var state = this._cbcState;
  8354. var superProto = this.constructor.super_.prototype;
  8355. var iv = state.iv;
  8356. if (this.type === 'encrypt') {
  8357. for (var i = 0; i < this.blockSize; i++)
  8358. iv[i] ^= inp[inOff + i];
  8359. superProto._update.call(this, iv, 0, out, outOff);
  8360. for (var i = 0; i < this.blockSize; i++)
  8361. iv[i] = out[outOff + i];
  8362. } else {
  8363. superProto._update.call(this, inp, inOff, out, outOff);
  8364. for (var i = 0; i < this.blockSize; i++)
  8365. out[outOff + i] ^= iv[i];
  8366. for (var i = 0; i < this.blockSize; i++)
  8367. iv[i] = inp[inOff + i];
  8368. }
  8369. };
  8370. },{"inherits":92,"minimalistic-assert":99}],57:[function(require,module,exports){
  8371. 'use strict';
  8372. var assert = require('minimalistic-assert');
  8373. function Cipher(options) {
  8374. this.options = options;
  8375. this.type = this.options.type;
  8376. this.blockSize = 8;
  8377. this._init();
  8378. this.buffer = new Array(this.blockSize);
  8379. this.bufferOff = 0;
  8380. }
  8381. module.exports = Cipher;
  8382. Cipher.prototype._init = function _init() {
  8383. // Might be overrided
  8384. };
  8385. Cipher.prototype.update = function update(data) {
  8386. if (data.length === 0)
  8387. return [];
  8388. if (this.type === 'decrypt')
  8389. return this._updateDecrypt(data);
  8390. else
  8391. return this._updateEncrypt(data);
  8392. };
  8393. Cipher.prototype._buffer = function _buffer(data, off) {
  8394. // Append data to buffer
  8395. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  8396. for (var i = 0; i < min; i++)
  8397. this.buffer[this.bufferOff + i] = data[off + i];
  8398. this.bufferOff += min;
  8399. // Shift next
  8400. return min;
  8401. };
  8402. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  8403. this._update(this.buffer, 0, out, off);
  8404. this.bufferOff = 0;
  8405. return this.blockSize;
  8406. };
  8407. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  8408. var inputOff = 0;
  8409. var outputOff = 0;
  8410. var count = ((this.bufferOff + data.length) / this.blockSize) | 0;
  8411. var out = new Array(count * this.blockSize);
  8412. if (this.bufferOff !== 0) {
  8413. inputOff += this._buffer(data, inputOff);
  8414. if (this.bufferOff === this.buffer.length)
  8415. outputOff += this._flushBuffer(out, outputOff);
  8416. }
  8417. // Write blocks
  8418. var max = data.length - ((data.length - inputOff) % this.blockSize);
  8419. for (; inputOff < max; inputOff += this.blockSize) {
  8420. this._update(data, inputOff, out, outputOff);
  8421. outputOff += this.blockSize;
  8422. }
  8423. // Queue rest
  8424. for (; inputOff < data.length; inputOff++, this.bufferOff++)
  8425. this.buffer[this.bufferOff] = data[inputOff];
  8426. return out;
  8427. };
  8428. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  8429. var inputOff = 0;
  8430. var outputOff = 0;
  8431. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  8432. var out = new Array(count * this.blockSize);
  8433. // TODO(indutny): optimize it, this is far from optimal
  8434. for (; count > 0; count--) {
  8435. inputOff += this._buffer(data, inputOff);
  8436. outputOff += this._flushBuffer(out, outputOff);
  8437. }
  8438. // Buffer rest of the input
  8439. inputOff += this._buffer(data, inputOff);
  8440. return out;
  8441. };
  8442. Cipher.prototype.final = function final(buffer) {
  8443. var first;
  8444. if (buffer)
  8445. first = this.update(buffer);
  8446. var last;
  8447. if (this.type === 'encrypt')
  8448. last = this._finalEncrypt();
  8449. else
  8450. last = this._finalDecrypt();
  8451. if (first)
  8452. return first.concat(last);
  8453. else
  8454. return last;
  8455. };
  8456. Cipher.prototype._pad = function _pad(buffer, off) {
  8457. if (off === 0)
  8458. return false;
  8459. while (off < buffer.length)
  8460. buffer[off++] = 0;
  8461. return true;
  8462. };
  8463. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  8464. if (!this._pad(this.buffer, this.bufferOff))
  8465. return [];
  8466. var out = new Array(this.blockSize);
  8467. this._update(this.buffer, 0, out, 0);
  8468. return out;
  8469. };
  8470. Cipher.prototype._unpad = function _unpad(buffer) {
  8471. return buffer;
  8472. };
  8473. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  8474. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  8475. var out = new Array(this.blockSize);
  8476. this._flushBuffer(out, 0);
  8477. return this._unpad(out);
  8478. };
  8479. },{"minimalistic-assert":99}],58:[function(require,module,exports){
  8480. 'use strict';
  8481. var assert = require('minimalistic-assert');
  8482. var inherits = require('inherits');
  8483. var des = require('../des');
  8484. var utils = des.utils;
  8485. var Cipher = des.Cipher;
  8486. function DESState() {
  8487. this.tmp = new Array(2);
  8488. this.keys = null;
  8489. }
  8490. function DES(options) {
  8491. Cipher.call(this, options);
  8492. var state = new DESState();
  8493. this._desState = state;
  8494. this.deriveKeys(state, options.key);
  8495. }
  8496. inherits(DES, Cipher);
  8497. module.exports = DES;
  8498. DES.create = function create(options) {
  8499. return new DES(options);
  8500. };
  8501. var shiftTable = [
  8502. 1, 1, 2, 2, 2, 2, 2, 2,
  8503. 1, 2, 2, 2, 2, 2, 2, 1
  8504. ];
  8505. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  8506. state.keys = new Array(16 * 2);
  8507. assert.equal(key.length, this.blockSize, 'Invalid key length');
  8508. var kL = utils.readUInt32BE(key, 0);
  8509. var kR = utils.readUInt32BE(key, 4);
  8510. utils.pc1(kL, kR, state.tmp, 0);
  8511. kL = state.tmp[0];
  8512. kR = state.tmp[1];
  8513. for (var i = 0; i < state.keys.length; i += 2) {
  8514. var shift = shiftTable[i >>> 1];
  8515. kL = utils.r28shl(kL, shift);
  8516. kR = utils.r28shl(kR, shift);
  8517. utils.pc2(kL, kR, state.keys, i);
  8518. }
  8519. };
  8520. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  8521. var state = this._desState;
  8522. var l = utils.readUInt32BE(inp, inOff);
  8523. var r = utils.readUInt32BE(inp, inOff + 4);
  8524. // Initial Permutation
  8525. utils.ip(l, r, state.tmp, 0);
  8526. l = state.tmp[0];
  8527. r = state.tmp[1];
  8528. if (this.type === 'encrypt')
  8529. this._encrypt(state, l, r, state.tmp, 0);
  8530. else
  8531. this._decrypt(state, l, r, state.tmp, 0);
  8532. l = state.tmp[0];
  8533. r = state.tmp[1];
  8534. utils.writeUInt32BE(out, l, outOff);
  8535. utils.writeUInt32BE(out, r, outOff + 4);
  8536. };
  8537. DES.prototype._pad = function _pad(buffer, off) {
  8538. var value = buffer.length - off;
  8539. for (var i = off; i < buffer.length; i++)
  8540. buffer[i] = value;
  8541. return true;
  8542. };
  8543. DES.prototype._unpad = function _unpad(buffer) {
  8544. var pad = buffer[buffer.length - 1];
  8545. for (var i = buffer.length - pad; i < buffer.length; i++)
  8546. assert.equal(buffer[i], pad);
  8547. return buffer.slice(0, buffer.length - pad);
  8548. };
  8549. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  8550. var l = lStart;
  8551. var r = rStart;
  8552. // Apply f() x16 times
  8553. for (var i = 0; i < state.keys.length; i += 2) {
  8554. var keyL = state.keys[i];
  8555. var keyR = state.keys[i + 1];
  8556. // f(r, k)
  8557. utils.expand(r, state.tmp, 0);
  8558. keyL ^= state.tmp[0];
  8559. keyR ^= state.tmp[1];
  8560. var s = utils.substitute(keyL, keyR);
  8561. var f = utils.permute(s);
  8562. var t = r;
  8563. r = (l ^ f) >>> 0;
  8564. l = t;
  8565. }
  8566. // Reverse Initial Permutation
  8567. utils.rip(r, l, out, off);
  8568. };
  8569. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  8570. var l = rStart;
  8571. var r = lStart;
  8572. // Apply f() x16 times
  8573. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  8574. var keyL = state.keys[i];
  8575. var keyR = state.keys[i + 1];
  8576. // f(r, k)
  8577. utils.expand(l, state.tmp, 0);
  8578. keyL ^= state.tmp[0];
  8579. keyR ^= state.tmp[1];
  8580. var s = utils.substitute(keyL, keyR);
  8581. var f = utils.permute(s);
  8582. var t = l;
  8583. l = (r ^ f) >>> 0;
  8584. r = t;
  8585. }
  8586. // Reverse Initial Permutation
  8587. utils.rip(l, r, out, off);
  8588. };
  8589. },{"../des":55,"inherits":92,"minimalistic-assert":99}],59:[function(require,module,exports){
  8590. 'use strict';
  8591. var assert = require('minimalistic-assert');
  8592. var inherits = require('inherits');
  8593. var des = require('../des');
  8594. var Cipher = des.Cipher;
  8595. var DES = des.DES;
  8596. function EDEState(type, key) {
  8597. assert.equal(key.length, 24, 'Invalid key length');
  8598. var k1 = key.slice(0, 8);
  8599. var k2 = key.slice(8, 16);
  8600. var k3 = key.slice(16, 24);
  8601. if (type === 'encrypt') {
  8602. this.ciphers = [
  8603. DES.create({ type: 'encrypt', key: k1 }),
  8604. DES.create({ type: 'decrypt', key: k2 }),
  8605. DES.create({ type: 'encrypt', key: k3 })
  8606. ];
  8607. } else {
  8608. this.ciphers = [
  8609. DES.create({ type: 'decrypt', key: k3 }),
  8610. DES.create({ type: 'encrypt', key: k2 }),
  8611. DES.create({ type: 'decrypt', key: k1 })
  8612. ];
  8613. }
  8614. }
  8615. function EDE(options) {
  8616. Cipher.call(this, options);
  8617. var state = new EDEState(this.type, this.options.key);
  8618. this._edeState = state;
  8619. }
  8620. inherits(EDE, Cipher);
  8621. module.exports = EDE;
  8622. EDE.create = function create(options) {
  8623. return new EDE(options);
  8624. };
  8625. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  8626. var state = this._edeState;
  8627. state.ciphers[0]._update(inp, inOff, out, outOff);
  8628. state.ciphers[1]._update(out, outOff, out, outOff);
  8629. state.ciphers[2]._update(out, outOff, out, outOff);
  8630. };
  8631. EDE.prototype._pad = DES.prototype._pad;
  8632. EDE.prototype._unpad = DES.prototype._unpad;
  8633. },{"../des":55,"inherits":92,"minimalistic-assert":99}],60:[function(require,module,exports){
  8634. 'use strict';
  8635. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  8636. var res = (bytes[0 + off] << 24) |
  8637. (bytes[1 + off] << 16) |
  8638. (bytes[2 + off] << 8) |
  8639. bytes[3 + off];
  8640. return res >>> 0;
  8641. };
  8642. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  8643. bytes[0 + off] = value >>> 24;
  8644. bytes[1 + off] = (value >>> 16) & 0xff;
  8645. bytes[2 + off] = (value >>> 8) & 0xff;
  8646. bytes[3 + off] = value & 0xff;
  8647. };
  8648. exports.ip = function ip(inL, inR, out, off) {
  8649. var outL = 0;
  8650. var outR = 0;
  8651. for (var i = 6; i >= 0; i -= 2) {
  8652. for (var j = 0; j <= 24; j += 8) {
  8653. outL <<= 1;
  8654. outL |= (inR >>> (j + i)) & 1;
  8655. }
  8656. for (var j = 0; j <= 24; j += 8) {
  8657. outL <<= 1;
  8658. outL |= (inL >>> (j + i)) & 1;
  8659. }
  8660. }
  8661. for (var i = 6; i >= 0; i -= 2) {
  8662. for (var j = 1; j <= 25; j += 8) {
  8663. outR <<= 1;
  8664. outR |= (inR >>> (j + i)) & 1;
  8665. }
  8666. for (var j = 1; j <= 25; j += 8) {
  8667. outR <<= 1;
  8668. outR |= (inL >>> (j + i)) & 1;
  8669. }
  8670. }
  8671. out[off + 0] = outL >>> 0;
  8672. out[off + 1] = outR >>> 0;
  8673. };
  8674. exports.rip = function rip(inL, inR, out, off) {
  8675. var outL = 0;
  8676. var outR = 0;
  8677. for (var i = 0; i < 4; i++) {
  8678. for (var j = 24; j >= 0; j -= 8) {
  8679. outL <<= 1;
  8680. outL |= (inR >>> (j + i)) & 1;
  8681. outL <<= 1;
  8682. outL |= (inL >>> (j + i)) & 1;
  8683. }
  8684. }
  8685. for (var i = 4; i < 8; i++) {
  8686. for (var j = 24; j >= 0; j -= 8) {
  8687. outR <<= 1;
  8688. outR |= (inR >>> (j + i)) & 1;
  8689. outR <<= 1;
  8690. outR |= (inL >>> (j + i)) & 1;
  8691. }
  8692. }
  8693. out[off + 0] = outL >>> 0;
  8694. out[off + 1] = outR >>> 0;
  8695. };
  8696. exports.pc1 = function pc1(inL, inR, out, off) {
  8697. var outL = 0;
  8698. var outR = 0;
  8699. // 7, 15, 23, 31, 39, 47, 55, 63
  8700. // 6, 14, 22, 30, 39, 47, 55, 63
  8701. // 5, 13, 21, 29, 39, 47, 55, 63
  8702. // 4, 12, 20, 28
  8703. for (var i = 7; i >= 5; i--) {
  8704. for (var j = 0; j <= 24; j += 8) {
  8705. outL <<= 1;
  8706. outL |= (inR >> (j + i)) & 1;
  8707. }
  8708. for (var j = 0; j <= 24; j += 8) {
  8709. outL <<= 1;
  8710. outL |= (inL >> (j + i)) & 1;
  8711. }
  8712. }
  8713. for (var j = 0; j <= 24; j += 8) {
  8714. outL <<= 1;
  8715. outL |= (inR >> (j + i)) & 1;
  8716. }
  8717. // 1, 9, 17, 25, 33, 41, 49, 57
  8718. // 2, 10, 18, 26, 34, 42, 50, 58
  8719. // 3, 11, 19, 27, 35, 43, 51, 59
  8720. // 36, 44, 52, 60
  8721. for (var i = 1; i <= 3; i++) {
  8722. for (var j = 0; j <= 24; j += 8) {
  8723. outR <<= 1;
  8724. outR |= (inR >> (j + i)) & 1;
  8725. }
  8726. for (var j = 0; j <= 24; j += 8) {
  8727. outR <<= 1;
  8728. outR |= (inL >> (j + i)) & 1;
  8729. }
  8730. }
  8731. for (var j = 0; j <= 24; j += 8) {
  8732. outR <<= 1;
  8733. outR |= (inL >> (j + i)) & 1;
  8734. }
  8735. out[off + 0] = outL >>> 0;
  8736. out[off + 1] = outR >>> 0;
  8737. };
  8738. exports.r28shl = function r28shl(num, shift) {
  8739. return ((num << shift) & 0xfffffff) | (num >>> (28 - shift));
  8740. };
  8741. var pc2table = [
  8742. // inL => outL
  8743. 14, 11, 17, 4, 27, 23, 25, 0,
  8744. 13, 22, 7, 18, 5, 9, 16, 24,
  8745. 2, 20, 12, 21, 1, 8, 15, 26,
  8746. // inR => outR
  8747. 15, 4, 25, 19, 9, 1, 26, 16,
  8748. 5, 11, 23, 8, 12, 7, 17, 0,
  8749. 22, 3, 10, 14, 6, 20, 27, 24
  8750. ];
  8751. exports.pc2 = function pc2(inL, inR, out, off) {
  8752. var outL = 0;
  8753. var outR = 0;
  8754. var len = pc2table.length >>> 1;
  8755. for (var i = 0; i < len; i++) {
  8756. outL <<= 1;
  8757. outL |= (inL >>> pc2table[i]) & 0x1;
  8758. }
  8759. for (var i = len; i < pc2table.length; i++) {
  8760. outR <<= 1;
  8761. outR |= (inR >>> pc2table[i]) & 0x1;
  8762. }
  8763. out[off + 0] = outL >>> 0;
  8764. out[off + 1] = outR >>> 0;
  8765. };
  8766. exports.expand = function expand(r, out, off) {
  8767. var outL = 0;
  8768. var outR = 0;
  8769. outL = ((r & 1) << 5) | (r >>> 27);
  8770. for (var i = 23; i >= 15; i -= 4) {
  8771. outL <<= 6;
  8772. outL |= (r >>> i) & 0x3f;
  8773. }
  8774. for (var i = 11; i >= 3; i -= 4) {
  8775. outR |= (r >>> i) & 0x3f;
  8776. outR <<= 6;
  8777. }
  8778. outR |= ((r & 0x1f) << 1) | (r >>> 31);
  8779. out[off + 0] = outL >>> 0;
  8780. out[off + 1] = outR >>> 0;
  8781. };
  8782. var sTable = [
  8783. 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
  8784. 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
  8785. 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
  8786. 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13,
  8787. 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
  8788. 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
  8789. 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
  8790. 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9,
  8791. 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
  8792. 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
  8793. 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
  8794. 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12,
  8795. 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
  8796. 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
  8797. 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
  8798. 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14,
  8799. 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
  8800. 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
  8801. 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
  8802. 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3,
  8803. 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
  8804. 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
  8805. 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
  8806. 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13,
  8807. 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
  8808. 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
  8809. 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
  8810. 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12,
  8811. 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
  8812. 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
  8813. 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
  8814. 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
  8815. ];
  8816. exports.substitute = function substitute(inL, inR) {
  8817. var out = 0;
  8818. for (var i = 0; i < 4; i++) {
  8819. var b = (inL >>> (18 - i * 6)) & 0x3f;
  8820. var sb = sTable[i * 0x40 + b];
  8821. out <<= 4;
  8822. out |= sb;
  8823. }
  8824. for (var i = 0; i < 4; i++) {
  8825. var b = (inR >>> (18 - i * 6)) & 0x3f;
  8826. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  8827. out <<= 4;
  8828. out |= sb;
  8829. }
  8830. return out >>> 0;
  8831. };
  8832. var permuteTable = [
  8833. 16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
  8834. 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7
  8835. ];
  8836. exports.permute = function permute(num) {
  8837. var out = 0;
  8838. for (var i = 0; i < permuteTable.length; i++) {
  8839. out <<= 1;
  8840. out |= (num >>> permuteTable[i]) & 0x1;
  8841. }
  8842. return out >>> 0;
  8843. };
  8844. exports.padSplit = function padSplit(num, size, group) {
  8845. var str = num.toString(2);
  8846. while (str.length < size)
  8847. str = '0' + str;
  8848. var out = [];
  8849. for (var i = 0; i < size; i += group)
  8850. out.push(str.slice(i, i + group));
  8851. return out.join(' ');
  8852. };
  8853. },{}],61:[function(require,module,exports){
  8854. (function (Buffer){
  8855. var generatePrime = require('./lib/generatePrime')
  8856. var primes = require('./lib/primes.json')
  8857. var DH = require('./lib/dh')
  8858. function getDiffieHellman (mod) {
  8859. var prime = new Buffer(primes[mod].prime, 'hex')
  8860. var gen = new Buffer(primes[mod].gen, 'hex')
  8861. return new DH(prime, gen)
  8862. }
  8863. var ENCODINGS = {
  8864. 'binary': true, 'hex': true, 'base64': true
  8865. }
  8866. function createDiffieHellman (prime, enc, generator, genc) {
  8867. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  8868. return createDiffieHellman(prime, 'binary', enc, generator)
  8869. }
  8870. enc = enc || 'binary'
  8871. genc = genc || 'binary'
  8872. generator = generator || new Buffer([2])
  8873. if (!Buffer.isBuffer(generator)) {
  8874. generator = new Buffer(generator, genc)
  8875. }
  8876. if (typeof prime === 'number') {
  8877. return new DH(generatePrime(prime, generator), generator, true)
  8878. }
  8879. if (!Buffer.isBuffer(prime)) {
  8880. prime = new Buffer(prime, enc)
  8881. }
  8882. return new DH(prime, generator, true)
  8883. }
  8884. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
  8885. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman
  8886. }).call(this,require("buffer").Buffer)
  8887. },{"./lib/dh":62,"./lib/generatePrime":63,"./lib/primes.json":64,"buffer":46}],62:[function(require,module,exports){
  8888. (function (Buffer){
  8889. var BN = require('bn.js');
  8890. var MillerRabin = require('miller-rabin');
  8891. var millerRabin = new MillerRabin();
  8892. var TWENTYFOUR = new BN(24);
  8893. var ELEVEN = new BN(11);
  8894. var TEN = new BN(10);
  8895. var THREE = new BN(3);
  8896. var SEVEN = new BN(7);
  8897. var primes = require('./generatePrime');
  8898. var randomBytes = require('randombytes');
  8899. module.exports = DH;
  8900. function setPublicKey(pub, enc) {
  8901. enc = enc || 'utf8';
  8902. if (!Buffer.isBuffer(pub)) {
  8903. pub = new Buffer(pub, enc);
  8904. }
  8905. this._pub = new BN(pub);
  8906. return this;
  8907. }
  8908. function setPrivateKey(priv, enc) {
  8909. enc = enc || 'utf8';
  8910. if (!Buffer.isBuffer(priv)) {
  8911. priv = new Buffer(priv, enc);
  8912. }
  8913. this._priv = new BN(priv);
  8914. return this;
  8915. }
  8916. var primeCache = {};
  8917. function checkPrime(prime, generator) {
  8918. var gen = generator.toString('hex');
  8919. var hex = [gen, prime.toString(16)].join('_');
  8920. if (hex in primeCache) {
  8921. return primeCache[hex];
  8922. }
  8923. var error = 0;
  8924. if (prime.isEven() ||
  8925. !primes.simpleSieve ||
  8926. !primes.fermatTest(prime) ||
  8927. !millerRabin.test(prime)) {
  8928. //not a prime so +1
  8929. error += 1;
  8930. if (gen === '02' || gen === '05') {
  8931. // we'd be able to check the generator
  8932. // it would fail so +8
  8933. error += 8;
  8934. } else {
  8935. //we wouldn't be able to test the generator
  8936. // so +4
  8937. error += 4;
  8938. }
  8939. primeCache[hex] = error;
  8940. return error;
  8941. }
  8942. if (!millerRabin.test(prime.shrn(1))) {
  8943. //not a safe prime
  8944. error += 2;
  8945. }
  8946. var rem;
  8947. switch (gen) {
  8948. case '02':
  8949. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  8950. // unsuidable generator
  8951. error += 8;
  8952. }
  8953. break;
  8954. case '05':
  8955. rem = prime.mod(TEN);
  8956. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  8957. // prime mod 10 needs to equal 3 or 7
  8958. error += 8;
  8959. }
  8960. break;
  8961. default:
  8962. error += 4;
  8963. }
  8964. primeCache[hex] = error;
  8965. return error;
  8966. }
  8967. function DH(prime, generator, malleable) {
  8968. this.setGenerator(generator);
  8969. this.__prime = new BN(prime);
  8970. this._prime = BN.mont(this.__prime);
  8971. this._primeLen = prime.length;
  8972. this._pub = undefined;
  8973. this._priv = undefined;
  8974. this._primeCode = undefined;
  8975. if (malleable) {
  8976. this.setPublicKey = setPublicKey;
  8977. this.setPrivateKey = setPrivateKey;
  8978. } else {
  8979. this._primeCode = 8;
  8980. }
  8981. }
  8982. Object.defineProperty(DH.prototype, 'verifyError', {
  8983. enumerable: true,
  8984. get: function () {
  8985. if (typeof this._primeCode !== 'number') {
  8986. this._primeCode = checkPrime(this.__prime, this.__gen);
  8987. }
  8988. return this._primeCode;
  8989. }
  8990. });
  8991. DH.prototype.generateKeys = function () {
  8992. if (!this._priv) {
  8993. this._priv = new BN(randomBytes(this._primeLen));
  8994. }
  8995. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  8996. return this.getPublicKey();
  8997. };
  8998. DH.prototype.computeSecret = function (other) {
  8999. other = new BN(other);
  9000. other = other.toRed(this._prime);
  9001. var secret = other.redPow(this._priv).fromRed();
  9002. var out = new Buffer(secret.toArray());
  9003. var prime = this.getPrime();
  9004. if (out.length < prime.length) {
  9005. var front = new Buffer(prime.length - out.length);
  9006. front.fill(0);
  9007. out = Buffer.concat([front, out]);
  9008. }
  9009. return out;
  9010. };
  9011. DH.prototype.getPublicKey = function getPublicKey(enc) {
  9012. return formatReturnValue(this._pub, enc);
  9013. };
  9014. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  9015. return formatReturnValue(this._priv, enc);
  9016. };
  9017. DH.prototype.getPrime = function (enc) {
  9018. return formatReturnValue(this.__prime, enc);
  9019. };
  9020. DH.prototype.getGenerator = function (enc) {
  9021. return formatReturnValue(this._gen, enc);
  9022. };
  9023. DH.prototype.setGenerator = function (gen, enc) {
  9024. enc = enc || 'utf8';
  9025. if (!Buffer.isBuffer(gen)) {
  9026. gen = new Buffer(gen, enc);
  9027. }
  9028. this.__gen = gen;
  9029. this._gen = new BN(gen);
  9030. return this;
  9031. };
  9032. function formatReturnValue(bn, enc) {
  9033. var buf = new Buffer(bn.toArray());
  9034. if (!enc) {
  9035. return buf;
  9036. } else {
  9037. return buf.toString(enc);
  9038. }
  9039. }
  9040. }).call(this,require("buffer").Buffer)
  9041. },{"./generatePrime":63,"bn.js":18,"buffer":46,"miller-rabin":98,"randombytes":117}],63:[function(require,module,exports){
  9042. var randomBytes = require('randombytes');
  9043. module.exports = findPrime;
  9044. findPrime.simpleSieve = simpleSieve;
  9045. findPrime.fermatTest = fermatTest;
  9046. var BN = require('bn.js');
  9047. var TWENTYFOUR = new BN(24);
  9048. var MillerRabin = require('miller-rabin');
  9049. var millerRabin = new MillerRabin();
  9050. var ONE = new BN(1);
  9051. var TWO = new BN(2);
  9052. var FIVE = new BN(5);
  9053. var SIXTEEN = new BN(16);
  9054. var EIGHT = new BN(8);
  9055. var TEN = new BN(10);
  9056. var THREE = new BN(3);
  9057. var SEVEN = new BN(7);
  9058. var ELEVEN = new BN(11);
  9059. var FOUR = new BN(4);
  9060. var TWELVE = new BN(12);
  9061. var primes = null;
  9062. function _getPrimes() {
  9063. if (primes !== null)
  9064. return primes;
  9065. var limit = 0x100000;
  9066. var res = [];
  9067. res[0] = 2;
  9068. for (var i = 1, k = 3; k < limit; k += 2) {
  9069. var sqrt = Math.ceil(Math.sqrt(k));
  9070. for (var j = 0; j < i && res[j] <= sqrt; j++)
  9071. if (k % res[j] === 0)
  9072. break;
  9073. if (i !== j && res[j] <= sqrt)
  9074. continue;
  9075. res[i++] = k;
  9076. }
  9077. primes = res;
  9078. return res;
  9079. }
  9080. function simpleSieve(p) {
  9081. var primes = _getPrimes();
  9082. for (var i = 0; i < primes.length; i++)
  9083. if (p.modn(primes[i]) === 0) {
  9084. if (p.cmpn(primes[i]) === 0) {
  9085. return true;
  9086. } else {
  9087. return false;
  9088. }
  9089. }
  9090. return true;
  9091. }
  9092. function fermatTest(p) {
  9093. var red = BN.mont(p);
  9094. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  9095. }
  9096. function findPrime(bits, gen) {
  9097. if (bits < 16) {
  9098. // this is what openssl does
  9099. if (gen === 2 || gen === 5) {
  9100. return new BN([0x8c, 0x7b]);
  9101. } else {
  9102. return new BN([0x8c, 0x27]);
  9103. }
  9104. }
  9105. gen = new BN(gen);
  9106. var num, n2;
  9107. while (true) {
  9108. num = new BN(randomBytes(Math.ceil(bits / 8)));
  9109. while (num.bitLength() > bits) {
  9110. num.ishrn(1);
  9111. }
  9112. if (num.isEven()) {
  9113. num.iadd(ONE);
  9114. }
  9115. if (!num.testn(1)) {
  9116. num.iadd(TWO);
  9117. }
  9118. if (!gen.cmp(TWO)) {
  9119. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  9120. num.iadd(FOUR);
  9121. }
  9122. } else if (!gen.cmp(FIVE)) {
  9123. while (num.mod(TEN).cmp(THREE)) {
  9124. num.iadd(FOUR);
  9125. }
  9126. }
  9127. n2 = num.shrn(1);
  9128. if (simpleSieve(n2) && simpleSieve(num) &&
  9129. fermatTest(n2) && fermatTest(num) &&
  9130. millerRabin.test(n2) && millerRabin.test(num)) {
  9131. return num;
  9132. }
  9133. }
  9134. }
  9135. },{"bn.js":18,"miller-rabin":98,"randombytes":117}],64:[function(require,module,exports){
  9136. module.exports={
  9137. "modp1": {
  9138. "gen": "02",
  9139. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
  9140. },
  9141. "modp2": {
  9142. "gen": "02",
  9143. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
  9144. },
  9145. "modp5": {
  9146. "gen": "02",
  9147. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
  9148. },
  9149. "modp14": {
  9150. "gen": "02",
  9151. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
  9152. },
  9153. "modp15": {
  9154. "gen": "02",
  9155. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
  9156. },
  9157. "modp16": {
  9158. "gen": "02",
  9159. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
  9160. },
  9161. "modp17": {
  9162. "gen": "02",
  9163. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
  9164. },
  9165. "modp18": {
  9166. "gen": "02",
  9167. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
  9168. }
  9169. }
  9170. },{}],65:[function(require,module,exports){
  9171. 'use strict';
  9172. var elliptic = exports;
  9173. elliptic.version = require('../package.json').version;
  9174. elliptic.utils = require('./elliptic/utils');
  9175. elliptic.rand = require('brorand');
  9176. elliptic.hmacDRBG = require('./elliptic/hmac-drbg');
  9177. elliptic.curve = require('./elliptic/curve');
  9178. elliptic.curves = require('./elliptic/curves');
  9179. // Protocols
  9180. elliptic.ec = require('./elliptic/ec');
  9181. elliptic.eddsa = require('./elliptic/eddsa');
  9182. },{"../package.json":81,"./elliptic/curve":68,"./elliptic/curves":71,"./elliptic/ec":72,"./elliptic/eddsa":75,"./elliptic/hmac-drbg":78,"./elliptic/utils":80,"brorand":19}],66:[function(require,module,exports){
  9183. 'use strict';
  9184. var BN = require('bn.js');
  9185. var elliptic = require('../../elliptic');
  9186. var utils = elliptic.utils;
  9187. var getNAF = utils.getNAF;
  9188. var getJSF = utils.getJSF;
  9189. var assert = utils.assert;
  9190. function BaseCurve(type, conf) {
  9191. this.type = type;
  9192. this.p = new BN(conf.p, 16);
  9193. // Use Montgomery, when there is no fast reduction for the prime
  9194. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
  9195. // Useful for many curves
  9196. this.zero = new BN(0).toRed(this.red);
  9197. this.one = new BN(1).toRed(this.red);
  9198. this.two = new BN(2).toRed(this.red);
  9199. // Curve configuration, optional
  9200. this.n = conf.n && new BN(conf.n, 16);
  9201. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
  9202. // Temporary arrays
  9203. this._wnafT1 = new Array(4);
  9204. this._wnafT2 = new Array(4);
  9205. this._wnafT3 = new Array(4);
  9206. this._wnafT4 = new Array(4);
  9207. }
  9208. module.exports = BaseCurve;
  9209. BaseCurve.prototype.point = function point() {
  9210. throw new Error('Not implemented');
  9211. };
  9212. BaseCurve.prototype.validate = function validate() {
  9213. throw new Error('Not implemented');
  9214. };
  9215. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  9216. assert(p.precomputed);
  9217. var doubles = p._getDoubles();
  9218. var naf = getNAF(k, 1);
  9219. var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
  9220. I /= 3;
  9221. // Translate into more windowed form
  9222. var repr = [];
  9223. for (var j = 0; j < naf.length; j += doubles.step) {
  9224. var nafW = 0;
  9225. for (var k = j + doubles.step - 1; k >= j; k--)
  9226. nafW = (nafW << 1) + naf[k];
  9227. repr.push(nafW);
  9228. }
  9229. var a = this.jpoint(null, null, null);
  9230. var b = this.jpoint(null, null, null);
  9231. for (var i = I; i > 0; i--) {
  9232. for (var j = 0; j < repr.length; j++) {
  9233. var nafW = repr[j];
  9234. if (nafW === i)
  9235. b = b.mixedAdd(doubles.points[j]);
  9236. else if (nafW === -i)
  9237. b = b.mixedAdd(doubles.points[j].neg());
  9238. }
  9239. a = a.add(b);
  9240. }
  9241. return a.toP();
  9242. };
  9243. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  9244. var w = 4;
  9245. // Precompute window
  9246. var nafPoints = p._getNAFPoints(w);
  9247. w = nafPoints.wnd;
  9248. var wnd = nafPoints.points;
  9249. // Get NAF form
  9250. var naf = getNAF(k, w);
  9251. // Add `this`*(N+1) for every w-NAF index
  9252. var acc = this.jpoint(null, null, null);
  9253. for (var i = naf.length - 1; i >= 0; i--) {
  9254. // Count zeroes
  9255. for (var k = 0; i >= 0 && naf[i] === 0; i--)
  9256. k++;
  9257. if (i >= 0)
  9258. k++;
  9259. acc = acc.dblp(k);
  9260. if (i < 0)
  9261. break;
  9262. var z = naf[i];
  9263. assert(z !== 0);
  9264. if (p.type === 'affine') {
  9265. // J +- P
  9266. if (z > 0)
  9267. acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
  9268. else
  9269. acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
  9270. } else {
  9271. // J +- J
  9272. if (z > 0)
  9273. acc = acc.add(wnd[(z - 1) >> 1]);
  9274. else
  9275. acc = acc.add(wnd[(-z - 1) >> 1].neg());
  9276. }
  9277. }
  9278. return p.type === 'affine' ? acc.toP() : acc;
  9279. };
  9280. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
  9281. points,
  9282. coeffs,
  9283. len) {
  9284. var wndWidth = this._wnafT1;
  9285. var wnd = this._wnafT2;
  9286. var naf = this._wnafT3;
  9287. // Fill all arrays
  9288. var max = 0;
  9289. for (var i = 0; i < len; i++) {
  9290. var p = points[i];
  9291. var nafPoints = p._getNAFPoints(defW);
  9292. wndWidth[i] = nafPoints.wnd;
  9293. wnd[i] = nafPoints.points;
  9294. }
  9295. // Comb small window NAFs
  9296. for (var i = len - 1; i >= 1; i -= 2) {
  9297. var a = i - 1;
  9298. var b = i;
  9299. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  9300. naf[a] = getNAF(coeffs[a], wndWidth[a]);
  9301. naf[b] = getNAF(coeffs[b], wndWidth[b]);
  9302. max = Math.max(naf[a].length, max);
  9303. max = Math.max(naf[b].length, max);
  9304. continue;
  9305. }
  9306. var comb = [
  9307. points[a], /* 1 */
  9308. null, /* 3 */
  9309. null, /* 5 */
  9310. points[b] /* 7 */
  9311. ];
  9312. // Try to avoid Projective points, if possible
  9313. if (points[a].y.cmp(points[b].y) === 0) {
  9314. comb[1] = points[a].add(points[b]);
  9315. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  9316. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  9317. comb[1] = points[a].toJ().mixedAdd(points[b]);
  9318. comb[2] = points[a].add(points[b].neg());
  9319. } else {
  9320. comb[1] = points[a].toJ().mixedAdd(points[b]);
  9321. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  9322. }
  9323. var index = [
  9324. -3, /* -1 -1 */
  9325. -1, /* -1 0 */
  9326. -5, /* -1 1 */
  9327. -7, /* 0 -1 */
  9328. 0, /* 0 0 */
  9329. 7, /* 0 1 */
  9330. 5, /* 1 -1 */
  9331. 1, /* 1 0 */
  9332. 3 /* 1 1 */
  9333. ];
  9334. var jsf = getJSF(coeffs[a], coeffs[b]);
  9335. max = Math.max(jsf[0].length, max);
  9336. naf[a] = new Array(max);
  9337. naf[b] = new Array(max);
  9338. for (var j = 0; j < max; j++) {
  9339. var ja = jsf[0][j] | 0;
  9340. var jb = jsf[1][j] | 0;
  9341. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  9342. naf[b][j] = 0;
  9343. wnd[a] = comb;
  9344. }
  9345. }
  9346. var acc = this.jpoint(null, null, null);
  9347. var tmp = this._wnafT4;
  9348. for (var i = max; i >= 0; i--) {
  9349. var k = 0;
  9350. while (i >= 0) {
  9351. var zero = true;
  9352. for (var j = 0; j < len; j++) {
  9353. tmp[j] = naf[j][i] | 0;
  9354. if (tmp[j] !== 0)
  9355. zero = false;
  9356. }
  9357. if (!zero)
  9358. break;
  9359. k++;
  9360. i--;
  9361. }
  9362. if (i >= 0)
  9363. k++;
  9364. acc = acc.dblp(k);
  9365. if (i < 0)
  9366. break;
  9367. for (var j = 0; j < len; j++) {
  9368. var z = tmp[j];
  9369. var p;
  9370. if (z === 0)
  9371. continue;
  9372. else if (z > 0)
  9373. p = wnd[j][(z - 1) >> 1];
  9374. else if (z < 0)
  9375. p = wnd[j][(-z - 1) >> 1].neg();
  9376. if (p.type === 'affine')
  9377. acc = acc.mixedAdd(p);
  9378. else
  9379. acc = acc.add(p);
  9380. }
  9381. }
  9382. // Zeroify references
  9383. for (var i = 0; i < len; i++)
  9384. wnd[i] = null;
  9385. return acc.toP();
  9386. };
  9387. function BasePoint(curve, type) {
  9388. this.curve = curve;
  9389. this.type = type;
  9390. this.precomputed = null;
  9391. }
  9392. BaseCurve.BasePoint = BasePoint;
  9393. BasePoint.prototype.eq = function eq(/*other*/) {
  9394. throw new Error('Not implemented');
  9395. };
  9396. BasePoint.prototype.validate = function validate() {
  9397. return this.curve.validate(this);
  9398. };
  9399. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  9400. bytes = utils.toArray(bytes, enc);
  9401. var len = this.p.byteLength();
  9402. if (bytes[0] === 0x04 && bytes.length - 1 === 2 * len) {
  9403. return this.point(bytes.slice(1, 1 + len),
  9404. bytes.slice(1 + len, 1 + 2 * len));
  9405. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
  9406. bytes.length - 1 === len) {
  9407. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  9408. }
  9409. throw new Error('Unknown point format');
  9410. };
  9411. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  9412. return this.encode(enc, true);
  9413. };
  9414. BasePoint.prototype._encode = function _encode(compact) {
  9415. var len = this.curve.p.byteLength();
  9416. var x = this.getX().toArray('be', len);
  9417. if (compact)
  9418. return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
  9419. return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
  9420. };
  9421. BasePoint.prototype.encode = function encode(enc, compact) {
  9422. return utils.encode(this._encode(compact), enc);
  9423. };
  9424. BasePoint.prototype.precompute = function precompute(power) {
  9425. if (this.precomputed)
  9426. return this;
  9427. var precomputed = {
  9428. doubles: null,
  9429. naf: null,
  9430. beta: null
  9431. };
  9432. precomputed.naf = this._getNAFPoints(8);
  9433. precomputed.doubles = this._getDoubles(4, power);
  9434. precomputed.beta = this._getBeta();
  9435. this.precomputed = precomputed;
  9436. return this;
  9437. };
  9438. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  9439. if (!this.precomputed)
  9440. return false;
  9441. var doubles = this.precomputed.doubles;
  9442. if (!doubles)
  9443. return false;
  9444. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  9445. };
  9446. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  9447. if (this.precomputed && this.precomputed.doubles)
  9448. return this.precomputed.doubles;
  9449. var doubles = [ this ];
  9450. var acc = this;
  9451. for (var i = 0; i < power; i += step) {
  9452. for (var j = 0; j < step; j++)
  9453. acc = acc.dbl();
  9454. doubles.push(acc);
  9455. }
  9456. return {
  9457. step: step,
  9458. points: doubles
  9459. };
  9460. };
  9461. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  9462. if (this.precomputed && this.precomputed.naf)
  9463. return this.precomputed.naf;
  9464. var res = [ this ];
  9465. var max = (1 << wnd) - 1;
  9466. var dbl = max === 1 ? null : this.dbl();
  9467. for (var i = 1; i < max; i++)
  9468. res[i] = res[i - 1].add(dbl);
  9469. return {
  9470. wnd: wnd,
  9471. points: res
  9472. };
  9473. };
  9474. BasePoint.prototype._getBeta = function _getBeta() {
  9475. return null;
  9476. };
  9477. BasePoint.prototype.dblp = function dblp(k) {
  9478. var r = this;
  9479. for (var i = 0; i < k; i++)
  9480. r = r.dbl();
  9481. return r;
  9482. };
  9483. },{"../../elliptic":65,"bn.js":18}],67:[function(require,module,exports){
  9484. 'use strict';
  9485. var curve = require('../curve');
  9486. var elliptic = require('../../elliptic');
  9487. var BN = require('bn.js');
  9488. var inherits = require('inherits');
  9489. var Base = curve.base;
  9490. var assert = elliptic.utils.assert;
  9491. function EdwardsCurve(conf) {
  9492. // NOTE: Important as we are creating point in Base.call()
  9493. this.twisted = (conf.a | 0) !== 1;
  9494. this.mOneA = this.twisted && (conf.a | 0) === -1;
  9495. this.extended = this.mOneA;
  9496. Base.call(this, 'edwards', conf);
  9497. this.a = new BN(conf.a, 16).umod(this.red.m);
  9498. this.a = this.a.toRed(this.red);
  9499. this.c = new BN(conf.c, 16).toRed(this.red);
  9500. this.c2 = this.c.redSqr();
  9501. this.d = new BN(conf.d, 16).toRed(this.red);
  9502. this.dd = this.d.redAdd(this.d);
  9503. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  9504. this.oneC = (conf.c | 0) === 1;
  9505. }
  9506. inherits(EdwardsCurve, Base);
  9507. module.exports = EdwardsCurve;
  9508. EdwardsCurve.prototype._mulA = function _mulA(num) {
  9509. if (this.mOneA)
  9510. return num.redNeg();
  9511. else
  9512. return this.a.redMul(num);
  9513. };
  9514. EdwardsCurve.prototype._mulC = function _mulC(num) {
  9515. if (this.oneC)
  9516. return num;
  9517. else
  9518. return this.c.redMul(num);
  9519. };
  9520. // Just for compatibility with Short curve
  9521. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  9522. return this.point(x, y, z, t);
  9523. };
  9524. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  9525. x = new BN(x, 16);
  9526. if (!x.red)
  9527. x = x.toRed(this.red);
  9528. var x2 = x.redSqr();
  9529. var rhs = this.c2.redSub(this.a.redMul(x2));
  9530. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  9531. var y2 = rhs.redMul(lhs.redInvm());
  9532. var y = y2.redSqrt();
  9533. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
  9534. throw new Error('invalid point');
  9535. var isOdd = y.fromRed().isOdd();
  9536. if (odd && !isOdd || !odd && isOdd)
  9537. y = y.redNeg();
  9538. return this.point(x, y);
  9539. };
  9540. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  9541. y = new BN(y, 16);
  9542. if (!y.red)
  9543. y = y.toRed(this.red);
  9544. // x^2 = (y^2 - 1) / (d y^2 + 1)
  9545. var y2 = y.redSqr();
  9546. var lhs = y2.redSub(this.one);
  9547. var rhs = y2.redMul(this.d).redAdd(this.one);
  9548. var x2 = lhs.redMul(rhs.redInvm());
  9549. if (x2.cmp(this.zero) === 0) {
  9550. if (odd)
  9551. throw new Error('invalid point');
  9552. else
  9553. return this.point(this.zero, y);
  9554. }
  9555. var x = x2.redSqrt();
  9556. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
  9557. throw new Error('invalid point');
  9558. if (x.isOdd() !== odd)
  9559. x = x.redNeg();
  9560. return this.point(x, y);
  9561. };
  9562. EdwardsCurve.prototype.validate = function validate(point) {
  9563. if (point.isInfinity())
  9564. return true;
  9565. // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  9566. point.normalize();
  9567. var x2 = point.x.redSqr();
  9568. var y2 = point.y.redSqr();
  9569. var lhs = x2.redMul(this.a).redAdd(y2);
  9570. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  9571. return lhs.cmp(rhs) === 0;
  9572. };
  9573. function Point(curve, x, y, z, t) {
  9574. Base.BasePoint.call(this, curve, 'projective');
  9575. if (x === null && y === null && z === null) {
  9576. this.x = this.curve.zero;
  9577. this.y = this.curve.one;
  9578. this.z = this.curve.one;
  9579. this.t = this.curve.zero;
  9580. this.zOne = true;
  9581. } else {
  9582. this.x = new BN(x, 16);
  9583. this.y = new BN(y, 16);
  9584. this.z = z ? new BN(z, 16) : this.curve.one;
  9585. this.t = t && new BN(t, 16);
  9586. if (!this.x.red)
  9587. this.x = this.x.toRed(this.curve.red);
  9588. if (!this.y.red)
  9589. this.y = this.y.toRed(this.curve.red);
  9590. if (!this.z.red)
  9591. this.z = this.z.toRed(this.curve.red);
  9592. if (this.t && !this.t.red)
  9593. this.t = this.t.toRed(this.curve.red);
  9594. this.zOne = this.z === this.curve.one;
  9595. // Use extended coordinates
  9596. if (this.curve.extended && !this.t) {
  9597. this.t = this.x.redMul(this.y);
  9598. if (!this.zOne)
  9599. this.t = this.t.redMul(this.z.redInvm());
  9600. }
  9601. }
  9602. }
  9603. inherits(Point, Base.BasePoint);
  9604. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  9605. return Point.fromJSON(this, obj);
  9606. };
  9607. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  9608. return new Point(this, x, y, z, t);
  9609. };
  9610. Point.fromJSON = function fromJSON(curve, obj) {
  9611. return new Point(curve, obj[0], obj[1], obj[2]);
  9612. };
  9613. Point.prototype.inspect = function inspect() {
  9614. if (this.isInfinity())
  9615. return '<EC Point Infinity>';
  9616. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  9617. ' y: ' + this.y.fromRed().toString(16, 2) +
  9618. ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  9619. };
  9620. Point.prototype.isInfinity = function isInfinity() {
  9621. // XXX This code assumes that zero is always zero in red
  9622. return this.x.cmpn(0) === 0 &&
  9623. this.y.cmp(this.z) === 0;
  9624. };
  9625. Point.prototype._extDbl = function _extDbl() {
  9626. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  9627. // #doubling-dbl-2008-hwcd
  9628. // 4M + 4S
  9629. // A = X1^2
  9630. var a = this.x.redSqr();
  9631. // B = Y1^2
  9632. var b = this.y.redSqr();
  9633. // C = 2 * Z1^2
  9634. var c = this.z.redSqr();
  9635. c = c.redIAdd(c);
  9636. // D = a * A
  9637. var d = this.curve._mulA(a);
  9638. // E = (X1 + Y1)^2 - A - B
  9639. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
  9640. // G = D + B
  9641. var g = d.redAdd(b);
  9642. // F = G - C
  9643. var f = g.redSub(c);
  9644. // H = D - B
  9645. var h = d.redSub(b);
  9646. // X3 = E * F
  9647. var nx = e.redMul(f);
  9648. // Y3 = G * H
  9649. var ny = g.redMul(h);
  9650. // T3 = E * H
  9651. var nt = e.redMul(h);
  9652. // Z3 = F * G
  9653. var nz = f.redMul(g);
  9654. return this.curve.point(nx, ny, nz, nt);
  9655. };
  9656. Point.prototype._projDbl = function _projDbl() {
  9657. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  9658. // #doubling-dbl-2008-bbjlp
  9659. // #doubling-dbl-2007-bl
  9660. // and others
  9661. // Generally 3M + 4S or 2M + 4S
  9662. // B = (X1 + Y1)^2
  9663. var b = this.x.redAdd(this.y).redSqr();
  9664. // C = X1^2
  9665. var c = this.x.redSqr();
  9666. // D = Y1^2
  9667. var d = this.y.redSqr();
  9668. var nx;
  9669. var ny;
  9670. var nz;
  9671. if (this.curve.twisted) {
  9672. // E = a * C
  9673. var e = this.curve._mulA(c);
  9674. // F = E + D
  9675. var f = e.redAdd(d);
  9676. if (this.zOne) {
  9677. // X3 = (B - C - D) * (F - 2)
  9678. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
  9679. // Y3 = F * (E - D)
  9680. ny = f.redMul(e.redSub(d));
  9681. // Z3 = F^2 - 2 * F
  9682. nz = f.redSqr().redSub(f).redSub(f);
  9683. } else {
  9684. // H = Z1^2
  9685. var h = this.z.redSqr();
  9686. // J = F - 2 * H
  9687. var j = f.redSub(h).redISub(h);
  9688. // X3 = (B-C-D)*J
  9689. nx = b.redSub(c).redISub(d).redMul(j);
  9690. // Y3 = F * (E - D)
  9691. ny = f.redMul(e.redSub(d));
  9692. // Z3 = F * J
  9693. nz = f.redMul(j);
  9694. }
  9695. } else {
  9696. // E = C + D
  9697. var e = c.redAdd(d);
  9698. // H = (c * Z1)^2
  9699. var h = this.curve._mulC(this.c.redMul(this.z)).redSqr();
  9700. // J = E - 2 * H
  9701. var j = e.redSub(h).redSub(h);
  9702. // X3 = c * (B - E) * J
  9703. nx = this.curve._mulC(b.redISub(e)).redMul(j);
  9704. // Y3 = c * E * (C - D)
  9705. ny = this.curve._mulC(e).redMul(c.redISub(d));
  9706. // Z3 = E * J
  9707. nz = e.redMul(j);
  9708. }
  9709. return this.curve.point(nx, ny, nz);
  9710. };
  9711. Point.prototype.dbl = function dbl() {
  9712. if (this.isInfinity())
  9713. return this;
  9714. // Double in extended coordinates
  9715. if (this.curve.extended)
  9716. return this._extDbl();
  9717. else
  9718. return this._projDbl();
  9719. };
  9720. Point.prototype._extAdd = function _extAdd(p) {
  9721. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  9722. // #addition-add-2008-hwcd-3
  9723. // 8M
  9724. // A = (Y1 - X1) * (Y2 - X2)
  9725. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
  9726. // B = (Y1 + X1) * (Y2 + X2)
  9727. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
  9728. // C = T1 * k * T2
  9729. var c = this.t.redMul(this.curve.dd).redMul(p.t);
  9730. // D = Z1 * 2 * Z2
  9731. var d = this.z.redMul(p.z.redAdd(p.z));
  9732. // E = B - A
  9733. var e = b.redSub(a);
  9734. // F = D - C
  9735. var f = d.redSub(c);
  9736. // G = D + C
  9737. var g = d.redAdd(c);
  9738. // H = B + A
  9739. var h = b.redAdd(a);
  9740. // X3 = E * F
  9741. var nx = e.redMul(f);
  9742. // Y3 = G * H
  9743. var ny = g.redMul(h);
  9744. // T3 = E * H
  9745. var nt = e.redMul(h);
  9746. // Z3 = F * G
  9747. var nz = f.redMul(g);
  9748. return this.curve.point(nx, ny, nz, nt);
  9749. };
  9750. Point.prototype._projAdd = function _projAdd(p) {
  9751. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  9752. // #addition-add-2008-bbjlp
  9753. // #addition-add-2007-bl
  9754. // 10M + 1S
  9755. // A = Z1 * Z2
  9756. var a = this.z.redMul(p.z);
  9757. // B = A^2
  9758. var b = a.redSqr();
  9759. // C = X1 * X2
  9760. var c = this.x.redMul(p.x);
  9761. // D = Y1 * Y2
  9762. var d = this.y.redMul(p.y);
  9763. // E = d * C * D
  9764. var e = this.curve.d.redMul(c).redMul(d);
  9765. // F = B - E
  9766. var f = b.redSub(e);
  9767. // G = B + E
  9768. var g = b.redAdd(e);
  9769. // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  9770. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  9771. var nx = a.redMul(f).redMul(tmp);
  9772. var ny;
  9773. var nz;
  9774. if (this.curve.twisted) {
  9775. // Y3 = A * G * (D - a * C)
  9776. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
  9777. // Z3 = F * G
  9778. nz = f.redMul(g);
  9779. } else {
  9780. // Y3 = A * G * (D - C)
  9781. ny = a.redMul(g).redMul(d.redSub(c));
  9782. // Z3 = c * F * G
  9783. nz = this.curve._mulC(f).redMul(g);
  9784. }
  9785. return this.curve.point(nx, ny, nz);
  9786. };
  9787. Point.prototype.add = function add(p) {
  9788. if (this.isInfinity())
  9789. return p;
  9790. if (p.isInfinity())
  9791. return this;
  9792. if (this.curve.extended)
  9793. return this._extAdd(p);
  9794. else
  9795. return this._projAdd(p);
  9796. };
  9797. Point.prototype.mul = function mul(k) {
  9798. if (this._hasDoubles(k))
  9799. return this.curve._fixedNafMul(this, k);
  9800. else
  9801. return this.curve._wnafMul(this, k);
  9802. };
  9803. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  9804. return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2);
  9805. };
  9806. Point.prototype.normalize = function normalize() {
  9807. if (this.zOne)
  9808. return this;
  9809. // Normalize coordinates
  9810. var zi = this.z.redInvm();
  9811. this.x = this.x.redMul(zi);
  9812. this.y = this.y.redMul(zi);
  9813. if (this.t)
  9814. this.t = this.t.redMul(zi);
  9815. this.z = this.curve.one;
  9816. this.zOne = true;
  9817. return this;
  9818. };
  9819. Point.prototype.neg = function neg() {
  9820. return this.curve.point(this.x.redNeg(),
  9821. this.y,
  9822. this.z,
  9823. this.t && this.t.redNeg());
  9824. };
  9825. Point.prototype.getX = function getX() {
  9826. this.normalize();
  9827. return this.x.fromRed();
  9828. };
  9829. Point.prototype.getY = function getY() {
  9830. this.normalize();
  9831. return this.y.fromRed();
  9832. };
  9833. Point.prototype.eq = function eq(other) {
  9834. return this === other ||
  9835. this.getX().cmp(other.getX()) === 0 &&
  9836. this.getY().cmp(other.getY()) === 0;
  9837. };
  9838. // Compatibility with BaseCurve
  9839. Point.prototype.toP = Point.prototype.normalize;
  9840. Point.prototype.mixedAdd = Point.prototype.add;
  9841. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],68:[function(require,module,exports){
  9842. 'use strict';
  9843. var curve = exports;
  9844. curve.base = require('./base');
  9845. curve.short = require('./short');
  9846. curve.mont = require('./mont');
  9847. curve.edwards = require('./edwards');
  9848. },{"./base":66,"./edwards":67,"./mont":69,"./short":70}],69:[function(require,module,exports){
  9849. 'use strict';
  9850. var curve = require('../curve');
  9851. var BN = require('bn.js');
  9852. var inherits = require('inherits');
  9853. var Base = curve.base;
  9854. var elliptic = require('../../elliptic');
  9855. var utils = elliptic.utils;
  9856. function MontCurve(conf) {
  9857. Base.call(this, 'mont', conf);
  9858. this.a = new BN(conf.a, 16).toRed(this.red);
  9859. this.b = new BN(conf.b, 16).toRed(this.red);
  9860. this.i4 = new BN(4).toRed(this.red).redInvm();
  9861. this.two = new BN(2).toRed(this.red);
  9862. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  9863. }
  9864. inherits(MontCurve, Base);
  9865. module.exports = MontCurve;
  9866. MontCurve.prototype.validate = function validate(point) {
  9867. var x = point.normalize().x;
  9868. var x2 = x.redSqr();
  9869. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  9870. var y = rhs.redSqrt();
  9871. return y.redSqr().cmp(rhs) === 0;
  9872. };
  9873. function Point(curve, x, z) {
  9874. Base.BasePoint.call(this, curve, 'projective');
  9875. if (x === null && z === null) {
  9876. this.x = this.curve.one;
  9877. this.z = this.curve.zero;
  9878. } else {
  9879. this.x = new BN(x, 16);
  9880. this.z = new BN(z, 16);
  9881. if (!this.x.red)
  9882. this.x = this.x.toRed(this.curve.red);
  9883. if (!this.z.red)
  9884. this.z = this.z.toRed(this.curve.red);
  9885. }
  9886. }
  9887. inherits(Point, Base.BasePoint);
  9888. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  9889. return this.point(utils.toArray(bytes, enc), 1);
  9890. };
  9891. MontCurve.prototype.point = function point(x, z) {
  9892. return new Point(this, x, z);
  9893. };
  9894. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  9895. return Point.fromJSON(this, obj);
  9896. };
  9897. Point.prototype.precompute = function precompute() {
  9898. // No-op
  9899. };
  9900. Point.prototype._encode = function _encode() {
  9901. return this.getX().toArray('be', this.curve.p.byteLength());
  9902. };
  9903. Point.fromJSON = function fromJSON(curve, obj) {
  9904. return new Point(curve, obj[0], obj[1] || curve.one);
  9905. };
  9906. Point.prototype.inspect = function inspect() {
  9907. if (this.isInfinity())
  9908. return '<EC Point Infinity>';
  9909. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  9910. ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  9911. };
  9912. Point.prototype.isInfinity = function isInfinity() {
  9913. // XXX This code assumes that zero is always zero in red
  9914. return this.z.cmpn(0) === 0;
  9915. };
  9916. Point.prototype.dbl = function dbl() {
  9917. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  9918. // 2M + 2S + 4A
  9919. // A = X1 + Z1
  9920. var a = this.x.redAdd(this.z);
  9921. // AA = A^2
  9922. var aa = a.redSqr();
  9923. // B = X1 - Z1
  9924. var b = this.x.redSub(this.z);
  9925. // BB = B^2
  9926. var bb = b.redSqr();
  9927. // C = AA - BB
  9928. var c = aa.redSub(bb);
  9929. // X3 = AA * BB
  9930. var nx = aa.redMul(bb);
  9931. // Z3 = C * (BB + A24 * C)
  9932. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  9933. return this.curve.point(nx, nz);
  9934. };
  9935. Point.prototype.add = function add() {
  9936. throw new Error('Not supported on Montgomery curve');
  9937. };
  9938. Point.prototype.diffAdd = function diffAdd(p, diff) {
  9939. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  9940. // 4M + 2S + 6A
  9941. // A = X2 + Z2
  9942. var a = this.x.redAdd(this.z);
  9943. // B = X2 - Z2
  9944. var b = this.x.redSub(this.z);
  9945. // C = X3 + Z3
  9946. var c = p.x.redAdd(p.z);
  9947. // D = X3 - Z3
  9948. var d = p.x.redSub(p.z);
  9949. // DA = D * A
  9950. var da = d.redMul(a);
  9951. // CB = C * B
  9952. var cb = c.redMul(b);
  9953. // X5 = Z1 * (DA + CB)^2
  9954. var nx = diff.z.redMul(da.redAdd(cb).redSqr());
  9955. // Z5 = X1 * (DA - CB)^2
  9956. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  9957. return this.curve.point(nx, nz);
  9958. };
  9959. Point.prototype.mul = function mul(k) {
  9960. var t = k.clone();
  9961. var a = this; // (N / 2) * Q + Q
  9962. var b = this.curve.point(null, null); // (N / 2) * Q
  9963. var c = this; // Q
  9964. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
  9965. bits.push(t.andln(1));
  9966. for (var i = bits.length - 1; i >= 0; i--) {
  9967. if (bits[i] === 0) {
  9968. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  9969. a = a.diffAdd(b, c);
  9970. // N * Q = 2 * ((N / 2) * Q + Q))
  9971. b = b.dbl();
  9972. } else {
  9973. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  9974. b = a.diffAdd(b, c);
  9975. // N * Q + Q = 2 * ((N / 2) * Q + Q)
  9976. a = a.dbl();
  9977. }
  9978. }
  9979. return b;
  9980. };
  9981. Point.prototype.mulAdd = function mulAdd() {
  9982. throw new Error('Not supported on Montgomery curve');
  9983. };
  9984. Point.prototype.eq = function eq(other) {
  9985. return this.getX().cmp(other.getX()) === 0;
  9986. };
  9987. Point.prototype.normalize = function normalize() {
  9988. this.x = this.x.redMul(this.z.redInvm());
  9989. this.z = this.curve.one;
  9990. return this;
  9991. };
  9992. Point.prototype.getX = function getX() {
  9993. // Normalize coordinates
  9994. this.normalize();
  9995. return this.x.fromRed();
  9996. };
  9997. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],70:[function(require,module,exports){
  9998. 'use strict';
  9999. var curve = require('../curve');
  10000. var elliptic = require('../../elliptic');
  10001. var BN = require('bn.js');
  10002. var inherits = require('inherits');
  10003. var Base = curve.base;
  10004. var assert = elliptic.utils.assert;
  10005. function ShortCurve(conf) {
  10006. Base.call(this, 'short', conf);
  10007. this.a = new BN(conf.a, 16).toRed(this.red);
  10008. this.b = new BN(conf.b, 16).toRed(this.red);
  10009. this.tinv = this.two.redInvm();
  10010. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  10011. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
  10012. // If the curve is endomorphic, precalculate beta and lambda
  10013. this.endo = this._getEndomorphism(conf);
  10014. this._endoWnafT1 = new Array(4);
  10015. this._endoWnafT2 = new Array(4);
  10016. }
  10017. inherits(ShortCurve, Base);
  10018. module.exports = ShortCurve;
  10019. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  10020. // No efficient endomorphism
  10021. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
  10022. return;
  10023. // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  10024. var beta;
  10025. var lambda;
  10026. if (conf.beta) {
  10027. beta = new BN(conf.beta, 16).toRed(this.red);
  10028. } else {
  10029. var betas = this._getEndoRoots(this.p);
  10030. // Choose the smallest beta
  10031. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  10032. beta = beta.toRed(this.red);
  10033. }
  10034. if (conf.lambda) {
  10035. lambda = new BN(conf.lambda, 16);
  10036. } else {
  10037. // Choose the lambda that is matching selected beta
  10038. var lambdas = this._getEndoRoots(this.n);
  10039. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  10040. lambda = lambdas[0];
  10041. } else {
  10042. lambda = lambdas[1];
  10043. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  10044. }
  10045. }
  10046. // Get basis vectors, used for balanced length-two representation
  10047. var basis;
  10048. if (conf.basis) {
  10049. basis = conf.basis.map(function(vec) {
  10050. return {
  10051. a: new BN(vec.a, 16),
  10052. b: new BN(vec.b, 16)
  10053. };
  10054. });
  10055. } else {
  10056. basis = this._getEndoBasis(lambda);
  10057. }
  10058. return {
  10059. beta: beta,
  10060. lambda: lambda,
  10061. basis: basis
  10062. };
  10063. };
  10064. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  10065. // Find roots of for x^2 + x + 1 in F
  10066. // Root = (-1 +- Sqrt(-3)) / 2
  10067. //
  10068. var red = num === this.p ? this.red : BN.mont(num);
  10069. var tinv = new BN(2).toRed(red).redInvm();
  10070. var ntinv = tinv.redNeg();
  10071. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  10072. var l1 = ntinv.redAdd(s).fromRed();
  10073. var l2 = ntinv.redSub(s).fromRed();
  10074. return [ l1, l2 ];
  10075. };
  10076. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  10077. // aprxSqrt >= sqrt(this.n)
  10078. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
  10079. // 3.74
  10080. // Run EGCD, until r(L + 1) < aprxSqrt
  10081. var u = lambda;
  10082. var v = this.n.clone();
  10083. var x1 = new BN(1);
  10084. var y1 = new BN(0);
  10085. var x2 = new BN(0);
  10086. var y2 = new BN(1);
  10087. // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  10088. var a0;
  10089. var b0;
  10090. // First vector
  10091. var a1;
  10092. var b1;
  10093. // Second vector
  10094. var a2;
  10095. var b2;
  10096. var prevR;
  10097. var i = 0;
  10098. var r;
  10099. var x;
  10100. while (u.cmpn(0) !== 0) {
  10101. var q = v.div(u);
  10102. r = v.sub(q.mul(u));
  10103. x = x2.sub(q.mul(x1));
  10104. var y = y2.sub(q.mul(y1));
  10105. if (!a1 && r.cmp(aprxSqrt) < 0) {
  10106. a0 = prevR.neg();
  10107. b0 = x1;
  10108. a1 = r.neg();
  10109. b1 = x;
  10110. } else if (a1 && ++i === 2) {
  10111. break;
  10112. }
  10113. prevR = r;
  10114. v = u;
  10115. u = r;
  10116. x2 = x1;
  10117. x1 = x;
  10118. y2 = y1;
  10119. y1 = y;
  10120. }
  10121. a2 = r.neg();
  10122. b2 = x;
  10123. var len1 = a1.sqr().add(b1.sqr());
  10124. var len2 = a2.sqr().add(b2.sqr());
  10125. if (len2.cmp(len1) >= 0) {
  10126. a2 = a0;
  10127. b2 = b0;
  10128. }
  10129. // Normalize signs
  10130. if (a1.negative) {
  10131. a1 = a1.neg();
  10132. b1 = b1.neg();
  10133. }
  10134. if (a2.negative) {
  10135. a2 = a2.neg();
  10136. b2 = b2.neg();
  10137. }
  10138. return [
  10139. { a: a1, b: b1 },
  10140. { a: a2, b: b2 }
  10141. ];
  10142. };
  10143. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  10144. var basis = this.endo.basis;
  10145. var v1 = basis[0];
  10146. var v2 = basis[1];
  10147. var c1 = v2.b.mul(k).divRound(this.n);
  10148. var c2 = v1.b.neg().mul(k).divRound(this.n);
  10149. var p1 = c1.mul(v1.a);
  10150. var p2 = c2.mul(v2.a);
  10151. var q1 = c1.mul(v1.b);
  10152. var q2 = c2.mul(v2.b);
  10153. // Calculate answer
  10154. var k1 = k.sub(p1).sub(p2);
  10155. var k2 = q1.add(q2).neg();
  10156. return { k1: k1, k2: k2 };
  10157. };
  10158. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  10159. x = new BN(x, 16);
  10160. if (!x.red)
  10161. x = x.toRed(this.red);
  10162. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  10163. var y = y2.redSqrt();
  10164. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
  10165. throw new Error('invalid point');
  10166. // XXX Is there any way to tell if the number is odd without converting it
  10167. // to non-red form?
  10168. var isOdd = y.fromRed().isOdd();
  10169. if (odd && !isOdd || !odd && isOdd)
  10170. y = y.redNeg();
  10171. return this.point(x, y);
  10172. };
  10173. ShortCurve.prototype.validate = function validate(point) {
  10174. if (point.inf)
  10175. return true;
  10176. var x = point.x;
  10177. var y = point.y;
  10178. var ax = this.a.redMul(x);
  10179. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  10180. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  10181. };
  10182. ShortCurve.prototype._endoWnafMulAdd =
  10183. function _endoWnafMulAdd(points, coeffs) {
  10184. var npoints = this._endoWnafT1;
  10185. var ncoeffs = this._endoWnafT2;
  10186. for (var i = 0; i < points.length; i++) {
  10187. var split = this._endoSplit(coeffs[i]);
  10188. var p = points[i];
  10189. var beta = p._getBeta();
  10190. if (split.k1.negative) {
  10191. split.k1.ineg();
  10192. p = p.neg(true);
  10193. }
  10194. if (split.k2.negative) {
  10195. split.k2.ineg();
  10196. beta = beta.neg(true);
  10197. }
  10198. npoints[i * 2] = p;
  10199. npoints[i * 2 + 1] = beta;
  10200. ncoeffs[i * 2] = split.k1;
  10201. ncoeffs[i * 2 + 1] = split.k2;
  10202. }
  10203. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2);
  10204. // Clean-up references to points and coefficients
  10205. for (var j = 0; j < i * 2; j++) {
  10206. npoints[j] = null;
  10207. ncoeffs[j] = null;
  10208. }
  10209. return res;
  10210. };
  10211. function Point(curve, x, y, isRed) {
  10212. Base.BasePoint.call(this, curve, 'affine');
  10213. if (x === null && y === null) {
  10214. this.x = null;
  10215. this.y = null;
  10216. this.inf = true;
  10217. } else {
  10218. this.x = new BN(x, 16);
  10219. this.y = new BN(y, 16);
  10220. // Force redgomery representation when loading from JSON
  10221. if (isRed) {
  10222. this.x.forceRed(this.curve.red);
  10223. this.y.forceRed(this.curve.red);
  10224. }
  10225. if (!this.x.red)
  10226. this.x = this.x.toRed(this.curve.red);
  10227. if (!this.y.red)
  10228. this.y = this.y.toRed(this.curve.red);
  10229. this.inf = false;
  10230. }
  10231. }
  10232. inherits(Point, Base.BasePoint);
  10233. ShortCurve.prototype.point = function point(x, y, isRed) {
  10234. return new Point(this, x, y, isRed);
  10235. };
  10236. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  10237. return Point.fromJSON(this, obj, red);
  10238. };
  10239. Point.prototype._getBeta = function _getBeta() {
  10240. if (!this.curve.endo)
  10241. return;
  10242. var pre = this.precomputed;
  10243. if (pre && pre.beta)
  10244. return pre.beta;
  10245. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  10246. if (pre) {
  10247. var curve = this.curve;
  10248. var endoMul = function(p) {
  10249. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  10250. };
  10251. pre.beta = beta;
  10252. beta.precomputed = {
  10253. beta: null,
  10254. naf: pre.naf && {
  10255. wnd: pre.naf.wnd,
  10256. points: pre.naf.points.map(endoMul)
  10257. },
  10258. doubles: pre.doubles && {
  10259. step: pre.doubles.step,
  10260. points: pre.doubles.points.map(endoMul)
  10261. }
  10262. };
  10263. }
  10264. return beta;
  10265. };
  10266. Point.prototype.toJSON = function toJSON() {
  10267. if (!this.precomputed)
  10268. return [ this.x, this.y ];
  10269. return [ this.x, this.y, this.precomputed && {
  10270. doubles: this.precomputed.doubles && {
  10271. step: this.precomputed.doubles.step,
  10272. points: this.precomputed.doubles.points.slice(1)
  10273. },
  10274. naf: this.precomputed.naf && {
  10275. wnd: this.precomputed.naf.wnd,
  10276. points: this.precomputed.naf.points.slice(1)
  10277. }
  10278. } ];
  10279. };
  10280. Point.fromJSON = function fromJSON(curve, obj, red) {
  10281. if (typeof obj === 'string')
  10282. obj = JSON.parse(obj);
  10283. var res = curve.point(obj[0], obj[1], red);
  10284. if (!obj[2])
  10285. return res;
  10286. function obj2point(obj) {
  10287. return curve.point(obj[0], obj[1], red);
  10288. }
  10289. var pre = obj[2];
  10290. res.precomputed = {
  10291. beta: null,
  10292. doubles: pre.doubles && {
  10293. step: pre.doubles.step,
  10294. points: [ res ].concat(pre.doubles.points.map(obj2point))
  10295. },
  10296. naf: pre.naf && {
  10297. wnd: pre.naf.wnd,
  10298. points: [ res ].concat(pre.naf.points.map(obj2point))
  10299. }
  10300. };
  10301. return res;
  10302. };
  10303. Point.prototype.inspect = function inspect() {
  10304. if (this.isInfinity())
  10305. return '<EC Point Infinity>';
  10306. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  10307. ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  10308. };
  10309. Point.prototype.isInfinity = function isInfinity() {
  10310. return this.inf;
  10311. };
  10312. Point.prototype.add = function add(p) {
  10313. // O + P = P
  10314. if (this.inf)
  10315. return p;
  10316. // P + O = P
  10317. if (p.inf)
  10318. return this;
  10319. // P + P = 2P
  10320. if (this.eq(p))
  10321. return this.dbl();
  10322. // P + (-P) = O
  10323. if (this.neg().eq(p))
  10324. return this.curve.point(null, null);
  10325. // P + Q = O
  10326. if (this.x.cmp(p.x) === 0)
  10327. return this.curve.point(null, null);
  10328. var c = this.y.redSub(p.y);
  10329. if (c.cmpn(0) !== 0)
  10330. c = c.redMul(this.x.redSub(p.x).redInvm());
  10331. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  10332. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  10333. return this.curve.point(nx, ny);
  10334. };
  10335. Point.prototype.dbl = function dbl() {
  10336. if (this.inf)
  10337. return this;
  10338. // 2P = O
  10339. var ys1 = this.y.redAdd(this.y);
  10340. if (ys1.cmpn(0) === 0)
  10341. return this.curve.point(null, null);
  10342. var a = this.curve.a;
  10343. var x2 = this.x.redSqr();
  10344. var dyinv = ys1.redInvm();
  10345. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  10346. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  10347. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  10348. return this.curve.point(nx, ny);
  10349. };
  10350. Point.prototype.getX = function getX() {
  10351. return this.x.fromRed();
  10352. };
  10353. Point.prototype.getY = function getY() {
  10354. return this.y.fromRed();
  10355. };
  10356. Point.prototype.mul = function mul(k) {
  10357. k = new BN(k, 16);
  10358. if (this._hasDoubles(k))
  10359. return this.curve._fixedNafMul(this, k);
  10360. else if (this.curve.endo)
  10361. return this.curve._endoWnafMulAdd([ this ], [ k ]);
  10362. else
  10363. return this.curve._wnafMul(this, k);
  10364. };
  10365. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  10366. var points = [ this, p2 ];
  10367. var coeffs = [ k1, k2 ];
  10368. if (this.curve.endo)
  10369. return this.curve._endoWnafMulAdd(points, coeffs);
  10370. else
  10371. return this.curve._wnafMulAdd(1, points, coeffs, 2);
  10372. };
  10373. Point.prototype.eq = function eq(p) {
  10374. return this === p ||
  10375. this.inf === p.inf &&
  10376. (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  10377. };
  10378. Point.prototype.neg = function neg(_precompute) {
  10379. if (this.inf)
  10380. return this;
  10381. var res = this.curve.point(this.x, this.y.redNeg());
  10382. if (_precompute && this.precomputed) {
  10383. var pre = this.precomputed;
  10384. var negate = function(p) {
  10385. return p.neg();
  10386. };
  10387. res.precomputed = {
  10388. naf: pre.naf && {
  10389. wnd: pre.naf.wnd,
  10390. points: pre.naf.points.map(negate)
  10391. },
  10392. doubles: pre.doubles && {
  10393. step: pre.doubles.step,
  10394. points: pre.doubles.points.map(negate)
  10395. }
  10396. };
  10397. }
  10398. return res;
  10399. };
  10400. Point.prototype.toJ = function toJ() {
  10401. if (this.inf)
  10402. return this.curve.jpoint(null, null, null);
  10403. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  10404. return res;
  10405. };
  10406. function JPoint(curve, x, y, z) {
  10407. Base.BasePoint.call(this, curve, 'jacobian');
  10408. if (x === null && y === null && z === null) {
  10409. this.x = this.curve.one;
  10410. this.y = this.curve.one;
  10411. this.z = new BN(0);
  10412. } else {
  10413. this.x = new BN(x, 16);
  10414. this.y = new BN(y, 16);
  10415. this.z = new BN(z, 16);
  10416. }
  10417. if (!this.x.red)
  10418. this.x = this.x.toRed(this.curve.red);
  10419. if (!this.y.red)
  10420. this.y = this.y.toRed(this.curve.red);
  10421. if (!this.z.red)
  10422. this.z = this.z.toRed(this.curve.red);
  10423. this.zOne = this.z === this.curve.one;
  10424. }
  10425. inherits(JPoint, Base.BasePoint);
  10426. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  10427. return new JPoint(this, x, y, z);
  10428. };
  10429. JPoint.prototype.toP = function toP() {
  10430. if (this.isInfinity())
  10431. return this.curve.point(null, null);
  10432. var zinv = this.z.redInvm();
  10433. var zinv2 = zinv.redSqr();
  10434. var ax = this.x.redMul(zinv2);
  10435. var ay = this.y.redMul(zinv2).redMul(zinv);
  10436. return this.curve.point(ax, ay);
  10437. };
  10438. JPoint.prototype.neg = function neg() {
  10439. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  10440. };
  10441. JPoint.prototype.add = function add(p) {
  10442. // O + P = P
  10443. if (this.isInfinity())
  10444. return p;
  10445. // P + O = P
  10446. if (p.isInfinity())
  10447. return this;
  10448. // 12M + 4S + 7A
  10449. var pz2 = p.z.redSqr();
  10450. var z2 = this.z.redSqr();
  10451. var u1 = this.x.redMul(pz2);
  10452. var u2 = p.x.redMul(z2);
  10453. var s1 = this.y.redMul(pz2.redMul(p.z));
  10454. var s2 = p.y.redMul(z2.redMul(this.z));
  10455. var h = u1.redSub(u2);
  10456. var r = s1.redSub(s2);
  10457. if (h.cmpn(0) === 0) {
  10458. if (r.cmpn(0) !== 0)
  10459. return this.curve.jpoint(null, null, null);
  10460. else
  10461. return this.dbl();
  10462. }
  10463. var h2 = h.redSqr();
  10464. var h3 = h2.redMul(h);
  10465. var v = u1.redMul(h2);
  10466. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  10467. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  10468. var nz = this.z.redMul(p.z).redMul(h);
  10469. return this.curve.jpoint(nx, ny, nz);
  10470. };
  10471. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  10472. // O + P = P
  10473. if (this.isInfinity())
  10474. return p.toJ();
  10475. // P + O = P
  10476. if (p.isInfinity())
  10477. return this;
  10478. // 8M + 3S + 7A
  10479. var z2 = this.z.redSqr();
  10480. var u1 = this.x;
  10481. var u2 = p.x.redMul(z2);
  10482. var s1 = this.y;
  10483. var s2 = p.y.redMul(z2).redMul(this.z);
  10484. var h = u1.redSub(u2);
  10485. var r = s1.redSub(s2);
  10486. if (h.cmpn(0) === 0) {
  10487. if (r.cmpn(0) !== 0)
  10488. return this.curve.jpoint(null, null, null);
  10489. else
  10490. return this.dbl();
  10491. }
  10492. var h2 = h.redSqr();
  10493. var h3 = h2.redMul(h);
  10494. var v = u1.redMul(h2);
  10495. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  10496. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  10497. var nz = this.z.redMul(h);
  10498. return this.curve.jpoint(nx, ny, nz);
  10499. };
  10500. JPoint.prototype.dblp = function dblp(pow) {
  10501. if (pow === 0)
  10502. return this;
  10503. if (this.isInfinity())
  10504. return this;
  10505. if (!pow)
  10506. return this.dbl();
  10507. if (this.curve.zeroA || this.curve.threeA) {
  10508. var r = this;
  10509. for (var i = 0; i < pow; i++)
  10510. r = r.dbl();
  10511. return r;
  10512. }
  10513. // 1M + 2S + 1A + N * (4S + 5M + 8A)
  10514. // N = 1 => 6M + 6S + 9A
  10515. var a = this.curve.a;
  10516. var tinv = this.curve.tinv;
  10517. var jx = this.x;
  10518. var jy = this.y;
  10519. var jz = this.z;
  10520. var jz4 = jz.redSqr().redSqr();
  10521. // Reuse results
  10522. var jyd = jy.redAdd(jy);
  10523. for (var i = 0; i < pow; i++) {
  10524. var jx2 = jx.redSqr();
  10525. var jyd2 = jyd.redSqr();
  10526. var jyd4 = jyd2.redSqr();
  10527. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  10528. var t1 = jx.redMul(jyd2);
  10529. var nx = c.redSqr().redISub(t1.redAdd(t1));
  10530. var t2 = t1.redISub(nx);
  10531. var dny = c.redMul(t2);
  10532. dny = dny.redIAdd(dny).redISub(jyd4);
  10533. var nz = jyd.redMul(jz);
  10534. if (i + 1 < pow)
  10535. jz4 = jz4.redMul(jyd4);
  10536. jx = nx;
  10537. jz = nz;
  10538. jyd = dny;
  10539. }
  10540. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  10541. };
  10542. JPoint.prototype.dbl = function dbl() {
  10543. if (this.isInfinity())
  10544. return this;
  10545. if (this.curve.zeroA)
  10546. return this._zeroDbl();
  10547. else if (this.curve.threeA)
  10548. return this._threeDbl();
  10549. else
  10550. return this._dbl();
  10551. };
  10552. JPoint.prototype._zeroDbl = function _zeroDbl() {
  10553. var nx;
  10554. var ny;
  10555. var nz;
  10556. // Z = 1
  10557. if (this.zOne) {
  10558. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  10559. // #doubling-mdbl-2007-bl
  10560. // 1M + 5S + 14A
  10561. // XX = X1^2
  10562. var xx = this.x.redSqr();
  10563. // YY = Y1^2
  10564. var yy = this.y.redSqr();
  10565. // YYYY = YY^2
  10566. var yyyy = yy.redSqr();
  10567. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  10568. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10569. s = s.redIAdd(s);
  10570. // M = 3 * XX + a; a = 0
  10571. var m = xx.redAdd(xx).redIAdd(xx);
  10572. // T = M ^ 2 - 2*S
  10573. var t = m.redSqr().redISub(s).redISub(s);
  10574. // 8 * YYYY
  10575. var yyyy8 = yyyy.redIAdd(yyyy);
  10576. yyyy8 = yyyy8.redIAdd(yyyy8);
  10577. yyyy8 = yyyy8.redIAdd(yyyy8);
  10578. // X3 = T
  10579. nx = t;
  10580. // Y3 = M * (S - T) - 8 * YYYY
  10581. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  10582. // Z3 = 2*Y1
  10583. nz = this.y.redAdd(this.y);
  10584. } else {
  10585. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  10586. // #doubling-dbl-2009-l
  10587. // 2M + 5S + 13A
  10588. // A = X1^2
  10589. var a = this.x.redSqr();
  10590. // B = Y1^2
  10591. var b = this.y.redSqr();
  10592. // C = B^2
  10593. var c = b.redSqr();
  10594. // D = 2 * ((X1 + B)^2 - A - C)
  10595. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  10596. d = d.redIAdd(d);
  10597. // E = 3 * A
  10598. var e = a.redAdd(a).redIAdd(a);
  10599. // F = E^2
  10600. var f = e.redSqr();
  10601. // 8 * C
  10602. var c8 = c.redIAdd(c);
  10603. c8 = c8.redIAdd(c8);
  10604. c8 = c8.redIAdd(c8);
  10605. // X3 = F - 2 * D
  10606. nx = f.redISub(d).redISub(d);
  10607. // Y3 = E * (D - X3) - 8 * C
  10608. ny = e.redMul(d.redISub(nx)).redISub(c8);
  10609. // Z3 = 2 * Y1 * Z1
  10610. nz = this.y.redMul(this.z);
  10611. nz = nz.redIAdd(nz);
  10612. }
  10613. return this.curve.jpoint(nx, ny, nz);
  10614. };
  10615. JPoint.prototype._threeDbl = function _threeDbl() {
  10616. var nx;
  10617. var ny;
  10618. var nz;
  10619. // Z = 1
  10620. if (this.zOne) {
  10621. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  10622. // #doubling-mdbl-2007-bl
  10623. // 1M + 5S + 15A
  10624. // XX = X1^2
  10625. var xx = this.x.redSqr();
  10626. // YY = Y1^2
  10627. var yy = this.y.redSqr();
  10628. // YYYY = YY^2
  10629. var yyyy = yy.redSqr();
  10630. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  10631. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10632. s = s.redIAdd(s);
  10633. // M = 3 * XX + a
  10634. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
  10635. // T = M^2 - 2 * S
  10636. var t = m.redSqr().redISub(s).redISub(s);
  10637. // X3 = T
  10638. nx = t;
  10639. // Y3 = M * (S - T) - 8 * YYYY
  10640. var yyyy8 = yyyy.redIAdd(yyyy);
  10641. yyyy8 = yyyy8.redIAdd(yyyy8);
  10642. yyyy8 = yyyy8.redIAdd(yyyy8);
  10643. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  10644. // Z3 = 2 * Y1
  10645. nz = this.y.redAdd(this.y);
  10646. } else {
  10647. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  10648. // 3M + 5S
  10649. // delta = Z1^2
  10650. var delta = this.z.redSqr();
  10651. // gamma = Y1^2
  10652. var gamma = this.y.redSqr();
  10653. // beta = X1 * gamma
  10654. var beta = this.x.redMul(gamma);
  10655. // alpha = 3 * (X1 - delta) * (X1 + delta)
  10656. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  10657. alpha = alpha.redAdd(alpha).redIAdd(alpha);
  10658. // X3 = alpha^2 - 8 * beta
  10659. var beta4 = beta.redIAdd(beta);
  10660. beta4 = beta4.redIAdd(beta4);
  10661. var beta8 = beta4.redAdd(beta4);
  10662. nx = alpha.redSqr().redISub(beta8);
  10663. // Z3 = (Y1 + Z1)^2 - gamma - delta
  10664. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
  10665. // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  10666. var ggamma8 = gamma.redSqr();
  10667. ggamma8 = ggamma8.redIAdd(ggamma8);
  10668. ggamma8 = ggamma8.redIAdd(ggamma8);
  10669. ggamma8 = ggamma8.redIAdd(ggamma8);
  10670. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  10671. }
  10672. return this.curve.jpoint(nx, ny, nz);
  10673. };
  10674. JPoint.prototype._dbl = function _dbl() {
  10675. var a = this.curve.a;
  10676. // 4M + 6S + 10A
  10677. var jx = this.x;
  10678. var jy = this.y;
  10679. var jz = this.z;
  10680. var jz4 = jz.redSqr().redSqr();
  10681. var jx2 = jx.redSqr();
  10682. var jy2 = jy.redSqr();
  10683. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  10684. var jxd4 = jx.redAdd(jx);
  10685. jxd4 = jxd4.redIAdd(jxd4);
  10686. var t1 = jxd4.redMul(jy2);
  10687. var nx = c.redSqr().redISub(t1.redAdd(t1));
  10688. var t2 = t1.redISub(nx);
  10689. var jyd8 = jy2.redSqr();
  10690. jyd8 = jyd8.redIAdd(jyd8);
  10691. jyd8 = jyd8.redIAdd(jyd8);
  10692. jyd8 = jyd8.redIAdd(jyd8);
  10693. var ny = c.redMul(t2).redISub(jyd8);
  10694. var nz = jy.redAdd(jy).redMul(jz);
  10695. return this.curve.jpoint(nx, ny, nz);
  10696. };
  10697. JPoint.prototype.trpl = function trpl() {
  10698. if (!this.curve.zeroA)
  10699. return this.dbl().add(this);
  10700. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  10701. // 5M + 10S + ...
  10702. // XX = X1^2
  10703. var xx = this.x.redSqr();
  10704. // YY = Y1^2
  10705. var yy = this.y.redSqr();
  10706. // ZZ = Z1^2
  10707. var zz = this.z.redSqr();
  10708. // YYYY = YY^2
  10709. var yyyy = yy.redSqr();
  10710. // M = 3 * XX + a * ZZ2; a = 0
  10711. var m = xx.redAdd(xx).redIAdd(xx);
  10712. // MM = M^2
  10713. var mm = m.redSqr();
  10714. // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  10715. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10716. e = e.redIAdd(e);
  10717. e = e.redAdd(e).redIAdd(e);
  10718. e = e.redISub(mm);
  10719. // EE = E^2
  10720. var ee = e.redSqr();
  10721. // T = 16*YYYY
  10722. var t = yyyy.redIAdd(yyyy);
  10723. t = t.redIAdd(t);
  10724. t = t.redIAdd(t);
  10725. t = t.redIAdd(t);
  10726. // U = (M + E)^2 - MM - EE - T
  10727. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
  10728. // X3 = 4 * (X1 * EE - 4 * YY * U)
  10729. var yyu4 = yy.redMul(u);
  10730. yyu4 = yyu4.redIAdd(yyu4);
  10731. yyu4 = yyu4.redIAdd(yyu4);
  10732. var nx = this.x.redMul(ee).redISub(yyu4);
  10733. nx = nx.redIAdd(nx);
  10734. nx = nx.redIAdd(nx);
  10735. // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  10736. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  10737. ny = ny.redIAdd(ny);
  10738. ny = ny.redIAdd(ny);
  10739. ny = ny.redIAdd(ny);
  10740. // Z3 = (Z1 + E)^2 - ZZ - EE
  10741. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  10742. return this.curve.jpoint(nx, ny, nz);
  10743. };
  10744. JPoint.prototype.mul = function mul(k, kbase) {
  10745. k = new BN(k, kbase);
  10746. return this.curve._wnafMul(this, k);
  10747. };
  10748. JPoint.prototype.eq = function eq(p) {
  10749. if (p.type === 'affine')
  10750. return this.eq(p.toJ());
  10751. if (this === p)
  10752. return true;
  10753. // x1 * z2^2 == x2 * z1^2
  10754. var z2 = this.z.redSqr();
  10755. var pz2 = p.z.redSqr();
  10756. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
  10757. return false;
  10758. // y1 * z2^3 == y2 * z1^3
  10759. var z3 = z2.redMul(this.z);
  10760. var pz3 = pz2.redMul(p.z);
  10761. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  10762. };
  10763. JPoint.prototype.inspect = function inspect() {
  10764. if (this.isInfinity())
  10765. return '<EC JPoint Infinity>';
  10766. return '<EC JPoint x: ' + this.x.toString(16, 2) +
  10767. ' y: ' + this.y.toString(16, 2) +
  10768. ' z: ' + this.z.toString(16, 2) + '>';
  10769. };
  10770. JPoint.prototype.isInfinity = function isInfinity() {
  10771. // XXX This code assumes that zero is always zero in red
  10772. return this.z.cmpn(0) === 0;
  10773. };
  10774. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],71:[function(require,module,exports){
  10775. 'use strict';
  10776. var curves = exports;
  10777. var hash = require('hash.js');
  10778. var elliptic = require('../elliptic');
  10779. var assert = elliptic.utils.assert;
  10780. function PresetCurve(options) {
  10781. if (options.type === 'short')
  10782. this.curve = new elliptic.curve.short(options);
  10783. else if (options.type === 'edwards')
  10784. this.curve = new elliptic.curve.edwards(options);
  10785. else
  10786. this.curve = new elliptic.curve.mont(options);
  10787. this.g = this.curve.g;
  10788. this.n = this.curve.n;
  10789. this.hash = options.hash;
  10790. assert(this.g.validate(), 'Invalid curve');
  10791. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  10792. }
  10793. curves.PresetCurve = PresetCurve;
  10794. function defineCurve(name, options) {
  10795. Object.defineProperty(curves, name, {
  10796. configurable: true,
  10797. enumerable: true,
  10798. get: function() {
  10799. var curve = new PresetCurve(options);
  10800. Object.defineProperty(curves, name, {
  10801. configurable: true,
  10802. enumerable: true,
  10803. value: curve
  10804. });
  10805. return curve;
  10806. }
  10807. });
  10808. }
  10809. defineCurve('p192', {
  10810. type: 'short',
  10811. prime: 'p192',
  10812. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  10813. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  10814. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  10815. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  10816. hash: hash.sha256,
  10817. gRed: false,
  10818. g: [
  10819. '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
  10820. '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
  10821. ]
  10822. });
  10823. defineCurve('p224', {
  10824. type: 'short',
  10825. prime: 'p224',
  10826. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  10827. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  10828. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  10829. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  10830. hash: hash.sha256,
  10831. gRed: false,
  10832. g: [
  10833. 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
  10834. 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
  10835. ]
  10836. });
  10837. defineCurve('p256', {
  10838. type: 'short',
  10839. prime: null,
  10840. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  10841. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  10842. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  10843. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  10844. hash: hash.sha256,
  10845. gRed: false,
  10846. g: [
  10847. '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
  10848. '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
  10849. ]
  10850. });
  10851. defineCurve('p384', {
  10852. type: 'short',
  10853. prime: null,
  10854. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10855. 'fffffffe ffffffff 00000000 00000000 ffffffff',
  10856. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10857. 'fffffffe ffffffff 00000000 00000000 fffffffc',
  10858. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
  10859. '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  10860. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
  10861. 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  10862. hash: hash.sha384,
  10863. gRed: false,
  10864. g: [
  10865. 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
  10866. '5502f25d bf55296c 3a545e38 72760ab7',
  10867. '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
  10868. '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
  10869. ]
  10870. });
  10871. defineCurve('p521', {
  10872. type: 'short',
  10873. prime: null,
  10874. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10875. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10876. 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  10877. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10878. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10879. 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  10880. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
  10881. '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
  10882. '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  10883. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10884. 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
  10885. 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  10886. hash: hash.sha512,
  10887. gRed: false,
  10888. g: [
  10889. '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
  10890. '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
  10891. 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
  10892. '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
  10893. '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
  10894. '3fad0761 353c7086 a272c240 88be9476 9fd16650'
  10895. ]
  10896. });
  10897. defineCurve('curve25519', {
  10898. type: 'mont',
  10899. prime: 'p25519',
  10900. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  10901. a: '76d06',
  10902. b: '0',
  10903. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  10904. hash: hash.sha256,
  10905. gRed: false,
  10906. g: [
  10907. '9'
  10908. ]
  10909. });
  10910. defineCurve('ed25519', {
  10911. type: 'edwards',
  10912. prime: 'p25519',
  10913. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  10914. a: '-1',
  10915. c: '1',
  10916. // -121665 * (121666^(-1)) (mod P)
  10917. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  10918. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  10919. hash: hash.sha256,
  10920. gRed: false,
  10921. g: [
  10922. '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
  10923. // 4/5
  10924. '6666666666666666666666666666666666666666666666666666666666666658'
  10925. ]
  10926. });
  10927. var pre;
  10928. try {
  10929. pre = require('./precomputed/secp256k1');
  10930. } catch (e) {
  10931. pre = undefined;
  10932. }
  10933. defineCurve('secp256k1', {
  10934. type: 'short',
  10935. prime: 'k256',
  10936. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  10937. a: '0',
  10938. b: '7',
  10939. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  10940. h: '1',
  10941. hash: hash.sha256,
  10942. // Precomputed endomorphism
  10943. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  10944. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  10945. basis: [
  10946. {
  10947. a: '3086d221a7d46bcde86c90e49284eb15',
  10948. b: '-e4437ed6010e88286f547fa90abfe4c3'
  10949. },
  10950. {
  10951. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  10952. b: '3086d221a7d46bcde86c90e49284eb15'
  10953. }
  10954. ],
  10955. gRed: false,
  10956. g: [
  10957. '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
  10958. '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
  10959. pre
  10960. ]
  10961. });
  10962. },{"../elliptic":65,"./precomputed/secp256k1":79,"hash.js":84}],72:[function(require,module,exports){
  10963. 'use strict';
  10964. var BN = require('bn.js');
  10965. var elliptic = require('../../elliptic');
  10966. var utils = elliptic.utils;
  10967. var assert = utils.assert;
  10968. var KeyPair = require('./key');
  10969. var Signature = require('./signature');
  10970. function EC(options) {
  10971. if (!(this instanceof EC))
  10972. return new EC(options);
  10973. // Shortcut `elliptic.ec(curve-name)`
  10974. if (typeof options === 'string') {
  10975. assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options);
  10976. options = elliptic.curves[options];
  10977. }
  10978. // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  10979. if (options instanceof elliptic.curves.PresetCurve)
  10980. options = { curve: options };
  10981. this.curve = options.curve.curve;
  10982. this.n = this.curve.n;
  10983. this.nh = this.n.ushrn(1);
  10984. this.g = this.curve.g;
  10985. // Point on curve
  10986. this.g = options.curve.g;
  10987. this.g.precompute(options.curve.n.bitLength() + 1);
  10988. // Hash for function for DRBG
  10989. this.hash = options.hash || options.curve.hash;
  10990. }
  10991. module.exports = EC;
  10992. EC.prototype.keyPair = function keyPair(options) {
  10993. return new KeyPair(this, options);
  10994. };
  10995. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  10996. return KeyPair.fromPrivate(this, priv, enc);
  10997. };
  10998. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  10999. return KeyPair.fromPublic(this, pub, enc);
  11000. };
  11001. EC.prototype.genKeyPair = function genKeyPair(options) {
  11002. if (!options)
  11003. options = {};
  11004. // Instantiate Hmac_DRBG
  11005. var drbg = new elliptic.hmacDRBG({
  11006. hash: this.hash,
  11007. pers: options.pers,
  11008. entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
  11009. nonce: this.n.toArray()
  11010. });
  11011. var bytes = this.n.byteLength();
  11012. var ns2 = this.n.sub(new BN(2));
  11013. do {
  11014. var priv = new BN(drbg.generate(bytes));
  11015. if (priv.cmp(ns2) > 0)
  11016. continue;
  11017. priv.iaddn(1);
  11018. return this.keyFromPrivate(priv);
  11019. } while (true);
  11020. };
  11021. EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
  11022. var delta = msg.byteLength() * 8 - this.n.bitLength();
  11023. if (delta > 0)
  11024. msg = msg.ushrn(delta);
  11025. if (!truncOnly && msg.cmp(this.n) >= 0)
  11026. return msg.sub(this.n);
  11027. else
  11028. return msg;
  11029. };
  11030. EC.prototype.sign = function sign(msg, key, enc, options) {
  11031. if (typeof enc === 'object') {
  11032. options = enc;
  11033. enc = null;
  11034. }
  11035. if (!options)
  11036. options = {};
  11037. key = this.keyFromPrivate(key, enc);
  11038. msg = this._truncateToN(new BN(msg, 16));
  11039. // Zero-extend key to provide enough entropy
  11040. var bytes = this.n.byteLength();
  11041. var bkey = key.getPrivate().toArray('be', bytes);
  11042. // Zero-extend nonce to have the same byte size as N
  11043. var nonce = msg.toArray('be', bytes);
  11044. // Instantiate Hmac_DRBG
  11045. var drbg = new elliptic.hmacDRBG({
  11046. hash: this.hash,
  11047. entropy: bkey,
  11048. nonce: nonce,
  11049. pers: options.pers,
  11050. persEnc: options.persEnc
  11051. });
  11052. // Number of bytes to generate
  11053. var ns1 = this.n.sub(new BN(1));
  11054. for (var iter = 0; true; iter++) {
  11055. var k = options.k ?
  11056. options.k(iter) :
  11057. new BN(drbg.generate(this.n.byteLength()));
  11058. k = this._truncateToN(k, true);
  11059. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
  11060. continue;
  11061. var kp = this.g.mul(k);
  11062. if (kp.isInfinity())
  11063. continue;
  11064. var kpX = kp.getX();
  11065. var r = kpX.umod(this.n);
  11066. if (r.cmpn(0) === 0)
  11067. continue;
  11068. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  11069. s = s.umod(this.n);
  11070. if (s.cmpn(0) === 0)
  11071. continue;
  11072. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
  11073. (kpX.cmp(r) !== 0 ? 2 : 0);
  11074. // Use complement of `s`, if it is > `n / 2`
  11075. if (options.canonical && s.cmp(this.nh) > 0) {
  11076. s = this.n.sub(s);
  11077. recoveryParam ^= 1;
  11078. }
  11079. return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
  11080. }
  11081. };
  11082. EC.prototype.verify = function verify(msg, signature, key, enc) {
  11083. msg = this._truncateToN(new BN(msg, 16));
  11084. key = this.keyFromPublic(key, enc);
  11085. signature = new Signature(signature, 'hex');
  11086. // Perform primitive values validation
  11087. var r = signature.r;
  11088. var s = signature.s;
  11089. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
  11090. return false;
  11091. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
  11092. return false;
  11093. // Validate signature
  11094. var sinv = s.invm(this.n);
  11095. var u1 = sinv.mul(msg).umod(this.n);
  11096. var u2 = sinv.mul(r).umod(this.n);
  11097. var p = this.g.mulAdd(u1, key.getPublic(), u2);
  11098. if (p.isInfinity())
  11099. return false;
  11100. return p.getX().umod(this.n).cmp(r) === 0;
  11101. };
  11102. EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
  11103. assert((3 & j) === j, 'The recovery param is more than two bits');
  11104. signature = new Signature(signature, enc);
  11105. var n = this.n;
  11106. var e = new BN(msg);
  11107. var r = signature.r;
  11108. var s = signature.s;
  11109. // A set LSB signifies that the y-coordinate is odd
  11110. var isYOdd = j & 1;
  11111. var isSecondKey = j >> 1;
  11112. if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
  11113. throw new Error('Unable to find sencond key candinate');
  11114. // 1.1. Let x = r + jn.
  11115. if (isSecondKey)
  11116. r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
  11117. else
  11118. r = this.curve.pointFromX(r, isYOdd);
  11119. var eNeg = n.sub(e);
  11120. // 1.6.1 Compute Q = r^-1 (sR - eG)
  11121. // Q = r^-1 (sR + -eG)
  11122. var rInv = signature.r.invm(n);
  11123. return this.g.mulAdd(eNeg, r, s).mul(rInv);
  11124. };
  11125. EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
  11126. signature = new Signature(signature, enc);
  11127. if (signature.recoveryParam !== null)
  11128. return signature.recoveryParam;
  11129. for (var i = 0; i < 4; i++) {
  11130. var Qprime;
  11131. try {
  11132. Qprime = this.recoverPubKey(e, signature, i);
  11133. } catch (e) {
  11134. continue;
  11135. }
  11136. if (Qprime.eq(Q))
  11137. return i;
  11138. }
  11139. throw new Error('Unable to find valid recovery factor');
  11140. };
  11141. },{"../../elliptic":65,"./key":73,"./signature":74,"bn.js":18}],73:[function(require,module,exports){
  11142. 'use strict';
  11143. var BN = require('bn.js');
  11144. function KeyPair(ec, options) {
  11145. this.ec = ec;
  11146. this.priv = null;
  11147. this.pub = null;
  11148. // KeyPair(ec, { priv: ..., pub: ... })
  11149. if (options.priv)
  11150. this._importPrivate(options.priv, options.privEnc);
  11151. if (options.pub)
  11152. this._importPublic(options.pub, options.pubEnc);
  11153. }
  11154. module.exports = KeyPair;
  11155. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  11156. if (pub instanceof KeyPair)
  11157. return pub;
  11158. return new KeyPair(ec, {
  11159. pub: pub,
  11160. pubEnc: enc
  11161. });
  11162. };
  11163. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  11164. if (priv instanceof KeyPair)
  11165. return priv;
  11166. return new KeyPair(ec, {
  11167. priv: priv,
  11168. privEnc: enc
  11169. });
  11170. };
  11171. KeyPair.prototype.validate = function validate() {
  11172. var pub = this.getPublic();
  11173. if (pub.isInfinity())
  11174. return { result: false, reason: 'Invalid public key' };
  11175. if (!pub.validate())
  11176. return { result: false, reason: 'Public key is not a point' };
  11177. if (!pub.mul(this.ec.curve.n).isInfinity())
  11178. return { result: false, reason: 'Public key * N != O' };
  11179. return { result: true, reason: null };
  11180. };
  11181. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  11182. // compact is optional argument
  11183. if (typeof compact === 'string') {
  11184. enc = compact;
  11185. compact = null;
  11186. }
  11187. if (!this.pub)
  11188. this.pub = this.ec.g.mul(this.priv);
  11189. if (!enc)
  11190. return this.pub;
  11191. return this.pub.encode(enc, compact);
  11192. };
  11193. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  11194. if (enc === 'hex')
  11195. return this.priv.toString(16, 2);
  11196. else
  11197. return this.priv;
  11198. };
  11199. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  11200. this.priv = new BN(key, enc || 16);
  11201. // Ensure that the priv won't be bigger than n, otherwise we may fail
  11202. // in fixed multiplication method
  11203. this.priv = this.priv.umod(this.ec.curve.n);
  11204. };
  11205. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  11206. if (key.x || key.y) {
  11207. this.pub = this.ec.curve.point(key.x, key.y);
  11208. return;
  11209. }
  11210. this.pub = this.ec.curve.decodePoint(key, enc);
  11211. };
  11212. // ECDH
  11213. KeyPair.prototype.derive = function derive(pub) {
  11214. return pub.mul(this.priv).getX();
  11215. };
  11216. // ECDSA
  11217. KeyPair.prototype.sign = function sign(msg, enc, options) {
  11218. return this.ec.sign(msg, this, enc, options);
  11219. };
  11220. KeyPair.prototype.verify = function verify(msg, signature) {
  11221. return this.ec.verify(msg, signature, this);
  11222. };
  11223. KeyPair.prototype.inspect = function inspect() {
  11224. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
  11225. ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  11226. };
  11227. },{"bn.js":18}],74:[function(require,module,exports){
  11228. 'use strict';
  11229. var BN = require('bn.js');
  11230. var elliptic = require('../../elliptic');
  11231. var utils = elliptic.utils;
  11232. var assert = utils.assert;
  11233. function Signature(options, enc) {
  11234. if (options instanceof Signature)
  11235. return options;
  11236. if (this._importDER(options, enc))
  11237. return;
  11238. assert(options.r && options.s, 'Signature without r or s');
  11239. this.r = new BN(options.r, 16);
  11240. this.s = new BN(options.s, 16);
  11241. if (options.recoveryParam === undefined)
  11242. this.recoveryParam = null;
  11243. else
  11244. this.recoveryParam = options.recoveryParam;
  11245. }
  11246. module.exports = Signature;
  11247. function Position() {
  11248. this.place = 0;
  11249. }
  11250. function getLength(buf, p) {
  11251. var initial = buf[p.place++];
  11252. if (!(initial & 0x80)) {
  11253. return initial;
  11254. }
  11255. var octetLen = initial & 0xf;
  11256. var val = 0;
  11257. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  11258. val <<= 8;
  11259. val |= buf[off];
  11260. }
  11261. p.place = off;
  11262. return val;
  11263. }
  11264. function rmPadding(buf) {
  11265. var i = 0;
  11266. var len = buf.length - 1;
  11267. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  11268. i++;
  11269. }
  11270. if (i === 0) {
  11271. return buf;
  11272. }
  11273. return buf.slice(i);
  11274. }
  11275. Signature.prototype._importDER = function _importDER(data, enc) {
  11276. data = utils.toArray(data, enc);
  11277. var p = new Position();
  11278. if (data[p.place++] !== 0x30) {
  11279. return false;
  11280. }
  11281. var len = getLength(data, p);
  11282. if ((len + p.place) !== data.length) {
  11283. return false;
  11284. }
  11285. if (data[p.place++] !== 0x02) {
  11286. return false;
  11287. }
  11288. var rlen = getLength(data, p);
  11289. var r = data.slice(p.place, rlen + p.place);
  11290. p.place += rlen;
  11291. if (data[p.place++] !== 0x02) {
  11292. return false;
  11293. }
  11294. var slen = getLength(data, p);
  11295. if (data.length !== slen + p.place) {
  11296. return false;
  11297. }
  11298. var s = data.slice(p.place, slen + p.place);
  11299. if (r[0] === 0 && (r[1] & 0x80)) {
  11300. r = r.slice(1);
  11301. }
  11302. if (s[0] === 0 && (s[1] & 0x80)) {
  11303. s = s.slice(1);
  11304. }
  11305. this.r = new BN(r);
  11306. this.s = new BN(s);
  11307. this.recoveryParam = null;
  11308. return true;
  11309. };
  11310. function constructLength(arr, len) {
  11311. if (len < 0x80) {
  11312. arr.push(len);
  11313. return;
  11314. }
  11315. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  11316. arr.push(octets | 0x80);
  11317. while (--octets) {
  11318. arr.push((len >>> (octets << 3)) & 0xff);
  11319. }
  11320. arr.push(len);
  11321. }
  11322. Signature.prototype.toDER = function toDER(enc) {
  11323. var r = this.r.toArray();
  11324. var s = this.s.toArray();
  11325. // Pad values
  11326. if (r[0] & 0x80)
  11327. r = [ 0 ].concat(r);
  11328. // Pad values
  11329. if (s[0] & 0x80)
  11330. s = [ 0 ].concat(s);
  11331. r = rmPadding(r);
  11332. s = rmPadding(s);
  11333. while (!s[0] && !(s[1] & 0x80)) {
  11334. s = s.slice(1);
  11335. }
  11336. var arr = [ 0x02 ];
  11337. constructLength(arr, r.length);
  11338. arr = arr.concat(r);
  11339. arr.push(0x02);
  11340. constructLength(arr, s.length);
  11341. var backHalf = arr.concat(s);
  11342. var res = [ 0x30 ];
  11343. constructLength(res, backHalf.length);
  11344. res = res.concat(backHalf);
  11345. return utils.encode(res, enc);
  11346. };
  11347. },{"../../elliptic":65,"bn.js":18}],75:[function(require,module,exports){
  11348. 'use strict';
  11349. var hash = require('hash.js');
  11350. var elliptic = require('../../elliptic');
  11351. var utils = elliptic.utils;
  11352. var assert = utils.assert;
  11353. var parseBytes = utils.parseBytes;
  11354. var KeyPair = require('./key');
  11355. var Signature = require('./signature');
  11356. function EDDSA(curve) {
  11357. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  11358. if (!(this instanceof EDDSA))
  11359. return new EDDSA(curve);
  11360. var curve = elliptic.curves[curve].curve;
  11361. this.curve = curve;
  11362. this.g = curve.g;
  11363. this.g.precompute(curve.n.bitLength() + 1);
  11364. this.pointClass = curve.point().constructor;
  11365. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  11366. this.hash = hash.sha512;
  11367. }
  11368. module.exports = EDDSA;
  11369. /**
  11370. * @param {Array|String} message - message bytes
  11371. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  11372. * @returns {Signature} - signature
  11373. */
  11374. EDDSA.prototype.sign = function sign(message, secret) {
  11375. message = parseBytes(message);
  11376. var key = this.keyFromSecret(secret);
  11377. var r = this.hashInt(key.messagePrefix(), message);
  11378. var R = this.g.mul(r);
  11379. var Rencoded = this.encodePoint(R);
  11380. var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
  11381. .mul(key.priv());
  11382. var S = r.add(s_).umod(this.curve.n);
  11383. return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
  11384. };
  11385. /**
  11386. * @param {Array} message - message bytes
  11387. * @param {Array|String|Signature} sig - sig bytes
  11388. * @param {Array|String|Point|KeyPair} pub - public key
  11389. * @returns {Boolean} - true if public key matches sig of message
  11390. */
  11391. EDDSA.prototype.verify = function verify(message, sig, pub) {
  11392. message = parseBytes(message);
  11393. sig = this.makeSignature(sig);
  11394. var key = this.keyFromPublic(pub);
  11395. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  11396. var SG = this.g.mul(sig.S());
  11397. var RplusAh = sig.R().add(key.pub().mul(h));
  11398. return RplusAh.eq(SG);
  11399. };
  11400. EDDSA.prototype.hashInt = function hashInt() {
  11401. var hash = this.hash();
  11402. for (var i = 0; i < arguments.length; i++)
  11403. hash.update(arguments[i]);
  11404. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  11405. };
  11406. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  11407. return KeyPair.fromPublic(this, pub);
  11408. };
  11409. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  11410. return KeyPair.fromSecret(this, secret);
  11411. };
  11412. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  11413. if (sig instanceof Signature)
  11414. return sig;
  11415. return new Signature(this, sig);
  11416. };
  11417. /**
  11418. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  11419. *
  11420. * EDDSA defines methods for encoding and decoding points and integers. These are
  11421. * helper convenience methods, that pass along to utility functions implied
  11422. * parameters.
  11423. *
  11424. */
  11425. EDDSA.prototype.encodePoint = function encodePoint(point) {
  11426. var enc = point.getY().toArray('le', this.encodingLength);
  11427. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  11428. return enc;
  11429. };
  11430. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  11431. bytes = utils.parseBytes(bytes);
  11432. var lastIx = bytes.length - 1;
  11433. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  11434. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  11435. var y = utils.intFromLE(normed);
  11436. return this.curve.pointFromY(y, xIsOdd);
  11437. };
  11438. EDDSA.prototype.encodeInt = function encodeInt(num) {
  11439. return num.toArray('le', this.encodingLength);
  11440. };
  11441. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  11442. return utils.intFromLE(bytes);
  11443. };
  11444. EDDSA.prototype.isPoint = function isPoint(val) {
  11445. return val instanceof this.pointClass;
  11446. };
  11447. },{"../../elliptic":65,"./key":76,"./signature":77,"hash.js":84}],76:[function(require,module,exports){
  11448. 'use strict';
  11449. var elliptic = require('../../elliptic');
  11450. var utils = elliptic.utils;
  11451. var assert = utils.assert;
  11452. var parseBytes = utils.parseBytes;
  11453. var cachedProperty = utils.cachedProperty;
  11454. /**
  11455. * @param {EDDSA} eddsa - instance
  11456. * @param {Object} params - public/private key parameters
  11457. *
  11458. * @param {Array<Byte>} [params.secret] - secret seed bytes
  11459. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  11460. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  11461. *
  11462. */
  11463. function KeyPair(eddsa, params) {
  11464. this.eddsa = eddsa;
  11465. this._secret = parseBytes(params.secret);
  11466. if (eddsa.isPoint(params.pub))
  11467. this._pub = params.pub;
  11468. else
  11469. this._pubBytes = parseBytes(params.pub);
  11470. }
  11471. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  11472. if (pub instanceof KeyPair)
  11473. return pub;
  11474. return new KeyPair(eddsa, { pub: pub });
  11475. };
  11476. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  11477. if (secret instanceof KeyPair)
  11478. return secret;
  11479. return new KeyPair(eddsa, { secret: secret });
  11480. };
  11481. KeyPair.prototype.secret = function secret() {
  11482. return this._secret;
  11483. };
  11484. cachedProperty(KeyPair, function pubBytes() {
  11485. return this.eddsa.encodePoint(this.pub());
  11486. });
  11487. cachedProperty(KeyPair, function pub() {
  11488. if (this._pubBytes)
  11489. return this.eddsa.decodePoint(this._pubBytes);
  11490. return this.eddsa.g.mul(this.priv());
  11491. });
  11492. cachedProperty(KeyPair, function privBytes() {
  11493. var eddsa = this.eddsa;
  11494. var hash = this.hash();
  11495. var lastIx = eddsa.encodingLength - 1;
  11496. var a = hash.slice(0, eddsa.encodingLength);
  11497. a[0] &= 248;
  11498. a[lastIx] &= 127;
  11499. a[lastIx] |= 64;
  11500. return a;
  11501. });
  11502. cachedProperty(KeyPair, function priv() {
  11503. return this.eddsa.decodeInt(this.privBytes());
  11504. });
  11505. cachedProperty(KeyPair, function hash() {
  11506. return this.eddsa.hash().update(this.secret()).digest();
  11507. });
  11508. cachedProperty(KeyPair, function messagePrefix() {
  11509. return this.hash().slice(this.eddsa.encodingLength);
  11510. });
  11511. KeyPair.prototype.sign = function sign(message) {
  11512. assert(this._secret, 'KeyPair can only verify');
  11513. return this.eddsa.sign(message, this);
  11514. };
  11515. KeyPair.prototype.verify = function verify(message, sig) {
  11516. return this.eddsa.verify(message, sig, this);
  11517. };
  11518. KeyPair.prototype.getSecret = function getSecret(enc) {
  11519. assert(this._secret, 'KeyPair is public only');
  11520. return utils.encode(this.secret(), enc);
  11521. };
  11522. KeyPair.prototype.getPublic = function getPublic(enc) {
  11523. return utils.encode(this.pubBytes(), enc);
  11524. };
  11525. module.exports = KeyPair;
  11526. },{"../../elliptic":65}],77:[function(require,module,exports){
  11527. 'use strict';
  11528. var BN = require('bn.js');
  11529. var elliptic = require('../../elliptic');
  11530. var utils = elliptic.utils;
  11531. var assert = utils.assert;
  11532. var cachedProperty = utils.cachedProperty;
  11533. var parseBytes = utils.parseBytes;
  11534. /**
  11535. * @param {EDDSA} eddsa - eddsa instance
  11536. * @param {Array<Bytes>|Object} sig -
  11537. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  11538. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  11539. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  11540. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  11541. */
  11542. function Signature(eddsa, sig) {
  11543. this.eddsa = eddsa;
  11544. if (typeof sig !== 'object')
  11545. sig = parseBytes(sig);
  11546. if (Array.isArray(sig)) {
  11547. sig = {
  11548. R: sig.slice(0, eddsa.encodingLength),
  11549. S: sig.slice(eddsa.encodingLength)
  11550. };
  11551. }
  11552. assert(sig.R && sig.S, 'Signature without R or S');
  11553. if (eddsa.isPoint(sig.R))
  11554. this._R = sig.R;
  11555. if (sig.S instanceof BN)
  11556. this._S = sig.S;
  11557. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  11558. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  11559. }
  11560. cachedProperty(Signature, function S() {
  11561. return this.eddsa.decodeInt(this.Sencoded());
  11562. });
  11563. cachedProperty(Signature, function R() {
  11564. return this.eddsa.decodePoint(this.Rencoded());
  11565. });
  11566. cachedProperty(Signature, function Rencoded() {
  11567. return this.eddsa.encodePoint(this.R());
  11568. });
  11569. cachedProperty(Signature, function Sencoded() {
  11570. return this.eddsa.encodeInt(this.S());
  11571. });
  11572. Signature.prototype.toBytes = function toBytes() {
  11573. return this.Rencoded().concat(this.Sencoded());
  11574. };
  11575. Signature.prototype.toHex = function toHex() {
  11576. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  11577. };
  11578. module.exports = Signature;
  11579. },{"../../elliptic":65,"bn.js":18}],78:[function(require,module,exports){
  11580. 'use strict';
  11581. var hash = require('hash.js');
  11582. var elliptic = require('../elliptic');
  11583. var utils = elliptic.utils;
  11584. var assert = utils.assert;
  11585. function HmacDRBG(options) {
  11586. if (!(this instanceof HmacDRBG))
  11587. return new HmacDRBG(options);
  11588. this.hash = options.hash;
  11589. this.predResist = !!options.predResist;
  11590. this.outLen = this.hash.outSize;
  11591. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  11592. this.reseed = null;
  11593. this.reseedInterval = null;
  11594. this.K = null;
  11595. this.V = null;
  11596. var entropy = utils.toArray(options.entropy, options.entropyEnc);
  11597. var nonce = utils.toArray(options.nonce, options.nonceEnc);
  11598. var pers = utils.toArray(options.pers, options.persEnc);
  11599. assert(entropy.length >= (this.minEntropy / 8),
  11600. 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  11601. this._init(entropy, nonce, pers);
  11602. }
  11603. module.exports = HmacDRBG;
  11604. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  11605. var seed = entropy.concat(nonce).concat(pers);
  11606. this.K = new Array(this.outLen / 8);
  11607. this.V = new Array(this.outLen / 8);
  11608. for (var i = 0; i < this.V.length; i++) {
  11609. this.K[i] = 0x00;
  11610. this.V[i] = 0x01;
  11611. }
  11612. this._update(seed);
  11613. this.reseed = 1;
  11614. this.reseedInterval = 0x1000000000000; // 2^48
  11615. };
  11616. HmacDRBG.prototype._hmac = function hmac() {
  11617. return new hash.hmac(this.hash, this.K);
  11618. };
  11619. HmacDRBG.prototype._update = function update(seed) {
  11620. var kmac = this._hmac()
  11621. .update(this.V)
  11622. .update([ 0x00 ]);
  11623. if (seed)
  11624. kmac = kmac.update(seed);
  11625. this.K = kmac.digest();
  11626. this.V = this._hmac().update(this.V).digest();
  11627. if (!seed)
  11628. return;
  11629. this.K = this._hmac()
  11630. .update(this.V)
  11631. .update([ 0x01 ])
  11632. .update(seed)
  11633. .digest();
  11634. this.V = this._hmac().update(this.V).digest();
  11635. };
  11636. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  11637. // Optional entropy enc
  11638. if (typeof entropyEnc !== 'string') {
  11639. addEnc = add;
  11640. add = entropyEnc;
  11641. entropyEnc = null;
  11642. }
  11643. entropy = utils.toBuffer(entropy, entropyEnc);
  11644. add = utils.toBuffer(add, addEnc);
  11645. assert(entropy.length >= (this.minEntropy / 8),
  11646. 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  11647. this._update(entropy.concat(add || []));
  11648. this.reseed = 1;
  11649. };
  11650. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  11651. if (this.reseed > this.reseedInterval)
  11652. throw new Error('Reseed is required');
  11653. // Optional encoding
  11654. if (typeof enc !== 'string') {
  11655. addEnc = add;
  11656. add = enc;
  11657. enc = null;
  11658. }
  11659. // Optional additional data
  11660. if (add) {
  11661. add = utils.toArray(add, addEnc);
  11662. this._update(add);
  11663. }
  11664. var temp = [];
  11665. while (temp.length < len) {
  11666. this.V = this._hmac().update(this.V).digest();
  11667. temp = temp.concat(this.V);
  11668. }
  11669. var res = temp.slice(0, len);
  11670. this._update(add);
  11671. this.reseed++;
  11672. return utils.encode(res, enc);
  11673. };
  11674. },{"../elliptic":65,"hash.js":84}],79:[function(require,module,exports){
  11675. module.exports = {
  11676. doubles: {
  11677. step: 4,
  11678. points: [
  11679. [
  11680. 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
  11681. 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
  11682. ],
  11683. [
  11684. '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
  11685. '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
  11686. ],
  11687. [
  11688. '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
  11689. 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
  11690. ],
  11691. [
  11692. '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
  11693. '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
  11694. ],
  11695. [
  11696. '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
  11697. '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
  11698. ],
  11699. [
  11700. '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
  11701. '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
  11702. ],
  11703. [
  11704. 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
  11705. '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
  11706. ],
  11707. [
  11708. '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
  11709. 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
  11710. ],
  11711. [
  11712. 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
  11713. '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
  11714. ],
  11715. [
  11716. 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
  11717. 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
  11718. ],
  11719. [
  11720. 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
  11721. '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
  11722. ],
  11723. [
  11724. '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
  11725. '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
  11726. ],
  11727. [
  11728. '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
  11729. '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
  11730. ],
  11731. [
  11732. '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
  11733. '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
  11734. ],
  11735. [
  11736. '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
  11737. '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
  11738. ],
  11739. [
  11740. '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
  11741. '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
  11742. ],
  11743. [
  11744. '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
  11745. '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
  11746. ],
  11747. [
  11748. '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
  11749. '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
  11750. ],
  11751. [
  11752. '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
  11753. 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
  11754. ],
  11755. [
  11756. 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
  11757. '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
  11758. ],
  11759. [
  11760. 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
  11761. '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
  11762. ],
  11763. [
  11764. '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
  11765. '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
  11766. ],
  11767. [
  11768. '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
  11769. '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
  11770. ],
  11771. [
  11772. 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
  11773. '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
  11774. ],
  11775. [
  11776. '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
  11777. 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
  11778. ],
  11779. [
  11780. 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
  11781. '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
  11782. ],
  11783. [
  11784. 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
  11785. 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
  11786. ],
  11787. [
  11788. 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
  11789. '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
  11790. ],
  11791. [
  11792. 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
  11793. 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
  11794. ],
  11795. [
  11796. 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
  11797. '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
  11798. ],
  11799. [
  11800. '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
  11801. 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
  11802. ],
  11803. [
  11804. '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
  11805. '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
  11806. ],
  11807. [
  11808. 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
  11809. '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
  11810. ],
  11811. [
  11812. '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
  11813. 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
  11814. ],
  11815. [
  11816. 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
  11817. '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
  11818. ],
  11819. [
  11820. 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
  11821. '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
  11822. ],
  11823. [
  11824. 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
  11825. 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
  11826. ],
  11827. [
  11828. '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
  11829. '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
  11830. ],
  11831. [
  11832. '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
  11833. '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
  11834. ],
  11835. [
  11836. '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
  11837. 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
  11838. ],
  11839. [
  11840. '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
  11841. '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
  11842. ],
  11843. [
  11844. 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
  11845. '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
  11846. ],
  11847. [
  11848. '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
  11849. '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
  11850. ],
  11851. [
  11852. '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
  11853. 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
  11854. ],
  11855. [
  11856. '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
  11857. '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
  11858. ],
  11859. [
  11860. 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
  11861. '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
  11862. ],
  11863. [
  11864. '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
  11865. 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
  11866. ],
  11867. [
  11868. 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
  11869. 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
  11870. ],
  11871. [
  11872. 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
  11873. '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
  11874. ],
  11875. [
  11876. '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
  11877. 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
  11878. ],
  11879. [
  11880. '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
  11881. 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
  11882. ],
  11883. [
  11884. 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
  11885. '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
  11886. ],
  11887. [
  11888. 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
  11889. '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
  11890. ],
  11891. [
  11892. 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
  11893. '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
  11894. ],
  11895. [
  11896. '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
  11897. 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
  11898. ],
  11899. [
  11900. '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
  11901. '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
  11902. ],
  11903. [
  11904. 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
  11905. 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
  11906. ],
  11907. [
  11908. '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
  11909. 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
  11910. ],
  11911. [
  11912. '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
  11913. '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
  11914. ],
  11915. [
  11916. '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
  11917. '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
  11918. ],
  11919. [
  11920. 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
  11921. 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
  11922. ],
  11923. [
  11924. '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
  11925. '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
  11926. ],
  11927. [
  11928. '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
  11929. '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
  11930. ],
  11931. [
  11932. 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
  11933. '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
  11934. ],
  11935. [
  11936. 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
  11937. 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
  11938. ]
  11939. ]
  11940. },
  11941. naf: {
  11942. wnd: 7,
  11943. points: [
  11944. [
  11945. 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
  11946. '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
  11947. ],
  11948. [
  11949. '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
  11950. 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
  11951. ],
  11952. [
  11953. '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
  11954. '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
  11955. ],
  11956. [
  11957. 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
  11958. 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
  11959. ],
  11960. [
  11961. '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
  11962. 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
  11963. ],
  11964. [
  11965. 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
  11966. 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
  11967. ],
  11968. [
  11969. 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
  11970. '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
  11971. ],
  11972. [
  11973. 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
  11974. '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
  11975. ],
  11976. [
  11977. '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
  11978. '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
  11979. ],
  11980. [
  11981. '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
  11982. '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
  11983. ],
  11984. [
  11985. '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
  11986. '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
  11987. ],
  11988. [
  11989. '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
  11990. '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
  11991. ],
  11992. [
  11993. 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
  11994. 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
  11995. ],
  11996. [
  11997. 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
  11998. '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
  11999. ],
  12000. [
  12001. '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
  12002. 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
  12003. ],
  12004. [
  12005. '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
  12006. 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
  12007. ],
  12008. [
  12009. '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
  12010. '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
  12011. ],
  12012. [
  12013. '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
  12014. '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
  12015. ],
  12016. [
  12017. '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
  12018. '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
  12019. ],
  12020. [
  12021. '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
  12022. 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
  12023. ],
  12024. [
  12025. 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
  12026. 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
  12027. ],
  12028. [
  12029. '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
  12030. '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
  12031. ],
  12032. [
  12033. '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
  12034. '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
  12035. ],
  12036. [
  12037. 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
  12038. 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
  12039. ],
  12040. [
  12041. '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
  12042. '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
  12043. ],
  12044. [
  12045. 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
  12046. 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
  12047. ],
  12048. [
  12049. 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
  12050. 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
  12051. ],
  12052. [
  12053. '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
  12054. '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
  12055. ],
  12056. [
  12057. '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
  12058. '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
  12059. ],
  12060. [
  12061. '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
  12062. '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
  12063. ],
  12064. [
  12065. 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
  12066. '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
  12067. ],
  12068. [
  12069. '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
  12070. '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
  12071. ],
  12072. [
  12073. 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
  12074. '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
  12075. ],
  12076. [
  12077. '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
  12078. 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
  12079. ],
  12080. [
  12081. '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
  12082. 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
  12083. ],
  12084. [
  12085. 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
  12086. 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
  12087. ],
  12088. [
  12089. '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
  12090. '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
  12091. ],
  12092. [
  12093. '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
  12094. 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
  12095. ],
  12096. [
  12097. 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
  12098. 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
  12099. ],
  12100. [
  12101. '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
  12102. '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
  12103. ],
  12104. [
  12105. '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
  12106. 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
  12107. ],
  12108. [
  12109. '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
  12110. '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
  12111. ],
  12112. [
  12113. '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
  12114. 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
  12115. ],
  12116. [
  12117. 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
  12118. '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
  12119. ],
  12120. [
  12121. '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
  12122. '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
  12123. ],
  12124. [
  12125. '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
  12126. 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
  12127. ],
  12128. [
  12129. '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
  12130. 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
  12131. ],
  12132. [
  12133. 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
  12134. 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
  12135. ],
  12136. [
  12137. 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
  12138. 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
  12139. ],
  12140. [
  12141. '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
  12142. '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
  12143. ],
  12144. [
  12145. '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
  12146. '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
  12147. ],
  12148. [
  12149. 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
  12150. '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
  12151. ],
  12152. [
  12153. 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
  12154. 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
  12155. ],
  12156. [
  12157. '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
  12158. '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
  12159. ],
  12160. [
  12161. '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
  12162. '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
  12163. ],
  12164. [
  12165. 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
  12166. '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
  12167. ],
  12168. [
  12169. '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
  12170. '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
  12171. ],
  12172. [
  12173. 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
  12174. 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
  12175. ],
  12176. [
  12177. '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
  12178. 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
  12179. ],
  12180. [
  12181. '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
  12182. '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
  12183. ],
  12184. [
  12185. 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
  12186. '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
  12187. ],
  12188. [
  12189. 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
  12190. '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
  12191. ],
  12192. [
  12193. '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
  12194. '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
  12195. ],
  12196. [
  12197. '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
  12198. '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
  12199. ],
  12200. [
  12201. '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
  12202. 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
  12203. ],
  12204. [
  12205. '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
  12206. 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
  12207. ],
  12208. [
  12209. '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
  12210. '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
  12211. ],
  12212. [
  12213. '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
  12214. '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
  12215. ],
  12216. [
  12217. '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
  12218. '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
  12219. ],
  12220. [
  12221. '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
  12222. 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
  12223. ],
  12224. [
  12225. 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
  12226. 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
  12227. ],
  12228. [
  12229. '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
  12230. 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
  12231. ],
  12232. [
  12233. 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
  12234. '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
  12235. ],
  12236. [
  12237. 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
  12238. '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
  12239. ],
  12240. [
  12241. 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
  12242. '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
  12243. ],
  12244. [
  12245. 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
  12246. '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
  12247. ],
  12248. [
  12249. '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
  12250. 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
  12251. ],
  12252. [
  12253. '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
  12254. '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
  12255. ],
  12256. [
  12257. '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
  12258. 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
  12259. ],
  12260. [
  12261. 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
  12262. 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
  12263. ],
  12264. [
  12265. 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
  12266. '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
  12267. ],
  12268. [
  12269. 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
  12270. 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
  12271. ],
  12272. [
  12273. 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
  12274. '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
  12275. ],
  12276. [
  12277. '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
  12278. '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
  12279. ],
  12280. [
  12281. 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
  12282. '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
  12283. ],
  12284. [
  12285. 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
  12286. '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
  12287. ],
  12288. [
  12289. '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
  12290. '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
  12291. ],
  12292. [
  12293. '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
  12294. 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
  12295. ],
  12296. [
  12297. 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
  12298. '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
  12299. ],
  12300. [
  12301. 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
  12302. '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
  12303. ],
  12304. [
  12305. 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
  12306. '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
  12307. ],
  12308. [
  12309. '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
  12310. '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
  12311. ],
  12312. [
  12313. 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
  12314. 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
  12315. ],
  12316. [
  12317. '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
  12318. 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
  12319. ],
  12320. [
  12321. 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
  12322. 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
  12323. ],
  12324. [
  12325. 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
  12326. '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
  12327. ],
  12328. [
  12329. '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
  12330. 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
  12331. ],
  12332. [
  12333. 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
  12334. '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
  12335. ],
  12336. [
  12337. 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
  12338. '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
  12339. ],
  12340. [
  12341. 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
  12342. '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
  12343. ],
  12344. [
  12345. '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
  12346. 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
  12347. ],
  12348. [
  12349. '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
  12350. 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
  12351. ],
  12352. [
  12353. 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
  12354. '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
  12355. ],
  12356. [
  12357. '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
  12358. 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
  12359. ],
  12360. [
  12361. '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
  12362. '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
  12363. ],
  12364. [
  12365. '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
  12366. 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
  12367. ],
  12368. [
  12369. 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
  12370. 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
  12371. ],
  12372. [
  12373. '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
  12374. 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
  12375. ],
  12376. [
  12377. '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
  12378. '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
  12379. ],
  12380. [
  12381. '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
  12382. 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
  12383. ],
  12384. [
  12385. '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
  12386. '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
  12387. ],
  12388. [
  12389. 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
  12390. 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
  12391. ],
  12392. [
  12393. '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
  12394. '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
  12395. ],
  12396. [
  12397. 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
  12398. '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
  12399. ],
  12400. [
  12401. '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
  12402. '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
  12403. ],
  12404. [
  12405. 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
  12406. 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
  12407. ],
  12408. [
  12409. 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
  12410. '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
  12411. ],
  12412. [
  12413. 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
  12414. 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
  12415. ],
  12416. [
  12417. '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
  12418. 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
  12419. ],
  12420. [
  12421. '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
  12422. '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
  12423. ],
  12424. [
  12425. '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
  12426. 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
  12427. ],
  12428. [
  12429. '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
  12430. '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
  12431. ],
  12432. [
  12433. '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
  12434. '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
  12435. ],
  12436. [
  12437. '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
  12438. 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
  12439. ],
  12440. [
  12441. '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
  12442. '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
  12443. ],
  12444. [
  12445. '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
  12446. '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
  12447. ],
  12448. [
  12449. '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
  12450. '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
  12451. ]
  12452. ]
  12453. }
  12454. };
  12455. },{}],80:[function(require,module,exports){
  12456. 'use strict';
  12457. var utils = exports;
  12458. var BN = require('bn.js');
  12459. utils.assert = function assert(val, msg) {
  12460. if (!val)
  12461. throw new Error(msg || 'Assertion failed');
  12462. };
  12463. function toArray(msg, enc) {
  12464. if (Array.isArray(msg))
  12465. return msg.slice();
  12466. if (!msg)
  12467. return [];
  12468. var res = [];
  12469. if (typeof msg !== 'string') {
  12470. for (var i = 0; i < msg.length; i++)
  12471. res[i] = msg[i] | 0;
  12472. return res;
  12473. }
  12474. if (!enc) {
  12475. for (var i = 0; i < msg.length; i++) {
  12476. var c = msg.charCodeAt(i);
  12477. var hi = c >> 8;
  12478. var lo = c & 0xff;
  12479. if (hi)
  12480. res.push(hi, lo);
  12481. else
  12482. res.push(lo);
  12483. }
  12484. } else if (enc === 'hex') {
  12485. msg = msg.replace(/[^a-z0-9]+/ig, '');
  12486. if (msg.length % 2 !== 0)
  12487. msg = '0' + msg;
  12488. for (var i = 0; i < msg.length; i += 2)
  12489. res.push(parseInt(msg[i] + msg[i + 1], 16));
  12490. }
  12491. return res;
  12492. }
  12493. utils.toArray = toArray;
  12494. function zero2(word) {
  12495. if (word.length === 1)
  12496. return '0' + word;
  12497. else
  12498. return word;
  12499. }
  12500. utils.zero2 = zero2;
  12501. function toHex(msg) {
  12502. var res = '';
  12503. for (var i = 0; i < msg.length; i++)
  12504. res += zero2(msg[i].toString(16));
  12505. return res;
  12506. }
  12507. utils.toHex = toHex;
  12508. utils.encode = function encode(arr, enc) {
  12509. if (enc === 'hex')
  12510. return toHex(arr);
  12511. else
  12512. return arr;
  12513. };
  12514. // Represent num in a w-NAF form
  12515. function getNAF(num, w) {
  12516. var naf = [];
  12517. var ws = 1 << (w + 1);
  12518. var k = num.clone();
  12519. while (k.cmpn(1) >= 0) {
  12520. var z;
  12521. if (k.isOdd()) {
  12522. var mod = k.andln(ws - 1);
  12523. if (mod > (ws >> 1) - 1)
  12524. z = (ws >> 1) - mod;
  12525. else
  12526. z = mod;
  12527. k.isubn(z);
  12528. } else {
  12529. z = 0;
  12530. }
  12531. naf.push(z);
  12532. // Optimization, shift by word if possible
  12533. var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
  12534. for (var i = 1; i < shift; i++)
  12535. naf.push(0);
  12536. k.iushrn(shift);
  12537. }
  12538. return naf;
  12539. }
  12540. utils.getNAF = getNAF;
  12541. // Represent k1, k2 in a Joint Sparse Form
  12542. function getJSF(k1, k2) {
  12543. var jsf = [
  12544. [],
  12545. []
  12546. ];
  12547. k1 = k1.clone();
  12548. k2 = k2.clone();
  12549. var d1 = 0;
  12550. var d2 = 0;
  12551. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  12552. // First phase
  12553. var m14 = (k1.andln(3) + d1) & 3;
  12554. var m24 = (k2.andln(3) + d2) & 3;
  12555. if (m14 === 3)
  12556. m14 = -1;
  12557. if (m24 === 3)
  12558. m24 = -1;
  12559. var u1;
  12560. if ((m14 & 1) === 0) {
  12561. u1 = 0;
  12562. } else {
  12563. var m8 = (k1.andln(7) + d1) & 7;
  12564. if ((m8 === 3 || m8 === 5) && m24 === 2)
  12565. u1 = -m14;
  12566. else
  12567. u1 = m14;
  12568. }
  12569. jsf[0].push(u1);
  12570. var u2;
  12571. if ((m24 & 1) === 0) {
  12572. u2 = 0;
  12573. } else {
  12574. var m8 = (k2.andln(7) + d2) & 7;
  12575. if ((m8 === 3 || m8 === 5) && m14 === 2)
  12576. u2 = -m24;
  12577. else
  12578. u2 = m24;
  12579. }
  12580. jsf[1].push(u2);
  12581. // Second phase
  12582. if (2 * d1 === u1 + 1)
  12583. d1 = 1 - d1;
  12584. if (2 * d2 === u2 + 1)
  12585. d2 = 1 - d2;
  12586. k1.iushrn(1);
  12587. k2.iushrn(1);
  12588. }
  12589. return jsf;
  12590. }
  12591. utils.getJSF = getJSF;
  12592. function cachedProperty(obj, computer) {
  12593. var name = computer.name;
  12594. var key = '_' + name;
  12595. obj.prototype[name] = function cachedProperty() {
  12596. return this[key] !== undefined ? this[key] :
  12597. this[key] = computer.call(this);
  12598. };
  12599. }
  12600. utils.cachedProperty = cachedProperty;
  12601. function parseBytes(bytes) {
  12602. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
  12603. bytes;
  12604. }
  12605. utils.parseBytes = parseBytes;
  12606. function intFromLE(bytes) {
  12607. return new BN(bytes, 'hex', 'le');
  12608. }
  12609. utils.intFromLE = intFromLE;
  12610. },{"bn.js":18}],81:[function(require,module,exports){
  12611. module.exports={
  12612. "_args": [
  12613. [
  12614. "elliptic@^6.0.0",
  12615. "/home/guillaume/workspace/lesspass/lesspass/webextension/node_modules/browserify-sign"
  12616. ]
  12617. ],
  12618. "_from": "elliptic@>=6.0.0 <7.0.0",
  12619. "_id": "elliptic@6.2.3",
  12620. "_inCache": true,
  12621. "_installable": true,
  12622. "_location": "/elliptic",
  12623. "_nodeVersion": "5.4.1",
  12624. "_npmUser": {
  12625. "email": "fedor@indutny.com",
  12626. "name": "indutny"
  12627. },
  12628. "_npmVersion": "3.3.12",
  12629. "_phantomChildren": {},
  12630. "_requested": {
  12631. "name": "elliptic",
  12632. "raw": "elliptic@^6.0.0",
  12633. "rawSpec": "^6.0.0",
  12634. "scope": null,
  12635. "spec": ">=6.0.0 <7.0.0",
  12636. "type": "range"
  12637. },
  12638. "_requiredBy": [
  12639. "/browserify-sign",
  12640. "/create-ecdh"
  12641. ],
  12642. "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.2.3.tgz",
  12643. "_shasum": "18e46d7306b0951275a2d42063270a14b74ebe99",
  12644. "_shrinkwrap": null,
  12645. "_spec": "elliptic@^6.0.0",
  12646. "_where": "/home/guillaume/workspace/lesspass/lesspass/webextension/node_modules/browserify-sign",
  12647. "author": {
  12648. "email": "fedor@indutny.com",
  12649. "name": "Fedor Indutny"
  12650. },
  12651. "bugs": {
  12652. "url": "https://github.com/indutny/elliptic/issues"
  12653. },
  12654. "dependencies": {
  12655. "bn.js": "^4.0.0",
  12656. "brorand": "^1.0.1",
  12657. "hash.js": "^1.0.0",
  12658. "inherits": "^2.0.1"
  12659. },
  12660. "description": "EC cryptography",
  12661. "devDependencies": {
  12662. "coveralls": "^2.11.3",
  12663. "istanbul": "^0.4.2",
  12664. "jscs": "^2.9.0",
  12665. "jshint": "^2.6.0",
  12666. "mocha": "^2.1.0"
  12667. },
  12668. "directories": {},
  12669. "dist": {
  12670. "shasum": "18e46d7306b0951275a2d42063270a14b74ebe99",
  12671. "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.2.3.tgz"
  12672. },
  12673. "files": [
  12674. "lib"
  12675. ],
  12676. "gitHead": "c32f20b22b420eb6af3c6dda28963deb7facf823",
  12677. "homepage": "https://github.com/indutny/elliptic",
  12678. "keywords": [
  12679. "Cryptography",
  12680. "EC",
  12681. "Elliptic",
  12682. "curve"
  12683. ],
  12684. "license": "MIT",
  12685. "main": "lib/elliptic.js",
  12686. "maintainers": [
  12687. {
  12688. "name": "indutny",
  12689. "email": "fedor@indutny.com"
  12690. }
  12691. ],
  12692. "name": "elliptic",
  12693. "optionalDependencies": {},
  12694. "readme": "ERROR: No README data found!",
  12695. "repository": {
  12696. "type": "git",
  12697. "url": "git+ssh://git@github.com/indutny/elliptic.git"
  12698. },
  12699. "scripts": {
  12700. "coverage": "npm run unit --coverage",
  12701. "coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
  12702. "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/*.js",
  12703. "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/*.js",
  12704. "lint": "npm run jscs && npm run jshint",
  12705. "test": "npm run lint && npm run unit",
  12706. "unit": "istanbul test _mocha --reporter=spec test/*-test.js"
  12707. },
  12708. "version": "6.2.3"
  12709. }
  12710. },{}],82:[function(require,module,exports){
  12711. // Copyright Joyent, Inc. and other Node contributors.
  12712. //
  12713. // Permission is hereby granted, free of charge, to any person obtaining a
  12714. // copy of this software and associated documentation files (the
  12715. // "Software"), to deal in the Software without restriction, including
  12716. // without limitation the rights to use, copy, modify, merge, publish,
  12717. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12718. // persons to whom the Software is furnished to do so, subject to the
  12719. // following conditions:
  12720. //
  12721. // The above copyright notice and this permission notice shall be included
  12722. // in all copies or substantial portions of the Software.
  12723. //
  12724. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12725. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12726. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12727. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12728. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12729. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12730. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12731. function EventEmitter() {
  12732. this._events = this._events || {};
  12733. this._maxListeners = this._maxListeners || undefined;
  12734. }
  12735. module.exports = EventEmitter;
  12736. // Backwards-compat with node 0.10.x
  12737. EventEmitter.EventEmitter = EventEmitter;
  12738. EventEmitter.prototype._events = undefined;
  12739. EventEmitter.prototype._maxListeners = undefined;
  12740. // By default EventEmitters will print a warning if more than 10 listeners are
  12741. // added to it. This is a useful default which helps finding memory leaks.
  12742. EventEmitter.defaultMaxListeners = 10;
  12743. // Obviously not all Emitters should be limited to 10. This function allows
  12744. // that to be increased. Set to zero for unlimited.
  12745. EventEmitter.prototype.setMaxListeners = function(n) {
  12746. if (!isNumber(n) || n < 0 || isNaN(n))
  12747. throw TypeError('n must be a positive number');
  12748. this._maxListeners = n;
  12749. return this;
  12750. };
  12751. EventEmitter.prototype.emit = function(type) {
  12752. var er, handler, len, args, i, listeners;
  12753. if (!this._events)
  12754. this._events = {};
  12755. // If there is no 'error' event listener then throw.
  12756. if (type === 'error') {
  12757. if (!this._events.error ||
  12758. (isObject(this._events.error) && !this._events.error.length)) {
  12759. er = arguments[1];
  12760. if (er instanceof Error) {
  12761. throw er; // Unhandled 'error' event
  12762. }
  12763. throw TypeError('Uncaught, unspecified "error" event.');
  12764. }
  12765. }
  12766. handler = this._events[type];
  12767. if (isUndefined(handler))
  12768. return false;
  12769. if (isFunction(handler)) {
  12770. switch (arguments.length) {
  12771. // fast cases
  12772. case 1:
  12773. handler.call(this);
  12774. break;
  12775. case 2:
  12776. handler.call(this, arguments[1]);
  12777. break;
  12778. case 3:
  12779. handler.call(this, arguments[1], arguments[2]);
  12780. break;
  12781. // slower
  12782. default:
  12783. args = Array.prototype.slice.call(arguments, 1);
  12784. handler.apply(this, args);
  12785. }
  12786. } else if (isObject(handler)) {
  12787. args = Array.prototype.slice.call(arguments, 1);
  12788. listeners = handler.slice();
  12789. len = listeners.length;
  12790. for (i = 0; i < len; i++)
  12791. listeners[i].apply(this, args);
  12792. }
  12793. return true;
  12794. };
  12795. EventEmitter.prototype.addListener = function(type, listener) {
  12796. var m;
  12797. if (!isFunction(listener))
  12798. throw TypeError('listener must be a function');
  12799. if (!this._events)
  12800. this._events = {};
  12801. // To avoid recursion in the case that type === "newListener"! Before
  12802. // adding it to the listeners, first emit "newListener".
  12803. if (this._events.newListener)
  12804. this.emit('newListener', type,
  12805. isFunction(listener.listener) ?
  12806. listener.listener : listener);
  12807. if (!this._events[type])
  12808. // Optimize the case of one listener. Don't need the extra array object.
  12809. this._events[type] = listener;
  12810. else if (isObject(this._events[type]))
  12811. // If we've already got an array, just append.
  12812. this._events[type].push(listener);
  12813. else
  12814. // Adding the second element, need to change to array.
  12815. this._events[type] = [this._events[type], listener];
  12816. // Check for listener leak
  12817. if (isObject(this._events[type]) && !this._events[type].warned) {
  12818. if (!isUndefined(this._maxListeners)) {
  12819. m = this._maxListeners;
  12820. } else {
  12821. m = EventEmitter.defaultMaxListeners;
  12822. }
  12823. if (m && m > 0 && this._events[type].length > m) {
  12824. this._events[type].warned = true;
  12825. console.error('(node) warning: possible EventEmitter memory ' +
  12826. 'leak detected. %d listeners added. ' +
  12827. 'Use emitter.setMaxListeners() to increase limit.',
  12828. this._events[type].length);
  12829. if (typeof console.trace === 'function') {
  12830. // not supported in IE 10
  12831. console.trace();
  12832. }
  12833. }
  12834. }
  12835. return this;
  12836. };
  12837. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  12838. EventEmitter.prototype.once = function(type, listener) {
  12839. if (!isFunction(listener))
  12840. throw TypeError('listener must be a function');
  12841. var fired = false;
  12842. function g() {
  12843. this.removeListener(type, g);
  12844. if (!fired) {
  12845. fired = true;
  12846. listener.apply(this, arguments);
  12847. }
  12848. }
  12849. g.listener = listener;
  12850. this.on(type, g);
  12851. return this;
  12852. };
  12853. // emits a 'removeListener' event iff the listener was removed
  12854. EventEmitter.prototype.removeListener = function(type, listener) {
  12855. var list, position, length, i;
  12856. if (!isFunction(listener))
  12857. throw TypeError('listener must be a function');
  12858. if (!this._events || !this._events[type])
  12859. return this;
  12860. list = this._events[type];
  12861. length = list.length;
  12862. position = -1;
  12863. if (list === listener ||
  12864. (isFunction(list.listener) && list.listener === listener)) {
  12865. delete this._events[type];
  12866. if (this._events.removeListener)
  12867. this.emit('removeListener', type, listener);
  12868. } else if (isObject(list)) {
  12869. for (i = length; i-- > 0;) {
  12870. if (list[i] === listener ||
  12871. (list[i].listener && list[i].listener === listener)) {
  12872. position = i;
  12873. break;
  12874. }
  12875. }
  12876. if (position < 0)
  12877. return this;
  12878. if (list.length === 1) {
  12879. list.length = 0;
  12880. delete this._events[type];
  12881. } else {
  12882. list.splice(position, 1);
  12883. }
  12884. if (this._events.removeListener)
  12885. this.emit('removeListener', type, listener);
  12886. }
  12887. return this;
  12888. };
  12889. EventEmitter.prototype.removeAllListeners = function(type) {
  12890. var key, listeners;
  12891. if (!this._events)
  12892. return this;
  12893. // not listening for removeListener, no need to emit
  12894. if (!this._events.removeListener) {
  12895. if (arguments.length === 0)
  12896. this._events = {};
  12897. else if (this._events[type])
  12898. delete this._events[type];
  12899. return this;
  12900. }
  12901. // emit removeListener for all listeners on all events
  12902. if (arguments.length === 0) {
  12903. for (key in this._events) {
  12904. if (key === 'removeListener') continue;
  12905. this.removeAllListeners(key);
  12906. }
  12907. this.removeAllListeners('removeListener');
  12908. this._events = {};
  12909. return this;
  12910. }
  12911. listeners = this._events[type];
  12912. if (isFunction(listeners)) {
  12913. this.removeListener(type, listeners);
  12914. } else if (listeners) {
  12915. // LIFO order
  12916. while (listeners.length)
  12917. this.removeListener(type, listeners[listeners.length - 1]);
  12918. }
  12919. delete this._events[type];
  12920. return this;
  12921. };
  12922. EventEmitter.prototype.listeners = function(type) {
  12923. var ret;
  12924. if (!this._events || !this._events[type])
  12925. ret = [];
  12926. else if (isFunction(this._events[type]))
  12927. ret = [this._events[type]];
  12928. else
  12929. ret = this._events[type].slice();
  12930. return ret;
  12931. };
  12932. EventEmitter.prototype.listenerCount = function(type) {
  12933. if (this._events) {
  12934. var evlistener = this._events[type];
  12935. if (isFunction(evlistener))
  12936. return 1;
  12937. else if (evlistener)
  12938. return evlistener.length;
  12939. }
  12940. return 0;
  12941. };
  12942. EventEmitter.listenerCount = function(emitter, type) {
  12943. return emitter.listenerCount(type);
  12944. };
  12945. function isFunction(arg) {
  12946. return typeof arg === 'function';
  12947. }
  12948. function isNumber(arg) {
  12949. return typeof arg === 'number';
  12950. }
  12951. function isObject(arg) {
  12952. return typeof arg === 'object' && arg !== null;
  12953. }
  12954. function isUndefined(arg) {
  12955. return arg === void 0;
  12956. }
  12957. },{}],83:[function(require,module,exports){
  12958. (function (Buffer){
  12959. var md5 = require('create-hash/md5')
  12960. module.exports = EVP_BytesToKey
  12961. function EVP_BytesToKey (password, salt, keyLen, ivLen) {
  12962. if (!Buffer.isBuffer(password)) {
  12963. password = new Buffer(password, 'binary')
  12964. }
  12965. if (salt && !Buffer.isBuffer(salt)) {
  12966. salt = new Buffer(salt, 'binary')
  12967. }
  12968. keyLen = keyLen / 8
  12969. ivLen = ivLen || 0
  12970. var ki = 0
  12971. var ii = 0
  12972. var key = new Buffer(keyLen)
  12973. var iv = new Buffer(ivLen)
  12974. var addmd = 0
  12975. var md_buf
  12976. var i
  12977. var bufs = []
  12978. while (true) {
  12979. if (addmd++ > 0) {
  12980. bufs.push(md_buf)
  12981. }
  12982. bufs.push(password)
  12983. if (salt) {
  12984. bufs.push(salt)
  12985. }
  12986. md_buf = md5(Buffer.concat(bufs))
  12987. bufs = []
  12988. i = 0
  12989. if (keyLen > 0) {
  12990. while (true) {
  12991. if (keyLen === 0) {
  12992. break
  12993. }
  12994. if (i === md_buf.length) {
  12995. break
  12996. }
  12997. key[ki++] = md_buf[i]
  12998. keyLen--
  12999. i++
  13000. }
  13001. }
  13002. if (ivLen > 0 && i !== md_buf.length) {
  13003. while (true) {
  13004. if (ivLen === 0) {
  13005. break
  13006. }
  13007. if (i === md_buf.length) {
  13008. break
  13009. }
  13010. iv[ii++] = md_buf[i]
  13011. ivLen--
  13012. i++
  13013. }
  13014. }
  13015. if (keyLen === 0 && ivLen === 0) {
  13016. break
  13017. }
  13018. }
  13019. for (i = 0; i < md_buf.length; i++) {
  13020. md_buf[i] = 0
  13021. }
  13022. return {
  13023. key: key,
  13024. iv: iv
  13025. }
  13026. }
  13027. }).call(this,require("buffer").Buffer)
  13028. },{"buffer":46,"create-hash/md5":52}],84:[function(require,module,exports){
  13029. var hash = exports;
  13030. hash.utils = require('./hash/utils');
  13031. hash.common = require('./hash/common');
  13032. hash.sha = require('./hash/sha');
  13033. hash.ripemd = require('./hash/ripemd');
  13034. hash.hmac = require('./hash/hmac');
  13035. // Proxy hash functions to the main object
  13036. hash.sha1 = hash.sha.sha1;
  13037. hash.sha256 = hash.sha.sha256;
  13038. hash.sha224 = hash.sha.sha224;
  13039. hash.sha384 = hash.sha.sha384;
  13040. hash.sha512 = hash.sha.sha512;
  13041. hash.ripemd160 = hash.ripemd.ripemd160;
  13042. },{"./hash/common":85,"./hash/hmac":86,"./hash/ripemd":87,"./hash/sha":88,"./hash/utils":89}],85:[function(require,module,exports){
  13043. var hash = require('../hash');
  13044. var utils = hash.utils;
  13045. var assert = utils.assert;
  13046. function BlockHash() {
  13047. this.pending = null;
  13048. this.pendingTotal = 0;
  13049. this.blockSize = this.constructor.blockSize;
  13050. this.outSize = this.constructor.outSize;
  13051. this.hmacStrength = this.constructor.hmacStrength;
  13052. this.padLength = this.constructor.padLength / 8;
  13053. this.endian = 'big';
  13054. this._delta8 = this.blockSize / 8;
  13055. this._delta32 = this.blockSize / 32;
  13056. }
  13057. exports.BlockHash = BlockHash;
  13058. BlockHash.prototype.update = function update(msg, enc) {
  13059. // Convert message to array, pad it, and join into 32bit blocks
  13060. msg = utils.toArray(msg, enc);
  13061. if (!this.pending)
  13062. this.pending = msg;
  13063. else
  13064. this.pending = this.pending.concat(msg);
  13065. this.pendingTotal += msg.length;
  13066. // Enough data, try updating
  13067. if (this.pending.length >= this._delta8) {
  13068. msg = this.pending;
  13069. // Process pending data in blocks
  13070. var r = msg.length % this._delta8;
  13071. this.pending = msg.slice(msg.length - r, msg.length);
  13072. if (this.pending.length === 0)
  13073. this.pending = null;
  13074. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  13075. for (var i = 0; i < msg.length; i += this._delta32)
  13076. this._update(msg, i, i + this._delta32);
  13077. }
  13078. return this;
  13079. };
  13080. BlockHash.prototype.digest = function digest(enc) {
  13081. this.update(this._pad());
  13082. assert(this.pending === null);
  13083. return this._digest(enc);
  13084. };
  13085. BlockHash.prototype._pad = function pad() {
  13086. var len = this.pendingTotal;
  13087. var bytes = this._delta8;
  13088. var k = bytes - ((len + this.padLength) % bytes);
  13089. var res = new Array(k + this.padLength);
  13090. res[0] = 0x80;
  13091. for (var i = 1; i < k; i++)
  13092. res[i] = 0;
  13093. // Append length
  13094. len <<= 3;
  13095. if (this.endian === 'big') {
  13096. for (var t = 8; t < this.padLength; t++)
  13097. res[i++] = 0;
  13098. res[i++] = 0;
  13099. res[i++] = 0;
  13100. res[i++] = 0;
  13101. res[i++] = 0;
  13102. res[i++] = (len >>> 24) & 0xff;
  13103. res[i++] = (len >>> 16) & 0xff;
  13104. res[i++] = (len >>> 8) & 0xff;
  13105. res[i++] = len & 0xff;
  13106. } else {
  13107. res[i++] = len & 0xff;
  13108. res[i++] = (len >>> 8) & 0xff;
  13109. res[i++] = (len >>> 16) & 0xff;
  13110. res[i++] = (len >>> 24) & 0xff;
  13111. res[i++] = 0;
  13112. res[i++] = 0;
  13113. res[i++] = 0;
  13114. res[i++] = 0;
  13115. for (var t = 8; t < this.padLength; t++)
  13116. res[i++] = 0;
  13117. }
  13118. return res;
  13119. };
  13120. },{"../hash":84}],86:[function(require,module,exports){
  13121. var hmac = exports;
  13122. var hash = require('../hash');
  13123. var utils = hash.utils;
  13124. var assert = utils.assert;
  13125. function Hmac(hash, key, enc) {
  13126. if (!(this instanceof Hmac))
  13127. return new Hmac(hash, key, enc);
  13128. this.Hash = hash;
  13129. this.blockSize = hash.blockSize / 8;
  13130. this.outSize = hash.outSize / 8;
  13131. this.inner = null;
  13132. this.outer = null;
  13133. this._init(utils.toArray(key, enc));
  13134. }
  13135. module.exports = Hmac;
  13136. Hmac.prototype._init = function init(key) {
  13137. // Shorten key, if needed
  13138. if (key.length > this.blockSize)
  13139. key = new this.Hash().update(key).digest();
  13140. assert(key.length <= this.blockSize);
  13141. // Add padding to key
  13142. for (var i = key.length; i < this.blockSize; i++)
  13143. key.push(0);
  13144. for (var i = 0; i < key.length; i++)
  13145. key[i] ^= 0x36;
  13146. this.inner = new this.Hash().update(key);
  13147. // 0x36 ^ 0x5c = 0x6a
  13148. for (var i = 0; i < key.length; i++)
  13149. key[i] ^= 0x6a;
  13150. this.outer = new this.Hash().update(key);
  13151. };
  13152. Hmac.prototype.update = function update(msg, enc) {
  13153. this.inner.update(msg, enc);
  13154. return this;
  13155. };
  13156. Hmac.prototype.digest = function digest(enc) {
  13157. this.outer.update(this.inner.digest());
  13158. return this.outer.digest(enc);
  13159. };
  13160. },{"../hash":84}],87:[function(require,module,exports){
  13161. var hash = require('../hash');
  13162. var utils = hash.utils;
  13163. var rotl32 = utils.rotl32;
  13164. var sum32 = utils.sum32;
  13165. var sum32_3 = utils.sum32_3;
  13166. var sum32_4 = utils.sum32_4;
  13167. var BlockHash = hash.common.BlockHash;
  13168. function RIPEMD160() {
  13169. if (!(this instanceof RIPEMD160))
  13170. return new RIPEMD160();
  13171. BlockHash.call(this);
  13172. this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
  13173. this.endian = 'little';
  13174. }
  13175. utils.inherits(RIPEMD160, BlockHash);
  13176. exports.ripemd160 = RIPEMD160;
  13177. RIPEMD160.blockSize = 512;
  13178. RIPEMD160.outSize = 160;
  13179. RIPEMD160.hmacStrength = 192;
  13180. RIPEMD160.padLength = 64;
  13181. RIPEMD160.prototype._update = function update(msg, start) {
  13182. var A = this.h[0];
  13183. var B = this.h[1];
  13184. var C = this.h[2];
  13185. var D = this.h[3];
  13186. var E = this.h[4];
  13187. var Ah = A;
  13188. var Bh = B;
  13189. var Ch = C;
  13190. var Dh = D;
  13191. var Eh = E;
  13192. for (var j = 0; j < 80; j++) {
  13193. var T = sum32(
  13194. rotl32(
  13195. sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
  13196. s[j]),
  13197. E);
  13198. A = E;
  13199. E = D;
  13200. D = rotl32(C, 10);
  13201. C = B;
  13202. B = T;
  13203. T = sum32(
  13204. rotl32(
  13205. sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
  13206. sh[j]),
  13207. Eh);
  13208. Ah = Eh;
  13209. Eh = Dh;
  13210. Dh = rotl32(Ch, 10);
  13211. Ch = Bh;
  13212. Bh = T;
  13213. }
  13214. T = sum32_3(this.h[1], C, Dh);
  13215. this.h[1] = sum32_3(this.h[2], D, Eh);
  13216. this.h[2] = sum32_3(this.h[3], E, Ah);
  13217. this.h[3] = sum32_3(this.h[4], A, Bh);
  13218. this.h[4] = sum32_3(this.h[0], B, Ch);
  13219. this.h[0] = T;
  13220. };
  13221. RIPEMD160.prototype._digest = function digest(enc) {
  13222. if (enc === 'hex')
  13223. return utils.toHex32(this.h, 'little');
  13224. else
  13225. return utils.split32(this.h, 'little');
  13226. };
  13227. function f(j, x, y, z) {
  13228. if (j <= 15)
  13229. return x ^ y ^ z;
  13230. else if (j <= 31)
  13231. return (x & y) | ((~x) & z);
  13232. else if (j <= 47)
  13233. return (x | (~y)) ^ z;
  13234. else if (j <= 63)
  13235. return (x & z) | (y & (~z));
  13236. else
  13237. return x ^ (y | (~z));
  13238. }
  13239. function K(j) {
  13240. if (j <= 15)
  13241. return 0x00000000;
  13242. else if (j <= 31)
  13243. return 0x5a827999;
  13244. else if (j <= 47)
  13245. return 0x6ed9eba1;
  13246. else if (j <= 63)
  13247. return 0x8f1bbcdc;
  13248. else
  13249. return 0xa953fd4e;
  13250. }
  13251. function Kh(j) {
  13252. if (j <= 15)
  13253. return 0x50a28be6;
  13254. else if (j <= 31)
  13255. return 0x5c4dd124;
  13256. else if (j <= 47)
  13257. return 0x6d703ef3;
  13258. else if (j <= 63)
  13259. return 0x7a6d76e9;
  13260. else
  13261. return 0x00000000;
  13262. }
  13263. var r = [
  13264. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  13265. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  13266. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  13267. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  13268. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  13269. ];
  13270. var rh = [
  13271. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  13272. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  13273. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  13274. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  13275. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  13276. ];
  13277. var s = [
  13278. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  13279. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  13280. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  13281. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  13282. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  13283. ];
  13284. var sh = [
  13285. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  13286. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  13287. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  13288. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  13289. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  13290. ];
  13291. },{"../hash":84}],88:[function(require,module,exports){
  13292. var hash = require('../hash');
  13293. var utils = hash.utils;
  13294. var assert = utils.assert;
  13295. var rotr32 = utils.rotr32;
  13296. var rotl32 = utils.rotl32;
  13297. var sum32 = utils.sum32;
  13298. var sum32_4 = utils.sum32_4;
  13299. var sum32_5 = utils.sum32_5;
  13300. var rotr64_hi = utils.rotr64_hi;
  13301. var rotr64_lo = utils.rotr64_lo;
  13302. var shr64_hi = utils.shr64_hi;
  13303. var shr64_lo = utils.shr64_lo;
  13304. var sum64 = utils.sum64;
  13305. var sum64_hi = utils.sum64_hi;
  13306. var sum64_lo = utils.sum64_lo;
  13307. var sum64_4_hi = utils.sum64_4_hi;
  13308. var sum64_4_lo = utils.sum64_4_lo;
  13309. var sum64_5_hi = utils.sum64_5_hi;
  13310. var sum64_5_lo = utils.sum64_5_lo;
  13311. var BlockHash = hash.common.BlockHash;
  13312. var sha256_K = [
  13313. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  13314. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  13315. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  13316. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  13317. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  13318. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  13319. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  13320. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  13321. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  13322. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  13323. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  13324. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  13325. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  13326. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  13327. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  13328. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  13329. ];
  13330. var sha512_K = [
  13331. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  13332. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  13333. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  13334. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  13335. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  13336. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  13337. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  13338. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  13339. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  13340. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  13341. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  13342. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  13343. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  13344. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  13345. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  13346. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  13347. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  13348. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  13349. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  13350. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  13351. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  13352. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  13353. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  13354. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  13355. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  13356. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  13357. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  13358. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  13359. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  13360. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  13361. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  13362. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  13363. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  13364. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  13365. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  13366. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  13367. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  13368. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  13369. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  13370. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  13371. ];
  13372. var sha1_K = [
  13373. 0x5A827999, 0x6ED9EBA1,
  13374. 0x8F1BBCDC, 0xCA62C1D6
  13375. ];
  13376. function SHA256() {
  13377. if (!(this instanceof SHA256))
  13378. return new SHA256();
  13379. BlockHash.call(this);
  13380. this.h = [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  13381. 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ];
  13382. this.k = sha256_K;
  13383. this.W = new Array(64);
  13384. }
  13385. utils.inherits(SHA256, BlockHash);
  13386. exports.sha256 = SHA256;
  13387. SHA256.blockSize = 512;
  13388. SHA256.outSize = 256;
  13389. SHA256.hmacStrength = 192;
  13390. SHA256.padLength = 64;
  13391. SHA256.prototype._update = function _update(msg, start) {
  13392. var W = this.W;
  13393. for (var i = 0; i < 16; i++)
  13394. W[i] = msg[start + i];
  13395. for (; i < W.length; i++)
  13396. W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  13397. var a = this.h[0];
  13398. var b = this.h[1];
  13399. var c = this.h[2];
  13400. var d = this.h[3];
  13401. var e = this.h[4];
  13402. var f = this.h[5];
  13403. var g = this.h[6];
  13404. var h = this.h[7];
  13405. assert(this.k.length === W.length);
  13406. for (var i = 0; i < W.length; i++) {
  13407. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  13408. var T2 = sum32(s0_256(a), maj32(a, b, c));
  13409. h = g;
  13410. g = f;
  13411. f = e;
  13412. e = sum32(d, T1);
  13413. d = c;
  13414. c = b;
  13415. b = a;
  13416. a = sum32(T1, T2);
  13417. }
  13418. this.h[0] = sum32(this.h[0], a);
  13419. this.h[1] = sum32(this.h[1], b);
  13420. this.h[2] = sum32(this.h[2], c);
  13421. this.h[3] = sum32(this.h[3], d);
  13422. this.h[4] = sum32(this.h[4], e);
  13423. this.h[5] = sum32(this.h[5], f);
  13424. this.h[6] = sum32(this.h[6], g);
  13425. this.h[7] = sum32(this.h[7], h);
  13426. };
  13427. SHA256.prototype._digest = function digest(enc) {
  13428. if (enc === 'hex')
  13429. return utils.toHex32(this.h, 'big');
  13430. else
  13431. return utils.split32(this.h, 'big');
  13432. };
  13433. function SHA224() {
  13434. if (!(this instanceof SHA224))
  13435. return new SHA224();
  13436. SHA256.call(this);
  13437. this.h = [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  13438. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
  13439. }
  13440. utils.inherits(SHA224, SHA256);
  13441. exports.sha224 = SHA224;
  13442. SHA224.blockSize = 512;
  13443. SHA224.outSize = 224;
  13444. SHA224.hmacStrength = 192;
  13445. SHA224.padLength = 64;
  13446. SHA224.prototype._digest = function digest(enc) {
  13447. // Just truncate output
  13448. if (enc === 'hex')
  13449. return utils.toHex32(this.h.slice(0, 7), 'big');
  13450. else
  13451. return utils.split32(this.h.slice(0, 7), 'big');
  13452. };
  13453. function SHA512() {
  13454. if (!(this instanceof SHA512))
  13455. return new SHA512();
  13456. BlockHash.call(this);
  13457. this.h = [ 0x6a09e667, 0xf3bcc908,
  13458. 0xbb67ae85, 0x84caa73b,
  13459. 0x3c6ef372, 0xfe94f82b,
  13460. 0xa54ff53a, 0x5f1d36f1,
  13461. 0x510e527f, 0xade682d1,
  13462. 0x9b05688c, 0x2b3e6c1f,
  13463. 0x1f83d9ab, 0xfb41bd6b,
  13464. 0x5be0cd19, 0x137e2179 ];
  13465. this.k = sha512_K;
  13466. this.W = new Array(160);
  13467. }
  13468. utils.inherits(SHA512, BlockHash);
  13469. exports.sha512 = SHA512;
  13470. SHA512.blockSize = 1024;
  13471. SHA512.outSize = 512;
  13472. SHA512.hmacStrength = 192;
  13473. SHA512.padLength = 128;
  13474. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  13475. var W = this.W;
  13476. // 32 x 32bit words
  13477. for (var i = 0; i < 32; i++)
  13478. W[i] = msg[start + i];
  13479. for (; i < W.length; i += 2) {
  13480. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  13481. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  13482. var c1_hi = W[i - 14]; // i - 7
  13483. var c1_lo = W[i - 13];
  13484. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  13485. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  13486. var c3_hi = W[i - 32]; // i - 16
  13487. var c3_lo = W[i - 31];
  13488. W[i] = sum64_4_hi(c0_hi, c0_lo,
  13489. c1_hi, c1_lo,
  13490. c2_hi, c2_lo,
  13491. c3_hi, c3_lo);
  13492. W[i + 1] = sum64_4_lo(c0_hi, c0_lo,
  13493. c1_hi, c1_lo,
  13494. c2_hi, c2_lo,
  13495. c3_hi, c3_lo);
  13496. }
  13497. };
  13498. SHA512.prototype._update = function _update(msg, start) {
  13499. this._prepareBlock(msg, start);
  13500. var W = this.W;
  13501. var ah = this.h[0];
  13502. var al = this.h[1];
  13503. var bh = this.h[2];
  13504. var bl = this.h[3];
  13505. var ch = this.h[4];
  13506. var cl = this.h[5];
  13507. var dh = this.h[6];
  13508. var dl = this.h[7];
  13509. var eh = this.h[8];
  13510. var el = this.h[9];
  13511. var fh = this.h[10];
  13512. var fl = this.h[11];
  13513. var gh = this.h[12];
  13514. var gl = this.h[13];
  13515. var hh = this.h[14];
  13516. var hl = this.h[15];
  13517. assert(this.k.length === W.length);
  13518. for (var i = 0; i < W.length; i += 2) {
  13519. var c0_hi = hh;
  13520. var c0_lo = hl;
  13521. var c1_hi = s1_512_hi(eh, el);
  13522. var c1_lo = s1_512_lo(eh, el);
  13523. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  13524. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  13525. var c3_hi = this.k[i];
  13526. var c3_lo = this.k[i + 1];
  13527. var c4_hi = W[i];
  13528. var c4_lo = W[i + 1];
  13529. var T1_hi = sum64_5_hi(c0_hi, c0_lo,
  13530. c1_hi, c1_lo,
  13531. c2_hi, c2_lo,
  13532. c3_hi, c3_lo,
  13533. c4_hi, c4_lo);
  13534. var T1_lo = sum64_5_lo(c0_hi, c0_lo,
  13535. c1_hi, c1_lo,
  13536. c2_hi, c2_lo,
  13537. c3_hi, c3_lo,
  13538. c4_hi, c4_lo);
  13539. var c0_hi = s0_512_hi(ah, al);
  13540. var c0_lo = s0_512_lo(ah, al);
  13541. var c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  13542. var c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  13543. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  13544. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  13545. hh = gh;
  13546. hl = gl;
  13547. gh = fh;
  13548. gl = fl;
  13549. fh = eh;
  13550. fl = el;
  13551. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  13552. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  13553. dh = ch;
  13554. dl = cl;
  13555. ch = bh;
  13556. cl = bl;
  13557. bh = ah;
  13558. bl = al;
  13559. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  13560. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  13561. }
  13562. sum64(this.h, 0, ah, al);
  13563. sum64(this.h, 2, bh, bl);
  13564. sum64(this.h, 4, ch, cl);
  13565. sum64(this.h, 6, dh, dl);
  13566. sum64(this.h, 8, eh, el);
  13567. sum64(this.h, 10, fh, fl);
  13568. sum64(this.h, 12, gh, gl);
  13569. sum64(this.h, 14, hh, hl);
  13570. };
  13571. SHA512.prototype._digest = function digest(enc) {
  13572. if (enc === 'hex')
  13573. return utils.toHex32(this.h, 'big');
  13574. else
  13575. return utils.split32(this.h, 'big');
  13576. };
  13577. function SHA384() {
  13578. if (!(this instanceof SHA384))
  13579. return new SHA384();
  13580. SHA512.call(this);
  13581. this.h = [ 0xcbbb9d5d, 0xc1059ed8,
  13582. 0x629a292a, 0x367cd507,
  13583. 0x9159015a, 0x3070dd17,
  13584. 0x152fecd8, 0xf70e5939,
  13585. 0x67332667, 0xffc00b31,
  13586. 0x8eb44a87, 0x68581511,
  13587. 0xdb0c2e0d, 0x64f98fa7,
  13588. 0x47b5481d, 0xbefa4fa4 ];
  13589. }
  13590. utils.inherits(SHA384, SHA512);
  13591. exports.sha384 = SHA384;
  13592. SHA384.blockSize = 1024;
  13593. SHA384.outSize = 384;
  13594. SHA384.hmacStrength = 192;
  13595. SHA384.padLength = 128;
  13596. SHA384.prototype._digest = function digest(enc) {
  13597. if (enc === 'hex')
  13598. return utils.toHex32(this.h.slice(0, 12), 'big');
  13599. else
  13600. return utils.split32(this.h.slice(0, 12), 'big');
  13601. };
  13602. function SHA1() {
  13603. if (!(this instanceof SHA1))
  13604. return new SHA1();
  13605. BlockHash.call(this);
  13606. this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe,
  13607. 0x10325476, 0xc3d2e1f0 ];
  13608. this.W = new Array(80);
  13609. }
  13610. utils.inherits(SHA1, BlockHash);
  13611. exports.sha1 = SHA1;
  13612. SHA1.blockSize = 512;
  13613. SHA1.outSize = 160;
  13614. SHA1.hmacStrength = 80;
  13615. SHA1.padLength = 64;
  13616. SHA1.prototype._update = function _update(msg, start) {
  13617. var W = this.W;
  13618. for (var i = 0; i < 16; i++)
  13619. W[i] = msg[start + i];
  13620. for(; i < W.length; i++)
  13621. W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  13622. var a = this.h[0];
  13623. var b = this.h[1];
  13624. var c = this.h[2];
  13625. var d = this.h[3];
  13626. var e = this.h[4];
  13627. for (var i = 0; i < W.length; i++) {
  13628. var s = ~~(i / 20);
  13629. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  13630. e = d;
  13631. d = c;
  13632. c = rotl32(b, 30);
  13633. b = a;
  13634. a = t;
  13635. }
  13636. this.h[0] = sum32(this.h[0], a);
  13637. this.h[1] = sum32(this.h[1], b);
  13638. this.h[2] = sum32(this.h[2], c);
  13639. this.h[3] = sum32(this.h[3], d);
  13640. this.h[4] = sum32(this.h[4], e);
  13641. };
  13642. SHA1.prototype._digest = function digest(enc) {
  13643. if (enc === 'hex')
  13644. return utils.toHex32(this.h, 'big');
  13645. else
  13646. return utils.split32(this.h, 'big');
  13647. };
  13648. function ch32(x, y, z) {
  13649. return (x & y) ^ ((~x) & z);
  13650. }
  13651. function maj32(x, y, z) {
  13652. return (x & y) ^ (x & z) ^ (y & z);
  13653. }
  13654. function p32(x, y, z) {
  13655. return x ^ y ^ z;
  13656. }
  13657. function s0_256(x) {
  13658. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  13659. }
  13660. function s1_256(x) {
  13661. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  13662. }
  13663. function g0_256(x) {
  13664. return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
  13665. }
  13666. function g1_256(x) {
  13667. return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
  13668. }
  13669. function ft_1(s, x, y, z) {
  13670. if (s === 0)
  13671. return ch32(x, y, z);
  13672. if (s === 1 || s === 3)
  13673. return p32(x, y, z);
  13674. if (s === 2)
  13675. return maj32(x, y, z);
  13676. }
  13677. function ch64_hi(xh, xl, yh, yl, zh, zl) {
  13678. var r = (xh & yh) ^ ((~xh) & zh);
  13679. if (r < 0)
  13680. r += 0x100000000;
  13681. return r;
  13682. }
  13683. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  13684. var r = (xl & yl) ^ ((~xl) & zl);
  13685. if (r < 0)
  13686. r += 0x100000000;
  13687. return r;
  13688. }
  13689. function maj64_hi(xh, xl, yh, yl, zh, zl) {
  13690. var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
  13691. if (r < 0)
  13692. r += 0x100000000;
  13693. return r;
  13694. }
  13695. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  13696. var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
  13697. if (r < 0)
  13698. r += 0x100000000;
  13699. return r;
  13700. }
  13701. function s0_512_hi(xh, xl) {
  13702. var c0_hi = rotr64_hi(xh, xl, 28);
  13703. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  13704. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  13705. var r = c0_hi ^ c1_hi ^ c2_hi;
  13706. if (r < 0)
  13707. r += 0x100000000;
  13708. return r;
  13709. }
  13710. function s0_512_lo(xh, xl) {
  13711. var c0_lo = rotr64_lo(xh, xl, 28);
  13712. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  13713. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  13714. var r = c0_lo ^ c1_lo ^ c2_lo;
  13715. if (r < 0)
  13716. r += 0x100000000;
  13717. return r;
  13718. }
  13719. function s1_512_hi(xh, xl) {
  13720. var c0_hi = rotr64_hi(xh, xl, 14);
  13721. var c1_hi = rotr64_hi(xh, xl, 18);
  13722. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  13723. var r = c0_hi ^ c1_hi ^ c2_hi;
  13724. if (r < 0)
  13725. r += 0x100000000;
  13726. return r;
  13727. }
  13728. function s1_512_lo(xh, xl) {
  13729. var c0_lo = rotr64_lo(xh, xl, 14);
  13730. var c1_lo = rotr64_lo(xh, xl, 18);
  13731. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  13732. var r = c0_lo ^ c1_lo ^ c2_lo;
  13733. if (r < 0)
  13734. r += 0x100000000;
  13735. return r;
  13736. }
  13737. function g0_512_hi(xh, xl) {
  13738. var c0_hi = rotr64_hi(xh, xl, 1);
  13739. var c1_hi = rotr64_hi(xh, xl, 8);
  13740. var c2_hi = shr64_hi(xh, xl, 7);
  13741. var r = c0_hi ^ c1_hi ^ c2_hi;
  13742. if (r < 0)
  13743. r += 0x100000000;
  13744. return r;
  13745. }
  13746. function g0_512_lo(xh, xl) {
  13747. var c0_lo = rotr64_lo(xh, xl, 1);
  13748. var c1_lo = rotr64_lo(xh, xl, 8);
  13749. var c2_lo = shr64_lo(xh, xl, 7);
  13750. var r = c0_lo ^ c1_lo ^ c2_lo;
  13751. if (r < 0)
  13752. r += 0x100000000;
  13753. return r;
  13754. }
  13755. function g1_512_hi(xh, xl) {
  13756. var c0_hi = rotr64_hi(xh, xl, 19);
  13757. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  13758. var c2_hi = shr64_hi(xh, xl, 6);
  13759. var r = c0_hi ^ c1_hi ^ c2_hi;
  13760. if (r < 0)
  13761. r += 0x100000000;
  13762. return r;
  13763. }
  13764. function g1_512_lo(xh, xl) {
  13765. var c0_lo = rotr64_lo(xh, xl, 19);
  13766. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  13767. var c2_lo = shr64_lo(xh, xl, 6);
  13768. var r = c0_lo ^ c1_lo ^ c2_lo;
  13769. if (r < 0)
  13770. r += 0x100000000;
  13771. return r;
  13772. }
  13773. },{"../hash":84}],89:[function(require,module,exports){
  13774. var utils = exports;
  13775. var inherits = require('inherits');
  13776. function toArray(msg, enc) {
  13777. if (Array.isArray(msg))
  13778. return msg.slice();
  13779. if (!msg)
  13780. return [];
  13781. var res = [];
  13782. if (typeof msg === 'string') {
  13783. if (!enc) {
  13784. for (var i = 0; i < msg.length; i++) {
  13785. var c = msg.charCodeAt(i);
  13786. var hi = c >> 8;
  13787. var lo = c & 0xff;
  13788. if (hi)
  13789. res.push(hi, lo);
  13790. else
  13791. res.push(lo);
  13792. }
  13793. } else if (enc === 'hex') {
  13794. msg = msg.replace(/[^a-z0-9]+/ig, '');
  13795. if (msg.length % 2 !== 0)
  13796. msg = '0' + msg;
  13797. for (var i = 0; i < msg.length; i += 2)
  13798. res.push(parseInt(msg[i] + msg[i + 1], 16));
  13799. }
  13800. } else {
  13801. for (var i = 0; i < msg.length; i++)
  13802. res[i] = msg[i] | 0;
  13803. }
  13804. return res;
  13805. }
  13806. utils.toArray = toArray;
  13807. function toHex(msg) {
  13808. var res = '';
  13809. for (var i = 0; i < msg.length; i++)
  13810. res += zero2(msg[i].toString(16));
  13811. return res;
  13812. }
  13813. utils.toHex = toHex;
  13814. function htonl(w) {
  13815. var res = (w >>> 24) |
  13816. ((w >>> 8) & 0xff00) |
  13817. ((w << 8) & 0xff0000) |
  13818. ((w & 0xff) << 24);
  13819. return res >>> 0;
  13820. }
  13821. utils.htonl = htonl;
  13822. function toHex32(msg, endian) {
  13823. var res = '';
  13824. for (var i = 0; i < msg.length; i++) {
  13825. var w = msg[i];
  13826. if (endian === 'little')
  13827. w = htonl(w);
  13828. res += zero8(w.toString(16));
  13829. }
  13830. return res;
  13831. }
  13832. utils.toHex32 = toHex32;
  13833. function zero2(word) {
  13834. if (word.length === 1)
  13835. return '0' + word;
  13836. else
  13837. return word;
  13838. }
  13839. utils.zero2 = zero2;
  13840. function zero8(word) {
  13841. if (word.length === 7)
  13842. return '0' + word;
  13843. else if (word.length === 6)
  13844. return '00' + word;
  13845. else if (word.length === 5)
  13846. return '000' + word;
  13847. else if (word.length === 4)
  13848. return '0000' + word;
  13849. else if (word.length === 3)
  13850. return '00000' + word;
  13851. else if (word.length === 2)
  13852. return '000000' + word;
  13853. else if (word.length === 1)
  13854. return '0000000' + word;
  13855. else
  13856. return word;
  13857. }
  13858. utils.zero8 = zero8;
  13859. function join32(msg, start, end, endian) {
  13860. var len = end - start;
  13861. assert(len % 4 === 0);
  13862. var res = new Array(len / 4);
  13863. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  13864. var w;
  13865. if (endian === 'big')
  13866. w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
  13867. else
  13868. w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
  13869. res[i] = w >>> 0;
  13870. }
  13871. return res;
  13872. }
  13873. utils.join32 = join32;
  13874. function split32(msg, endian) {
  13875. var res = new Array(msg.length * 4);
  13876. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  13877. var m = msg[i];
  13878. if (endian === 'big') {
  13879. res[k] = m >>> 24;
  13880. res[k + 1] = (m >>> 16) & 0xff;
  13881. res[k + 2] = (m >>> 8) & 0xff;
  13882. res[k + 3] = m & 0xff;
  13883. } else {
  13884. res[k + 3] = m >>> 24;
  13885. res[k + 2] = (m >>> 16) & 0xff;
  13886. res[k + 1] = (m >>> 8) & 0xff;
  13887. res[k] = m & 0xff;
  13888. }
  13889. }
  13890. return res;
  13891. }
  13892. utils.split32 = split32;
  13893. function rotr32(w, b) {
  13894. return (w >>> b) | (w << (32 - b));
  13895. }
  13896. utils.rotr32 = rotr32;
  13897. function rotl32(w, b) {
  13898. return (w << b) | (w >>> (32 - b));
  13899. }
  13900. utils.rotl32 = rotl32;
  13901. function sum32(a, b) {
  13902. return (a + b) >>> 0;
  13903. }
  13904. utils.sum32 = sum32;
  13905. function sum32_3(a, b, c) {
  13906. return (a + b + c) >>> 0;
  13907. }
  13908. utils.sum32_3 = sum32_3;
  13909. function sum32_4(a, b, c, d) {
  13910. return (a + b + c + d) >>> 0;
  13911. }
  13912. utils.sum32_4 = sum32_4;
  13913. function sum32_5(a, b, c, d, e) {
  13914. return (a + b + c + d + e) >>> 0;
  13915. }
  13916. utils.sum32_5 = sum32_5;
  13917. function assert(cond, msg) {
  13918. if (!cond)
  13919. throw new Error(msg || 'Assertion failed');
  13920. }
  13921. utils.assert = assert;
  13922. utils.inherits = inherits;
  13923. function sum64(buf, pos, ah, al) {
  13924. var bh = buf[pos];
  13925. var bl = buf[pos + 1];
  13926. var lo = (al + bl) >>> 0;
  13927. var hi = (lo < al ? 1 : 0) + ah + bh;
  13928. buf[pos] = hi >>> 0;
  13929. buf[pos + 1] = lo;
  13930. }
  13931. exports.sum64 = sum64;
  13932. function sum64_hi(ah, al, bh, bl) {
  13933. var lo = (al + bl) >>> 0;
  13934. var hi = (lo < al ? 1 : 0) + ah + bh;
  13935. return hi >>> 0;
  13936. };
  13937. exports.sum64_hi = sum64_hi;
  13938. function sum64_lo(ah, al, bh, bl) {
  13939. var lo = al + bl;
  13940. return lo >>> 0;
  13941. };
  13942. exports.sum64_lo = sum64_lo;
  13943. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  13944. var carry = 0;
  13945. var lo = al;
  13946. lo = (lo + bl) >>> 0;
  13947. carry += lo < al ? 1 : 0;
  13948. lo = (lo + cl) >>> 0;
  13949. carry += lo < cl ? 1 : 0;
  13950. lo = (lo + dl) >>> 0;
  13951. carry += lo < dl ? 1 : 0;
  13952. var hi = ah + bh + ch + dh + carry;
  13953. return hi >>> 0;
  13954. };
  13955. exports.sum64_4_hi = sum64_4_hi;
  13956. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  13957. var lo = al + bl + cl + dl;
  13958. return lo >>> 0;
  13959. };
  13960. exports.sum64_4_lo = sum64_4_lo;
  13961. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  13962. var carry = 0;
  13963. var lo = al;
  13964. lo = (lo + bl) >>> 0;
  13965. carry += lo < al ? 1 : 0;
  13966. lo = (lo + cl) >>> 0;
  13967. carry += lo < cl ? 1 : 0;
  13968. lo = (lo + dl) >>> 0;
  13969. carry += lo < dl ? 1 : 0;
  13970. lo = (lo + el) >>> 0;
  13971. carry += lo < el ? 1 : 0;
  13972. var hi = ah + bh + ch + dh + eh + carry;
  13973. return hi >>> 0;
  13974. };
  13975. exports.sum64_5_hi = sum64_5_hi;
  13976. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  13977. var lo = al + bl + cl + dl + el;
  13978. return lo >>> 0;
  13979. };
  13980. exports.sum64_5_lo = sum64_5_lo;
  13981. function rotr64_hi(ah, al, num) {
  13982. var r = (al << (32 - num)) | (ah >>> num);
  13983. return r >>> 0;
  13984. };
  13985. exports.rotr64_hi = rotr64_hi;
  13986. function rotr64_lo(ah, al, num) {
  13987. var r = (ah << (32 - num)) | (al >>> num);
  13988. return r >>> 0;
  13989. };
  13990. exports.rotr64_lo = rotr64_lo;
  13991. function shr64_hi(ah, al, num) {
  13992. return ah >>> num;
  13993. };
  13994. exports.shr64_hi = shr64_hi;
  13995. function shr64_lo(ah, al, num) {
  13996. var r = (ah << (32 - num)) | (al >>> num);
  13997. return r >>> 0;
  13998. };
  13999. exports.shr64_lo = shr64_lo;
  14000. },{"inherits":92}],90:[function(require,module,exports){
  14001. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  14002. var e, m
  14003. var eLen = nBytes * 8 - mLen - 1
  14004. var eMax = (1 << eLen) - 1
  14005. var eBias = eMax >> 1
  14006. var nBits = -7
  14007. var i = isLE ? (nBytes - 1) : 0
  14008. var d = isLE ? -1 : 1
  14009. var s = buffer[offset + i]
  14010. i += d
  14011. e = s & ((1 << (-nBits)) - 1)
  14012. s >>= (-nBits)
  14013. nBits += eLen
  14014. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  14015. m = e & ((1 << (-nBits)) - 1)
  14016. e >>= (-nBits)
  14017. nBits += mLen
  14018. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  14019. if (e === 0) {
  14020. e = 1 - eBias
  14021. } else if (e === eMax) {
  14022. return m ? NaN : ((s ? -1 : 1) * Infinity)
  14023. } else {
  14024. m = m + Math.pow(2, mLen)
  14025. e = e - eBias
  14026. }
  14027. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  14028. }
  14029. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  14030. var e, m, c
  14031. var eLen = nBytes * 8 - mLen - 1
  14032. var eMax = (1 << eLen) - 1
  14033. var eBias = eMax >> 1
  14034. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  14035. var i = isLE ? 0 : (nBytes - 1)
  14036. var d = isLE ? 1 : -1
  14037. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  14038. value = Math.abs(value)
  14039. if (isNaN(value) || value === Infinity) {
  14040. m = isNaN(value) ? 1 : 0
  14041. e = eMax
  14042. } else {
  14043. e = Math.floor(Math.log(value) / Math.LN2)
  14044. if (value * (c = Math.pow(2, -e)) < 1) {
  14045. e--
  14046. c *= 2
  14047. }
  14048. if (e + eBias >= 1) {
  14049. value += rt / c
  14050. } else {
  14051. value += rt * Math.pow(2, 1 - eBias)
  14052. }
  14053. if (value * c >= 2) {
  14054. e++
  14055. c /= 2
  14056. }
  14057. if (e + eBias >= eMax) {
  14058. m = 0
  14059. e = eMax
  14060. } else if (e + eBias >= 1) {
  14061. m = (value * c - 1) * Math.pow(2, mLen)
  14062. e = e + eBias
  14063. } else {
  14064. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  14065. e = 0
  14066. }
  14067. }
  14068. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  14069. e = (e << mLen) | m
  14070. eLen += mLen
  14071. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  14072. buffer[offset + i - d] |= s * 128
  14073. }
  14074. },{}],91:[function(require,module,exports){
  14075. var indexOf = [].indexOf;
  14076. module.exports = function(arr, obj){
  14077. if (indexOf) return arr.indexOf(obj);
  14078. for (var i = 0; i < arr.length; ++i) {
  14079. if (arr[i] === obj) return i;
  14080. }
  14081. return -1;
  14082. };
  14083. },{}],92:[function(require,module,exports){
  14084. if (typeof Object.create === 'function') {
  14085. // implementation from standard node.js 'util' module
  14086. module.exports = function inherits(ctor, superCtor) {
  14087. ctor.super_ = superCtor
  14088. ctor.prototype = Object.create(superCtor.prototype, {
  14089. constructor: {
  14090. value: ctor,
  14091. enumerable: false,
  14092. writable: true,
  14093. configurable: true
  14094. }
  14095. });
  14096. };
  14097. } else {
  14098. // old school shim for old browsers
  14099. module.exports = function inherits(ctor, superCtor) {
  14100. ctor.super_ = superCtor
  14101. var TempCtor = function () {}
  14102. TempCtor.prototype = superCtor.prototype
  14103. ctor.prototype = new TempCtor()
  14104. ctor.prototype.constructor = ctor
  14105. }
  14106. }
  14107. },{}],93:[function(require,module,exports){
  14108. /**
  14109. * Determine if an object is Buffer
  14110. *
  14111. * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  14112. * License: MIT
  14113. *
  14114. * `npm install is-buffer`
  14115. */
  14116. module.exports = function (obj) {
  14117. return !!(obj != null &&
  14118. (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
  14119. (obj.constructor &&
  14120. typeof obj.constructor.isBuffer === 'function' &&
  14121. obj.constructor.isBuffer(obj))
  14122. ))
  14123. }
  14124. },{}],94:[function(require,module,exports){
  14125. var toString = {}.toString;
  14126. module.exports = Array.isArray || function (arr) {
  14127. return toString.call(arr) == '[object Array]';
  14128. };
  14129. },{}],95:[function(require,module,exports){
  14130. 'use strict';
  14131. var _crypto = require('crypto');
  14132. var _crypto2 = _interopRequireDefault(_crypto);
  14133. var _render = require('./render');
  14134. var _render2 = _interopRequireDefault(_render);
  14135. function _interopRequireDefault(obj) {
  14136. return obj && obj.__esModule ? obj : { default: obj };
  14137. }
  14138. module.exports = {
  14139. createPassword: _createPassword,
  14140. generatePassword: _generatePassword,
  14141. encryptLogin: _encryptLogin,
  14142. deriveHash: _deriveHash
  14143. };
  14144. function _encryptLogin(login, masterPassword) {
  14145. return new Promise(function (resolve, reject) {
  14146. if (!login || !masterPassword) {
  14147. reject('encryptLogin parameter could not be empty');
  14148. }
  14149. var iterations = 8192;
  14150. var keylen = 32;
  14151. _crypto2.default.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
  14152. if (error) {
  14153. reject('error in pbkdf2');
  14154. } else {
  14155. resolve(key.toString('hex'));
  14156. }
  14157. });
  14158. });
  14159. }
  14160. function _deriveHash(hash, site) {
  14161. var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  14162. var _ref$password = _ref.password;
  14163. var password = _ref$password === undefined ? { length: 12 } : _ref$password;
  14164. var _ref$counter = _ref.counter;
  14165. var counter = _ref$counter === undefined ? 1 : _ref$counter;
  14166. var salt = site + counter.toString();
  14167. var derivedHash = _crypto2.default.createHmac('sha256', hash).update(salt).digest('hex');
  14168. return derivedHash.substring(0, password.length);
  14169. }
  14170. function _createPassword(hash, entry) {
  14171. // createPassword is deprecated use generatePassword instead
  14172. var options = {
  14173. counter: entry.password.counter || 1,
  14174. password: entry.password
  14175. };
  14176. var site = entry.site;
  14177. var derivedHash = _deriveHash(hash, site, options);
  14178. var template = _render2.default.getTemplate(options.password.settings);
  14179. return _render2.default.prettyPrint(derivedHash, template);
  14180. }
  14181. function _generatePassword(login, masterPassword, site, options) {
  14182. return new Promise(function (resolve, reject) {
  14183. if (!login || !masterPassword || !site) {
  14184. reject('generatePassword invalid parameter');
  14185. }
  14186. _encryptLogin(login, masterPassword).then(function (hash) {
  14187. var derivedHash = _deriveHash(hash, site, options);
  14188. var template = _render2.default.getTemplate(options.password.settings);
  14189. resolve(_render2.default.prettyPrint(derivedHash, template));
  14190. });
  14191. });
  14192. }
  14193. },{"./render":97,"crypto":54}],96:[function(require,module,exports){
  14194. 'use strict';
  14195. var _encryption = require('./encryption');
  14196. var _encryption2 = _interopRequireDefault(_encryption);
  14197. function _interopRequireDefault(obj) {
  14198. return obj && obj.__esModule ? obj : { default: obj };
  14199. }
  14200. module.exports = {
  14201. generatePassword: _encryption2.default.generatePassword,
  14202. createPassword: _encryption2.default.createPassword,
  14203. createMasterPassword: _encryption2.default.encryptLogin
  14204. };
  14205. },{"./encryption":95}],97:[function(require,module,exports){
  14206. 'use strict';
  14207. module.exports = {
  14208. prettyPrint: _prettyPrint,
  14209. getTemplate: _getTemplate,
  14210. _getCharType: _getCharType,
  14211. _getPasswordChar: _getPasswordChar,
  14212. _string2charCodes: _string2charCodes
  14213. };
  14214. function _getCharType(template, index) {
  14215. return template[index % template.length];
  14216. }
  14217. function _getPasswordChar(charType, index) {
  14218. var passwordsChars = {
  14219. V: 'AEIOUY',
  14220. C: 'BCDFGHJKLMNPQRSTVWXZ',
  14221. v: 'aeiouy',
  14222. c: 'bcdfghjklmnpqrstvwxz',
  14223. A: 'AEIOUYBCDFGHJKLMNPQRSTVWXZ',
  14224. a: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz',
  14225. n: '0123456789',
  14226. s: '@&%?,=[]_:-+*$#!\'^~;()/.',
  14227. x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
  14228. };
  14229. var passwordChar = passwordsChars[charType];
  14230. return passwordChar[index % passwordChar.length];
  14231. }
  14232. function _prettyPrint(hash, template) {
  14233. var password = '';
  14234. _string2charCodes(hash).forEach(function (charCode, index) {
  14235. var charType = _getCharType(template, index);
  14236. password += _getPasswordChar(charType, charCode);
  14237. });
  14238. return password;
  14239. }
  14240. function _string2charCodes(text) {
  14241. var charCodes = [];
  14242. for (var i = 0; i < text.length; i++) {
  14243. charCodes.push(text.charCodeAt(i));
  14244. }
  14245. return charCodes;
  14246. }
  14247. function _getTemplate() {
  14248. var passwordTypes = arguments.length <= 0 || arguments[0] === undefined ? ['strong'] : arguments[0];
  14249. var passwordTypesInfo = {
  14250. lowercase: { value: 'vc', order: 1 },
  14251. uppercase: { value: 'VC', order: 2 },
  14252. numbers: { value: 'n', order: 3 },
  14253. symbols: { value: 's', order: 4 },
  14254. strong: { value: 'Cvcvns', order: 5 }
  14255. };
  14256. return passwordTypes.map(function (passwordType) {
  14257. return passwordTypesInfo[passwordType];
  14258. }).sort(function (passwordType1, passwordType2) {
  14259. return passwordType1.order > passwordType2.order;
  14260. }).map(function (passwordType) {
  14261. return passwordType.value;
  14262. }).join('');
  14263. }
  14264. },{}],98:[function(require,module,exports){
  14265. var bn = require('bn.js');
  14266. var brorand = require('brorand');
  14267. function MillerRabin(rand) {
  14268. this.rand = rand || new brorand.Rand();
  14269. }
  14270. module.exports = MillerRabin;
  14271. MillerRabin.create = function create(rand) {
  14272. return new MillerRabin(rand);
  14273. };
  14274. MillerRabin.prototype._rand = function _rand(n) {
  14275. var len = n.bitLength();
  14276. var buf = this.rand.generate(Math.ceil(len / 8));
  14277. // Set low bits
  14278. buf[0] |= 3;
  14279. // Mask high bits
  14280. var mask = len & 0x7;
  14281. if (mask !== 0)
  14282. buf[buf.length - 1] >>= 7 - mask;
  14283. return new bn(buf);
  14284. }
  14285. MillerRabin.prototype.test = function test(n, k, cb) {
  14286. var len = n.bitLength();
  14287. var red = bn.mont(n);
  14288. var rone = new bn(1).toRed(red);
  14289. if (!k)
  14290. k = Math.max(1, (len / 48) | 0);
  14291. // Find d and s, (n - 1) = (2 ^ s) * d;
  14292. var n1 = n.subn(1);
  14293. var n2 = n1.subn(1);
  14294. for (var s = 0; !n1.testn(s); s++) {}
  14295. var d = n.shrn(s);
  14296. var rn1 = n1.toRed(red);
  14297. var prime = true;
  14298. for (; k > 0; k--) {
  14299. var a = this._rand(n2);
  14300. if (cb)
  14301. cb(a);
  14302. var x = a.toRed(red).redPow(d);
  14303. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
  14304. continue;
  14305. for (var i = 1; i < s; i++) {
  14306. x = x.redSqr();
  14307. if (x.cmp(rone) === 0)
  14308. return false;
  14309. if (x.cmp(rn1) === 0)
  14310. break;
  14311. }
  14312. if (i === s)
  14313. return false;
  14314. }
  14315. return prime;
  14316. };
  14317. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  14318. var len = n.bitLength();
  14319. var red = bn.mont(n);
  14320. var rone = new bn(1).toRed(red);
  14321. if (!k)
  14322. k = Math.max(1, (len / 48) | 0);
  14323. // Find d and s, (n - 1) = (2 ^ s) * d;
  14324. var n1 = n.subn(1);
  14325. var n2 = n1.subn(1);
  14326. for (var s = 0; !n1.testn(s); s++) {}
  14327. var d = n.shrn(s);
  14328. var rn1 = n1.toRed(red);
  14329. for (; k > 0; k--) {
  14330. var a = this._rand(n2);
  14331. var g = n.gcd(a);
  14332. if (g.cmpn(1) !== 0)
  14333. return g;
  14334. var x = a.toRed(red).redPow(d);
  14335. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
  14336. continue;
  14337. for (var i = 1; i < s; i++) {
  14338. x = x.redSqr();
  14339. if (x.cmp(rone) === 0)
  14340. return x.fromRed().subn(1).gcd(n);
  14341. if (x.cmp(rn1) === 0)
  14342. break;
  14343. }
  14344. if (i === s) {
  14345. x = x.redSqr();
  14346. return x.fromRed().subn(1).gcd(n);
  14347. }
  14348. }
  14349. return false;
  14350. };
  14351. },{"bn.js":18,"brorand":19}],99:[function(require,module,exports){
  14352. module.exports = assert;
  14353. function assert(val, msg) {
  14354. if (!val)
  14355. throw new Error(msg || 'Assertion failed');
  14356. }
  14357. assert.equal = function assertEqual(l, r, msg) {
  14358. if (l != r)
  14359. throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
  14360. };
  14361. },{}],100:[function(require,module,exports){
  14362. module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
  14363. "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
  14364. "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
  14365. "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
  14366. "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
  14367. "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
  14368. "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
  14369. "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
  14370. "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
  14371. "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
  14372. "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
  14373. "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
  14374. }
  14375. },{}],101:[function(require,module,exports){
  14376. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  14377. // Fedor, you are amazing.
  14378. var asn1 = require('asn1.js')
  14379. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  14380. this.seq().obj(
  14381. this.key('version').int(),
  14382. this.key('modulus').int(),
  14383. this.key('publicExponent').int(),
  14384. this.key('privateExponent').int(),
  14385. this.key('prime1').int(),
  14386. this.key('prime2').int(),
  14387. this.key('exponent1').int(),
  14388. this.key('exponent2').int(),
  14389. this.key('coefficient').int()
  14390. )
  14391. })
  14392. exports.RSAPrivateKey = RSAPrivateKey
  14393. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  14394. this.seq().obj(
  14395. this.key('modulus').int(),
  14396. this.key('publicExponent').int()
  14397. )
  14398. })
  14399. exports.RSAPublicKey = RSAPublicKey
  14400. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  14401. this.seq().obj(
  14402. this.key('algorithm').use(AlgorithmIdentifier),
  14403. this.key('subjectPublicKey').bitstr()
  14404. )
  14405. })
  14406. exports.PublicKey = PublicKey
  14407. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  14408. this.seq().obj(
  14409. this.key('algorithm').objid(),
  14410. this.key('none').null_().optional(),
  14411. this.key('curve').objid().optional(),
  14412. this.key('params').seq().obj(
  14413. this.key('p').int(),
  14414. this.key('q').int(),
  14415. this.key('g').int()
  14416. ).optional()
  14417. )
  14418. })
  14419. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  14420. this.seq().obj(
  14421. this.key('version').int(),
  14422. this.key('algorithm').use(AlgorithmIdentifier),
  14423. this.key('subjectPrivateKey').octstr()
  14424. )
  14425. })
  14426. exports.PrivateKey = PrivateKeyInfo
  14427. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  14428. this.seq().obj(
  14429. this.key('algorithm').seq().obj(
  14430. this.key('id').objid(),
  14431. this.key('decrypt').seq().obj(
  14432. this.key('kde').seq().obj(
  14433. this.key('id').objid(),
  14434. this.key('kdeparams').seq().obj(
  14435. this.key('salt').octstr(),
  14436. this.key('iters').int()
  14437. )
  14438. ),
  14439. this.key('cipher').seq().obj(
  14440. this.key('algo').objid(),
  14441. this.key('iv').octstr()
  14442. )
  14443. )
  14444. ),
  14445. this.key('subjectPrivateKey').octstr()
  14446. )
  14447. })
  14448. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
  14449. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  14450. this.seq().obj(
  14451. this.key('version').int(),
  14452. this.key('p').int(),
  14453. this.key('q').int(),
  14454. this.key('g').int(),
  14455. this.key('pub_key').int(),
  14456. this.key('priv_key').int()
  14457. )
  14458. })
  14459. exports.DSAPrivateKey = DSAPrivateKey
  14460. exports.DSAparam = asn1.define('DSAparam', function () {
  14461. this.int()
  14462. })
  14463. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  14464. this.seq().obj(
  14465. this.key('version').int(),
  14466. this.key('privateKey').octstr(),
  14467. this.key('parameters').optional().explicit(0).use(ECParameters),
  14468. this.key('publicKey').optional().explicit(1).bitstr()
  14469. )
  14470. })
  14471. exports.ECPrivateKey = ECPrivateKey
  14472. var ECParameters = asn1.define('ECParameters', function () {
  14473. this.choice({
  14474. namedCurve: this.objid()
  14475. })
  14476. })
  14477. exports.signature = asn1.define('signature', function () {
  14478. this.seq().obj(
  14479. this.key('r').int(),
  14480. this.key('s').int()
  14481. )
  14482. })
  14483. },{"asn1.js":3}],102:[function(require,module,exports){
  14484. (function (Buffer){
  14485. // adapted from https://github.com/apatil/pemstrip
  14486. var findProc = /Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)\r?\n\r?\n([0-9A-z\n\r\+\/\=]+)\r?\n/m
  14487. var startRegex = /^-----BEGIN (.*) KEY-----\r?\n/m
  14488. var fullRegex = /^-----BEGIN (.*) KEY-----\r?\n([0-9A-z\n\r\+\/\=]+)\r?\n-----END \1 KEY-----$/m
  14489. var evp = require('evp_bytestokey')
  14490. var ciphers = require('browserify-aes')
  14491. module.exports = function (okey, password) {
  14492. var key = okey.toString()
  14493. var match = key.match(findProc)
  14494. var decrypted
  14495. if (!match) {
  14496. var match2 = key.match(fullRegex)
  14497. decrypted = new Buffer(match2[2].replace(/\r?\n/g, ''), 'base64')
  14498. } else {
  14499. var suite = 'aes' + match[1]
  14500. var iv = new Buffer(match[2], 'hex')
  14501. var cipherText = new Buffer(match[3].replace(/\r?\n/g, ''), 'base64')
  14502. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key
  14503. var out = []
  14504. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv)
  14505. out.push(cipher.update(cipherText))
  14506. out.push(cipher.final())
  14507. decrypted = Buffer.concat(out)
  14508. }
  14509. var tag = key.match(startRegex)[1] + ' KEY'
  14510. return {
  14511. tag: tag,
  14512. data: decrypted
  14513. }
  14514. }
  14515. }).call(this,require("buffer").Buffer)
  14516. },{"browserify-aes":23,"buffer":46,"evp_bytestokey":83}],103:[function(require,module,exports){
  14517. (function (Buffer){
  14518. var asn1 = require('./asn1')
  14519. var aesid = require('./aesid.json')
  14520. var fixProc = require('./fixProc')
  14521. var ciphers = require('browserify-aes')
  14522. var compat = require('pbkdf2')
  14523. module.exports = parseKeys
  14524. function parseKeys (buffer) {
  14525. var password
  14526. if (typeof buffer === 'object' && !Buffer.isBuffer(buffer)) {
  14527. password = buffer.passphrase
  14528. buffer = buffer.key
  14529. }
  14530. if (typeof buffer === 'string') {
  14531. buffer = new Buffer(buffer)
  14532. }
  14533. var stripped = fixProc(buffer, password)
  14534. var type = stripped.tag
  14535. var data = stripped.data
  14536. var subtype, ndata
  14537. switch (type) {
  14538. case 'PUBLIC KEY':
  14539. ndata = asn1.PublicKey.decode(data, 'der')
  14540. subtype = ndata.algorithm.algorithm.join('.')
  14541. switch (subtype) {
  14542. case '1.2.840.113549.1.1.1':
  14543. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der')
  14544. case '1.2.840.10045.2.1':
  14545. ndata.subjectPrivateKey = ndata.subjectPublicKey
  14546. return {
  14547. type: 'ec',
  14548. data: ndata
  14549. }
  14550. case '1.2.840.10040.4.1':
  14551. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der')
  14552. return {
  14553. type: 'dsa',
  14554. data: ndata.algorithm.params
  14555. }
  14556. default: throw new Error('unknown key id ' + subtype)
  14557. }
  14558. throw new Error('unknown key type ' + type)
  14559. case 'ENCRYPTED PRIVATE KEY':
  14560. data = asn1.EncryptedPrivateKey.decode(data, 'der')
  14561. data = decrypt(data, password)
  14562. // falls through
  14563. case 'PRIVATE KEY':
  14564. ndata = asn1.PrivateKey.decode(data, 'der')
  14565. subtype = ndata.algorithm.algorithm.join('.')
  14566. switch (subtype) {
  14567. case '1.2.840.113549.1.1.1':
  14568. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der')
  14569. case '1.2.840.10045.2.1':
  14570. return {
  14571. curve: ndata.algorithm.curve,
  14572. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  14573. }
  14574. case '1.2.840.10040.4.1':
  14575. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der')
  14576. return {
  14577. type: 'dsa',
  14578. params: ndata.algorithm.params
  14579. }
  14580. default: throw new Error('unknown key id ' + subtype)
  14581. }
  14582. throw new Error('unknown key type ' + type)
  14583. case 'RSA PUBLIC KEY':
  14584. return asn1.RSAPublicKey.decode(data, 'der')
  14585. case 'RSA PRIVATE KEY':
  14586. return asn1.RSAPrivateKey.decode(data, 'der')
  14587. case 'DSA PRIVATE KEY':
  14588. return {
  14589. type: 'dsa',
  14590. params: asn1.DSAPrivateKey.decode(data, 'der')
  14591. }
  14592. case 'EC PRIVATE KEY':
  14593. data = asn1.ECPrivateKey.decode(data, 'der')
  14594. return {
  14595. curve: data.parameters.value,
  14596. privateKey: data.privateKey
  14597. }
  14598. default: throw new Error('unknown key type ' + type)
  14599. }
  14600. }
  14601. parseKeys.signature = asn1.signature
  14602. function decrypt (data, password) {
  14603. var salt = data.algorithm.decrypt.kde.kdeparams.salt
  14604. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10)
  14605. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')]
  14606. var iv = data.algorithm.decrypt.cipher.iv
  14607. var cipherText = data.subjectPrivateKey
  14608. var keylen = parseInt(algo.split('-')[1], 10) / 8
  14609. var key = compat.pbkdf2Sync(password, salt, iters, keylen)
  14610. var cipher = ciphers.createDecipheriv(algo, key, iv)
  14611. var out = []
  14612. out.push(cipher.update(cipherText))
  14613. out.push(cipher.final())
  14614. return Buffer.concat(out)
  14615. }
  14616. }).call(this,require("buffer").Buffer)
  14617. },{"./aesid.json":100,"./asn1":101,"./fixProc":102,"browserify-aes":23,"buffer":46,"pbkdf2":104}],104:[function(require,module,exports){
  14618. (function (Buffer){
  14619. var createHmac = require('create-hmac')
  14620. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  14621. exports.pbkdf2 = pbkdf2
  14622. function pbkdf2 (password, salt, iterations, keylen, digest, callback) {
  14623. if (typeof digest === 'function') {
  14624. callback = digest
  14625. digest = undefined
  14626. }
  14627. if (typeof callback !== 'function') {
  14628. throw new Error('No callback provided to pbkdf2')
  14629. }
  14630. var result = pbkdf2Sync(password, salt, iterations, keylen, digest)
  14631. setTimeout(function () {
  14632. callback(undefined, result)
  14633. })
  14634. }
  14635. exports.pbkdf2Sync = pbkdf2Sync
  14636. function pbkdf2Sync (password, salt, iterations, keylen, digest) {
  14637. if (typeof iterations !== 'number') {
  14638. throw new TypeError('Iterations not a number')
  14639. }
  14640. if (iterations < 0) {
  14641. throw new TypeError('Bad iterations')
  14642. }
  14643. if (typeof keylen !== 'number') {
  14644. throw new TypeError('Key length not a number')
  14645. }
  14646. if (keylen < 0 || keylen > MAX_ALLOC) {
  14647. throw new TypeError('Bad key length')
  14648. }
  14649. digest = digest || 'sha1'
  14650. if (!Buffer.isBuffer(password)) password = new Buffer(password, 'binary')
  14651. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, 'binary')
  14652. var hLen
  14653. var l = 1
  14654. var DK = new Buffer(keylen)
  14655. var block1 = new Buffer(salt.length + 4)
  14656. salt.copy(block1, 0, 0, salt.length)
  14657. var r
  14658. var T
  14659. for (var i = 1; i <= l; i++) {
  14660. block1.writeUInt32BE(i, salt.length)
  14661. var U = createHmac(digest, password).update(block1).digest()
  14662. if (!hLen) {
  14663. hLen = U.length
  14664. T = new Buffer(hLen)
  14665. l = Math.ceil(keylen / hLen)
  14666. r = keylen - (l - 1) * hLen
  14667. }
  14668. U.copy(T, 0, 0, hLen)
  14669. for (var j = 1; j < iterations; j++) {
  14670. U = createHmac(digest, password).update(U).digest()
  14671. for (var k = 0; k < hLen; k++) {
  14672. T[k] ^= U[k]
  14673. }
  14674. }
  14675. var destPos = (i - 1) * hLen
  14676. var len = (i === l ? r : hLen)
  14677. T.copy(DK, destPos, 0, len)
  14678. }
  14679. return DK
  14680. }
  14681. }).call(this,require("buffer").Buffer)
  14682. },{"buffer":46,"create-hmac":53}],105:[function(require,module,exports){
  14683. (function (process){
  14684. 'use strict';
  14685. if (!process.version ||
  14686. process.version.indexOf('v0.') === 0 ||
  14687. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  14688. module.exports = nextTick;
  14689. } else {
  14690. module.exports = process.nextTick;
  14691. }
  14692. function nextTick(fn, arg1, arg2, arg3) {
  14693. if (typeof fn !== 'function') {
  14694. throw new TypeError('"callback" argument must be a function');
  14695. }
  14696. var len = arguments.length;
  14697. var args, i;
  14698. switch (len) {
  14699. case 0:
  14700. case 1:
  14701. return process.nextTick(fn);
  14702. case 2:
  14703. return process.nextTick(function afterTickOne() {
  14704. fn.call(null, arg1);
  14705. });
  14706. case 3:
  14707. return process.nextTick(function afterTickTwo() {
  14708. fn.call(null, arg1, arg2);
  14709. });
  14710. case 4:
  14711. return process.nextTick(function afterTickThree() {
  14712. fn.call(null, arg1, arg2, arg3);
  14713. });
  14714. default:
  14715. args = new Array(len - 1);
  14716. i = 0;
  14717. while (i < args.length) {
  14718. args[i++] = arguments[i];
  14719. }
  14720. return process.nextTick(function afterTick() {
  14721. fn.apply(null, args);
  14722. });
  14723. }
  14724. }
  14725. }).call(this,require('_process'))
  14726. },{"_process":106}],106:[function(require,module,exports){
  14727. // shim for using process in browser
  14728. var process = module.exports = {};
  14729. var queue = [];
  14730. var draining = false;
  14731. var currentQueue;
  14732. var queueIndex = -1;
  14733. function cleanUpNextTick() {
  14734. if (!draining || !currentQueue) {
  14735. return;
  14736. }
  14737. draining = false;
  14738. if (currentQueue.length) {
  14739. queue = currentQueue.concat(queue);
  14740. } else {
  14741. queueIndex = -1;
  14742. }
  14743. if (queue.length) {
  14744. drainQueue();
  14745. }
  14746. }
  14747. function drainQueue() {
  14748. if (draining) {
  14749. return;
  14750. }
  14751. var timeout = setTimeout(cleanUpNextTick);
  14752. draining = true;
  14753. var len = queue.length;
  14754. while(len) {
  14755. currentQueue = queue;
  14756. queue = [];
  14757. while (++queueIndex < len) {
  14758. if (currentQueue) {
  14759. currentQueue[queueIndex].run();
  14760. }
  14761. }
  14762. queueIndex = -1;
  14763. len = queue.length;
  14764. }
  14765. currentQueue = null;
  14766. draining = false;
  14767. clearTimeout(timeout);
  14768. }
  14769. process.nextTick = function (fun) {
  14770. var args = new Array(arguments.length - 1);
  14771. if (arguments.length > 1) {
  14772. for (var i = 1; i < arguments.length; i++) {
  14773. args[i - 1] = arguments[i];
  14774. }
  14775. }
  14776. queue.push(new Item(fun, args));
  14777. if (queue.length === 1 && !draining) {
  14778. setTimeout(drainQueue, 0);
  14779. }
  14780. };
  14781. // v8 likes predictible objects
  14782. function Item(fun, array) {
  14783. this.fun = fun;
  14784. this.array = array;
  14785. }
  14786. Item.prototype.run = function () {
  14787. this.fun.apply(null, this.array);
  14788. };
  14789. process.title = 'browser';
  14790. process.browser = true;
  14791. process.env = {};
  14792. process.argv = [];
  14793. process.version = ''; // empty string to avoid regexp issues
  14794. process.versions = {};
  14795. function noop() {}
  14796. process.on = noop;
  14797. process.addListener = noop;
  14798. process.once = noop;
  14799. process.off = noop;
  14800. process.removeListener = noop;
  14801. process.removeAllListeners = noop;
  14802. process.emit = noop;
  14803. process.binding = function (name) {
  14804. throw new Error('process.binding is not supported');
  14805. };
  14806. process.cwd = function () { return '/' };
  14807. process.chdir = function (dir) {
  14808. throw new Error('process.chdir is not supported');
  14809. };
  14810. process.umask = function() { return 0; };
  14811. },{}],107:[function(require,module,exports){
  14812. exports.publicEncrypt = require('./publicEncrypt');
  14813. exports.privateDecrypt = require('./privateDecrypt');
  14814. exports.privateEncrypt = function privateEncrypt(key, buf) {
  14815. return exports.publicEncrypt(key, buf, true);
  14816. };
  14817. exports.publicDecrypt = function publicDecrypt(key, buf) {
  14818. return exports.privateDecrypt(key, buf, true);
  14819. };
  14820. },{"./privateDecrypt":109,"./publicEncrypt":110}],108:[function(require,module,exports){
  14821. (function (Buffer){
  14822. var createHash = require('create-hash');
  14823. module.exports = function (seed, len) {
  14824. var t = new Buffer('');
  14825. var i = 0, c;
  14826. while (t.length < len) {
  14827. c = i2ops(i++);
  14828. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  14829. }
  14830. return t.slice(0, len);
  14831. };
  14832. function i2ops(c) {
  14833. var out = new Buffer(4);
  14834. out.writeUInt32BE(c,0);
  14835. return out;
  14836. }
  14837. }).call(this,require("buffer").Buffer)
  14838. },{"buffer":46,"create-hash":50}],109:[function(require,module,exports){
  14839. (function (Buffer){
  14840. var parseKeys = require('parse-asn1');
  14841. var mgf = require('./mgf');
  14842. var xor = require('./xor');
  14843. var bn = require('bn.js');
  14844. var crt = require('browserify-rsa');
  14845. var createHash = require('create-hash');
  14846. var withPublic = require('./withPublic');
  14847. module.exports = function privateDecrypt(private_key, enc, reverse) {
  14848. var padding;
  14849. if (private_key.padding) {
  14850. padding = private_key.padding;
  14851. } else if (reverse) {
  14852. padding = 1;
  14853. } else {
  14854. padding = 4;
  14855. }
  14856. var key = parseKeys(private_key);
  14857. var k = key.modulus.byteLength();
  14858. if (enc.length > k || new bn(enc).cmp(key.modulus) >= 0) {
  14859. throw new Error('decryption error');
  14860. }
  14861. var msg;
  14862. if (reverse) {
  14863. msg = withPublic(new bn(enc), key);
  14864. } else {
  14865. msg = crt(enc, key);
  14866. }
  14867. var zBuffer = new Buffer(k - msg.length);
  14868. zBuffer.fill(0);
  14869. msg = Buffer.concat([zBuffer, msg], k);
  14870. if (padding === 4) {
  14871. return oaep(key, msg);
  14872. } else if (padding === 1) {
  14873. return pkcs1(key, msg, reverse);
  14874. } else if (padding === 3) {
  14875. return msg;
  14876. } else {
  14877. throw new Error('unknown padding');
  14878. }
  14879. };
  14880. function oaep(key, msg){
  14881. var n = key.modulus;
  14882. var k = key.modulus.byteLength();
  14883. var mLen = msg.length;
  14884. var iHash = createHash('sha1').update(new Buffer('')).digest();
  14885. var hLen = iHash.length;
  14886. var hLen2 = 2 * hLen;
  14887. if (msg[0] !== 0) {
  14888. throw new Error('decryption error');
  14889. }
  14890. var maskedSeed = msg.slice(1, hLen + 1);
  14891. var maskedDb = msg.slice(hLen + 1);
  14892. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  14893. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  14894. if (compare(iHash, db.slice(0, hLen))) {
  14895. throw new Error('decryption error');
  14896. }
  14897. var i = hLen;
  14898. while (db[i] === 0) {
  14899. i++;
  14900. }
  14901. if (db[i++] !== 1) {
  14902. throw new Error('decryption error');
  14903. }
  14904. return db.slice(i);
  14905. }
  14906. function pkcs1(key, msg, reverse){
  14907. var p1 = msg.slice(0, 2);
  14908. var i = 2;
  14909. var status = 0;
  14910. while (msg[i++] !== 0) {
  14911. if (i >= msg.length) {
  14912. status++;
  14913. break;
  14914. }
  14915. }
  14916. var ps = msg.slice(2, i - 1);
  14917. var p2 = msg.slice(i - 1, i);
  14918. if ((p1.toString('hex') !== '0002' && !reverse) || (p1.toString('hex') !== '0001' && reverse)){
  14919. status++;
  14920. }
  14921. if (ps.length < 8) {
  14922. status++;
  14923. }
  14924. if (status) {
  14925. throw new Error('decryption error');
  14926. }
  14927. return msg.slice(i);
  14928. }
  14929. function compare(a, b){
  14930. a = new Buffer(a);
  14931. b = new Buffer(b);
  14932. var dif = 0;
  14933. var len = a.length;
  14934. if (a.length !== b.length) {
  14935. dif++;
  14936. len = Math.min(a.length, b.length);
  14937. }
  14938. var i = -1;
  14939. while (++i < len) {
  14940. dif += (a[i] ^ b[i]);
  14941. }
  14942. return dif;
  14943. }
  14944. }).call(this,require("buffer").Buffer)
  14945. },{"./mgf":108,"./withPublic":111,"./xor":112,"bn.js":18,"browserify-rsa":39,"buffer":46,"create-hash":50,"parse-asn1":103}],110:[function(require,module,exports){
  14946. (function (Buffer){
  14947. var parseKeys = require('parse-asn1');
  14948. var randomBytes = require('randombytes');
  14949. var createHash = require('create-hash');
  14950. var mgf = require('./mgf');
  14951. var xor = require('./xor');
  14952. var bn = require('bn.js');
  14953. var withPublic = require('./withPublic');
  14954. var crt = require('browserify-rsa');
  14955. var constants = {
  14956. RSA_PKCS1_OAEP_PADDING: 4,
  14957. RSA_PKCS1_PADDIN: 1,
  14958. RSA_NO_PADDING: 3
  14959. };
  14960. module.exports = function publicEncrypt(public_key, msg, reverse) {
  14961. var padding;
  14962. if (public_key.padding) {
  14963. padding = public_key.padding;
  14964. } else if (reverse) {
  14965. padding = 1;
  14966. } else {
  14967. padding = 4;
  14968. }
  14969. var key = parseKeys(public_key);
  14970. var paddedMsg;
  14971. if (padding === 4) {
  14972. paddedMsg = oaep(key, msg);
  14973. } else if (padding === 1) {
  14974. paddedMsg = pkcs1(key, msg, reverse);
  14975. } else if (padding === 3) {
  14976. paddedMsg = new bn(msg);
  14977. if (paddedMsg.cmp(key.modulus) >= 0) {
  14978. throw new Error('data too long for modulus');
  14979. }
  14980. } else {
  14981. throw new Error('unknown padding');
  14982. }
  14983. if (reverse) {
  14984. return crt(paddedMsg, key);
  14985. } else {
  14986. return withPublic(paddedMsg, key);
  14987. }
  14988. };
  14989. function oaep(key, msg){
  14990. var k = key.modulus.byteLength();
  14991. var mLen = msg.length;
  14992. var iHash = createHash('sha1').update(new Buffer('')).digest();
  14993. var hLen = iHash.length;
  14994. var hLen2 = 2 * hLen;
  14995. if (mLen > k - hLen2 - 2) {
  14996. throw new Error('message too long');
  14997. }
  14998. var ps = new Buffer(k - mLen - hLen2 - 2);
  14999. ps.fill(0);
  15000. var dblen = k - hLen - 1;
  15001. var seed = randomBytes(hLen);
  15002. var maskedDb = xor(Buffer.concat([iHash, ps, new Buffer([1]), msg], dblen), mgf(seed, dblen));
  15003. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  15004. return new bn(Buffer.concat([new Buffer([0]), maskedSeed, maskedDb], k));
  15005. }
  15006. function pkcs1(key, msg, reverse){
  15007. var mLen = msg.length;
  15008. var k = key.modulus.byteLength();
  15009. if (mLen > k - 11) {
  15010. throw new Error('message too long');
  15011. }
  15012. var ps;
  15013. if (reverse) {
  15014. ps = new Buffer(k - mLen - 3);
  15015. ps.fill(0xff);
  15016. } else {
  15017. ps = nonZero(k - mLen - 3);
  15018. }
  15019. return new bn(Buffer.concat([new Buffer([0, reverse?1:2]), ps, new Buffer([0]), msg], k));
  15020. }
  15021. function nonZero(len, crypto) {
  15022. var out = new Buffer(len);
  15023. var i = 0;
  15024. var cache = randomBytes(len*2);
  15025. var cur = 0;
  15026. var num;
  15027. while (i < len) {
  15028. if (cur === cache.length) {
  15029. cache = randomBytes(len*2);
  15030. cur = 0;
  15031. }
  15032. num = cache[cur++];
  15033. if (num) {
  15034. out[i++] = num;
  15035. }
  15036. }
  15037. return out;
  15038. }
  15039. }).call(this,require("buffer").Buffer)
  15040. },{"./mgf":108,"./withPublic":111,"./xor":112,"bn.js":18,"browserify-rsa":39,"buffer":46,"create-hash":50,"parse-asn1":103,"randombytes":117}],111:[function(require,module,exports){
  15041. (function (Buffer){
  15042. var bn = require('bn.js');
  15043. function withPublic(paddedMsg, key) {
  15044. return new Buffer(paddedMsg
  15045. .toRed(bn.mont(key.modulus))
  15046. .redPow(new bn(key.publicExponent))
  15047. .fromRed()
  15048. .toArray());
  15049. }
  15050. module.exports = withPublic;
  15051. }).call(this,require("buffer").Buffer)
  15052. },{"bn.js":18,"buffer":46}],112:[function(require,module,exports){
  15053. module.exports = function xor(a, b) {
  15054. var len = a.length;
  15055. var i = -1;
  15056. while (++i < len) {
  15057. a[i] ^= b[i];
  15058. }
  15059. return a
  15060. };
  15061. },{}],113:[function(require,module,exports){
  15062. (function (global){
  15063. /*! https://mths.be/punycode v1.4.1 by @mathias */
  15064. ;(function(root) {
  15065. /** Detect free variables */
  15066. var freeExports = typeof exports == 'object' && exports &&
  15067. !exports.nodeType && exports;
  15068. var freeModule = typeof module == 'object' && module &&
  15069. !module.nodeType && module;
  15070. var freeGlobal = typeof global == 'object' && global;
  15071. if (
  15072. freeGlobal.global === freeGlobal ||
  15073. freeGlobal.window === freeGlobal ||
  15074. freeGlobal.self === freeGlobal
  15075. ) {
  15076. root = freeGlobal;
  15077. }
  15078. /**
  15079. * The `punycode` object.
  15080. * @name punycode
  15081. * @type Object
  15082. */
  15083. var punycode,
  15084. /** Highest positive signed 32-bit float value */
  15085. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  15086. /** Bootstring parameters */
  15087. base = 36,
  15088. tMin = 1,
  15089. tMax = 26,
  15090. skew = 38,
  15091. damp = 700,
  15092. initialBias = 72,
  15093. initialN = 128, // 0x80
  15094. delimiter = '-', // '\x2D'
  15095. /** Regular expressions */
  15096. regexPunycode = /^xn--/,
  15097. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  15098. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  15099. /** Error messages */
  15100. errors = {
  15101. 'overflow': 'Overflow: input needs wider integers to process',
  15102. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  15103. 'invalid-input': 'Invalid input'
  15104. },
  15105. /** Convenience shortcuts */
  15106. baseMinusTMin = base - tMin,
  15107. floor = Math.floor,
  15108. stringFromCharCode = String.fromCharCode,
  15109. /** Temporary variable */
  15110. key;
  15111. /*--------------------------------------------------------------------------*/
  15112. /**
  15113. * A generic error utility function.
  15114. * @private
  15115. * @param {String} type The error type.
  15116. * @returns {Error} Throws a `RangeError` with the applicable error message.
  15117. */
  15118. function error(type) {
  15119. throw new RangeError(errors[type]);
  15120. }
  15121. /**
  15122. * A generic `Array#map` utility function.
  15123. * @private
  15124. * @param {Array} array The array to iterate over.
  15125. * @param {Function} callback The function that gets called for every array
  15126. * item.
  15127. * @returns {Array} A new array of values returned by the callback function.
  15128. */
  15129. function map(array, fn) {
  15130. var length = array.length;
  15131. var result = [];
  15132. while (length--) {
  15133. result[length] = fn(array[length]);
  15134. }
  15135. return result;
  15136. }
  15137. /**
  15138. * A simple `Array#map`-like wrapper to work with domain name strings or email
  15139. * addresses.
  15140. * @private
  15141. * @param {String} domain The domain name or email address.
  15142. * @param {Function} callback The function that gets called for every
  15143. * character.
  15144. * @returns {Array} A new string of characters returned by the callback
  15145. * function.
  15146. */
  15147. function mapDomain(string, fn) {
  15148. var parts = string.split('@');
  15149. var result = '';
  15150. if (parts.length > 1) {
  15151. // In email addresses, only the domain name should be punycoded. Leave
  15152. // the local part (i.e. everything up to `@`) intact.
  15153. result = parts[0] + '@';
  15154. string = parts[1];
  15155. }
  15156. // Avoid `split(regex)` for IE8 compatibility. See #17.
  15157. string = string.replace(regexSeparators, '\x2E');
  15158. var labels = string.split('.');
  15159. var encoded = map(labels, fn).join('.');
  15160. return result + encoded;
  15161. }
  15162. /**
  15163. * Creates an array containing the numeric code points of each Unicode
  15164. * character in the string. While JavaScript uses UCS-2 internally,
  15165. * this function will convert a pair of surrogate halves (each of which
  15166. * UCS-2 exposes as separate characters) into a single code point,
  15167. * matching UTF-16.
  15168. * @see `punycode.ucs2.encode`
  15169. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  15170. * @memberOf punycode.ucs2
  15171. * @name decode
  15172. * @param {String} string The Unicode input string (UCS-2).
  15173. * @returns {Array} The new array of code points.
  15174. */
  15175. function ucs2decode(string) {
  15176. var output = [],
  15177. counter = 0,
  15178. length = string.length,
  15179. value,
  15180. extra;
  15181. while (counter < length) {
  15182. value = string.charCodeAt(counter++);
  15183. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  15184. // high surrogate, and there is a next character
  15185. extra = string.charCodeAt(counter++);
  15186. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  15187. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  15188. } else {
  15189. // unmatched surrogate; only append this code unit, in case the next
  15190. // code unit is the high surrogate of a surrogate pair
  15191. output.push(value);
  15192. counter--;
  15193. }
  15194. } else {
  15195. output.push(value);
  15196. }
  15197. }
  15198. return output;
  15199. }
  15200. /**
  15201. * Creates a string based on an array of numeric code points.
  15202. * @see `punycode.ucs2.decode`
  15203. * @memberOf punycode.ucs2
  15204. * @name encode
  15205. * @param {Array} codePoints The array of numeric code points.
  15206. * @returns {String} The new Unicode string (UCS-2).
  15207. */
  15208. function ucs2encode(array) {
  15209. return map(array, function(value) {
  15210. var output = '';
  15211. if (value > 0xFFFF) {
  15212. value -= 0x10000;
  15213. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  15214. value = 0xDC00 | value & 0x3FF;
  15215. }
  15216. output += stringFromCharCode(value);
  15217. return output;
  15218. }).join('');
  15219. }
  15220. /**
  15221. * Converts a basic code point into a digit/integer.
  15222. * @see `digitToBasic()`
  15223. * @private
  15224. * @param {Number} codePoint The basic numeric code point value.
  15225. * @returns {Number} The numeric value of a basic code point (for use in
  15226. * representing integers) in the range `0` to `base - 1`, or `base` if
  15227. * the code point does not represent a value.
  15228. */
  15229. function basicToDigit(codePoint) {
  15230. if (codePoint - 48 < 10) {
  15231. return codePoint - 22;
  15232. }
  15233. if (codePoint - 65 < 26) {
  15234. return codePoint - 65;
  15235. }
  15236. if (codePoint - 97 < 26) {
  15237. return codePoint - 97;
  15238. }
  15239. return base;
  15240. }
  15241. /**
  15242. * Converts a digit/integer into a basic code point.
  15243. * @see `basicToDigit()`
  15244. * @private
  15245. * @param {Number} digit The numeric value of a basic code point.
  15246. * @returns {Number} The basic code point whose value (when used for
  15247. * representing integers) is `digit`, which needs to be in the range
  15248. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  15249. * used; else, the lowercase form is used. The behavior is undefined
  15250. * if `flag` is non-zero and `digit` has no uppercase form.
  15251. */
  15252. function digitToBasic(digit, flag) {
  15253. // 0..25 map to ASCII a..z or A..Z
  15254. // 26..35 map to ASCII 0..9
  15255. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  15256. }
  15257. /**
  15258. * Bias adaptation function as per section 3.4 of RFC 3492.
  15259. * https://tools.ietf.org/html/rfc3492#section-3.4
  15260. * @private
  15261. */
  15262. function adapt(delta, numPoints, firstTime) {
  15263. var k = 0;
  15264. delta = firstTime ? floor(delta / damp) : delta >> 1;
  15265. delta += floor(delta / numPoints);
  15266. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  15267. delta = floor(delta / baseMinusTMin);
  15268. }
  15269. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  15270. }
  15271. /**
  15272. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  15273. * symbols.
  15274. * @memberOf punycode
  15275. * @param {String} input The Punycode string of ASCII-only symbols.
  15276. * @returns {String} The resulting string of Unicode symbols.
  15277. */
  15278. function decode(input) {
  15279. // Don't use UCS-2
  15280. var output = [],
  15281. inputLength = input.length,
  15282. out,
  15283. i = 0,
  15284. n = initialN,
  15285. bias = initialBias,
  15286. basic,
  15287. j,
  15288. index,
  15289. oldi,
  15290. w,
  15291. k,
  15292. digit,
  15293. t,
  15294. /** Cached calculation results */
  15295. baseMinusT;
  15296. // Handle the basic code points: let `basic` be the number of input code
  15297. // points before the last delimiter, or `0` if there is none, then copy
  15298. // the first basic code points to the output.
  15299. basic = input.lastIndexOf(delimiter);
  15300. if (basic < 0) {
  15301. basic = 0;
  15302. }
  15303. for (j = 0; j < basic; ++j) {
  15304. // if it's not a basic code point
  15305. if (input.charCodeAt(j) >= 0x80) {
  15306. error('not-basic');
  15307. }
  15308. output.push(input.charCodeAt(j));
  15309. }
  15310. // Main decoding loop: start just after the last delimiter if any basic code
  15311. // points were copied; start at the beginning otherwise.
  15312. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  15313. // `index` is the index of the next character to be consumed.
  15314. // Decode a generalized variable-length integer into `delta`,
  15315. // which gets added to `i`. The overflow checking is easier
  15316. // if we increase `i` as we go, then subtract off its starting
  15317. // value at the end to obtain `delta`.
  15318. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  15319. if (index >= inputLength) {
  15320. error('invalid-input');
  15321. }
  15322. digit = basicToDigit(input.charCodeAt(index++));
  15323. if (digit >= base || digit > floor((maxInt - i) / w)) {
  15324. error('overflow');
  15325. }
  15326. i += digit * w;
  15327. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  15328. if (digit < t) {
  15329. break;
  15330. }
  15331. baseMinusT = base - t;
  15332. if (w > floor(maxInt / baseMinusT)) {
  15333. error('overflow');
  15334. }
  15335. w *= baseMinusT;
  15336. }
  15337. out = output.length + 1;
  15338. bias = adapt(i - oldi, out, oldi == 0);
  15339. // `i` was supposed to wrap around from `out` to `0`,
  15340. // incrementing `n` each time, so we'll fix that now:
  15341. if (floor(i / out) > maxInt - n) {
  15342. error('overflow');
  15343. }
  15344. n += floor(i / out);
  15345. i %= out;
  15346. // Insert `n` at position `i` of the output
  15347. output.splice(i++, 0, n);
  15348. }
  15349. return ucs2encode(output);
  15350. }
  15351. /**
  15352. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  15353. * Punycode string of ASCII-only symbols.
  15354. * @memberOf punycode
  15355. * @param {String} input The string of Unicode symbols.
  15356. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  15357. */
  15358. function encode(input) {
  15359. var n,
  15360. delta,
  15361. handledCPCount,
  15362. basicLength,
  15363. bias,
  15364. j,
  15365. m,
  15366. q,
  15367. k,
  15368. t,
  15369. currentValue,
  15370. output = [],
  15371. /** `inputLength` will hold the number of code points in `input`. */
  15372. inputLength,
  15373. /** Cached calculation results */
  15374. handledCPCountPlusOne,
  15375. baseMinusT,
  15376. qMinusT;
  15377. // Convert the input in UCS-2 to Unicode
  15378. input = ucs2decode(input);
  15379. // Cache the length
  15380. inputLength = input.length;
  15381. // Initialize the state
  15382. n = initialN;
  15383. delta = 0;
  15384. bias = initialBias;
  15385. // Handle the basic code points
  15386. for (j = 0; j < inputLength; ++j) {
  15387. currentValue = input[j];
  15388. if (currentValue < 0x80) {
  15389. output.push(stringFromCharCode(currentValue));
  15390. }
  15391. }
  15392. handledCPCount = basicLength = output.length;
  15393. // `handledCPCount` is the number of code points that have been handled;
  15394. // `basicLength` is the number of basic code points.
  15395. // Finish the basic string - if it is not empty - with a delimiter
  15396. if (basicLength) {
  15397. output.push(delimiter);
  15398. }
  15399. // Main encoding loop:
  15400. while (handledCPCount < inputLength) {
  15401. // All non-basic code points < n have been handled already. Find the next
  15402. // larger one:
  15403. for (m = maxInt, j = 0; j < inputLength; ++j) {
  15404. currentValue = input[j];
  15405. if (currentValue >= n && currentValue < m) {
  15406. m = currentValue;
  15407. }
  15408. }
  15409. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  15410. // but guard against overflow
  15411. handledCPCountPlusOne = handledCPCount + 1;
  15412. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  15413. error('overflow');
  15414. }
  15415. delta += (m - n) * handledCPCountPlusOne;
  15416. n = m;
  15417. for (j = 0; j < inputLength; ++j) {
  15418. currentValue = input[j];
  15419. if (currentValue < n && ++delta > maxInt) {
  15420. error('overflow');
  15421. }
  15422. if (currentValue == n) {
  15423. // Represent delta as a generalized variable-length integer
  15424. for (q = delta, k = base; /* no condition */; k += base) {
  15425. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  15426. if (q < t) {
  15427. break;
  15428. }
  15429. qMinusT = q - t;
  15430. baseMinusT = base - t;
  15431. output.push(
  15432. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  15433. );
  15434. q = floor(qMinusT / baseMinusT);
  15435. }
  15436. output.push(stringFromCharCode(digitToBasic(q, 0)));
  15437. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  15438. delta = 0;
  15439. ++handledCPCount;
  15440. }
  15441. }
  15442. ++delta;
  15443. ++n;
  15444. }
  15445. return output.join('');
  15446. }
  15447. /**
  15448. * Converts a Punycode string representing a domain name or an email address
  15449. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  15450. * it doesn't matter if you call it on a string that has already been
  15451. * converted to Unicode.
  15452. * @memberOf punycode
  15453. * @param {String} input The Punycoded domain name or email address to
  15454. * convert to Unicode.
  15455. * @returns {String} The Unicode representation of the given Punycode
  15456. * string.
  15457. */
  15458. function toUnicode(input) {
  15459. return mapDomain(input, function(string) {
  15460. return regexPunycode.test(string)
  15461. ? decode(string.slice(4).toLowerCase())
  15462. : string;
  15463. });
  15464. }
  15465. /**
  15466. * Converts a Unicode string representing a domain name or an email address to
  15467. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  15468. * i.e. it doesn't matter if you call it with a domain that's already in
  15469. * ASCII.
  15470. * @memberOf punycode
  15471. * @param {String} input The domain name or email address to convert, as a
  15472. * Unicode string.
  15473. * @returns {String} The Punycode representation of the given domain name or
  15474. * email address.
  15475. */
  15476. function toASCII(input) {
  15477. return mapDomain(input, function(string) {
  15478. return regexNonASCII.test(string)
  15479. ? 'xn--' + encode(string)
  15480. : string;
  15481. });
  15482. }
  15483. /*--------------------------------------------------------------------------*/
  15484. /** Define the public API */
  15485. punycode = {
  15486. /**
  15487. * A string representing the current Punycode.js version number.
  15488. * @memberOf punycode
  15489. * @type String
  15490. */
  15491. 'version': '1.4.1',
  15492. /**
  15493. * An object of methods to convert from JavaScript's internal character
  15494. * representation (UCS-2) to Unicode code points, and back.
  15495. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  15496. * @memberOf punycode
  15497. * @type Object
  15498. */
  15499. 'ucs2': {
  15500. 'decode': ucs2decode,
  15501. 'encode': ucs2encode
  15502. },
  15503. 'decode': decode,
  15504. 'encode': encode,
  15505. 'toASCII': toASCII,
  15506. 'toUnicode': toUnicode
  15507. };
  15508. /** Expose `punycode` */
  15509. // Some AMD build optimizers, like r.js, check for specific condition patterns
  15510. // like the following:
  15511. if (
  15512. typeof define == 'function' &&
  15513. typeof define.amd == 'object' &&
  15514. define.amd
  15515. ) {
  15516. define('punycode', function() {
  15517. return punycode;
  15518. });
  15519. } else if (freeExports && freeModule) {
  15520. if (module.exports == freeExports) {
  15521. // in Node.js, io.js, or RingoJS v0.8.0+
  15522. freeModule.exports = punycode;
  15523. } else {
  15524. // in Narwhal or RingoJS v0.7.0-
  15525. for (key in punycode) {
  15526. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  15527. }
  15528. }
  15529. } else {
  15530. // in Rhino or a web browser
  15531. root.punycode = punycode;
  15532. }
  15533. }(this));
  15534. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  15535. },{}],114:[function(require,module,exports){
  15536. // Copyright Joyent, Inc. and other Node contributors.
  15537. //
  15538. // Permission is hereby granted, free of charge, to any person obtaining a
  15539. // copy of this software and associated documentation files (the
  15540. // "Software"), to deal in the Software without restriction, including
  15541. // without limitation the rights to use, copy, modify, merge, publish,
  15542. // distribute, sublicense, and/or sell copies of the Software, and to permit
  15543. // persons to whom the Software is furnished to do so, subject to the
  15544. // following conditions:
  15545. //
  15546. // The above copyright notice and this permission notice shall be included
  15547. // in all copies or substantial portions of the Software.
  15548. //
  15549. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15550. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15551. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  15552. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15553. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15554. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  15555. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  15556. 'use strict';
  15557. // If obj.hasOwnProperty has been overridden, then calling
  15558. // obj.hasOwnProperty(prop) will break.
  15559. // See: https://github.com/joyent/node/issues/1707
  15560. function hasOwnProperty(obj, prop) {
  15561. return Object.prototype.hasOwnProperty.call(obj, prop);
  15562. }
  15563. module.exports = function(qs, sep, eq, options) {
  15564. sep = sep || '&';
  15565. eq = eq || '=';
  15566. var obj = {};
  15567. if (typeof qs !== 'string' || qs.length === 0) {
  15568. return obj;
  15569. }
  15570. var regexp = /\+/g;
  15571. qs = qs.split(sep);
  15572. var maxKeys = 1000;
  15573. if (options && typeof options.maxKeys === 'number') {
  15574. maxKeys = options.maxKeys;
  15575. }
  15576. var len = qs.length;
  15577. // maxKeys <= 0 means that we should not limit keys count
  15578. if (maxKeys > 0 && len > maxKeys) {
  15579. len = maxKeys;
  15580. }
  15581. for (var i = 0; i < len; ++i) {
  15582. var x = qs[i].replace(regexp, '%20'),
  15583. idx = x.indexOf(eq),
  15584. kstr, vstr, k, v;
  15585. if (idx >= 0) {
  15586. kstr = x.substr(0, idx);
  15587. vstr = x.substr(idx + 1);
  15588. } else {
  15589. kstr = x;
  15590. vstr = '';
  15591. }
  15592. k = decodeURIComponent(kstr);
  15593. v = decodeURIComponent(vstr);
  15594. if (!hasOwnProperty(obj, k)) {
  15595. obj[k] = v;
  15596. } else if (isArray(obj[k])) {
  15597. obj[k].push(v);
  15598. } else {
  15599. obj[k] = [obj[k], v];
  15600. }
  15601. }
  15602. return obj;
  15603. };
  15604. var isArray = Array.isArray || function (xs) {
  15605. return Object.prototype.toString.call(xs) === '[object Array]';
  15606. };
  15607. },{}],115:[function(require,module,exports){
  15608. // Copyright Joyent, Inc. and other Node contributors.
  15609. //
  15610. // Permission is hereby granted, free of charge, to any person obtaining a
  15611. // copy of this software and associated documentation files (the
  15612. // "Software"), to deal in the Software without restriction, including
  15613. // without limitation the rights to use, copy, modify, merge, publish,
  15614. // distribute, sublicense, and/or sell copies of the Software, and to permit
  15615. // persons to whom the Software is furnished to do so, subject to the
  15616. // following conditions:
  15617. //
  15618. // The above copyright notice and this permission notice shall be included
  15619. // in all copies or substantial portions of the Software.
  15620. //
  15621. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15622. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15623. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  15624. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15625. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15626. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  15627. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  15628. 'use strict';
  15629. var stringifyPrimitive = function(v) {
  15630. switch (typeof v) {
  15631. case 'string':
  15632. return v;
  15633. case 'boolean':
  15634. return v ? 'true' : 'false';
  15635. case 'number':
  15636. return isFinite(v) ? v : '';
  15637. default:
  15638. return '';
  15639. }
  15640. };
  15641. module.exports = function(obj, sep, eq, name) {
  15642. sep = sep || '&';
  15643. eq = eq || '=';
  15644. if (obj === null) {
  15645. obj = undefined;
  15646. }
  15647. if (typeof obj === 'object') {
  15648. return map(objectKeys(obj), function(k) {
  15649. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  15650. if (isArray(obj[k])) {
  15651. return map(obj[k], function(v) {
  15652. return ks + encodeURIComponent(stringifyPrimitive(v));
  15653. }).join(sep);
  15654. } else {
  15655. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  15656. }
  15657. }).join(sep);
  15658. }
  15659. if (!name) return '';
  15660. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  15661. encodeURIComponent(stringifyPrimitive(obj));
  15662. };
  15663. var isArray = Array.isArray || function (xs) {
  15664. return Object.prototype.toString.call(xs) === '[object Array]';
  15665. };
  15666. function map (xs, f) {
  15667. if (xs.map) return xs.map(f);
  15668. var res = [];
  15669. for (var i = 0; i < xs.length; i++) {
  15670. res.push(f(xs[i], i));
  15671. }
  15672. return res;
  15673. }
  15674. var objectKeys = Object.keys || function (obj) {
  15675. var res = [];
  15676. for (var key in obj) {
  15677. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  15678. }
  15679. return res;
  15680. };
  15681. },{}],116:[function(require,module,exports){
  15682. 'use strict';
  15683. exports.decode = exports.parse = require('./decode');
  15684. exports.encode = exports.stringify = require('./encode');
  15685. },{"./decode":114,"./encode":115}],117:[function(require,module,exports){
  15686. (function (process,global,Buffer){
  15687. 'use strict'
  15688. function oldBrowser () {
  15689. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
  15690. }
  15691. var crypto = global.crypto || global.msCrypto
  15692. if (crypto && crypto.getRandomValues) {
  15693. module.exports = randomBytes
  15694. } else {
  15695. module.exports = oldBrowser
  15696. }
  15697. function randomBytes (size, cb) {
  15698. // phantomjs needs to throw
  15699. if (size > 65536) throw new Error('requested too many random bytes')
  15700. // in case browserify isn't using the Uint8Array version
  15701. var rawBytes = new global.Uint8Array(size)
  15702. // This will not work in older browsers.
  15703. // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  15704. if (size > 0) { // getRandomValues fails on IE if size == 0
  15705. crypto.getRandomValues(rawBytes)
  15706. }
  15707. // phantomjs doesn't like a buffer being passed here
  15708. var bytes = new Buffer(rawBytes.buffer)
  15709. if (typeof cb === 'function') {
  15710. return process.nextTick(function () {
  15711. cb(null, bytes)
  15712. })
  15713. }
  15714. return bytes
  15715. }
  15716. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
  15717. },{"_process":106,"buffer":46}],118:[function(require,module,exports){
  15718. module.exports = require("./lib/_stream_duplex.js")
  15719. },{"./lib/_stream_duplex.js":119}],119:[function(require,module,exports){
  15720. // a duplex stream is just a stream that is both readable and writable.
  15721. // Since JS doesn't have multiple prototypal inheritance, this class
  15722. // prototypally inherits from Readable, and then parasitically from
  15723. // Writable.
  15724. 'use strict';
  15725. /*<replacement>*/
  15726. var objectKeys = Object.keys || function (obj) {
  15727. var keys = [];
  15728. for (var key in obj) {
  15729. keys.push(key);
  15730. }return keys;
  15731. };
  15732. /*</replacement>*/
  15733. module.exports = Duplex;
  15734. /*<replacement>*/
  15735. var processNextTick = require('process-nextick-args');
  15736. /*</replacement>*/
  15737. /*<replacement>*/
  15738. var util = require('core-util-is');
  15739. util.inherits = require('inherits');
  15740. /*</replacement>*/
  15741. var Readable = require('./_stream_readable');
  15742. var Writable = require('./_stream_writable');
  15743. util.inherits(Duplex, Readable);
  15744. var keys = objectKeys(Writable.prototype);
  15745. for (var v = 0; v < keys.length; v++) {
  15746. var method = keys[v];
  15747. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  15748. }
  15749. function Duplex(options) {
  15750. if (!(this instanceof Duplex)) return new Duplex(options);
  15751. Readable.call(this, options);
  15752. Writable.call(this, options);
  15753. if (options && options.readable === false) this.readable = false;
  15754. if (options && options.writable === false) this.writable = false;
  15755. this.allowHalfOpen = true;
  15756. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  15757. this.once('end', onend);
  15758. }
  15759. // the no-half-open enforcer
  15760. function onend() {
  15761. // if we allow half-open state, or if the writable side ended,
  15762. // then we're ok.
  15763. if (this.allowHalfOpen || this._writableState.ended) return;
  15764. // no more data can be written.
  15765. // But allow more writes to happen in this tick.
  15766. processNextTick(onEndNT, this);
  15767. }
  15768. function onEndNT(self) {
  15769. self.end();
  15770. }
  15771. function forEach(xs, f) {
  15772. for (var i = 0, l = xs.length; i < l; i++) {
  15773. f(xs[i], i);
  15774. }
  15775. }
  15776. },{"./_stream_readable":121,"./_stream_writable":123,"core-util-is":48,"inherits":92,"process-nextick-args":105}],120:[function(require,module,exports){
  15777. // a passthrough stream.
  15778. // basically just the most minimal sort of Transform stream.
  15779. // Every written chunk gets output as-is.
  15780. 'use strict';
  15781. module.exports = PassThrough;
  15782. var Transform = require('./_stream_transform');
  15783. /*<replacement>*/
  15784. var util = require('core-util-is');
  15785. util.inherits = require('inherits');
  15786. /*</replacement>*/
  15787. util.inherits(PassThrough, Transform);
  15788. function PassThrough(options) {
  15789. if (!(this instanceof PassThrough)) return new PassThrough(options);
  15790. Transform.call(this, options);
  15791. }
  15792. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  15793. cb(null, chunk);
  15794. };
  15795. },{"./_stream_transform":122,"core-util-is":48,"inherits":92}],121:[function(require,module,exports){
  15796. (function (process){
  15797. 'use strict';
  15798. module.exports = Readable;
  15799. /*<replacement>*/
  15800. var processNextTick = require('process-nextick-args');
  15801. /*</replacement>*/
  15802. /*<replacement>*/
  15803. var isArray = require('isarray');
  15804. /*</replacement>*/
  15805. /*<replacement>*/
  15806. var Buffer = require('buffer').Buffer;
  15807. /*</replacement>*/
  15808. Readable.ReadableState = ReadableState;
  15809. var EE = require('events');
  15810. /*<replacement>*/
  15811. var EElistenerCount = function (emitter, type) {
  15812. return emitter.listeners(type).length;
  15813. };
  15814. /*</replacement>*/
  15815. /*<replacement>*/
  15816. var Stream;
  15817. (function () {
  15818. try {
  15819. Stream = require('st' + 'ream');
  15820. } catch (_) {} finally {
  15821. if (!Stream) Stream = require('events').EventEmitter;
  15822. }
  15823. })();
  15824. /*</replacement>*/
  15825. var Buffer = require('buffer').Buffer;
  15826. /*<replacement>*/
  15827. var util = require('core-util-is');
  15828. util.inherits = require('inherits');
  15829. /*</replacement>*/
  15830. /*<replacement>*/
  15831. var debugUtil = require('util');
  15832. var debug = undefined;
  15833. if (debugUtil && debugUtil.debuglog) {
  15834. debug = debugUtil.debuglog('stream');
  15835. } else {
  15836. debug = function () {};
  15837. }
  15838. /*</replacement>*/
  15839. var StringDecoder;
  15840. util.inherits(Readable, Stream);
  15841. var Duplex;
  15842. function ReadableState(options, stream) {
  15843. Duplex = Duplex || require('./_stream_duplex');
  15844. options = options || {};
  15845. // object stream flag. Used to make read(n) ignore n and to
  15846. // make all the buffer merging and length checks go away
  15847. this.objectMode = !!options.objectMode;
  15848. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  15849. // the point at which it stops calling _read() to fill the buffer
  15850. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  15851. var hwm = options.highWaterMark;
  15852. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  15853. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  15854. // cast to ints.
  15855. this.highWaterMark = ~ ~this.highWaterMark;
  15856. this.buffer = [];
  15857. this.length = 0;
  15858. this.pipes = null;
  15859. this.pipesCount = 0;
  15860. this.flowing = null;
  15861. this.ended = false;
  15862. this.endEmitted = false;
  15863. this.reading = false;
  15864. // a flag to be able to tell if the onwrite cb is called immediately,
  15865. // or on a later tick. We set this to true at first, because any
  15866. // actions that shouldn't happen until "later" should generally also
  15867. // not happen before the first write call.
  15868. this.sync = true;
  15869. // whenever we return null, then we set a flag to say
  15870. // that we're awaiting a 'readable' event emission.
  15871. this.needReadable = false;
  15872. this.emittedReadable = false;
  15873. this.readableListening = false;
  15874. this.resumeScheduled = false;
  15875. // Crypto is kind of old and crusty. Historically, its default string
  15876. // encoding is 'binary' so we have to make this configurable.
  15877. // Everything else in the universe uses 'utf8', though.
  15878. this.defaultEncoding = options.defaultEncoding || 'utf8';
  15879. // when piping, we only care about 'readable' events that happen
  15880. // after read()ing all the bytes and not getting any pushback.
  15881. this.ranOut = false;
  15882. // the number of writers that are awaiting a drain event in .pipe()s
  15883. this.awaitDrain = 0;
  15884. // if true, a maybeReadMore has been scheduled
  15885. this.readingMore = false;
  15886. this.decoder = null;
  15887. this.encoding = null;
  15888. if (options.encoding) {
  15889. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  15890. this.decoder = new StringDecoder(options.encoding);
  15891. this.encoding = options.encoding;
  15892. }
  15893. }
  15894. var Duplex;
  15895. function Readable(options) {
  15896. Duplex = Duplex || require('./_stream_duplex');
  15897. if (!(this instanceof Readable)) return new Readable(options);
  15898. this._readableState = new ReadableState(options, this);
  15899. // legacy
  15900. this.readable = true;
  15901. if (options && typeof options.read === 'function') this._read = options.read;
  15902. Stream.call(this);
  15903. }
  15904. // Manually shove something into the read() buffer.
  15905. // This returns true if the highWaterMark has not been hit yet,
  15906. // similar to how Writable.write() returns true if you should
  15907. // write() some more.
  15908. Readable.prototype.push = function (chunk, encoding) {
  15909. var state = this._readableState;
  15910. if (!state.objectMode && typeof chunk === 'string') {
  15911. encoding = encoding || state.defaultEncoding;
  15912. if (encoding !== state.encoding) {
  15913. chunk = new Buffer(chunk, encoding);
  15914. encoding = '';
  15915. }
  15916. }
  15917. return readableAddChunk(this, state, chunk, encoding, false);
  15918. };
  15919. // Unshift should *always* be something directly out of read()
  15920. Readable.prototype.unshift = function (chunk) {
  15921. var state = this._readableState;
  15922. return readableAddChunk(this, state, chunk, '', true);
  15923. };
  15924. Readable.prototype.isPaused = function () {
  15925. return this._readableState.flowing === false;
  15926. };
  15927. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  15928. var er = chunkInvalid(state, chunk);
  15929. if (er) {
  15930. stream.emit('error', er);
  15931. } else if (chunk === null) {
  15932. state.reading = false;
  15933. onEofChunk(stream, state);
  15934. } else if (state.objectMode || chunk && chunk.length > 0) {
  15935. if (state.ended && !addToFront) {
  15936. var e = new Error('stream.push() after EOF');
  15937. stream.emit('error', e);
  15938. } else if (state.endEmitted && addToFront) {
  15939. var e = new Error('stream.unshift() after end event');
  15940. stream.emit('error', e);
  15941. } else {
  15942. var skipAdd;
  15943. if (state.decoder && !addToFront && !encoding) {
  15944. chunk = state.decoder.write(chunk);
  15945. skipAdd = !state.objectMode && chunk.length === 0;
  15946. }
  15947. if (!addToFront) state.reading = false;
  15948. // Don't add to the buffer if we've decoded to an empty string chunk and
  15949. // we're not in object mode
  15950. if (!skipAdd) {
  15951. // if we want the data now, just emit it.
  15952. if (state.flowing && state.length === 0 && !state.sync) {
  15953. stream.emit('data', chunk);
  15954. stream.read(0);
  15955. } else {
  15956. // update the buffer info.
  15957. state.length += state.objectMode ? 1 : chunk.length;
  15958. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  15959. if (state.needReadable) emitReadable(stream);
  15960. }
  15961. }
  15962. maybeReadMore(stream, state);
  15963. }
  15964. } else if (!addToFront) {
  15965. state.reading = false;
  15966. }
  15967. return needMoreData(state);
  15968. }
  15969. // if it's past the high water mark, we can push in some more.
  15970. // Also, if we have no data yet, we can stand some
  15971. // more bytes. This is to work around cases where hwm=0,
  15972. // such as the repl. Also, if the push() triggered a
  15973. // readable event, and the user called read(largeNumber) such that
  15974. // needReadable was set, then we ought to push more, so that another
  15975. // 'readable' event will be triggered.
  15976. function needMoreData(state) {
  15977. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  15978. }
  15979. // backwards compatibility.
  15980. Readable.prototype.setEncoding = function (enc) {
  15981. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  15982. this._readableState.decoder = new StringDecoder(enc);
  15983. this._readableState.encoding = enc;
  15984. return this;
  15985. };
  15986. // Don't raise the hwm > 8MB
  15987. var MAX_HWM = 0x800000;
  15988. function computeNewHighWaterMark(n) {
  15989. if (n >= MAX_HWM) {
  15990. n = MAX_HWM;
  15991. } else {
  15992. // Get the next highest power of 2
  15993. n--;
  15994. n |= n >>> 1;
  15995. n |= n >>> 2;
  15996. n |= n >>> 4;
  15997. n |= n >>> 8;
  15998. n |= n >>> 16;
  15999. n++;
  16000. }
  16001. return n;
  16002. }
  16003. function howMuchToRead(n, state) {
  16004. if (state.length === 0 && state.ended) return 0;
  16005. if (state.objectMode) return n === 0 ? 0 : 1;
  16006. if (n === null || isNaN(n)) {
  16007. // only flow one buffer at a time
  16008. if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length;
  16009. }
  16010. if (n <= 0) return 0;
  16011. // If we're asking for more than the target buffer level,
  16012. // then raise the water mark. Bump up to the next highest
  16013. // power of 2, to prevent increasing it excessively in tiny
  16014. // amounts.
  16015. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  16016. // don't have that much. return null, unless we've ended.
  16017. if (n > state.length) {
  16018. if (!state.ended) {
  16019. state.needReadable = true;
  16020. return 0;
  16021. } else {
  16022. return state.length;
  16023. }
  16024. }
  16025. return n;
  16026. }
  16027. // you can override either this method, or the async _read(n) below.
  16028. Readable.prototype.read = function (n) {
  16029. debug('read', n);
  16030. var state = this._readableState;
  16031. var nOrig = n;
  16032. if (typeof n !== 'number' || n > 0) state.emittedReadable = false;
  16033. // if we're doing read(0) to trigger a readable event, but we
  16034. // already have a bunch of data in the buffer, then just trigger
  16035. // the 'readable' event and move on.
  16036. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  16037. debug('read: emitReadable', state.length, state.ended);
  16038. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  16039. return null;
  16040. }
  16041. n = howMuchToRead(n, state);
  16042. // if we've ended, and we're now clear, then finish it up.
  16043. if (n === 0 && state.ended) {
  16044. if (state.length === 0) endReadable(this);
  16045. return null;
  16046. }
  16047. // All the actual chunk generation logic needs to be
  16048. // *below* the call to _read. The reason is that in certain
  16049. // synthetic stream cases, such as passthrough streams, _read
  16050. // may be a completely synchronous operation which may change
  16051. // the state of the read buffer, providing enough data when
  16052. // before there was *not* enough.
  16053. //
  16054. // So, the steps are:
  16055. // 1. Figure out what the state of things will be after we do
  16056. // a read from the buffer.
  16057. //
  16058. // 2. If that resulting state will trigger a _read, then call _read.
  16059. // Note that this may be asynchronous, or synchronous. Yes, it is
  16060. // deeply ugly to write APIs this way, but that still doesn't mean
  16061. // that the Readable class should behave improperly, as streams are
  16062. // designed to be sync/async agnostic.
  16063. // Take note if the _read call is sync or async (ie, if the read call
  16064. // has returned yet), so that we know whether or not it's safe to emit
  16065. // 'readable' etc.
  16066. //
  16067. // 3. Actually pull the requested chunks out of the buffer and return.
  16068. // if we need a readable event, then we need to do some reading.
  16069. var doRead = state.needReadable;
  16070. debug('need readable', doRead);
  16071. // if we currently have less than the highWaterMark, then also read some
  16072. if (state.length === 0 || state.length - n < state.highWaterMark) {
  16073. doRead = true;
  16074. debug('length less than watermark', doRead);
  16075. }
  16076. // however, if we've ended, then there's no point, and if we're already
  16077. // reading, then it's unnecessary.
  16078. if (state.ended || state.reading) {
  16079. doRead = false;
  16080. debug('reading or ended', doRead);
  16081. }
  16082. if (doRead) {
  16083. debug('do read');
  16084. state.reading = true;
  16085. state.sync = true;
  16086. // if the length is currently zero, then we *need* a readable event.
  16087. if (state.length === 0) state.needReadable = true;
  16088. // call internal read method
  16089. this._read(state.highWaterMark);
  16090. state.sync = false;
  16091. }
  16092. // If _read pushed data synchronously, then `reading` will be false,
  16093. // and we need to re-evaluate how much data we can return to the user.
  16094. if (doRead && !state.reading) n = howMuchToRead(nOrig, state);
  16095. var ret;
  16096. if (n > 0) ret = fromList(n, state);else ret = null;
  16097. if (ret === null) {
  16098. state.needReadable = true;
  16099. n = 0;
  16100. }
  16101. state.length -= n;
  16102. // If we have nothing in the buffer, then we want to know
  16103. // as soon as we *do* get something into the buffer.
  16104. if (state.length === 0 && !state.ended) state.needReadable = true;
  16105. // If we tried to read() past the EOF, then emit end on the next tick.
  16106. if (nOrig !== n && state.ended && state.length === 0) endReadable(this);
  16107. if (ret !== null) this.emit('data', ret);
  16108. return ret;
  16109. };
  16110. function chunkInvalid(state, chunk) {
  16111. var er = null;
  16112. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  16113. er = new TypeError('Invalid non-string/buffer chunk');
  16114. }
  16115. return er;
  16116. }
  16117. function onEofChunk(stream, state) {
  16118. if (state.ended) return;
  16119. if (state.decoder) {
  16120. var chunk = state.decoder.end();
  16121. if (chunk && chunk.length) {
  16122. state.buffer.push(chunk);
  16123. state.length += state.objectMode ? 1 : chunk.length;
  16124. }
  16125. }
  16126. state.ended = true;
  16127. // emit 'readable' now to make sure it gets picked up.
  16128. emitReadable(stream);
  16129. }
  16130. // Don't emit readable right away in sync mode, because this can trigger
  16131. // another read() call => stack overflow. This way, it might trigger
  16132. // a nextTick recursion warning, but that's not so bad.
  16133. function emitReadable(stream) {
  16134. var state = stream._readableState;
  16135. state.needReadable = false;
  16136. if (!state.emittedReadable) {
  16137. debug('emitReadable', state.flowing);
  16138. state.emittedReadable = true;
  16139. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  16140. }
  16141. }
  16142. function emitReadable_(stream) {
  16143. debug('emit readable');
  16144. stream.emit('readable');
  16145. flow(stream);
  16146. }
  16147. // at this point, the user has presumably seen the 'readable' event,
  16148. // and called read() to consume some data. that may have triggered
  16149. // in turn another _read(n) call, in which case reading = true if
  16150. // it's in progress.
  16151. // However, if we're not ended, or reading, and the length < hwm,
  16152. // then go ahead and try to read some more preemptively.
  16153. function maybeReadMore(stream, state) {
  16154. if (!state.readingMore) {
  16155. state.readingMore = true;
  16156. processNextTick(maybeReadMore_, stream, state);
  16157. }
  16158. }
  16159. function maybeReadMore_(stream, state) {
  16160. var len = state.length;
  16161. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  16162. debug('maybeReadMore read 0');
  16163. stream.read(0);
  16164. if (len === state.length)
  16165. // didn't get any data, stop spinning.
  16166. break;else len = state.length;
  16167. }
  16168. state.readingMore = false;
  16169. }
  16170. // abstract method. to be overridden in specific implementation classes.
  16171. // call cb(er, data) where data is <= n in length.
  16172. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  16173. // arbitrary, and perhaps not very meaningful.
  16174. Readable.prototype._read = function (n) {
  16175. this.emit('error', new Error('not implemented'));
  16176. };
  16177. Readable.prototype.pipe = function (dest, pipeOpts) {
  16178. var src = this;
  16179. var state = this._readableState;
  16180. switch (state.pipesCount) {
  16181. case 0:
  16182. state.pipes = dest;
  16183. break;
  16184. case 1:
  16185. state.pipes = [state.pipes, dest];
  16186. break;
  16187. default:
  16188. state.pipes.push(dest);
  16189. break;
  16190. }
  16191. state.pipesCount += 1;
  16192. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  16193. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  16194. var endFn = doEnd ? onend : cleanup;
  16195. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  16196. dest.on('unpipe', onunpipe);
  16197. function onunpipe(readable) {
  16198. debug('onunpipe');
  16199. if (readable === src) {
  16200. cleanup();
  16201. }
  16202. }
  16203. function onend() {
  16204. debug('onend');
  16205. dest.end();
  16206. }
  16207. // when the dest drains, it reduces the awaitDrain counter
  16208. // on the source. This would be more elegant with a .once()
  16209. // handler in flow(), but adding and removing repeatedly is
  16210. // too slow.
  16211. var ondrain = pipeOnDrain(src);
  16212. dest.on('drain', ondrain);
  16213. var cleanedUp = false;
  16214. function cleanup() {
  16215. debug('cleanup');
  16216. // cleanup event handlers once the pipe is broken
  16217. dest.removeListener('close', onclose);
  16218. dest.removeListener('finish', onfinish);
  16219. dest.removeListener('drain', ondrain);
  16220. dest.removeListener('error', onerror);
  16221. dest.removeListener('unpipe', onunpipe);
  16222. src.removeListener('end', onend);
  16223. src.removeListener('end', cleanup);
  16224. src.removeListener('data', ondata);
  16225. cleanedUp = true;
  16226. // if the reader is waiting for a drain event from this
  16227. // specific writer, then it would cause it to never start
  16228. // flowing again.
  16229. // So, if this is awaiting a drain, then we just call it now.
  16230. // If we don't know, then assume that we are waiting for one.
  16231. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  16232. }
  16233. src.on('data', ondata);
  16234. function ondata(chunk) {
  16235. debug('ondata');
  16236. var ret = dest.write(chunk);
  16237. if (false === ret) {
  16238. // If the user unpiped during `dest.write()`, it is possible
  16239. // to get stuck in a permanently paused state if that write
  16240. // also returned false.
  16241. if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) {
  16242. debug('false write response, pause', src._readableState.awaitDrain);
  16243. src._readableState.awaitDrain++;
  16244. }
  16245. src.pause();
  16246. }
  16247. }
  16248. // if the dest has an error, then stop piping into it.
  16249. // however, don't suppress the throwing behavior for this.
  16250. function onerror(er) {
  16251. debug('onerror', er);
  16252. unpipe();
  16253. dest.removeListener('error', onerror);
  16254. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  16255. }
  16256. // This is a brutally ugly hack to make sure that our error handler
  16257. // is attached before any userland ones. NEVER DO THIS.
  16258. if (!dest._events || !dest._events.error) dest.on('error', onerror);else if (isArray(dest._events.error)) dest._events.error.unshift(onerror);else dest._events.error = [onerror, dest._events.error];
  16259. // Both close and finish should trigger unpipe, but only once.
  16260. function onclose() {
  16261. dest.removeListener('finish', onfinish);
  16262. unpipe();
  16263. }
  16264. dest.once('close', onclose);
  16265. function onfinish() {
  16266. debug('onfinish');
  16267. dest.removeListener('close', onclose);
  16268. unpipe();
  16269. }
  16270. dest.once('finish', onfinish);
  16271. function unpipe() {
  16272. debug('unpipe');
  16273. src.unpipe(dest);
  16274. }
  16275. // tell the dest that it's being piped to
  16276. dest.emit('pipe', src);
  16277. // start the flow if it hasn't been started already.
  16278. if (!state.flowing) {
  16279. debug('pipe resume');
  16280. src.resume();
  16281. }
  16282. return dest;
  16283. };
  16284. function pipeOnDrain(src) {
  16285. return function () {
  16286. var state = src._readableState;
  16287. debug('pipeOnDrain', state.awaitDrain);
  16288. if (state.awaitDrain) state.awaitDrain--;
  16289. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  16290. state.flowing = true;
  16291. flow(src);
  16292. }
  16293. };
  16294. }
  16295. Readable.prototype.unpipe = function (dest) {
  16296. var state = this._readableState;
  16297. // if we're not piping anywhere, then do nothing.
  16298. if (state.pipesCount === 0) return this;
  16299. // just one destination. most common case.
  16300. if (state.pipesCount === 1) {
  16301. // passed in one, but it's not the right one.
  16302. if (dest && dest !== state.pipes) return this;
  16303. if (!dest) dest = state.pipes;
  16304. // got a match.
  16305. state.pipes = null;
  16306. state.pipesCount = 0;
  16307. state.flowing = false;
  16308. if (dest) dest.emit('unpipe', this);
  16309. return this;
  16310. }
  16311. // slow case. multiple pipe destinations.
  16312. if (!dest) {
  16313. // remove all.
  16314. var dests = state.pipes;
  16315. var len = state.pipesCount;
  16316. state.pipes = null;
  16317. state.pipesCount = 0;
  16318. state.flowing = false;
  16319. for (var _i = 0; _i < len; _i++) {
  16320. dests[_i].emit('unpipe', this);
  16321. }return this;
  16322. }
  16323. // try to find the right one.
  16324. var i = indexOf(state.pipes, dest);
  16325. if (i === -1) return this;
  16326. state.pipes.splice(i, 1);
  16327. state.pipesCount -= 1;
  16328. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  16329. dest.emit('unpipe', this);
  16330. return this;
  16331. };
  16332. // set up data events if they are asked for
  16333. // Ensure readable listeners eventually get something
  16334. Readable.prototype.on = function (ev, fn) {
  16335. var res = Stream.prototype.on.call(this, ev, fn);
  16336. // If listening to data, and it has not explicitly been paused,
  16337. // then call resume to start the flow of data on the next tick.
  16338. if (ev === 'data' && false !== this._readableState.flowing) {
  16339. this.resume();
  16340. }
  16341. if (ev === 'readable' && !this._readableState.endEmitted) {
  16342. var state = this._readableState;
  16343. if (!state.readableListening) {
  16344. state.readableListening = true;
  16345. state.emittedReadable = false;
  16346. state.needReadable = true;
  16347. if (!state.reading) {
  16348. processNextTick(nReadingNextTick, this);
  16349. } else if (state.length) {
  16350. emitReadable(this, state);
  16351. }
  16352. }
  16353. }
  16354. return res;
  16355. };
  16356. Readable.prototype.addListener = Readable.prototype.on;
  16357. function nReadingNextTick(self) {
  16358. debug('readable nexttick read 0');
  16359. self.read(0);
  16360. }
  16361. // pause() and resume() are remnants of the legacy readable stream API
  16362. // If the user uses them, then switch into old mode.
  16363. Readable.prototype.resume = function () {
  16364. var state = this._readableState;
  16365. if (!state.flowing) {
  16366. debug('resume');
  16367. state.flowing = true;
  16368. resume(this, state);
  16369. }
  16370. return this;
  16371. };
  16372. function resume(stream, state) {
  16373. if (!state.resumeScheduled) {
  16374. state.resumeScheduled = true;
  16375. processNextTick(resume_, stream, state);
  16376. }
  16377. }
  16378. function resume_(stream, state) {
  16379. if (!state.reading) {
  16380. debug('resume read 0');
  16381. stream.read(0);
  16382. }
  16383. state.resumeScheduled = false;
  16384. stream.emit('resume');
  16385. flow(stream);
  16386. if (state.flowing && !state.reading) stream.read(0);
  16387. }
  16388. Readable.prototype.pause = function () {
  16389. debug('call pause flowing=%j', this._readableState.flowing);
  16390. if (false !== this._readableState.flowing) {
  16391. debug('pause');
  16392. this._readableState.flowing = false;
  16393. this.emit('pause');
  16394. }
  16395. return this;
  16396. };
  16397. function flow(stream) {
  16398. var state = stream._readableState;
  16399. debug('flow', state.flowing);
  16400. if (state.flowing) {
  16401. do {
  16402. var chunk = stream.read();
  16403. } while (null !== chunk && state.flowing);
  16404. }
  16405. }
  16406. // wrap an old-style stream as the async data source.
  16407. // This is *not* part of the readable stream interface.
  16408. // It is an ugly unfortunate mess of history.
  16409. Readable.prototype.wrap = function (stream) {
  16410. var state = this._readableState;
  16411. var paused = false;
  16412. var self = this;
  16413. stream.on('end', function () {
  16414. debug('wrapped end');
  16415. if (state.decoder && !state.ended) {
  16416. var chunk = state.decoder.end();
  16417. if (chunk && chunk.length) self.push(chunk);
  16418. }
  16419. self.push(null);
  16420. });
  16421. stream.on('data', function (chunk) {
  16422. debug('wrapped data');
  16423. if (state.decoder) chunk = state.decoder.write(chunk);
  16424. // don't skip over falsy values in objectMode
  16425. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  16426. var ret = self.push(chunk);
  16427. if (!ret) {
  16428. paused = true;
  16429. stream.pause();
  16430. }
  16431. });
  16432. // proxy all the other methods.
  16433. // important when wrapping filters and duplexes.
  16434. for (var i in stream) {
  16435. if (this[i] === undefined && typeof stream[i] === 'function') {
  16436. this[i] = function (method) {
  16437. return function () {
  16438. return stream[method].apply(stream, arguments);
  16439. };
  16440. }(i);
  16441. }
  16442. }
  16443. // proxy certain important events.
  16444. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  16445. forEach(events, function (ev) {
  16446. stream.on(ev, self.emit.bind(self, ev));
  16447. });
  16448. // when we try to consume some more bytes, simply unpause the
  16449. // underlying stream.
  16450. self._read = function (n) {
  16451. debug('wrapped _read', n);
  16452. if (paused) {
  16453. paused = false;
  16454. stream.resume();
  16455. }
  16456. };
  16457. return self;
  16458. };
  16459. // exposed for testing purposes only.
  16460. Readable._fromList = fromList;
  16461. // Pluck off n bytes from an array of buffers.
  16462. // Length is the combined lengths of all the buffers in the list.
  16463. function fromList(n, state) {
  16464. var list = state.buffer;
  16465. var length = state.length;
  16466. var stringMode = !!state.decoder;
  16467. var objectMode = !!state.objectMode;
  16468. var ret;
  16469. // nothing in the list, definitely empty.
  16470. if (list.length === 0) return null;
  16471. if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) {
  16472. // read it all, truncate the array.
  16473. if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length);
  16474. list.length = 0;
  16475. } else {
  16476. // read just some of it.
  16477. if (n < list[0].length) {
  16478. // just take a part of the first list item.
  16479. // slice is the same for buffers and strings.
  16480. var buf = list[0];
  16481. ret = buf.slice(0, n);
  16482. list[0] = buf.slice(n);
  16483. } else if (n === list[0].length) {
  16484. // first list is a perfect match
  16485. ret = list.shift();
  16486. } else {
  16487. // complex case.
  16488. // we have enough to cover it, but it spans past the first buffer.
  16489. if (stringMode) ret = '';else ret = new Buffer(n);
  16490. var c = 0;
  16491. for (var i = 0, l = list.length; i < l && c < n; i++) {
  16492. var buf = list[0];
  16493. var cpy = Math.min(n - c, buf.length);
  16494. if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy);
  16495. if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift();
  16496. c += cpy;
  16497. }
  16498. }
  16499. }
  16500. return ret;
  16501. }
  16502. function endReadable(stream) {
  16503. var state = stream._readableState;
  16504. // If we get here before consuming all the bytes, then that is a
  16505. // bug in node. Should never happen.
  16506. if (state.length > 0) throw new Error('endReadable called on non-empty stream');
  16507. if (!state.endEmitted) {
  16508. state.ended = true;
  16509. processNextTick(endReadableNT, state, stream);
  16510. }
  16511. }
  16512. function endReadableNT(state, stream) {
  16513. // Check that we didn't get one last unshift.
  16514. if (!state.endEmitted && state.length === 0) {
  16515. state.endEmitted = true;
  16516. stream.readable = false;
  16517. stream.emit('end');
  16518. }
  16519. }
  16520. function forEach(xs, f) {
  16521. for (var i = 0, l = xs.length; i < l; i++) {
  16522. f(xs[i], i);
  16523. }
  16524. }
  16525. function indexOf(xs, x) {
  16526. for (var i = 0, l = xs.length; i < l; i++) {
  16527. if (xs[i] === x) return i;
  16528. }
  16529. return -1;
  16530. }
  16531. }).call(this,require('_process'))
  16532. },{"./_stream_duplex":119,"_process":106,"buffer":46,"core-util-is":48,"events":82,"inherits":92,"isarray":94,"process-nextick-args":105,"string_decoder/":138,"util":20}],122:[function(require,module,exports){
  16533. // a transform stream is a readable/writable stream where you do
  16534. // something with the data. Sometimes it's called a "filter",
  16535. // but that's not a great name for it, since that implies a thing where
  16536. // some bits pass through, and others are simply ignored. (That would
  16537. // be a valid example of a transform, of course.)
  16538. //
  16539. // While the output is causally related to the input, it's not a
  16540. // necessarily symmetric or synchronous transformation. For example,
  16541. // a zlib stream might take multiple plain-text writes(), and then
  16542. // emit a single compressed chunk some time in the future.
  16543. //
  16544. // Here's how this works:
  16545. //
  16546. // The Transform stream has all the aspects of the readable and writable
  16547. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  16548. // internally, and returns false if there's a lot of pending writes
  16549. // buffered up. When you call read(), that calls _read(n) until
  16550. // there's enough pending readable data buffered up.
  16551. //
  16552. // In a transform stream, the written data is placed in a buffer. When
  16553. // _read(n) is called, it transforms the queued up data, calling the
  16554. // buffered _write cb's as it consumes chunks. If consuming a single
  16555. // written chunk would result in multiple output chunks, then the first
  16556. // outputted bit calls the readcb, and subsequent chunks just go into
  16557. // the read buffer, and will cause it to emit 'readable' if necessary.
  16558. //
  16559. // This way, back-pressure is actually determined by the reading side,
  16560. // since _read has to be called to start processing a new chunk. However,
  16561. // a pathological inflate type of transform can cause excessive buffering
  16562. // here. For example, imagine a stream where every byte of input is
  16563. // interpreted as an integer from 0-255, and then results in that many
  16564. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  16565. // 1kb of data being output. In this case, you could write a very small
  16566. // amount of input, and end up with a very large amount of output. In
  16567. // such a pathological inflating mechanism, there'd be no way to tell
  16568. // the system to stop doing the transform. A single 4MB write could
  16569. // cause the system to run out of memory.
  16570. //
  16571. // However, even in such a pathological case, only a single written chunk
  16572. // would be consumed, and then the rest would wait (un-transformed) until
  16573. // the results of the previous transformed chunk were consumed.
  16574. 'use strict';
  16575. module.exports = Transform;
  16576. var Duplex = require('./_stream_duplex');
  16577. /*<replacement>*/
  16578. var util = require('core-util-is');
  16579. util.inherits = require('inherits');
  16580. /*</replacement>*/
  16581. util.inherits(Transform, Duplex);
  16582. function TransformState(stream) {
  16583. this.afterTransform = function (er, data) {
  16584. return afterTransform(stream, er, data);
  16585. };
  16586. this.needTransform = false;
  16587. this.transforming = false;
  16588. this.writecb = null;
  16589. this.writechunk = null;
  16590. this.writeencoding = null;
  16591. }
  16592. function afterTransform(stream, er, data) {
  16593. var ts = stream._transformState;
  16594. ts.transforming = false;
  16595. var cb = ts.writecb;
  16596. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  16597. ts.writechunk = null;
  16598. ts.writecb = null;
  16599. if (data !== null && data !== undefined) stream.push(data);
  16600. cb(er);
  16601. var rs = stream._readableState;
  16602. rs.reading = false;
  16603. if (rs.needReadable || rs.length < rs.highWaterMark) {
  16604. stream._read(rs.highWaterMark);
  16605. }
  16606. }
  16607. function Transform(options) {
  16608. if (!(this instanceof Transform)) return new Transform(options);
  16609. Duplex.call(this, options);
  16610. this._transformState = new TransformState(this);
  16611. // when the writable side finishes, then flush out anything remaining.
  16612. var stream = this;
  16613. // start out asking for a readable event once data is transformed.
  16614. this._readableState.needReadable = true;
  16615. // we have implemented the _read method, and done the other things
  16616. // that Readable wants before the first _read call, so unset the
  16617. // sync guard flag.
  16618. this._readableState.sync = false;
  16619. if (options) {
  16620. if (typeof options.transform === 'function') this._transform = options.transform;
  16621. if (typeof options.flush === 'function') this._flush = options.flush;
  16622. }
  16623. this.once('prefinish', function () {
  16624. if (typeof this._flush === 'function') this._flush(function (er) {
  16625. done(stream, er);
  16626. });else done(stream);
  16627. });
  16628. }
  16629. Transform.prototype.push = function (chunk, encoding) {
  16630. this._transformState.needTransform = false;
  16631. return Duplex.prototype.push.call(this, chunk, encoding);
  16632. };
  16633. // This is the part where you do stuff!
  16634. // override this function in implementation classes.
  16635. // 'chunk' is an input chunk.
  16636. //
  16637. // Call `push(newChunk)` to pass along transformed output
  16638. // to the readable side. You may call 'push' zero or more times.
  16639. //
  16640. // Call `cb(err)` when you are done with this chunk. If you pass
  16641. // an error, then that'll put the hurt on the whole operation. If you
  16642. // never call cb(), then you'll never get another chunk.
  16643. Transform.prototype._transform = function (chunk, encoding, cb) {
  16644. throw new Error('not implemented');
  16645. };
  16646. Transform.prototype._write = function (chunk, encoding, cb) {
  16647. var ts = this._transformState;
  16648. ts.writecb = cb;
  16649. ts.writechunk = chunk;
  16650. ts.writeencoding = encoding;
  16651. if (!ts.transforming) {
  16652. var rs = this._readableState;
  16653. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  16654. }
  16655. };
  16656. // Doesn't matter what the args are here.
  16657. // _transform does all the work.
  16658. // That we got here means that the readable side wants more data.
  16659. Transform.prototype._read = function (n) {
  16660. var ts = this._transformState;
  16661. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  16662. ts.transforming = true;
  16663. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  16664. } else {
  16665. // mark that we need a transform, so that any data that comes in
  16666. // will get processed, now that we've asked for it.
  16667. ts.needTransform = true;
  16668. }
  16669. };
  16670. function done(stream, er) {
  16671. if (er) return stream.emit('error', er);
  16672. // if there's nothing in the write buffer, then that means
  16673. // that nothing more will ever be provided
  16674. var ws = stream._writableState;
  16675. var ts = stream._transformState;
  16676. if (ws.length) throw new Error('calling transform done when ws.length != 0');
  16677. if (ts.transforming) throw new Error('calling transform done when still transforming');
  16678. return stream.push(null);
  16679. }
  16680. },{"./_stream_duplex":119,"core-util-is":48,"inherits":92}],123:[function(require,module,exports){
  16681. (function (process){
  16682. // A bit simpler than readable streams.
  16683. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  16684. // the drain event emission and buffering.
  16685. 'use strict';
  16686. module.exports = Writable;
  16687. /*<replacement>*/
  16688. var processNextTick = require('process-nextick-args');
  16689. /*</replacement>*/
  16690. /*<replacement>*/
  16691. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  16692. /*</replacement>*/
  16693. /*<replacement>*/
  16694. var Buffer = require('buffer').Buffer;
  16695. /*</replacement>*/
  16696. Writable.WritableState = WritableState;
  16697. /*<replacement>*/
  16698. var util = require('core-util-is');
  16699. util.inherits = require('inherits');
  16700. /*</replacement>*/
  16701. /*<replacement>*/
  16702. var internalUtil = {
  16703. deprecate: require('util-deprecate')
  16704. };
  16705. /*</replacement>*/
  16706. /*<replacement>*/
  16707. var Stream;
  16708. (function () {
  16709. try {
  16710. Stream = require('st' + 'ream');
  16711. } catch (_) {} finally {
  16712. if (!Stream) Stream = require('events').EventEmitter;
  16713. }
  16714. })();
  16715. /*</replacement>*/
  16716. var Buffer = require('buffer').Buffer;
  16717. util.inherits(Writable, Stream);
  16718. function nop() {}
  16719. function WriteReq(chunk, encoding, cb) {
  16720. this.chunk = chunk;
  16721. this.encoding = encoding;
  16722. this.callback = cb;
  16723. this.next = null;
  16724. }
  16725. var Duplex;
  16726. function WritableState(options, stream) {
  16727. Duplex = Duplex || require('./_stream_duplex');
  16728. options = options || {};
  16729. // object stream flag to indicate whether or not this stream
  16730. // contains buffers or objects.
  16731. this.objectMode = !!options.objectMode;
  16732. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  16733. // the point at which write() starts returning false
  16734. // Note: 0 is a valid value, means that we always return false if
  16735. // the entire buffer is not flushed immediately on write()
  16736. var hwm = options.highWaterMark;
  16737. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  16738. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  16739. // cast to ints.
  16740. this.highWaterMark = ~ ~this.highWaterMark;
  16741. this.needDrain = false;
  16742. // at the start of calling end()
  16743. this.ending = false;
  16744. // when end() has been called, and returned
  16745. this.ended = false;
  16746. // when 'finish' is emitted
  16747. this.finished = false;
  16748. // should we decode strings into buffers before passing to _write?
  16749. // this is here so that some node-core streams can optimize string
  16750. // handling at a lower level.
  16751. var noDecode = options.decodeStrings === false;
  16752. this.decodeStrings = !noDecode;
  16753. // Crypto is kind of old and crusty. Historically, its default string
  16754. // encoding is 'binary' so we have to make this configurable.
  16755. // Everything else in the universe uses 'utf8', though.
  16756. this.defaultEncoding = options.defaultEncoding || 'utf8';
  16757. // not an actual buffer we keep track of, but a measurement
  16758. // of how much we're waiting to get pushed to some underlying
  16759. // socket or file.
  16760. this.length = 0;
  16761. // a flag to see when we're in the middle of a write.
  16762. this.writing = false;
  16763. // when true all writes will be buffered until .uncork() call
  16764. this.corked = 0;
  16765. // a flag to be able to tell if the onwrite cb is called immediately,
  16766. // or on a later tick. We set this to true at first, because any
  16767. // actions that shouldn't happen until "later" should generally also
  16768. // not happen before the first write call.
  16769. this.sync = true;
  16770. // a flag to know if we're processing previously buffered items, which
  16771. // may call the _write() callback in the same tick, so that we don't
  16772. // end up in an overlapped onwrite situation.
  16773. this.bufferProcessing = false;
  16774. // the callback that's passed to _write(chunk,cb)
  16775. this.onwrite = function (er) {
  16776. onwrite(stream, er);
  16777. };
  16778. // the callback that the user supplies to write(chunk,encoding,cb)
  16779. this.writecb = null;
  16780. // the amount that is being written when _write is called.
  16781. this.writelen = 0;
  16782. this.bufferedRequest = null;
  16783. this.lastBufferedRequest = null;
  16784. // number of pending user-supplied write callbacks
  16785. // this must be 0 before 'finish' can be emitted
  16786. this.pendingcb = 0;
  16787. // emit prefinish if the only thing we're waiting for is _write cbs
  16788. // This is relevant for synchronous Transform streams
  16789. this.prefinished = false;
  16790. // True if the error was already emitted and should not be thrown again
  16791. this.errorEmitted = false;
  16792. // count buffered requests
  16793. this.bufferedRequestCount = 0;
  16794. // create the two objects needed to store the corked requests
  16795. // they are not a linked list, as no new elements are inserted in there
  16796. this.corkedRequestsFree = new CorkedRequest(this);
  16797. this.corkedRequestsFree.next = new CorkedRequest(this);
  16798. }
  16799. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  16800. var current = this.bufferedRequest;
  16801. var out = [];
  16802. while (current) {
  16803. out.push(current);
  16804. current = current.next;
  16805. }
  16806. return out;
  16807. };
  16808. (function () {
  16809. try {
  16810. Object.defineProperty(WritableState.prototype, 'buffer', {
  16811. get: internalUtil.deprecate(function () {
  16812. return this.getBuffer();
  16813. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  16814. });
  16815. } catch (_) {}
  16816. })();
  16817. var Duplex;
  16818. function Writable(options) {
  16819. Duplex = Duplex || require('./_stream_duplex');
  16820. // Writable ctor is applied to Duplexes, though they're not
  16821. // instanceof Writable, they're instanceof Readable.
  16822. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  16823. this._writableState = new WritableState(options, this);
  16824. // legacy.
  16825. this.writable = true;
  16826. if (options) {
  16827. if (typeof options.write === 'function') this._write = options.write;
  16828. if (typeof options.writev === 'function') this._writev = options.writev;
  16829. }
  16830. Stream.call(this);
  16831. }
  16832. // Otherwise people can pipe Writable streams, which is just wrong.
  16833. Writable.prototype.pipe = function () {
  16834. this.emit('error', new Error('Cannot pipe. Not readable.'));
  16835. };
  16836. function writeAfterEnd(stream, cb) {
  16837. var er = new Error('write after end');
  16838. // TODO: defer error events consistently everywhere, not just the cb
  16839. stream.emit('error', er);
  16840. processNextTick(cb, er);
  16841. }
  16842. // If we get something that is not a buffer, string, null, or undefined,
  16843. // and we're not in objectMode, then that's an error.
  16844. // Otherwise stream chunks are all considered to be of length=1, and the
  16845. // watermarks determine how many objects to keep in the buffer, rather than
  16846. // how many bytes or characters.
  16847. function validChunk(stream, state, chunk, cb) {
  16848. var valid = true;
  16849. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  16850. var er = new TypeError('Invalid non-string/buffer chunk');
  16851. stream.emit('error', er);
  16852. processNextTick(cb, er);
  16853. valid = false;
  16854. }
  16855. return valid;
  16856. }
  16857. Writable.prototype.write = function (chunk, encoding, cb) {
  16858. var state = this._writableState;
  16859. var ret = false;
  16860. if (typeof encoding === 'function') {
  16861. cb = encoding;
  16862. encoding = null;
  16863. }
  16864. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  16865. if (typeof cb !== 'function') cb = nop;
  16866. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  16867. state.pendingcb++;
  16868. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  16869. }
  16870. return ret;
  16871. };
  16872. Writable.prototype.cork = function () {
  16873. var state = this._writableState;
  16874. state.corked++;
  16875. };
  16876. Writable.prototype.uncork = function () {
  16877. var state = this._writableState;
  16878. if (state.corked) {
  16879. state.corked--;
  16880. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  16881. }
  16882. };
  16883. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  16884. // node::ParseEncoding() requires lower case.
  16885. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  16886. 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);
  16887. this._writableState.defaultEncoding = encoding;
  16888. };
  16889. function decodeChunk(state, chunk, encoding) {
  16890. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  16891. chunk = new Buffer(chunk, encoding);
  16892. }
  16893. return chunk;
  16894. }
  16895. // if we're already writing something, then just put this
  16896. // in the queue, and wait our turn. Otherwise, call _write
  16897. // If we return false, then we need a drain event, so set that flag.
  16898. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  16899. chunk = decodeChunk(state, chunk, encoding);
  16900. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  16901. var len = state.objectMode ? 1 : chunk.length;
  16902. state.length += len;
  16903. var ret = state.length < state.highWaterMark;
  16904. // we must ensure that previous needDrain will not be reset to false.
  16905. if (!ret) state.needDrain = true;
  16906. if (state.writing || state.corked) {
  16907. var last = state.lastBufferedRequest;
  16908. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  16909. if (last) {
  16910. last.next = state.lastBufferedRequest;
  16911. } else {
  16912. state.bufferedRequest = state.lastBufferedRequest;
  16913. }
  16914. state.bufferedRequestCount += 1;
  16915. } else {
  16916. doWrite(stream, state, false, len, chunk, encoding, cb);
  16917. }
  16918. return ret;
  16919. }
  16920. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  16921. state.writelen = len;
  16922. state.writecb = cb;
  16923. state.writing = true;
  16924. state.sync = true;
  16925. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  16926. state.sync = false;
  16927. }
  16928. function onwriteError(stream, state, sync, er, cb) {
  16929. --state.pendingcb;
  16930. if (sync) processNextTick(cb, er);else cb(er);
  16931. stream._writableState.errorEmitted = true;
  16932. stream.emit('error', er);
  16933. }
  16934. function onwriteStateUpdate(state) {
  16935. state.writing = false;
  16936. state.writecb = null;
  16937. state.length -= state.writelen;
  16938. state.writelen = 0;
  16939. }
  16940. function onwrite(stream, er) {
  16941. var state = stream._writableState;
  16942. var sync = state.sync;
  16943. var cb = state.writecb;
  16944. onwriteStateUpdate(state);
  16945. if (er) onwriteError(stream, state, sync, er, cb);else {
  16946. // Check if we're actually ready to finish, but don't emit yet
  16947. var finished = needFinish(state);
  16948. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  16949. clearBuffer(stream, state);
  16950. }
  16951. if (sync) {
  16952. /*<replacement>*/
  16953. asyncWrite(afterWrite, stream, state, finished, cb);
  16954. /*</replacement>*/
  16955. } else {
  16956. afterWrite(stream, state, finished, cb);
  16957. }
  16958. }
  16959. }
  16960. function afterWrite(stream, state, finished, cb) {
  16961. if (!finished) onwriteDrain(stream, state);
  16962. state.pendingcb--;
  16963. cb();
  16964. finishMaybe(stream, state);
  16965. }
  16966. // Must force callback to be called on nextTick, so that we don't
  16967. // emit 'drain' before the write() consumer gets the 'false' return
  16968. // value, and has a chance to attach a 'drain' listener.
  16969. function onwriteDrain(stream, state) {
  16970. if (state.length === 0 && state.needDrain) {
  16971. state.needDrain = false;
  16972. stream.emit('drain');
  16973. }
  16974. }
  16975. // if there's something in the buffer waiting, then process it
  16976. function clearBuffer(stream, state) {
  16977. state.bufferProcessing = true;
  16978. var entry = state.bufferedRequest;
  16979. if (stream._writev && entry && entry.next) {
  16980. // Fast case, write everything using _writev()
  16981. var l = state.bufferedRequestCount;
  16982. var buffer = new Array(l);
  16983. var holder = state.corkedRequestsFree;
  16984. holder.entry = entry;
  16985. var count = 0;
  16986. while (entry) {
  16987. buffer[count] = entry;
  16988. entry = entry.next;
  16989. count += 1;
  16990. }
  16991. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  16992. // doWrite is always async, defer these to save a bit of time
  16993. // as the hot path ends with doWrite
  16994. state.pendingcb++;
  16995. state.lastBufferedRequest = null;
  16996. state.corkedRequestsFree = holder.next;
  16997. holder.next = null;
  16998. } else {
  16999. // Slow case, write chunks one-by-one
  17000. while (entry) {
  17001. var chunk = entry.chunk;
  17002. var encoding = entry.encoding;
  17003. var cb = entry.callback;
  17004. var len = state.objectMode ? 1 : chunk.length;
  17005. doWrite(stream, state, false, len, chunk, encoding, cb);
  17006. entry = entry.next;
  17007. // if we didn't call the onwrite immediately, then
  17008. // it means that we need to wait until it does.
  17009. // also, that means that the chunk and cb are currently
  17010. // being processed, so move the buffer counter past them.
  17011. if (state.writing) {
  17012. break;
  17013. }
  17014. }
  17015. if (entry === null) state.lastBufferedRequest = null;
  17016. }
  17017. state.bufferedRequestCount = 0;
  17018. state.bufferedRequest = entry;
  17019. state.bufferProcessing = false;
  17020. }
  17021. Writable.prototype._write = function (chunk, encoding, cb) {
  17022. cb(new Error('not implemented'));
  17023. };
  17024. Writable.prototype._writev = null;
  17025. Writable.prototype.end = function (chunk, encoding, cb) {
  17026. var state = this._writableState;
  17027. if (typeof chunk === 'function') {
  17028. cb = chunk;
  17029. chunk = null;
  17030. encoding = null;
  17031. } else if (typeof encoding === 'function') {
  17032. cb = encoding;
  17033. encoding = null;
  17034. }
  17035. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  17036. // .end() fully uncorks
  17037. if (state.corked) {
  17038. state.corked = 1;
  17039. this.uncork();
  17040. }
  17041. // ignore unnecessary end() calls.
  17042. if (!state.ending && !state.finished) endWritable(this, state, cb);
  17043. };
  17044. function needFinish(state) {
  17045. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  17046. }
  17047. function prefinish(stream, state) {
  17048. if (!state.prefinished) {
  17049. state.prefinished = true;
  17050. stream.emit('prefinish');
  17051. }
  17052. }
  17053. function finishMaybe(stream, state) {
  17054. var need = needFinish(state);
  17055. if (need) {
  17056. if (state.pendingcb === 0) {
  17057. prefinish(stream, state);
  17058. state.finished = true;
  17059. stream.emit('finish');
  17060. } else {
  17061. prefinish(stream, state);
  17062. }
  17063. }
  17064. return need;
  17065. }
  17066. function endWritable(stream, state, cb) {
  17067. state.ending = true;
  17068. finishMaybe(stream, state);
  17069. if (cb) {
  17070. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  17071. }
  17072. state.ended = true;
  17073. stream.writable = false;
  17074. }
  17075. // It seems a linked list but it is not
  17076. // there will be only 2 of these for each stream
  17077. function CorkedRequest(state) {
  17078. var _this = this;
  17079. this.next = null;
  17080. this.entry = null;
  17081. this.finish = function (err) {
  17082. var entry = _this.entry;
  17083. _this.entry = null;
  17084. while (entry) {
  17085. var cb = entry.callback;
  17086. state.pendingcb--;
  17087. cb(err);
  17088. entry = entry.next;
  17089. }
  17090. if (state.corkedRequestsFree) {
  17091. state.corkedRequestsFree.next = _this;
  17092. } else {
  17093. state.corkedRequestsFree = _this;
  17094. }
  17095. };
  17096. }
  17097. }).call(this,require('_process'))
  17098. },{"./_stream_duplex":119,"_process":106,"buffer":46,"core-util-is":48,"events":82,"inherits":92,"process-nextick-args":105,"util-deprecate":145}],124:[function(require,module,exports){
  17099. module.exports = require("./lib/_stream_passthrough.js")
  17100. },{"./lib/_stream_passthrough.js":120}],125:[function(require,module,exports){
  17101. (function (process){
  17102. var Stream = (function (){
  17103. try {
  17104. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  17105. } catch(_){}
  17106. }());
  17107. exports = module.exports = require('./lib/_stream_readable.js');
  17108. exports.Stream = Stream || exports;
  17109. exports.Readable = exports;
  17110. exports.Writable = require('./lib/_stream_writable.js');
  17111. exports.Duplex = require('./lib/_stream_duplex.js');
  17112. exports.Transform = require('./lib/_stream_transform.js');
  17113. exports.PassThrough = require('./lib/_stream_passthrough.js');
  17114. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  17115. module.exports = Stream;
  17116. }
  17117. }).call(this,require('_process'))
  17118. },{"./lib/_stream_duplex.js":119,"./lib/_stream_passthrough.js":120,"./lib/_stream_readable.js":121,"./lib/_stream_transform.js":122,"./lib/_stream_writable.js":123,"_process":106}],126:[function(require,module,exports){
  17119. module.exports = require("./lib/_stream_transform.js")
  17120. },{"./lib/_stream_transform.js":122}],127:[function(require,module,exports){
  17121. module.exports = require("./lib/_stream_writable.js")
  17122. },{"./lib/_stream_writable.js":123}],128:[function(require,module,exports){
  17123. (function (Buffer){
  17124. /*
  17125. CryptoJS v3.1.2
  17126. code.google.com/p/crypto-js
  17127. (c) 2009-2013 by Jeff Mott. All rights reserved.
  17128. code.google.com/p/crypto-js/wiki/License
  17129. */
  17130. /** @preserve
  17131. (c) 2012 by Cédric Mesnil. All rights reserved.
  17132. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  17133. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  17134. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  17135. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17136. */
  17137. // constants table
  17138. var zl = [
  17139. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  17140. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  17141. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  17142. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  17143. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  17144. ]
  17145. var zr = [
  17146. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  17147. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  17148. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  17149. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  17150. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  17151. ]
  17152. var sl = [
  17153. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  17154. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  17155. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  17156. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  17157. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  17158. ]
  17159. var sr = [
  17160. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  17161. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  17162. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  17163. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  17164. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  17165. ]
  17166. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  17167. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  17168. function bytesToWords (bytes) {
  17169. var words = []
  17170. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  17171. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  17172. }
  17173. return words
  17174. }
  17175. function wordsToBytes (words) {
  17176. var bytes = []
  17177. for (var b = 0; b < words.length * 32; b += 8) {
  17178. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  17179. }
  17180. return bytes
  17181. }
  17182. function processBlock (H, M, offset) {
  17183. // swap endian
  17184. for (var i = 0; i < 16; i++) {
  17185. var offset_i = offset + i
  17186. var M_offset_i = M[offset_i]
  17187. // Swap
  17188. M[offset_i] = (
  17189. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  17190. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  17191. )
  17192. }
  17193. // Working variables
  17194. var al, bl, cl, dl, el
  17195. var ar, br, cr, dr, er
  17196. ar = al = H[0]
  17197. br = bl = H[1]
  17198. cr = cl = H[2]
  17199. dr = dl = H[3]
  17200. er = el = H[4]
  17201. // computation
  17202. var t
  17203. for (i = 0; i < 80; i += 1) {
  17204. t = (al + M[offset + zl[i]]) | 0
  17205. if (i < 16) {
  17206. t += f1(bl, cl, dl) + hl[0]
  17207. } else if (i < 32) {
  17208. t += f2(bl, cl, dl) + hl[1]
  17209. } else if (i < 48) {
  17210. t += f3(bl, cl, dl) + hl[2]
  17211. } else if (i < 64) {
  17212. t += f4(bl, cl, dl) + hl[3]
  17213. } else {// if (i<80) {
  17214. t += f5(bl, cl, dl) + hl[4]
  17215. }
  17216. t = t | 0
  17217. t = rotl(t, sl[i])
  17218. t = (t + el) | 0
  17219. al = el
  17220. el = dl
  17221. dl = rotl(cl, 10)
  17222. cl = bl
  17223. bl = t
  17224. t = (ar + M[offset + zr[i]]) | 0
  17225. if (i < 16) {
  17226. t += f5(br, cr, dr) + hr[0]
  17227. } else if (i < 32) {
  17228. t += f4(br, cr, dr) + hr[1]
  17229. } else if (i < 48) {
  17230. t += f3(br, cr, dr) + hr[2]
  17231. } else if (i < 64) {
  17232. t += f2(br, cr, dr) + hr[3]
  17233. } else {// if (i<80) {
  17234. t += f1(br, cr, dr) + hr[4]
  17235. }
  17236. t = t | 0
  17237. t = rotl(t, sr[i])
  17238. t = (t + er) | 0
  17239. ar = er
  17240. er = dr
  17241. dr = rotl(cr, 10)
  17242. cr = br
  17243. br = t
  17244. }
  17245. // intermediate hash value
  17246. t = (H[1] + cl + dr) | 0
  17247. H[1] = (H[2] + dl + er) | 0
  17248. H[2] = (H[3] + el + ar) | 0
  17249. H[3] = (H[4] + al + br) | 0
  17250. H[4] = (H[0] + bl + cr) | 0
  17251. H[0] = t
  17252. }
  17253. function f1 (x, y, z) {
  17254. return ((x) ^ (y) ^ (z))
  17255. }
  17256. function f2 (x, y, z) {
  17257. return (((x) & (y)) | ((~x) & (z)))
  17258. }
  17259. function f3 (x, y, z) {
  17260. return (((x) | (~(y))) ^ (z))
  17261. }
  17262. function f4 (x, y, z) {
  17263. return (((x) & (z)) | ((y) & (~(z))))
  17264. }
  17265. function f5 (x, y, z) {
  17266. return ((x) ^ ((y) | (~(z))))
  17267. }
  17268. function rotl (x, n) {
  17269. return (x << n) | (x >>> (32 - n))
  17270. }
  17271. function ripemd160 (message) {
  17272. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  17273. if (typeof message === 'string') {
  17274. message = new Buffer(message, 'utf8')
  17275. }
  17276. var m = bytesToWords(message)
  17277. var nBitsLeft = message.length * 8
  17278. var nBitsTotal = message.length * 8
  17279. // Add padding
  17280. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  17281. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  17282. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  17283. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  17284. )
  17285. for (var i = 0; i < m.length; i += 16) {
  17286. processBlock(H, m, i)
  17287. }
  17288. // swap endian
  17289. for (i = 0; i < 5; i++) {
  17290. // shortcut
  17291. var H_i = H[i]
  17292. // Swap
  17293. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  17294. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  17295. }
  17296. var digestbytes = wordsToBytes(H)
  17297. return new Buffer(digestbytes)
  17298. }
  17299. module.exports = ripemd160
  17300. }).call(this,require("buffer").Buffer)
  17301. },{"buffer":46}],129:[function(require,module,exports){
  17302. (function (Buffer){
  17303. // prototype class for hash functions
  17304. function Hash (blockSize, finalSize) {
  17305. this._block = new Buffer(blockSize)
  17306. this._finalSize = finalSize
  17307. this._blockSize = blockSize
  17308. this._len = 0
  17309. this._s = 0
  17310. }
  17311. Hash.prototype.update = function (data, enc) {
  17312. if (typeof data === 'string') {
  17313. enc = enc || 'utf8'
  17314. data = new Buffer(data, enc)
  17315. }
  17316. var l = this._len += data.length
  17317. var s = this._s || 0
  17318. var f = 0
  17319. var buffer = this._block
  17320. while (s < l) {
  17321. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  17322. var ch = (t - f)
  17323. for (var i = 0; i < ch; i++) {
  17324. buffer[(s % this._blockSize) + i] = data[i + f]
  17325. }
  17326. s += ch
  17327. f += ch
  17328. if ((s % this._blockSize) === 0) {
  17329. this._update(buffer)
  17330. }
  17331. }
  17332. this._s = s
  17333. return this
  17334. }
  17335. Hash.prototype.digest = function (enc) {
  17336. // Suppose the length of the message M, in bits, is l
  17337. var l = this._len * 8
  17338. // Append the bit 1 to the end of the message
  17339. this._block[this._len % this._blockSize] = 0x80
  17340. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  17341. this._block.fill(0, this._len % this._blockSize + 1)
  17342. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  17343. this._update(this._block)
  17344. this._block.fill(0)
  17345. }
  17346. // to this append the block which is equal to the number l written in binary
  17347. // TODO: handle case where l is > Math.pow(2, 29)
  17348. this._block.writeInt32BE(l, this._blockSize - 4)
  17349. var hash = this._update(this._block) || this._hash()
  17350. return enc ? hash.toString(enc) : hash
  17351. }
  17352. Hash.prototype._update = function () {
  17353. throw new Error('_update must be implemented by subclass')
  17354. }
  17355. module.exports = Hash
  17356. }).call(this,require("buffer").Buffer)
  17357. },{"buffer":46}],130:[function(require,module,exports){
  17358. var exports = module.exports = function SHA (algorithm) {
  17359. algorithm = algorithm.toLowerCase()
  17360. var Algorithm = exports[algorithm]
  17361. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  17362. return new Algorithm()
  17363. }
  17364. exports.sha = require('./sha')
  17365. exports.sha1 = require('./sha1')
  17366. exports.sha224 = require('./sha224')
  17367. exports.sha256 = require('./sha256')
  17368. exports.sha384 = require('./sha384')
  17369. exports.sha512 = require('./sha512')
  17370. },{"./sha":131,"./sha1":132,"./sha224":133,"./sha256":134,"./sha384":135,"./sha512":136}],131:[function(require,module,exports){
  17371. (function (Buffer){
  17372. /*
  17373. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  17374. * in FIPS PUB 180-1
  17375. * This source code is derived from sha1.js of the same repository.
  17376. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  17377. * operation was added.
  17378. */
  17379. var inherits = require('inherits')
  17380. var Hash = require('./hash')
  17381. var K = [
  17382. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  17383. ]
  17384. var W = new Array(80)
  17385. function Sha () {
  17386. this.init()
  17387. this._w = W
  17388. Hash.call(this, 64, 56)
  17389. }
  17390. inherits(Sha, Hash)
  17391. Sha.prototype.init = function () {
  17392. this._a = 0x67452301
  17393. this._b = 0xefcdab89
  17394. this._c = 0x98badcfe
  17395. this._d = 0x10325476
  17396. this._e = 0xc3d2e1f0
  17397. return this
  17398. }
  17399. function rotl5 (num) {
  17400. return (num << 5) | (num >>> 27)
  17401. }
  17402. function rotl30 (num) {
  17403. return (num << 30) | (num >>> 2)
  17404. }
  17405. function ft (s, b, c, d) {
  17406. if (s === 0) return (b & c) | ((~b) & d)
  17407. if (s === 2) return (b & c) | (b & d) | (c & d)
  17408. return b ^ c ^ d
  17409. }
  17410. Sha.prototype._update = function (M) {
  17411. var W = this._w
  17412. var a = this._a | 0
  17413. var b = this._b | 0
  17414. var c = this._c | 0
  17415. var d = this._d | 0
  17416. var e = this._e | 0
  17417. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17418. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  17419. for (var j = 0; j < 80; ++j) {
  17420. var s = ~~(j / 20)
  17421. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  17422. e = d
  17423. d = c
  17424. c = rotl30(b)
  17425. b = a
  17426. a = t
  17427. }
  17428. this._a = (a + this._a) | 0
  17429. this._b = (b + this._b) | 0
  17430. this._c = (c + this._c) | 0
  17431. this._d = (d + this._d) | 0
  17432. this._e = (e + this._e) | 0
  17433. }
  17434. Sha.prototype._hash = function () {
  17435. var H = new Buffer(20)
  17436. H.writeInt32BE(this._a | 0, 0)
  17437. H.writeInt32BE(this._b | 0, 4)
  17438. H.writeInt32BE(this._c | 0, 8)
  17439. H.writeInt32BE(this._d | 0, 12)
  17440. H.writeInt32BE(this._e | 0, 16)
  17441. return H
  17442. }
  17443. module.exports = Sha
  17444. }).call(this,require("buffer").Buffer)
  17445. },{"./hash":129,"buffer":46,"inherits":92}],132:[function(require,module,exports){
  17446. (function (Buffer){
  17447. /*
  17448. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  17449. * in FIPS PUB 180-1
  17450. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  17451. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17452. * Distributed under the BSD License
  17453. * See http://pajhome.org.uk/crypt/md5 for details.
  17454. */
  17455. var inherits = require('inherits')
  17456. var Hash = require('./hash')
  17457. var K = [
  17458. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  17459. ]
  17460. var W = new Array(80)
  17461. function Sha1 () {
  17462. this.init()
  17463. this._w = W
  17464. Hash.call(this, 64, 56)
  17465. }
  17466. inherits(Sha1, Hash)
  17467. Sha1.prototype.init = function () {
  17468. this._a = 0x67452301
  17469. this._b = 0xefcdab89
  17470. this._c = 0x98badcfe
  17471. this._d = 0x10325476
  17472. this._e = 0xc3d2e1f0
  17473. return this
  17474. }
  17475. function rotl1 (num) {
  17476. return (num << 1) | (num >>> 31)
  17477. }
  17478. function rotl5 (num) {
  17479. return (num << 5) | (num >>> 27)
  17480. }
  17481. function rotl30 (num) {
  17482. return (num << 30) | (num >>> 2)
  17483. }
  17484. function ft (s, b, c, d) {
  17485. if (s === 0) return (b & c) | ((~b) & d)
  17486. if (s === 2) return (b & c) | (b & d) | (c & d)
  17487. return b ^ c ^ d
  17488. }
  17489. Sha1.prototype._update = function (M) {
  17490. var W = this._w
  17491. var a = this._a | 0
  17492. var b = this._b | 0
  17493. var c = this._c | 0
  17494. var d = this._d | 0
  17495. var e = this._e | 0
  17496. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17497. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  17498. for (var j = 0; j < 80; ++j) {
  17499. var s = ~~(j / 20)
  17500. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  17501. e = d
  17502. d = c
  17503. c = rotl30(b)
  17504. b = a
  17505. a = t
  17506. }
  17507. this._a = (a + this._a) | 0
  17508. this._b = (b + this._b) | 0
  17509. this._c = (c + this._c) | 0
  17510. this._d = (d + this._d) | 0
  17511. this._e = (e + this._e) | 0
  17512. }
  17513. Sha1.prototype._hash = function () {
  17514. var H = new Buffer(20)
  17515. H.writeInt32BE(this._a | 0, 0)
  17516. H.writeInt32BE(this._b | 0, 4)
  17517. H.writeInt32BE(this._c | 0, 8)
  17518. H.writeInt32BE(this._d | 0, 12)
  17519. H.writeInt32BE(this._e | 0, 16)
  17520. return H
  17521. }
  17522. module.exports = Sha1
  17523. }).call(this,require("buffer").Buffer)
  17524. },{"./hash":129,"buffer":46,"inherits":92}],133:[function(require,module,exports){
  17525. (function (Buffer){
  17526. /**
  17527. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  17528. * in FIPS 180-2
  17529. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  17530. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17531. *
  17532. */
  17533. var inherits = require('inherits')
  17534. var Sha256 = require('./sha256')
  17535. var Hash = require('./hash')
  17536. var W = new Array(64)
  17537. function Sha224 () {
  17538. this.init()
  17539. this._w = W // new Array(64)
  17540. Hash.call(this, 64, 56)
  17541. }
  17542. inherits(Sha224, Sha256)
  17543. Sha224.prototype.init = function () {
  17544. this._a = 0xc1059ed8
  17545. this._b = 0x367cd507
  17546. this._c = 0x3070dd17
  17547. this._d = 0xf70e5939
  17548. this._e = 0xffc00b31
  17549. this._f = 0x68581511
  17550. this._g = 0x64f98fa7
  17551. this._h = 0xbefa4fa4
  17552. return this
  17553. }
  17554. Sha224.prototype._hash = function () {
  17555. var H = new Buffer(28)
  17556. H.writeInt32BE(this._a, 0)
  17557. H.writeInt32BE(this._b, 4)
  17558. H.writeInt32BE(this._c, 8)
  17559. H.writeInt32BE(this._d, 12)
  17560. H.writeInt32BE(this._e, 16)
  17561. H.writeInt32BE(this._f, 20)
  17562. H.writeInt32BE(this._g, 24)
  17563. return H
  17564. }
  17565. module.exports = Sha224
  17566. }).call(this,require("buffer").Buffer)
  17567. },{"./hash":129,"./sha256":134,"buffer":46,"inherits":92}],134:[function(require,module,exports){
  17568. (function (Buffer){
  17569. /**
  17570. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  17571. * in FIPS 180-2
  17572. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  17573. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17574. *
  17575. */
  17576. var inherits = require('inherits')
  17577. var Hash = require('./hash')
  17578. var K = [
  17579. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  17580. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  17581. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  17582. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  17583. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  17584. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  17585. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  17586. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  17587. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  17588. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  17589. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  17590. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  17591. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  17592. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  17593. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  17594. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  17595. ]
  17596. var W = new Array(64)
  17597. function Sha256 () {
  17598. this.init()
  17599. this._w = W // new Array(64)
  17600. Hash.call(this, 64, 56)
  17601. }
  17602. inherits(Sha256, Hash)
  17603. Sha256.prototype.init = function () {
  17604. this._a = 0x6a09e667
  17605. this._b = 0xbb67ae85
  17606. this._c = 0x3c6ef372
  17607. this._d = 0xa54ff53a
  17608. this._e = 0x510e527f
  17609. this._f = 0x9b05688c
  17610. this._g = 0x1f83d9ab
  17611. this._h = 0x5be0cd19
  17612. return this
  17613. }
  17614. function ch (x, y, z) {
  17615. return z ^ (x & (y ^ z))
  17616. }
  17617. function maj (x, y, z) {
  17618. return (x & y) | (z & (x | y))
  17619. }
  17620. function sigma0 (x) {
  17621. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  17622. }
  17623. function sigma1 (x) {
  17624. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  17625. }
  17626. function gamma0 (x) {
  17627. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  17628. }
  17629. function gamma1 (x) {
  17630. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  17631. }
  17632. Sha256.prototype._update = function (M) {
  17633. var W = this._w
  17634. var a = this._a | 0
  17635. var b = this._b | 0
  17636. var c = this._c | 0
  17637. var d = this._d | 0
  17638. var e = this._e | 0
  17639. var f = this._f | 0
  17640. var g = this._g | 0
  17641. var h = this._h | 0
  17642. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17643. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  17644. for (var j = 0; j < 64; ++j) {
  17645. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  17646. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  17647. h = g
  17648. g = f
  17649. f = e
  17650. e = (d + T1) | 0
  17651. d = c
  17652. c = b
  17653. b = a
  17654. a = (T1 + T2) | 0
  17655. }
  17656. this._a = (a + this._a) | 0
  17657. this._b = (b + this._b) | 0
  17658. this._c = (c + this._c) | 0
  17659. this._d = (d + this._d) | 0
  17660. this._e = (e + this._e) | 0
  17661. this._f = (f + this._f) | 0
  17662. this._g = (g + this._g) | 0
  17663. this._h = (h + this._h) | 0
  17664. }
  17665. Sha256.prototype._hash = function () {
  17666. var H = new Buffer(32)
  17667. H.writeInt32BE(this._a, 0)
  17668. H.writeInt32BE(this._b, 4)
  17669. H.writeInt32BE(this._c, 8)
  17670. H.writeInt32BE(this._d, 12)
  17671. H.writeInt32BE(this._e, 16)
  17672. H.writeInt32BE(this._f, 20)
  17673. H.writeInt32BE(this._g, 24)
  17674. H.writeInt32BE(this._h, 28)
  17675. return H
  17676. }
  17677. module.exports = Sha256
  17678. }).call(this,require("buffer").Buffer)
  17679. },{"./hash":129,"buffer":46,"inherits":92}],135:[function(require,module,exports){
  17680. (function (Buffer){
  17681. var inherits = require('inherits')
  17682. var SHA512 = require('./sha512')
  17683. var Hash = require('./hash')
  17684. var W = new Array(160)
  17685. function Sha384 () {
  17686. this.init()
  17687. this._w = W
  17688. Hash.call(this, 128, 112)
  17689. }
  17690. inherits(Sha384, SHA512)
  17691. Sha384.prototype.init = function () {
  17692. this._ah = 0xcbbb9d5d
  17693. this._bh = 0x629a292a
  17694. this._ch = 0x9159015a
  17695. this._dh = 0x152fecd8
  17696. this._eh = 0x67332667
  17697. this._fh = 0x8eb44a87
  17698. this._gh = 0xdb0c2e0d
  17699. this._hh = 0x47b5481d
  17700. this._al = 0xc1059ed8
  17701. this._bl = 0x367cd507
  17702. this._cl = 0x3070dd17
  17703. this._dl = 0xf70e5939
  17704. this._el = 0xffc00b31
  17705. this._fl = 0x68581511
  17706. this._gl = 0x64f98fa7
  17707. this._hl = 0xbefa4fa4
  17708. return this
  17709. }
  17710. Sha384.prototype._hash = function () {
  17711. var H = new Buffer(48)
  17712. function writeInt64BE (h, l, offset) {
  17713. H.writeInt32BE(h, offset)
  17714. H.writeInt32BE(l, offset + 4)
  17715. }
  17716. writeInt64BE(this._ah, this._al, 0)
  17717. writeInt64BE(this._bh, this._bl, 8)
  17718. writeInt64BE(this._ch, this._cl, 16)
  17719. writeInt64BE(this._dh, this._dl, 24)
  17720. writeInt64BE(this._eh, this._el, 32)
  17721. writeInt64BE(this._fh, this._fl, 40)
  17722. return H
  17723. }
  17724. module.exports = Sha384
  17725. }).call(this,require("buffer").Buffer)
  17726. },{"./hash":129,"./sha512":136,"buffer":46,"inherits":92}],136:[function(require,module,exports){
  17727. (function (Buffer){
  17728. var inherits = require('inherits')
  17729. var Hash = require('./hash')
  17730. var K = [
  17731. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  17732. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  17733. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  17734. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  17735. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  17736. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  17737. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  17738. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  17739. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  17740. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  17741. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  17742. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  17743. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  17744. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  17745. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  17746. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  17747. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  17748. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  17749. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  17750. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  17751. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  17752. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  17753. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  17754. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  17755. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  17756. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  17757. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  17758. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  17759. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  17760. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  17761. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  17762. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  17763. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  17764. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  17765. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  17766. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  17767. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  17768. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  17769. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  17770. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  17771. ]
  17772. var W = new Array(160)
  17773. function Sha512 () {
  17774. this.init()
  17775. this._w = W
  17776. Hash.call(this, 128, 112)
  17777. }
  17778. inherits(Sha512, Hash)
  17779. Sha512.prototype.init = function () {
  17780. this._ah = 0x6a09e667
  17781. this._bh = 0xbb67ae85
  17782. this._ch = 0x3c6ef372
  17783. this._dh = 0xa54ff53a
  17784. this._eh = 0x510e527f
  17785. this._fh = 0x9b05688c
  17786. this._gh = 0x1f83d9ab
  17787. this._hh = 0x5be0cd19
  17788. this._al = 0xf3bcc908
  17789. this._bl = 0x84caa73b
  17790. this._cl = 0xfe94f82b
  17791. this._dl = 0x5f1d36f1
  17792. this._el = 0xade682d1
  17793. this._fl = 0x2b3e6c1f
  17794. this._gl = 0xfb41bd6b
  17795. this._hl = 0x137e2179
  17796. return this
  17797. }
  17798. function Ch (x, y, z) {
  17799. return z ^ (x & (y ^ z))
  17800. }
  17801. function maj (x, y, z) {
  17802. return (x & y) | (z & (x | y))
  17803. }
  17804. function sigma0 (x, xl) {
  17805. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  17806. }
  17807. function sigma1 (x, xl) {
  17808. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  17809. }
  17810. function Gamma0 (x, xl) {
  17811. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  17812. }
  17813. function Gamma0l (x, xl) {
  17814. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  17815. }
  17816. function Gamma1 (x, xl) {
  17817. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  17818. }
  17819. function Gamma1l (x, xl) {
  17820. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  17821. }
  17822. function getCarry (a, b) {
  17823. return (a >>> 0) < (b >>> 0) ? 1 : 0
  17824. }
  17825. Sha512.prototype._update = function (M) {
  17826. var W = this._w
  17827. var ah = this._ah | 0
  17828. var bh = this._bh | 0
  17829. var ch = this._ch | 0
  17830. var dh = this._dh | 0
  17831. var eh = this._eh | 0
  17832. var fh = this._fh | 0
  17833. var gh = this._gh | 0
  17834. var hh = this._hh | 0
  17835. var al = this._al | 0
  17836. var bl = this._bl | 0
  17837. var cl = this._cl | 0
  17838. var dl = this._dl | 0
  17839. var el = this._el | 0
  17840. var fl = this._fl | 0
  17841. var gl = this._gl | 0
  17842. var hl = this._hl | 0
  17843. for (var i = 0; i < 32; i += 2) {
  17844. W[i] = M.readInt32BE(i * 4)
  17845. W[i + 1] = M.readInt32BE(i * 4 + 4)
  17846. }
  17847. for (; i < 160; i += 2) {
  17848. var xh = W[i - 15 * 2]
  17849. var xl = W[i - 15 * 2 + 1]
  17850. var gamma0 = Gamma0(xh, xl)
  17851. var gamma0l = Gamma0l(xl, xh)
  17852. xh = W[i - 2 * 2]
  17853. xl = W[i - 2 * 2 + 1]
  17854. var gamma1 = Gamma1(xh, xl)
  17855. var gamma1l = Gamma1l(xl, xh)
  17856. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  17857. var Wi7h = W[i - 7 * 2]
  17858. var Wi7l = W[i - 7 * 2 + 1]
  17859. var Wi16h = W[i - 16 * 2]
  17860. var Wi16l = W[i - 16 * 2 + 1]
  17861. var Wil = (gamma0l + Wi7l) | 0
  17862. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  17863. Wil = (Wil + gamma1l) | 0
  17864. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  17865. Wil = (Wil + Wi16l) | 0
  17866. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  17867. W[i] = Wih
  17868. W[i + 1] = Wil
  17869. }
  17870. for (var j = 0; j < 160; j += 2) {
  17871. Wih = W[j]
  17872. Wil = W[j + 1]
  17873. var majh = maj(ah, bh, ch)
  17874. var majl = maj(al, bl, cl)
  17875. var sigma0h = sigma0(ah, al)
  17876. var sigma0l = sigma0(al, ah)
  17877. var sigma1h = sigma1(eh, el)
  17878. var sigma1l = sigma1(el, eh)
  17879. // t1 = h + sigma1 + ch + K[j] + W[j]
  17880. var Kih = K[j]
  17881. var Kil = K[j + 1]
  17882. var chh = Ch(eh, fh, gh)
  17883. var chl = Ch(el, fl, gl)
  17884. var t1l = (hl + sigma1l) | 0
  17885. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  17886. t1l = (t1l + chl) | 0
  17887. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  17888. t1l = (t1l + Kil) | 0
  17889. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  17890. t1l = (t1l + Wil) | 0
  17891. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  17892. // t2 = sigma0 + maj
  17893. var t2l = (sigma0l + majl) | 0
  17894. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  17895. hh = gh
  17896. hl = gl
  17897. gh = fh
  17898. gl = fl
  17899. fh = eh
  17900. fl = el
  17901. el = (dl + t1l) | 0
  17902. eh = (dh + t1h + getCarry(el, dl)) | 0
  17903. dh = ch
  17904. dl = cl
  17905. ch = bh
  17906. cl = bl
  17907. bh = ah
  17908. bl = al
  17909. al = (t1l + t2l) | 0
  17910. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  17911. }
  17912. this._al = (this._al + al) | 0
  17913. this._bl = (this._bl + bl) | 0
  17914. this._cl = (this._cl + cl) | 0
  17915. this._dl = (this._dl + dl) | 0
  17916. this._el = (this._el + el) | 0
  17917. this._fl = (this._fl + fl) | 0
  17918. this._gl = (this._gl + gl) | 0
  17919. this._hl = (this._hl + hl) | 0
  17920. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  17921. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  17922. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  17923. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  17924. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  17925. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  17926. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  17927. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  17928. }
  17929. Sha512.prototype._hash = function () {
  17930. var H = new Buffer(64)
  17931. function writeInt64BE (h, l, offset) {
  17932. H.writeInt32BE(h, offset)
  17933. H.writeInt32BE(l, offset + 4)
  17934. }
  17935. writeInt64BE(this._ah, this._al, 0)
  17936. writeInt64BE(this._bh, this._bl, 8)
  17937. writeInt64BE(this._ch, this._cl, 16)
  17938. writeInt64BE(this._dh, this._dl, 24)
  17939. writeInt64BE(this._eh, this._el, 32)
  17940. writeInt64BE(this._fh, this._fl, 40)
  17941. writeInt64BE(this._gh, this._gl, 48)
  17942. writeInt64BE(this._hh, this._hl, 56)
  17943. return H
  17944. }
  17945. module.exports = Sha512
  17946. }).call(this,require("buffer").Buffer)
  17947. },{"./hash":129,"buffer":46,"inherits":92}],137:[function(require,module,exports){
  17948. // Copyright Joyent, Inc. and other Node contributors.
  17949. //
  17950. // Permission is hereby granted, free of charge, to any person obtaining a
  17951. // copy of this software and associated documentation files (the
  17952. // "Software"), to deal in the Software without restriction, including
  17953. // without limitation the rights to use, copy, modify, merge, publish,
  17954. // distribute, sublicense, and/or sell copies of the Software, and to permit
  17955. // persons to whom the Software is furnished to do so, subject to the
  17956. // following conditions:
  17957. //
  17958. // The above copyright notice and this permission notice shall be included
  17959. // in all copies or substantial portions of the Software.
  17960. //
  17961. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17962. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17963. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17964. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17965. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17966. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  17967. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  17968. module.exports = Stream;
  17969. var EE = require('events').EventEmitter;
  17970. var inherits = require('inherits');
  17971. inherits(Stream, EE);
  17972. Stream.Readable = require('readable-stream/readable.js');
  17973. Stream.Writable = require('readable-stream/writable.js');
  17974. Stream.Duplex = require('readable-stream/duplex.js');
  17975. Stream.Transform = require('readable-stream/transform.js');
  17976. Stream.PassThrough = require('readable-stream/passthrough.js');
  17977. // Backwards-compat with node 0.4.x
  17978. Stream.Stream = Stream;
  17979. // old-style streams. Note that the pipe method (the only relevant
  17980. // part of this class) is overridden in the Readable class.
  17981. function Stream() {
  17982. EE.call(this);
  17983. }
  17984. Stream.prototype.pipe = function(dest, options) {
  17985. var source = this;
  17986. function ondata(chunk) {
  17987. if (dest.writable) {
  17988. if (false === dest.write(chunk) && source.pause) {
  17989. source.pause();
  17990. }
  17991. }
  17992. }
  17993. source.on('data', ondata);
  17994. function ondrain() {
  17995. if (source.readable && source.resume) {
  17996. source.resume();
  17997. }
  17998. }
  17999. dest.on('drain', ondrain);
  18000. // If the 'end' option is not supplied, dest.end() will be called when
  18001. // source gets the 'end' or 'close' events. Only dest.end() once.
  18002. if (!dest._isStdio && (!options || options.end !== false)) {
  18003. source.on('end', onend);
  18004. source.on('close', onclose);
  18005. }
  18006. var didOnEnd = false;
  18007. function onend() {
  18008. if (didOnEnd) return;
  18009. didOnEnd = true;
  18010. dest.end();
  18011. }
  18012. function onclose() {
  18013. if (didOnEnd) return;
  18014. didOnEnd = true;
  18015. if (typeof dest.destroy === 'function') dest.destroy();
  18016. }
  18017. // don't leave dangling pipes when there are errors.
  18018. function onerror(er) {
  18019. cleanup();
  18020. if (EE.listenerCount(this, 'error') === 0) {
  18021. throw er; // Unhandled stream error in pipe.
  18022. }
  18023. }
  18024. source.on('error', onerror);
  18025. dest.on('error', onerror);
  18026. // remove all the event listeners that were added.
  18027. function cleanup() {
  18028. source.removeListener('data', ondata);
  18029. dest.removeListener('drain', ondrain);
  18030. source.removeListener('end', onend);
  18031. source.removeListener('close', onclose);
  18032. source.removeListener('error', onerror);
  18033. dest.removeListener('error', onerror);
  18034. source.removeListener('end', cleanup);
  18035. source.removeListener('close', cleanup);
  18036. dest.removeListener('close', cleanup);
  18037. }
  18038. source.on('end', cleanup);
  18039. source.on('close', cleanup);
  18040. dest.on('close', cleanup);
  18041. dest.emit('pipe', source);
  18042. // Allow for unix-like usage: A.pipe(B).pipe(C)
  18043. return dest;
  18044. };
  18045. },{"events":82,"inherits":92,"readable-stream/duplex.js":118,"readable-stream/passthrough.js":124,"readable-stream/readable.js":125,"readable-stream/transform.js":126,"readable-stream/writable.js":127}],138:[function(require,module,exports){
  18046. // Copyright Joyent, Inc. and other Node contributors.
  18047. //
  18048. // Permission is hereby granted, free of charge, to any person obtaining a
  18049. // copy of this software and associated documentation files (the
  18050. // "Software"), to deal in the Software without restriction, including
  18051. // without limitation the rights to use, copy, modify, merge, publish,
  18052. // distribute, sublicense, and/or sell copies of the Software, and to permit
  18053. // persons to whom the Software is furnished to do so, subject to the
  18054. // following conditions:
  18055. //
  18056. // The above copyright notice and this permission notice shall be included
  18057. // in all copies or substantial portions of the Software.
  18058. //
  18059. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18060. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18061. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  18062. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18063. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18064. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18065. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  18066. var Buffer = require('buffer').Buffer;
  18067. var isBufferEncoding = Buffer.isEncoding
  18068. || function(encoding) {
  18069. switch (encoding && encoding.toLowerCase()) {
  18070. 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': return true;
  18071. default: return false;
  18072. }
  18073. }
  18074. function assertEncoding(encoding) {
  18075. if (encoding && !isBufferEncoding(encoding)) {
  18076. throw new Error('Unknown encoding: ' + encoding);
  18077. }
  18078. }
  18079. // StringDecoder provides an interface for efficiently splitting a series of
  18080. // buffers into a series of JS strings without breaking apart multi-byte
  18081. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  18082. //
  18083. // @TODO Handling all encodings inside a single object makes it very difficult
  18084. // to reason about this code, so it should be split up in the future.
  18085. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  18086. // points as used by CESU-8.
  18087. var StringDecoder = exports.StringDecoder = function(encoding) {
  18088. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  18089. assertEncoding(encoding);
  18090. switch (this.encoding) {
  18091. case 'utf8':
  18092. // CESU-8 represents each of Surrogate Pair by 3-bytes
  18093. this.surrogateSize = 3;
  18094. break;
  18095. case 'ucs2':
  18096. case 'utf16le':
  18097. // UTF-16 represents each of Surrogate Pair by 2-bytes
  18098. this.surrogateSize = 2;
  18099. this.detectIncompleteChar = utf16DetectIncompleteChar;
  18100. break;
  18101. case 'base64':
  18102. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  18103. this.surrogateSize = 3;
  18104. this.detectIncompleteChar = base64DetectIncompleteChar;
  18105. break;
  18106. default:
  18107. this.write = passThroughWrite;
  18108. return;
  18109. }
  18110. // Enough space to store all bytes of a single character. UTF-8 needs 4
  18111. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  18112. this.charBuffer = new Buffer(6);
  18113. // Number of bytes received for the current incomplete multi-byte character.
  18114. this.charReceived = 0;
  18115. // Number of bytes expected for the current incomplete multi-byte character.
  18116. this.charLength = 0;
  18117. };
  18118. // write decodes the given buffer and returns it as JS string that is
  18119. // guaranteed to not contain any partial multi-byte characters. Any partial
  18120. // character found at the end of the buffer is buffered up, and will be
  18121. // returned when calling write again with the remaining bytes.
  18122. //
  18123. // Note: Converting a Buffer containing an orphan surrogate to a String
  18124. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  18125. // Buffer#write) will replace incomplete surrogates with the unicode
  18126. // replacement character. See https://codereview.chromium.org/121173009/ .
  18127. StringDecoder.prototype.write = function(buffer) {
  18128. var charStr = '';
  18129. // if our last write ended with an incomplete multibyte character
  18130. while (this.charLength) {
  18131. // determine how many remaining bytes this buffer has to offer for this char
  18132. var available = (buffer.length >= this.charLength - this.charReceived) ?
  18133. this.charLength - this.charReceived :
  18134. buffer.length;
  18135. // add the new bytes to the char buffer
  18136. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  18137. this.charReceived += available;
  18138. if (this.charReceived < this.charLength) {
  18139. // still not enough chars in this buffer? wait for more ...
  18140. return '';
  18141. }
  18142. // remove bytes belonging to the current character from the buffer
  18143. buffer = buffer.slice(available, buffer.length);
  18144. // get the character that was split
  18145. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  18146. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  18147. var charCode = charStr.charCodeAt(charStr.length - 1);
  18148. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  18149. this.charLength += this.surrogateSize;
  18150. charStr = '';
  18151. continue;
  18152. }
  18153. this.charReceived = this.charLength = 0;
  18154. // if there are no more bytes in this buffer, just emit our char
  18155. if (buffer.length === 0) {
  18156. return charStr;
  18157. }
  18158. break;
  18159. }
  18160. // determine and set charLength / charReceived
  18161. this.detectIncompleteChar(buffer);
  18162. var end = buffer.length;
  18163. if (this.charLength) {
  18164. // buffer the incomplete character bytes we got
  18165. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  18166. end -= this.charReceived;
  18167. }
  18168. charStr += buffer.toString(this.encoding, 0, end);
  18169. var end = charStr.length - 1;
  18170. var charCode = charStr.charCodeAt(end);
  18171. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  18172. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  18173. var size = this.surrogateSize;
  18174. this.charLength += size;
  18175. this.charReceived += size;
  18176. this.charBuffer.copy(this.charBuffer, size, 0, size);
  18177. buffer.copy(this.charBuffer, 0, 0, size);
  18178. return charStr.substring(0, end);
  18179. }
  18180. // or just emit the charStr
  18181. return charStr;
  18182. };
  18183. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  18184. // the end of the given buffer. If so, it sets this.charLength to the byte
  18185. // length that character, and sets this.charReceived to the number of bytes
  18186. // that are available for this character.
  18187. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  18188. // determine how many bytes we have to check at the end of this buffer
  18189. var i = (buffer.length >= 3) ? 3 : buffer.length;
  18190. // Figure out if one of the last i bytes of our buffer announces an
  18191. // incomplete char.
  18192. for (; i > 0; i--) {
  18193. var c = buffer[buffer.length - i];
  18194. // See http://en.wikipedia.org/wiki/UTF-8#Description
  18195. // 110XXXXX
  18196. if (i == 1 && c >> 5 == 0x06) {
  18197. this.charLength = 2;
  18198. break;
  18199. }
  18200. // 1110XXXX
  18201. if (i <= 2 && c >> 4 == 0x0E) {
  18202. this.charLength = 3;
  18203. break;
  18204. }
  18205. // 11110XXX
  18206. if (i <= 3 && c >> 3 == 0x1E) {
  18207. this.charLength = 4;
  18208. break;
  18209. }
  18210. }
  18211. this.charReceived = i;
  18212. };
  18213. StringDecoder.prototype.end = function(buffer) {
  18214. var res = '';
  18215. if (buffer && buffer.length)
  18216. res = this.write(buffer);
  18217. if (this.charReceived) {
  18218. var cr = this.charReceived;
  18219. var buf = this.charBuffer;
  18220. var enc = this.encoding;
  18221. res += buf.slice(0, cr).toString(enc);
  18222. }
  18223. return res;
  18224. };
  18225. function passThroughWrite(buffer) {
  18226. return buffer.toString(this.encoding);
  18227. }
  18228. function utf16DetectIncompleteChar(buffer) {
  18229. this.charReceived = buffer.length % 2;
  18230. this.charLength = this.charReceived ? 2 : 0;
  18231. }
  18232. function base64DetectIncompleteChar(buffer) {
  18233. this.charReceived = buffer.length % 3;
  18234. this.charLength = this.charReceived ? 3 : 0;
  18235. }
  18236. },{"buffer":46}],139:[function(require,module,exports){
  18237. "use strict";
  18238. var tld = require('./lib/tld.js').init();
  18239. tld.rules = require('./rules.json');
  18240. module.exports = tld;
  18241. },{"./lib/tld.js":141,"./rules.json":142}],140:[function(require,module,exports){
  18242. "use strict";
  18243. function Rule (data){
  18244. data = data || {};
  18245. this.exception = data.exception || false;
  18246. this.firstLevel = data.firstLevel || '';
  18247. this.secondLevel = data.secondLevel || null;
  18248. this.isHost = data.isHost || false;
  18249. this.source = data.source || '';
  18250. this.wildcard = data.wildcard || false;
  18251. }
  18252. /**
  18253. * Returns the TLD or SLD (Second Level Domain) pattern for a rule
  18254. *
  18255. * @return {String}
  18256. */
  18257. Rule.prototype.getNormalXld = function getNormalXld(){
  18258. return (this.secondLevel ? '.' + this.secondLevel : '') + '.' + this.firstLevel;
  18259. };
  18260. /**
  18261. * Returns a pattern suitable for normal rule
  18262. * Mostly for internal use
  18263. *
  18264. * @return {String}
  18265. */
  18266. Rule.prototype.getNormalPattern = function getNormalPattern(){
  18267. return (this.secondLevel ? '\\.' + this.secondLevel : '') + '\\.' + this.firstLevel;
  18268. };
  18269. /**
  18270. * Returns a pattern suitable for wildcard rule
  18271. * Mostly for internal use
  18272. *
  18273. * @return {String}
  18274. */
  18275. Rule.prototype.getWildcardPattern = function getWildcardPattern(){
  18276. return '\\.[^\\.]+' + this.getNormalXld().replace(/\./g, '\\.');
  18277. };
  18278. /**
  18279. * Returns a pattern suitable for exception rule
  18280. * Mostly for internal use
  18281. *
  18282. * @return {String}
  18283. */
  18284. Rule.prototype.getExceptionPattern = function getExceptionPattern(){
  18285. return (this.secondLevel || '') + '\\.' + this.firstLevel;
  18286. };
  18287. /**
  18288. * Returns the best pattern possible for a rule
  18289. * You just have to test a value against it to check or extract a hostname
  18290. *
  18291. * @api
  18292. * @param {string|undefined} before
  18293. * @param {string|undefined} after
  18294. * @return {String} A pattern to challenge some string against
  18295. */
  18296. Rule.prototype.getPattern = function getPattern(before, after){
  18297. var pattern = '';
  18298. before = (before === undefined) ? '(': before+'';
  18299. after = (after === undefined) ? ')$': after+'';
  18300. if (this.exception === true){
  18301. pattern = this.getExceptionPattern();
  18302. }
  18303. else if (this.isHost === true) {
  18304. pattern = this.firstLevel;
  18305. }
  18306. else{
  18307. pattern = '[^\\.]+' + (this.wildcard ? this.getWildcardPattern() : this.getNormalPattern());
  18308. }
  18309. return before + pattern + after;
  18310. };
  18311. module.exports = Rule;
  18312. },{}],141:[function(require,module,exports){
  18313. "use strict";
  18314. var Rule = require('./rule.js');
  18315. var URL = require('url');
  18316. /**
  18317. * tld library
  18318. *
  18319. * Useable methods are those documented with an @api in JSDoc
  18320. * See README.md for more explanations on how to use this stuff.
  18321. */
  18322. function tld () {
  18323. /* jshint validthis: true */
  18324. this.validHosts = [];
  18325. this.rules = [];
  18326. }
  18327. tld.init = function init () {
  18328. return new tld();
  18329. };
  18330. function trim(value) {
  18331. return String(value).replace(/(^\s+|\s+$)/g, '');
  18332. }
  18333. // Array.some() polyfill for IE8
  18334. function _someFunction(value, fun /*, thisArg */) {
  18335. 'use strict';
  18336. if (value === void 0 || value === null)
  18337. throw new TypeError();
  18338. var t = Object(value);
  18339. var len = t.length >>> 0;
  18340. if (typeof fun !== 'function') {
  18341. throw new TypeError();
  18342. }
  18343. var thisArg = arguments.length >= 3 ? arguments[2] : void 0;
  18344. for (var i = 0; i < len; i++)
  18345. {
  18346. if (i in t && fun.call(thisArg, t[i], i, t))
  18347. return true;
  18348. }
  18349. return false;
  18350. }
  18351. // Array.map polyfill for IE8
  18352. function _mapFunction(thisVal, fun /*, thisArg */) {
  18353. "use strict";
  18354. if (thisVal === void 0 || thisVal === null)
  18355. throw new TypeError();
  18356. var t = Object(thisVal);
  18357. var len = t.length >>> 0;
  18358. if (typeof fun !== "function") {
  18359. throw new TypeError();
  18360. }
  18361. var res = new Array(len);
  18362. var thisArg = arguments.length >= 3 ? arguments[2] : void 0;
  18363. for (var i = 0; i < len; i++)
  18364. {
  18365. // NOTE: Absolute correctness would demand Object.defineProperty
  18366. // be used. But this method is fairly new, and failure is
  18367. // possible only if Object.prototype or Array.prototype
  18368. // has a property |i| (very unlikely), so use a lesscorrect
  18369. // but more portable alternative.
  18370. if (i in t)
  18371. res[i] = fun.call(thisArg, t[i], i, t);
  18372. }
  18373. return res;
  18374. };
  18375. /**
  18376. * Returns the best rule for a given host based on candidates
  18377. *
  18378. * @static
  18379. * @param host {String} Hostname to check rules against
  18380. * @param rules {Array} List of rules used to work on
  18381. * @return {Object} Candidate object, with a normal and exception state
  18382. */
  18383. tld.getCandidateRule = function getCandidateRule (host, rules, options) {
  18384. var rule = {'normal': null, 'exception': null};
  18385. options = options || { lazy: false };
  18386. _someFunction(rules, function (r) {
  18387. var pattern;
  18388. // sld matching or validHost? escape the loop immediately (except if it's an exception)
  18389. if ('.' + host === r.getNormalXld()) {
  18390. if (options.lazy || r.exception || r.isHost) {
  18391. rule.normal = r;
  18392. }
  18393. return true;
  18394. }
  18395. // otherwise check as a complete host
  18396. // if it's an exception, we want to loop a bit more to a normal rule
  18397. pattern = '.+' + r.getNormalPattern() + '$';
  18398. if ((new RegExp(pattern)).test(host)) {
  18399. rule[r.exception ? 'exception' : 'normal'] = r;
  18400. return !r.exception;
  18401. }
  18402. return false;
  18403. });
  18404. // favouring the exception if encountered
  18405. // previously we were copy-altering a rule, creating inconsistent results based on rule order order
  18406. // @see https://github.com/oncletom/tld.js/pull/35
  18407. if (rule.normal && rule.exception) {
  18408. return rule.exception;
  18409. }
  18410. return rule.normal;
  18411. };
  18412. /**
  18413. * Retrieve a subset of rules for a Top-Level-Domain string
  18414. *
  18415. * @param tld {String} Top-Level-Domain string
  18416. * @return {Array} Rules subset
  18417. */
  18418. tld.prototype.getRulesForTld = function getRulesForTld (tld, default_rule) {
  18419. var exception = '!';
  18420. var wildcard = '*';
  18421. var append_tld_rule = true;
  18422. var rules = this.rules[tld];
  18423. // Already parsed
  18424. // Array.isArray polyfill for IE8
  18425. if (Object.prototype.toString.call(rules) === '[object Array]') {
  18426. return rules;
  18427. }
  18428. // Nothing found, apply some default value
  18429. if (rules === void 0) {
  18430. return default_rule ? [ default_rule ] : [];
  18431. }
  18432. // Parsing needed
  18433. rules = _mapFunction(rules.split('|'), function transformAsRule (sld) {
  18434. var first_bit = sld[0];
  18435. if (first_bit === exception || first_bit === wildcard) {
  18436. sld = sld.slice(1);
  18437. if (!sld) {
  18438. append_tld_rule = false;
  18439. }
  18440. }
  18441. return new Rule({
  18442. "firstLevel": tld,
  18443. "secondLevel": sld,
  18444. "exception": first_bit === exception,
  18445. "wildcard": first_bit === wildcard
  18446. });
  18447. });
  18448. // Always prepend to make it the latest rule to be applied
  18449. if (append_tld_rule) {
  18450. rules.unshift(new Rule({
  18451. "firstLevel": tld
  18452. }));
  18453. }
  18454. this.rules[tld] = rules.reverse();
  18455. return rules;
  18456. };
  18457. /**
  18458. * Checks if the TLD exists for a given host
  18459. *
  18460. * @api
  18461. * @param {string} host
  18462. * @return {boolean}
  18463. */
  18464. tld.prototype.tldExists = function tldExists(host){
  18465. var hostTld;
  18466. host = tld.cleanHostValue(host);
  18467. // Easy case, it's a TLD
  18468. if (this.rules[host]){
  18469. return true;
  18470. }
  18471. // Popping only the TLD of the hostname
  18472. hostTld = tld.extractTldFromHost(host);
  18473. return this.rules[hostTld] !== undefined;
  18474. };
  18475. /**
  18476. * Returns the public suffix (including exact matches)
  18477. *
  18478. * @api
  18479. * @since 1.5
  18480. * @param {string} host
  18481. * @return {String}
  18482. */
  18483. tld.prototype.getPublicSuffix = function getPublicSuffix(host) {
  18484. var hostTld, rules, rule;
  18485. if (host in this.rules){
  18486. return host;
  18487. }
  18488. host = tld.cleanHostValue(host);
  18489. hostTld = tld.extractTldFromHost(host);
  18490. rules = this.getRulesForTld(hostTld);
  18491. rule = tld.getCandidateRule(host, rules, { lazy: true });
  18492. if (rule === null) {
  18493. return null;
  18494. }
  18495. return rule.getNormalXld().slice(1);
  18496. };
  18497. /**
  18498. * Detects the domain based on rules and upon and a host string
  18499. *
  18500. * @api
  18501. * @param {string} host
  18502. * @return {String}
  18503. */
  18504. tld.prototype.getDomain = function getDomain (host) {
  18505. var domain = null, hostTld, rules, rule;
  18506. if (this.isValid(host) === false) {
  18507. return null;
  18508. }
  18509. host = tld.cleanHostValue(host);
  18510. hostTld = tld.extractTldFromHost(host);
  18511. rules = this.getRulesForTld(hostTld, new Rule({"firstLevel": hostTld, "isHost": this.validHosts.indexOf(hostTld) !== -1}));
  18512. rule = tld.getCandidateRule(host, rules);
  18513. if (rule === null) {
  18514. return null;
  18515. }
  18516. host.replace(new RegExp(rule.getPattern()), function (m, d) {
  18517. domain = d;
  18518. });
  18519. return domain;
  18520. };
  18521. /**
  18522. * Returns the subdomain of a host string
  18523. *
  18524. * @api
  18525. * @param {string} host
  18526. * @return {string|null} a subdomain string if any, blank string if subdomain is empty, otherwise null
  18527. */
  18528. tld.prototype.getSubdomain = function getSubdomain(host){
  18529. var domain, r, subdomain;
  18530. host = tld.cleanHostValue(host);
  18531. domain = this.getDomain(host);
  18532. // No domain found? Just abort, abort!
  18533. if (domain === null){
  18534. return null;
  18535. }
  18536. r = '\\.?'+ tld.escapeRegExp(domain)+'$';
  18537. subdomain = host.replace(new RegExp(r, 'i'), '');
  18538. return subdomain;
  18539. };
  18540. /**
  18541. * Checking if a host string is valid
  18542. * It's usually a preliminary check before trying to use getDomain or anything else
  18543. *
  18544. * Beware: it does not check if the TLD exists.
  18545. *
  18546. * @api
  18547. * @param host {String}
  18548. * @return {Boolean}
  18549. */
  18550. tld.prototype.isValid = function isValid (host) {
  18551. return typeof host === 'string' && (this.validHosts.indexOf(host) !== -1 || (host.indexOf('.') !== -1 && host[0] !== '.'));
  18552. };
  18553. /**
  18554. * Utility to cleanup the base host value. Also removes url fragments.
  18555. *
  18556. * Works for:
  18557. * - hostname
  18558. * - //hostname
  18559. * - scheme://hostname
  18560. * - scheme+scheme://hostname
  18561. *
  18562. * @param {string} value
  18563. * @return {String}
  18564. */
  18565. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  18566. var hasPrefixRE = /^(([a-z][a-z0-9+.-]*)?:)?\/\//;
  18567. var invalidHostnameChars = /[^A-Za-z0-9.-]/;
  18568. tld.cleanHostValue = function cleanHostValue(value){
  18569. value = trim(value).toLowerCase();
  18570. var parts = URL.parse(hasPrefixRE.test(value) ? value : '//' + value, null, true);
  18571. if (parts.hostname && !invalidHostnameChars.test(parts.hostname)) { return parts.hostname; }
  18572. if (!invalidHostnameChars.test(value)) { return value; }
  18573. return '';
  18574. };
  18575. /**
  18576. * Utility to extract the TLD from a host string
  18577. *
  18578. * @param {string} host
  18579. * @return {String}
  18580. */
  18581. tld.extractTldFromHost = function extractTldFromHost(host){
  18582. return host.split('.').pop();
  18583. };
  18584. /**
  18585. * Escapes RegExp specific chars.
  18586. *
  18587. * @since 1.3.1
  18588. * @see https://github.com/oncletom/tld.js/pull/33
  18589. * @param {String|Mixed} s
  18590. * @returns {string} Escaped string for a safe use in a `new RegExp` expression
  18591. */
  18592. tld.escapeRegExp = function escapeRegExp(s) {
  18593. return String(s).replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  18594. };
  18595. module.exports = tld;
  18596. },{"./rule.js":140,"url":143}],142:[function(require,module,exports){
  18597. module.exports={"ac":"com|edu|gov|net|mil|org","ad":"nom","ae":"co|net|org|sch|ac|gov|mil|blogspot","aero":"accident-investigation|accident-prevention|aerobatic|aeroclub|aerodrome|agents|aircraft|airline|airport|air-surveillance|airtraffic|air-traffic-control|ambulance|amusement|association|author|ballooning|broker|caa|cargo|catering|certification|championship|charter|civilaviation|club|conference|consultant|consulting|control|council|crew|design|dgca|educator|emergency|engine|engineer|entertainment|equipment|exchange|express|federation|flight|freight|fuel|gliding|government|groundhandling|group|hanggliding|homebuilt|insurance|journal|journalist|leasing|logistics|magazine|maintenance|marketplace|media|microlight|modelling|navigation|parachuting|paragliding|passenger-association|pilot|press|production|recreation|repbody|res|research|rotorcraft|safety|scientist|services|show|skydiving|software|student|taxi|trader|trading|trainer|union|workinggroup|works","af":"gov|com|org|net|edu","ag":"com|org|net|co|nom","ai":"off|com|net|org","al":"com|edu|gov|mil|net|org|blogspot","am":"blogspot","ao":"ed|gv|og|co|pb|it","aq":"","ar":"com|edu|gob|gov|int|mil|net|org|tur|blogspot.com","arpa":"e164|in-addr|ip6|iris|uri|urn","as":"gov","asia":"","at":"ac|co|gv|or|blogspot.co|biz|info|priv","au":"com|net|org|edu|gov|asn|id|info|conf|oz|act|nsw|nt|qld|sa|tas|vic|wa|act.edu|nsw.edu|nt.edu|qld.edu|sa.edu|tas.edu|vic.edu|wa.edu|qld.gov|sa.gov|tas.gov|vic.gov|wa.gov|blogspot.com","aw":"com","ax":"","az":"com|net|int|gov|org|edu|info|pp|mil|name|pro|biz","ba":"org|net|edu|gov|mil|unsa|unbi|co|com|rs|blogspot","bb":"biz|co|com|edu|gov|info|net|org|store|tv","bd":"*","be":"ac|blogspot","bf":"gov","bg":"a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|0|1|2|3|4|5|6|7|8|9|blogspot","bh":"com|edu|net|org|gov","bi":"co|com|edu|or|org","biz":"dyndns|for-better|for-more|for-some|for-the|selfip|webhop","bj":"asso|barreau|gouv|blogspot","bm":"com|edu|gov|net|org","bn":"*","bo":"com|edu|gov|gob|int|org|net|mil|tv","br":"adm|adv|agr|am|arq|art|ato|b|bio|blog|bmd|cim|cng|cnt|com|coop|ecn|eco|edu|emp|eng|esp|etc|eti|far|flog|fm|fnd|fot|fst|g12|ggf|gov|imb|ind|inf|jor|jus|leg|lel|mat|med|mil|mp|mus|net|*nom|not|ntr|odo|org|ppg|pro|psc|psi|qsl|radio|rec|slg|srv|taxi|teo|tmp|trd|tur|tv|vet|vlog|wiki|zlg|blogspot.com","bs":"com|net|org|edu|gov","bt":"com|edu|gov|net|org","bv":"","bw":"co|org","by":"gov|mil|com|of|blogspot.com","bz":"com|net|org|edu|gov|za","ca":"ab|bc|mb|nb|nf|nl|ns|nt|nu|on|pe|qc|sk|yk|gc|co|blogspot","cat":"","cc":"ftpaccess|game-server|myphotos|scrapping","cd":"gov","cf":"blogspot","cg":"","ch":"blogspot","ci":"org|or|com|co|edu|ed|ac|net|go|asso|xn--aroport-bya|int|presse|md|gouv","ck":"*|!www","cl":"gov|gob|co|mil|blogspot","cm":"co|com|gov|net","cn":"ac|com|edu|gov|net|org|mil|xn--55qx5d|xn--io0a7i|xn--od0alg|ah|bj|cq|fj|gd|gs|gz|gx|ha|hb|he|hi|hl|hn|jl|js|jx|ln|nm|nx|qh|sc|sd|sh|sn|sx|tj|xj|xz|yn|zj|hk|mo|tw|cn-north-1.compute.amazonaws|compute.amazonaws|s3.cn-north-1.amazonaws.com","co":"arts|com|edu|firm|gov|info|int|mil|net|nom|org|rec|web|blogspot.com","com":"ap-northeast-1.compute.amazonaws|ap-southeast-1.compute.amazonaws|ap-southeast-2.compute.amazonaws|compute.amazonaws|compute-1.amazonaws|eu-west-1.compute.amazonaws|eu-central-1.compute.amazonaws|sa-east-1.compute.amazonaws|us-east-1.amazonaws|us-gov-west-1.compute.amazonaws|us-west-1.compute.amazonaws|us-west-2.compute.amazonaws|z-1.compute-1.amazonaws|z-2.compute-1.amazonaws|elasticbeanstalk|elb.amazonaws|s3.amazonaws|s3-ap-northeast-1.amazonaws|s3-ap-southeast-1.amazonaws|s3-ap-southeast-2.amazonaws|s3-external-1.amazonaws|s3-external-2.amazonaws|s3-fips-us-gov-west-1.amazonaws|s3-eu-central-1.amazonaws|s3-eu-west-1.amazonaws|s3-sa-east-1.amazonaws|s3-us-gov-west-1.amazonaws|s3-us-west-1.amazonaws|s3-us-west-2.amazonaws|s3.eu-central-1.amazonaws|betainabox|ar|br|cn|de|eu|gb|hu|jpn|kr|mex|no|qc|ru|sa|se|uk|us|uy|za|africa|gr|co|cloudcontrolled|cloudcontrolapp|dreamhosters|dyndns-at-home|dyndns-at-work|dyndns-blog|dyndns-free|dyndns-home|dyndns-ip|dyndns-mail|dyndns-office|dyndns-pics|dyndns-remote|dyndns-server|dyndns-web|dyndns-wiki|dyndns-work|blogdns|cechire|dnsalias|dnsdojo|doesntexist|dontexist|doomdns|dyn-o-saur|dynalias|est-a-la-maison|est-a-la-masion|est-le-patron|est-mon-blogueur|from-ak|from-al|from-ar|from-ca|from-ct|from-dc|from-de|from-fl|from-ga|from-hi|from-ia|from-id|from-il|from-in|from-ks|from-ky|from-ma|from-md|from-mi|from-mn|from-mo|from-ms|from-mt|from-nc|from-nd|from-ne|from-nh|from-nj|from-nm|from-nv|from-oh|from-ok|from-or|from-pa|from-pr|from-ri|from-sc|from-sd|from-tn|from-tx|from-ut|from-va|from-vt|from-wa|from-wi|from-wv|from-wy|getmyip|gotdns|hobby-site|homelinux|homeunix|iamallama|is-a-anarchist|is-a-blogger|is-a-bookkeeper|is-a-bulls-fan|is-a-caterer|is-a-chef|is-a-conservative|is-a-cpa|is-a-cubicle-slave|is-a-democrat|is-a-designer|is-a-doctor|is-a-financialadvisor|is-a-geek|is-a-green|is-a-guru|is-a-hard-worker|is-a-hunter|is-a-landscaper|is-a-lawyer|is-a-liberal|is-a-libertarian|is-a-llama|is-a-musician|is-a-nascarfan|is-a-nurse|is-a-painter|is-a-personaltrainer|is-a-photographer|is-a-player|is-a-republican|is-a-rockstar|is-a-socialist|is-a-student|is-a-teacher|is-a-techie|is-a-therapist|is-an-accountant|is-an-actor|is-an-actress|is-an-anarchist|is-an-artist|is-an-engineer|is-an-entertainer|is-certified|is-gone|is-into-anime|is-into-cars|is-into-cartoons|is-into-games|is-leet|is-not-certified|is-slick|is-uberleet|is-with-theband|isa-geek|isa-hockeynut|issmarterthanyou|likes-pie|likescandy|neat-url|saves-the-whales|selfip|sells-for-less|sells-for-u|servebbs|simple-url|space-to-rent|teaches-yoga|writesthisblog|firebaseapp|flynnhub|githubusercontent|ro|appspot|blogspot|codespot|googleapis|googlecode|pagespeedmobilizer|withgoogle|withyoutube|herokuapp|herokussl|4u|nfshost|operaunite|outsystemscloud|gotpantheon|qa2|rhcloud|sinaapp|vipsinaapp|1kapp|hk|yolasite","coop":"","cr":"ac|co|ed|fi|go|or|sa","cu":"com|edu|org|net|gov|inf","cv":"blogspot","cw":"com|edu|net|org","cx":"gov|ath","cy":"ac|biz|com|ekloges|gov|ltd|name|net|org|parliament|press|pro|tm|blogspot.com","cz":"blogspot","de":"com|fuettertdasnetz|isteingeek|istmein|lebtimnetz|leitungsen|traeumtgerade|blogspot","dj":"","dk":"blogspot","dm":"com|net|org|edu|gov","do":"art|com|edu|gob|gov|mil|net|org|sld|web","dz":"com|org|net|gov|edu|asso|pol|art","ec":"com|info|net|fin|k12|med|pro|org|edu|gov|gob|mil","edu":"","ee":"edu|gov|riik|lib|med|com|pri|aip|org|fie|blogspot.com","eg":"com|edu|eun|gov|mil|name|net|org|sci|blogspot.com","er":"*","es":"com|nom|org|gob|edu|blogspot.com","et":"com|gov|org|edu|biz|name|info|net","eu":"","fi":"aland|blogspot|iki","fj":"*","fk":"*","fm":"","fo":"","fr":"com|asso|nom|prd|presse|tm|aeroport|assedic|avocat|avoues|cci|chambagri|chirurgiens-dentistes|experts-comptables|geometre-expert|gouv|greta|huissier-justice|medecin|notaires|pharmacien|port|veterinaire|blogspot","ga":"","gb":"","gd":"","ge":"com|edu|gov|org|mil|net|pvt","gf":"","gg":"co|net|org","gh":"com|edu|gov|org|mil","gi":"com|ltd|gov|mod|edu|org","gl":"co|com|edu|net|org","gm":"","gn":"ac|com|edu|gov|org|net","gov":"","gp":"com|net|mobi|edu|org|asso","gq":"","gr":"com|edu|net|org|gov|blogspot","gs":"","gt":"com|edu|gob|ind|mil|net|org","gu":"*","gw":"","gy":"co|com|net","hk":"com|edu|gov|idv|net|org|xn--55qx5d|xn--wcvs22d|xn--lcvr32d|xn--mxtq1m|xn--gmqw5a|xn--ciqpn|xn--gmq050i|xn--zf0avx|xn--io0a7i|xn--mk0axi|xn--od0alg|xn--od0aq3b|xn--tn0ag|xn--uc0atv|xn--uc0ay4a|blogspot|ltd|inc","hm":"","hn":"com|edu|org|net|mil|gob","hr":"iz|from|name|com|blogspot","ht":"com|shop|firm|info|adult|net|pro|org|med|art|coop|pol|asso|edu|rel|gouv|perso","hu":"co|info|org|priv|sport|tm|2000|agrar|bolt|casino|city|erotica|erotika|film|forum|games|hotel|ingatlan|jogasz|konyvelo|lakas|media|news|reklam|sex|shop|suli|szex|tozsde|utazas|video|blogspot","id":"ac|biz|co|desa|go|mil|my|net|or|sch|web|blogspot.co","ie":"gov|blogspot","il":"ac|co|gov|idf|k12|muni|net|org|blogspot.co","im":"ac|co|com|ltd.co|net|org|plc.co|tt|tv","in":"co|firm|net|org|gen|ind|nic|ac|edu|res|gov|mil|blogspot","info":"dyndns|barrel-of-knowledge|barrell-of-knowledge|for-our|groks-the|groks-this|here-for-more|knowsitall|selfip|webhop","int":"eu","io":"com|github|ngrok|nid|pantheon|sandcats","iq":"gov|edu|mil|com|org|net","ir":"ac|co|gov|id|net|org|sch|xn--mgba3a4f16a|xn--mgba3a4fra","is":"net|com|edu|gov|org|int|cupcake|blogspot","it":"gov|edu|abr|abruzzo|aosta-valley|aostavalley|bas|basilicata|cal|calabria|cam|campania|emilia-romagna|emiliaromagna|emr|friuli-v-giulia|friuli-ve-giulia|friuli-vegiulia|friuli-venezia-giulia|friuli-veneziagiulia|friuli-vgiulia|friuliv-giulia|friulive-giulia|friulivegiulia|friulivenezia-giulia|friuliveneziagiulia|friulivgiulia|fvg|laz|lazio|lig|liguria|lom|lombardia|lombardy|lucania|mar|marche|mol|molise|piedmont|piemonte|pmn|pug|puglia|sar|sardegna|sardinia|sic|sicilia|sicily|taa|tos|toscana|trentino-a-adige|trentino-aadige|trentino-alto-adige|trentino-altoadige|trentino-s-tirol|trentino-stirol|trentino-sud-tirol|trentino-sudtirol|trentino-sued-tirol|trentino-suedtirol|trentinoa-adige|trentinoaadige|trentinoalto-adige|trentinoaltoadige|trentinos-tirol|trentinostirol|trentinosud-tirol|trentinosudtirol|trentinosued-tirol|trentinosuedtirol|tuscany|umb|umbria|val-d-aosta|val-daosta|vald-aosta|valdaosta|valle-aosta|valle-d-aosta|valle-daosta|valleaosta|valled-aosta|valledaosta|vallee-aoste|valleeaoste|vao|vda|ven|veneto|ag|agrigento|al|alessandria|alto-adige|altoadige|an|ancona|andria-barletta-trani|andria-trani-barletta|andriabarlettatrani|andriatranibarletta|ao|aosta|aoste|ap|aq|aquila|ar|arezzo|ascoli-piceno|ascolipiceno|asti|at|av|avellino|ba|balsan|bari|barletta-trani-andria|barlettatraniandria|belluno|benevento|bergamo|bg|bi|biella|bl|bn|bo|bologna|bolzano|bozen|br|brescia|brindisi|bs|bt|bz|ca|cagliari|caltanissetta|campidano-medio|campidanomedio|campobasso|carbonia-iglesias|carboniaiglesias|carrara-massa|carraramassa|caserta|catania|catanzaro|cb|ce|cesena-forli|cesenaforli|ch|chieti|ci|cl|cn|co|como|cosenza|cr|cremona|crotone|cs|ct|cuneo|cz|dell-ogliastra|dellogliastra|en|enna|fc|fe|fermo|ferrara|fg|fi|firenze|florence|fm|foggia|forli-cesena|forlicesena|fr|frosinone|ge|genoa|genova|go|gorizia|gr|grosseto|iglesias-carbonia|iglesiascarbonia|im|imperia|is|isernia|kr|la-spezia|laquila|laspezia|latina|lc|le|lecce|lecco|li|livorno|lo|lodi|lt|lu|lucca|macerata|mantova|massa-carrara|massacarrara|matera|mb|mc|me|medio-campidano|mediocampidano|messina|mi|milan|milano|mn|mo|modena|monza-brianza|monza-e-della-brianza|monza|monzabrianza|monzaebrianza|monzaedellabrianza|ms|mt|na|naples|napoli|no|novara|nu|nuoro|og|ogliastra|olbia-tempio|olbiatempio|or|oristano|ot|pa|padova|padua|palermo|parma|pavia|pc|pd|pe|perugia|pesaro-urbino|pesarourbino|pescara|pg|pi|piacenza|pisa|pistoia|pn|po|pordenone|potenza|pr|prato|pt|pu|pv|pz|ra|ragusa|ravenna|rc|re|reggio-calabria|reggio-emilia|reggiocalabria|reggioemilia|rg|ri|rieti|rimini|rm|rn|ro|roma|rome|rovigo|sa|salerno|sassari|savona|si|siena|siracusa|so|sondrio|sp|sr|ss|suedtirol|sv|ta|taranto|te|tempio-olbia|tempioolbia|teramo|terni|tn|to|torino|tp|tr|trani-andria-barletta|trani-barletta-andria|traniandriabarletta|tranibarlettaandria|trapani|trentino|trento|treviso|trieste|ts|turin|tv|ud|udine|urbino-pesaro|urbinopesaro|va|varese|vb|vc|ve|venezia|venice|verbania|vercelli|verona|vi|vibo-valentia|vibovalentia|vicenza|viterbo|vr|vs|vt|vv|blogspot","je":"co|net|org","jm":"*","jo":"com|org|net|edu|sch|gov|mil|name","jobs":"","jp":"ac|ad|co|ed|go|gr|lg|ne|or|aichi|akita|aomori|chiba|ehime|fukui|fukuoka|fukushima|gifu|gunma|hiroshima|hokkaido|hyogo|ibaraki|ishikawa|iwate|kagawa|kagoshima|kanagawa|kochi|kumamoto|kyoto|mie|miyagi|miyazaki|nagano|nagasaki|nara|niigata|oita|okayama|okinawa|osaka|saga|saitama|shiga|shimane|shizuoka|tochigi|tokushima|tokyo|tottori|toyama|wakayama|yamagata|yamaguchi|yamanashi|xn--4pvxs|xn--vgu402c|xn--c3s14m|xn--f6qx53a|xn--8pvr4u|xn--uist22h|xn--djrs72d6uy|xn--mkru45i|xn--0trq7p7nn|xn--8ltr62k|xn--2m4a15e|xn--efvn9s|xn--32vp30h|xn--4it797k|xn--1lqs71d|xn--5rtp49c|xn--5js045d|xn--ehqz56n|xn--1lqs03n|xn--qqqt11m|xn--kbrq7o|xn--pssu33l|xn--ntsq17g|xn--uisz3g|xn--6btw5a|xn--1ctwo|xn--6orx2r|xn--rht61e|xn--rht27z|xn--djty4k|xn--nit225k|xn--rht3d|xn--klty5x|xn--kltx9a|xn--kltp7d|xn--uuwu58a|xn--zbx025d|xn--ntso0iqx3a|xn--elqq16h|xn--4it168d|xn--klt787d|xn--rny31h|xn--7t0a264c|xn--5rtq34k|xn--k7yn95e|xn--tor131o|xn--d5qv7z876c|*kawasaki|*kitakyushu|*kobe|*nagoya|*sapporo|*sendai|*yokohama|!city.kawasaki|!city.kitakyushu|!city.kobe|!city.nagoya|!city.sapporo|!city.sendai|!city.yokohama|aisai.aichi|ama.aichi|anjo.aichi|asuke.aichi|chiryu.aichi|chita.aichi|fuso.aichi|gamagori.aichi|handa.aichi|hazu.aichi|hekinan.aichi|higashiura.aichi|ichinomiya.aichi|inazawa.aichi|inuyama.aichi|isshiki.aichi|iwakura.aichi|kanie.aichi|kariya.aichi|kasugai.aichi|kira.aichi|kiyosu.aichi|komaki.aichi|konan.aichi|kota.aichi|mihama.aichi|miyoshi.aichi|nishio.aichi|nisshin.aichi|obu.aichi|oguchi.aichi|oharu.aichi|okazaki.aichi|owariasahi.aichi|seto.aichi|shikatsu.aichi|shinshiro.aichi|shitara.aichi|tahara.aichi|takahama.aichi|tobishima.aichi|toei.aichi|togo.aichi|tokai.aichi|tokoname.aichi|toyoake.aichi|toyohashi.aichi|toyokawa.aichi|toyone.aichi|toyota.aichi|tsushima.aichi|yatomi.aichi|akita.akita|daisen.akita|fujisato.akita|gojome.akita|hachirogata.akita|happou.akita|higashinaruse.akita|honjo.akita|honjyo.akita|ikawa.akita|kamikoani.akita|kamioka.akita|katagami.akita|kazuno.akita|kitaakita.akita|kosaka.akita|kyowa.akita|misato.akita|mitane.akita|moriyoshi.akita|nikaho.akita|noshiro.akita|odate.akita|oga.akita|ogata.akita|semboku.akita|yokote.akita|yurihonjo.akita|aomori.aomori|gonohe.aomori|hachinohe.aomori|hashikami.aomori|hiranai.aomori|hirosaki.aomori|itayanagi.aomori|kuroishi.aomori|misawa.aomori|mutsu.aomori|nakadomari.aomori|noheji.aomori|oirase.aomori|owani.aomori|rokunohe.aomori|sannohe.aomori|shichinohe.aomori|shingo.aomori|takko.aomori|towada.aomori|tsugaru.aomori|tsuruta.aomori|abiko.chiba|asahi.chiba|chonan.chiba|chosei.chiba|choshi.chiba|chuo.chiba|funabashi.chiba|futtsu.chiba|hanamigawa.chiba|ichihara.chiba|ichikawa.chiba|ichinomiya.chiba|inzai.chiba|isumi.chiba|kamagaya.chiba|kamogawa.chiba|kashiwa.chiba|katori.chiba|katsuura.chiba|kimitsu.chiba|kisarazu.chiba|kozaki.chiba|kujukuri.chiba|kyonan.chiba|matsudo.chiba|midori.chiba|mihama.chiba|minamiboso.chiba|mobara.chiba|mutsuzawa.chiba|nagara.chiba|nagareyama.chiba|narashino.chiba|narita.chiba|noda.chiba|oamishirasato.chiba|omigawa.chiba|onjuku.chiba|otaki.chiba|sakae.chiba|sakura.chiba|shimofusa.chiba|shirako.chiba|shiroi.chiba|shisui.chiba|sodegaura.chiba|sosa.chiba|tako.chiba|tateyama.chiba|togane.chiba|tohnosho.chiba|tomisato.chiba|urayasu.chiba|yachimata.chiba|yachiyo.chiba|yokaichiba.chiba|yokoshibahikari.chiba|yotsukaido.chiba|ainan.ehime|honai.ehime|ikata.ehime|imabari.ehime|iyo.ehime|kamijima.ehime|kihoku.ehime|kumakogen.ehime|masaki.ehime|matsuno.ehime|matsuyama.ehime|namikata.ehime|niihama.ehime|ozu.ehime|saijo.ehime|seiyo.ehime|shikokuchuo.ehime|tobe.ehime|toon.ehime|uchiko.ehime|uwajima.ehime|yawatahama.ehime|echizen.fukui|eiheiji.fukui|fukui.fukui|ikeda.fukui|katsuyama.fukui|mihama.fukui|minamiechizen.fukui|obama.fukui|ohi.fukui|ono.fukui|sabae.fukui|sakai.fukui|takahama.fukui|tsuruga.fukui|wakasa.fukui|ashiya.fukuoka|buzen.fukuoka|chikugo.fukuoka|chikuho.fukuoka|chikujo.fukuoka|chikushino.fukuoka|chikuzen.fukuoka|chuo.fukuoka|dazaifu.fukuoka|fukuchi.fukuoka|hakata.fukuoka|higashi.fukuoka|hirokawa.fukuoka|hisayama.fukuoka|iizuka.fukuoka|inatsuki.fukuoka|kaho.fukuoka|kasuga.fukuoka|kasuya.fukuoka|kawara.fukuoka|keisen.fukuoka|koga.fukuoka|kurate.fukuoka|kurogi.fukuoka|kurume.fukuoka|minami.fukuoka|miyako.fukuoka|miyama.fukuoka|miyawaka.fukuoka|mizumaki.fukuoka|munakata.fukuoka|nakagawa.fukuoka|nakama.fukuoka|nishi.fukuoka|nogata.fukuoka|ogori.fukuoka|okagaki.fukuoka|okawa.fukuoka|oki.fukuoka|omuta.fukuoka|onga.fukuoka|onojo.fukuoka|oto.fukuoka|saigawa.fukuoka|sasaguri.fukuoka|shingu.fukuoka|shinyoshitomi.fukuoka|shonai.fukuoka|soeda.fukuoka|sue.fukuoka|tachiarai.fukuoka|tagawa.fukuoka|takata.fukuoka|toho.fukuoka|toyotsu.fukuoka|tsuiki.fukuoka|ukiha.fukuoka|umi.fukuoka|usui.fukuoka|yamada.fukuoka|yame.fukuoka|yanagawa.fukuoka|yukuhashi.fukuoka|aizubange.fukushima|aizumisato.fukushima|aizuwakamatsu.fukushima|asakawa.fukushima|bandai.fukushima|date.fukushima|fukushima.fukushima|furudono.fukushima|futaba.fukushima|hanawa.fukushima|higashi.fukushima|hirata.fukushima|hirono.fukushima|iitate.fukushima|inawashiro.fukushima|ishikawa.fukushima|iwaki.fukushima|izumizaki.fukushima|kagamiishi.fukushima|kaneyama.fukushima|kawamata.fukushima|kitakata.fukushima|kitashiobara.fukushima|koori.fukushima|koriyama.fukushima|kunimi.fukushima|miharu.fukushima|mishima.fukushima|namie.fukushima|nango.fukushima|nishiaizu.fukushima|nishigo.fukushima|okuma.fukushima|omotego.fukushima|ono.fukushima|otama.fukushima|samegawa.fukushima|shimogo.fukushima|shirakawa.fukushima|showa.fukushima|soma.fukushima|sukagawa.fukushima|taishin.fukushima|tamakawa.fukushima|tanagura.fukushima|tenei.fukushima|yabuki.fukushima|yamato.fukushima|yamatsuri.fukushima|yanaizu.fukushima|yugawa.fukushima|anpachi.gifu|ena.gifu|gifu.gifu|ginan.gifu|godo.gifu|gujo.gifu|hashima.gifu|hichiso.gifu|hida.gifu|higashishirakawa.gifu|ibigawa.gifu|ikeda.gifu|kakamigahara.gifu|kani.gifu|kasahara.gifu|kasamatsu.gifu|kawaue.gifu|kitagata.gifu|mino.gifu|minokamo.gifu|mitake.gifu|mizunami.gifu|motosu.gifu|nakatsugawa.gifu|ogaki.gifu|sakahogi.gifu|seki.gifu|sekigahara.gifu|shirakawa.gifu|tajimi.gifu|takayama.gifu|tarui.gifu|toki.gifu|tomika.gifu|wanouchi.gifu|yamagata.gifu|yaotsu.gifu|yoro.gifu|annaka.gunma|chiyoda.gunma|fujioka.gunma|higashiagatsuma.gunma|isesaki.gunma|itakura.gunma|kanna.gunma|kanra.gunma|katashina.gunma|kawaba.gunma|kiryu.gunma|kusatsu.gunma|maebashi.gunma|meiwa.gunma|midori.gunma|minakami.gunma|naganohara.gunma|nakanojo.gunma|nanmoku.gunma|numata.gunma|oizumi.gunma|ora.gunma|ota.gunma|shibukawa.gunma|shimonita.gunma|shinto.gunma|showa.gunma|takasaki.gunma|takayama.gunma|tamamura.gunma|tatebayashi.gunma|tomioka.gunma|tsukiyono.gunma|tsumagoi.gunma|ueno.gunma|yoshioka.gunma|asaminami.hiroshima|daiwa.hiroshima|etajima.hiroshima|fuchu.hiroshima|fukuyama.hiroshima|hatsukaichi.hiroshima|higashihiroshima.hiroshima|hongo.hiroshima|jinsekikogen.hiroshima|kaita.hiroshima|kui.hiroshima|kumano.hiroshima|kure.hiroshima|mihara.hiroshima|miyoshi.hiroshima|naka.hiroshima|onomichi.hiroshima|osakikamijima.hiroshima|otake.hiroshima|saka.hiroshima|sera.hiroshima|seranishi.hiroshima|shinichi.hiroshima|shobara.hiroshima|takehara.hiroshima|abashiri.hokkaido|abira.hokkaido|aibetsu.hokkaido|akabira.hokkaido|akkeshi.hokkaido|asahikawa.hokkaido|ashibetsu.hokkaido|ashoro.hokkaido|assabu.hokkaido|atsuma.hokkaido|bibai.hokkaido|biei.hokkaido|bifuka.hokkaido|bihoro.hokkaido|biratori.hokkaido|chippubetsu.hokkaido|chitose.hokkaido|date.hokkaido|ebetsu.hokkaido|embetsu.hokkaido|eniwa.hokkaido|erimo.hokkaido|esan.hokkaido|esashi.hokkaido|fukagawa.hokkaido|fukushima.hokkaido|furano.hokkaido|furubira.hokkaido|haboro.hokkaido|hakodate.hokkaido|hamatonbetsu.hokkaido|hidaka.hokkaido|higashikagura.hokkaido|higashikawa.hokkaido|hiroo.hokkaido|hokuryu.hokkaido|hokuto.hokkaido|honbetsu.hokkaido|horokanai.hokkaido|horonobe.hokkaido|ikeda.hokkaido|imakane.hokkaido|ishikari.hokkaido|iwamizawa.hokkaido|iwanai.hokkaido|kamifurano.hokkaido|kamikawa.hokkaido|kamishihoro.hokkaido|kamisunagawa.hokkaido|kamoenai.hokkaido|kayabe.hokkaido|kembuchi.hokkaido|kikonai.hokkaido|kimobetsu.hokkaido|kitahiroshima.hokkaido|kitami.hokkaido|kiyosato.hokkaido|koshimizu.hokkaido|kunneppu.hokkaido|kuriyama.hokkaido|kuromatsunai.hokkaido|kushiro.hokkaido|kutchan.hokkaido|kyowa.hokkaido|mashike.hokkaido|matsumae.hokkaido|mikasa.hokkaido|minamifurano.hokkaido|mombetsu.hokkaido|moseushi.hokkaido|mukawa.hokkaido|muroran.hokkaido|naie.hokkaido|nakagawa.hokkaido|nakasatsunai.hokkaido|nakatombetsu.hokkaido|nanae.hokkaido|nanporo.hokkaido|nayoro.hokkaido|nemuro.hokkaido|niikappu.hokkaido|niki.hokkaido|nishiokoppe.hokkaido|noboribetsu.hokkaido|numata.hokkaido|obihiro.hokkaido|obira.hokkaido|oketo.hokkaido|okoppe.hokkaido|otaru.hokkaido|otobe.hokkaido|otofuke.hokkaido|otoineppu.hokkaido|oumu.hokkaido|ozora.hokkaido|pippu.hokkaido|rankoshi.hokkaido|rebun.hokkaido|rikubetsu.hokkaido|rishiri.hokkaido|rishirifuji.hokkaido|saroma.hokkaido|sarufutsu.hokkaido|shakotan.hokkaido|shari.hokkaido|shibecha.hokkaido|shibetsu.hokkaido|shikabe.hokkaido|shikaoi.hokkaido|shimamaki.hokkaido|shimizu.hokkaido|shimokawa.hokkaido|shinshinotsu.hokkaido|shintoku.hokkaido|shiranuka.hokkaido|shiraoi.hokkaido|shiriuchi.hokkaido|sobetsu.hokkaido|sunagawa.hokkaido|taiki.hokkaido|takasu.hokkaido|takikawa.hokkaido|takinoue.hokkaido|teshikaga.hokkaido|tobetsu.hokkaido|tohma.hokkaido|tomakomai.hokkaido|tomari.hokkaido|toya.hokkaido|toyako.hokkaido|toyotomi.hokkaido|toyoura.hokkaido|tsubetsu.hokkaido|tsukigata.hokkaido|urakawa.hokkaido|urausu.hokkaido|uryu.hokkaido|utashinai.hokkaido|wakkanai.hokkaido|wassamu.hokkaido|yakumo.hokkaido|yoichi.hokkaido|aioi.hyogo|akashi.hyogo|ako.hyogo|amagasaki.hyogo|aogaki.hyogo|asago.hyogo|ashiya.hyogo|awaji.hyogo|fukusaki.hyogo|goshiki.hyogo|harima.hyogo|himeji.hyogo|ichikawa.hyogo|inagawa.hyogo|itami.hyogo|kakogawa.hyogo|kamigori.hyogo|kamikawa.hyogo|kasai.hyogo|kasuga.hyogo|kawanishi.hyogo|miki.hyogo|minamiawaji.hyogo|nishinomiya.hyogo|nishiwaki.hyogo|ono.hyogo|sanda.hyogo|sannan.hyogo|sasayama.hyogo|sayo.hyogo|shingu.hyogo|shinonsen.hyogo|shiso.hyogo|sumoto.hyogo|taishi.hyogo|taka.hyogo|takarazuka.hyogo|takasago.hyogo|takino.hyogo|tamba.hyogo|tatsuno.hyogo|toyooka.hyogo|yabu.hyogo|yashiro.hyogo|yoka.hyogo|yokawa.hyogo|ami.ibaraki|asahi.ibaraki|bando.ibaraki|chikusei.ibaraki|daigo.ibaraki|fujishiro.ibaraki|hitachi.ibaraki|hitachinaka.ibaraki|hitachiomiya.ibaraki|hitachiota.ibaraki|ibaraki.ibaraki|ina.ibaraki|inashiki.ibaraki|itako.ibaraki|iwama.ibaraki|joso.ibaraki|kamisu.ibaraki|kasama.ibaraki|kashima.ibaraki|kasumigaura.ibaraki|koga.ibaraki|miho.ibaraki|mito.ibaraki|moriya.ibaraki|naka.ibaraki|namegata.ibaraki|oarai.ibaraki|ogawa.ibaraki|omitama.ibaraki|ryugasaki.ibaraki|sakai.ibaraki|sakuragawa.ibaraki|shimodate.ibaraki|shimotsuma.ibaraki|shirosato.ibaraki|sowa.ibaraki|suifu.ibaraki|takahagi.ibaraki|tamatsukuri.ibaraki|tokai.ibaraki|tomobe.ibaraki|tone.ibaraki|toride.ibaraki|tsuchiura.ibaraki|tsukuba.ibaraki|uchihara.ibaraki|ushiku.ibaraki|yachiyo.ibaraki|yamagata.ibaraki|yawara.ibaraki|yuki.ibaraki|anamizu.ishikawa|hakui.ishikawa|hakusan.ishikawa|kaga.ishikawa|kahoku.ishikawa|kanazawa.ishikawa|kawakita.ishikawa|komatsu.ishikawa|nakanoto.ishikawa|nanao.ishikawa|nomi.ishikawa|nonoichi.ishikawa|noto.ishikawa|shika.ishikawa|suzu.ishikawa|tsubata.ishikawa|tsurugi.ishikawa|uchinada.ishikawa|wajima.ishikawa|fudai.iwate|fujisawa.iwate|hanamaki.iwate|hiraizumi.iwate|hirono.iwate|ichinohe.iwate|ichinoseki.iwate|iwaizumi.iwate|iwate.iwate|joboji.iwate|kamaishi.iwate|kanegasaki.iwate|karumai.iwate|kawai.iwate|kitakami.iwate|kuji.iwate|kunohe.iwate|kuzumaki.iwate|miyako.iwate|mizusawa.iwate|morioka.iwate|ninohe.iwate|noda.iwate|ofunato.iwate|oshu.iwate|otsuchi.iwate|rikuzentakata.iwate|shiwa.iwate|shizukuishi.iwate|sumita.iwate|tanohata.iwate|tono.iwate|yahaba.iwate|yamada.iwate|ayagawa.kagawa|higashikagawa.kagawa|kanonji.kagawa|kotohira.kagawa|manno.kagawa|marugame.kagawa|mitoyo.kagawa|naoshima.kagawa|sanuki.kagawa|tadotsu.kagawa|takamatsu.kagawa|tonosho.kagawa|uchinomi.kagawa|utazu.kagawa|zentsuji.kagawa|akune.kagoshima|amami.kagoshima|hioki.kagoshima|isa.kagoshima|isen.kagoshima|izumi.kagoshima|kagoshima.kagoshima|kanoya.kagoshima|kawanabe.kagoshima|kinko.kagoshima|kouyama.kagoshima|makurazaki.kagoshima|matsumoto.kagoshima|minamitane.kagoshima|nakatane.kagoshima|nishinoomote.kagoshima|satsumasendai.kagoshima|soo.kagoshima|tarumizu.kagoshima|yusui.kagoshima|aikawa.kanagawa|atsugi.kanagawa|ayase.kanagawa|chigasaki.kanagawa|ebina.kanagawa|fujisawa.kanagawa|hadano.kanagawa|hakone.kanagawa|hiratsuka.kanagawa|isehara.kanagawa|kaisei.kanagawa|kamakura.kanagawa|kiyokawa.kanagawa|matsuda.kanagawa|minamiashigara.kanagawa|miura.kanagawa|nakai.kanagawa|ninomiya.kanagawa|odawara.kanagawa|oi.kanagawa|oiso.kanagawa|sagamihara.kanagawa|samukawa.kanagawa|tsukui.kanagawa|yamakita.kanagawa|yamato.kanagawa|yokosuka.kanagawa|yugawara.kanagawa|zama.kanagawa|zushi.kanagawa|aki.kochi|geisei.kochi|hidaka.kochi|higashitsuno.kochi|ino.kochi|kagami.kochi|kami.kochi|kitagawa.kochi|kochi.kochi|mihara.kochi|motoyama.kochi|muroto.kochi|nahari.kochi|nakamura.kochi|nankoku.kochi|nishitosa.kochi|niyodogawa.kochi|ochi.kochi|okawa.kochi|otoyo.kochi|otsuki.kochi|sakawa.kochi|sukumo.kochi|susaki.kochi|tosa.kochi|tosashimizu.kochi|toyo.kochi|tsuno.kochi|umaji.kochi|yasuda.kochi|yusuhara.kochi|amakusa.kumamoto|arao.kumamoto|aso.kumamoto|choyo.kumamoto|gyokuto.kumamoto|hitoyoshi.kumamoto|kamiamakusa.kumamoto|kashima.kumamoto|kikuchi.kumamoto|kosa.kumamoto|kumamoto.kumamoto|mashiki.kumamoto|mifune.kumamoto|minamata.kumamoto|minamioguni.kumamoto|nagasu.kumamoto|nishihara.kumamoto|oguni.kumamoto|ozu.kumamoto|sumoto.kumamoto|takamori.kumamoto|uki.kumamoto|uto.kumamoto|yamaga.kumamoto|yamato.kumamoto|yatsushiro.kumamoto|ayabe.kyoto|fukuchiyama.kyoto|higashiyama.kyoto|ide.kyoto|ine.kyoto|joyo.kyoto|kameoka.kyoto|kamo.kyoto|kita.kyoto|kizu.kyoto|kumiyama.kyoto|kyotamba.kyoto|kyotanabe.kyoto|kyotango.kyoto|maizuru.kyoto|minami.kyoto|minamiyamashiro.kyoto|miyazu.kyoto|muko.kyoto|nagaokakyo.kyoto|nakagyo.kyoto|nantan.kyoto|oyamazaki.kyoto|sakyo.kyoto|seika.kyoto|tanabe.kyoto|uji.kyoto|ujitawara.kyoto|wazuka.kyoto|yamashina.kyoto|yawata.kyoto|asahi.mie|inabe.mie|ise.mie|kameyama.mie|kawagoe.mie|kiho.mie|kisosaki.mie|kiwa.mie|komono.mie|kumano.mie|kuwana.mie|matsusaka.mie|meiwa.mie|mihama.mie|minamiise.mie|misugi.mie|miyama.mie|nabari.mie|shima.mie|suzuka.mie|tado.mie|taiki.mie|taki.mie|tamaki.mie|toba.mie|tsu.mie|udono.mie|ureshino.mie|watarai.mie|yokkaichi.mie|furukawa.miyagi|higashimatsushima.miyagi|ishinomaki.miyagi|iwanuma.miyagi|kakuda.miyagi|kami.miyagi|kawasaki.miyagi|kesennuma.miyagi|marumori.miyagi|matsushima.miyagi|minamisanriku.miyagi|misato.miyagi|murata.miyagi|natori.miyagi|ogawara.miyagi|ohira.miyagi|onagawa.miyagi|osaki.miyagi|rifu.miyagi|semine.miyagi|shibata.miyagi|shichikashuku.miyagi|shikama.miyagi|shiogama.miyagi|shiroishi.miyagi|tagajo.miyagi|taiwa.miyagi|tome.miyagi|tomiya.miyagi|wakuya.miyagi|watari.miyagi|yamamoto.miyagi|zao.miyagi|aya.miyazaki|ebino.miyazaki|gokase.miyazaki|hyuga.miyazaki|kadogawa.miyazaki|kawaminami.miyazaki|kijo.miyazaki|kitagawa.miyazaki|kitakata.miyazaki|kitaura.miyazaki|kobayashi.miyazaki|kunitomi.miyazaki|kushima.miyazaki|mimata.miyazaki|miyakonojo.miyazaki|miyazaki.miyazaki|morotsuka.miyazaki|nichinan.miyazaki|nishimera.miyazaki|nobeoka.miyazaki|saito.miyazaki|shiiba.miyazaki|shintomi.miyazaki|takaharu.miyazaki|takanabe.miyazaki|takazaki.miyazaki|tsuno.miyazaki|achi.nagano|agematsu.nagano|anan.nagano|aoki.nagano|asahi.nagano|azumino.nagano|chikuhoku.nagano|chikuma.nagano|chino.nagano|fujimi.nagano|hakuba.nagano|hara.nagano|hiraya.nagano|iida.nagano|iijima.nagano|iiyama.nagano|iizuna.nagano|ikeda.nagano|ikusaka.nagano|ina.nagano|karuizawa.nagano|kawakami.nagano|kiso.nagano|kisofukushima.nagano|kitaaiki.nagano|komagane.nagano|komoro.nagano|matsukawa.nagano|matsumoto.nagano|miasa.nagano|minamiaiki.nagano|minamimaki.nagano|minamiminowa.nagano|minowa.nagano|miyada.nagano|miyota.nagano|mochizuki.nagano|nagano.nagano|nagawa.nagano|nagiso.nagano|nakagawa.nagano|nakano.nagano|nozawaonsen.nagano|obuse.nagano|ogawa.nagano|okaya.nagano|omachi.nagano|omi.nagano|ookuwa.nagano|ooshika.nagano|otaki.nagano|otari.nagano|sakae.nagano|sakaki.nagano|saku.nagano|sakuho.nagano|shimosuwa.nagano|shinanomachi.nagano|shiojiri.nagano|suwa.nagano|suzaka.nagano|takagi.nagano|takamori.nagano|takayama.nagano|tateshina.nagano|tatsuno.nagano|togakushi.nagano|togura.nagano|tomi.nagano|ueda.nagano|wada.nagano|yamagata.nagano|yamanouchi.nagano|yasaka.nagano|yasuoka.nagano|chijiwa.nagasaki|futsu.nagasaki|goto.nagasaki|hasami.nagasaki|hirado.nagasaki|iki.nagasaki|isahaya.nagasaki|kawatana.nagasaki|kuchinotsu.nagasaki|matsuura.nagasaki|nagasaki.nagasaki|obama.nagasaki|omura.nagasaki|oseto.nagasaki|saikai.nagasaki|sasebo.nagasaki|seihi.nagasaki|shimabara.nagasaki|shinkamigoto.nagasaki|togitsu.nagasaki|tsushima.nagasaki|unzen.nagasaki|ando.nara|gose.nara|heguri.nara|higashiyoshino.nara|ikaruga.nara|ikoma.nara|kamikitayama.nara|kanmaki.nara|kashiba.nara|kashihara.nara|katsuragi.nara|kawai.nara|kawakami.nara|kawanishi.nara|koryo.nara|kurotaki.nara|mitsue.nara|miyake.nara|nara.nara|nosegawa.nara|oji.nara|ouda.nara|oyodo.nara|sakurai.nara|sango.nara|shimoichi.nara|shimokitayama.nara|shinjo.nara|soni.nara|takatori.nara|tawaramoto.nara|tenkawa.nara|tenri.nara|uda.nara|yamatokoriyama.nara|yamatotakada.nara|yamazoe.nara|yoshino.nara|aga.niigata|agano.niigata|gosen.niigata|itoigawa.niigata|izumozaki.niigata|joetsu.niigata|kamo.niigata|kariwa.niigata|kashiwazaki.niigata|minamiuonuma.niigata|mitsuke.niigata|muika.niigata|murakami.niigata|myoko.niigata|nagaoka.niigata|niigata.niigata|ojiya.niigata|omi.niigata|sado.niigata|sanjo.niigata|seiro.niigata|seirou.niigata|sekikawa.niigata|shibata.niigata|tagami.niigata|tainai.niigata|tochio.niigata|tokamachi.niigata|tsubame.niigata|tsunan.niigata|uonuma.niigata|yahiko.niigata|yoita.niigata|yuzawa.niigata|beppu.oita|bungoono.oita|bungotakada.oita|hasama.oita|hiji.oita|himeshima.oita|hita.oita|kamitsue.oita|kokonoe.oita|kuju.oita|kunisaki.oita|kusu.oita|oita.oita|saiki.oita|taketa.oita|tsukumi.oita|usa.oita|usuki.oita|yufu.oita|akaiwa.okayama|asakuchi.okayama|bizen.okayama|hayashima.okayama|ibara.okayama|kagamino.okayama|kasaoka.okayama|kibichuo.okayama|kumenan.okayama|kurashiki.okayama|maniwa.okayama|misaki.okayama|nagi.okayama|niimi.okayama|nishiawakura.okayama|okayama.okayama|satosho.okayama|setouchi.okayama|shinjo.okayama|shoo.okayama|soja.okayama|takahashi.okayama|tamano.okayama|tsuyama.okayama|wake.okayama|yakage.okayama|aguni.okinawa|ginowan.okinawa|ginoza.okinawa|gushikami.okinawa|haebaru.okinawa|higashi.okinawa|hirara.okinawa|iheya.okinawa|ishigaki.okinawa|ishikawa.okinawa|itoman.okinawa|izena.okinawa|kadena.okinawa|kin.okinawa|kitadaito.okinawa|kitanakagusuku.okinawa|kumejima.okinawa|kunigami.okinawa|minamidaito.okinawa|motobu.okinawa|nago.okinawa|naha.okinawa|nakagusuku.okinawa|nakijin.okinawa|nanjo.okinawa|nishihara.okinawa|ogimi.okinawa|okinawa.okinawa|onna.okinawa|shimoji.okinawa|taketomi.okinawa|tarama.okinawa|tokashiki.okinawa|tomigusuku.okinawa|tonaki.okinawa|urasoe.okinawa|uruma.okinawa|yaese.okinawa|yomitan.okinawa|yonabaru.okinawa|yonaguni.okinawa|zamami.okinawa|abeno.osaka|chihayaakasaka.osaka|chuo.osaka|daito.osaka|fujiidera.osaka|habikino.osaka|hannan.osaka|higashiosaka.osaka|higashisumiyoshi.osaka|higashiyodogawa.osaka|hirakata.osaka|ibaraki.osaka|ikeda.osaka|izumi.osaka|izumiotsu.osaka|izumisano.osaka|kadoma.osaka|kaizuka.osaka|kanan.osaka|kashiwara.osaka|katano.osaka|kawachinagano.osaka|kishiwada.osaka|kita.osaka|kumatori.osaka|matsubara.osaka|minato.osaka|minoh.osaka|misaki.osaka|moriguchi.osaka|neyagawa.osaka|nishi.osaka|nose.osaka|osakasayama.osaka|sakai.osaka|sayama.osaka|sennan.osaka|settsu.osaka|shijonawate.osaka|shimamoto.osaka|suita.osaka|tadaoka.osaka|taishi.osaka|tajiri.osaka|takaishi.osaka|takatsuki.osaka|tondabayashi.osaka|toyonaka.osaka|toyono.osaka|yao.osaka|ariake.saga|arita.saga|fukudomi.saga|genkai.saga|hamatama.saga|hizen.saga|imari.saga|kamimine.saga|kanzaki.saga|karatsu.saga|kashima.saga|kitagata.saga|kitahata.saga|kiyama.saga|kouhoku.saga|kyuragi.saga|nishiarita.saga|ogi.saga|omachi.saga|ouchi.saga|saga.saga|shiroishi.saga|taku.saga|tara.saga|tosu.saga|yoshinogari.saga|arakawa.saitama|asaka.saitama|chichibu.saitama|fujimi.saitama|fujimino.saitama|fukaya.saitama|hanno.saitama|hanyu.saitama|hasuda.saitama|hatogaya.saitama|hatoyama.saitama|hidaka.saitama|higashichichibu.saitama|higashimatsuyama.saitama|honjo.saitama|ina.saitama|iruma.saitama|iwatsuki.saitama|kamiizumi.saitama|kamikawa.saitama|kamisato.saitama|kasukabe.saitama|kawagoe.saitama|kawaguchi.saitama|kawajima.saitama|kazo.saitama|kitamoto.saitama|koshigaya.saitama|kounosu.saitama|kuki.saitama|kumagaya.saitama|matsubushi.saitama|minano.saitama|misato.saitama|miyashiro.saitama|miyoshi.saitama|moroyama.saitama|nagatoro.saitama|namegawa.saitama|niiza.saitama|ogano.saitama|ogawa.saitama|ogose.saitama|okegawa.saitama|omiya.saitama|otaki.saitama|ranzan.saitama|ryokami.saitama|saitama.saitama|sakado.saitama|satte.saitama|sayama.saitama|shiki.saitama|shiraoka.saitama|soka.saitama|sugito.saitama|toda.saitama|tokigawa.saitama|tokorozawa.saitama|tsurugashima.saitama|urawa.saitama|warabi.saitama|yashio.saitama|yokoze.saitama|yono.saitama|yorii.saitama|yoshida.saitama|yoshikawa.saitama|yoshimi.saitama|aisho.shiga|gamo.shiga|higashiomi.shiga|hikone.shiga|koka.shiga|konan.shiga|kosei.shiga|koto.shiga|kusatsu.shiga|maibara.shiga|moriyama.shiga|nagahama.shiga|nishiazai.shiga|notogawa.shiga|omihachiman.shiga|otsu.shiga|ritto.shiga|ryuoh.shiga|takashima.shiga|takatsuki.shiga|torahime.shiga|toyosato.shiga|yasu.shiga|akagi.shimane|ama.shimane|gotsu.shimane|hamada.shimane|higashiizumo.shimane|hikawa.shimane|hikimi.shimane|izumo.shimane|kakinoki.shimane|masuda.shimane|matsue.shimane|misato.shimane|nishinoshima.shimane|ohda.shimane|okinoshima.shimane|okuizumo.shimane|shimane.shimane|tamayu.shimane|tsuwano.shimane|unnan.shimane|yakumo.shimane|yasugi.shimane|yatsuka.shimane|arai.shizuoka|atami.shizuoka|fuji.shizuoka|fujieda.shizuoka|fujikawa.shizuoka|fujinomiya.shizuoka|fukuroi.shizuoka|gotemba.shizuoka|haibara.shizuoka|hamamatsu.shizuoka|higashiizu.shizuoka|ito.shizuoka|iwata.shizuoka|izu.shizuoka|izunokuni.shizuoka|kakegawa.shizuoka|kannami.shizuoka|kawanehon.shizuoka|kawazu.shizuoka|kikugawa.shizuoka|kosai.shizuoka|makinohara.shizuoka|matsuzaki.shizuoka|minamiizu.shizuoka|mishima.shizuoka|morimachi.shizuoka|nishiizu.shizuoka|numazu.shizuoka|omaezaki.shizuoka|shimada.shizuoka|shimizu.shizuoka|shimoda.shizuoka|shizuoka.shizuoka|susono.shizuoka|yaizu.shizuoka|yoshida.shizuoka|ashikaga.tochigi|bato.tochigi|haga.tochigi|ichikai.tochigi|iwafune.tochigi|kaminokawa.tochigi|kanuma.tochigi|karasuyama.tochigi|kuroiso.tochigi|mashiko.tochigi|mibu.tochigi|moka.tochigi|motegi.tochigi|nasu.tochigi|nasushiobara.tochigi|nikko.tochigi|nishikata.tochigi|nogi.tochigi|ohira.tochigi|ohtawara.tochigi|oyama.tochigi|sakura.tochigi|sano.tochigi|shimotsuke.tochigi|shioya.tochigi|takanezawa.tochigi|tochigi.tochigi|tsuga.tochigi|ujiie.tochigi|utsunomiya.tochigi|yaita.tochigi|aizumi.tokushima|anan.tokushima|ichiba.tokushima|itano.tokushima|kainan.tokushima|komatsushima.tokushima|matsushige.tokushima|mima.tokushima|minami.tokushima|miyoshi.tokushima|mugi.tokushima|nakagawa.tokushima|naruto.tokushima|sanagochi.tokushima|shishikui.tokushima|tokushima.tokushima|wajiki.tokushima|adachi.tokyo|akiruno.tokyo|akishima.tokyo|aogashima.tokyo|arakawa.tokyo|bunkyo.tokyo|chiyoda.tokyo|chofu.tokyo|chuo.tokyo|edogawa.tokyo|fuchu.tokyo|fussa.tokyo|hachijo.tokyo|hachioji.tokyo|hamura.tokyo|higashikurume.tokyo|higashimurayama.tokyo|higashiyamato.tokyo|hino.tokyo|hinode.tokyo|hinohara.tokyo|inagi.tokyo|itabashi.tokyo|katsushika.tokyo|kita.tokyo|kiyose.tokyo|kodaira.tokyo|koganei.tokyo|kokubunji.tokyo|komae.tokyo|koto.tokyo|kouzushima.tokyo|kunitachi.tokyo|machida.tokyo|meguro.tokyo|minato.tokyo|mitaka.tokyo|mizuho.tokyo|musashimurayama.tokyo|musashino.tokyo|nakano.tokyo|nerima.tokyo|ogasawara.tokyo|okutama.tokyo|ome.tokyo|oshima.tokyo|ota.tokyo|setagaya.tokyo|shibuya.tokyo|shinagawa.tokyo|shinjuku.tokyo|suginami.tokyo|sumida.tokyo|tachikawa.tokyo|taito.tokyo|tama.tokyo|toshima.tokyo|chizu.tottori|hino.tottori|kawahara.tottori|koge.tottori|kotoura.tottori|misasa.tottori|nanbu.tottori|nichinan.tottori|sakaiminato.tottori|tottori.tottori|wakasa.tottori|yazu.tottori|yonago.tottori|asahi.toyama|fuchu.toyama|fukumitsu.toyama|funahashi.toyama|himi.toyama|imizu.toyama|inami.toyama|johana.toyama|kamiichi.toyama|kurobe.toyama|nakaniikawa.toyama|namerikawa.toyama|nanto.toyama|nyuzen.toyama|oyabe.toyama|taira.toyama|takaoka.toyama|tateyama.toyama|toga.toyama|tonami.toyama|toyama.toyama|unazuki.toyama|uozu.toyama|yamada.toyama|arida.wakayama|aridagawa.wakayama|gobo.wakayama|hashimoto.wakayama|hidaka.wakayama|hirogawa.wakayama|inami.wakayama|iwade.wakayama|kainan.wakayama|kamitonda.wakayama|katsuragi.wakayama|kimino.wakayama|kinokawa.wakayama|kitayama.wakayama|koya.wakayama|koza.wakayama|kozagawa.wakayama|kudoyama.wakayama|kushimoto.wakayama|mihama.wakayama|misato.wakayama|nachikatsuura.wakayama|shingu.wakayama|shirahama.wakayama|taiji.wakayama|tanabe.wakayama|wakayama.wakayama|yuasa.wakayama|yura.wakayama|asahi.yamagata|funagata.yamagata|higashine.yamagata|iide.yamagata|kahoku.yamagata|kaminoyama.yamagata|kaneyama.yamagata|kawanishi.yamagata|mamurogawa.yamagata|mikawa.yamagata|murayama.yamagata|nagai.yamagata|nakayama.yamagata|nanyo.yamagata|nishikawa.yamagata|obanazawa.yamagata|oe.yamagata|oguni.yamagata|ohkura.yamagata|oishida.yamagata|sagae.yamagata|sakata.yamagata|sakegawa.yamagata|shinjo.yamagata|shirataka.yamagata|shonai.yamagata|takahata.yamagata|tendo.yamagata|tozawa.yamagata|tsuruoka.yamagata|yamagata.yamagata|yamanobe.yamagata|yonezawa.yamagata|yuza.yamagata|abu.yamaguchi|hagi.yamaguchi|hikari.yamaguchi|hofu.yamaguchi|iwakuni.yamaguchi|kudamatsu.yamaguchi|mitou.yamaguchi|nagato.yamaguchi|oshima.yamaguchi|shimonoseki.yamaguchi|shunan.yamaguchi|tabuse.yamaguchi|tokuyama.yamaguchi|toyota.yamaguchi|ube.yamaguchi|yuu.yamaguchi|chuo.yamanashi|doshi.yamanashi|fuefuki.yamanashi|fujikawa.yamanashi|fujikawaguchiko.yamanashi|fujiyoshida.yamanashi|hayakawa.yamanashi|hokuto.yamanashi|ichikawamisato.yamanashi|kai.yamanashi|kofu.yamanashi|koshu.yamanashi|kosuge.yamanashi|minami-alps.yamanashi|minobu.yamanashi|nakamichi.yamanashi|nanbu.yamanashi|narusawa.yamanashi|nirasaki.yamanashi|nishikatsura.yamanashi|oshino.yamanashi|otsuki.yamanashi|showa.yamanashi|tabayama.yamanashi|tsuru.yamanashi|uenohara.yamanashi|yamanakako.yamanashi|yamanashi.yamanashi|blogspot","ke":"*|blogspot.co","kg":"org|net|com|edu|gov|mil","kh":"*","ki":"edu|biz|net|org|gov|info|com","km":"org|nom|gov|prd|tm|edu|mil|ass|com|coop|asso|presse|medecin|notaires|pharmaciens|veterinaire|gouv","kn":"net|org|edu|gov","kp":"com|edu|gov|org|rep|tra","kr":"ac|co|es|go|hs|kg|mil|ms|ne|or|pe|re|sc|busan|chungbuk|chungnam|daegu|daejeon|gangwon|gwangju|gyeongbuk|gyeonggi|gyeongnam|incheon|jeju|jeonbuk|jeonnam|seoul|ulsan|blogspot","kw":"*","ky":"edu|gov|com|org|net","kz":"org|edu|net|gov|mil|com","la":"int|net|info|edu|gov|per|com|org|c","lb":"com|edu|gov|net|org","lc":"com|net|co|org|edu|gov","li":"blogspot","lk":"gov|sch|net|int|com|org|edu|ngo|soc|web|ltd|assn|grp|hotel|ac","lr":"com|edu|gov|org|net","ls":"co|org","lt":"gov|blogspot","lu":"blogspot","lv":"com|edu|gov|org|mil|id|net|asn|conf","ly":"com|net|gov|plc|edu|sch|med|org|id","ma":"co|net|gov|org|ac|press","mc":"tm|asso","md":"blogspot","me":"co|net|org|edu|ac|gov|its|priv","mg":"org|nom|gov|prd|tm|edu|mil|com|co","mh":"","mil":"","mk":"com|org|net|edu|gov|inf|name|blogspot","ml":"com|edu|gouv|gov|net|org|presse","mm":"*","mn":"gov|edu|org|nyc","mo":"com|net|org|edu|gov","mobi":"","mp":"","mq":"","mr":"gov|blogspot","ms":"com|edu|gov|net|org","mt":"com|edu|net|org|blogspot.com","mu":"com|net|org|gov|ac|co|or","museum":"academy|agriculture|air|airguard|alabama|alaska|amber|ambulance|american|americana|americanantiques|americanart|amsterdam|and|annefrank|anthro|anthropology|antiques|aquarium|arboretum|archaeological|archaeology|architecture|art|artanddesign|artcenter|artdeco|arteducation|artgallery|arts|artsandcrafts|asmatart|assassination|assisi|association|astronomy|atlanta|austin|australia|automotive|aviation|axis|badajoz|baghdad|bahn|bale|baltimore|barcelona|baseball|basel|baths|bauern|beauxarts|beeldengeluid|bellevue|bergbau|berkeley|berlin|bern|bible|bilbao|bill|birdart|birthplace|bonn|boston|botanical|botanicalgarden|botanicgarden|botany|brandywinevalley|brasil|bristol|british|britishcolumbia|broadcast|brunel|brussel|brussels|bruxelles|building|burghof|bus|bushey|cadaques|california|cambridge|can|canada|capebreton|carrier|cartoonart|casadelamoneda|castle|castres|celtic|center|chattanooga|cheltenham|chesapeakebay|chicago|children|childrens|childrensgarden|chiropractic|chocolate|christiansburg|cincinnati|cinema|circus|civilisation|civilization|civilwar|clinton|clock|coal|coastaldefence|cody|coldwar|collection|colonialwilliamsburg|coloradoplateau|columbia|columbus|communication|communications|community|computer|computerhistory|xn--comunicaes-v6a2o|contemporary|contemporaryart|convent|copenhagen|corporation|xn--correios-e-telecomunicaes-ghc29a|corvette|costume|countryestate|county|crafts|cranbrook|creation|cultural|culturalcenter|culture|cyber|cymru|dali|dallas|database|ddr|decorativearts|delaware|delmenhorst|denmark|depot|design|detroit|dinosaur|discovery|dolls|donostia|durham|eastafrica|eastcoast|education|educational|egyptian|eisenbahn|elburg|elvendrell|embroidery|encyclopedic|england|entomology|environment|environmentalconservation|epilepsy|essex|estate|ethnology|exeter|exhibition|family|farm|farmequipment|farmers|farmstead|field|figueres|filatelia|film|fineart|finearts|finland|flanders|florida|force|fortmissoula|fortworth|foundation|francaise|frankfurt|franziskaner|freemasonry|freiburg|fribourg|frog|fundacio|furniture|gallery|garden|gateway|geelvinck|gemological|geology|georgia|giessen|glas|glass|gorge|grandrapids|graz|guernsey|halloffame|hamburg|handson|harvestcelebration|hawaii|health|heimatunduhren|hellas|helsinki|hembygdsforbund|heritage|histoire|historical|historicalsociety|historichouses|historisch|historisches|history|historyofscience|horology|house|humanities|illustration|imageandsound|indian|indiana|indianapolis|indianmarket|intelligence|interactive|iraq|iron|isleofman|jamison|jefferson|jerusalem|jewelry|jewish|jewishart|jfk|journalism|judaica|judygarland|juedisches|juif|karate|karikatur|kids|koebenhavn|koeln|kunst|kunstsammlung|kunstunddesign|labor|labour|lajolla|lancashire|landes|lans|xn--lns-qla|larsson|lewismiller|lincoln|linz|living|livinghistory|localhistory|london|losangeles|louvre|loyalist|lucerne|luxembourg|luzern|mad|madrid|mallorca|manchester|mansion|mansions|manx|marburg|maritime|maritimo|maryland|marylhurst|media|medical|medizinhistorisches|meeres|memorial|mesaverde|michigan|midatlantic|military|mill|miners|mining|minnesota|missile|missoula|modern|moma|money|monmouth|monticello|montreal|moscow|motorcycle|muenchen|muenster|mulhouse|muncie|museet|museumcenter|museumvereniging|music|national|nationalfirearms|nationalheritage|nativeamerican|naturalhistory|naturalhistorymuseum|naturalsciences|nature|naturhistorisches|natuurwetenschappen|naumburg|naval|nebraska|neues|newhampshire|newjersey|newmexico|newport|newspaper|newyork|niepce|norfolk|north|nrw|nuernberg|nuremberg|nyc|nyny|oceanographic|oceanographique|omaha|online|ontario|openair|oregon|oregontrail|otago|oxford|pacific|paderborn|palace|paleo|palmsprings|panama|paris|pasadena|pharmacy|philadelphia|philadelphiaarea|philately|phoenix|photography|pilots|pittsburgh|planetarium|plantation|plants|plaza|portal|portland|portlligat|posts-and-telecommunications|preservation|presidio|press|project|public|pubol|quebec|railroad|railway|research|resistance|riodejaneiro|rochester|rockart|roma|russia|saintlouis|salem|salvadordali|salzburg|sandiego|sanfrancisco|santabarbara|santacruz|santafe|saskatchewan|satx|savannahga|schlesisches|schoenbrunn|schokoladen|school|schweiz|science|scienceandhistory|scienceandindustry|sciencecenter|sciencecenters|science-fiction|sciencehistory|sciences|sciencesnaturelles|scotland|seaport|settlement|settlers|shell|sherbrooke|sibenik|silk|ski|skole|society|sologne|soundandvision|southcarolina|southwest|space|spy|square|stadt|stalbans|starnberg|state|stateofdelaware|station|steam|steiermark|stjohn|stockholm|stpetersburg|stuttgart|suisse|surgeonshall|surrey|svizzera|sweden|sydney|tank|tcm|technology|telekommunikation|television|texas|textile|theater|time|timekeeping|topology|torino|touch|town|transport|tree|trolley|trust|trustee|uhren|ulm|undersea|university|usa|usantiques|usarts|uscountryestate|usculture|usdecorativearts|usgarden|ushistory|ushuaia|uslivinghistory|utah|uvic|valley|vantaa|versailles|viking|village|virginia|virtual|virtuel|vlaanderen|volkenkunde|wales|wallonie|war|washingtondc|watchandclock|watch-and-clock|western|westfalen|whaling|wildlife|williamsburg|windmill|workshop|york|yorkshire|yosemite|youth|zoological|zoology|xn--9dbhblg6di|xn--h1aegh","mv":"aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro","mw":"ac|biz|co|com|coop|edu|gov|int|museum|net|org","mx":"com|org|gob|edu|net|blogspot","my":"com|net|org|gov|edu|mil|name|blogspot","mz":"*|!teledata","na":"info|pro|name|school|or|dr|us|mx|ca|in|cc|tv|ws|mobi|co|com|org","name":"forgot.her|forgot.his","nc":"asso","ne":"","net":"cloudfront|gb|hu|jp|se|uk|in|cdn77-ssl|r.cdn77|at-band-camp|blogdns|broke-it|buyshouses|dnsalias|dnsdojo|does-it|dontexist|dynalias|dynathome|endofinternet|from-az|from-co|from-la|from-ny|gets-it|ham-radio-op|homeftp|homeip|homelinux|homeunix|in-the-band|is-a-chef|is-a-geek|isa-geek|kicks-ass|office-on-the|podzone|scrapper-site|selfip|sells-it|servebbs|serveftp|thruhere|webhop|a.ssl.fastly|b.ssl.fastly|global.ssl.fastly|a.prod.fastly|global.prod.fastly|azurewebsites|azure-mobile|cloudapp|za","nf":"com|net|per|rec|web|arts|firm|info|other|store","ng":"com|edu|name|net|org|sch|gov|mil|mobi|blogspot.com","ni":"*","nl":"bv|co|blogspot","no":"fhs|vgs|fylkesbibl|folkebibl|museum|idrett|priv|mil|stat|dep|kommune|herad|aa|ah|bu|fm|hl|hm|jan-mayen|mr|nl|nt|of|ol|oslo|rl|sf|st|svalbard|tm|tr|va|vf|gs.aa|gs.ah|gs.bu|gs.fm|gs.hl|gs.hm|gs.jan-mayen|gs.mr|gs.nl|gs.nt|gs.of|gs.ol|gs.oslo|gs.rl|gs.sf|gs.st|gs.svalbard|gs.tm|gs.tr|gs.va|gs.vf|akrehamn|xn--krehamn-dxa|algard|xn--lgrd-poac|arna|brumunddal|bryne|bronnoysund|xn--brnnysund-m8ac|drobak|xn--drbak-wua|egersund|fetsund|floro|xn--flor-jra|fredrikstad|hokksund|honefoss|xn--hnefoss-q1a|jessheim|jorpeland|xn--jrpeland-54a|kirkenes|kopervik|krokstadelva|langevag|xn--langevg-jxa|leirvik|mjondalen|xn--mjndalen-64a|mo-i-rana|mosjoen|xn--mosjen-eya|nesoddtangen|orkanger|osoyro|xn--osyro-wua|raholt|xn--rholt-mra|sandnessjoen|xn--sandnessjen-ogb|skedsmokorset|slattum|spjelkavik|stathelle|stavern|stjordalshalsen|xn--stjrdalshalsen-sqb|tananger|tranby|vossevangen|afjord|xn--fjord-lra|agdenes|al|xn--l-1fa|alesund|xn--lesund-hua|alstahaug|alta|xn--lt-liac|alaheadju|xn--laheadju-7ya|alvdal|amli|xn--mli-tla|amot|xn--mot-tla|andebu|andoy|xn--andy-ira|andasuolo|ardal|xn--rdal-poa|aremark|arendal|xn--s-1fa|aseral|xn--seral-lra|asker|askim|askvoll|askoy|xn--asky-ira|asnes|xn--snes-poa|audnedaln|aukra|aure|aurland|aurskog-holand|xn--aurskog-hland-jnb|austevoll|austrheim|averoy|xn--avery-yua|balestrand|ballangen|balat|xn--blt-elab|balsfjord|bahccavuotna|xn--bhccavuotna-k7a|bamble|bardu|beardu|beiarn|bajddar|xn--bjddar-pta|baidar|xn--bidr-5nac|berg|bergen|berlevag|xn--berlevg-jxa|bearalvahki|xn--bearalvhki-y4a|bindal|birkenes|bjarkoy|xn--bjarky-fya|bjerkreim|bjugn|bodo|xn--bod-2na|badaddja|xn--bdddj-mrabd|budejju|bokn|bremanger|bronnoy|xn--brnny-wuac|bygland|bykle|barum|xn--brum-voa|bo.telemark|xn--b-5ga.telemark|bo.nordland|xn--b-5ga.nordland|bievat|xn--bievt-0qa|bomlo|xn--bmlo-gra|batsfjord|xn--btsfjord-9za|bahcavuotna|xn--bhcavuotna-s4a|dovre|drammen|drangedal|dyroy|xn--dyry-ira|donna|xn--dnna-gra|eid|eidfjord|eidsberg|eidskog|eidsvoll|eigersund|elverum|enebakk|engerdal|etne|etnedal|evenes|evenassi|xn--eveni-0qa01ga|evje-og-hornnes|farsund|fauske|fuossko|fuoisku|fedje|fet|finnoy|xn--finny-yua|fitjar|fjaler|fjell|flakstad|flatanger|flekkefjord|flesberg|flora|fla|xn--fl-zia|folldal|forsand|fosnes|frei|frogn|froland|frosta|frana|xn--frna-woa|froya|xn--frya-hra|fusa|fyresdal|forde|xn--frde-gra|gamvik|gangaviika|xn--ggaviika-8ya47h|gaular|gausdal|gildeskal|xn--gildeskl-g0a|giske|gjemnes|gjerdrum|gjerstad|gjesdal|gjovik|xn--gjvik-wua|gloppen|gol|gran|grane|granvin|gratangen|grimstad|grong|kraanghke|xn--kranghke-b0a|grue|gulen|hadsel|halden|halsa|hamar|hamaroy|habmer|xn--hbmer-xqa|hapmir|xn--hpmir-xqa|hammerfest|hammarfeasta|xn--hmmrfeasta-s4ac|haram|hareid|harstad|hasvik|aknoluokta|xn--koluokta-7ya57h|hattfjelldal|aarborte|haugesund|hemne|hemnes|hemsedal|heroy.more-og-romsdal|xn--hery-ira.xn--mre-og-romsdal-qqb|heroy.nordland|xn--hery-ira.nordland|hitra|hjartdal|hjelmeland|hobol|xn--hobl-ira|hof|hol|hole|holmestrand|holtalen|xn--holtlen-hxa|hornindal|horten|hurdal|hurum|hvaler|hyllestad|hagebostad|xn--hgebostad-g3a|hoyanger|xn--hyanger-q1a|hoylandet|xn--hylandet-54a|ha|xn--h-2fa|ibestad|inderoy|xn--indery-fya|iveland|jevnaker|jondal|jolster|xn--jlster-bya|karasjok|karasjohka|xn--krjohka-hwab49j|karlsoy|galsa|xn--gls-elac|karmoy|xn--karmy-yua|kautokeino|guovdageaidnu|klepp|klabu|xn--klbu-woa|kongsberg|kongsvinger|kragero|xn--krager-gya|kristiansand|kristiansund|krodsherad|xn--krdsherad-m8a|kvalsund|rahkkeravju|xn--rhkkervju-01af|kvam|kvinesdal|kvinnherad|kviteseid|kvitsoy|xn--kvitsy-fya|kvafjord|xn--kvfjord-nxa|giehtavuoatna|kvanangen|xn--kvnangen-k0a|navuotna|xn--nvuotna-hwa|kafjord|xn--kfjord-iua|gaivuotna|xn--givuotna-8ya|larvik|lavangen|lavagis|loabat|xn--loabt-0qa|lebesby|davvesiida|leikanger|leirfjord|leka|leksvik|lenvik|leangaviika|xn--leagaviika-52b|lesja|levanger|lier|lierne|lillehammer|lillesand|lindesnes|lindas|xn--linds-pra|lom|loppa|lahppi|xn--lhppi-xqa|lund|lunner|luroy|xn--lury-ira|luster|lyngdal|lyngen|ivgu|lardal|lerdal|xn--lrdal-sra|lodingen|xn--ldingen-q1a|lorenskog|xn--lrenskog-54a|loten|xn--lten-gra|malvik|masoy|xn--msy-ula0h|muosat|xn--muost-0qa|mandal|marker|marnardal|masfjorden|meland|meldal|melhus|meloy|xn--mely-ira|meraker|xn--merker-kua|moareke|xn--moreke-jua|midsund|midtre-gauldal|modalen|modum|molde|moskenes|moss|mosvik|malselv|xn--mlselv-iua|malatvuopmi|xn--mlatvuopmi-s4a|namdalseid|aejrie|namsos|namsskogan|naamesjevuemie|xn--nmesjevuemie-tcba|laakesvuemie|nannestad|narvik|narviika|naustdal|nedre-eiker|nes.akershus|nes.buskerud|nesna|nesodden|nesseby|unjarga|xn--unjrga-rta|nesset|nissedal|nittedal|nord-aurdal|nord-fron|nord-odal|norddal|nordkapp|davvenjarga|xn--davvenjrga-y4a|nordre-land|nordreisa|raisa|xn--risa-5na|nore-og-uvdal|notodden|naroy|xn--nry-yla5g|notteroy|xn--nttery-byae|odda|oksnes|xn--ksnes-uua|oppdal|oppegard|xn--oppegrd-ixa|orkdal|orland|xn--rland-uua|orskog|xn--rskog-uua|orsta|xn--rsta-fra|os.hedmark|os.hordaland|osen|osteroy|xn--ostery-fya|ostre-toten|xn--stre-toten-zcb|overhalla|ovre-eiker|xn--vre-eiker-k8a|oyer|xn--yer-zna|oygarden|xn--ygarden-p1a|oystre-slidre|xn--ystre-slidre-ujb|porsanger|porsangu|xn--porsgu-sta26f|porsgrunn|radoy|xn--rady-ira|rakkestad|rana|ruovat|randaberg|rauma|rendalen|rennebu|rennesoy|xn--rennesy-v1a|rindal|ringebu|ringerike|ringsaker|rissa|risor|xn--risr-ira|roan|rollag|rygge|ralingen|xn--rlingen-mxa|rodoy|xn--rdy-0nab|romskog|xn--rmskog-bya|roros|xn--rros-gra|rost|xn--rst-0na|royken|xn--ryken-vua|royrvik|xn--ryrvik-bya|rade|xn--rde-ula|salangen|siellak|saltdal|salat|xn--slt-elab|xn--slat-5na|samnanger|sande.more-og-romsdal|sande.xn--mre-og-romsdal-qqb|sande.vestfold|sandefjord|sandnes|sandoy|xn--sandy-yua|sarpsborg|sauda|sauherad|sel|selbu|selje|seljord|sigdal|siljan|sirdal|skaun|skedsmo|ski|skien|skiptvet|skjervoy|xn--skjervy-v1a|skierva|xn--skierv-uta|skjak|xn--skjk-soa|skodje|skanland|xn--sknland-fxa|skanit|xn--sknit-yqa|smola|xn--smla-hra|snillfjord|snasa|xn--snsa-roa|snoasa|snaase|xn--snase-nra|sogndal|sokndal|sola|solund|songdalen|sortland|spydeberg|stange|stavanger|steigen|steinkjer|stjordal|xn--stjrdal-s1a|stokke|stor-elvdal|stord|stordal|storfjord|omasvuotna|strand|stranda|stryn|sula|suldal|sund|sunndal|surnadal|sveio|svelvik|sykkylven|sogne|xn--sgne-gra|somna|xn--smna-gra|sondre-land|xn--sndre-land-0cb|sor-aurdal|xn--sr-aurdal-l8a|sor-fron|xn--sr-fron-q1a|sor-odal|xn--sr-odal-q1a|sor-varanger|xn--sr-varanger-ggb|matta-varjjat|xn--mtta-vrjjat-k7af|sorfold|xn--srfold-bya|sorreisa|xn--srreisa-q1a|sorum|xn--srum-gra|tana|deatnu|time|tingvoll|tinn|tjeldsund|dielddanuorri|tjome|xn--tjme-hra|tokke|tolga|torsken|tranoy|xn--trany-yua|tromso|xn--troms-zua|tromsa|romsa|trondheim|troandin|trysil|trana|xn--trna-woa|trogstad|xn--trgstad-r1a|tvedestrand|tydal|tynset|tysfjord|divtasvuodna|divttasvuotna|tysnes|tysvar|xn--tysvr-vra|tonsberg|xn--tnsberg-q1a|ullensaker|ullensvang|ulvik|utsira|vadso|xn--vads-jra|cahcesuolo|xn--hcesuolo-7ya35b|vaksdal|valle|vang|vanylven|vardo|xn--vard-jra|varggat|xn--vrggt-xqad|vefsn|vaapste|vega|vegarshei|xn--vegrshei-c0a|vennesla|verdal|verran|vestby|vestnes|vestre-slidre|vestre-toten|vestvagoy|xn--vestvgy-ixa6o|vevelstad|vik|vikna|vindafjord|volda|voss|varoy|xn--vry-yla5g|vagan|xn--vgan-qoa|voagat|vagsoy|xn--vgsy-qoa0j|vaga|xn--vg-yiab|valer.ostfold|xn--vler-qoa.xn--stfold-9xa|valer.hedmark|xn--vler-qoa.hedmark|co|blogspot","np":"*","nr":"biz|info|gov|edu|org|net|com","nu":"merseine|mine|shacknet","nz":"ac|co|cri|geek|gen|govt|health|iwi|kiwi|maori|mil|xn--mori-qsa|net|org|parliament|school|blogspot.co","om":"co|com|edu|gov|med|museum|net|org|pro","org":"ae|us|c.cdn77|rsc.cdn77|ssl.origin.cdn77-secure|duckdns|dyndns|blogdns|blogsite|boldlygoingnowhere|dnsalias|dnsdojo|doesntexist|dontexist|doomdns|dvrdns|dynalias|endofinternet|endoftheinternet|from-me|game-host|go.dyndns|gotdns|hobby-site|home.dyndns|homedns|homeftp|homelinux|homeunix|is-a-bruinsfan|is-a-candidate|is-a-celticsfan|is-a-chef|is-a-geek|is-a-knight|is-a-linux-user|is-a-patsfan|is-a-soxfan|is-found|is-lost|is-saved|is-very-bad|is-very-evil|is-very-good|is-very-nice|is-very-sweet|isa-geek|kicks-ass|misconfused|podzone|readmyblog|selfip|sellsyourhome|servebbs|serveftp|servegame|stuff-4-sale|webhop|eu|al.eu|asso.eu|at.eu|au.eu|be.eu|bg.eu|ca.eu|cd.eu|ch.eu|cn.eu|cy.eu|cz.eu|de.eu|dk.eu|edu.eu|ee.eu|es.eu|fi.eu|fr.eu|gr.eu|hr.eu|hu.eu|ie.eu|il.eu|in.eu|int.eu|is.eu|it.eu|jp.eu|kr.eu|lt.eu|lu.eu|lv.eu|mc.eu|me.eu|mk.eu|mt.eu|my.eu|net.eu|ng.eu|nl.eu|no.eu|nz.eu|paris.eu|pl.eu|pt.eu|q-a.eu|ro.eu|ru.eu|se.eu|si.eu|sk.eu|tr.eu|uk.eu|us.eu|bmoattachments|hk|za","pa":"ac|gob|com|org|sld|edu|net|ing|abo|med|nom","pe":"edu|gob|nom|mil|org|com|net|blogspot","pf":"com|org|edu","pg":"*","ph":"com|net|org|gov|edu|ngo|mil|i","pk":"com|net|edu|org|fam|biz|web|gov|gob|gok|gon|gop|gos|info","pl":"com|net|org|aid|agro|atm|auto|biz|edu|gmina|gsm|info|mail|miasta|media|mil|nieruchomosci|nom|pc|powiat|priv|realestate|rel|sex|shop|sklep|sos|szkola|targi|tm|tourism|travel|turystyka|gov|ap.gov|ic.gov|is.gov|us.gov|kmpsp.gov|kppsp.gov|kwpsp.gov|psp.gov|wskr.gov|kwp.gov|mw.gov|ug.gov|um.gov|umig.gov|ugim.gov|upow.gov|uw.gov|starostwo.gov|pa.gov|po.gov|psse.gov|pup.gov|rzgw.gov|sa.gov|so.gov|sr.gov|wsa.gov|sko.gov|uzs.gov|wiih.gov|winb.gov|pinb.gov|wios.gov|witd.gov|wzmiuw.gov|piw.gov|wiw.gov|griw.gov|wif.gov|oum.gov|sdn.gov|zp.gov|uppo.gov|mup.gov|wuoz.gov|konsulat.gov|oirm.gov|augustow|babia-gora|bedzin|beskidy|bialowieza|bialystok|bielawa|bieszczady|boleslawiec|bydgoszcz|bytom|cieszyn|czeladz|czest|dlugoleka|elblag|elk|glogow|gniezno|gorlice|grajewo|ilawa|jaworzno|jelenia-gora|jgora|kalisz|kazimierz-dolny|karpacz|kartuzy|kaszuby|katowice|kepno|ketrzyn|klodzko|kobierzyce|kolobrzeg|konin|konskowola|kutno|lapy|lebork|legnica|lezajsk|limanowa|lomza|lowicz|lubin|lukow|malbork|malopolska|mazowsze|mazury|mielec|mielno|mragowo|naklo|nowaruda|nysa|olawa|olecko|olkusz|olsztyn|opoczno|opole|ostroda|ostroleka|ostrowiec|ostrowwlkp|pila|pisz|podhale|podlasie|polkowice|pomorze|pomorskie|prochowice|pruszkow|przeworsk|pulawy|radom|rawa-maz|rybnik|rzeszow|sanok|sejny|slask|slupsk|sosnowiec|stalowa-wola|skoczow|starachowice|stargard|suwalki|swidnica|swiebodzin|swinoujscie|szczecin|szczytno|tarnobrzeg|tgory|turek|tychy|ustka|walbrzych|warmia|warszawa|waw|wegrow|wielun|wlocl|wloclawek|wodzislaw|wolomin|wroclaw|zachpomor|zagan|zarow|zgora|zgorzelec|co|art|gliwice|krakow|poznan|wroc|zakopane|gda|gdansk|gdynia|med|sopot","pm":"","pn":"gov|co|org|edu|net","post":"","pr":"com|net|org|gov|edu|isla|pro|biz|info|name|est|prof|ac","pro":"aca|bar|cpa|jur|law|med|eng","ps":"edu|gov|sec|plo|com|org|net","pt":"net|gov|org|edu|int|publ|com|nome|blogspot","pw":"co|ne|or|ed|go|belau","py":"com|coop|edu|gov|mil|net|org","qa":"com|edu|gov|mil|name|net|org|sch|blogspot","re":"com|asso|nom|blogspot","ro":"com|org|tm|nt|nom|info|rec|arts|firm|store|www|blogspot","rs":"co|org|edu|ac|gov|in|blogspot","ru":"ac|com|edu|int|net|org|pp|adygeya|altai|amur|arkhangelsk|astrakhan|bashkiria|belgorod|bir|bryansk|buryatia|cbg|chel|chelyabinsk|chita|chukotka|chuvashia|dagestan|dudinka|e-burg|grozny|irkutsk|ivanovo|izhevsk|jar|joshkar-ola|kalmykia|kaluga|kamchatka|karelia|kazan|kchr|kemerovo|khabarovsk|khakassia|khv|kirov|koenig|komi|kostroma|krasnoyarsk|kuban|kurgan|kursk|lipetsk|magadan|mari|mari-el|marine|mordovia|msk|murmansk|nalchik|nnov|nov|novosibirsk|nsk|omsk|orenburg|oryol|palana|penza|perm|ptz|rnd|ryazan|sakhalin|samara|saratov|simbirsk|smolensk|spb|stavropol|stv|surgut|tambov|tatarstan|tom|tomsk|tsaritsyn|tsk|tula|tuva|tver|tyumen|udm|udmurtia|ulan-ude|vladikavkaz|vladimir|vladivostok|volgograd|vologda|voronezh|vrn|vyatka|yakutia|yamal|yaroslavl|yekaterinburg|yuzhno-sakhalinsk|amursk|baikal|cmw|fareast|jamal|kms|k-uralsk|kustanai|kuzbass|magnitka|mytis|nakhodka|nkz|norilsk|oskol|pyatigorsk|rubtsovsk|snz|syzran|vdonsk|zgrad|gov|mil|test|blogspot","rw":"gov|net|edu|ac|com|co|int|mil|gouv","sa":"com|net|org|gov|med|pub|edu|sch","sb":"com|edu|gov|net|org","sc":"com|gov|net|org|edu","sd":"com|net|org|edu|med|tv|gov|info","se":"a|ac|b|bd|brand|c|d|e|f|fh|fhsk|fhv|g|h|i|k|komforb|kommunalforbund|komvux|l|lanbib|m|n|naturbruksgymn|o|org|p|parti|pp|press|r|s|t|tm|u|w|x|y|z|com|blogspot","sg":"com|net|org|gov|edu|per|blogspot","sh":"com|net|gov|org|mil|*platform","si":"blogspot","sj":"","sk":"blogspot","sl":"com|net|edu|gov|org","sm":"","sn":"art|com|edu|gouv|org|perso|univ|blogspot","so":"com|net|org","sr":"","st":"co|com|consulado|edu|embaixada|gov|mil|net|org|principe|saotome|store","su":"adygeya|arkhangelsk|balashov|bashkiria|bryansk|dagestan|grozny|ivanovo|kalmykia|kaluga|karelia|khakassia|krasnodar|kurgan|lenug|mordovia|msk|murmansk|nalchik|nov|obninsk|penza|pokrovsk|sochi|spb|togliatti|troitsk|tula|tuva|vladikavkaz|vladimir|vologda","sv":"com|edu|gob|org|red","sx":"gov","sy":"edu|gov|net|mil|com|org","sz":"co|ac|org","tc":"","td":"blogspot","tel":"","tf":"","tg":"","th":"ac|co|go|in|mi|net|or","tj":"ac|biz|co|com|edu|go|gov|int|mil|name|net|nic|org|test|web","tk":"","tl":"gov","tm":"com|co|org|net|nom|gov|mil|edu","tn":"com|ens|fin|gov|ind|intl|nat|net|org|info|perso|tourism|edunet|rnrt|rns|rnu|mincom|agrinet|defense|turen","to":"com|gov|net|org|edu|mil","tp":"","tr":"com|info|biz|net|org|web|gen|tv|av|dr|bbs|name|tel|gov|bel|pol|mil|k12|edu|kep|nc|gov.nc|blogspot.com","travel":"","tt":"co|com|org|net|biz|info|pro|int|coop|jobs|mobi|travel|museum|aero|name|gov|edu","tv":"dyndns|better-than|on-the-web|worse-than","tw":"edu|gov|mil|com|net|org|idv|game|ebiz|club|xn--zf0ao64a|xn--uc0atv|xn--czrw28b|blogspot","tz":"ac|co|go|hotel|info|me|mil|mobi|ne|or|sc|tv","ua":"com|edu|gov|in|net|org|cherkassy|cherkasy|chernigov|chernihiv|chernivtsi|chernovtsy|ck|cn|cr|crimea|cv|dn|dnepropetrovsk|dnipropetrovsk|dominic|donetsk|dp|if|ivano-frankivsk|kh|kharkiv|kharkov|kherson|khmelnitskiy|khmelnytskyi|kiev|kirovograd|km|kr|krym|ks|kv|kyiv|lg|lt|lugansk|lutsk|lv|lviv|mk|mykolaiv|nikolaev|od|odesa|odessa|pl|poltava|rivne|rovno|rv|sb|sebastopol|sevastopol|sm|sumy|te|ternopil|uz|uzhgorod|vinnica|vinnytsia|vn|volyn|yalta|zaporizhzhe|zaporizhzhia|zhitomir|zhytomyr|zp|zt|biz|co|pp","ug":"co|or|ac|sc|go|ne|com|org|blogspot","uk":"ac|co|gov|ltd|me|net|nhs|org|plc|police|*sch|service.gov|blogspot.co","us":"dni|fed|isa|kids|nsn|ak|al|ar|as|az|ca|co|ct|dc|de|fl|ga|gu|hi|ia|id|il|in|ks|ky|la|ma|md|me|mi|mn|mo|ms|mt|nc|nd|ne|nh|nj|nm|nv|ny|oh|ok|or|pa|pr|ri|sc|sd|tn|tx|ut|vi|vt|va|wa|wi|wv|wy|k12.ak|k12.al|k12.ar|k12.as|k12.az|k12.ca|k12.co|k12.ct|k12.dc|k12.de|k12.fl|k12.ga|k12.gu|k12.ia|k12.id|k12.il|k12.in|k12.ks|k12.ky|k12.la|k12.ma|k12.md|k12.me|k12.mi|k12.mn|k12.mo|k12.ms|k12.mt|k12.nc|k12.ne|k12.nh|k12.nj|k12.nm|k12.nv|k12.ny|k12.oh|k12.ok|k12.or|k12.pa|k12.pr|k12.ri|k12.sc|k12.tn|k12.tx|k12.ut|k12.vi|k12.vt|k12.va|k12.wa|k12.wi|k12.wy|cc.ak|cc.al|cc.ar|cc.as|cc.az|cc.ca|cc.co|cc.ct|cc.dc|cc.de|cc.fl|cc.ga|cc.gu|cc.hi|cc.ia|cc.id|cc.il|cc.in|cc.ks|cc.ky|cc.la|cc.ma|cc.md|cc.me|cc.mi|cc.mn|cc.mo|cc.ms|cc.mt|cc.nc|cc.nd|cc.ne|cc.nh|cc.nj|cc.nm|cc.nv|cc.ny|cc.oh|cc.ok|cc.or|cc.pa|cc.pr|cc.ri|cc.sc|cc.sd|cc.tn|cc.tx|cc.ut|cc.vi|cc.vt|cc.va|cc.wa|cc.wi|cc.wv|cc.wy|lib.ak|lib.al|lib.ar|lib.as|lib.az|lib.ca|lib.co|lib.ct|lib.dc|lib.de|lib.fl|lib.ga|lib.gu|lib.hi|lib.ia|lib.id|lib.il|lib.in|lib.ks|lib.ky|lib.la|lib.ma|lib.md|lib.me|lib.mi|lib.mn|lib.mo|lib.ms|lib.mt|lib.nc|lib.nd|lib.ne|lib.nh|lib.nj|lib.nm|lib.nv|lib.ny|lib.oh|lib.ok|lib.or|lib.pa|lib.pr|lib.ri|lib.sc|lib.sd|lib.tn|lib.tx|lib.ut|lib.vi|lib.vt|lib.va|lib.wa|lib.wi|lib.wy|pvt.k12.ma|chtr.k12.ma|paroch.k12.ma|is-by|land-4-sale|stuff-4-sale","uy":"com|edu|gub|mil|net|org|blogspot.com","uz":"co|com|net|org","va":"","vc":"com|net|org|gov|mil|edu","ve":"arts|co|com|e12|edu|firm|gob|gov|info|int|mil|net|org|rec|store|tec|web","vg":"","vi":"co|com|k12|net|org","vn":"com|net|org|edu|gov|int|ac|biz|info|name|pro|health|blogspot","vu":"com|edu|net|org","wf":"","ws":"com|net|org|gov|edu|dyndns|mypets","yt":"","xn--mgbaam7a8h":"","xn--y9a3aq":"","xn--54b7fta0cc":"","xn--90ais":"","xn--fiqs8s":"","xn--fiqz9s":"","xn--lgbbat1ad8j":"","xn--wgbh1c":"","xn--node":"","xn--qxam":"","xn--j6w193g":"","xn--h2brj9c":"","xn--mgbbh1a71e":"","xn--fpcrj9c3d":"","xn--gecrj9c":"","xn--s9brj9c":"","xn--45brj9c":"","xn--xkc2dl3a5ee0h":"","xn--mgba3a4f16a":"","xn--mgba3a4fra":"","xn--mgbtx2b":"","xn--mgbayh7gpa":"","xn--3e0b707e":"","xn--80ao21a":"","xn--fzc2c9e2c":"","xn--xkc2al3hye2a":"","xn--mgbc0a9azcg":"","xn--d1alf":"","xn--l1acc":"","xn--mix891f":"","xn--mix082f":"","xn--mgbx4cd0ab":"","xn--mgb9awbf":"","xn--mgbai9azgqp6j":"","xn--mgbai9a5eva00b":"","xn--ygbi2ammx":"","xn--90a3ac":"xn--o1ac|xn--c1avg|xn--90azh|xn--d1at|xn--o1ach|xn--80au","xn--p1ai":"","xn--wgbl6a":"","xn--mgberp4a5d4ar":"","xn--mgberp4a5d4a87g":"","xn--mgbqly7c0a67fbc":"","xn--mgbqly7cvafr":"","xn--mgbpl2fh":"","xn--yfro4i67o":"","xn--clchc0ea0b2g2a9gcd":"","xn--ogbpf8fl":"","xn--mgbtf8fl":"","xn--o3cw4h":"","xn--pgbs0dh":"","xn--kpry57d":"","xn--kprw13d":"","xn--nnx388a":"","xn--j1amh":"","xn--mgb2ddes":"","xxx":"","ye":"*","za":"ac|agrica|alt|co|edu|gov|grondar|law|mil|net|ngo|nis|nom|org|school|tm|web|blogspot.co","zm":"*","zw":"*","aaa":"","aarp":"","abarth":"","abb":"","abbott":"","abbvie":"","abc":"","able":"","abogado":"","abudhabi":"","academy":"","accenture":"","accountant":"","accountants":"","aco":"","active":"","actor":"","adac":"","ads":"","adult":"","aeg":"","aetna":"","afamilycompany":"","afl":"","africa":"","africamagic":"","agakhan":"","agency":"","aig":"","aigo":"","airbus":"","airforce":"","airtel":"","akdn":"","alfaromeo":"","alibaba":"","alipay":"","allfinanz":"","allstate":"","ally":"","alsace":"","alstom":"","americanexpress":"","americanfamily":"","amex":"","amfam":"","amica":"","amsterdam":"","analytics":"","android":"","anquan":"","anz":"","aol":"","apartments":"","app":"","apple":"","aquarelle":"","aramco":"","archi":"","army":"","arte":"","asda":"","associates":"","athleta":"","attorney":"","auction":"","audi":"","audible":"","audio":"","auspost":"","author":"","auto":"","autos":"","avianca":"","aws":"","axa":"","azure":"","baby":"","baidu":"","banamex":"","bananarepublic":"","band":"","bank":"","bar":"","barcelona":"","barclaycard":"","barclays":"","barefoot":"","bargains":"","baseball":"","basketball":"","bauhaus":"","bayern":"","bbc":"","bbt":"","bbva":"","bcg":"","bcn":"","beats":"","beer":"","bentley":"","berlin":"","best":"","bestbuy":"","bet":"","bharti":"","bible":"","bid":"","bike":"","bing":"","bingo":"","bio":"","black":"","blackfriday":"","blanco":"","blockbuster":"","blog":"","bloomberg":"","blue":"","bms":"","bmw":"","bnl":"","bnpparibas":"","boats":"","boehringer":"","bofa":"","bom":"","bond":"","boo":"","book":"","booking":"","boots":"","bosch":"","bostik":"","bot":"","boutique":"","bradesco":"","bridgestone":"","broadway":"","broker":"","brother":"","brussels":"","budapest":"","bugatti":"","build":"","builders":"","business":"","buy":"","buzz":"","bzh":"","cab":"","cafe":"","cal":"","call":"","calvinklein":"","camera":"","camp":"","cancerresearch":"","canon":"","capetown":"","capital":"","capitalone":"","car":"","caravan":"","cards":"","care":"","career":"","careers":"","cars":"","cartier":"","casa":"","case":"","caseih":"","cash":"","casino":"","catering":"","catholic":"","cba":"","cbn":"","cbre":"","cbs":"","ceb":"","center":"","ceo":"","cern":"","cfa":"","cfd":"","chanel":"","channel":"","chase":"","chat":"","cheap":"","chintai":"","chloe":"","christmas":"","chrome":"","chrysler":"","church":"","cipriani":"","circle":"","cisco":"","citadel":"","citi":"","citic":"","city":"","cityeats":"","claims":"","cleaning":"","click":"","clinic":"","clinique":"","clothing":"","cloud":"","club":"","clubmed":"","coach":"","codes":"","coffee":"","college":"","cologne":"","comcast":"","commbank":"","community":"","company":"","compare":"","computer":"","comsec":"","condos":"","construction":"","consulting":"","contact":"","contractors":"","cooking":"","cookingchannel":"","cool":"","corsica":"","country":"","coupon":"","coupons":"","courses":"","credit":"","creditcard":"","creditunion":"","cricket":"","crown":"","crs":"","cruises":"","csc":"","cuisinella":"","cymru":"","cyou":"","dabur":"","dad":"","dance":"","date":"","dating":"","datsun":"","day":"","dclk":"","dds":"","deal":"","dealer":"","deals":"","degree":"","delivery":"","dell":"","deloitte":"","delta":"","democrat":"","dental":"","dentist":"","desi":"","design":"","dev":"","dhl":"","diamonds":"","diet":"","digital":"","direct":"","directory":"","discount":"","discover":"","dish":"","diy":"","dnp":"","docs":"","dodge":"","dog":"","doha":"","domains":"","doosan":"","dot":"","download":"","drive":"","dstv":"","dtv":"","dubai":"","duck":"","dunlop":"","duns":"","dupont":"","durban":"","dvag":"","dwg":"","earth":"","eat":"","edeka":"","education":"","email":"","emerck":"","emerson":"","energy":"","engineer":"","engineering":"","enterprises":"","epost":"","epson":"","equipment":"","ericsson":"","erni":"","esq":"","estate":"","esurance":"","etisalat":"","eurovision":"","eus":"","events":"","everbank":"","exchange":"","expert":"","exposed":"","express":"","extraspace":"","fage":"","fail":"","fairwinds":"","faith":"","family":"","fan":"","fans":"","farm":"","farmers":"","fashion":"","fast":"","fedex":"","feedback":"","ferrari":"","ferrero":"","fiat":"","fidelity":"","fido":"","film":"","final":"","finance":"","financial":"","fire":"","firestone":"","firmdale":"","fish":"","fishing":"","fit":"","fitness":"","flickr":"","flights":"","flir":"","florist":"","flowers":"","flsmidth":"","fly":"","foo":"","foodnetwork":"","football":"","ford":"","forex":"","forsale":"","forum":"","foundation":"","fox":"","fresenius":"","frl":"","frogans":"","frontdoor":"","frontier":"","ftr":"","fujitsu":"","fujixerox":"","fund":"","furniture":"","futbol":"","fyi":"","gal":"","gallery":"","gallo":"","gallup":"","game":"","games":"","gap":"","garden":"","gbiz":"","gdn":"","gea":"","gent":"","genting":"","george":"","ggee":"","gift":"","gifts":"","gives":"","giving":"","glade":"","glass":"","gle":"","global":"","globo":"","gmail":"","gmo":"","gmx":"","godaddy":"","gold":"","goldpoint":"","golf":"","goo":"","goodhands":"","goodyear":"","goog":"","google":"","gop":"","got":"","gotv":"","grainger":"","graphics":"","gratis":"","green":"","gripe":"","group":"","guardian":"","gucci":"","guge":"","guide":"","guitars":"","guru":"","hamburg":"","hangout":"","haus":"","hbo":"","hdfc":"","hdfcbank":"","health":"","healthcare":"","help":"","helsinki":"","here":"","hermes":"","hgtv":"","hiphop":"","hisamitsu":"","hitachi":"","hiv":"","hkt":"","hockey":"","holdings":"","holiday":"","homedepot":"","homegoods":"","homes":"","homesense":"","honda":"","honeywell":"","horse":"","host":"","hosting":"","hot":"","hoteles":"","hotmail":"","house":"","how":"","hsbc":"","htc":"","hughes":"","hyatt":"","hyundai":"","ibm":"","icbc":"","ice":"","icu":"","ieee":"","ifm":"","iinet":"","ikano":"","imamat":"","imdb":"","immo":"","immobilien":"","industries":"","infiniti":"","ing":"","ink":"","institute":"","insurance":"","insure":"","intel":"","international":"","intuit":"","investments":"","ipiranga":"","irish":"","iselect":"","ismaili":"","ist":"","istanbul":"","itau":"","itv":"","iveco":"","iwc":"","jaguar":"","java":"","jcb":"","jcp":"","jeep":"","jetzt":"","jewelry":"","jio":"","jlc":"","jll":"","jmp":"","jnj":"","joburg":"","jot":"","joy":"","jpmorgan":"","jprs":"","juegos":"","juniper":"","kaufen":"","kddi":"","kerryhotels":"","kerrylogistics":"","kerryproperties":"","kfh":"","kia":"","kim":"","kinder":"","kindle":"","kitchen":"","kiwi":"","koeln":"","komatsu":"","kosher":"","kpmg":"","kpn":"","krd":"","kred":"","kuokgroup":"","kyknet":"","kyoto":"","lacaixa":"","ladbrokes":"","lamborghini":"","lamer":"","lancaster":"","lancia":"","lancome":"","land":"","landrover":"","lanxess":"","lasalle":"","lat":"","latino":"","latrobe":"","law":"","lawyer":"","lds":"","lease":"","leclerc":"","lefrak":"","legal":"","lego":"","lexus":"","lgbt":"","liaison":"","lidl":"","life":"","lifeinsurance":"","lifestyle":"","lighting":"","like":"","lilly":"","limited":"","limo":"","lincoln":"","linde":"","link":"","lipsy":"","live":"","living":"","lixil":"","loan":"","loans":"","locker":"","locus":"","loft":"","lol":"","london":"","lotte":"","lotto":"","love":"","lpl":"","lplfinancial":"","ltd":"","ltda":"","lundbeck":"","lupin":"","luxe":"","luxury":"","macys":"","madrid":"","maif":"","maison":"","makeup":"","man":"","management":"","mango":"","market":"","marketing":"","markets":"","marriott":"","marshalls":"","maserati":"","mattel":"","mba":"","mcd":"","mcdonalds":"","mckinsey":"","med":"","media":"","meet":"","melbourne":"","meme":"","memorial":"","men":"","menu":"","meo":"","metlife":"","miami":"","microsoft":"","mini":"","mint":"","mit":"","mitsubishi":"","mlb":"","mls":"","mma":"","mnet":"","mobily":"","moda":"","moe":"","moi":"","mom":"","monash":"","money":"","monster":"","montblanc":"","mopar":"","mormon":"","mortgage":"","moscow":"","moto":"","motorcycles":"","mov":"","movie":"","movistar":"","msd":"","mtn":"","mtpc":"","mtr":"","multichoice":"","mutual":"","mutuelle":"","mzansimagic":"","nab":"","nadex":"","nagoya":"","naspers":"","nationwide":"","natura":"","navy":"","nba":"","nec":"","netbank":"","netflix":"","network":"","neustar":"","new":"","newholland":"","news":"","next":"","nextdirect":"","nexus":"","nfl":"","ngo":"","nhk":"","nico":"","nike":"","nikon":"","ninja":"","nissan":"","nissay":"","nokia":"","northwesternmutual":"","norton":"","now":"","nowruz":"","nowtv":"","nra":"","nrw":"","ntt":"","nyc":"","obi":"","observer":"","off":"","office":"","okinawa":"","olayan":"","olayangroup":"","oldnavy":"","ollo":"","omega":"","one":"","ong":"","onl":"","online":"","onyourside":"","ooo":"","open":"","oracle":"","orange":"","organic":"","orientexpress":"","origins":"","osaka":"","otsuka":"","ott":"","ovh":"","page":"","pamperedchef":"","panasonic":"","panerai":"","paris":"","pars":"","partners":"","parts":"","party":"","passagens":"","pay":"","payu":"","pccw":"","pet":"","pfizer":"","pharmacy":"","philips":"","photo":"","photography":"","photos":"","physio":"","piaget":"","pics":"","pictet":"","pictures":"","pid":"","pin":"","ping":"","pink":"","pioneer":"","pizza":"","place":"","play":"","playstation":"","plumbing":"","plus":"","pnc":"","pohl":"","poker":"","politie":"","porn":"","pramerica":"","praxi":"","press":"","prime":"","prod":"","productions":"","prof":"","progressive":"","promo":"","properties":"","property":"","protection":"","pru":"","prudential":"","pub":"","pwc":"","qpon":"","quebec":"","quest":"","qvc":"","racing":"","raid":"","read":"","realestate":"","realtor":"","realty":"","recipes":"","red":"","redstone":"","redumbrella":"","rehab":"","reise":"","reisen":"","reit":"","reliance":"","ren":"","rent":"","rentals":"","repair":"","report":"","republican":"","rest":"","restaurant":"","review":"","reviews":"","rexroth":"","rich":"","richardli":"","ricoh":"","rightathome":"","ril":"","rio":"","rip":"","rocher":"","rocks":"","rodeo":"","rogers":"","room":"","rsvp":"","ruhr":"","run":"","rwe":"","ryukyu":"","saarland":"","safe":"","safety":"","sakura":"","sale":"","salon":"","samsclub":"","samsung":"","sandvik":"","sandvikcoromant":"","sanofi":"","sap":"","sapo":"","sarl":"","sas":"","save":"","saxo":"","sbi":"","sbs":"","sca":"","scb":"","schaeffler":"","schmidt":"","scholarships":"","school":"","schule":"","schwarz":"","science":"","scjohnson":"","scor":"","scot":"","seat":"","secure":"","security":"","seek":"","select":"","sener":"","services":"","ses":"","seven":"","sew":"","sex":"","sexy":"","sfr":"","shangrila":"","sharp":"","shaw":"","shell":"","shia":"","shiksha":"","shoes":"","shouji":"","show":"","showtime":"","shriram":"","silk":"","sina":"","singles":"","site":"","ski":"","skin":"","sky":"","skype":"","sling":"","smart":"","smile":"","sncf":"","soccer":"","social":"","softbank":"","software":"","sohu":"","solar":"","solutions":"","song":"","sony":"","soy":"","space":"","spiegel":"","spot":"","spreadbetting":"","srl":"","srt":"","stada":"","staples":"","star":"","starhub":"","statebank":"","statefarm":"","statoil":"","stc":"","stcgroup":"","stockholm":"","storage":"","store":"","studio":"","study":"","style":"","sucks":"","supersport":"","supplies":"","supply":"","support":"","surf":"","surgery":"","suzuki":"","swatch":"","swiftcover":"","swiss":"","sydney":"","symantec":"","systems":"","tab":"","taipei":"","talk":"","taobao":"","target":"","tatamotors":"","tatar":"","tattoo":"","tax":"","taxi":"","tci":"","tdk":"","team":"","tech":"","technology":"","telecity":"","telefonica":"","temasek":"","tennis":"","teva":"","thd":"","theater":"","theatre":"","theguardian":"","tiaa":"","tickets":"","tienda":"","tiffany":"","tips":"","tires":"","tirol":"","tjmaxx":"","tjx":"","tkmaxx":"","tmall":"","today":"","tokyo":"","tools":"","top":"","toray":"","toshiba":"","total":"","tours":"","town":"","toyota":"","toys":"","trade":"","trading":"","training":"","travelchannel":"","travelers":"","travelersinsurance":"","trust":"","trv":"","tube":"","tui":"","tunes":"","tushu":"","tvs":"","ubank":"","ubs":"","uconnect":"","unicom":"","university":"","uno":"","uol":"","ups":"","vacations":"","vana":"","vanguard":"","vegas":"","ventures":"","verisign":"","versicherung":"","vet":"","viajes":"","video":"","vig":"","viking":"","villas":"","vin":"","vip":"","virgin":"","visa":"","vision":"","vista":"","vistaprint":"","viva":"","vivo":"","vlaanderen":"","vodka":"","volkswagen":"","vote":"","voting":"","voto":"","voyage":"","vuelos":"","wales":"","walmart":"","walter":"","wang":"","wanggou":"","warman":"","watch":"","watches":"","weather":"","weatherchannel":"","webcam":"","weber":"","website":"","wed":"","wedding":"","weibo":"","weir":"","whoswho":"","wien":"","wiki":"","williamhill":"","win":"","windows":"","wine":"","winners":"","wme":"","wolterskluwer":"","woodside":"","work":"","works":"","world":"","wow":"","wtc":"","wtf":"","xbox":"","xerox":"","xfinity":"","xihuan":"","xin":"","xn--11b4c3d":"","xn--1ck2e1b":"","xn--1qqw23a":"","xn--30rr7y":"","xn--3bst00m":"","xn--3ds443g":"","xn--3oq18vl8pn36a":"","xn--3pxu8k":"","xn--42c2d9a":"","xn--45q11c":"","xn--4gbrim":"","xn--4gq48lf9j":"","xn--55qw42g":"","xn--55qx5d":"","xn--5su34j936bgsg":"","xn--5tzm5g":"","xn--6frz82g":"","xn--6qq986b3xl":"","xn--80adxhks":"","xn--80aqecdr1a":"","xn--80asehdb":"","xn--80aswg":"","xn--8y0a063a":"","xn--9dbq2a":"","xn--9et52u":"","xn--9krt00a":"","xn--b4w605ferd":"","xn--bck1b9a5dre4c":"","xn--c1avg":"","xn--c2br7g":"","xn--cck2b3b":"","xn--cg4bki":"","xn--czr694b":"","xn--czrs0t":"","xn--czru2d":"","xn--d1acj3b":"","xn--eckvdtc9d":"","xn--efvy88h":"","xn--estv75g":"","xn--fct429k":"","xn--fhbei":"","xn--fiq228c5hs":"","xn--fiq64b":"","xn--fjq720a":"","xn--flw351e":"","xn--fzys8d69uvgm":"","xn--g2xx48c":"","xn--gckr3f0f":"","xn--gk3at1e":"","xn--hxt814e":"","xn--i1b6b1a6a2e":"","xn--imr513n":"","xn--io0a7i":"","xn--j1aef":"","xn--jlq61u9w7b":"","xn--jvr189m":"","xn--kcrx77d1x4a":"","xn--kpu716f":"","xn--kput3i":"","xn--mgba3a3ejt":"","xn--mgba7c0bbn0a":"","xn--mgbaakc7dvf":"","xn--mgbab2bd":"","xn--mgbb9fbpob":"","xn--mgbca7dzdo":"","xn--mgbi4ecexp":"","xn--mgbt3dhd":"","xn--mk1bu44c":"","xn--mxtq1m":"","xn--ngbc5azd":"","xn--ngbe9e0a":"","xn--nqv7f":"","xn--nqv7fs00ema":"","xn--nyqy26a":"","xn--p1acf":"","xn--pbt977c":"","xn--pssy2u":"","xn--q9jyb4c":"","xn--qcka1pmc":"","xn--rhqv96g":"","xn--rovu88b":"","xn--ses554g":"","xn--t60b56a":"","xn--tckwe":"","xn--tiq49xqyj":"","xn--unup4y":"","xn--vermgensberater-ctb":"","xn--vermgensberatung-pwb":"","xn--vhquv":"","xn--vuq861b":"","xn--w4r85el8fhu5dnra":"","xn--w4rs40l":"","xn--xhq521b":"","xn--zfr164b":"","xperia":"","xyz":"","yachts":"","yahoo":"","yamaxun":"","yandex":"","yodobashi":"","yoga":"","yokohama":"","you":"","youtube":"","yun":"","zappos":"","zara":"","zero":"","zip":"","zippo":"","zone":"","zuerich":""}
  18598. },{}],143:[function(require,module,exports){
  18599. // Copyright Joyent, Inc. and other Node contributors.
  18600. //
  18601. // Permission is hereby granted, free of charge, to any person obtaining a
  18602. // copy of this software and associated documentation files (the
  18603. // "Software"), to deal in the Software without restriction, including
  18604. // without limitation the rights to use, copy, modify, merge, publish,
  18605. // distribute, sublicense, and/or sell copies of the Software, and to permit
  18606. // persons to whom the Software is furnished to do so, subject to the
  18607. // following conditions:
  18608. //
  18609. // The above copyright notice and this permission notice shall be included
  18610. // in all copies or substantial portions of the Software.
  18611. //
  18612. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18613. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18614. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  18615. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18616. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18617. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18618. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  18619. 'use strict';
  18620. var punycode = require('punycode');
  18621. var util = require('./util');
  18622. exports.parse = urlParse;
  18623. exports.resolve = urlResolve;
  18624. exports.resolveObject = urlResolveObject;
  18625. exports.format = urlFormat;
  18626. exports.Url = Url;
  18627. function Url() {
  18628. this.protocol = null;
  18629. this.slashes = null;
  18630. this.auth = null;
  18631. this.host = null;
  18632. this.port = null;
  18633. this.hostname = null;
  18634. this.hash = null;
  18635. this.search = null;
  18636. this.query = null;
  18637. this.pathname = null;
  18638. this.path = null;
  18639. this.href = null;
  18640. }
  18641. // Reference: RFC 3986, RFC 1808, RFC 2396
  18642. // define these here so at least they only have to be
  18643. // compiled once on the first module load.
  18644. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  18645. portPattern = /:[0-9]*$/,
  18646. // Special case for a simple path URL
  18647. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  18648. // RFC 2396: characters reserved for delimiting URLs.
  18649. // We actually just auto-escape these.
  18650. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  18651. // RFC 2396: characters not allowed for various reasons.
  18652. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  18653. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  18654. autoEscape = ['\''].concat(unwise),
  18655. // Characters that are never ever allowed in a hostname.
  18656. // Note that any invalid chars are also handled, but these
  18657. // are the ones that are *expected* to be seen, so we fast-path
  18658. // them.
  18659. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  18660. hostEndingChars = ['/', '?', '#'],
  18661. hostnameMaxLen = 255,
  18662. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  18663. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  18664. // protocols that can allow "unsafe" and "unwise" chars.
  18665. unsafeProtocol = {
  18666. 'javascript': true,
  18667. 'javascript:': true
  18668. },
  18669. // protocols that never have a hostname.
  18670. hostlessProtocol = {
  18671. 'javascript': true,
  18672. 'javascript:': true
  18673. },
  18674. // protocols that always contain a // bit.
  18675. slashedProtocol = {
  18676. 'http': true,
  18677. 'https': true,
  18678. 'ftp': true,
  18679. 'gopher': true,
  18680. 'file': true,
  18681. 'http:': true,
  18682. 'https:': true,
  18683. 'ftp:': true,
  18684. 'gopher:': true,
  18685. 'file:': true
  18686. },
  18687. querystring = require('querystring');
  18688. function urlParse(url, parseQueryString, slashesDenoteHost) {
  18689. if (url && util.isObject(url) && url instanceof Url) return url;
  18690. var u = new Url;
  18691. u.parse(url, parseQueryString, slashesDenoteHost);
  18692. return u;
  18693. }
  18694. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  18695. if (!util.isString(url)) {
  18696. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  18697. }
  18698. // Copy chrome, IE, opera backslash-handling behavior.
  18699. // Back slashes before the query string get converted to forward slashes
  18700. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  18701. var queryIndex = url.indexOf('?'),
  18702. splitter =
  18703. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  18704. uSplit = url.split(splitter),
  18705. slashRegex = /\\/g;
  18706. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  18707. url = uSplit.join(splitter);
  18708. var rest = url;
  18709. // trim before proceeding.
  18710. // This is to support parse stuff like " http://foo.com \n"
  18711. rest = rest.trim();
  18712. if (!slashesDenoteHost && url.split('#').length === 1) {
  18713. // Try fast path regexp
  18714. var simplePath = simplePathPattern.exec(rest);
  18715. if (simplePath) {
  18716. this.path = rest;
  18717. this.href = rest;
  18718. this.pathname = simplePath[1];
  18719. if (simplePath[2]) {
  18720. this.search = simplePath[2];
  18721. if (parseQueryString) {
  18722. this.query = querystring.parse(this.search.substr(1));
  18723. } else {
  18724. this.query = this.search.substr(1);
  18725. }
  18726. } else if (parseQueryString) {
  18727. this.search = '';
  18728. this.query = {};
  18729. }
  18730. return this;
  18731. }
  18732. }
  18733. var proto = protocolPattern.exec(rest);
  18734. if (proto) {
  18735. proto = proto[0];
  18736. var lowerProto = proto.toLowerCase();
  18737. this.protocol = lowerProto;
  18738. rest = rest.substr(proto.length);
  18739. }
  18740. // figure out if it's got a host
  18741. // user@server is *always* interpreted as a hostname, and url
  18742. // resolution will treat //foo/bar as host=foo,path=bar because that's
  18743. // how the browser resolves relative URLs.
  18744. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  18745. var slashes = rest.substr(0, 2) === '//';
  18746. if (slashes && !(proto && hostlessProtocol[proto])) {
  18747. rest = rest.substr(2);
  18748. this.slashes = true;
  18749. }
  18750. }
  18751. if (!hostlessProtocol[proto] &&
  18752. (slashes || (proto && !slashedProtocol[proto]))) {
  18753. // there's a hostname.
  18754. // the first instance of /, ?, ;, or # ends the host.
  18755. //
  18756. // If there is an @ in the hostname, then non-host chars *are* allowed
  18757. // to the left of the last @ sign, unless some host-ending character
  18758. // comes *before* the @-sign.
  18759. // URLs are obnoxious.
  18760. //
  18761. // ex:
  18762. // http://a@b@c/ => user:a@b host:c
  18763. // http://a@b?@c => user:a host:c path:/?@c
  18764. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  18765. // Review our test case against browsers more comprehensively.
  18766. // find the first instance of any hostEndingChars
  18767. var hostEnd = -1;
  18768. for (var i = 0; i < hostEndingChars.length; i++) {
  18769. var hec = rest.indexOf(hostEndingChars[i]);
  18770. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  18771. hostEnd = hec;
  18772. }
  18773. // at this point, either we have an explicit point where the
  18774. // auth portion cannot go past, or the last @ char is the decider.
  18775. var auth, atSign;
  18776. if (hostEnd === -1) {
  18777. // atSign can be anywhere.
  18778. atSign = rest.lastIndexOf('@');
  18779. } else {
  18780. // atSign must be in auth portion.
  18781. // http://a@b/c@d => host:b auth:a path:/c@d
  18782. atSign = rest.lastIndexOf('@', hostEnd);
  18783. }
  18784. // Now we have a portion which is definitely the auth.
  18785. // Pull that off.
  18786. if (atSign !== -1) {
  18787. auth = rest.slice(0, atSign);
  18788. rest = rest.slice(atSign + 1);
  18789. this.auth = decodeURIComponent(auth);
  18790. }
  18791. // the host is the remaining to the left of the first non-host char
  18792. hostEnd = -1;
  18793. for (var i = 0; i < nonHostChars.length; i++) {
  18794. var hec = rest.indexOf(nonHostChars[i]);
  18795. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  18796. hostEnd = hec;
  18797. }
  18798. // if we still have not hit it, then the entire thing is a host.
  18799. if (hostEnd === -1)
  18800. hostEnd = rest.length;
  18801. this.host = rest.slice(0, hostEnd);
  18802. rest = rest.slice(hostEnd);
  18803. // pull out port.
  18804. this.parseHost();
  18805. // we've indicated that there is a hostname,
  18806. // so even if it's empty, it has to be present.
  18807. this.hostname = this.hostname || '';
  18808. // if hostname begins with [ and ends with ]
  18809. // assume that it's an IPv6 address.
  18810. var ipv6Hostname = this.hostname[0] === '[' &&
  18811. this.hostname[this.hostname.length - 1] === ']';
  18812. // validate a little.
  18813. if (!ipv6Hostname) {
  18814. var hostparts = this.hostname.split(/\./);
  18815. for (var i = 0, l = hostparts.length; i < l; i++) {
  18816. var part = hostparts[i];
  18817. if (!part) continue;
  18818. if (!part.match(hostnamePartPattern)) {
  18819. var newpart = '';
  18820. for (var j = 0, k = part.length; j < k; j++) {
  18821. if (part.charCodeAt(j) > 127) {
  18822. // we replace non-ASCII char with a temporary placeholder
  18823. // we need this to make sure size of hostname is not
  18824. // broken by replacing non-ASCII by nothing
  18825. newpart += 'x';
  18826. } else {
  18827. newpart += part[j];
  18828. }
  18829. }
  18830. // we test again with ASCII char only
  18831. if (!newpart.match(hostnamePartPattern)) {
  18832. var validParts = hostparts.slice(0, i);
  18833. var notHost = hostparts.slice(i + 1);
  18834. var bit = part.match(hostnamePartStart);
  18835. if (bit) {
  18836. validParts.push(bit[1]);
  18837. notHost.unshift(bit[2]);
  18838. }
  18839. if (notHost.length) {
  18840. rest = '/' + notHost.join('.') + rest;
  18841. }
  18842. this.hostname = validParts.join('.');
  18843. break;
  18844. }
  18845. }
  18846. }
  18847. }
  18848. if (this.hostname.length > hostnameMaxLen) {
  18849. this.hostname = '';
  18850. } else {
  18851. // hostnames are always lower case.
  18852. this.hostname = this.hostname.toLowerCase();
  18853. }
  18854. if (!ipv6Hostname) {
  18855. // IDNA Support: Returns a punycoded representation of "domain".
  18856. // It only converts parts of the domain name that
  18857. // have non-ASCII characters, i.e. it doesn't matter if
  18858. // you call it with a domain that already is ASCII-only.
  18859. this.hostname = punycode.toASCII(this.hostname);
  18860. }
  18861. var p = this.port ? ':' + this.port : '';
  18862. var h = this.hostname || '';
  18863. this.host = h + p;
  18864. this.href += this.host;
  18865. // strip [ and ] from the hostname
  18866. // the host field still retains them, though
  18867. if (ipv6Hostname) {
  18868. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  18869. if (rest[0] !== '/') {
  18870. rest = '/' + rest;
  18871. }
  18872. }
  18873. }
  18874. // now rest is set to the post-host stuff.
  18875. // chop off any delim chars.
  18876. if (!unsafeProtocol[lowerProto]) {
  18877. // First, make 100% sure that any "autoEscape" chars get
  18878. // escaped, even if encodeURIComponent doesn't think they
  18879. // need to be.
  18880. for (var i = 0, l = autoEscape.length; i < l; i++) {
  18881. var ae = autoEscape[i];
  18882. if (rest.indexOf(ae) === -1)
  18883. continue;
  18884. var esc = encodeURIComponent(ae);
  18885. if (esc === ae) {
  18886. esc = escape(ae);
  18887. }
  18888. rest = rest.split(ae).join(esc);
  18889. }
  18890. }
  18891. // chop off from the tail first.
  18892. var hash = rest.indexOf('#');
  18893. if (hash !== -1) {
  18894. // got a fragment string.
  18895. this.hash = rest.substr(hash);
  18896. rest = rest.slice(0, hash);
  18897. }
  18898. var qm = rest.indexOf('?');
  18899. if (qm !== -1) {
  18900. this.search = rest.substr(qm);
  18901. this.query = rest.substr(qm + 1);
  18902. if (parseQueryString) {
  18903. this.query = querystring.parse(this.query);
  18904. }
  18905. rest = rest.slice(0, qm);
  18906. } else if (parseQueryString) {
  18907. // no query string, but parseQueryString still requested
  18908. this.search = '';
  18909. this.query = {};
  18910. }
  18911. if (rest) this.pathname = rest;
  18912. if (slashedProtocol[lowerProto] &&
  18913. this.hostname && !this.pathname) {
  18914. this.pathname = '/';
  18915. }
  18916. //to support http.request
  18917. if (this.pathname || this.search) {
  18918. var p = this.pathname || '';
  18919. var s = this.search || '';
  18920. this.path = p + s;
  18921. }
  18922. // finally, reconstruct the href based on what has been validated.
  18923. this.href = this.format();
  18924. return this;
  18925. };
  18926. // format a parsed object into a url string
  18927. function urlFormat(obj) {
  18928. // ensure it's an object, and not a string url.
  18929. // If it's an obj, this is a no-op.
  18930. // this way, you can call url_format() on strings
  18931. // to clean up potentially wonky urls.
  18932. if (util.isString(obj)) obj = urlParse(obj);
  18933. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  18934. return obj.format();
  18935. }
  18936. Url.prototype.format = function() {
  18937. var auth = this.auth || '';
  18938. if (auth) {
  18939. auth = encodeURIComponent(auth);
  18940. auth = auth.replace(/%3A/i, ':');
  18941. auth += '@';
  18942. }
  18943. var protocol = this.protocol || '',
  18944. pathname = this.pathname || '',
  18945. hash = this.hash || '',
  18946. host = false,
  18947. query = '';
  18948. if (this.host) {
  18949. host = auth + this.host;
  18950. } else if (this.hostname) {
  18951. host = auth + (this.hostname.indexOf(':') === -1 ?
  18952. this.hostname :
  18953. '[' + this.hostname + ']');
  18954. if (this.port) {
  18955. host += ':' + this.port;
  18956. }
  18957. }
  18958. if (this.query &&
  18959. util.isObject(this.query) &&
  18960. Object.keys(this.query).length) {
  18961. query = querystring.stringify(this.query);
  18962. }
  18963. var search = this.search || (query && ('?' + query)) || '';
  18964. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  18965. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  18966. // unless they had them to begin with.
  18967. if (this.slashes ||
  18968. (!protocol || slashedProtocol[protocol]) && host !== false) {
  18969. host = '//' + (host || '');
  18970. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  18971. } else if (!host) {
  18972. host = '';
  18973. }
  18974. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  18975. if (search && search.charAt(0) !== '?') search = '?' + search;
  18976. pathname = pathname.replace(/[?#]/g, function(match) {
  18977. return encodeURIComponent(match);
  18978. });
  18979. search = search.replace('#', '%23');
  18980. return protocol + host + pathname + search + hash;
  18981. };
  18982. function urlResolve(source, relative) {
  18983. return urlParse(source, false, true).resolve(relative);
  18984. }
  18985. Url.prototype.resolve = function(relative) {
  18986. return this.resolveObject(urlParse(relative, false, true)).format();
  18987. };
  18988. function urlResolveObject(source, relative) {
  18989. if (!source) return relative;
  18990. return urlParse(source, false, true).resolveObject(relative);
  18991. }
  18992. Url.prototype.resolveObject = function(relative) {
  18993. if (util.isString(relative)) {
  18994. var rel = new Url();
  18995. rel.parse(relative, false, true);
  18996. relative = rel;
  18997. }
  18998. var result = new Url();
  18999. var tkeys = Object.keys(this);
  19000. for (var tk = 0; tk < tkeys.length; tk++) {
  19001. var tkey = tkeys[tk];
  19002. result[tkey] = this[tkey];
  19003. }
  19004. // hash is always overridden, no matter what.
  19005. // even href="" will remove it.
  19006. result.hash = relative.hash;
  19007. // if the relative url is empty, then there's nothing left to do here.
  19008. if (relative.href === '') {
  19009. result.href = result.format();
  19010. return result;
  19011. }
  19012. // hrefs like //foo/bar always cut to the protocol.
  19013. if (relative.slashes && !relative.protocol) {
  19014. // take everything except the protocol from relative
  19015. var rkeys = Object.keys(relative);
  19016. for (var rk = 0; rk < rkeys.length; rk++) {
  19017. var rkey = rkeys[rk];
  19018. if (rkey !== 'protocol')
  19019. result[rkey] = relative[rkey];
  19020. }
  19021. //urlParse appends trailing / to urls like http://www.example.com
  19022. if (slashedProtocol[result.protocol] &&
  19023. result.hostname && !result.pathname) {
  19024. result.path = result.pathname = '/';
  19025. }
  19026. result.href = result.format();
  19027. return result;
  19028. }
  19029. if (relative.protocol && relative.protocol !== result.protocol) {
  19030. // if it's a known url protocol, then changing
  19031. // the protocol does weird things
  19032. // first, if it's not file:, then we MUST have a host,
  19033. // and if there was a path
  19034. // to begin with, then we MUST have a path.
  19035. // if it is file:, then the host is dropped,
  19036. // because that's known to be hostless.
  19037. // anything else is assumed to be absolute.
  19038. if (!slashedProtocol[relative.protocol]) {
  19039. var keys = Object.keys(relative);
  19040. for (var v = 0; v < keys.length; v++) {
  19041. var k = keys[v];
  19042. result[k] = relative[k];
  19043. }
  19044. result.href = result.format();
  19045. return result;
  19046. }
  19047. result.protocol = relative.protocol;
  19048. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  19049. var relPath = (relative.pathname || '').split('/');
  19050. while (relPath.length && !(relative.host = relPath.shift()));
  19051. if (!relative.host) relative.host = '';
  19052. if (!relative.hostname) relative.hostname = '';
  19053. if (relPath[0] !== '') relPath.unshift('');
  19054. if (relPath.length < 2) relPath.unshift('');
  19055. result.pathname = relPath.join('/');
  19056. } else {
  19057. result.pathname = relative.pathname;
  19058. }
  19059. result.search = relative.search;
  19060. result.query = relative.query;
  19061. result.host = relative.host || '';
  19062. result.auth = relative.auth;
  19063. result.hostname = relative.hostname || relative.host;
  19064. result.port = relative.port;
  19065. // to support http.request
  19066. if (result.pathname || result.search) {
  19067. var p = result.pathname || '';
  19068. var s = result.search || '';
  19069. result.path = p + s;
  19070. }
  19071. result.slashes = result.slashes || relative.slashes;
  19072. result.href = result.format();
  19073. return result;
  19074. }
  19075. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  19076. isRelAbs = (
  19077. relative.host ||
  19078. relative.pathname && relative.pathname.charAt(0) === '/'
  19079. ),
  19080. mustEndAbs = (isRelAbs || isSourceAbs ||
  19081. (result.host && relative.pathname)),
  19082. removeAllDots = mustEndAbs,
  19083. srcPath = result.pathname && result.pathname.split('/') || [],
  19084. relPath = relative.pathname && relative.pathname.split('/') || [],
  19085. psychotic = result.protocol && !slashedProtocol[result.protocol];
  19086. // if the url is a non-slashed url, then relative
  19087. // links like ../.. should be able
  19088. // to crawl up to the hostname, as well. This is strange.
  19089. // result.protocol has already been set by now.
  19090. // Later on, put the first path part into the host field.
  19091. if (psychotic) {
  19092. result.hostname = '';
  19093. result.port = null;
  19094. if (result.host) {
  19095. if (srcPath[0] === '') srcPath[0] = result.host;
  19096. else srcPath.unshift(result.host);
  19097. }
  19098. result.host = '';
  19099. if (relative.protocol) {
  19100. relative.hostname = null;
  19101. relative.port = null;
  19102. if (relative.host) {
  19103. if (relPath[0] === '') relPath[0] = relative.host;
  19104. else relPath.unshift(relative.host);
  19105. }
  19106. relative.host = null;
  19107. }
  19108. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  19109. }
  19110. if (isRelAbs) {
  19111. // it's absolute.
  19112. result.host = (relative.host || relative.host === '') ?
  19113. relative.host : result.host;
  19114. result.hostname = (relative.hostname || relative.hostname === '') ?
  19115. relative.hostname : result.hostname;
  19116. result.search = relative.search;
  19117. result.query = relative.query;
  19118. srcPath = relPath;
  19119. // fall through to the dot-handling below.
  19120. } else if (relPath.length) {
  19121. // it's relative
  19122. // throw away the existing file, and take the new path instead.
  19123. if (!srcPath) srcPath = [];
  19124. srcPath.pop();
  19125. srcPath = srcPath.concat(relPath);
  19126. result.search = relative.search;
  19127. result.query = relative.query;
  19128. } else if (!util.isNullOrUndefined(relative.search)) {
  19129. // just pull out the search.
  19130. // like href='?foo'.
  19131. // Put this after the other two cases because it simplifies the booleans
  19132. if (psychotic) {
  19133. result.hostname = result.host = srcPath.shift();
  19134. //occationaly the auth can get stuck only in host
  19135. //this especially happens in cases like
  19136. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  19137. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  19138. result.host.split('@') : false;
  19139. if (authInHost) {
  19140. result.auth = authInHost.shift();
  19141. result.host = result.hostname = authInHost.shift();
  19142. }
  19143. }
  19144. result.search = relative.search;
  19145. result.query = relative.query;
  19146. //to support http.request
  19147. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  19148. result.path = (result.pathname ? result.pathname : '') +
  19149. (result.search ? result.search : '');
  19150. }
  19151. result.href = result.format();
  19152. return result;
  19153. }
  19154. if (!srcPath.length) {
  19155. // no path at all. easy.
  19156. // we've already handled the other stuff above.
  19157. result.pathname = null;
  19158. //to support http.request
  19159. if (result.search) {
  19160. result.path = '/' + result.search;
  19161. } else {
  19162. result.path = null;
  19163. }
  19164. result.href = result.format();
  19165. return result;
  19166. }
  19167. // if a url ENDs in . or .., then it must get a trailing slash.
  19168. // however, if it ends in anything else non-slashy,
  19169. // then it must NOT get a trailing slash.
  19170. var last = srcPath.slice(-1)[0];
  19171. var hasTrailingSlash = (
  19172. (result.host || relative.host || srcPath.length > 1) &&
  19173. (last === '.' || last === '..') || last === '');
  19174. // strip single dots, resolve double dots to parent dir
  19175. // if the path tries to go above the root, `up` ends up > 0
  19176. var up = 0;
  19177. for (var i = srcPath.length; i >= 0; i--) {
  19178. last = srcPath[i];
  19179. if (last === '.') {
  19180. srcPath.splice(i, 1);
  19181. } else if (last === '..') {
  19182. srcPath.splice(i, 1);
  19183. up++;
  19184. } else if (up) {
  19185. srcPath.splice(i, 1);
  19186. up--;
  19187. }
  19188. }
  19189. // if the path is allowed to go above the root, restore leading ..s
  19190. if (!mustEndAbs && !removeAllDots) {
  19191. for (; up--; up) {
  19192. srcPath.unshift('..');
  19193. }
  19194. }
  19195. if (mustEndAbs && srcPath[0] !== '' &&
  19196. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  19197. srcPath.unshift('');
  19198. }
  19199. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  19200. srcPath.push('');
  19201. }
  19202. var isAbsolute = srcPath[0] === '' ||
  19203. (srcPath[0] && srcPath[0].charAt(0) === '/');
  19204. // put the host back
  19205. if (psychotic) {
  19206. result.hostname = result.host = isAbsolute ? '' :
  19207. srcPath.length ? srcPath.shift() : '';
  19208. //occationaly the auth can get stuck only in host
  19209. //this especially happens in cases like
  19210. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  19211. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  19212. result.host.split('@') : false;
  19213. if (authInHost) {
  19214. result.auth = authInHost.shift();
  19215. result.host = result.hostname = authInHost.shift();
  19216. }
  19217. }
  19218. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  19219. if (mustEndAbs && !isAbsolute) {
  19220. srcPath.unshift('');
  19221. }
  19222. if (!srcPath.length) {
  19223. result.pathname = null;
  19224. result.path = null;
  19225. } else {
  19226. result.pathname = srcPath.join('/');
  19227. }
  19228. //to support request.http
  19229. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  19230. result.path = (result.pathname ? result.pathname : '') +
  19231. (result.search ? result.search : '');
  19232. }
  19233. result.auth = relative.auth || result.auth;
  19234. result.slashes = result.slashes || relative.slashes;
  19235. result.href = result.format();
  19236. return result;
  19237. };
  19238. Url.prototype.parseHost = function() {
  19239. var host = this.host;
  19240. var port = portPattern.exec(host);
  19241. if (port) {
  19242. port = port[0];
  19243. if (port !== ':') {
  19244. this.port = port.substr(1);
  19245. }
  19246. host = host.substr(0, host.length - port.length);
  19247. }
  19248. if (host) this.hostname = host;
  19249. };
  19250. },{"./util":144,"punycode":113,"querystring":116}],144:[function(require,module,exports){
  19251. 'use strict';
  19252. module.exports = {
  19253. isString: function(arg) {
  19254. return typeof(arg) === 'string';
  19255. },
  19256. isObject: function(arg) {
  19257. return typeof(arg) === 'object' && arg !== null;
  19258. },
  19259. isNull: function(arg) {
  19260. return arg === null;
  19261. },
  19262. isNullOrUndefined: function(arg) {
  19263. return arg == null;
  19264. }
  19265. };
  19266. },{}],145:[function(require,module,exports){
  19267. (function (global){
  19268. /**
  19269. * Module exports.
  19270. */
  19271. module.exports = deprecate;
  19272. /**
  19273. * Mark that a method should not be used.
  19274. * Returns a modified function which warns once by default.
  19275. *
  19276. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  19277. *
  19278. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  19279. * will throw an Error when invoked.
  19280. *
  19281. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  19282. * will invoke `console.trace()` instead of `console.error()`.
  19283. *
  19284. * @param {Function} fn - the function to deprecate
  19285. * @param {String} msg - the string to print to the console when `fn` is invoked
  19286. * @returns {Function} a new "deprecated" version of `fn`
  19287. * @api public
  19288. */
  19289. function deprecate (fn, msg) {
  19290. if (config('noDeprecation')) {
  19291. return fn;
  19292. }
  19293. var warned = false;
  19294. function deprecated() {
  19295. if (!warned) {
  19296. if (config('throwDeprecation')) {
  19297. throw new Error(msg);
  19298. } else if (config('traceDeprecation')) {
  19299. console.trace(msg);
  19300. } else {
  19301. console.warn(msg);
  19302. }
  19303. warned = true;
  19304. }
  19305. return fn.apply(this, arguments);
  19306. }
  19307. return deprecated;
  19308. }
  19309. /**
  19310. * Checks `localStorage` for boolean values for the given `name`.
  19311. *
  19312. * @param {String} name
  19313. * @returns {Boolean}
  19314. * @api private
  19315. */
  19316. function config (name) {
  19317. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  19318. try {
  19319. if (!global.localStorage) return false;
  19320. } catch (_) {
  19321. return false;
  19322. }
  19323. var val = global.localStorage[name];
  19324. if (null == val) return false;
  19325. return String(val).toLowerCase() === 'true';
  19326. }
  19327. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  19328. },{}],146:[function(require,module,exports){
  19329. var indexOf = require('indexof');
  19330. var Object_keys = function (obj) {
  19331. if (Object.keys) return Object.keys(obj)
  19332. else {
  19333. var res = [];
  19334. for (var key in obj) res.push(key)
  19335. return res;
  19336. }
  19337. };
  19338. var forEach = function (xs, fn) {
  19339. if (xs.forEach) return xs.forEach(fn)
  19340. else for (var i = 0; i < xs.length; i++) {
  19341. fn(xs[i], i, xs);
  19342. }
  19343. };
  19344. var defineProp = (function() {
  19345. try {
  19346. Object.defineProperty({}, '_', {});
  19347. return function(obj, name, value) {
  19348. Object.defineProperty(obj, name, {
  19349. writable: true,
  19350. enumerable: false,
  19351. configurable: true,
  19352. value: value
  19353. })
  19354. };
  19355. } catch(e) {
  19356. return function(obj, name, value) {
  19357. obj[name] = value;
  19358. };
  19359. }
  19360. }());
  19361. var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
  19362. 'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
  19363. 'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
  19364. 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
  19365. 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'];
  19366. function Context() {}
  19367. Context.prototype = {};
  19368. var Script = exports.Script = function NodeScript (code) {
  19369. if (!(this instanceof Script)) return new Script(code);
  19370. this.code = code;
  19371. };
  19372. Script.prototype.runInContext = function (context) {
  19373. if (!(context instanceof Context)) {
  19374. throw new TypeError("needs a 'context' argument.");
  19375. }
  19376. var iframe = document.createElement('iframe');
  19377. if (!iframe.style) iframe.style = {};
  19378. iframe.style.display = 'none';
  19379. document.body.appendChild(iframe);
  19380. var win = iframe.contentWindow;
  19381. var wEval = win.eval, wExecScript = win.execScript;
  19382. if (!wEval && wExecScript) {
  19383. // win.eval() magically appears when this is called in IE:
  19384. wExecScript.call(win, 'null');
  19385. wEval = win.eval;
  19386. }
  19387. forEach(Object_keys(context), function (key) {
  19388. win[key] = context[key];
  19389. });
  19390. forEach(globals, function (key) {
  19391. if (context[key]) {
  19392. win[key] = context[key];
  19393. }
  19394. });
  19395. var winKeys = Object_keys(win);
  19396. var res = wEval.call(win, this.code);
  19397. forEach(Object_keys(win), function (key) {
  19398. // Avoid copying circular objects like `top` and `window` by only
  19399. // updating existing context properties or new properties in the `win`
  19400. // that was only introduced after the eval.
  19401. if (key in context || indexOf(winKeys, key) === -1) {
  19402. context[key] = win[key];
  19403. }
  19404. });
  19405. forEach(globals, function (key) {
  19406. if (!(key in context)) {
  19407. defineProp(context, key, win[key]);
  19408. }
  19409. });
  19410. document.body.removeChild(iframe);
  19411. return res;
  19412. };
  19413. Script.prototype.runInThisContext = function () {
  19414. return eval(this.code); // maybe...
  19415. };
  19416. Script.prototype.runInNewContext = function (context) {
  19417. var ctx = Script.createContext(context);
  19418. var res = this.runInContext(ctx);
  19419. forEach(Object_keys(ctx), function (key) {
  19420. context[key] = ctx[key];
  19421. });
  19422. return res;
  19423. };
  19424. forEach(Object_keys(Script.prototype), function (name) {
  19425. exports[name] = Script[name] = function (code) {
  19426. var s = Script(code);
  19427. return s[name].apply(s, [].slice.call(arguments, 1));
  19428. };
  19429. });
  19430. exports.createScript = function (code) {
  19431. return exports.Script(code);
  19432. };
  19433. exports.createContext = Script.createContext = function (context) {
  19434. var copy = new Context();
  19435. if(typeof context === 'object') {
  19436. forEach(Object_keys(context), function (key) {
  19437. copy[key] = context[key];
  19438. });
  19439. }
  19440. return copy;
  19441. };
  19442. },{"indexof":91}]},{},[1]);