選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

22575 行
672 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. var emailField = document.querySelector('#login-container-email');
  8. var passwordField = document.querySelector('#login-container-password');
  9. var siteField = document.querySelector('#login-container-site');
  10. function getLocalStore(storeName) {
  11. return new Promise(function (resolve, reject) {
  12. chrome.storage.local.get(storeName, function (result) {
  13. if (result === null) {
  14. return reject(storeName + ' not found');
  15. }
  16. resolve(result);
  17. });
  18. });
  19. }
  20. function updateStore(store) {
  21. return new Promise(function (resolve) {
  22. chrome.storage.local.set(store, function () {
  23. resolve(store);
  24. });
  25. });
  26. }
  27. function getCurrentTab() {
  28. return new Promise(function (resolve) {
  29. chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
  30. resolve(tabs[0]);
  31. });
  32. });
  33. }
  34. document.getElementById('login-container-btn').addEventListener('click', function () {
  35. var email = emailField.value;
  36. var site = siteField.value;
  37. var masterPassword = passwordField.value;
  38. if (!email || !masterPassword || !site) {
  39. return;
  40. }
  41. var storagePromise = getLocalStore('lesspassStore').then(function (store) {
  42. store.lesspassStore.email = email;
  43. return updateStore(store);
  44. });
  45. var hashPromise = _lesspass2.default.createMasterPassword(email, masterPassword);
  46. var lesspassPromise = Promise.all([hashPromise, storagePromise]).then(function (values) {
  47. var entry = {
  48. site: site,
  49. password: values[1].lesspassStore.password
  50. };
  51. return _lesspass2.default.createPassword(values[0], entry);
  52. });
  53. var tabPromise = getCurrentTab();
  54. Promise.all([lesspassPromise, tabPromise]).then(function (values) {
  55. chrome.tabs.sendMessage(values[1].id, { login: email, password: values[0] });
  56. window.close();
  57. });
  58. });
  59. function setDomainName(domain) {
  60. siteField.value = domain;
  61. }
  62. function setEmail(email) {
  63. emailField.value = email;
  64. }
  65. function initStore(callback) {
  66. chrome.storage.local.get('lesspassStore', function (result) {
  67. var store = {
  68. password: { length: 12, settings: ['lowercase', 'uppercase', 'numbers', 'symbols'], counter: 1 },
  69. email: ''
  70. };
  71. var lesspassStore = result.lesspassStore;
  72. if (typeof lesspassStore !== 'undefined') {
  73. if ('email' in lesspassStore) {
  74. store.email = lesspassStore.email;
  75. }
  76. if ('password' in lesspassStore) {
  77. store.password = lesspassStore.password;
  78. }
  79. }
  80. chrome.storage.local.set({ lesspassStore: store }, function () {
  81. callback(store);
  82. });
  83. });
  84. }
  85. chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
  86. if (tabs[0]) {
  87. initStore(function (store) {
  88. setEmail(store.email);
  89. });
  90. var currentTab = tabs[0];
  91. setDomainName((0, _urlParser.getDomainName)(currentTab.url));
  92. passwordField.focus();
  93. }
  94. });
  95. },{"./url-parser":2,"lesspass":95}],2:[function(require,module,exports){
  96. 'use strict';
  97. Object.defineProperty(exports, "__esModule", {
  98. value: true
  99. });
  100. exports._ipIsValid = exports.getDomainName = undefined;
  101. var _tldjs = require('tldjs');
  102. var _tldjs2 = _interopRequireDefault(_tldjs);
  103. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  104. function _ipIsValid(ipAddress) {
  105. 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));
  106. }
  107. function getDomainName(urlStr) {
  108. var domain = _tldjs2.default.getDomain(urlStr);
  109. var subDomain = _tldjs2.default.getSubdomain(urlStr);
  110. var ip = subDomain + '.' + domain;
  111. if (_ipIsValid(ip)) {
  112. return ip;
  113. }
  114. return domain;
  115. }
  116. exports.getDomainName = getDomainName;
  117. exports._ipIsValid = _ipIsValid;
  118. },{"tldjs":139}],3:[function(require,module,exports){
  119. var asn1 = exports;
  120. asn1.bignum = require('bn.js');
  121. asn1.define = require('./asn1/api').define;
  122. asn1.base = require('./asn1/base');
  123. asn1.constants = require('./asn1/constants');
  124. asn1.decoders = require('./asn1/decoders');
  125. asn1.encoders = require('./asn1/encoders');
  126. },{"./asn1/api":4,"./asn1/base":6,"./asn1/constants":10,"./asn1/decoders":12,"./asn1/encoders":15,"bn.js":18}],4:[function(require,module,exports){
  127. var asn1 = require('../asn1');
  128. var inherits = require('inherits');
  129. var api = exports;
  130. api.define = function define(name, body) {
  131. return new Entity(name, body);
  132. };
  133. function Entity(name, body) {
  134. this.name = name;
  135. this.body = body;
  136. this.decoders = {};
  137. this.encoders = {};
  138. };
  139. Entity.prototype._createNamed = function createNamed(base) {
  140. var named;
  141. try {
  142. named = require('vm').runInThisContext(
  143. '(function ' + this.name + '(entity) {\n' +
  144. ' this._initNamed(entity);\n' +
  145. '})'
  146. );
  147. } catch (e) {
  148. named = function (entity) {
  149. this._initNamed(entity);
  150. };
  151. }
  152. inherits(named, base);
  153. named.prototype._initNamed = function initnamed(entity) {
  154. base.call(this, entity);
  155. };
  156. return new named(this);
  157. };
  158. Entity.prototype._getDecoder = function _getDecoder(enc) {
  159. enc = enc || 'der';
  160. // Lazily create decoder
  161. if (!this.decoders.hasOwnProperty(enc))
  162. this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
  163. return this.decoders[enc];
  164. };
  165. Entity.prototype.decode = function decode(data, enc, options) {
  166. return this._getDecoder(enc).decode(data, options);
  167. };
  168. Entity.prototype._getEncoder = function _getEncoder(enc) {
  169. enc = enc || 'der';
  170. // Lazily create encoder
  171. if (!this.encoders.hasOwnProperty(enc))
  172. this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
  173. return this.encoders[enc];
  174. };
  175. Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
  176. return this._getEncoder(enc).encode(data, reporter);
  177. };
  178. },{"../asn1":3,"inherits":92,"vm":146}],5:[function(require,module,exports){
  179. var inherits = require('inherits');
  180. var Reporter = require('../base').Reporter;
  181. var Buffer = require('buffer').Buffer;
  182. function DecoderBuffer(base, options) {
  183. Reporter.call(this, options);
  184. if (!Buffer.isBuffer(base)) {
  185. this.error('Input not Buffer');
  186. return;
  187. }
  188. this.base = base;
  189. this.offset = 0;
  190. this.length = base.length;
  191. }
  192. inherits(DecoderBuffer, Reporter);
  193. exports.DecoderBuffer = DecoderBuffer;
  194. DecoderBuffer.prototype.save = function save() {
  195. return { offset: this.offset, reporter: Reporter.prototype.save.call(this) };
  196. };
  197. DecoderBuffer.prototype.restore = function restore(save) {
  198. // Return skipped data
  199. var res = new DecoderBuffer(this.base);
  200. res.offset = save.offset;
  201. res.length = this.offset;
  202. this.offset = save.offset;
  203. Reporter.prototype.restore.call(this, save.reporter);
  204. return res;
  205. };
  206. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  207. return this.offset === this.length;
  208. };
  209. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  210. if (this.offset + 1 <= this.length)
  211. return this.base.readUInt8(this.offset++, true);
  212. else
  213. return this.error(fail || 'DecoderBuffer overrun');
  214. }
  215. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  216. if (!(this.offset + bytes <= this.length))
  217. return this.error(fail || 'DecoderBuffer overrun');
  218. var res = new DecoderBuffer(this.base);
  219. // Share reporter state
  220. res._reporterState = this._reporterState;
  221. res.offset = this.offset;
  222. res.length = this.offset + bytes;
  223. this.offset += bytes;
  224. return res;
  225. }
  226. DecoderBuffer.prototype.raw = function raw(save) {
  227. return this.base.slice(save ? save.offset : this.offset, this.length);
  228. }
  229. function EncoderBuffer(value, reporter) {
  230. if (Array.isArray(value)) {
  231. this.length = 0;
  232. this.value = value.map(function(item) {
  233. if (!(item instanceof EncoderBuffer))
  234. item = new EncoderBuffer(item, reporter);
  235. this.length += item.length;
  236. return item;
  237. }, this);
  238. } else if (typeof value === 'number') {
  239. if (!(0 <= value && value <= 0xff))
  240. return reporter.error('non-byte EncoderBuffer value');
  241. this.value = value;
  242. this.length = 1;
  243. } else if (typeof value === 'string') {
  244. this.value = value;
  245. this.length = Buffer.byteLength(value);
  246. } else if (Buffer.isBuffer(value)) {
  247. this.value = value;
  248. this.length = value.length;
  249. } else {
  250. return reporter.error('Unsupported type: ' + typeof value);
  251. }
  252. }
  253. exports.EncoderBuffer = EncoderBuffer;
  254. EncoderBuffer.prototype.join = function join(out, offset) {
  255. if (!out)
  256. out = new Buffer(this.length);
  257. if (!offset)
  258. offset = 0;
  259. if (this.length === 0)
  260. return out;
  261. if (Array.isArray(this.value)) {
  262. this.value.forEach(function(item) {
  263. item.join(out, offset);
  264. offset += item.length;
  265. });
  266. } else {
  267. if (typeof this.value === 'number')
  268. out[offset] = this.value;
  269. else if (typeof this.value === 'string')
  270. out.write(this.value, offset);
  271. else if (Buffer.isBuffer(this.value))
  272. this.value.copy(out, offset);
  273. offset += this.length;
  274. }
  275. return out;
  276. };
  277. },{"../base":6,"buffer":46,"inherits":92}],6:[function(require,module,exports){
  278. var base = exports;
  279. base.Reporter = require('./reporter').Reporter;
  280. base.DecoderBuffer = require('./buffer').DecoderBuffer;
  281. base.EncoderBuffer = require('./buffer').EncoderBuffer;
  282. base.Node = require('./node');
  283. },{"./buffer":5,"./node":7,"./reporter":8}],7:[function(require,module,exports){
  284. var Reporter = require('../base').Reporter;
  285. var EncoderBuffer = require('../base').EncoderBuffer;
  286. var DecoderBuffer = require('../base').DecoderBuffer;
  287. var assert = require('minimalistic-assert');
  288. // Supported tags
  289. var tags = [
  290. 'seq', 'seqof', 'set', 'setof', 'objid', 'bool',
  291. 'gentime', 'utctime', 'null_', 'enum', 'int',
  292. 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str',
  293. 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr'
  294. ];
  295. // Public methods list
  296. var methods = [
  297. 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice',
  298. 'any', 'contains'
  299. ].concat(tags);
  300. // Overrided methods list
  301. var overrided = [
  302. '_peekTag', '_decodeTag', '_use',
  303. '_decodeStr', '_decodeObjid', '_decodeTime',
  304. '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList',
  305. '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime',
  306. '_encodeNull', '_encodeInt', '_encodeBool'
  307. ];
  308. function Node(enc, parent) {
  309. var state = {};
  310. this._baseState = state;
  311. state.enc = enc;
  312. state.parent = parent || null;
  313. state.children = null;
  314. // State
  315. state.tag = null;
  316. state.args = null;
  317. state.reverseArgs = null;
  318. state.choice = null;
  319. state.optional = false;
  320. state.any = false;
  321. state.obj = false;
  322. state.use = null;
  323. state.useDecoder = null;
  324. state.key = null;
  325. state['default'] = null;
  326. state.explicit = null;
  327. state.implicit = null;
  328. state.contains = null;
  329. // Should create new instance on each method
  330. if (!state.parent) {
  331. state.children = [];
  332. this._wrap();
  333. }
  334. }
  335. module.exports = Node;
  336. var stateProps = [
  337. 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice',
  338. 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit',
  339. 'implicit'
  340. ];
  341. Node.prototype.clone = function clone() {
  342. var state = this._baseState;
  343. var cstate = {};
  344. stateProps.forEach(function(prop) {
  345. cstate[prop] = state[prop];
  346. });
  347. var res = new this.constructor(cstate.parent);
  348. res._baseState = cstate;
  349. return res;
  350. };
  351. Node.prototype._wrap = function wrap() {
  352. var state = this._baseState;
  353. methods.forEach(function(method) {
  354. this[method] = function _wrappedMethod() {
  355. var clone = new this.constructor(this);
  356. state.children.push(clone);
  357. return clone[method].apply(clone, arguments);
  358. };
  359. }, this);
  360. };
  361. Node.prototype._init = function init(body) {
  362. var state = this._baseState;
  363. assert(state.parent === null);
  364. body.call(this);
  365. // Filter children
  366. state.children = state.children.filter(function(child) {
  367. return child._baseState.parent === this;
  368. }, this);
  369. assert.equal(state.children.length, 1, 'Root node can have only one child');
  370. };
  371. Node.prototype._useArgs = function useArgs(args) {
  372. var state = this._baseState;
  373. // Filter children and args
  374. var children = args.filter(function(arg) {
  375. return arg instanceof this.constructor;
  376. }, this);
  377. args = args.filter(function(arg) {
  378. return !(arg instanceof this.constructor);
  379. }, this);
  380. if (children.length !== 0) {
  381. assert(state.children === null);
  382. state.children = children;
  383. // Replace parent to maintain backward link
  384. children.forEach(function(child) {
  385. child._baseState.parent = this;
  386. }, this);
  387. }
  388. if (args.length !== 0) {
  389. assert(state.args === null);
  390. state.args = args;
  391. state.reverseArgs = args.map(function(arg) {
  392. if (typeof arg !== 'object' || arg.constructor !== Object)
  393. return arg;
  394. var res = {};
  395. Object.keys(arg).forEach(function(key) {
  396. if (key == (key | 0))
  397. key |= 0;
  398. var value = arg[key];
  399. res[value] = key;
  400. });
  401. return res;
  402. });
  403. }
  404. };
  405. //
  406. // Overrided methods
  407. //
  408. overrided.forEach(function(method) {
  409. Node.prototype[method] = function _overrided() {
  410. var state = this._baseState;
  411. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  412. };
  413. });
  414. //
  415. // Public methods
  416. //
  417. tags.forEach(function(tag) {
  418. Node.prototype[tag] = function _tagMethod() {
  419. var state = this._baseState;
  420. var args = Array.prototype.slice.call(arguments);
  421. assert(state.tag === null);
  422. state.tag = tag;
  423. this._useArgs(args);
  424. return this;
  425. };
  426. });
  427. Node.prototype.use = function use(item) {
  428. var state = this._baseState;
  429. assert(state.use === null);
  430. state.use = item;
  431. return this;
  432. };
  433. Node.prototype.optional = function optional() {
  434. var state = this._baseState;
  435. state.optional = true;
  436. return this;
  437. };
  438. Node.prototype.def = function def(val) {
  439. var state = this._baseState;
  440. assert(state['default'] === null);
  441. state['default'] = val;
  442. state.optional = true;
  443. return this;
  444. };
  445. Node.prototype.explicit = function explicit(num) {
  446. var state = this._baseState;
  447. assert(state.explicit === null && state.implicit === null);
  448. state.explicit = num;
  449. return this;
  450. };
  451. Node.prototype.implicit = function implicit(num) {
  452. var state = this._baseState;
  453. assert(state.explicit === null && state.implicit === null);
  454. state.implicit = num;
  455. return this;
  456. };
  457. Node.prototype.obj = function obj() {
  458. var state = this._baseState;
  459. var args = Array.prototype.slice.call(arguments);
  460. state.obj = true;
  461. if (args.length !== 0)
  462. this._useArgs(args);
  463. return this;
  464. };
  465. Node.prototype.key = function key(newKey) {
  466. var state = this._baseState;
  467. assert(state.key === null);
  468. state.key = newKey;
  469. return this;
  470. };
  471. Node.prototype.any = function any() {
  472. var state = this._baseState;
  473. state.any = true;
  474. return this;
  475. };
  476. Node.prototype.choice = function choice(obj) {
  477. var state = this._baseState;
  478. assert(state.choice === null);
  479. state.choice = obj;
  480. this._useArgs(Object.keys(obj).map(function(key) {
  481. return obj[key];
  482. }));
  483. return this;
  484. };
  485. Node.prototype.contains = function contains(item) {
  486. var state = this._baseState;
  487. assert(state.use === null);
  488. state.contains = item;
  489. return this;
  490. };
  491. //
  492. // Decoding
  493. //
  494. Node.prototype._decode = function decode(input) {
  495. var state = this._baseState;
  496. // Decode root node
  497. if (state.parent === null)
  498. return input.wrapResult(state.children[0]._decode(input));
  499. var result = state['default'];
  500. var present = true;
  501. var prevKey;
  502. if (state.key !== null)
  503. prevKey = input.enterKey(state.key);
  504. // Check if tag is there
  505. if (state.optional) {
  506. var tag = null;
  507. if (state.explicit !== null)
  508. tag = state.explicit;
  509. else if (state.implicit !== null)
  510. tag = state.implicit;
  511. else if (state.tag !== null)
  512. tag = state.tag;
  513. if (tag === null && !state.any) {
  514. // Trial and Error
  515. var save = input.save();
  516. try {
  517. if (state.choice === null)
  518. this._decodeGeneric(state.tag, input);
  519. else
  520. this._decodeChoice(input);
  521. present = true;
  522. } catch (e) {
  523. present = false;
  524. }
  525. input.restore(save);
  526. } else {
  527. present = this._peekTag(input, tag, state.any);
  528. if (input.isError(present))
  529. return present;
  530. }
  531. }
  532. // Push object on stack
  533. var prevObj;
  534. if (state.obj && present)
  535. prevObj = input.enterObject();
  536. if (present) {
  537. // Unwrap explicit values
  538. if (state.explicit !== null) {
  539. var explicit = this._decodeTag(input, state.explicit);
  540. if (input.isError(explicit))
  541. return explicit;
  542. input = explicit;
  543. }
  544. // Unwrap implicit and normal values
  545. if (state.use === null && state.choice === null) {
  546. if (state.any)
  547. var save = input.save();
  548. var body = this._decodeTag(
  549. input,
  550. state.implicit !== null ? state.implicit : state.tag,
  551. state.any
  552. );
  553. if (input.isError(body))
  554. return body;
  555. if (state.any)
  556. result = input.raw(save);
  557. else
  558. input = body;
  559. }
  560. // Select proper method for tag
  561. if (state.any)
  562. result = result;
  563. else if (state.choice === null)
  564. result = this._decodeGeneric(state.tag, input);
  565. else
  566. result = this._decodeChoice(input);
  567. if (input.isError(result))
  568. return result;
  569. // Decode children
  570. if (!state.any && state.choice === null && state.children !== null) {
  571. state.children.forEach(function decodeChildren(child) {
  572. // NOTE: We are ignoring errors here, to let parser continue with other
  573. // parts of encoded data
  574. child._decode(input);
  575. });
  576. }
  577. // Decode contained/encoded by schema, only in bit or octet strings
  578. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  579. var data = new DecoderBuffer(result);
  580. result = this._getUse(state.contains, input._reporterState.obj)._decode(data);
  581. }
  582. }
  583. // Pop object
  584. if (state.obj && present)
  585. result = input.leaveObject(prevObj);
  586. // Set key
  587. if (state.key !== null && (result !== null || present === true))
  588. input.leaveKey(prevKey, state.key, result);
  589. return result;
  590. };
  591. Node.prototype._decodeGeneric = function decodeGeneric(tag, input) {
  592. var state = this._baseState;
  593. if (tag === 'seq' || tag === 'set')
  594. return null;
  595. if (tag === 'seqof' || tag === 'setof')
  596. return this._decodeList(input, tag, state.args[0]);
  597. else if (/str$/.test(tag))
  598. return this._decodeStr(input, tag);
  599. else if (tag === 'objid' && state.args)
  600. return this._decodeObjid(input, state.args[0], state.args[1]);
  601. else if (tag === 'objid')
  602. return this._decodeObjid(input, null, null);
  603. else if (tag === 'gentime' || tag === 'utctime')
  604. return this._decodeTime(input, tag);
  605. else if (tag === 'null_')
  606. return this._decodeNull(input);
  607. else if (tag === 'bool')
  608. return this._decodeBool(input);
  609. else if (tag === 'int' || tag === 'enum')
  610. return this._decodeInt(input, state.args && state.args[0]);
  611. else if (state.use !== null)
  612. return this._getUse(state.use, input._reporterState.obj)._decode(input);
  613. else
  614. return input.error('unknown tag: ' + tag);
  615. };
  616. Node.prototype._getUse = function _getUse(entity, obj) {
  617. var state = this._baseState;
  618. // Create altered use decoder if implicit is set
  619. state.useDecoder = this._use(entity, obj);
  620. assert(state.useDecoder._baseState.parent === null);
  621. state.useDecoder = state.useDecoder._baseState.children[0];
  622. if (state.implicit !== state.useDecoder._baseState.implicit) {
  623. state.useDecoder = state.useDecoder.clone();
  624. state.useDecoder._baseState.implicit = state.implicit;
  625. }
  626. return state.useDecoder;
  627. };
  628. Node.prototype._decodeChoice = function decodeChoice(input) {
  629. var state = this._baseState;
  630. var result = null;
  631. var match = false;
  632. Object.keys(state.choice).some(function(key) {
  633. var save = input.save();
  634. var node = state.choice[key];
  635. try {
  636. var value = node._decode(input);
  637. if (input.isError(value))
  638. return false;
  639. result = { type: key, value: value };
  640. match = true;
  641. } catch (e) {
  642. input.restore(save);
  643. return false;
  644. }
  645. return true;
  646. }, this);
  647. if (!match)
  648. return input.error('Choice not matched');
  649. return result;
  650. };
  651. //
  652. // Encoding
  653. //
  654. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  655. return new EncoderBuffer(data, this.reporter);
  656. };
  657. Node.prototype._encode = function encode(data, reporter, parent) {
  658. var state = this._baseState;
  659. if (state['default'] !== null && state['default'] === data)
  660. return;
  661. var result = this._encodeValue(data, reporter, parent);
  662. if (result === undefined)
  663. return;
  664. if (this._skipDefault(result, reporter, parent))
  665. return;
  666. return result;
  667. };
  668. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  669. var state = this._baseState;
  670. // Decode root node
  671. if (state.parent === null)
  672. return state.children[0]._encode(data, reporter || new Reporter());
  673. var result = null;
  674. // Set reporter to share it with a child class
  675. this.reporter = reporter;
  676. // Check if data is there
  677. if (state.optional && data === undefined) {
  678. if (state['default'] !== null)
  679. data = state['default']
  680. else
  681. return;
  682. }
  683. // Encode children first
  684. var content = null;
  685. var primitive = false;
  686. if (state.any) {
  687. // Anything that was given is translated to buffer
  688. result = this._createEncoderBuffer(data);
  689. } else if (state.choice) {
  690. result = this._encodeChoice(data, reporter);
  691. } else if (state.contains) {
  692. content = this._getUse(state.contains, parent)._encode(data, reporter);
  693. primitive = true;
  694. } else if (state.children) {
  695. content = state.children.map(function(child) {
  696. if (child._baseState.tag === 'null_')
  697. return child._encode(null, reporter, data);
  698. if (child._baseState.key === null)
  699. return reporter.error('Child should have a key');
  700. var prevKey = reporter.enterKey(child._baseState.key);
  701. if (typeof data !== 'object')
  702. return reporter.error('Child expected, but input is not object');
  703. var res = child._encode(data[child._baseState.key], reporter, data);
  704. reporter.leaveKey(prevKey);
  705. return res;
  706. }, this).filter(function(child) {
  707. return child;
  708. });
  709. content = this._createEncoderBuffer(content);
  710. } else {
  711. if (state.tag === 'seqof' || state.tag === 'setof') {
  712. // TODO(indutny): this should be thrown on DSL level
  713. if (!(state.args && state.args.length === 1))
  714. return reporter.error('Too many args for : ' + state.tag);
  715. if (!Array.isArray(data))
  716. return reporter.error('seqof/setof, but data is not Array');
  717. var child = this.clone();
  718. child._baseState.implicit = null;
  719. content = this._createEncoderBuffer(data.map(function(item) {
  720. var state = this._baseState;
  721. return this._getUse(state.args[0], data)._encode(item, reporter);
  722. }, child));
  723. } else if (state.use !== null) {
  724. result = this._getUse(state.use, parent)._encode(data, reporter);
  725. } else {
  726. content = this._encodePrimitive(state.tag, data);
  727. primitive = true;
  728. }
  729. }
  730. // Encode data itself
  731. var result;
  732. if (!state.any && state.choice === null) {
  733. var tag = state.implicit !== null ? state.implicit : state.tag;
  734. var cls = state.implicit === null ? 'universal' : 'context';
  735. if (tag === null) {
  736. if (state.use === null)
  737. reporter.error('Tag could be ommited only for .use()');
  738. } else {
  739. if (state.use === null)
  740. result = this._encodeComposite(tag, primitive, cls, content);
  741. }
  742. }
  743. // Wrap in explicit
  744. if (state.explicit !== null)
  745. result = this._encodeComposite(state.explicit, false, 'context', result);
  746. return result;
  747. };
  748. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  749. var state = this._baseState;
  750. var node = state.choice[data.type];
  751. if (!node) {
  752. assert(
  753. false,
  754. data.type + ' not found in ' +
  755. JSON.stringify(Object.keys(state.choice)));
  756. }
  757. return node._encode(data.value, reporter);
  758. };
  759. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  760. var state = this._baseState;
  761. if (/str$/.test(tag))
  762. return this._encodeStr(data, tag);
  763. else if (tag === 'objid' && state.args)
  764. return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);
  765. else if (tag === 'objid')
  766. return this._encodeObjid(data, null, null);
  767. else if (tag === 'gentime' || tag === 'utctime')
  768. return this._encodeTime(data, tag);
  769. else if (tag === 'null_')
  770. return this._encodeNull();
  771. else if (tag === 'int' || tag === 'enum')
  772. return this._encodeInt(data, state.args && state.reverseArgs[0]);
  773. else if (tag === 'bool')
  774. return this._encodeBool(data);
  775. else
  776. throw new Error('Unsupported tag: ' + tag);
  777. };
  778. Node.prototype._isNumstr = function isNumstr(str) {
  779. return /^[0-9 ]*$/.test(str);
  780. };
  781. Node.prototype._isPrintstr = function isPrintstr(str) {
  782. return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str);
  783. };
  784. },{"../base":6,"minimalistic-assert":99}],8:[function(require,module,exports){
  785. var inherits = require('inherits');
  786. function Reporter(options) {
  787. this._reporterState = {
  788. obj: null,
  789. path: [],
  790. options: options || {},
  791. errors: []
  792. };
  793. }
  794. exports.Reporter = Reporter;
  795. Reporter.prototype.isError = function isError(obj) {
  796. return obj instanceof ReporterError;
  797. };
  798. Reporter.prototype.save = function save() {
  799. var state = this._reporterState;
  800. return { obj: state.obj, pathLen: state.path.length };
  801. };
  802. Reporter.prototype.restore = function restore(data) {
  803. var state = this._reporterState;
  804. state.obj = data.obj;
  805. state.path = state.path.slice(0, data.pathLen);
  806. };
  807. Reporter.prototype.enterKey = function enterKey(key) {
  808. return this._reporterState.path.push(key);
  809. };
  810. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  811. var state = this._reporterState;
  812. state.path = state.path.slice(0, index - 1);
  813. if (state.obj !== null)
  814. state.obj[key] = value;
  815. };
  816. Reporter.prototype.enterObject = function enterObject() {
  817. var state = this._reporterState;
  818. var prev = state.obj;
  819. state.obj = {};
  820. return prev;
  821. };
  822. Reporter.prototype.leaveObject = function leaveObject(prev) {
  823. var state = this._reporterState;
  824. var now = state.obj;
  825. state.obj = prev;
  826. return now;
  827. };
  828. Reporter.prototype.error = function error(msg) {
  829. var err;
  830. var state = this._reporterState;
  831. var inherited = msg instanceof ReporterError;
  832. if (inherited) {
  833. err = msg;
  834. } else {
  835. err = new ReporterError(state.path.map(function(elem) {
  836. return '[' + JSON.stringify(elem) + ']';
  837. }).join(''), msg.message || msg, msg.stack);
  838. }
  839. if (!state.options.partial)
  840. throw err;
  841. if (!inherited)
  842. state.errors.push(err);
  843. return err;
  844. };
  845. Reporter.prototype.wrapResult = function wrapResult(result) {
  846. var state = this._reporterState;
  847. if (!state.options.partial)
  848. return result;
  849. return {
  850. result: this.isError(result) ? null : result,
  851. errors: state.errors
  852. };
  853. };
  854. function ReporterError(path, msg) {
  855. this.path = path;
  856. this.rethrow(msg);
  857. };
  858. inherits(ReporterError, Error);
  859. ReporterError.prototype.rethrow = function rethrow(msg) {
  860. this.message = msg + ' at: ' + (this.path || '(shallow)');
  861. Error.captureStackTrace(this, ReporterError);
  862. return this;
  863. };
  864. },{"inherits":92}],9:[function(require,module,exports){
  865. var constants = require('../constants');
  866. exports.tagClass = {
  867. 0: 'universal',
  868. 1: 'application',
  869. 2: 'context',
  870. 3: 'private'
  871. };
  872. exports.tagClassByName = constants._reverse(exports.tagClass);
  873. exports.tag = {
  874. 0x00: 'end',
  875. 0x01: 'bool',
  876. 0x02: 'int',
  877. 0x03: 'bitstr',
  878. 0x04: 'octstr',
  879. 0x05: 'null_',
  880. 0x06: 'objid',
  881. 0x07: 'objDesc',
  882. 0x08: 'external',
  883. 0x09: 'real',
  884. 0x0a: 'enum',
  885. 0x0b: 'embed',
  886. 0x0c: 'utf8str',
  887. 0x0d: 'relativeOid',
  888. 0x10: 'seq',
  889. 0x11: 'set',
  890. 0x12: 'numstr',
  891. 0x13: 'printstr',
  892. 0x14: 't61str',
  893. 0x15: 'videostr',
  894. 0x16: 'ia5str',
  895. 0x17: 'utctime',
  896. 0x18: 'gentime',
  897. 0x19: 'graphstr',
  898. 0x1a: 'iso646str',
  899. 0x1b: 'genstr',
  900. 0x1c: 'unistr',
  901. 0x1d: 'charstr',
  902. 0x1e: 'bmpstr'
  903. };
  904. exports.tagByName = constants._reverse(exports.tag);
  905. },{"../constants":10}],10:[function(require,module,exports){
  906. var constants = exports;
  907. // Helper
  908. constants._reverse = function reverse(map) {
  909. var res = {};
  910. Object.keys(map).forEach(function(key) {
  911. // Convert key to integer if it is stringified
  912. if ((key | 0) == key)
  913. key = key | 0;
  914. var value = map[key];
  915. res[value] = key;
  916. });
  917. return res;
  918. };
  919. constants.der = require('./der');
  920. },{"./der":9}],11:[function(require,module,exports){
  921. var inherits = require('inherits');
  922. var asn1 = require('../../asn1');
  923. var base = asn1.base;
  924. var bignum = asn1.bignum;
  925. // Import DER constants
  926. var der = asn1.constants.der;
  927. function DERDecoder(entity) {
  928. this.enc = 'der';
  929. this.name = entity.name;
  930. this.entity = entity;
  931. // Construct base tree
  932. this.tree = new DERNode();
  933. this.tree._init(entity.body);
  934. };
  935. module.exports = DERDecoder;
  936. DERDecoder.prototype.decode = function decode(data, options) {
  937. if (!(data instanceof base.DecoderBuffer))
  938. data = new base.DecoderBuffer(data, options);
  939. return this.tree._decode(data, options);
  940. };
  941. // Tree methods
  942. function DERNode(parent) {
  943. base.Node.call(this, 'der', parent);
  944. }
  945. inherits(DERNode, base.Node);
  946. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  947. if (buffer.isEmpty())
  948. return false;
  949. var state = buffer.save();
  950. var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  951. if (buffer.isError(decodedTag))
  952. return decodedTag;
  953. buffer.restore(state);
  954. return decodedTag.tag === tag || decodedTag.tagStr === tag ||
  955. (decodedTag.tagStr + 'of') === tag || any;
  956. };
  957. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  958. var decodedTag = derDecodeTag(buffer,
  959. 'Failed to decode tag of "' + tag + '"');
  960. if (buffer.isError(decodedTag))
  961. return decodedTag;
  962. var len = derDecodeLen(buffer,
  963. decodedTag.primitive,
  964. 'Failed to get length of "' + tag + '"');
  965. // Failure
  966. if (buffer.isError(len))
  967. return len;
  968. if (!any &&
  969. decodedTag.tag !== tag &&
  970. decodedTag.tagStr !== tag &&
  971. decodedTag.tagStr + 'of' !== tag) {
  972. return buffer.error('Failed to match tag: "' + tag + '"');
  973. }
  974. if (decodedTag.primitive || len !== null)
  975. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  976. // Indefinite length... find END tag
  977. var state = buffer.save();
  978. var res = this._skipUntilEnd(
  979. buffer,
  980. 'Failed to skip indefinite length body: "' + this.tag + '"');
  981. if (buffer.isError(res))
  982. return res;
  983. len = buffer.offset - state.offset;
  984. buffer.restore(state);
  985. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  986. };
  987. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  988. while (true) {
  989. var tag = derDecodeTag(buffer, fail);
  990. if (buffer.isError(tag))
  991. return tag;
  992. var len = derDecodeLen(buffer, tag.primitive, fail);
  993. if (buffer.isError(len))
  994. return len;
  995. var res;
  996. if (tag.primitive || len !== null)
  997. res = buffer.skip(len)
  998. else
  999. res = this._skipUntilEnd(buffer, fail);
  1000. // Failure
  1001. if (buffer.isError(res))
  1002. return res;
  1003. if (tag.tagStr === 'end')
  1004. break;
  1005. }
  1006. };
  1007. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder) {
  1008. var result = [];
  1009. while (!buffer.isEmpty()) {
  1010. var possibleEnd = this._peekTag(buffer, 'end');
  1011. if (buffer.isError(possibleEnd))
  1012. return possibleEnd;
  1013. var res = decoder.decode(buffer, 'der');
  1014. if (buffer.isError(res) && possibleEnd)
  1015. break;
  1016. result.push(res);
  1017. }
  1018. return result;
  1019. };
  1020. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  1021. if (tag === 'bitstr') {
  1022. var unused = buffer.readUInt8();
  1023. if (buffer.isError(unused))
  1024. return unused;
  1025. return { unused: unused, data: buffer.raw() };
  1026. } else if (tag === 'bmpstr') {
  1027. var raw = buffer.raw();
  1028. if (raw.length % 2 === 1)
  1029. return buffer.error('Decoding of string type: bmpstr length mismatch');
  1030. var str = '';
  1031. for (var i = 0; i < raw.length / 2; i++) {
  1032. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  1033. }
  1034. return str;
  1035. } else if (tag === 'numstr') {
  1036. var numstr = buffer.raw().toString('ascii');
  1037. if (!this._isNumstr(numstr)) {
  1038. return buffer.error('Decoding of string type: ' +
  1039. 'numstr unsupported characters');
  1040. }
  1041. return numstr;
  1042. } else if (tag === 'octstr') {
  1043. return buffer.raw();
  1044. } else if (tag === 'printstr') {
  1045. var printstr = buffer.raw().toString('ascii');
  1046. if (!this._isPrintstr(printstr)) {
  1047. return buffer.error('Decoding of string type: ' +
  1048. 'printstr unsupported characters');
  1049. }
  1050. return printstr;
  1051. } else if (/str$/.test(tag)) {
  1052. return buffer.raw().toString();
  1053. } else {
  1054. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  1055. }
  1056. };
  1057. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  1058. var result;
  1059. var identifiers = [];
  1060. var ident = 0;
  1061. while (!buffer.isEmpty()) {
  1062. var subident = buffer.readUInt8();
  1063. ident <<= 7;
  1064. ident |= subident & 0x7f;
  1065. if ((subident & 0x80) === 0) {
  1066. identifiers.push(ident);
  1067. ident = 0;
  1068. }
  1069. }
  1070. if (subident & 0x80)
  1071. identifiers.push(ident);
  1072. var first = (identifiers[0] / 40) | 0;
  1073. var second = identifiers[0] % 40;
  1074. if (relative)
  1075. result = identifiers;
  1076. else
  1077. result = [first, second].concat(identifiers.slice(1));
  1078. if (values) {
  1079. var tmp = values[result.join(' ')];
  1080. if (tmp === undefined)
  1081. tmp = values[result.join('.')];
  1082. if (tmp !== undefined)
  1083. result = tmp;
  1084. }
  1085. return result;
  1086. };
  1087. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  1088. var str = buffer.raw().toString();
  1089. if (tag === 'gentime') {
  1090. var year = str.slice(0, 4) | 0;
  1091. var mon = str.slice(4, 6) | 0;
  1092. var day = str.slice(6, 8) | 0;
  1093. var hour = str.slice(8, 10) | 0;
  1094. var min = str.slice(10, 12) | 0;
  1095. var sec = str.slice(12, 14) | 0;
  1096. } else if (tag === 'utctime') {
  1097. var year = str.slice(0, 2) | 0;
  1098. var mon = str.slice(2, 4) | 0;
  1099. var day = str.slice(4, 6) | 0;
  1100. var hour = str.slice(6, 8) | 0;
  1101. var min = str.slice(8, 10) | 0;
  1102. var sec = str.slice(10, 12) | 0;
  1103. if (year < 70)
  1104. year = 2000 + year;
  1105. else
  1106. year = 1900 + year;
  1107. } else {
  1108. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  1109. }
  1110. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  1111. };
  1112. DERNode.prototype._decodeNull = function decodeNull(buffer) {
  1113. return null;
  1114. };
  1115. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  1116. var res = buffer.readUInt8();
  1117. if (buffer.isError(res))
  1118. return res;
  1119. else
  1120. return res !== 0;
  1121. };
  1122. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  1123. // Bigint, return as it is (assume big endian)
  1124. var raw = buffer.raw();
  1125. var res = new bignum(raw);
  1126. if (values)
  1127. res = values[res.toString(10)] || res;
  1128. return res;
  1129. };
  1130. DERNode.prototype._use = function use(entity, obj) {
  1131. if (typeof entity === 'function')
  1132. entity = entity(obj);
  1133. return entity._getDecoder('der').tree;
  1134. };
  1135. // Utility methods
  1136. function derDecodeTag(buf, fail) {
  1137. var tag = buf.readUInt8(fail);
  1138. if (buf.isError(tag))
  1139. return tag;
  1140. var cls = der.tagClass[tag >> 6];
  1141. var primitive = (tag & 0x20) === 0;
  1142. // Multi-octet tag - load
  1143. if ((tag & 0x1f) === 0x1f) {
  1144. var oct = tag;
  1145. tag = 0;
  1146. while ((oct & 0x80) === 0x80) {
  1147. oct = buf.readUInt8(fail);
  1148. if (buf.isError(oct))
  1149. return oct;
  1150. tag <<= 7;
  1151. tag |= oct & 0x7f;
  1152. }
  1153. } else {
  1154. tag &= 0x1f;
  1155. }
  1156. var tagStr = der.tag[tag];
  1157. return {
  1158. cls: cls,
  1159. primitive: primitive,
  1160. tag: tag,
  1161. tagStr: tagStr
  1162. };
  1163. }
  1164. function derDecodeLen(buf, primitive, fail) {
  1165. var len = buf.readUInt8(fail);
  1166. if (buf.isError(len))
  1167. return len;
  1168. // Indefinite form
  1169. if (!primitive && len === 0x80)
  1170. return null;
  1171. // Definite form
  1172. if ((len & 0x80) === 0) {
  1173. // Short form
  1174. return len;
  1175. }
  1176. // Long form
  1177. var num = len & 0x7f;
  1178. if (num >= 4)
  1179. return buf.error('length octect is too long');
  1180. len = 0;
  1181. for (var i = 0; i < num; i++) {
  1182. len <<= 8;
  1183. var j = buf.readUInt8(fail);
  1184. if (buf.isError(j))
  1185. return j;
  1186. len |= j;
  1187. }
  1188. return len;
  1189. }
  1190. },{"../../asn1":3,"inherits":92}],12:[function(require,module,exports){
  1191. var decoders = exports;
  1192. decoders.der = require('./der');
  1193. decoders.pem = require('./pem');
  1194. },{"./der":11,"./pem":13}],13:[function(require,module,exports){
  1195. var inherits = require('inherits');
  1196. var Buffer = require('buffer').Buffer;
  1197. var DERDecoder = require('./der');
  1198. function PEMDecoder(entity) {
  1199. DERDecoder.call(this, entity);
  1200. this.enc = 'pem';
  1201. };
  1202. inherits(PEMDecoder, DERDecoder);
  1203. module.exports = PEMDecoder;
  1204. PEMDecoder.prototype.decode = function decode(data, options) {
  1205. var lines = data.toString().split(/[\r\n]+/g);
  1206. var label = options.label.toUpperCase();
  1207. var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  1208. var start = -1;
  1209. var end = -1;
  1210. for (var i = 0; i < lines.length; i++) {
  1211. var match = lines[i].match(re);
  1212. if (match === null)
  1213. continue;
  1214. if (match[2] !== label)
  1215. continue;
  1216. if (start === -1) {
  1217. if (match[1] !== 'BEGIN')
  1218. break;
  1219. start = i;
  1220. } else {
  1221. if (match[1] !== 'END')
  1222. break;
  1223. end = i;
  1224. break;
  1225. }
  1226. }
  1227. if (start === -1 || end === -1)
  1228. throw new Error('PEM section not found for: ' + label);
  1229. var base64 = lines.slice(start + 1, end).join('');
  1230. // Remove excessive symbols
  1231. base64.replace(/[^a-z0-9\+\/=]+/gi, '');
  1232. var input = new Buffer(base64, 'base64');
  1233. return DERDecoder.prototype.decode.call(this, input, options);
  1234. };
  1235. },{"./der":11,"buffer":46,"inherits":92}],14:[function(require,module,exports){
  1236. var inherits = require('inherits');
  1237. var Buffer = require('buffer').Buffer;
  1238. var asn1 = require('../../asn1');
  1239. var base = asn1.base;
  1240. // Import DER constants
  1241. var der = asn1.constants.der;
  1242. function DEREncoder(entity) {
  1243. this.enc = 'der';
  1244. this.name = entity.name;
  1245. this.entity = entity;
  1246. // Construct base tree
  1247. this.tree = new DERNode();
  1248. this.tree._init(entity.body);
  1249. };
  1250. module.exports = DEREncoder;
  1251. DEREncoder.prototype.encode = function encode(data, reporter) {
  1252. return this.tree._encode(data, reporter).join();
  1253. };
  1254. // Tree methods
  1255. function DERNode(parent) {
  1256. base.Node.call(this, 'der', parent);
  1257. }
  1258. inherits(DERNode, base.Node);
  1259. DERNode.prototype._encodeComposite = function encodeComposite(tag,
  1260. primitive,
  1261. cls,
  1262. content) {
  1263. var encodedTag = encodeTag(tag, primitive, cls, this.reporter);
  1264. // Short form
  1265. if (content.length < 0x80) {
  1266. var header = new Buffer(2);
  1267. header[0] = encodedTag;
  1268. header[1] = content.length;
  1269. return this._createEncoderBuffer([ header, content ]);
  1270. }
  1271. // Long form
  1272. // Count octets required to store length
  1273. var lenOctets = 1;
  1274. for (var i = content.length; i >= 0x100; i >>= 8)
  1275. lenOctets++;
  1276. var header = new Buffer(1 + 1 + lenOctets);
  1277. header[0] = encodedTag;
  1278. header[1] = 0x80 | lenOctets;
  1279. for (var i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8)
  1280. header[i] = j & 0xff;
  1281. return this._createEncoderBuffer([ header, content ]);
  1282. };
  1283. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  1284. if (tag === 'bitstr') {
  1285. return this._createEncoderBuffer([ str.unused | 0, str.data ]);
  1286. } else if (tag === 'bmpstr') {
  1287. var buf = new Buffer(str.length * 2);
  1288. for (var i = 0; i < str.length; i++) {
  1289. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  1290. }
  1291. return this._createEncoderBuffer(buf);
  1292. } else if (tag === 'numstr') {
  1293. if (!this._isNumstr(str)) {
  1294. return this.reporter.error('Encoding of string type: numstr supports ' +
  1295. 'only digits and space');
  1296. }
  1297. return this._createEncoderBuffer(str);
  1298. } else if (tag === 'printstr') {
  1299. if (!this._isPrintstr(str)) {
  1300. return this.reporter.error('Encoding of string type: printstr supports ' +
  1301. 'only latin upper and lower case letters, ' +
  1302. 'digits, space, apostrophe, left and rigth ' +
  1303. 'parenthesis, plus sign, comma, hyphen, ' +
  1304. 'dot, slash, colon, equal sign, ' +
  1305. 'question mark');
  1306. }
  1307. return this._createEncoderBuffer(str);
  1308. } else if (/str$/.test(tag)) {
  1309. return this._createEncoderBuffer(str);
  1310. } else {
  1311. return this.reporter.error('Encoding of string type: ' + tag +
  1312. ' unsupported');
  1313. }
  1314. };
  1315. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  1316. if (typeof id === 'string') {
  1317. if (!values)
  1318. return this.reporter.error('string objid given, but no values map found');
  1319. if (!values.hasOwnProperty(id))
  1320. return this.reporter.error('objid not found in values map');
  1321. id = values[id].split(/[\s\.]+/g);
  1322. for (var i = 0; i < id.length; i++)
  1323. id[i] |= 0;
  1324. } else if (Array.isArray(id)) {
  1325. id = id.slice();
  1326. for (var i = 0; i < id.length; i++)
  1327. id[i] |= 0;
  1328. }
  1329. if (!Array.isArray(id)) {
  1330. return this.reporter.error('objid() should be either array or string, ' +
  1331. 'got: ' + JSON.stringify(id));
  1332. }
  1333. if (!relative) {
  1334. if (id[1] >= 40)
  1335. return this.reporter.error('Second objid identifier OOB');
  1336. id.splice(0, 2, id[0] * 40 + id[1]);
  1337. }
  1338. // Count number of octets
  1339. var size = 0;
  1340. for (var i = 0; i < id.length; i++) {
  1341. var ident = id[i];
  1342. for (size++; ident >= 0x80; ident >>= 7)
  1343. size++;
  1344. }
  1345. var objid = new Buffer(size);
  1346. var offset = objid.length - 1;
  1347. for (var i = id.length - 1; i >= 0; i--) {
  1348. var ident = id[i];
  1349. objid[offset--] = ident & 0x7f;
  1350. while ((ident >>= 7) > 0)
  1351. objid[offset--] = 0x80 | (ident & 0x7f);
  1352. }
  1353. return this._createEncoderBuffer(objid);
  1354. };
  1355. function two(num) {
  1356. if (num < 10)
  1357. return '0' + num;
  1358. else
  1359. return num;
  1360. }
  1361. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  1362. var str;
  1363. var date = new Date(time);
  1364. if (tag === 'gentime') {
  1365. str = [
  1366. two(date.getFullYear()),
  1367. two(date.getUTCMonth() + 1),
  1368. two(date.getUTCDate()),
  1369. two(date.getUTCHours()),
  1370. two(date.getUTCMinutes()),
  1371. two(date.getUTCSeconds()),
  1372. 'Z'
  1373. ].join('');
  1374. } else if (tag === 'utctime') {
  1375. str = [
  1376. two(date.getFullYear() % 100),
  1377. two(date.getUTCMonth() + 1),
  1378. two(date.getUTCDate()),
  1379. two(date.getUTCHours()),
  1380. two(date.getUTCMinutes()),
  1381. two(date.getUTCSeconds()),
  1382. 'Z'
  1383. ].join('');
  1384. } else {
  1385. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  1386. }
  1387. return this._encodeStr(str, 'octstr');
  1388. };
  1389. DERNode.prototype._encodeNull = function encodeNull() {
  1390. return this._createEncoderBuffer('');
  1391. };
  1392. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  1393. if (typeof num === 'string') {
  1394. if (!values)
  1395. return this.reporter.error('String int or enum given, but no values map');
  1396. if (!values.hasOwnProperty(num)) {
  1397. return this.reporter.error('Values map doesn\'t contain: ' +
  1398. JSON.stringify(num));
  1399. }
  1400. num = values[num];
  1401. }
  1402. // Bignum, assume big endian
  1403. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  1404. var numArray = num.toArray();
  1405. if (!num.sign && numArray[0] & 0x80) {
  1406. numArray.unshift(0);
  1407. }
  1408. num = new Buffer(numArray);
  1409. }
  1410. if (Buffer.isBuffer(num)) {
  1411. var size = num.length;
  1412. if (num.length === 0)
  1413. size++;
  1414. var out = new Buffer(size);
  1415. num.copy(out);
  1416. if (num.length === 0)
  1417. out[0] = 0
  1418. return this._createEncoderBuffer(out);
  1419. }
  1420. if (num < 0x80)
  1421. return this._createEncoderBuffer(num);
  1422. if (num < 0x100)
  1423. return this._createEncoderBuffer([0, num]);
  1424. var size = 1;
  1425. for (var i = num; i >= 0x100; i >>= 8)
  1426. size++;
  1427. var out = new Array(size);
  1428. for (var i = out.length - 1; i >= 0; i--) {
  1429. out[i] = num & 0xff;
  1430. num >>= 8;
  1431. }
  1432. if(out[0] & 0x80) {
  1433. out.unshift(0);
  1434. }
  1435. return this._createEncoderBuffer(new Buffer(out));
  1436. };
  1437. DERNode.prototype._encodeBool = function encodeBool(value) {
  1438. return this._createEncoderBuffer(value ? 0xff : 0);
  1439. };
  1440. DERNode.prototype._use = function use(entity, obj) {
  1441. if (typeof entity === 'function')
  1442. entity = entity(obj);
  1443. return entity._getEncoder('der').tree;
  1444. };
  1445. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  1446. var state = this._baseState;
  1447. var i;
  1448. if (state['default'] === null)
  1449. return false;
  1450. var data = dataBuffer.join();
  1451. if (state.defaultBuffer === undefined)
  1452. state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  1453. if (data.length !== state.defaultBuffer.length)
  1454. return false;
  1455. for (i=0; i < data.length; i++)
  1456. if (data[i] !== state.defaultBuffer[i])
  1457. return false;
  1458. return true;
  1459. };
  1460. // Utility methods
  1461. function encodeTag(tag, primitive, cls, reporter) {
  1462. var res;
  1463. if (tag === 'seqof')
  1464. tag = 'seq';
  1465. else if (tag === 'setof')
  1466. tag = 'set';
  1467. if (der.tagByName.hasOwnProperty(tag))
  1468. res = der.tagByName[tag];
  1469. else if (typeof tag === 'number' && (tag | 0) === tag)
  1470. res = tag;
  1471. else
  1472. return reporter.error('Unknown tag: ' + tag);
  1473. if (res >= 0x1f)
  1474. return reporter.error('Multi-octet tag encoding unsupported');
  1475. if (!primitive)
  1476. res |= 0x20;
  1477. res |= (der.tagClassByName[cls || 'universal'] << 6);
  1478. return res;
  1479. }
  1480. },{"../../asn1":3,"buffer":46,"inherits":92}],15:[function(require,module,exports){
  1481. var encoders = exports;
  1482. encoders.der = require('./der');
  1483. encoders.pem = require('./pem');
  1484. },{"./der":14,"./pem":16}],16:[function(require,module,exports){
  1485. var inherits = require('inherits');
  1486. var DEREncoder = require('./der');
  1487. function PEMEncoder(entity) {
  1488. DEREncoder.call(this, entity);
  1489. this.enc = 'pem';
  1490. };
  1491. inherits(PEMEncoder, DEREncoder);
  1492. module.exports = PEMEncoder;
  1493. PEMEncoder.prototype.encode = function encode(data, options) {
  1494. var buf = DEREncoder.prototype.encode.call(this, data);
  1495. var p = buf.toString('base64');
  1496. var out = [ '-----BEGIN ' + options.label + '-----' ];
  1497. for (var i = 0; i < p.length; i += 64)
  1498. out.push(p.slice(i, i + 64));
  1499. out.push('-----END ' + options.label + '-----');
  1500. return out.join('\n');
  1501. };
  1502. },{"./der":14,"inherits":92}],17:[function(require,module,exports){
  1503. 'use strict'
  1504. exports.toByteArray = toByteArray
  1505. exports.fromByteArray = fromByteArray
  1506. var lookup = []
  1507. var revLookup = []
  1508. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  1509. function init () {
  1510. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  1511. for (var i = 0, len = code.length; i < len; ++i) {
  1512. lookup[i] = code[i]
  1513. revLookup[code.charCodeAt(i)] = i
  1514. }
  1515. revLookup['-'.charCodeAt(0)] = 62
  1516. revLookup['_'.charCodeAt(0)] = 63
  1517. }
  1518. init()
  1519. function toByteArray (b64) {
  1520. var i, j, l, tmp, placeHolders, arr
  1521. var len = b64.length
  1522. if (len % 4 > 0) {
  1523. throw new Error('Invalid string. Length must be a multiple of 4')
  1524. }
  1525. // the number of equal signs (place holders)
  1526. // if there are two placeholders, than the two characters before it
  1527. // represent one byte
  1528. // if there is only one, then the three characters before it represent 2 bytes
  1529. // this is just a cheap hack to not do indexOf twice
  1530. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  1531. // base64 is 4/3 + up to two characters of the original data
  1532. arr = new Arr(len * 3 / 4 - placeHolders)
  1533. // if there are placeholders, only get up to the last complete 4 chars
  1534. l = placeHolders > 0 ? len - 4 : len
  1535. var L = 0
  1536. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1537. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  1538. arr[L++] = (tmp >> 16) & 0xFF
  1539. arr[L++] = (tmp >> 8) & 0xFF
  1540. arr[L++] = tmp & 0xFF
  1541. }
  1542. if (placeHolders === 2) {
  1543. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  1544. arr[L++] = tmp & 0xFF
  1545. } else if (placeHolders === 1) {
  1546. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  1547. arr[L++] = (tmp >> 8) & 0xFF
  1548. arr[L++] = tmp & 0xFF
  1549. }
  1550. return arr
  1551. }
  1552. function tripletToBase64 (num) {
  1553. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  1554. }
  1555. function encodeChunk (uint8, start, end) {
  1556. var tmp
  1557. var output = []
  1558. for (var i = start; i < end; i += 3) {
  1559. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  1560. output.push(tripletToBase64(tmp))
  1561. }
  1562. return output.join('')
  1563. }
  1564. function fromByteArray (uint8) {
  1565. var tmp
  1566. var len = uint8.length
  1567. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  1568. var output = ''
  1569. var parts = []
  1570. var maxChunkLength = 16383 // must be multiple of 3
  1571. // go through the array every three bytes, we'll deal with trailing stuff later
  1572. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  1573. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  1574. }
  1575. // pad the end with zeros, but make sure to not forget the extra bytes
  1576. if (extraBytes === 1) {
  1577. tmp = uint8[len - 1]
  1578. output += lookup[tmp >> 2]
  1579. output += lookup[(tmp << 4) & 0x3F]
  1580. output += '=='
  1581. } else if (extraBytes === 2) {
  1582. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  1583. output += lookup[tmp >> 10]
  1584. output += lookup[(tmp >> 4) & 0x3F]
  1585. output += lookup[(tmp << 2) & 0x3F]
  1586. output += '='
  1587. }
  1588. parts.push(output)
  1589. return parts.join('')
  1590. }
  1591. },{}],18:[function(require,module,exports){
  1592. (function (module, exports) {
  1593. 'use strict';
  1594. // Utils
  1595. function assert (val, msg) {
  1596. if (!val) throw new Error(msg || 'Assertion failed');
  1597. }
  1598. // Could use `inherits` module, but don't want to move from single file
  1599. // architecture yet.
  1600. function inherits (ctor, superCtor) {
  1601. ctor.super_ = superCtor;
  1602. var TempCtor = function () {};
  1603. TempCtor.prototype = superCtor.prototype;
  1604. ctor.prototype = new TempCtor();
  1605. ctor.prototype.constructor = ctor;
  1606. }
  1607. // BN
  1608. function BN (number, base, endian) {
  1609. if (BN.isBN(number)) {
  1610. return number;
  1611. }
  1612. this.negative = 0;
  1613. this.words = null;
  1614. this.length = 0;
  1615. // Reduction context
  1616. this.red = null;
  1617. if (number !== null) {
  1618. if (base === 'le' || base === 'be') {
  1619. endian = base;
  1620. base = 10;
  1621. }
  1622. this._init(number || 0, base || 10, endian || 'be');
  1623. }
  1624. }
  1625. if (typeof module === 'object') {
  1626. module.exports = BN;
  1627. } else {
  1628. exports.BN = BN;
  1629. }
  1630. BN.BN = BN;
  1631. BN.wordSize = 26;
  1632. var Buffer;
  1633. try {
  1634. Buffer = require('buf' + 'fer').Buffer;
  1635. } catch (e) {
  1636. }
  1637. BN.isBN = function isBN (num) {
  1638. return num !== null && typeof num === 'object' &&
  1639. num.constructor.name === 'BN' && Array.isArray(num.words);
  1640. };
  1641. BN.max = function max (left, right) {
  1642. if (left.cmp(right) > 0) return left;
  1643. return right;
  1644. };
  1645. BN.min = function min (left, right) {
  1646. if (left.cmp(right) < 0) return left;
  1647. return right;
  1648. };
  1649. BN.prototype._init = function init (number, base, endian) {
  1650. if (typeof number === 'number') {
  1651. return this._initNumber(number, base, endian);
  1652. }
  1653. if (typeof number === 'object') {
  1654. return this._initArray(number, base, endian);
  1655. }
  1656. if (base === 'hex') {
  1657. base = 16;
  1658. }
  1659. assert(base === (base | 0) && base >= 2 && base <= 36);
  1660. number = number.toString().replace(/\s+/g, '');
  1661. var start = 0;
  1662. if (number[0] === '-') {
  1663. start++;
  1664. }
  1665. if (base === 16) {
  1666. this._parseHex(number, start);
  1667. } else {
  1668. this._parseBase(number, base, start);
  1669. }
  1670. if (number[0] === '-') {
  1671. this.negative = 1;
  1672. }
  1673. this.strip();
  1674. if (endian !== 'le') return;
  1675. this._initArray(this.toArray(), base, endian);
  1676. };
  1677. BN.prototype._initNumber = function _initNumber (number, base, endian) {
  1678. if (number < 0) {
  1679. this.negative = 1;
  1680. number = -number;
  1681. }
  1682. if (number < 0x4000000) {
  1683. this.words = [ number & 0x3ffffff ];
  1684. this.length = 1;
  1685. } else if (number < 0x10000000000000) {
  1686. this.words = [
  1687. number & 0x3ffffff,
  1688. (number / 0x4000000) & 0x3ffffff
  1689. ];
  1690. this.length = 2;
  1691. } else {
  1692. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  1693. this.words = [
  1694. number & 0x3ffffff,
  1695. (number / 0x4000000) & 0x3ffffff,
  1696. 1
  1697. ];
  1698. this.length = 3;
  1699. }
  1700. if (endian !== 'le') return;
  1701. // Reverse the bytes
  1702. this._initArray(this.toArray(), base, endian);
  1703. };
  1704. BN.prototype._initArray = function _initArray (number, base, endian) {
  1705. // Perhaps a Uint8Array
  1706. assert(typeof number.length === 'number');
  1707. if (number.length <= 0) {
  1708. this.words = [ 0 ];
  1709. this.length = 1;
  1710. return this;
  1711. }
  1712. this.length = Math.ceil(number.length / 3);
  1713. this.words = new Array(this.length);
  1714. for (var i = 0; i < this.length; i++) {
  1715. this.words[i] = 0;
  1716. }
  1717. var j, w;
  1718. var off = 0;
  1719. if (endian === 'be') {
  1720. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  1721. w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
  1722. this.words[j] |= (w << off) & 0x3ffffff;
  1723. this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
  1724. off += 24;
  1725. if (off >= 26) {
  1726. off -= 26;
  1727. j++;
  1728. }
  1729. }
  1730. } else if (endian === 'le') {
  1731. for (i = 0, j = 0; i < number.length; i += 3) {
  1732. w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
  1733. this.words[j] |= (w << off) & 0x3ffffff;
  1734. this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
  1735. off += 24;
  1736. if (off >= 26) {
  1737. off -= 26;
  1738. j++;
  1739. }
  1740. }
  1741. }
  1742. return this.strip();
  1743. };
  1744. function parseHex (str, start, end) {
  1745. var r = 0;
  1746. var len = Math.min(str.length, end);
  1747. for (var i = start; i < len; i++) {
  1748. var c = str.charCodeAt(i) - 48;
  1749. r <<= 4;
  1750. // 'a' - 'f'
  1751. if (c >= 49 && c <= 54) {
  1752. r |= c - 49 + 0xa;
  1753. // 'A' - 'F'
  1754. } else if (c >= 17 && c <= 22) {
  1755. r |= c - 17 + 0xa;
  1756. // '0' - '9'
  1757. } else {
  1758. r |= c & 0xf;
  1759. }
  1760. }
  1761. return r;
  1762. }
  1763. BN.prototype._parseHex = function _parseHex (number, start) {
  1764. // Create possibly bigger array to ensure that it fits the number
  1765. this.length = Math.ceil((number.length - start) / 6);
  1766. this.words = new Array(this.length);
  1767. for (var i = 0; i < this.length; i++) {
  1768. this.words[i] = 0;
  1769. }
  1770. var j, w;
  1771. // Scan 24-bit chunks and add them to the number
  1772. var off = 0;
  1773. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  1774. w = parseHex(number, i, i + 6);
  1775. this.words[j] |= (w << off) & 0x3ffffff;
  1776. // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  1777. this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
  1778. off += 24;
  1779. if (off >= 26) {
  1780. off -= 26;
  1781. j++;
  1782. }
  1783. }
  1784. if (i + 6 !== start) {
  1785. w = parseHex(number, start, i + 6);
  1786. this.words[j] |= (w << off) & 0x3ffffff;
  1787. this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
  1788. }
  1789. this.strip();
  1790. };
  1791. function parseBase (str, start, end, mul) {
  1792. var r = 0;
  1793. var len = Math.min(str.length, end);
  1794. for (var i = start; i < len; i++) {
  1795. var c = str.charCodeAt(i) - 48;
  1796. r *= mul;
  1797. // 'a'
  1798. if (c >= 49) {
  1799. r += c - 49 + 0xa;
  1800. // 'A'
  1801. } else if (c >= 17) {
  1802. r += c - 17 + 0xa;
  1803. // '0' - '9'
  1804. } else {
  1805. r += c;
  1806. }
  1807. }
  1808. return r;
  1809. }
  1810. BN.prototype._parseBase = function _parseBase (number, base, start) {
  1811. // Initialize as zero
  1812. this.words = [ 0 ];
  1813. this.length = 1;
  1814. // Find length of limb in base
  1815. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  1816. limbLen++;
  1817. }
  1818. limbLen--;
  1819. limbPow = (limbPow / base) | 0;
  1820. var total = number.length - start;
  1821. var mod = total % limbLen;
  1822. var end = Math.min(total, total - mod) + start;
  1823. var word = 0;
  1824. for (var i = start; i < end; i += limbLen) {
  1825. word = parseBase(number, i, i + limbLen, base);
  1826. this.imuln(limbPow);
  1827. if (this.words[0] + word < 0x4000000) {
  1828. this.words[0] += word;
  1829. } else {
  1830. this._iaddn(word);
  1831. }
  1832. }
  1833. if (mod !== 0) {
  1834. var pow = 1;
  1835. word = parseBase(number, i, number.length, base);
  1836. for (i = 0; i < mod; i++) {
  1837. pow *= base;
  1838. }
  1839. this.imuln(pow);
  1840. if (this.words[0] + word < 0x4000000) {
  1841. this.words[0] += word;
  1842. } else {
  1843. this._iaddn(word);
  1844. }
  1845. }
  1846. };
  1847. BN.prototype.copy = function copy (dest) {
  1848. dest.words = new Array(this.length);
  1849. for (var i = 0; i < this.length; i++) {
  1850. dest.words[i] = this.words[i];
  1851. }
  1852. dest.length = this.length;
  1853. dest.negative = this.negative;
  1854. dest.red = this.red;
  1855. };
  1856. BN.prototype.clone = function clone () {
  1857. var r = new BN(null);
  1858. this.copy(r);
  1859. return r;
  1860. };
  1861. BN.prototype._expand = function _expand (size) {
  1862. while (this.length < size) {
  1863. this.words[this.length++] = 0;
  1864. }
  1865. return this;
  1866. };
  1867. // Remove leading `0` from `this`
  1868. BN.prototype.strip = function strip () {
  1869. while (this.length > 1 && this.words[this.length - 1] === 0) {
  1870. this.length--;
  1871. }
  1872. return this._normSign();
  1873. };
  1874. BN.prototype._normSign = function _normSign () {
  1875. // -0 = 0
  1876. if (this.length === 1 && this.words[0] === 0) {
  1877. this.negative = 0;
  1878. }
  1879. return this;
  1880. };
  1881. BN.prototype.inspect = function inspect () {
  1882. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  1883. };
  1884. /*
  1885. var zeros = [];
  1886. var groupSizes = [];
  1887. var groupBases = [];
  1888. var s = '';
  1889. var i = -1;
  1890. while (++i < BN.wordSize) {
  1891. zeros[i] = s;
  1892. s += '0';
  1893. }
  1894. groupSizes[0] = 0;
  1895. groupSizes[1] = 0;
  1896. groupBases[0] = 0;
  1897. groupBases[1] = 0;
  1898. var base = 2 - 1;
  1899. while (++base < 36 + 1) {
  1900. var groupSize = 0;
  1901. var groupBase = 1;
  1902. while (groupBase < (1 << BN.wordSize) / base) {
  1903. groupBase *= base;
  1904. groupSize += 1;
  1905. }
  1906. groupSizes[base] = groupSize;
  1907. groupBases[base] = groupBase;
  1908. }
  1909. */
  1910. var zeros = [
  1911. '',
  1912. '0',
  1913. '00',
  1914. '000',
  1915. '0000',
  1916. '00000',
  1917. '000000',
  1918. '0000000',
  1919. '00000000',
  1920. '000000000',
  1921. '0000000000',
  1922. '00000000000',
  1923. '000000000000',
  1924. '0000000000000',
  1925. '00000000000000',
  1926. '000000000000000',
  1927. '0000000000000000',
  1928. '00000000000000000',
  1929. '000000000000000000',
  1930. '0000000000000000000',
  1931. '00000000000000000000',
  1932. '000000000000000000000',
  1933. '0000000000000000000000',
  1934. '00000000000000000000000',
  1935. '000000000000000000000000',
  1936. '0000000000000000000000000'
  1937. ];
  1938. var groupSizes = [
  1939. 0, 0,
  1940. 25, 16, 12, 11, 10, 9, 8,
  1941. 8, 7, 7, 7, 7, 6, 6,
  1942. 6, 6, 6, 6, 6, 5, 5,
  1943. 5, 5, 5, 5, 5, 5, 5,
  1944. 5, 5, 5, 5, 5, 5, 5
  1945. ];
  1946. var groupBases = [
  1947. 0, 0,
  1948. 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
  1949. 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
  1950. 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
  1951. 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
  1952. 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
  1953. ];
  1954. BN.prototype.toString = function toString (base, padding) {
  1955. base = base || 10;
  1956. padding = padding | 0 || 1;
  1957. var out;
  1958. if (base === 16 || base === 'hex') {
  1959. out = '';
  1960. var off = 0;
  1961. var carry = 0;
  1962. for (var i = 0; i < this.length; i++) {
  1963. var w = this.words[i];
  1964. var word = (((w << off) | carry) & 0xffffff).toString(16);
  1965. carry = (w >>> (24 - off)) & 0xffffff;
  1966. if (carry !== 0 || i !== this.length - 1) {
  1967. out = zeros[6 - word.length] + word + out;
  1968. } else {
  1969. out = word + out;
  1970. }
  1971. off += 2;
  1972. if (off >= 26) {
  1973. off -= 26;
  1974. i--;
  1975. }
  1976. }
  1977. if (carry !== 0) {
  1978. out = carry.toString(16) + out;
  1979. }
  1980. while (out.length % padding !== 0) {
  1981. out = '0' + out;
  1982. }
  1983. if (this.negative !== 0) {
  1984. out = '-' + out;
  1985. }
  1986. return out;
  1987. }
  1988. if (base === (base | 0) && base >= 2 && base <= 36) {
  1989. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  1990. var groupSize = groupSizes[base];
  1991. // var groupBase = Math.pow(base, groupSize);
  1992. var groupBase = groupBases[base];
  1993. out = '';
  1994. var c = this.clone();
  1995. c.negative = 0;
  1996. while (!c.isZero()) {
  1997. var r = c.modn(groupBase).toString(base);
  1998. c = c.idivn(groupBase);
  1999. if (!c.isZero()) {
  2000. out = zeros[groupSize - r.length] + r + out;
  2001. } else {
  2002. out = r + out;
  2003. }
  2004. }
  2005. if (this.isZero()) {
  2006. out = '0' + out;
  2007. }
  2008. while (out.length % padding !== 0) {
  2009. out = '0' + out;
  2010. }
  2011. if (this.negative !== 0) {
  2012. out = '-' + out;
  2013. }
  2014. return out;
  2015. }
  2016. assert(false, 'Base should be between 2 and 36');
  2017. };
  2018. BN.prototype.toNumber = function toNumber () {
  2019. var ret = this.words[0];
  2020. if (this.length === 2) {
  2021. ret += this.words[1] * 0x4000000;
  2022. } else if (this.length === 3 && this.words[2] === 0x01) {
  2023. // NOTE: at this stage it is known that the top bit is set
  2024. ret += 0x10000000000000 + (this.words[1] * 0x4000000);
  2025. } else if (this.length > 2) {
  2026. assert(false, 'Number can only safely store up to 53 bits');
  2027. }
  2028. return (this.negative !== 0) ? -ret : ret;
  2029. };
  2030. BN.prototype.toJSON = function toJSON () {
  2031. return this.toString(16);
  2032. };
  2033. BN.prototype.toBuffer = function toBuffer (endian, length) {
  2034. assert(typeof Buffer !== 'undefined');
  2035. return this.toArrayLike(Buffer, endian, length);
  2036. };
  2037. BN.prototype.toArray = function toArray (endian, length) {
  2038. return this.toArrayLike(Array, endian, length);
  2039. };
  2040. BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
  2041. var byteLength = this.byteLength();
  2042. var reqLength = length || Math.max(1, byteLength);
  2043. assert(byteLength <= reqLength, 'byte array longer than desired length');
  2044. assert(reqLength > 0, 'Requested array length <= 0');
  2045. this.strip();
  2046. var littleEndian = endian === 'le';
  2047. var res = new ArrayType(reqLength);
  2048. var b, i;
  2049. var q = this.clone();
  2050. if (!littleEndian) {
  2051. // Assume big-endian
  2052. for (i = 0; i < reqLength - byteLength; i++) {
  2053. res[i] = 0;
  2054. }
  2055. for (i = 0; !q.isZero(); i++) {
  2056. b = q.andln(0xff);
  2057. q.iushrn(8);
  2058. res[reqLength - i - 1] = b;
  2059. }
  2060. } else {
  2061. for (i = 0; !q.isZero(); i++) {
  2062. b = q.andln(0xff);
  2063. q.iushrn(8);
  2064. res[i] = b;
  2065. }
  2066. for (; i < reqLength; i++) {
  2067. res[i] = 0;
  2068. }
  2069. }
  2070. return res;
  2071. };
  2072. if (Math.clz32) {
  2073. BN.prototype._countBits = function _countBits (w) {
  2074. return 32 - Math.clz32(w);
  2075. };
  2076. } else {
  2077. BN.prototype._countBits = function _countBits (w) {
  2078. var t = w;
  2079. var r = 0;
  2080. if (t >= 0x1000) {
  2081. r += 13;
  2082. t >>>= 13;
  2083. }
  2084. if (t >= 0x40) {
  2085. r += 7;
  2086. t >>>= 7;
  2087. }
  2088. if (t >= 0x8) {
  2089. r += 4;
  2090. t >>>= 4;
  2091. }
  2092. if (t >= 0x02) {
  2093. r += 2;
  2094. t >>>= 2;
  2095. }
  2096. return r + t;
  2097. };
  2098. }
  2099. BN.prototype._zeroBits = function _zeroBits (w) {
  2100. // Short-cut
  2101. if (w === 0) return 26;
  2102. var t = w;
  2103. var r = 0;
  2104. if ((t & 0x1fff) === 0) {
  2105. r += 13;
  2106. t >>>= 13;
  2107. }
  2108. if ((t & 0x7f) === 0) {
  2109. r += 7;
  2110. t >>>= 7;
  2111. }
  2112. if ((t & 0xf) === 0) {
  2113. r += 4;
  2114. t >>>= 4;
  2115. }
  2116. if ((t & 0x3) === 0) {
  2117. r += 2;
  2118. t >>>= 2;
  2119. }
  2120. if ((t & 0x1) === 0) {
  2121. r++;
  2122. }
  2123. return r;
  2124. };
  2125. // Return number of used bits in a BN
  2126. BN.prototype.bitLength = function bitLength () {
  2127. var w = this.words[this.length - 1];
  2128. var hi = this._countBits(w);
  2129. return (this.length - 1) * 26 + hi;
  2130. };
  2131. function toBitArray (num) {
  2132. var w = new Array(num.bitLength());
  2133. for (var bit = 0; bit < w.length; bit++) {
  2134. var off = (bit / 26) | 0;
  2135. var wbit = bit % 26;
  2136. w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
  2137. }
  2138. return w;
  2139. }
  2140. // Number of trailing zero bits
  2141. BN.prototype.zeroBits = function zeroBits () {
  2142. if (this.isZero()) return 0;
  2143. var r = 0;
  2144. for (var i = 0; i < this.length; i++) {
  2145. var b = this._zeroBits(this.words[i]);
  2146. r += b;
  2147. if (b !== 26) break;
  2148. }
  2149. return r;
  2150. };
  2151. BN.prototype.byteLength = function byteLength () {
  2152. return Math.ceil(this.bitLength() / 8);
  2153. };
  2154. BN.prototype.toTwos = function toTwos (width) {
  2155. if (this.negative !== 0) {
  2156. return this.abs().inotn(width).iaddn(1);
  2157. }
  2158. return this.clone();
  2159. };
  2160. BN.prototype.fromTwos = function fromTwos (width) {
  2161. if (this.testn(width - 1)) {
  2162. return this.notn(width).iaddn(1).ineg();
  2163. }
  2164. return this.clone();
  2165. };
  2166. BN.prototype.isNeg = function isNeg () {
  2167. return this.negative !== 0;
  2168. };
  2169. // Return negative clone of `this`
  2170. BN.prototype.neg = function neg () {
  2171. return this.clone().ineg();
  2172. };
  2173. BN.prototype.ineg = function ineg () {
  2174. if (!this.isZero()) {
  2175. this.negative ^= 1;
  2176. }
  2177. return this;
  2178. };
  2179. // Or `num` with `this` in-place
  2180. BN.prototype.iuor = function iuor (num) {
  2181. while (this.length < num.length) {
  2182. this.words[this.length++] = 0;
  2183. }
  2184. for (var i = 0; i < num.length; i++) {
  2185. this.words[i] = this.words[i] | num.words[i];
  2186. }
  2187. return this.strip();
  2188. };
  2189. BN.prototype.ior = function ior (num) {
  2190. assert((this.negative | num.negative) === 0);
  2191. return this.iuor(num);
  2192. };
  2193. // Or `num` with `this`
  2194. BN.prototype.or = function or (num) {
  2195. if (this.length > num.length) return this.clone().ior(num);
  2196. return num.clone().ior(this);
  2197. };
  2198. BN.prototype.uor = function uor (num) {
  2199. if (this.length > num.length) return this.clone().iuor(num);
  2200. return num.clone().iuor(this);
  2201. };
  2202. // And `num` with `this` in-place
  2203. BN.prototype.iuand = function iuand (num) {
  2204. // b = min-length(num, this)
  2205. var b;
  2206. if (this.length > num.length) {
  2207. b = num;
  2208. } else {
  2209. b = this;
  2210. }
  2211. for (var i = 0; i < b.length; i++) {
  2212. this.words[i] = this.words[i] & num.words[i];
  2213. }
  2214. this.length = b.length;
  2215. return this.strip();
  2216. };
  2217. BN.prototype.iand = function iand (num) {
  2218. assert((this.negative | num.negative) === 0);
  2219. return this.iuand(num);
  2220. };
  2221. // And `num` with `this`
  2222. BN.prototype.and = function and (num) {
  2223. if (this.length > num.length) return this.clone().iand(num);
  2224. return num.clone().iand(this);
  2225. };
  2226. BN.prototype.uand = function uand (num) {
  2227. if (this.length > num.length) return this.clone().iuand(num);
  2228. return num.clone().iuand(this);
  2229. };
  2230. // Xor `num` with `this` in-place
  2231. BN.prototype.iuxor = function iuxor (num) {
  2232. // a.length > b.length
  2233. var a;
  2234. var b;
  2235. if (this.length > num.length) {
  2236. a = this;
  2237. b = num;
  2238. } else {
  2239. a = num;
  2240. b = this;
  2241. }
  2242. for (var i = 0; i < b.length; i++) {
  2243. this.words[i] = a.words[i] ^ b.words[i];
  2244. }
  2245. if (this !== a) {
  2246. for (; i < a.length; i++) {
  2247. this.words[i] = a.words[i];
  2248. }
  2249. }
  2250. this.length = a.length;
  2251. return this.strip();
  2252. };
  2253. BN.prototype.ixor = function ixor (num) {
  2254. assert((this.negative | num.negative) === 0);
  2255. return this.iuxor(num);
  2256. };
  2257. // Xor `num` with `this`
  2258. BN.prototype.xor = function xor (num) {
  2259. if (this.length > num.length) return this.clone().ixor(num);
  2260. return num.clone().ixor(this);
  2261. };
  2262. BN.prototype.uxor = function uxor (num) {
  2263. if (this.length > num.length) return this.clone().iuxor(num);
  2264. return num.clone().iuxor(this);
  2265. };
  2266. // Not ``this`` with ``width`` bitwidth
  2267. BN.prototype.inotn = function inotn (width) {
  2268. assert(typeof width === 'number' && width >= 0);
  2269. var bytesNeeded = Math.ceil(width / 26) | 0;
  2270. var bitsLeft = width % 26;
  2271. // Extend the buffer with leading zeroes
  2272. this._expand(bytesNeeded);
  2273. if (bitsLeft > 0) {
  2274. bytesNeeded--;
  2275. }
  2276. // Handle complete words
  2277. for (var i = 0; i < bytesNeeded; i++) {
  2278. this.words[i] = ~this.words[i] & 0x3ffffff;
  2279. }
  2280. // Handle the residue
  2281. if (bitsLeft > 0) {
  2282. this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
  2283. }
  2284. // And remove leading zeroes
  2285. return this.strip();
  2286. };
  2287. BN.prototype.notn = function notn (width) {
  2288. return this.clone().inotn(width);
  2289. };
  2290. // Set `bit` of `this`
  2291. BN.prototype.setn = function setn (bit, val) {
  2292. assert(typeof bit === 'number' && bit >= 0);
  2293. var off = (bit / 26) | 0;
  2294. var wbit = bit % 26;
  2295. this._expand(off + 1);
  2296. if (val) {
  2297. this.words[off] = this.words[off] | (1 << wbit);
  2298. } else {
  2299. this.words[off] = this.words[off] & ~(1 << wbit);
  2300. }
  2301. return this.strip();
  2302. };
  2303. // Add `num` to `this` in-place
  2304. BN.prototype.iadd = function iadd (num) {
  2305. var r;
  2306. // negative + positive
  2307. if (this.negative !== 0 && num.negative === 0) {
  2308. this.negative = 0;
  2309. r = this.isub(num);
  2310. this.negative ^= 1;
  2311. return this._normSign();
  2312. // positive + negative
  2313. } else if (this.negative === 0 && num.negative !== 0) {
  2314. num.negative = 0;
  2315. r = this.isub(num);
  2316. num.negative = 1;
  2317. return r._normSign();
  2318. }
  2319. // a.length > b.length
  2320. var a, b;
  2321. if (this.length > num.length) {
  2322. a = this;
  2323. b = num;
  2324. } else {
  2325. a = num;
  2326. b = this;
  2327. }
  2328. var carry = 0;
  2329. for (var i = 0; i < b.length; i++) {
  2330. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  2331. this.words[i] = r & 0x3ffffff;
  2332. carry = r >>> 26;
  2333. }
  2334. for (; carry !== 0 && i < a.length; i++) {
  2335. r = (a.words[i] | 0) + carry;
  2336. this.words[i] = r & 0x3ffffff;
  2337. carry = r >>> 26;
  2338. }
  2339. this.length = a.length;
  2340. if (carry !== 0) {
  2341. this.words[this.length] = carry;
  2342. this.length++;
  2343. // Copy the rest of the words
  2344. } else if (a !== this) {
  2345. for (; i < a.length; i++) {
  2346. this.words[i] = a.words[i];
  2347. }
  2348. }
  2349. return this;
  2350. };
  2351. // Add `num` to `this`
  2352. BN.prototype.add = function add (num) {
  2353. var res;
  2354. if (num.negative !== 0 && this.negative === 0) {
  2355. num.negative = 0;
  2356. res = this.sub(num);
  2357. num.negative ^= 1;
  2358. return res;
  2359. } else if (num.negative === 0 && this.negative !== 0) {
  2360. this.negative = 0;
  2361. res = num.sub(this);
  2362. this.negative = 1;
  2363. return res;
  2364. }
  2365. if (this.length > num.length) return this.clone().iadd(num);
  2366. return num.clone().iadd(this);
  2367. };
  2368. // Subtract `num` from `this` in-place
  2369. BN.prototype.isub = function isub (num) {
  2370. // this - (-num) = this + num
  2371. if (num.negative !== 0) {
  2372. num.negative = 0;
  2373. var r = this.iadd(num);
  2374. num.negative = 1;
  2375. return r._normSign();
  2376. // -this - num = -(this + num)
  2377. } else if (this.negative !== 0) {
  2378. this.negative = 0;
  2379. this.iadd(num);
  2380. this.negative = 1;
  2381. return this._normSign();
  2382. }
  2383. // At this point both numbers are positive
  2384. var cmp = this.cmp(num);
  2385. // Optimization - zeroify
  2386. if (cmp === 0) {
  2387. this.negative = 0;
  2388. this.length = 1;
  2389. this.words[0] = 0;
  2390. return this;
  2391. }
  2392. // a > b
  2393. var a, b;
  2394. if (cmp > 0) {
  2395. a = this;
  2396. b = num;
  2397. } else {
  2398. a = num;
  2399. b = this;
  2400. }
  2401. var carry = 0;
  2402. for (var i = 0; i < b.length; i++) {
  2403. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  2404. carry = r >> 26;
  2405. this.words[i] = r & 0x3ffffff;
  2406. }
  2407. for (; carry !== 0 && i < a.length; i++) {
  2408. r = (a.words[i] | 0) + carry;
  2409. carry = r >> 26;
  2410. this.words[i] = r & 0x3ffffff;
  2411. }
  2412. // Copy rest of the words
  2413. if (carry === 0 && i < a.length && a !== this) {
  2414. for (; i < a.length; i++) {
  2415. this.words[i] = a.words[i];
  2416. }
  2417. }
  2418. this.length = Math.max(this.length, i);
  2419. if (a !== this) {
  2420. this.negative = 1;
  2421. }
  2422. return this.strip();
  2423. };
  2424. // Subtract `num` from `this`
  2425. BN.prototype.sub = function sub (num) {
  2426. return this.clone().isub(num);
  2427. };
  2428. function smallMulTo (self, num, out) {
  2429. out.negative = num.negative ^ self.negative;
  2430. var len = (self.length + num.length) | 0;
  2431. out.length = len;
  2432. len = (len - 1) | 0;
  2433. // Peel one iteration (compiler can't do it, because of code complexity)
  2434. var a = self.words[0] | 0;
  2435. var b = num.words[0] | 0;
  2436. var r = a * b;
  2437. var lo = r & 0x3ffffff;
  2438. var carry = (r / 0x4000000) | 0;
  2439. out.words[0] = lo;
  2440. for (var k = 1; k < len; k++) {
  2441. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  2442. // note that ncarry could be >= 0x3ffffff
  2443. var ncarry = carry >>> 26;
  2444. var rword = carry & 0x3ffffff;
  2445. var maxJ = Math.min(k, num.length - 1);
  2446. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  2447. var i = (k - j) | 0;
  2448. a = self.words[i] | 0;
  2449. b = num.words[j] | 0;
  2450. r = a * b + rword;
  2451. ncarry += (r / 0x4000000) | 0;
  2452. rword = r & 0x3ffffff;
  2453. }
  2454. out.words[k] = rword | 0;
  2455. carry = ncarry | 0;
  2456. }
  2457. if (carry !== 0) {
  2458. out.words[k] = carry | 0;
  2459. } else {
  2460. out.length--;
  2461. }
  2462. return out.strip();
  2463. }
  2464. // TODO(indutny): it may be reasonable to omit it for users who don't need
  2465. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  2466. // multiplication (like elliptic secp256k1).
  2467. var comb10MulTo = function comb10MulTo (self, num, out) {
  2468. var a = self.words;
  2469. var b = num.words;
  2470. var o = out.words;
  2471. var c = 0;
  2472. var lo;
  2473. var mid;
  2474. var hi;
  2475. var a0 = a[0] | 0;
  2476. var al0 = a0 & 0x1fff;
  2477. var ah0 = a0 >>> 13;
  2478. var a1 = a[1] | 0;
  2479. var al1 = a1 & 0x1fff;
  2480. var ah1 = a1 >>> 13;
  2481. var a2 = a[2] | 0;
  2482. var al2 = a2 & 0x1fff;
  2483. var ah2 = a2 >>> 13;
  2484. var a3 = a[3] | 0;
  2485. var al3 = a3 & 0x1fff;
  2486. var ah3 = a3 >>> 13;
  2487. var a4 = a[4] | 0;
  2488. var al4 = a4 & 0x1fff;
  2489. var ah4 = a4 >>> 13;
  2490. var a5 = a[5] | 0;
  2491. var al5 = a5 & 0x1fff;
  2492. var ah5 = a5 >>> 13;
  2493. var a6 = a[6] | 0;
  2494. var al6 = a6 & 0x1fff;
  2495. var ah6 = a6 >>> 13;
  2496. var a7 = a[7] | 0;
  2497. var al7 = a7 & 0x1fff;
  2498. var ah7 = a7 >>> 13;
  2499. var a8 = a[8] | 0;
  2500. var al8 = a8 & 0x1fff;
  2501. var ah8 = a8 >>> 13;
  2502. var a9 = a[9] | 0;
  2503. var al9 = a9 & 0x1fff;
  2504. var ah9 = a9 >>> 13;
  2505. var b0 = b[0] | 0;
  2506. var bl0 = b0 & 0x1fff;
  2507. var bh0 = b0 >>> 13;
  2508. var b1 = b[1] | 0;
  2509. var bl1 = b1 & 0x1fff;
  2510. var bh1 = b1 >>> 13;
  2511. var b2 = b[2] | 0;
  2512. var bl2 = b2 & 0x1fff;
  2513. var bh2 = b2 >>> 13;
  2514. var b3 = b[3] | 0;
  2515. var bl3 = b3 & 0x1fff;
  2516. var bh3 = b3 >>> 13;
  2517. var b4 = b[4] | 0;
  2518. var bl4 = b4 & 0x1fff;
  2519. var bh4 = b4 >>> 13;
  2520. var b5 = b[5] | 0;
  2521. var bl5 = b5 & 0x1fff;
  2522. var bh5 = b5 >>> 13;
  2523. var b6 = b[6] | 0;
  2524. var bl6 = b6 & 0x1fff;
  2525. var bh6 = b6 >>> 13;
  2526. var b7 = b[7] | 0;
  2527. var bl7 = b7 & 0x1fff;
  2528. var bh7 = b7 >>> 13;
  2529. var b8 = b[8] | 0;
  2530. var bl8 = b8 & 0x1fff;
  2531. var bh8 = b8 >>> 13;
  2532. var b9 = b[9] | 0;
  2533. var bl9 = b9 & 0x1fff;
  2534. var bh9 = b9 >>> 13;
  2535. out.negative = self.negative ^ num.negative;
  2536. out.length = 19;
  2537. /* k = 0 */
  2538. lo = Math.imul(al0, bl0);
  2539. mid = Math.imul(al0, bh0);
  2540. mid += Math.imul(ah0, bl0);
  2541. hi = Math.imul(ah0, bh0);
  2542. var w0 = c + lo + ((mid & 0x1fff) << 13);
  2543. c = hi + (mid >>> 13) + (w0 >>> 26);
  2544. w0 &= 0x3ffffff;
  2545. /* k = 1 */
  2546. lo = Math.imul(al1, bl0);
  2547. mid = Math.imul(al1, bh0);
  2548. mid += Math.imul(ah1, bl0);
  2549. hi = Math.imul(ah1, bh0);
  2550. lo += Math.imul(al0, bl1);
  2551. mid += Math.imul(al0, bh1);
  2552. mid += Math.imul(ah0, bl1);
  2553. hi += Math.imul(ah0, bh1);
  2554. var w1 = c + lo + ((mid & 0x1fff) << 13);
  2555. c = hi + (mid >>> 13) + (w1 >>> 26);
  2556. w1 &= 0x3ffffff;
  2557. /* k = 2 */
  2558. lo = Math.imul(al2, bl0);
  2559. mid = Math.imul(al2, bh0);
  2560. mid += Math.imul(ah2, bl0);
  2561. hi = Math.imul(ah2, bh0);
  2562. lo += Math.imul(al1, bl1);
  2563. mid += Math.imul(al1, bh1);
  2564. mid += Math.imul(ah1, bl1);
  2565. hi += Math.imul(ah1, bh1);
  2566. lo += Math.imul(al0, bl2);
  2567. mid += Math.imul(al0, bh2);
  2568. mid += Math.imul(ah0, bl2);
  2569. hi += Math.imul(ah0, bh2);
  2570. var w2 = c + lo + ((mid & 0x1fff) << 13);
  2571. c = hi + (mid >>> 13) + (w2 >>> 26);
  2572. w2 &= 0x3ffffff;
  2573. /* k = 3 */
  2574. lo = Math.imul(al3, bl0);
  2575. mid = Math.imul(al3, bh0);
  2576. mid += Math.imul(ah3, bl0);
  2577. hi = Math.imul(ah3, bh0);
  2578. lo += Math.imul(al2, bl1);
  2579. mid += Math.imul(al2, bh1);
  2580. mid += Math.imul(ah2, bl1);
  2581. hi += Math.imul(ah2, bh1);
  2582. lo += Math.imul(al1, bl2);
  2583. mid += Math.imul(al1, bh2);
  2584. mid += Math.imul(ah1, bl2);
  2585. hi += Math.imul(ah1, bh2);
  2586. lo += Math.imul(al0, bl3);
  2587. mid += Math.imul(al0, bh3);
  2588. mid += Math.imul(ah0, bl3);
  2589. hi += Math.imul(ah0, bh3);
  2590. var w3 = c + lo + ((mid & 0x1fff) << 13);
  2591. c = hi + (mid >>> 13) + (w3 >>> 26);
  2592. w3 &= 0x3ffffff;
  2593. /* k = 4 */
  2594. lo = Math.imul(al4, bl0);
  2595. mid = Math.imul(al4, bh0);
  2596. mid += Math.imul(ah4, bl0);
  2597. hi = Math.imul(ah4, bh0);
  2598. lo += Math.imul(al3, bl1);
  2599. mid += Math.imul(al3, bh1);
  2600. mid += Math.imul(ah3, bl1);
  2601. hi += Math.imul(ah3, bh1);
  2602. lo += Math.imul(al2, bl2);
  2603. mid += Math.imul(al2, bh2);
  2604. mid += Math.imul(ah2, bl2);
  2605. hi += Math.imul(ah2, bh2);
  2606. lo += Math.imul(al1, bl3);
  2607. mid += Math.imul(al1, bh3);
  2608. mid += Math.imul(ah1, bl3);
  2609. hi += Math.imul(ah1, bh3);
  2610. lo += Math.imul(al0, bl4);
  2611. mid += Math.imul(al0, bh4);
  2612. mid += Math.imul(ah0, bl4);
  2613. hi += Math.imul(ah0, bh4);
  2614. var w4 = c + lo + ((mid & 0x1fff) << 13);
  2615. c = hi + (mid >>> 13) + (w4 >>> 26);
  2616. w4 &= 0x3ffffff;
  2617. /* k = 5 */
  2618. lo = Math.imul(al5, bl0);
  2619. mid = Math.imul(al5, bh0);
  2620. mid += Math.imul(ah5, bl0);
  2621. hi = Math.imul(ah5, bh0);
  2622. lo += Math.imul(al4, bl1);
  2623. mid += Math.imul(al4, bh1);
  2624. mid += Math.imul(ah4, bl1);
  2625. hi += Math.imul(ah4, bh1);
  2626. lo += Math.imul(al3, bl2);
  2627. mid += Math.imul(al3, bh2);
  2628. mid += Math.imul(ah3, bl2);
  2629. hi += Math.imul(ah3, bh2);
  2630. lo += Math.imul(al2, bl3);
  2631. mid += Math.imul(al2, bh3);
  2632. mid += Math.imul(ah2, bl3);
  2633. hi += Math.imul(ah2, bh3);
  2634. lo += Math.imul(al1, bl4);
  2635. mid += Math.imul(al1, bh4);
  2636. mid += Math.imul(ah1, bl4);
  2637. hi += Math.imul(ah1, bh4);
  2638. lo += Math.imul(al0, bl5);
  2639. mid += Math.imul(al0, bh5);
  2640. mid += Math.imul(ah0, bl5);
  2641. hi += Math.imul(ah0, bh5);
  2642. var w5 = c + lo + ((mid & 0x1fff) << 13);
  2643. c = hi + (mid >>> 13) + (w5 >>> 26);
  2644. w5 &= 0x3ffffff;
  2645. /* k = 6 */
  2646. lo = Math.imul(al6, bl0);
  2647. mid = Math.imul(al6, bh0);
  2648. mid += Math.imul(ah6, bl0);
  2649. hi = Math.imul(ah6, bh0);
  2650. lo += Math.imul(al5, bl1);
  2651. mid += Math.imul(al5, bh1);
  2652. mid += Math.imul(ah5, bl1);
  2653. hi += Math.imul(ah5, bh1);
  2654. lo += Math.imul(al4, bl2);
  2655. mid += Math.imul(al4, bh2);
  2656. mid += Math.imul(ah4, bl2);
  2657. hi += Math.imul(ah4, bh2);
  2658. lo += Math.imul(al3, bl3);
  2659. mid += Math.imul(al3, bh3);
  2660. mid += Math.imul(ah3, bl3);
  2661. hi += Math.imul(ah3, bh3);
  2662. lo += Math.imul(al2, bl4);
  2663. mid += Math.imul(al2, bh4);
  2664. mid += Math.imul(ah2, bl4);
  2665. hi += Math.imul(ah2, bh4);
  2666. lo += Math.imul(al1, bl5);
  2667. mid += Math.imul(al1, bh5);
  2668. mid += Math.imul(ah1, bl5);
  2669. hi += Math.imul(ah1, bh5);
  2670. lo += Math.imul(al0, bl6);
  2671. mid += Math.imul(al0, bh6);
  2672. mid += Math.imul(ah0, bl6);
  2673. hi += Math.imul(ah0, bh6);
  2674. var w6 = c + lo + ((mid & 0x1fff) << 13);
  2675. c = hi + (mid >>> 13) + (w6 >>> 26);
  2676. w6 &= 0x3ffffff;
  2677. /* k = 7 */
  2678. lo = Math.imul(al7, bl0);
  2679. mid = Math.imul(al7, bh0);
  2680. mid += Math.imul(ah7, bl0);
  2681. hi = Math.imul(ah7, bh0);
  2682. lo += Math.imul(al6, bl1);
  2683. mid += Math.imul(al6, bh1);
  2684. mid += Math.imul(ah6, bl1);
  2685. hi += Math.imul(ah6, bh1);
  2686. lo += Math.imul(al5, bl2);
  2687. mid += Math.imul(al5, bh2);
  2688. mid += Math.imul(ah5, bl2);
  2689. hi += Math.imul(ah5, bh2);
  2690. lo += Math.imul(al4, bl3);
  2691. mid += Math.imul(al4, bh3);
  2692. mid += Math.imul(ah4, bl3);
  2693. hi += Math.imul(ah4, bh3);
  2694. lo += Math.imul(al3, bl4);
  2695. mid += Math.imul(al3, bh4);
  2696. mid += Math.imul(ah3, bl4);
  2697. hi += Math.imul(ah3, bh4);
  2698. lo += Math.imul(al2, bl5);
  2699. mid += Math.imul(al2, bh5);
  2700. mid += Math.imul(ah2, bl5);
  2701. hi += Math.imul(ah2, bh5);
  2702. lo += Math.imul(al1, bl6);
  2703. mid += Math.imul(al1, bh6);
  2704. mid += Math.imul(ah1, bl6);
  2705. hi += Math.imul(ah1, bh6);
  2706. lo += Math.imul(al0, bl7);
  2707. mid += Math.imul(al0, bh7);
  2708. mid += Math.imul(ah0, bl7);
  2709. hi += Math.imul(ah0, bh7);
  2710. var w7 = c + lo + ((mid & 0x1fff) << 13);
  2711. c = hi + (mid >>> 13) + (w7 >>> 26);
  2712. w7 &= 0x3ffffff;
  2713. /* k = 8 */
  2714. lo = Math.imul(al8, bl0);
  2715. mid = Math.imul(al8, bh0);
  2716. mid += Math.imul(ah8, bl0);
  2717. hi = Math.imul(ah8, bh0);
  2718. lo += Math.imul(al7, bl1);
  2719. mid += Math.imul(al7, bh1);
  2720. mid += Math.imul(ah7, bl1);
  2721. hi += Math.imul(ah7, bh1);
  2722. lo += Math.imul(al6, bl2);
  2723. mid += Math.imul(al6, bh2);
  2724. mid += Math.imul(ah6, bl2);
  2725. hi += Math.imul(ah6, bh2);
  2726. lo += Math.imul(al5, bl3);
  2727. mid += Math.imul(al5, bh3);
  2728. mid += Math.imul(ah5, bl3);
  2729. hi += Math.imul(ah5, bh3);
  2730. lo += Math.imul(al4, bl4);
  2731. mid += Math.imul(al4, bh4);
  2732. mid += Math.imul(ah4, bl4);
  2733. hi += Math.imul(ah4, bh4);
  2734. lo += Math.imul(al3, bl5);
  2735. mid += Math.imul(al3, bh5);
  2736. mid += Math.imul(ah3, bl5);
  2737. hi += Math.imul(ah3, bh5);
  2738. lo += Math.imul(al2, bl6);
  2739. mid += Math.imul(al2, bh6);
  2740. mid += Math.imul(ah2, bl6);
  2741. hi += Math.imul(ah2, bh6);
  2742. lo += Math.imul(al1, bl7);
  2743. mid += Math.imul(al1, bh7);
  2744. mid += Math.imul(ah1, bl7);
  2745. hi += Math.imul(ah1, bh7);
  2746. lo += Math.imul(al0, bl8);
  2747. mid += Math.imul(al0, bh8);
  2748. mid += Math.imul(ah0, bl8);
  2749. hi += Math.imul(ah0, bh8);
  2750. var w8 = c + lo + ((mid & 0x1fff) << 13);
  2751. c = hi + (mid >>> 13) + (w8 >>> 26);
  2752. w8 &= 0x3ffffff;
  2753. /* k = 9 */
  2754. lo = Math.imul(al9, bl0);
  2755. mid = Math.imul(al9, bh0);
  2756. mid += Math.imul(ah9, bl0);
  2757. hi = Math.imul(ah9, bh0);
  2758. lo += Math.imul(al8, bl1);
  2759. mid += Math.imul(al8, bh1);
  2760. mid += Math.imul(ah8, bl1);
  2761. hi += Math.imul(ah8, bh1);
  2762. lo += Math.imul(al7, bl2);
  2763. mid += Math.imul(al7, bh2);
  2764. mid += Math.imul(ah7, bl2);
  2765. hi += Math.imul(ah7, bh2);
  2766. lo += Math.imul(al6, bl3);
  2767. mid += Math.imul(al6, bh3);
  2768. mid += Math.imul(ah6, bl3);
  2769. hi += Math.imul(ah6, bh3);
  2770. lo += Math.imul(al5, bl4);
  2771. mid += Math.imul(al5, bh4);
  2772. mid += Math.imul(ah5, bl4);
  2773. hi += Math.imul(ah5, bh4);
  2774. lo += Math.imul(al4, bl5);
  2775. mid += Math.imul(al4, bh5);
  2776. mid += Math.imul(ah4, bl5);
  2777. hi += Math.imul(ah4, bh5);
  2778. lo += Math.imul(al3, bl6);
  2779. mid += Math.imul(al3, bh6);
  2780. mid += Math.imul(ah3, bl6);
  2781. hi += Math.imul(ah3, bh6);
  2782. lo += Math.imul(al2, bl7);
  2783. mid += Math.imul(al2, bh7);
  2784. mid += Math.imul(ah2, bl7);
  2785. hi += Math.imul(ah2, bh7);
  2786. lo += Math.imul(al1, bl8);
  2787. mid += Math.imul(al1, bh8);
  2788. mid += Math.imul(ah1, bl8);
  2789. hi += Math.imul(ah1, bh8);
  2790. lo += Math.imul(al0, bl9);
  2791. mid += Math.imul(al0, bh9);
  2792. mid += Math.imul(ah0, bl9);
  2793. hi += Math.imul(ah0, bh9);
  2794. var w9 = c + lo + ((mid & 0x1fff) << 13);
  2795. c = hi + (mid >>> 13) + (w9 >>> 26);
  2796. w9 &= 0x3ffffff;
  2797. /* k = 10 */
  2798. lo = Math.imul(al9, bl1);
  2799. mid = Math.imul(al9, bh1);
  2800. mid += Math.imul(ah9, bl1);
  2801. hi = Math.imul(ah9, bh1);
  2802. lo += Math.imul(al8, bl2);
  2803. mid += Math.imul(al8, bh2);
  2804. mid += Math.imul(ah8, bl2);
  2805. hi += Math.imul(ah8, bh2);
  2806. lo += Math.imul(al7, bl3);
  2807. mid += Math.imul(al7, bh3);
  2808. mid += Math.imul(ah7, bl3);
  2809. hi += Math.imul(ah7, bh3);
  2810. lo += Math.imul(al6, bl4);
  2811. mid += Math.imul(al6, bh4);
  2812. mid += Math.imul(ah6, bl4);
  2813. hi += Math.imul(ah6, bh4);
  2814. lo += Math.imul(al5, bl5);
  2815. mid += Math.imul(al5, bh5);
  2816. mid += Math.imul(ah5, bl5);
  2817. hi += Math.imul(ah5, bh5);
  2818. lo += Math.imul(al4, bl6);
  2819. mid += Math.imul(al4, bh6);
  2820. mid += Math.imul(ah4, bl6);
  2821. hi += Math.imul(ah4, bh6);
  2822. lo += Math.imul(al3, bl7);
  2823. mid += Math.imul(al3, bh7);
  2824. mid += Math.imul(ah3, bl7);
  2825. hi += Math.imul(ah3, bh7);
  2826. lo += Math.imul(al2, bl8);
  2827. mid += Math.imul(al2, bh8);
  2828. mid += Math.imul(ah2, bl8);
  2829. hi += Math.imul(ah2, bh8);
  2830. lo += Math.imul(al1, bl9);
  2831. mid += Math.imul(al1, bh9);
  2832. mid += Math.imul(ah1, bl9);
  2833. hi += Math.imul(ah1, bh9);
  2834. var w10 = c + lo + ((mid & 0x1fff) << 13);
  2835. c = hi + (mid >>> 13) + (w10 >>> 26);
  2836. w10 &= 0x3ffffff;
  2837. /* k = 11 */
  2838. lo = Math.imul(al9, bl2);
  2839. mid = Math.imul(al9, bh2);
  2840. mid += Math.imul(ah9, bl2);
  2841. hi = Math.imul(ah9, bh2);
  2842. lo += Math.imul(al8, bl3);
  2843. mid += Math.imul(al8, bh3);
  2844. mid += Math.imul(ah8, bl3);
  2845. hi += Math.imul(ah8, bh3);
  2846. lo += Math.imul(al7, bl4);
  2847. mid += Math.imul(al7, bh4);
  2848. mid += Math.imul(ah7, bl4);
  2849. hi += Math.imul(ah7, bh4);
  2850. lo += Math.imul(al6, bl5);
  2851. mid += Math.imul(al6, bh5);
  2852. mid += Math.imul(ah6, bl5);
  2853. hi += Math.imul(ah6, bh5);
  2854. lo += Math.imul(al5, bl6);
  2855. mid += Math.imul(al5, bh6);
  2856. mid += Math.imul(ah5, bl6);
  2857. hi += Math.imul(ah5, bh6);
  2858. lo += Math.imul(al4, bl7);
  2859. mid += Math.imul(al4, bh7);
  2860. mid += Math.imul(ah4, bl7);
  2861. hi += Math.imul(ah4, bh7);
  2862. lo += Math.imul(al3, bl8);
  2863. mid += Math.imul(al3, bh8);
  2864. mid += Math.imul(ah3, bl8);
  2865. hi += Math.imul(ah3, bh8);
  2866. lo += Math.imul(al2, bl9);
  2867. mid += Math.imul(al2, bh9);
  2868. mid += Math.imul(ah2, bl9);
  2869. hi += Math.imul(ah2, bh9);
  2870. var w11 = c + lo + ((mid & 0x1fff) << 13);
  2871. c = hi + (mid >>> 13) + (w11 >>> 26);
  2872. w11 &= 0x3ffffff;
  2873. /* k = 12 */
  2874. lo = Math.imul(al9, bl3);
  2875. mid = Math.imul(al9, bh3);
  2876. mid += Math.imul(ah9, bl3);
  2877. hi = Math.imul(ah9, bh3);
  2878. lo += Math.imul(al8, bl4);
  2879. mid += Math.imul(al8, bh4);
  2880. mid += Math.imul(ah8, bl4);
  2881. hi += Math.imul(ah8, bh4);
  2882. lo += Math.imul(al7, bl5);
  2883. mid += Math.imul(al7, bh5);
  2884. mid += Math.imul(ah7, bl5);
  2885. hi += Math.imul(ah7, bh5);
  2886. lo += Math.imul(al6, bl6);
  2887. mid += Math.imul(al6, bh6);
  2888. mid += Math.imul(ah6, bl6);
  2889. hi += Math.imul(ah6, bh6);
  2890. lo += Math.imul(al5, bl7);
  2891. mid += Math.imul(al5, bh7);
  2892. mid += Math.imul(ah5, bl7);
  2893. hi += Math.imul(ah5, bh7);
  2894. lo += Math.imul(al4, bl8);
  2895. mid += Math.imul(al4, bh8);
  2896. mid += Math.imul(ah4, bl8);
  2897. hi += Math.imul(ah4, bh8);
  2898. lo += Math.imul(al3, bl9);
  2899. mid += Math.imul(al3, bh9);
  2900. mid += Math.imul(ah3, bl9);
  2901. hi += Math.imul(ah3, bh9);
  2902. var w12 = c + lo + ((mid & 0x1fff) << 13);
  2903. c = hi + (mid >>> 13) + (w12 >>> 26);
  2904. w12 &= 0x3ffffff;
  2905. /* k = 13 */
  2906. lo = Math.imul(al9, bl4);
  2907. mid = Math.imul(al9, bh4);
  2908. mid += Math.imul(ah9, bl4);
  2909. hi = Math.imul(ah9, bh4);
  2910. lo += Math.imul(al8, bl5);
  2911. mid += Math.imul(al8, bh5);
  2912. mid += Math.imul(ah8, bl5);
  2913. hi += Math.imul(ah8, bh5);
  2914. lo += Math.imul(al7, bl6);
  2915. mid += Math.imul(al7, bh6);
  2916. mid += Math.imul(ah7, bl6);
  2917. hi += Math.imul(ah7, bh6);
  2918. lo += Math.imul(al6, bl7);
  2919. mid += Math.imul(al6, bh7);
  2920. mid += Math.imul(ah6, bl7);
  2921. hi += Math.imul(ah6, bh7);
  2922. lo += Math.imul(al5, bl8);
  2923. mid += Math.imul(al5, bh8);
  2924. mid += Math.imul(ah5, bl8);
  2925. hi += Math.imul(ah5, bh8);
  2926. lo += Math.imul(al4, bl9);
  2927. mid += Math.imul(al4, bh9);
  2928. mid += Math.imul(ah4, bl9);
  2929. hi += Math.imul(ah4, bh9);
  2930. var w13 = c + lo + ((mid & 0x1fff) << 13);
  2931. c = hi + (mid >>> 13) + (w13 >>> 26);
  2932. w13 &= 0x3ffffff;
  2933. /* k = 14 */
  2934. lo = Math.imul(al9, bl5);
  2935. mid = Math.imul(al9, bh5);
  2936. mid += Math.imul(ah9, bl5);
  2937. hi = Math.imul(ah9, bh5);
  2938. lo += Math.imul(al8, bl6);
  2939. mid += Math.imul(al8, bh6);
  2940. mid += Math.imul(ah8, bl6);
  2941. hi += Math.imul(ah8, bh6);
  2942. lo += Math.imul(al7, bl7);
  2943. mid += Math.imul(al7, bh7);
  2944. mid += Math.imul(ah7, bl7);
  2945. hi += Math.imul(ah7, bh7);
  2946. lo += Math.imul(al6, bl8);
  2947. mid += Math.imul(al6, bh8);
  2948. mid += Math.imul(ah6, bl8);
  2949. hi += Math.imul(ah6, bh8);
  2950. lo += Math.imul(al5, bl9);
  2951. mid += Math.imul(al5, bh9);
  2952. mid += Math.imul(ah5, bl9);
  2953. hi += Math.imul(ah5, bh9);
  2954. var w14 = c + lo + ((mid & 0x1fff) << 13);
  2955. c = hi + (mid >>> 13) + (w14 >>> 26);
  2956. w14 &= 0x3ffffff;
  2957. /* k = 15 */
  2958. lo = Math.imul(al9, bl6);
  2959. mid = Math.imul(al9, bh6);
  2960. mid += Math.imul(ah9, bl6);
  2961. hi = Math.imul(ah9, bh6);
  2962. lo += Math.imul(al8, bl7);
  2963. mid += Math.imul(al8, bh7);
  2964. mid += Math.imul(ah8, bl7);
  2965. hi += Math.imul(ah8, bh7);
  2966. lo += Math.imul(al7, bl8);
  2967. mid += Math.imul(al7, bh8);
  2968. mid += Math.imul(ah7, bl8);
  2969. hi += Math.imul(ah7, bh8);
  2970. lo += Math.imul(al6, bl9);
  2971. mid += Math.imul(al6, bh9);
  2972. mid += Math.imul(ah6, bl9);
  2973. hi += Math.imul(ah6, bh9);
  2974. var w15 = c + lo + ((mid & 0x1fff) << 13);
  2975. c = hi + (mid >>> 13) + (w15 >>> 26);
  2976. w15 &= 0x3ffffff;
  2977. /* k = 16 */
  2978. lo = Math.imul(al9, bl7);
  2979. mid = Math.imul(al9, bh7);
  2980. mid += Math.imul(ah9, bl7);
  2981. hi = Math.imul(ah9, bh7);
  2982. lo += Math.imul(al8, bl8);
  2983. mid += Math.imul(al8, bh8);
  2984. mid += Math.imul(ah8, bl8);
  2985. hi += Math.imul(ah8, bh8);
  2986. lo += Math.imul(al7, bl9);
  2987. mid += Math.imul(al7, bh9);
  2988. mid += Math.imul(ah7, bl9);
  2989. hi += Math.imul(ah7, bh9);
  2990. var w16 = c + lo + ((mid & 0x1fff) << 13);
  2991. c = hi + (mid >>> 13) + (w16 >>> 26);
  2992. w16 &= 0x3ffffff;
  2993. /* k = 17 */
  2994. lo = Math.imul(al9, bl8);
  2995. mid = Math.imul(al9, bh8);
  2996. mid += Math.imul(ah9, bl8);
  2997. hi = Math.imul(ah9, bh8);
  2998. lo += Math.imul(al8, bl9);
  2999. mid += Math.imul(al8, bh9);
  3000. mid += Math.imul(ah8, bl9);
  3001. hi += Math.imul(ah8, bh9);
  3002. var w17 = c + lo + ((mid & 0x1fff) << 13);
  3003. c = hi + (mid >>> 13) + (w17 >>> 26);
  3004. w17 &= 0x3ffffff;
  3005. /* k = 18 */
  3006. lo = Math.imul(al9, bl9);
  3007. mid = Math.imul(al9, bh9);
  3008. mid += Math.imul(ah9, bl9);
  3009. hi = Math.imul(ah9, bh9);
  3010. var w18 = c + lo + ((mid & 0x1fff) << 13);
  3011. c = hi + (mid >>> 13) + (w18 >>> 26);
  3012. w18 &= 0x3ffffff;
  3013. o[0] = w0;
  3014. o[1] = w1;
  3015. o[2] = w2;
  3016. o[3] = w3;
  3017. o[4] = w4;
  3018. o[5] = w5;
  3019. o[6] = w6;
  3020. o[7] = w7;
  3021. o[8] = w8;
  3022. o[9] = w9;
  3023. o[10] = w10;
  3024. o[11] = w11;
  3025. o[12] = w12;
  3026. o[13] = w13;
  3027. o[14] = w14;
  3028. o[15] = w15;
  3029. o[16] = w16;
  3030. o[17] = w17;
  3031. o[18] = w18;
  3032. if (c !== 0) {
  3033. o[19] = c;
  3034. out.length++;
  3035. }
  3036. return out;
  3037. };
  3038. // Polyfill comb
  3039. if (!Math.imul) {
  3040. comb10MulTo = smallMulTo;
  3041. }
  3042. function bigMulTo (self, num, out) {
  3043. out.negative = num.negative ^ self.negative;
  3044. out.length = self.length + num.length;
  3045. var carry = 0;
  3046. var hncarry = 0;
  3047. for (var k = 0; k < out.length - 1; k++) {
  3048. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  3049. // note that ncarry could be >= 0x3ffffff
  3050. var ncarry = hncarry;
  3051. hncarry = 0;
  3052. var rword = carry & 0x3ffffff;
  3053. var maxJ = Math.min(k, num.length - 1);
  3054. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  3055. var i = k - j;
  3056. var a = self.words[i] | 0;
  3057. var b = num.words[j] | 0;
  3058. var r = a * b;
  3059. var lo = r & 0x3ffffff;
  3060. ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
  3061. lo = (lo + rword) | 0;
  3062. rword = lo & 0x3ffffff;
  3063. ncarry = (ncarry + (lo >>> 26)) | 0;
  3064. hncarry += ncarry >>> 26;
  3065. ncarry &= 0x3ffffff;
  3066. }
  3067. out.words[k] = rword;
  3068. carry = ncarry;
  3069. ncarry = hncarry;
  3070. }
  3071. if (carry !== 0) {
  3072. out.words[k] = carry;
  3073. } else {
  3074. out.length--;
  3075. }
  3076. return out.strip();
  3077. }
  3078. function jumboMulTo (self, num, out) {
  3079. var fftm = new FFTM();
  3080. return fftm.mulp(self, num, out);
  3081. }
  3082. BN.prototype.mulTo = function mulTo (num, out) {
  3083. var res;
  3084. var len = this.length + num.length;
  3085. if (this.length === 10 && num.length === 10) {
  3086. res = comb10MulTo(this, num, out);
  3087. } else if (len < 63) {
  3088. res = smallMulTo(this, num, out);
  3089. } else if (len < 1024) {
  3090. res = bigMulTo(this, num, out);
  3091. } else {
  3092. res = jumboMulTo(this, num, out);
  3093. }
  3094. return res;
  3095. };
  3096. // Cooley-Tukey algorithm for FFT
  3097. // slightly revisited to rely on looping instead of recursion
  3098. function FFTM (x, y) {
  3099. this.x = x;
  3100. this.y = y;
  3101. }
  3102. FFTM.prototype.makeRBT = function makeRBT (N) {
  3103. var t = new Array(N);
  3104. var l = BN.prototype._countBits(N) - 1;
  3105. for (var i = 0; i < N; i++) {
  3106. t[i] = this.revBin(i, l, N);
  3107. }
  3108. return t;
  3109. };
  3110. // Returns binary-reversed representation of `x`
  3111. FFTM.prototype.revBin = function revBin (x, l, N) {
  3112. if (x === 0 || x === N - 1) return x;
  3113. var rb = 0;
  3114. for (var i = 0; i < l; i++) {
  3115. rb |= (x & 1) << (l - i - 1);
  3116. x >>= 1;
  3117. }
  3118. return rb;
  3119. };
  3120. // Performs "tweedling" phase, therefore 'emulating'
  3121. // behaviour of the recursive algorithm
  3122. FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
  3123. for (var i = 0; i < N; i++) {
  3124. rtws[i] = rws[rbt[i]];
  3125. itws[i] = iws[rbt[i]];
  3126. }
  3127. };
  3128. FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
  3129. this.permute(rbt, rws, iws, rtws, itws, N);
  3130. for (var s = 1; s < N; s <<= 1) {
  3131. var l = s << 1;
  3132. var rtwdf = Math.cos(2 * Math.PI / l);
  3133. var itwdf = Math.sin(2 * Math.PI / l);
  3134. for (var p = 0; p < N; p += l) {
  3135. var rtwdf_ = rtwdf;
  3136. var itwdf_ = itwdf;
  3137. for (var j = 0; j < s; j++) {
  3138. var re = rtws[p + j];
  3139. var ie = itws[p + j];
  3140. var ro = rtws[p + j + s];
  3141. var io = itws[p + j + s];
  3142. var rx = rtwdf_ * ro - itwdf_ * io;
  3143. io = rtwdf_ * io + itwdf_ * ro;
  3144. ro = rx;
  3145. rtws[p + j] = re + ro;
  3146. itws[p + j] = ie + io;
  3147. rtws[p + j + s] = re - ro;
  3148. itws[p + j + s] = ie - io;
  3149. /* jshint maxdepth : false */
  3150. if (j !== l) {
  3151. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  3152. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  3153. rtwdf_ = rx;
  3154. }
  3155. }
  3156. }
  3157. }
  3158. };
  3159. FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
  3160. var N = Math.max(m, n) | 1;
  3161. var odd = N & 1;
  3162. var i = 0;
  3163. for (N = N / 2 | 0; N; N = N >>> 1) {
  3164. i++;
  3165. }
  3166. return 1 << i + 1 + odd;
  3167. };
  3168. FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
  3169. if (N <= 1) return;
  3170. for (var i = 0; i < N / 2; i++) {
  3171. var t = rws[i];
  3172. rws[i] = rws[N - i - 1];
  3173. rws[N - i - 1] = t;
  3174. t = iws[i];
  3175. iws[i] = -iws[N - i - 1];
  3176. iws[N - i - 1] = -t;
  3177. }
  3178. };
  3179. FFTM.prototype.normalize13b = function normalize13b (ws, N) {
  3180. var carry = 0;
  3181. for (var i = 0; i < N / 2; i++) {
  3182. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
  3183. Math.round(ws[2 * i] / N) +
  3184. carry;
  3185. ws[i] = w & 0x3ffffff;
  3186. if (w < 0x4000000) {
  3187. carry = 0;
  3188. } else {
  3189. carry = w / 0x4000000 | 0;
  3190. }
  3191. }
  3192. return ws;
  3193. };
  3194. FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
  3195. var carry = 0;
  3196. for (var i = 0; i < len; i++) {
  3197. carry = carry + (ws[i] | 0);
  3198. rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
  3199. rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
  3200. }
  3201. // Pad with zeroes
  3202. for (i = 2 * len; i < N; ++i) {
  3203. rws[i] = 0;
  3204. }
  3205. assert(carry === 0);
  3206. assert((carry & ~0x1fff) === 0);
  3207. };
  3208. FFTM.prototype.stub = function stub (N) {
  3209. var ph = new Array(N);
  3210. for (var i = 0; i < N; i++) {
  3211. ph[i] = 0;
  3212. }
  3213. return ph;
  3214. };
  3215. FFTM.prototype.mulp = function mulp (x, y, out) {
  3216. var N = 2 * this.guessLen13b(x.length, y.length);
  3217. var rbt = this.makeRBT(N);
  3218. var _ = this.stub(N);
  3219. var rws = new Array(N);
  3220. var rwst = new Array(N);
  3221. var iwst = new Array(N);
  3222. var nrws = new Array(N);
  3223. var nrwst = new Array(N);
  3224. var niwst = new Array(N);
  3225. var rmws = out.words;
  3226. rmws.length = N;
  3227. this.convert13b(x.words, x.length, rws, N);
  3228. this.convert13b(y.words, y.length, nrws, N);
  3229. this.transform(rws, _, rwst, iwst, N, rbt);
  3230. this.transform(nrws, _, nrwst, niwst, N, rbt);
  3231. for (var i = 0; i < N; i++) {
  3232. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  3233. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  3234. rwst[i] = rx;
  3235. }
  3236. this.conjugate(rwst, iwst, N);
  3237. this.transform(rwst, iwst, rmws, _, N, rbt);
  3238. this.conjugate(rmws, _, N);
  3239. this.normalize13b(rmws, N);
  3240. out.negative = x.negative ^ y.negative;
  3241. out.length = x.length + y.length;
  3242. return out.strip();
  3243. };
  3244. // Multiply `this` by `num`
  3245. BN.prototype.mul = function mul (num) {
  3246. var out = new BN(null);
  3247. out.words = new Array(this.length + num.length);
  3248. return this.mulTo(num, out);
  3249. };
  3250. // Multiply employing FFT
  3251. BN.prototype.mulf = function mulf (num) {
  3252. var out = new BN(null);
  3253. out.words = new Array(this.length + num.length);
  3254. return jumboMulTo(this, num, out);
  3255. };
  3256. // In-place Multiplication
  3257. BN.prototype.imul = function imul (num) {
  3258. return this.clone().mulTo(num, this);
  3259. };
  3260. BN.prototype.imuln = function imuln (num) {
  3261. assert(typeof num === 'number');
  3262. assert(num < 0x4000000);
  3263. // Carry
  3264. var carry = 0;
  3265. for (var i = 0; i < this.length; i++) {
  3266. var w = (this.words[i] | 0) * num;
  3267. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  3268. carry >>= 26;
  3269. carry += (w / 0x4000000) | 0;
  3270. // NOTE: lo is 27bit maximum
  3271. carry += lo >>> 26;
  3272. this.words[i] = lo & 0x3ffffff;
  3273. }
  3274. if (carry !== 0) {
  3275. this.words[i] = carry;
  3276. this.length++;
  3277. }
  3278. return this;
  3279. };
  3280. BN.prototype.muln = function muln (num) {
  3281. return this.clone().imuln(num);
  3282. };
  3283. // `this` * `this`
  3284. BN.prototype.sqr = function sqr () {
  3285. return this.mul(this);
  3286. };
  3287. // `this` * `this` in-place
  3288. BN.prototype.isqr = function isqr () {
  3289. return this.imul(this.clone());
  3290. };
  3291. // Math.pow(`this`, `num`)
  3292. BN.prototype.pow = function pow (num) {
  3293. var w = toBitArray(num);
  3294. if (w.length === 0) return new BN(1);
  3295. // Skip leading zeroes
  3296. var res = this;
  3297. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  3298. if (w[i] !== 0) break;
  3299. }
  3300. if (++i < w.length) {
  3301. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  3302. if (w[i] === 0) continue;
  3303. res = res.mul(q);
  3304. }
  3305. }
  3306. return res;
  3307. };
  3308. // Shift-left in-place
  3309. BN.prototype.iushln = function iushln (bits) {
  3310. assert(typeof bits === 'number' && bits >= 0);
  3311. var r = bits % 26;
  3312. var s = (bits - r) / 26;
  3313. var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
  3314. var i;
  3315. if (r !== 0) {
  3316. var carry = 0;
  3317. for (i = 0; i < this.length; i++) {
  3318. var newCarry = this.words[i] & carryMask;
  3319. var c = ((this.words[i] | 0) - newCarry) << r;
  3320. this.words[i] = c | carry;
  3321. carry = newCarry >>> (26 - r);
  3322. }
  3323. if (carry) {
  3324. this.words[i] = carry;
  3325. this.length++;
  3326. }
  3327. }
  3328. if (s !== 0) {
  3329. for (i = this.length - 1; i >= 0; i--) {
  3330. this.words[i + s] = this.words[i];
  3331. }
  3332. for (i = 0; i < s; i++) {
  3333. this.words[i] = 0;
  3334. }
  3335. this.length += s;
  3336. }
  3337. return this.strip();
  3338. };
  3339. BN.prototype.ishln = function ishln (bits) {
  3340. // TODO(indutny): implement me
  3341. assert(this.negative === 0);
  3342. return this.iushln(bits);
  3343. };
  3344. // Shift-right in-place
  3345. // NOTE: `hint` is a lowest bit before trailing zeroes
  3346. // NOTE: if `extended` is present - it will be filled with destroyed bits
  3347. BN.prototype.iushrn = function iushrn (bits, hint, extended) {
  3348. assert(typeof bits === 'number' && bits >= 0);
  3349. var h;
  3350. if (hint) {
  3351. h = (hint - (hint % 26)) / 26;
  3352. } else {
  3353. h = 0;
  3354. }
  3355. var r = bits % 26;
  3356. var s = Math.min((bits - r) / 26, this.length);
  3357. var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
  3358. var maskedWords = extended;
  3359. h -= s;
  3360. h = Math.max(0, h);
  3361. // Extended mode, copy masked part
  3362. if (maskedWords) {
  3363. for (var i = 0; i < s; i++) {
  3364. maskedWords.words[i] = this.words[i];
  3365. }
  3366. maskedWords.length = s;
  3367. }
  3368. if (s === 0) {
  3369. // No-op, we should not move anything at all
  3370. } else if (this.length > s) {
  3371. this.length -= s;
  3372. for (i = 0; i < this.length; i++) {
  3373. this.words[i] = this.words[i + s];
  3374. }
  3375. } else {
  3376. this.words[0] = 0;
  3377. this.length = 1;
  3378. }
  3379. var carry = 0;
  3380. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  3381. var word = this.words[i] | 0;
  3382. this.words[i] = (carry << (26 - r)) | (word >>> r);
  3383. carry = word & mask;
  3384. }
  3385. // Push carried bits as a mask
  3386. if (maskedWords && carry !== 0) {
  3387. maskedWords.words[maskedWords.length++] = carry;
  3388. }
  3389. if (this.length === 0) {
  3390. this.words[0] = 0;
  3391. this.length = 1;
  3392. }
  3393. return this.strip();
  3394. };
  3395. BN.prototype.ishrn = function ishrn (bits, hint, extended) {
  3396. // TODO(indutny): implement me
  3397. assert(this.negative === 0);
  3398. return this.iushrn(bits, hint, extended);
  3399. };
  3400. // Shift-left
  3401. BN.prototype.shln = function shln (bits) {
  3402. return this.clone().ishln(bits);
  3403. };
  3404. BN.prototype.ushln = function ushln (bits) {
  3405. return this.clone().iushln(bits);
  3406. };
  3407. // Shift-right
  3408. BN.prototype.shrn = function shrn (bits) {
  3409. return this.clone().ishrn(bits);
  3410. };
  3411. BN.prototype.ushrn = function ushrn (bits) {
  3412. return this.clone().iushrn(bits);
  3413. };
  3414. // Test if n bit is set
  3415. BN.prototype.testn = function testn (bit) {
  3416. assert(typeof bit === 'number' && bit >= 0);
  3417. var r = bit % 26;
  3418. var s = (bit - r) / 26;
  3419. var q = 1 << r;
  3420. // Fast case: bit is much higher than all existing words
  3421. if (this.length <= s) return false;
  3422. // Check bit and return
  3423. var w = this.words[s];
  3424. return !!(w & q);
  3425. };
  3426. // Return only lowers bits of number (in-place)
  3427. BN.prototype.imaskn = function imaskn (bits) {
  3428. assert(typeof bits === 'number' && bits >= 0);
  3429. var r = bits % 26;
  3430. var s = (bits - r) / 26;
  3431. assert(this.negative === 0, 'imaskn works only with positive numbers');
  3432. if (r !== 0) {
  3433. s++;
  3434. }
  3435. this.length = Math.min(s, this.length);
  3436. if (r !== 0) {
  3437. var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
  3438. this.words[this.length - 1] &= mask;
  3439. }
  3440. return this.strip();
  3441. };
  3442. // Return only lowers bits of number
  3443. BN.prototype.maskn = function maskn (bits) {
  3444. return this.clone().imaskn(bits);
  3445. };
  3446. // Add plain number `num` to `this`
  3447. BN.prototype.iaddn = function iaddn (num) {
  3448. assert(typeof num === 'number');
  3449. assert(num < 0x4000000);
  3450. if (num < 0) return this.isubn(-num);
  3451. // Possible sign change
  3452. if (this.negative !== 0) {
  3453. if (this.length === 1 && (this.words[0] | 0) < num) {
  3454. this.words[0] = num - (this.words[0] | 0);
  3455. this.negative = 0;
  3456. return this;
  3457. }
  3458. this.negative = 0;
  3459. this.isubn(num);
  3460. this.negative = 1;
  3461. return this;
  3462. }
  3463. // Add without checks
  3464. return this._iaddn(num);
  3465. };
  3466. BN.prototype._iaddn = function _iaddn (num) {
  3467. this.words[0] += num;
  3468. // Carry
  3469. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  3470. this.words[i] -= 0x4000000;
  3471. if (i === this.length - 1) {
  3472. this.words[i + 1] = 1;
  3473. } else {
  3474. this.words[i + 1]++;
  3475. }
  3476. }
  3477. this.length = Math.max(this.length, i + 1);
  3478. return this;
  3479. };
  3480. // Subtract plain number `num` from `this`
  3481. BN.prototype.isubn = function isubn (num) {
  3482. assert(typeof num === 'number');
  3483. assert(num < 0x4000000);
  3484. if (num < 0) return this.iaddn(-num);
  3485. if (this.negative !== 0) {
  3486. this.negative = 0;
  3487. this.iaddn(num);
  3488. this.negative = 1;
  3489. return this;
  3490. }
  3491. this.words[0] -= num;
  3492. if (this.length === 1 && this.words[0] < 0) {
  3493. this.words[0] = -this.words[0];
  3494. this.negative = 1;
  3495. } else {
  3496. // Carry
  3497. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  3498. this.words[i] += 0x4000000;
  3499. this.words[i + 1] -= 1;
  3500. }
  3501. }
  3502. return this.strip();
  3503. };
  3504. BN.prototype.addn = function addn (num) {
  3505. return this.clone().iaddn(num);
  3506. };
  3507. BN.prototype.subn = function subn (num) {
  3508. return this.clone().isubn(num);
  3509. };
  3510. BN.prototype.iabs = function iabs () {
  3511. this.negative = 0;
  3512. return this;
  3513. };
  3514. BN.prototype.abs = function abs () {
  3515. return this.clone().iabs();
  3516. };
  3517. BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
  3518. var len = num.length + shift;
  3519. var i;
  3520. this._expand(len);
  3521. var w;
  3522. var carry = 0;
  3523. for (i = 0; i < num.length; i++) {
  3524. w = (this.words[i + shift] | 0) + carry;
  3525. var right = (num.words[i] | 0) * mul;
  3526. w -= right & 0x3ffffff;
  3527. carry = (w >> 26) - ((right / 0x4000000) | 0);
  3528. this.words[i + shift] = w & 0x3ffffff;
  3529. }
  3530. for (; i < this.length - shift; i++) {
  3531. w = (this.words[i + shift] | 0) + carry;
  3532. carry = w >> 26;
  3533. this.words[i + shift] = w & 0x3ffffff;
  3534. }
  3535. if (carry === 0) return this.strip();
  3536. // Subtraction overflow
  3537. assert(carry === -1);
  3538. carry = 0;
  3539. for (i = 0; i < this.length; i++) {
  3540. w = -(this.words[i] | 0) + carry;
  3541. carry = w >> 26;
  3542. this.words[i] = w & 0x3ffffff;
  3543. }
  3544. this.negative = 1;
  3545. return this.strip();
  3546. };
  3547. BN.prototype._wordDiv = function _wordDiv (num, mode) {
  3548. var shift = this.length - num.length;
  3549. var a = this.clone();
  3550. var b = num;
  3551. // Normalize
  3552. var bhi = b.words[b.length - 1] | 0;
  3553. var bhiBits = this._countBits(bhi);
  3554. shift = 26 - bhiBits;
  3555. if (shift !== 0) {
  3556. b = b.ushln(shift);
  3557. a.iushln(shift);
  3558. bhi = b.words[b.length - 1] | 0;
  3559. }
  3560. // Initialize quotient
  3561. var m = a.length - b.length;
  3562. var q;
  3563. if (mode !== 'mod') {
  3564. q = new BN(null);
  3565. q.length = m + 1;
  3566. q.words = new Array(q.length);
  3567. for (var i = 0; i < q.length; i++) {
  3568. q.words[i] = 0;
  3569. }
  3570. }
  3571. var diff = a.clone()._ishlnsubmul(b, 1, m);
  3572. if (diff.negative === 0) {
  3573. a = diff;
  3574. if (q) {
  3575. q.words[m] = 1;
  3576. }
  3577. }
  3578. for (var j = m - 1; j >= 0; j--) {
  3579. var qj = (a.words[b.length + j] | 0) * 0x4000000 +
  3580. (a.words[b.length + j - 1] | 0);
  3581. // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  3582. // (0x7ffffff)
  3583. qj = Math.min((qj / bhi) | 0, 0x3ffffff);
  3584. a._ishlnsubmul(b, qj, j);
  3585. while (a.negative !== 0) {
  3586. qj--;
  3587. a.negative = 0;
  3588. a._ishlnsubmul(b, 1, j);
  3589. if (!a.isZero()) {
  3590. a.negative ^= 1;
  3591. }
  3592. }
  3593. if (q) {
  3594. q.words[j] = qj;
  3595. }
  3596. }
  3597. if (q) {
  3598. q.strip();
  3599. }
  3600. a.strip();
  3601. // Denormalize
  3602. if (mode !== 'div' && shift !== 0) {
  3603. a.iushrn(shift);
  3604. }
  3605. return {
  3606. div: q || null,
  3607. mod: a
  3608. };
  3609. };
  3610. // NOTE: 1) `mode` can be set to `mod` to request mod only,
  3611. // to `div` to request div only, or be absent to
  3612. // request both div & mod
  3613. // 2) `positive` is true if unsigned mod is requested
  3614. BN.prototype.divmod = function divmod (num, mode, positive) {
  3615. assert(!num.isZero());
  3616. if (this.isZero()) {
  3617. return {
  3618. div: new BN(0),
  3619. mod: new BN(0)
  3620. };
  3621. }
  3622. var div, mod, res;
  3623. if (this.negative !== 0 && num.negative === 0) {
  3624. res = this.neg().divmod(num, mode);
  3625. if (mode !== 'mod') {
  3626. div = res.div.neg();
  3627. }
  3628. if (mode !== 'div') {
  3629. mod = res.mod.neg();
  3630. if (positive && mod.negative !== 0) {
  3631. mod.iadd(num);
  3632. }
  3633. }
  3634. return {
  3635. div: div,
  3636. mod: mod
  3637. };
  3638. }
  3639. if (this.negative === 0 && num.negative !== 0) {
  3640. res = this.divmod(num.neg(), mode);
  3641. if (mode !== 'mod') {
  3642. div = res.div.neg();
  3643. }
  3644. return {
  3645. div: div,
  3646. mod: res.mod
  3647. };
  3648. }
  3649. if ((this.negative & num.negative) !== 0) {
  3650. res = this.neg().divmod(num.neg(), mode);
  3651. if (mode !== 'div') {
  3652. mod = res.mod.neg();
  3653. if (positive && mod.negative !== 0) {
  3654. mod.isub(num);
  3655. }
  3656. }
  3657. return {
  3658. div: res.div,
  3659. mod: mod
  3660. };
  3661. }
  3662. // Both numbers are positive at this point
  3663. // Strip both numbers to approximate shift value
  3664. if (num.length > this.length || this.cmp(num) < 0) {
  3665. return {
  3666. div: new BN(0),
  3667. mod: this
  3668. };
  3669. }
  3670. // Very short reduction
  3671. if (num.length === 1) {
  3672. if (mode === 'div') {
  3673. return {
  3674. div: this.divn(num.words[0]),
  3675. mod: null
  3676. };
  3677. }
  3678. if (mode === 'mod') {
  3679. return {
  3680. div: null,
  3681. mod: new BN(this.modn(num.words[0]))
  3682. };
  3683. }
  3684. return {
  3685. div: this.divn(num.words[0]),
  3686. mod: new BN(this.modn(num.words[0]))
  3687. };
  3688. }
  3689. return this._wordDiv(num, mode);
  3690. };
  3691. // Find `this` / `num`
  3692. BN.prototype.div = function div (num) {
  3693. return this.divmod(num, 'div', false).div;
  3694. };
  3695. // Find `this` % `num`
  3696. BN.prototype.mod = function mod (num) {
  3697. return this.divmod(num, 'mod', false).mod;
  3698. };
  3699. BN.prototype.umod = function umod (num) {
  3700. return this.divmod(num, 'mod', true).mod;
  3701. };
  3702. // Find Round(`this` / `num`)
  3703. BN.prototype.divRound = function divRound (num) {
  3704. var dm = this.divmod(num);
  3705. // Fast case - exact division
  3706. if (dm.mod.isZero()) return dm.div;
  3707. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  3708. var half = num.ushrn(1);
  3709. var r2 = num.andln(1);
  3710. var cmp = mod.cmp(half);
  3711. // Round down
  3712. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
  3713. // Round up
  3714. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  3715. };
  3716. BN.prototype.modn = function modn (num) {
  3717. assert(num <= 0x3ffffff);
  3718. var p = (1 << 26) % num;
  3719. var acc = 0;
  3720. for (var i = this.length - 1; i >= 0; i--) {
  3721. acc = (p * acc + (this.words[i] | 0)) % num;
  3722. }
  3723. return acc;
  3724. };
  3725. // In-place division by number
  3726. BN.prototype.idivn = function idivn (num) {
  3727. assert(num <= 0x3ffffff);
  3728. var carry = 0;
  3729. for (var i = this.length - 1; i >= 0; i--) {
  3730. var w = (this.words[i] | 0) + carry * 0x4000000;
  3731. this.words[i] = (w / num) | 0;
  3732. carry = w % num;
  3733. }
  3734. return this.strip();
  3735. };
  3736. BN.prototype.divn = function divn (num) {
  3737. return this.clone().idivn(num);
  3738. };
  3739. BN.prototype.egcd = function egcd (p) {
  3740. assert(p.negative === 0);
  3741. assert(!p.isZero());
  3742. var x = this;
  3743. var y = p.clone();
  3744. if (x.negative !== 0) {
  3745. x = x.umod(p);
  3746. } else {
  3747. x = x.clone();
  3748. }
  3749. // A * x + B * y = x
  3750. var A = new BN(1);
  3751. var B = new BN(0);
  3752. // C * x + D * y = y
  3753. var C = new BN(0);
  3754. var D = new BN(1);
  3755. var g = 0;
  3756. while (x.isEven() && y.isEven()) {
  3757. x.iushrn(1);
  3758. y.iushrn(1);
  3759. ++g;
  3760. }
  3761. var yp = y.clone();
  3762. var xp = x.clone();
  3763. while (!x.isZero()) {
  3764. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  3765. if (i > 0) {
  3766. x.iushrn(i);
  3767. while (i-- > 0) {
  3768. if (A.isOdd() || B.isOdd()) {
  3769. A.iadd(yp);
  3770. B.isub(xp);
  3771. }
  3772. A.iushrn(1);
  3773. B.iushrn(1);
  3774. }
  3775. }
  3776. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  3777. if (j > 0) {
  3778. y.iushrn(j);
  3779. while (j-- > 0) {
  3780. if (C.isOdd() || D.isOdd()) {
  3781. C.iadd(yp);
  3782. D.isub(xp);
  3783. }
  3784. C.iushrn(1);
  3785. D.iushrn(1);
  3786. }
  3787. }
  3788. if (x.cmp(y) >= 0) {
  3789. x.isub(y);
  3790. A.isub(C);
  3791. B.isub(D);
  3792. } else {
  3793. y.isub(x);
  3794. C.isub(A);
  3795. D.isub(B);
  3796. }
  3797. }
  3798. return {
  3799. a: C,
  3800. b: D,
  3801. gcd: y.iushln(g)
  3802. };
  3803. };
  3804. // This is reduced incarnation of the binary EEA
  3805. // above, designated to invert members of the
  3806. // _prime_ fields F(p) at a maximal speed
  3807. BN.prototype._invmp = function _invmp (p) {
  3808. assert(p.negative === 0);
  3809. assert(!p.isZero());
  3810. var a = this;
  3811. var b = p.clone();
  3812. if (a.negative !== 0) {
  3813. a = a.umod(p);
  3814. } else {
  3815. a = a.clone();
  3816. }
  3817. var x1 = new BN(1);
  3818. var x2 = new BN(0);
  3819. var delta = b.clone();
  3820. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  3821. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  3822. if (i > 0) {
  3823. a.iushrn(i);
  3824. while (i-- > 0) {
  3825. if (x1.isOdd()) {
  3826. x1.iadd(delta);
  3827. }
  3828. x1.iushrn(1);
  3829. }
  3830. }
  3831. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  3832. if (j > 0) {
  3833. b.iushrn(j);
  3834. while (j-- > 0) {
  3835. if (x2.isOdd()) {
  3836. x2.iadd(delta);
  3837. }
  3838. x2.iushrn(1);
  3839. }
  3840. }
  3841. if (a.cmp(b) >= 0) {
  3842. a.isub(b);
  3843. x1.isub(x2);
  3844. } else {
  3845. b.isub(a);
  3846. x2.isub(x1);
  3847. }
  3848. }
  3849. var res;
  3850. if (a.cmpn(1) === 0) {
  3851. res = x1;
  3852. } else {
  3853. res = x2;
  3854. }
  3855. if (res.cmpn(0) < 0) {
  3856. res.iadd(p);
  3857. }
  3858. return res;
  3859. };
  3860. BN.prototype.gcd = function gcd (num) {
  3861. if (this.isZero()) return num.abs();
  3862. if (num.isZero()) return this.abs();
  3863. var a = this.clone();
  3864. var b = num.clone();
  3865. a.negative = 0;
  3866. b.negative = 0;
  3867. // Remove common factor of two
  3868. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  3869. a.iushrn(1);
  3870. b.iushrn(1);
  3871. }
  3872. do {
  3873. while (a.isEven()) {
  3874. a.iushrn(1);
  3875. }
  3876. while (b.isEven()) {
  3877. b.iushrn(1);
  3878. }
  3879. var r = a.cmp(b);
  3880. if (r < 0) {
  3881. // Swap `a` and `b` to make `a` always bigger than `b`
  3882. var t = a;
  3883. a = b;
  3884. b = t;
  3885. } else if (r === 0 || b.cmpn(1) === 0) {
  3886. break;
  3887. }
  3888. a.isub(b);
  3889. } while (true);
  3890. return b.iushln(shift);
  3891. };
  3892. // Invert number in the field F(num)
  3893. BN.prototype.invm = function invm (num) {
  3894. return this.egcd(num).a.umod(num);
  3895. };
  3896. BN.prototype.isEven = function isEven () {
  3897. return (this.words[0] & 1) === 0;
  3898. };
  3899. BN.prototype.isOdd = function isOdd () {
  3900. return (this.words[0] & 1) === 1;
  3901. };
  3902. // And first word and num
  3903. BN.prototype.andln = function andln (num) {
  3904. return this.words[0] & num;
  3905. };
  3906. // Increment at the bit position in-line
  3907. BN.prototype.bincn = function bincn (bit) {
  3908. assert(typeof bit === 'number');
  3909. var r = bit % 26;
  3910. var s = (bit - r) / 26;
  3911. var q = 1 << r;
  3912. // Fast case: bit is much higher than all existing words
  3913. if (this.length <= s) {
  3914. this._expand(s + 1);
  3915. this.words[s] |= q;
  3916. return this;
  3917. }
  3918. // Add bit and propagate, if needed
  3919. var carry = q;
  3920. for (var i = s; carry !== 0 && i < this.length; i++) {
  3921. var w = this.words[i] | 0;
  3922. w += carry;
  3923. carry = w >>> 26;
  3924. w &= 0x3ffffff;
  3925. this.words[i] = w;
  3926. }
  3927. if (carry !== 0) {
  3928. this.words[i] = carry;
  3929. this.length++;
  3930. }
  3931. return this;
  3932. };
  3933. BN.prototype.isZero = function isZero () {
  3934. return this.length === 1 && this.words[0] === 0;
  3935. };
  3936. BN.prototype.cmpn = function cmpn (num) {
  3937. var negative = num < 0;
  3938. if (this.negative !== 0 && !negative) return -1;
  3939. if (this.negative === 0 && negative) return 1;
  3940. this.strip();
  3941. var res;
  3942. if (this.length > 1) {
  3943. res = 1;
  3944. } else {
  3945. if (negative) {
  3946. num = -num;
  3947. }
  3948. assert(num <= 0x3ffffff, 'Number is too big');
  3949. var w = this.words[0] | 0;
  3950. res = w === num ? 0 : w < num ? -1 : 1;
  3951. }
  3952. if (this.negative !== 0) return -res | 0;
  3953. return res;
  3954. };
  3955. // Compare two numbers and return:
  3956. // 1 - if `this` > `num`
  3957. // 0 - if `this` == `num`
  3958. // -1 - if `this` < `num`
  3959. BN.prototype.cmp = function cmp (num) {
  3960. if (this.negative !== 0 && num.negative === 0) return -1;
  3961. if (this.negative === 0 && num.negative !== 0) return 1;
  3962. var res = this.ucmp(num);
  3963. if (this.negative !== 0) return -res | 0;
  3964. return res;
  3965. };
  3966. // Unsigned comparison
  3967. BN.prototype.ucmp = function ucmp (num) {
  3968. // At this point both numbers have the same sign
  3969. if (this.length > num.length) return 1;
  3970. if (this.length < num.length) return -1;
  3971. var res = 0;
  3972. for (var i = this.length - 1; i >= 0; i--) {
  3973. var a = this.words[i] | 0;
  3974. var b = num.words[i] | 0;
  3975. if (a === b) continue;
  3976. if (a < b) {
  3977. res = -1;
  3978. } else if (a > b) {
  3979. res = 1;
  3980. }
  3981. break;
  3982. }
  3983. return res;
  3984. };
  3985. BN.prototype.gtn = function gtn (num) {
  3986. return this.cmpn(num) === 1;
  3987. };
  3988. BN.prototype.gt = function gt (num) {
  3989. return this.cmp(num) === 1;
  3990. };
  3991. BN.prototype.gten = function gten (num) {
  3992. return this.cmpn(num) >= 0;
  3993. };
  3994. BN.prototype.gte = function gte (num) {
  3995. return this.cmp(num) >= 0;
  3996. };
  3997. BN.prototype.ltn = function ltn (num) {
  3998. return this.cmpn(num) === -1;
  3999. };
  4000. BN.prototype.lt = function lt (num) {
  4001. return this.cmp(num) === -1;
  4002. };
  4003. BN.prototype.lten = function lten (num) {
  4004. return this.cmpn(num) <= 0;
  4005. };
  4006. BN.prototype.lte = function lte (num) {
  4007. return this.cmp(num) <= 0;
  4008. };
  4009. BN.prototype.eqn = function eqn (num) {
  4010. return this.cmpn(num) === 0;
  4011. };
  4012. BN.prototype.eq = function eq (num) {
  4013. return this.cmp(num) === 0;
  4014. };
  4015. //
  4016. // A reduce context, could be using montgomery or something better, depending
  4017. // on the `m` itself.
  4018. //
  4019. BN.red = function red (num) {
  4020. return new Red(num);
  4021. };
  4022. BN.prototype.toRed = function toRed (ctx) {
  4023. assert(!this.red, 'Already a number in reduction context');
  4024. assert(this.negative === 0, 'red works only with positives');
  4025. return ctx.convertTo(this)._forceRed(ctx);
  4026. };
  4027. BN.prototype.fromRed = function fromRed () {
  4028. assert(this.red, 'fromRed works only with numbers in reduction context');
  4029. return this.red.convertFrom(this);
  4030. };
  4031. BN.prototype._forceRed = function _forceRed (ctx) {
  4032. this.red = ctx;
  4033. return this;
  4034. };
  4035. BN.prototype.forceRed = function forceRed (ctx) {
  4036. assert(!this.red, 'Already a number in reduction context');
  4037. return this._forceRed(ctx);
  4038. };
  4039. BN.prototype.redAdd = function redAdd (num) {
  4040. assert(this.red, 'redAdd works only with red numbers');
  4041. return this.red.add(this, num);
  4042. };
  4043. BN.prototype.redIAdd = function redIAdd (num) {
  4044. assert(this.red, 'redIAdd works only with red numbers');
  4045. return this.red.iadd(this, num);
  4046. };
  4047. BN.prototype.redSub = function redSub (num) {
  4048. assert(this.red, 'redSub works only with red numbers');
  4049. return this.red.sub(this, num);
  4050. };
  4051. BN.prototype.redISub = function redISub (num) {
  4052. assert(this.red, 'redISub works only with red numbers');
  4053. return this.red.isub(this, num);
  4054. };
  4055. BN.prototype.redShl = function redShl (num) {
  4056. assert(this.red, 'redShl works only with red numbers');
  4057. return this.red.shl(this, num);
  4058. };
  4059. BN.prototype.redMul = function redMul (num) {
  4060. assert(this.red, 'redMul works only with red numbers');
  4061. this.red._verify2(this, num);
  4062. return this.red.mul(this, num);
  4063. };
  4064. BN.prototype.redIMul = function redIMul (num) {
  4065. assert(this.red, 'redMul works only with red numbers');
  4066. this.red._verify2(this, num);
  4067. return this.red.imul(this, num);
  4068. };
  4069. BN.prototype.redSqr = function redSqr () {
  4070. assert(this.red, 'redSqr works only with red numbers');
  4071. this.red._verify1(this);
  4072. return this.red.sqr(this);
  4073. };
  4074. BN.prototype.redISqr = function redISqr () {
  4075. assert(this.red, 'redISqr works only with red numbers');
  4076. this.red._verify1(this);
  4077. return this.red.isqr(this);
  4078. };
  4079. // Square root over p
  4080. BN.prototype.redSqrt = function redSqrt () {
  4081. assert(this.red, 'redSqrt works only with red numbers');
  4082. this.red._verify1(this);
  4083. return this.red.sqrt(this);
  4084. };
  4085. BN.prototype.redInvm = function redInvm () {
  4086. assert(this.red, 'redInvm works only with red numbers');
  4087. this.red._verify1(this);
  4088. return this.red.invm(this);
  4089. };
  4090. // Return negative clone of `this` % `red modulo`
  4091. BN.prototype.redNeg = function redNeg () {
  4092. assert(this.red, 'redNeg works only with red numbers');
  4093. this.red._verify1(this);
  4094. return this.red.neg(this);
  4095. };
  4096. BN.prototype.redPow = function redPow (num) {
  4097. assert(this.red && !num.red, 'redPow(normalNum)');
  4098. this.red._verify1(this);
  4099. return this.red.pow(this, num);
  4100. };
  4101. // Prime numbers with efficient reduction
  4102. var primes = {
  4103. k256: null,
  4104. p224: null,
  4105. p192: null,
  4106. p25519: null
  4107. };
  4108. // Pseudo-Mersenne prime
  4109. function MPrime (name, p) {
  4110. // P = 2 ^ N - K
  4111. this.name = name;
  4112. this.p = new BN(p, 16);
  4113. this.n = this.p.bitLength();
  4114. this.k = new BN(1).iushln(this.n).isub(this.p);
  4115. this.tmp = this._tmp();
  4116. }
  4117. MPrime.prototype._tmp = function _tmp () {
  4118. var tmp = new BN(null);
  4119. tmp.words = new Array(Math.ceil(this.n / 13));
  4120. return tmp;
  4121. };
  4122. MPrime.prototype.ireduce = function ireduce (num) {
  4123. // Assumes that `num` is less than `P^2`
  4124. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  4125. var r = num;
  4126. var rlen;
  4127. do {
  4128. this.split(r, this.tmp);
  4129. r = this.imulK(r);
  4130. r = r.iadd(this.tmp);
  4131. rlen = r.bitLength();
  4132. } while (rlen > this.n);
  4133. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  4134. if (cmp === 0) {
  4135. r.words[0] = 0;
  4136. r.length = 1;
  4137. } else if (cmp > 0) {
  4138. r.isub(this.p);
  4139. } else {
  4140. r.strip();
  4141. }
  4142. return r;
  4143. };
  4144. MPrime.prototype.split = function split (input, out) {
  4145. input.iushrn(this.n, 0, out);
  4146. };
  4147. MPrime.prototype.imulK = function imulK (num) {
  4148. return num.imul(this.k);
  4149. };
  4150. function K256 () {
  4151. MPrime.call(
  4152. this,
  4153. 'k256',
  4154. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  4155. }
  4156. inherits(K256, MPrime);
  4157. K256.prototype.split = function split (input, output) {
  4158. // 256 = 9 * 26 + 22
  4159. var mask = 0x3fffff;
  4160. var outLen = Math.min(input.length, 9);
  4161. for (var i = 0; i < outLen; i++) {
  4162. output.words[i] = input.words[i];
  4163. }
  4164. output.length = outLen;
  4165. if (input.length <= 9) {
  4166. input.words[0] = 0;
  4167. input.length = 1;
  4168. return;
  4169. }
  4170. // Shift by 9 limbs
  4171. var prev = input.words[9];
  4172. output.words[output.length++] = prev & mask;
  4173. for (i = 10; i < input.length; i++) {
  4174. var next = input.words[i] | 0;
  4175. input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
  4176. prev = next;
  4177. }
  4178. prev >>>= 22;
  4179. input.words[i - 10] = prev;
  4180. if (prev === 0 && input.length > 10) {
  4181. input.length -= 10;
  4182. } else {
  4183. input.length -= 9;
  4184. }
  4185. };
  4186. K256.prototype.imulK = function imulK (num) {
  4187. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  4188. num.words[num.length] = 0;
  4189. num.words[num.length + 1] = 0;
  4190. num.length += 2;
  4191. // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  4192. var lo = 0;
  4193. for (var i = 0; i < num.length; i++) {
  4194. var w = num.words[i] | 0;
  4195. lo += w * 0x3d1;
  4196. num.words[i] = lo & 0x3ffffff;
  4197. lo = w * 0x40 + ((lo / 0x4000000) | 0);
  4198. }
  4199. // Fast length reduction
  4200. if (num.words[num.length - 1] === 0) {
  4201. num.length--;
  4202. if (num.words[num.length - 1] === 0) {
  4203. num.length--;
  4204. }
  4205. }
  4206. return num;
  4207. };
  4208. function P224 () {
  4209. MPrime.call(
  4210. this,
  4211. 'p224',
  4212. 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  4213. }
  4214. inherits(P224, MPrime);
  4215. function P192 () {
  4216. MPrime.call(
  4217. this,
  4218. 'p192',
  4219. 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  4220. }
  4221. inherits(P192, MPrime);
  4222. function P25519 () {
  4223. // 2 ^ 255 - 19
  4224. MPrime.call(
  4225. this,
  4226. '25519',
  4227. '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  4228. }
  4229. inherits(P25519, MPrime);
  4230. P25519.prototype.imulK = function imulK (num) {
  4231. // K = 0x13
  4232. var carry = 0;
  4233. for (var i = 0; i < num.length; i++) {
  4234. var hi = (num.words[i] | 0) * 0x13 + carry;
  4235. var lo = hi & 0x3ffffff;
  4236. hi >>>= 26;
  4237. num.words[i] = lo;
  4238. carry = hi;
  4239. }
  4240. if (carry !== 0) {
  4241. num.words[num.length++] = carry;
  4242. }
  4243. return num;
  4244. };
  4245. // Exported mostly for testing purposes, use plain name instead
  4246. BN._prime = function prime (name) {
  4247. // Cached version of prime
  4248. if (primes[name]) return primes[name];
  4249. var prime;
  4250. if (name === 'k256') {
  4251. prime = new K256();
  4252. } else if (name === 'p224') {
  4253. prime = new P224();
  4254. } else if (name === 'p192') {
  4255. prime = new P192();
  4256. } else if (name === 'p25519') {
  4257. prime = new P25519();
  4258. } else {
  4259. throw new Error('Unknown prime ' + name);
  4260. }
  4261. primes[name] = prime;
  4262. return prime;
  4263. };
  4264. //
  4265. // Base reduction engine
  4266. //
  4267. function Red (m) {
  4268. if (typeof m === 'string') {
  4269. var prime = BN._prime(m);
  4270. this.m = prime.p;
  4271. this.prime = prime;
  4272. } else {
  4273. assert(m.gtn(1), 'modulus must be greater than 1');
  4274. this.m = m;
  4275. this.prime = null;
  4276. }
  4277. }
  4278. Red.prototype._verify1 = function _verify1 (a) {
  4279. assert(a.negative === 0, 'red works only with positives');
  4280. assert(a.red, 'red works only with red numbers');
  4281. };
  4282. Red.prototype._verify2 = function _verify2 (a, b) {
  4283. assert((a.negative | b.negative) === 0, 'red works only with positives');
  4284. assert(a.red && a.red === b.red,
  4285. 'red works only with red numbers');
  4286. };
  4287. Red.prototype.imod = function imod (a) {
  4288. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  4289. return a.umod(this.m)._forceRed(this);
  4290. };
  4291. Red.prototype.neg = function neg (a) {
  4292. if (a.isZero()) {
  4293. return a.clone();
  4294. }
  4295. return this.m.sub(a)._forceRed(this);
  4296. };
  4297. Red.prototype.add = function add (a, b) {
  4298. this._verify2(a, b);
  4299. var res = a.add(b);
  4300. if (res.cmp(this.m) >= 0) {
  4301. res.isub(this.m);
  4302. }
  4303. return res._forceRed(this);
  4304. };
  4305. Red.prototype.iadd = function iadd (a, b) {
  4306. this._verify2(a, b);
  4307. var res = a.iadd(b);
  4308. if (res.cmp(this.m) >= 0) {
  4309. res.isub(this.m);
  4310. }
  4311. return res;
  4312. };
  4313. Red.prototype.sub = function sub (a, b) {
  4314. this._verify2(a, b);
  4315. var res = a.sub(b);
  4316. if (res.cmpn(0) < 0) {
  4317. res.iadd(this.m);
  4318. }
  4319. return res._forceRed(this);
  4320. };
  4321. Red.prototype.isub = function isub (a, b) {
  4322. this._verify2(a, b);
  4323. var res = a.isub(b);
  4324. if (res.cmpn(0) < 0) {
  4325. res.iadd(this.m);
  4326. }
  4327. return res;
  4328. };
  4329. Red.prototype.shl = function shl (a, num) {
  4330. this._verify1(a);
  4331. return this.imod(a.ushln(num));
  4332. };
  4333. Red.prototype.imul = function imul (a, b) {
  4334. this._verify2(a, b);
  4335. return this.imod(a.imul(b));
  4336. };
  4337. Red.prototype.mul = function mul (a, b) {
  4338. this._verify2(a, b);
  4339. return this.imod(a.mul(b));
  4340. };
  4341. Red.prototype.isqr = function isqr (a) {
  4342. return this.imul(a, a.clone());
  4343. };
  4344. Red.prototype.sqr = function sqr (a) {
  4345. return this.mul(a, a);
  4346. };
  4347. Red.prototype.sqrt = function sqrt (a) {
  4348. if (a.isZero()) return a.clone();
  4349. var mod3 = this.m.andln(3);
  4350. assert(mod3 % 2 === 1);
  4351. // Fast case
  4352. if (mod3 === 3) {
  4353. var pow = this.m.add(new BN(1)).iushrn(2);
  4354. return this.pow(a, pow);
  4355. }
  4356. // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  4357. //
  4358. // Find Q and S, that Q * 2 ^ S = (P - 1)
  4359. var q = this.m.subn(1);
  4360. var s = 0;
  4361. while (!q.isZero() && q.andln(1) === 0) {
  4362. s++;
  4363. q.iushrn(1);
  4364. }
  4365. assert(!q.isZero());
  4366. var one = new BN(1).toRed(this);
  4367. var nOne = one.redNeg();
  4368. // Find quadratic non-residue
  4369. // NOTE: Max is such because of generalized Riemann hypothesis.
  4370. var lpow = this.m.subn(1).iushrn(1);
  4371. var z = this.m.bitLength();
  4372. z = new BN(2 * z * z).toRed(this);
  4373. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  4374. z.redIAdd(nOne);
  4375. }
  4376. var c = this.pow(z, q);
  4377. var r = this.pow(a, q.addn(1).iushrn(1));
  4378. var t = this.pow(a, q);
  4379. var m = s;
  4380. while (t.cmp(one) !== 0) {
  4381. var tmp = t;
  4382. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  4383. tmp = tmp.redSqr();
  4384. }
  4385. assert(i < m);
  4386. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  4387. r = r.redMul(b);
  4388. c = b.redSqr();
  4389. t = t.redMul(c);
  4390. m = i;
  4391. }
  4392. return r;
  4393. };
  4394. Red.prototype.invm = function invm (a) {
  4395. var inv = a._invmp(this.m);
  4396. if (inv.negative !== 0) {
  4397. inv.negative = 0;
  4398. return this.imod(inv).redNeg();
  4399. } else {
  4400. return this.imod(inv);
  4401. }
  4402. };
  4403. Red.prototype.pow = function pow (a, num) {
  4404. if (num.isZero()) return new BN(1);
  4405. if (num.cmpn(1) === 0) return a.clone();
  4406. var windowSize = 4;
  4407. var wnd = new Array(1 << windowSize);
  4408. wnd[0] = new BN(1).toRed(this);
  4409. wnd[1] = a;
  4410. for (var i = 2; i < wnd.length; i++) {
  4411. wnd[i] = this.mul(wnd[i - 1], a);
  4412. }
  4413. var res = wnd[0];
  4414. var current = 0;
  4415. var currentLen = 0;
  4416. var start = num.bitLength() % 26;
  4417. if (start === 0) {
  4418. start = 26;
  4419. }
  4420. for (i = num.length - 1; i >= 0; i--) {
  4421. var word = num.words[i];
  4422. for (var j = start - 1; j >= 0; j--) {
  4423. var bit = (word >> j) & 1;
  4424. if (res !== wnd[0]) {
  4425. res = this.sqr(res);
  4426. }
  4427. if (bit === 0 && current === 0) {
  4428. currentLen = 0;
  4429. continue;
  4430. }
  4431. current <<= 1;
  4432. current |= bit;
  4433. currentLen++;
  4434. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  4435. res = this.mul(res, wnd[current]);
  4436. currentLen = 0;
  4437. current = 0;
  4438. }
  4439. start = 26;
  4440. }
  4441. return res;
  4442. };
  4443. Red.prototype.convertTo = function convertTo (num) {
  4444. var r = num.umod(this.m);
  4445. return r === num ? r.clone() : r;
  4446. };
  4447. Red.prototype.convertFrom = function convertFrom (num) {
  4448. var res = num.clone();
  4449. res.red = null;
  4450. return res;
  4451. };
  4452. //
  4453. // Montgomery method engine
  4454. //
  4455. BN.mont = function mont (num) {
  4456. return new Mont(num);
  4457. };
  4458. function Mont (m) {
  4459. Red.call(this, m);
  4460. this.shift = this.m.bitLength();
  4461. if (this.shift % 26 !== 0) {
  4462. this.shift += 26 - (this.shift % 26);
  4463. }
  4464. this.r = new BN(1).iushln(this.shift);
  4465. this.r2 = this.imod(this.r.sqr());
  4466. this.rinv = this.r._invmp(this.m);
  4467. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  4468. this.minv = this.minv.umod(this.r);
  4469. this.minv = this.r.sub(this.minv);
  4470. }
  4471. inherits(Mont, Red);
  4472. Mont.prototype.convertTo = function convertTo (num) {
  4473. return this.imod(num.ushln(this.shift));
  4474. };
  4475. Mont.prototype.convertFrom = function convertFrom (num) {
  4476. var r = this.imod(num.mul(this.rinv));
  4477. r.red = null;
  4478. return r;
  4479. };
  4480. Mont.prototype.imul = function imul (a, b) {
  4481. if (a.isZero() || b.isZero()) {
  4482. a.words[0] = 0;
  4483. a.length = 1;
  4484. return a;
  4485. }
  4486. var t = a.imul(b);
  4487. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  4488. var u = t.isub(c).iushrn(this.shift);
  4489. var res = u;
  4490. if (u.cmp(this.m) >= 0) {
  4491. res = u.isub(this.m);
  4492. } else if (u.cmpn(0) < 0) {
  4493. res = u.iadd(this.m);
  4494. }
  4495. return res._forceRed(this);
  4496. };
  4497. Mont.prototype.mul = function mul (a, b) {
  4498. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  4499. var t = a.mul(b);
  4500. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  4501. var u = t.isub(c).iushrn(this.shift);
  4502. var res = u;
  4503. if (u.cmp(this.m) >= 0) {
  4504. res = u.isub(this.m);
  4505. } else if (u.cmpn(0) < 0) {
  4506. res = u.iadd(this.m);
  4507. }
  4508. return res._forceRed(this);
  4509. };
  4510. Mont.prototype.invm = function invm (a) {
  4511. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  4512. var res = this.imod(a._invmp(this.m).mul(this.r2));
  4513. return res._forceRed(this);
  4514. };
  4515. })(typeof module === 'undefined' || module, this);
  4516. },{}],19:[function(require,module,exports){
  4517. var r;
  4518. module.exports = function rand(len) {
  4519. if (!r)
  4520. r = new Rand(null);
  4521. return r.generate(len);
  4522. };
  4523. function Rand(rand) {
  4524. this.rand = rand;
  4525. }
  4526. module.exports.Rand = Rand;
  4527. Rand.prototype.generate = function generate(len) {
  4528. return this._rand(len);
  4529. };
  4530. if (typeof window === 'object') {
  4531. if (window.crypto && window.crypto.getRandomValues) {
  4532. // Modern browsers
  4533. Rand.prototype._rand = function _rand(n) {
  4534. var arr = new Uint8Array(n);
  4535. window.crypto.getRandomValues(arr);
  4536. return arr;
  4537. };
  4538. } else if (window.msCrypto && window.msCrypto.getRandomValues) {
  4539. // IE
  4540. Rand.prototype._rand = function _rand(n) {
  4541. var arr = new Uint8Array(n);
  4542. window.msCrypto.getRandomValues(arr);
  4543. return arr;
  4544. };
  4545. } else {
  4546. // Old junk
  4547. Rand.prototype._rand = function() {
  4548. throw new Error('Not implemented yet');
  4549. };
  4550. }
  4551. } else {
  4552. // Node.js or Web worker
  4553. try {
  4554. var crypto = require('cry' + 'pto');
  4555. Rand.prototype._rand = function _rand(n) {
  4556. return crypto.randomBytes(n);
  4557. };
  4558. } catch (e) {
  4559. // Emulate crypto API using randy
  4560. Rand.prototype._rand = function _rand(n) {
  4561. var res = new Uint8Array(n);
  4562. for (var i = 0; i < res.length; i++)
  4563. res[i] = this.rand.getByte();
  4564. return res;
  4565. };
  4566. }
  4567. }
  4568. },{}],20:[function(require,module,exports){
  4569. },{}],21:[function(require,module,exports){
  4570. (function (Buffer){
  4571. // based on the aes implimentation in triple sec
  4572. // https://github.com/keybase/triplesec
  4573. // which is in turn based on the one from crypto-js
  4574. // https://code.google.com/p/crypto-js/
  4575. var uint_max = Math.pow(2, 32)
  4576. function fixup_uint32 (x) {
  4577. var ret, x_pos
  4578. ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x
  4579. return ret
  4580. }
  4581. function scrub_vec (v) {
  4582. for (var i = 0; i < v.length; v++) {
  4583. v[i] = 0
  4584. }
  4585. return false
  4586. }
  4587. function Global () {
  4588. this.SBOX = []
  4589. this.INV_SBOX = []
  4590. this.SUB_MIX = [[], [], [], []]
  4591. this.INV_SUB_MIX = [[], [], [], []]
  4592. this.init()
  4593. this.RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
  4594. }
  4595. Global.prototype.init = function () {
  4596. var d, i, sx, t, x, x2, x4, x8, xi, _i
  4597. d = (function () {
  4598. var _i, _results
  4599. _results = []
  4600. for (i = _i = 0; _i < 256; i = ++_i) {
  4601. if (i < 128) {
  4602. _results.push(i << 1)
  4603. } else {
  4604. _results.push((i << 1) ^ 0x11b)
  4605. }
  4606. }
  4607. return _results
  4608. })()
  4609. x = 0
  4610. xi = 0
  4611. for (i = _i = 0; _i < 256; i = ++_i) {
  4612. sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
  4613. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63
  4614. this.SBOX[x] = sx
  4615. this.INV_SBOX[sx] = x
  4616. x2 = d[x]
  4617. x4 = d[x2]
  4618. x8 = d[x4]
  4619. t = (d[sx] * 0x101) ^ (sx * 0x1010100)
  4620. this.SUB_MIX[0][x] = (t << 24) | (t >>> 8)
  4621. this.SUB_MIX[1][x] = (t << 16) | (t >>> 16)
  4622. this.SUB_MIX[2][x] = (t << 8) | (t >>> 24)
  4623. this.SUB_MIX[3][x] = t
  4624. t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100)
  4625. this.INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
  4626. this.INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
  4627. this.INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
  4628. this.INV_SUB_MIX[3][sx] = t
  4629. if (x === 0) {
  4630. x = xi = 1
  4631. } else {
  4632. x = x2 ^ d[d[d[x8 ^ x2]]]
  4633. xi ^= d[d[xi]]
  4634. }
  4635. }
  4636. return true
  4637. }
  4638. var G = new Global()
  4639. AES.blockSize = 4 * 4
  4640. AES.prototype.blockSize = AES.blockSize
  4641. AES.keySize = 256 / 8
  4642. AES.prototype.keySize = AES.keySize
  4643. function bufferToArray (buf) {
  4644. var len = buf.length / 4
  4645. var out = new Array(len)
  4646. var i = -1
  4647. while (++i < len) {
  4648. out[i] = buf.readUInt32BE(i * 4)
  4649. }
  4650. return out
  4651. }
  4652. function AES (key) {
  4653. this._key = bufferToArray(key)
  4654. this._doReset()
  4655. }
  4656. AES.prototype._doReset = function () {
  4657. var invKsRow, keySize, keyWords, ksRow, ksRows, t
  4658. keyWords = this._key
  4659. keySize = keyWords.length
  4660. this._nRounds = keySize + 6
  4661. ksRows = (this._nRounds + 1) * 4
  4662. this._keySchedule = []
  4663. for (ksRow = 0; ksRow < ksRows; ksRow++) {
  4664. 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)
  4665. }
  4666. this._invKeySchedule = []
  4667. for (invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  4668. ksRow = ksRows - invKsRow
  4669. t = this._keySchedule[ksRow - (invKsRow % 4 ? 0 : 4)]
  4670. 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]]
  4671. }
  4672. return true
  4673. }
  4674. AES.prototype.encryptBlock = function (M) {
  4675. M = bufferToArray(new Buffer(M))
  4676. var out = this._doCryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX)
  4677. var buf = new Buffer(16)
  4678. buf.writeUInt32BE(out[0], 0)
  4679. buf.writeUInt32BE(out[1], 4)
  4680. buf.writeUInt32BE(out[2], 8)
  4681. buf.writeUInt32BE(out[3], 12)
  4682. return buf
  4683. }
  4684. AES.prototype.decryptBlock = function (M) {
  4685. M = bufferToArray(new Buffer(M))
  4686. var temp = [M[3], M[1]]
  4687. M[1] = temp[0]
  4688. M[3] = temp[1]
  4689. var out = this._doCryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX)
  4690. var buf = new Buffer(16)
  4691. buf.writeUInt32BE(out[0], 0)
  4692. buf.writeUInt32BE(out[3], 4)
  4693. buf.writeUInt32BE(out[2], 8)
  4694. buf.writeUInt32BE(out[1], 12)
  4695. return buf
  4696. }
  4697. AES.prototype.scrub = function () {
  4698. scrub_vec(this._keySchedule)
  4699. scrub_vec(this._invKeySchedule)
  4700. scrub_vec(this._key)
  4701. }
  4702. AES.prototype._doCryptBlock = function (M, keySchedule, SUB_MIX, SBOX) {
  4703. var ksRow, s0, s1, s2, s3, t0, t1, t2, t3
  4704. s0 = M[0] ^ keySchedule[0]
  4705. s1 = M[1] ^ keySchedule[1]
  4706. s2 = M[2] ^ keySchedule[2]
  4707. s3 = M[3] ^ keySchedule[3]
  4708. ksRow = 4
  4709. for (var round = 1; round < this._nRounds; round++) {
  4710. 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++]
  4711. 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++]
  4712. 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++]
  4713. 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++]
  4714. s0 = t0
  4715. s1 = t1
  4716. s2 = t2
  4717. s3 = t3
  4718. }
  4719. t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]
  4720. t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]
  4721. t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]
  4722. t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]
  4723. return [
  4724. fixup_uint32(t0),
  4725. fixup_uint32(t1),
  4726. fixup_uint32(t2),
  4727. fixup_uint32(t3)
  4728. ]
  4729. }
  4730. exports.AES = AES
  4731. }).call(this,require("buffer").Buffer)
  4732. },{"buffer":46}],22:[function(require,module,exports){
  4733. (function (Buffer){
  4734. var aes = require('./aes')
  4735. var Transform = require('cipher-base')
  4736. var inherits = require('inherits')
  4737. var GHASH = require('./ghash')
  4738. var xor = require('buffer-xor')
  4739. inherits(StreamCipher, Transform)
  4740. module.exports = StreamCipher
  4741. function StreamCipher (mode, key, iv, decrypt) {
  4742. if (!(this instanceof StreamCipher)) {
  4743. return new StreamCipher(mode, key, iv)
  4744. }
  4745. Transform.call(this)
  4746. this._finID = Buffer.concat([iv, new Buffer([0, 0, 0, 1])])
  4747. iv = Buffer.concat([iv, new Buffer([0, 0, 0, 2])])
  4748. this._cipher = new aes.AES(key)
  4749. this._prev = new Buffer(iv.length)
  4750. this._cache = new Buffer('')
  4751. this._secCache = new Buffer('')
  4752. this._decrypt = decrypt
  4753. this._alen = 0
  4754. this._len = 0
  4755. iv.copy(this._prev)
  4756. this._mode = mode
  4757. var h = new Buffer(4)
  4758. h.fill(0)
  4759. this._ghash = new GHASH(this._cipher.encryptBlock(h))
  4760. this._authTag = null
  4761. this._called = false
  4762. }
  4763. StreamCipher.prototype._update = function (chunk) {
  4764. if (!this._called && this._alen) {
  4765. var rump = 16 - (this._alen % 16)
  4766. if (rump < 16) {
  4767. rump = new Buffer(rump)
  4768. rump.fill(0)
  4769. this._ghash.update(rump)
  4770. }
  4771. }
  4772. this._called = true
  4773. var out = this._mode.encrypt(this, chunk)
  4774. if (this._decrypt) {
  4775. this._ghash.update(chunk)
  4776. } else {
  4777. this._ghash.update(out)
  4778. }
  4779. this._len += chunk.length
  4780. return out
  4781. }
  4782. StreamCipher.prototype._final = function () {
  4783. if (this._decrypt && !this._authTag) {
  4784. throw new Error('Unsupported state or unable to authenticate data')
  4785. }
  4786. var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID))
  4787. if (this._decrypt) {
  4788. if (xorTest(tag, this._authTag)) {
  4789. throw new Error('Unsupported state or unable to authenticate data')
  4790. }
  4791. } else {
  4792. this._authTag = tag
  4793. }
  4794. this._cipher.scrub()
  4795. }
  4796. StreamCipher.prototype.getAuthTag = function getAuthTag () {
  4797. if (!this._decrypt && Buffer.isBuffer(this._authTag)) {
  4798. return this._authTag
  4799. } else {
  4800. throw new Error('Attempting to get auth tag in unsupported state')
  4801. }
  4802. }
  4803. StreamCipher.prototype.setAuthTag = function setAuthTag (tag) {
  4804. if (this._decrypt) {
  4805. this._authTag = tag
  4806. } else {
  4807. throw new Error('Attempting to set auth tag in unsupported state')
  4808. }
  4809. }
  4810. StreamCipher.prototype.setAAD = function setAAD (buf) {
  4811. if (!this._called) {
  4812. this._ghash.update(buf)
  4813. this._alen += buf.length
  4814. } else {
  4815. throw new Error('Attempting to set AAD in unsupported state')
  4816. }
  4817. }
  4818. function xorTest (a, b) {
  4819. var out = 0
  4820. if (a.length !== b.length) {
  4821. out++
  4822. }
  4823. var len = Math.min(a.length, b.length)
  4824. var i = -1
  4825. while (++i < len) {
  4826. out += (a[i] ^ b[i])
  4827. }
  4828. return out
  4829. }
  4830. }).call(this,require("buffer").Buffer)
  4831. },{"./aes":21,"./ghash":26,"buffer":46,"buffer-xor":45,"cipher-base":47,"inherits":92}],23:[function(require,module,exports){
  4832. var ciphers = require('./encrypter')
  4833. exports.createCipher = exports.Cipher = ciphers.createCipher
  4834. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv
  4835. var deciphers = require('./decrypter')
  4836. exports.createDecipher = exports.Decipher = deciphers.createDecipher
  4837. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv
  4838. var modes = require('./modes')
  4839. function getCiphers () {
  4840. return Object.keys(modes)
  4841. }
  4842. exports.listCiphers = exports.getCiphers = getCiphers
  4843. },{"./decrypter":24,"./encrypter":25,"./modes":27}],24:[function(require,module,exports){
  4844. (function (Buffer){
  4845. var aes = require('./aes')
  4846. var Transform = require('cipher-base')
  4847. var inherits = require('inherits')
  4848. var modes = require('./modes')
  4849. var StreamCipher = require('./streamCipher')
  4850. var AuthCipher = require('./authCipher')
  4851. var ebtk = require('evp_bytestokey')
  4852. inherits(Decipher, Transform)
  4853. function Decipher (mode, key, iv) {
  4854. if (!(this instanceof Decipher)) {
  4855. return new Decipher(mode, key, iv)
  4856. }
  4857. Transform.call(this)
  4858. this._cache = new Splitter()
  4859. this._last = void 0
  4860. this._cipher = new aes.AES(key)
  4861. this._prev = new Buffer(iv.length)
  4862. iv.copy(this._prev)
  4863. this._mode = mode
  4864. this._autopadding = true
  4865. }
  4866. Decipher.prototype._update = function (data) {
  4867. this._cache.add(data)
  4868. var chunk
  4869. var thing
  4870. var out = []
  4871. while ((chunk = this._cache.get(this._autopadding))) {
  4872. thing = this._mode.decrypt(this, chunk)
  4873. out.push(thing)
  4874. }
  4875. return Buffer.concat(out)
  4876. }
  4877. Decipher.prototype._final = function () {
  4878. var chunk = this._cache.flush()
  4879. if (this._autopadding) {
  4880. return unpad(this._mode.decrypt(this, chunk))
  4881. } else if (chunk) {
  4882. throw new Error('data not multiple of block length')
  4883. }
  4884. }
  4885. Decipher.prototype.setAutoPadding = function (setTo) {
  4886. this._autopadding = !!setTo
  4887. return this
  4888. }
  4889. function Splitter () {
  4890. if (!(this instanceof Splitter)) {
  4891. return new Splitter()
  4892. }
  4893. this.cache = new Buffer('')
  4894. }
  4895. Splitter.prototype.add = function (data) {
  4896. this.cache = Buffer.concat([this.cache, data])
  4897. }
  4898. Splitter.prototype.get = function (autoPadding) {
  4899. var out
  4900. if (autoPadding) {
  4901. if (this.cache.length > 16) {
  4902. out = this.cache.slice(0, 16)
  4903. this.cache = this.cache.slice(16)
  4904. return out
  4905. }
  4906. } else {
  4907. if (this.cache.length >= 16) {
  4908. out = this.cache.slice(0, 16)
  4909. this.cache = this.cache.slice(16)
  4910. return out
  4911. }
  4912. }
  4913. return null
  4914. }
  4915. Splitter.prototype.flush = function () {
  4916. if (this.cache.length) {
  4917. return this.cache
  4918. }
  4919. }
  4920. function unpad (last) {
  4921. var padded = last[15]
  4922. var i = -1
  4923. while (++i < padded) {
  4924. if (last[(i + (16 - padded))] !== padded) {
  4925. throw new Error('unable to decrypt data')
  4926. }
  4927. }
  4928. if (padded === 16) {
  4929. return
  4930. }
  4931. return last.slice(0, 16 - padded)
  4932. }
  4933. var modelist = {
  4934. ECB: require('./modes/ecb'),
  4935. CBC: require('./modes/cbc'),
  4936. CFB: require('./modes/cfb'),
  4937. CFB8: require('./modes/cfb8'),
  4938. CFB1: require('./modes/cfb1'),
  4939. OFB: require('./modes/ofb'),
  4940. CTR: require('./modes/ctr'),
  4941. GCM: require('./modes/ctr')
  4942. }
  4943. function createDecipheriv (suite, password, iv) {
  4944. var config = modes[suite.toLowerCase()]
  4945. if (!config) {
  4946. throw new TypeError('invalid suite type')
  4947. }
  4948. if (typeof iv === 'string') {
  4949. iv = new Buffer(iv)
  4950. }
  4951. if (typeof password === 'string') {
  4952. password = new Buffer(password)
  4953. }
  4954. if (password.length !== config.key / 8) {
  4955. throw new TypeError('invalid key length ' + password.length)
  4956. }
  4957. if (iv.length !== config.iv) {
  4958. throw new TypeError('invalid iv length ' + iv.length)
  4959. }
  4960. if (config.type === 'stream') {
  4961. return new StreamCipher(modelist[config.mode], password, iv, true)
  4962. } else if (config.type === 'auth') {
  4963. return new AuthCipher(modelist[config.mode], password, iv, true)
  4964. }
  4965. return new Decipher(modelist[config.mode], password, iv)
  4966. }
  4967. function createDecipher (suite, password) {
  4968. var config = modes[suite.toLowerCase()]
  4969. if (!config) {
  4970. throw new TypeError('invalid suite type')
  4971. }
  4972. var keys = ebtk(password, false, config.key, config.iv)
  4973. return createDecipheriv(suite, keys.key, keys.iv)
  4974. }
  4975. exports.createDecipher = createDecipher
  4976. exports.createDecipheriv = createDecipheriv
  4977. }).call(this,require("buffer").Buffer)
  4978. },{"./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){
  4979. (function (Buffer){
  4980. var aes = require('./aes')
  4981. var Transform = require('cipher-base')
  4982. var inherits = require('inherits')
  4983. var modes = require('./modes')
  4984. var ebtk = require('evp_bytestokey')
  4985. var StreamCipher = require('./streamCipher')
  4986. var AuthCipher = require('./authCipher')
  4987. inherits(Cipher, Transform)
  4988. function Cipher (mode, key, iv) {
  4989. if (!(this instanceof Cipher)) {
  4990. return new Cipher(mode, key, iv)
  4991. }
  4992. Transform.call(this)
  4993. this._cache = new Splitter()
  4994. this._cipher = new aes.AES(key)
  4995. this._prev = new Buffer(iv.length)
  4996. iv.copy(this._prev)
  4997. this._mode = mode
  4998. this._autopadding = true
  4999. }
  5000. Cipher.prototype._update = function (data) {
  5001. this._cache.add(data)
  5002. var chunk
  5003. var thing
  5004. var out = []
  5005. while ((chunk = this._cache.get())) {
  5006. thing = this._mode.encrypt(this, chunk)
  5007. out.push(thing)
  5008. }
  5009. return Buffer.concat(out)
  5010. }
  5011. Cipher.prototype._final = function () {
  5012. var chunk = this._cache.flush()
  5013. if (this._autopadding) {
  5014. chunk = this._mode.encrypt(this, chunk)
  5015. this._cipher.scrub()
  5016. return chunk
  5017. } else if (chunk.toString('hex') !== '10101010101010101010101010101010') {
  5018. this._cipher.scrub()
  5019. throw new Error('data not multiple of block length')
  5020. }
  5021. }
  5022. Cipher.prototype.setAutoPadding = function (setTo) {
  5023. this._autopadding = !!setTo
  5024. return this
  5025. }
  5026. function Splitter () {
  5027. if (!(this instanceof Splitter)) {
  5028. return new Splitter()
  5029. }
  5030. this.cache = new Buffer('')
  5031. }
  5032. Splitter.prototype.add = function (data) {
  5033. this.cache = Buffer.concat([this.cache, data])
  5034. }
  5035. Splitter.prototype.get = function () {
  5036. if (this.cache.length > 15) {
  5037. var out = this.cache.slice(0, 16)
  5038. this.cache = this.cache.slice(16)
  5039. return out
  5040. }
  5041. return null
  5042. }
  5043. Splitter.prototype.flush = function () {
  5044. var len = 16 - this.cache.length
  5045. var padBuff = new Buffer(len)
  5046. var i = -1
  5047. while (++i < len) {
  5048. padBuff.writeUInt8(len, i)
  5049. }
  5050. var out = Buffer.concat([this.cache, padBuff])
  5051. return out
  5052. }
  5053. var modelist = {
  5054. ECB: require('./modes/ecb'),
  5055. CBC: require('./modes/cbc'),
  5056. CFB: require('./modes/cfb'),
  5057. CFB8: require('./modes/cfb8'),
  5058. CFB1: require('./modes/cfb1'),
  5059. OFB: require('./modes/ofb'),
  5060. CTR: require('./modes/ctr'),
  5061. GCM: require('./modes/ctr')
  5062. }
  5063. function createCipheriv (suite, password, iv) {
  5064. var config = modes[suite.toLowerCase()]
  5065. if (!config) {
  5066. throw new TypeError('invalid suite type')
  5067. }
  5068. if (typeof iv === 'string') {
  5069. iv = new Buffer(iv)
  5070. }
  5071. if (typeof password === 'string') {
  5072. password = new Buffer(password)
  5073. }
  5074. if (password.length !== config.key / 8) {
  5075. throw new TypeError('invalid key length ' + password.length)
  5076. }
  5077. if (iv.length !== config.iv) {
  5078. throw new TypeError('invalid iv length ' + iv.length)
  5079. }
  5080. if (config.type === 'stream') {
  5081. return new StreamCipher(modelist[config.mode], password, iv)
  5082. } else if (config.type === 'auth') {
  5083. return new AuthCipher(modelist[config.mode], password, iv)
  5084. }
  5085. return new Cipher(modelist[config.mode], password, iv)
  5086. }
  5087. function createCipher (suite, password) {
  5088. var config = modes[suite.toLowerCase()]
  5089. if (!config) {
  5090. throw new TypeError('invalid suite type')
  5091. }
  5092. var keys = ebtk(password, false, config.key, config.iv)
  5093. return createCipheriv(suite, keys.key, keys.iv)
  5094. }
  5095. exports.createCipheriv = createCipheriv
  5096. exports.createCipher = createCipher
  5097. }).call(this,require("buffer").Buffer)
  5098. },{"./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){
  5099. (function (Buffer){
  5100. var zeros = new Buffer(16)
  5101. zeros.fill(0)
  5102. module.exports = GHASH
  5103. function GHASH (key) {
  5104. this.h = key
  5105. this.state = new Buffer(16)
  5106. this.state.fill(0)
  5107. this.cache = new Buffer('')
  5108. }
  5109. // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  5110. // by Juho Vähä-Herttua
  5111. GHASH.prototype.ghash = function (block) {
  5112. var i = -1
  5113. while (++i < block.length) {
  5114. this.state[i] ^= block[i]
  5115. }
  5116. this._multiply()
  5117. }
  5118. GHASH.prototype._multiply = function () {
  5119. var Vi = toArray(this.h)
  5120. var Zi = [0, 0, 0, 0]
  5121. var j, xi, lsb_Vi
  5122. var i = -1
  5123. while (++i < 128) {
  5124. xi = (this.state[~~(i / 8)] & (1 << (7 - i % 8))) !== 0
  5125. if (xi) {
  5126. // Z_i+1 = Z_i ^ V_i
  5127. Zi = xor(Zi, Vi)
  5128. }
  5129. // Store the value of LSB(V_i)
  5130. lsb_Vi = (Vi[3] & 1) !== 0
  5131. // V_i+1 = V_i >> 1
  5132. for (j = 3; j > 0; j--) {
  5133. Vi[j] = (Vi[j] >>> 1) | ((Vi[j - 1] & 1) << 31)
  5134. }
  5135. Vi[0] = Vi[0] >>> 1
  5136. // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  5137. if (lsb_Vi) {
  5138. Vi[0] = Vi[0] ^ (0xe1 << 24)
  5139. }
  5140. }
  5141. this.state = fromArray(Zi)
  5142. }
  5143. GHASH.prototype.update = function (buf) {
  5144. this.cache = Buffer.concat([this.cache, buf])
  5145. var chunk
  5146. while (this.cache.length >= 16) {
  5147. chunk = this.cache.slice(0, 16)
  5148. this.cache = this.cache.slice(16)
  5149. this.ghash(chunk)
  5150. }
  5151. }
  5152. GHASH.prototype.final = function (abl, bl) {
  5153. if (this.cache.length) {
  5154. this.ghash(Buffer.concat([this.cache, zeros], 16))
  5155. }
  5156. this.ghash(fromArray([
  5157. 0, abl,
  5158. 0, bl
  5159. ]))
  5160. return this.state
  5161. }
  5162. function toArray (buf) {
  5163. return [
  5164. buf.readUInt32BE(0),
  5165. buf.readUInt32BE(4),
  5166. buf.readUInt32BE(8),
  5167. buf.readUInt32BE(12)
  5168. ]
  5169. }
  5170. function fromArray (out) {
  5171. out = out.map(fixup_uint32)
  5172. var buf = new Buffer(16)
  5173. buf.writeUInt32BE(out[0], 0)
  5174. buf.writeUInt32BE(out[1], 4)
  5175. buf.writeUInt32BE(out[2], 8)
  5176. buf.writeUInt32BE(out[3], 12)
  5177. return buf
  5178. }
  5179. var uint_max = Math.pow(2, 32)
  5180. function fixup_uint32 (x) {
  5181. var ret, x_pos
  5182. ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x
  5183. return ret
  5184. }
  5185. function xor (a, b) {
  5186. return [
  5187. a[0] ^ b[0],
  5188. a[1] ^ b[1],
  5189. a[2] ^ b[2],
  5190. a[3] ^ b[3]
  5191. ]
  5192. }
  5193. }).call(this,require("buffer").Buffer)
  5194. },{"buffer":46}],27:[function(require,module,exports){
  5195. exports['aes-128-ecb'] = {
  5196. cipher: 'AES',
  5197. key: 128,
  5198. iv: 0,
  5199. mode: 'ECB',
  5200. type: 'block'
  5201. }
  5202. exports['aes-192-ecb'] = {
  5203. cipher: 'AES',
  5204. key: 192,
  5205. iv: 0,
  5206. mode: 'ECB',
  5207. type: 'block'
  5208. }
  5209. exports['aes-256-ecb'] = {
  5210. cipher: 'AES',
  5211. key: 256,
  5212. iv: 0,
  5213. mode: 'ECB',
  5214. type: 'block'
  5215. }
  5216. exports['aes-128-cbc'] = {
  5217. cipher: 'AES',
  5218. key: 128,
  5219. iv: 16,
  5220. mode: 'CBC',
  5221. type: 'block'
  5222. }
  5223. exports['aes-192-cbc'] = {
  5224. cipher: 'AES',
  5225. key: 192,
  5226. iv: 16,
  5227. mode: 'CBC',
  5228. type: 'block'
  5229. }
  5230. exports['aes-256-cbc'] = {
  5231. cipher: 'AES',
  5232. key: 256,
  5233. iv: 16,
  5234. mode: 'CBC',
  5235. type: 'block'
  5236. }
  5237. exports['aes128'] = exports['aes-128-cbc']
  5238. exports['aes192'] = exports['aes-192-cbc']
  5239. exports['aes256'] = exports['aes-256-cbc']
  5240. exports['aes-128-cfb'] = {
  5241. cipher: 'AES',
  5242. key: 128,
  5243. iv: 16,
  5244. mode: 'CFB',
  5245. type: 'stream'
  5246. }
  5247. exports['aes-192-cfb'] = {
  5248. cipher: 'AES',
  5249. key: 192,
  5250. iv: 16,
  5251. mode: 'CFB',
  5252. type: 'stream'
  5253. }
  5254. exports['aes-256-cfb'] = {
  5255. cipher: 'AES',
  5256. key: 256,
  5257. iv: 16,
  5258. mode: 'CFB',
  5259. type: 'stream'
  5260. }
  5261. exports['aes-128-cfb8'] = {
  5262. cipher: 'AES',
  5263. key: 128,
  5264. iv: 16,
  5265. mode: 'CFB8',
  5266. type: 'stream'
  5267. }
  5268. exports['aes-192-cfb8'] = {
  5269. cipher: 'AES',
  5270. key: 192,
  5271. iv: 16,
  5272. mode: 'CFB8',
  5273. type: 'stream'
  5274. }
  5275. exports['aes-256-cfb8'] = {
  5276. cipher: 'AES',
  5277. key: 256,
  5278. iv: 16,
  5279. mode: 'CFB8',
  5280. type: 'stream'
  5281. }
  5282. exports['aes-128-cfb1'] = {
  5283. cipher: 'AES',
  5284. key: 128,
  5285. iv: 16,
  5286. mode: 'CFB1',
  5287. type: 'stream'
  5288. }
  5289. exports['aes-192-cfb1'] = {
  5290. cipher: 'AES',
  5291. key: 192,
  5292. iv: 16,
  5293. mode: 'CFB1',
  5294. type: 'stream'
  5295. }
  5296. exports['aes-256-cfb1'] = {
  5297. cipher: 'AES',
  5298. key: 256,
  5299. iv: 16,
  5300. mode: 'CFB1',
  5301. type: 'stream'
  5302. }
  5303. exports['aes-128-ofb'] = {
  5304. cipher: 'AES',
  5305. key: 128,
  5306. iv: 16,
  5307. mode: 'OFB',
  5308. type: 'stream'
  5309. }
  5310. exports['aes-192-ofb'] = {
  5311. cipher: 'AES',
  5312. key: 192,
  5313. iv: 16,
  5314. mode: 'OFB',
  5315. type: 'stream'
  5316. }
  5317. exports['aes-256-ofb'] = {
  5318. cipher: 'AES',
  5319. key: 256,
  5320. iv: 16,
  5321. mode: 'OFB',
  5322. type: 'stream'
  5323. }
  5324. exports['aes-128-ctr'] = {
  5325. cipher: 'AES',
  5326. key: 128,
  5327. iv: 16,
  5328. mode: 'CTR',
  5329. type: 'stream'
  5330. }
  5331. exports['aes-192-ctr'] = {
  5332. cipher: 'AES',
  5333. key: 192,
  5334. iv: 16,
  5335. mode: 'CTR',
  5336. type: 'stream'
  5337. }
  5338. exports['aes-256-ctr'] = {
  5339. cipher: 'AES',
  5340. key: 256,
  5341. iv: 16,
  5342. mode: 'CTR',
  5343. type: 'stream'
  5344. }
  5345. exports['aes-128-gcm'] = {
  5346. cipher: 'AES',
  5347. key: 128,
  5348. iv: 12,
  5349. mode: 'GCM',
  5350. type: 'auth'
  5351. }
  5352. exports['aes-192-gcm'] = {
  5353. cipher: 'AES',
  5354. key: 192,
  5355. iv: 12,
  5356. mode: 'GCM',
  5357. type: 'auth'
  5358. }
  5359. exports['aes-256-gcm'] = {
  5360. cipher: 'AES',
  5361. key: 256,
  5362. iv: 12,
  5363. mode: 'GCM',
  5364. type: 'auth'
  5365. }
  5366. },{}],28:[function(require,module,exports){
  5367. var xor = require('buffer-xor')
  5368. exports.encrypt = function (self, block) {
  5369. var data = xor(block, self._prev)
  5370. self._prev = self._cipher.encryptBlock(data)
  5371. return self._prev
  5372. }
  5373. exports.decrypt = function (self, block) {
  5374. var pad = self._prev
  5375. self._prev = block
  5376. var out = self._cipher.decryptBlock(block)
  5377. return xor(out, pad)
  5378. }
  5379. },{"buffer-xor":45}],29:[function(require,module,exports){
  5380. (function (Buffer){
  5381. var xor = require('buffer-xor')
  5382. exports.encrypt = function (self, data, decrypt) {
  5383. var out = new Buffer('')
  5384. var len
  5385. while (data.length) {
  5386. if (self._cache.length === 0) {
  5387. self._cache = self._cipher.encryptBlock(self._prev)
  5388. self._prev = new Buffer('')
  5389. }
  5390. if (self._cache.length <= data.length) {
  5391. len = self._cache.length
  5392. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
  5393. data = data.slice(len)
  5394. } else {
  5395. out = Buffer.concat([out, encryptStart(self, data, decrypt)])
  5396. break
  5397. }
  5398. }
  5399. return out
  5400. }
  5401. function encryptStart (self, data, decrypt) {
  5402. var len = data.length
  5403. var out = xor(data, self._cache)
  5404. self._cache = self._cache.slice(len)
  5405. self._prev = Buffer.concat([self._prev, decrypt ? data : out])
  5406. return out
  5407. }
  5408. }).call(this,require("buffer").Buffer)
  5409. },{"buffer":46,"buffer-xor":45}],30:[function(require,module,exports){
  5410. (function (Buffer){
  5411. function encryptByte (self, byteParam, decrypt) {
  5412. var pad
  5413. var i = -1
  5414. var len = 8
  5415. var out = 0
  5416. var bit, value
  5417. while (++i < len) {
  5418. pad = self._cipher.encryptBlock(self._prev)
  5419. bit = (byteParam & (1 << (7 - i))) ? 0x80 : 0
  5420. value = pad[0] ^ bit
  5421. out += ((value & 0x80) >> (i % 8))
  5422. self._prev = shiftIn(self._prev, decrypt ? bit : value)
  5423. }
  5424. return out
  5425. }
  5426. exports.encrypt = function (self, chunk, decrypt) {
  5427. var len = chunk.length
  5428. var out = new Buffer(len)
  5429. var i = -1
  5430. while (++i < len) {
  5431. out[i] = encryptByte(self, chunk[i], decrypt)
  5432. }
  5433. return out
  5434. }
  5435. function shiftIn (buffer, value) {
  5436. var len = buffer.length
  5437. var i = -1
  5438. var out = new Buffer(buffer.length)
  5439. buffer = Buffer.concat([buffer, new Buffer([value])])
  5440. while (++i < len) {
  5441. out[i] = buffer[i] << 1 | buffer[i + 1] >> (7)
  5442. }
  5443. return out
  5444. }
  5445. }).call(this,require("buffer").Buffer)
  5446. },{"buffer":46}],31:[function(require,module,exports){
  5447. (function (Buffer){
  5448. function encryptByte (self, byteParam, decrypt) {
  5449. var pad = self._cipher.encryptBlock(self._prev)
  5450. var out = pad[0] ^ byteParam
  5451. self._prev = Buffer.concat([self._prev.slice(1), new Buffer([decrypt ? byteParam : out])])
  5452. return out
  5453. }
  5454. exports.encrypt = function (self, chunk, decrypt) {
  5455. var len = chunk.length
  5456. var out = new Buffer(len)
  5457. var i = -1
  5458. while (++i < len) {
  5459. out[i] = encryptByte(self, chunk[i], decrypt)
  5460. }
  5461. return out
  5462. }
  5463. }).call(this,require("buffer").Buffer)
  5464. },{"buffer":46}],32:[function(require,module,exports){
  5465. (function (Buffer){
  5466. var xor = require('buffer-xor')
  5467. function incr32 (iv) {
  5468. var len = iv.length
  5469. var item
  5470. while (len--) {
  5471. item = iv.readUInt8(len)
  5472. if (item === 255) {
  5473. iv.writeUInt8(0, len)
  5474. } else {
  5475. item++
  5476. iv.writeUInt8(item, len)
  5477. break
  5478. }
  5479. }
  5480. }
  5481. function getBlock (self) {
  5482. var out = self._cipher.encryptBlock(self._prev)
  5483. incr32(self._prev)
  5484. return out
  5485. }
  5486. exports.encrypt = function (self, chunk) {
  5487. while (self._cache.length < chunk.length) {
  5488. self._cache = Buffer.concat([self._cache, getBlock(self)])
  5489. }
  5490. var pad = self._cache.slice(0, chunk.length)
  5491. self._cache = self._cache.slice(chunk.length)
  5492. return xor(chunk, pad)
  5493. }
  5494. }).call(this,require("buffer").Buffer)
  5495. },{"buffer":46,"buffer-xor":45}],33:[function(require,module,exports){
  5496. exports.encrypt = function (self, block) {
  5497. return self._cipher.encryptBlock(block)
  5498. }
  5499. exports.decrypt = function (self, block) {
  5500. return self._cipher.decryptBlock(block)
  5501. }
  5502. },{}],34:[function(require,module,exports){
  5503. (function (Buffer){
  5504. var xor = require('buffer-xor')
  5505. function getBlock (self) {
  5506. self._prev = self._cipher.encryptBlock(self._prev)
  5507. return self._prev
  5508. }
  5509. exports.encrypt = function (self, chunk) {
  5510. while (self._cache.length < chunk.length) {
  5511. self._cache = Buffer.concat([self._cache, getBlock(self)])
  5512. }
  5513. var pad = self._cache.slice(0, chunk.length)
  5514. self._cache = self._cache.slice(chunk.length)
  5515. return xor(chunk, pad)
  5516. }
  5517. }).call(this,require("buffer").Buffer)
  5518. },{"buffer":46,"buffer-xor":45}],35:[function(require,module,exports){
  5519. (function (Buffer){
  5520. var aes = require('./aes')
  5521. var Transform = require('cipher-base')
  5522. var inherits = require('inherits')
  5523. inherits(StreamCipher, Transform)
  5524. module.exports = StreamCipher
  5525. function StreamCipher (mode, key, iv, decrypt) {
  5526. if (!(this instanceof StreamCipher)) {
  5527. return new StreamCipher(mode, key, iv)
  5528. }
  5529. Transform.call(this)
  5530. this._cipher = new aes.AES(key)
  5531. this._prev = new Buffer(iv.length)
  5532. this._cache = new Buffer('')
  5533. this._secCache = new Buffer('')
  5534. this._decrypt = decrypt
  5535. iv.copy(this._prev)
  5536. this._mode = mode
  5537. }
  5538. StreamCipher.prototype._update = function (chunk) {
  5539. return this._mode.encrypt(this, chunk, this._decrypt)
  5540. }
  5541. StreamCipher.prototype._final = function () {
  5542. this._cipher.scrub()
  5543. }
  5544. }).call(this,require("buffer").Buffer)
  5545. },{"./aes":21,"buffer":46,"cipher-base":47,"inherits":92}],36:[function(require,module,exports){
  5546. var ebtk = require('evp_bytestokey')
  5547. var aes = require('browserify-aes/browser')
  5548. var DES = require('browserify-des')
  5549. var desModes = require('browserify-des/modes')
  5550. var aesModes = require('browserify-aes/modes')
  5551. function createCipher (suite, password) {
  5552. var keyLen, ivLen
  5553. suite = suite.toLowerCase()
  5554. if (aesModes[suite]) {
  5555. keyLen = aesModes[suite].key
  5556. ivLen = aesModes[suite].iv
  5557. } else if (desModes[suite]) {
  5558. keyLen = desModes[suite].key * 8
  5559. ivLen = desModes[suite].iv
  5560. } else {
  5561. throw new TypeError('invalid suite type')
  5562. }
  5563. var keys = ebtk(password, false, keyLen, ivLen)
  5564. return createCipheriv(suite, keys.key, keys.iv)
  5565. }
  5566. function createDecipher (suite, password) {
  5567. var keyLen, ivLen
  5568. suite = suite.toLowerCase()
  5569. if (aesModes[suite]) {
  5570. keyLen = aesModes[suite].key
  5571. ivLen = aesModes[suite].iv
  5572. } else if (desModes[suite]) {
  5573. keyLen = desModes[suite].key * 8
  5574. ivLen = desModes[suite].iv
  5575. } else {
  5576. throw new TypeError('invalid suite type')
  5577. }
  5578. var keys = ebtk(password, false, keyLen, ivLen)
  5579. return createDecipheriv(suite, keys.key, keys.iv)
  5580. }
  5581. function createCipheriv (suite, key, iv) {
  5582. suite = suite.toLowerCase()
  5583. if (aesModes[suite]) {
  5584. return aes.createCipheriv(suite, key, iv)
  5585. } else if (desModes[suite]) {
  5586. return new DES({
  5587. key: key,
  5588. iv: iv,
  5589. mode: suite
  5590. })
  5591. } else {
  5592. throw new TypeError('invalid suite type')
  5593. }
  5594. }
  5595. function createDecipheriv (suite, key, iv) {
  5596. suite = suite.toLowerCase()
  5597. if (aesModes[suite]) {
  5598. return aes.createDecipheriv(suite, key, iv)
  5599. } else if (desModes[suite]) {
  5600. return new DES({
  5601. key: key,
  5602. iv: iv,
  5603. mode: suite,
  5604. decrypt: true
  5605. })
  5606. } else {
  5607. throw new TypeError('invalid suite type')
  5608. }
  5609. }
  5610. exports.createCipher = exports.Cipher = createCipher
  5611. exports.createCipheriv = exports.Cipheriv = createCipheriv
  5612. exports.createDecipher = exports.Decipher = createDecipher
  5613. exports.createDecipheriv = exports.Decipheriv = createDecipheriv
  5614. function getCiphers () {
  5615. return Object.keys(desModes).concat(aes.getCiphers())
  5616. }
  5617. exports.listCiphers = exports.getCiphers = getCiphers
  5618. },{"browserify-aes/browser":23,"browserify-aes/modes":27,"browserify-des":37,"browserify-des/modes":38,"evp_bytestokey":83}],37:[function(require,module,exports){
  5619. (function (Buffer){
  5620. var CipherBase = require('cipher-base')
  5621. var des = require('des.js')
  5622. var inherits = require('inherits')
  5623. var modes = {
  5624. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  5625. 'des-ede3': des.EDE,
  5626. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  5627. 'des-ede': des.EDE,
  5628. 'des-cbc': des.CBC.instantiate(des.DES),
  5629. 'des-ecb': des.DES
  5630. }
  5631. modes.des = modes['des-cbc']
  5632. modes.des3 = modes['des-ede3-cbc']
  5633. module.exports = DES
  5634. inherits(DES, CipherBase)
  5635. function DES (opts) {
  5636. CipherBase.call(this)
  5637. var modeName = opts.mode.toLowerCase()
  5638. var mode = modes[modeName]
  5639. var type
  5640. if (opts.decrypt) {
  5641. type = 'decrypt'
  5642. } else {
  5643. type = 'encrypt'
  5644. }
  5645. var key = opts.key
  5646. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  5647. key = Buffer.concat([key, key.slice(0, 8)])
  5648. }
  5649. var iv = opts.iv
  5650. this._des = mode.create({
  5651. key: key,
  5652. iv: iv,
  5653. type: type
  5654. })
  5655. }
  5656. DES.prototype._update = function (data) {
  5657. return new Buffer(this._des.update(data))
  5658. }
  5659. DES.prototype._final = function () {
  5660. return new Buffer(this._des.final())
  5661. }
  5662. }).call(this,require("buffer").Buffer)
  5663. },{"buffer":46,"cipher-base":47,"des.js":55,"inherits":92}],38:[function(require,module,exports){
  5664. exports['des-ecb'] = {
  5665. key: 8,
  5666. iv: 0
  5667. }
  5668. exports['des-cbc'] = exports.des = {
  5669. key: 8,
  5670. iv: 8
  5671. }
  5672. exports['des-ede3-cbc'] = exports.des3 = {
  5673. key: 24,
  5674. iv: 8
  5675. }
  5676. exports['des-ede3'] = {
  5677. key: 24,
  5678. iv: 0
  5679. }
  5680. exports['des-ede-cbc'] = {
  5681. key: 16,
  5682. iv: 8
  5683. }
  5684. exports['des-ede'] = {
  5685. key: 16,
  5686. iv: 0
  5687. }
  5688. },{}],39:[function(require,module,exports){
  5689. (function (Buffer){
  5690. var bn = require('bn.js');
  5691. var randomBytes = require('randombytes');
  5692. module.exports = crt;
  5693. function blind(priv) {
  5694. var r = getr(priv);
  5695. var blinder = r.toRed(bn.mont(priv.modulus))
  5696. .redPow(new bn(priv.publicExponent)).fromRed();
  5697. return {
  5698. blinder: blinder,
  5699. unblinder:r.invm(priv.modulus)
  5700. };
  5701. }
  5702. function crt(msg, priv) {
  5703. var blinds = blind(priv);
  5704. var len = priv.modulus.byteLength();
  5705. var mod = bn.mont(priv.modulus);
  5706. var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
  5707. var c1 = blinded.toRed(bn.mont(priv.prime1));
  5708. var c2 = blinded.toRed(bn.mont(priv.prime2));
  5709. var qinv = priv.coefficient;
  5710. var p = priv.prime1;
  5711. var q = priv.prime2;
  5712. var m1 = c1.redPow(priv.exponent1);
  5713. var m2 = c2.redPow(priv.exponent2);
  5714. m1 = m1.fromRed();
  5715. m2 = m2.fromRed();
  5716. var h = m1.isub(m2).imul(qinv).umod(p);
  5717. h.imul(q);
  5718. m2.iadd(h);
  5719. return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
  5720. }
  5721. crt.getr = getr;
  5722. function getr(priv) {
  5723. var len = priv.modulus.byteLength();
  5724. var r = new bn(randomBytes(len));
  5725. while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
  5726. r = new bn(randomBytes(len));
  5727. }
  5728. return r;
  5729. }
  5730. }).call(this,require("buffer").Buffer)
  5731. },{"bn.js":18,"buffer":46,"randombytes":117}],40:[function(require,module,exports){
  5732. (function (Buffer){
  5733. 'use strict'
  5734. exports['RSA-SHA224'] = exports.sha224WithRSAEncryption = {
  5735. sign: 'rsa',
  5736. hash: 'sha224',
  5737. id: new Buffer('302d300d06096086480165030402040500041c', 'hex')
  5738. }
  5739. exports['RSA-SHA256'] = exports.sha256WithRSAEncryption = {
  5740. sign: 'rsa',
  5741. hash: 'sha256',
  5742. id: new Buffer('3031300d060960864801650304020105000420', 'hex')
  5743. }
  5744. exports['RSA-SHA384'] = exports.sha384WithRSAEncryption = {
  5745. sign: 'rsa',
  5746. hash: 'sha384',
  5747. id: new Buffer('3041300d060960864801650304020205000430', 'hex')
  5748. }
  5749. exports['RSA-SHA512'] = exports.sha512WithRSAEncryption = {
  5750. sign: 'rsa',
  5751. hash: 'sha512',
  5752. id: new Buffer('3051300d060960864801650304020305000440', 'hex')
  5753. }
  5754. exports['RSA-SHA1'] = {
  5755. sign: 'rsa',
  5756. hash: 'sha1',
  5757. id: new Buffer('3021300906052b0e03021a05000414', 'hex')
  5758. }
  5759. exports['ecdsa-with-SHA1'] = {
  5760. sign: 'ecdsa',
  5761. hash: 'sha1',
  5762. id: new Buffer('', 'hex')
  5763. }
  5764. exports.DSA = exports['DSA-SHA1'] = exports['DSA-SHA'] = {
  5765. sign: 'dsa',
  5766. hash: 'sha1',
  5767. id: new Buffer('', 'hex')
  5768. }
  5769. exports['DSA-SHA224'] = exports['DSA-WITH-SHA224'] = {
  5770. sign: 'dsa',
  5771. hash: 'sha224',
  5772. id: new Buffer('', 'hex')
  5773. }
  5774. exports['DSA-SHA256'] = exports['DSA-WITH-SHA256'] = {
  5775. sign: 'dsa',
  5776. hash: 'sha256',
  5777. id: new Buffer('', 'hex')
  5778. }
  5779. exports['DSA-SHA384'] = exports['DSA-WITH-SHA384'] = {
  5780. sign: 'dsa',
  5781. hash: 'sha384',
  5782. id: new Buffer('', 'hex')
  5783. }
  5784. exports['DSA-SHA512'] = exports['DSA-WITH-SHA512'] = {
  5785. sign: 'dsa',
  5786. hash: 'sha512',
  5787. id: new Buffer('', 'hex')
  5788. }
  5789. exports['DSA-RIPEMD160'] = {
  5790. sign: 'dsa',
  5791. hash: 'rmd160',
  5792. id: new Buffer('', 'hex')
  5793. }
  5794. exports['RSA-RIPEMD160'] = exports.ripemd160WithRSA = {
  5795. sign: 'rsa',
  5796. hash: 'rmd160',
  5797. id: new Buffer('3021300906052b2403020105000414', 'hex')
  5798. }
  5799. exports['RSA-MD5'] = exports.md5WithRSAEncryption = {
  5800. sign: 'rsa',
  5801. hash: 'md5',
  5802. id: new Buffer('3020300c06082a864886f70d020505000410', 'hex')
  5803. }
  5804. }).call(this,require("buffer").Buffer)
  5805. },{"buffer":46}],41:[function(require,module,exports){
  5806. (function (Buffer){
  5807. var _algos = require('./algos')
  5808. var createHash = require('create-hash')
  5809. var inherits = require('inherits')
  5810. var sign = require('./sign')
  5811. var stream = require('stream')
  5812. var verify = require('./verify')
  5813. var algos = {}
  5814. Object.keys(_algos).forEach(function (key) {
  5815. algos[key] = algos[key.toLowerCase()] = _algos[key]
  5816. })
  5817. function Sign (algorithm) {
  5818. stream.Writable.call(this)
  5819. var data = algos[algorithm]
  5820. if (!data) {
  5821. throw new Error('Unknown message digest')
  5822. }
  5823. this._hashType = data.hash
  5824. this._hash = createHash(data.hash)
  5825. this._tag = data.id
  5826. this._signType = data.sign
  5827. }
  5828. inherits(Sign, stream.Writable)
  5829. Sign.prototype._write = function _write (data, _, done) {
  5830. this._hash.update(data)
  5831. done()
  5832. }
  5833. Sign.prototype.update = function update (data, enc) {
  5834. if (typeof data === 'string') {
  5835. data = new Buffer(data, enc)
  5836. }
  5837. this._hash.update(data)
  5838. return this
  5839. }
  5840. Sign.prototype.sign = function signMethod (key, enc) {
  5841. this.end()
  5842. var hash = this._hash.digest()
  5843. var sig = sign(Buffer.concat([this._tag, hash]), key, this._hashType, this._signType)
  5844. return enc ? sig.toString(enc) : sig
  5845. }
  5846. function Verify (algorithm) {
  5847. stream.Writable.call(this)
  5848. var data = algos[algorithm]
  5849. if (!data) {
  5850. throw new Error('Unknown message digest')
  5851. }
  5852. this._hash = createHash(data.hash)
  5853. this._tag = data.id
  5854. this._signType = data.sign
  5855. }
  5856. inherits(Verify, stream.Writable)
  5857. Verify.prototype._write = function _write (data, _, done) {
  5858. this._hash.update(data)
  5859. done()
  5860. }
  5861. Verify.prototype.update = function update (data, enc) {
  5862. if (typeof data === 'string') {
  5863. data = new Buffer(data, enc)
  5864. }
  5865. this._hash.update(data)
  5866. return this
  5867. }
  5868. Verify.prototype.verify = function verifyMethod (key, sig, enc) {
  5869. if (typeof sig === 'string') {
  5870. sig = new Buffer(sig, enc)
  5871. }
  5872. this.end()
  5873. var hash = this._hash.digest()
  5874. return verify(sig, Buffer.concat([this._tag, hash]), key, this._signType)
  5875. }
  5876. function createSign (algorithm) {
  5877. return new Sign(algorithm)
  5878. }
  5879. function createVerify (algorithm) {
  5880. return new Verify(algorithm)
  5881. }
  5882. module.exports = {
  5883. Sign: createSign,
  5884. Verify: createVerify,
  5885. createSign: createSign,
  5886. createVerify: createVerify
  5887. }
  5888. }).call(this,require("buffer").Buffer)
  5889. },{"./algos":40,"./sign":43,"./verify":44,"buffer":46,"create-hash":50,"inherits":92,"stream":137}],42:[function(require,module,exports){
  5890. 'use strict'
  5891. exports['1.3.132.0.10'] = 'secp256k1'
  5892. exports['1.3.132.0.33'] = 'p224'
  5893. exports['1.2.840.10045.3.1.1'] = 'p192'
  5894. exports['1.2.840.10045.3.1.7'] = 'p256'
  5895. exports['1.3.132.0.34'] = 'p384'
  5896. exports['1.3.132.0.35'] = 'p521'
  5897. },{}],43:[function(require,module,exports){
  5898. (function (Buffer){
  5899. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  5900. var createHmac = require('create-hmac')
  5901. var crt = require('browserify-rsa')
  5902. var curves = require('./curves')
  5903. var elliptic = require('elliptic')
  5904. var parseKeys = require('parse-asn1')
  5905. var BN = require('bn.js')
  5906. var EC = elliptic.ec
  5907. function sign (hash, key, hashType, signType) {
  5908. var priv = parseKeys(key)
  5909. if (priv.curve) {
  5910. if (signType !== 'ecdsa') throw new Error('wrong private key type')
  5911. return ecSign(hash, priv)
  5912. } else if (priv.type === 'dsa') {
  5913. if (signType !== 'dsa') {
  5914. throw new Error('wrong private key type')
  5915. }
  5916. return dsaSign(hash, priv, hashType)
  5917. } else {
  5918. if (signType !== 'rsa') throw new Error('wrong private key type')
  5919. }
  5920. var len = priv.modulus.byteLength()
  5921. var pad = [ 0, 1 ]
  5922. while (hash.length + pad.length + 1 < len) {
  5923. pad.push(0xff)
  5924. }
  5925. pad.push(0x00)
  5926. var i = -1
  5927. while (++i < hash.length) {
  5928. pad.push(hash[i])
  5929. }
  5930. var out = crt(pad, priv)
  5931. return out
  5932. }
  5933. function ecSign (hash, priv) {
  5934. var curveId = curves[priv.curve.join('.')]
  5935. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'))
  5936. var curve = new EC(curveId)
  5937. var key = curve.genKeyPair()
  5938. key._importPrivate(priv.privateKey)
  5939. var out = key.sign(hash)
  5940. return new Buffer(out.toDER())
  5941. }
  5942. function dsaSign (hash, priv, algo) {
  5943. var x = priv.params.priv_key
  5944. var p = priv.params.p
  5945. var q = priv.params.q
  5946. var g = priv.params.g
  5947. var r = new BN(0)
  5948. var k
  5949. var H = bits2int(hash, q).mod(q)
  5950. var s = false
  5951. var kv = getKey(x, q, hash, algo)
  5952. while (s === false) {
  5953. k = makeKey(q, kv, algo)
  5954. r = makeR(g, k, p, q)
  5955. s = k.invm(q).imul(H.add(x.mul(r))).mod(q)
  5956. if (!s.cmpn(0)) {
  5957. s = false
  5958. r = new BN(0)
  5959. }
  5960. }
  5961. return toDER(r, s)
  5962. }
  5963. function toDER (r, s) {
  5964. r = r.toArray()
  5965. s = s.toArray()
  5966. // Pad values
  5967. if (r[0] & 0x80) {
  5968. r = [ 0 ].concat(r)
  5969. }
  5970. // Pad values
  5971. if (s[0] & 0x80) {
  5972. s = [0].concat(s)
  5973. }
  5974. var total = r.length + s.length + 4
  5975. var res = [ 0x30, total, 0x02, r.length ]
  5976. res = res.concat(r, [ 0x02, s.length ], s)
  5977. return new Buffer(res)
  5978. }
  5979. function getKey (x, q, hash, algo) {
  5980. x = new Buffer(x.toArray())
  5981. if (x.length < q.byteLength()) {
  5982. var zeros = new Buffer(q.byteLength() - x.length)
  5983. zeros.fill(0)
  5984. x = Buffer.concat([zeros, x])
  5985. }
  5986. var hlen = hash.length
  5987. var hbits = bits2octets(hash, q)
  5988. var v = new Buffer(hlen)
  5989. v.fill(1)
  5990. var k = new Buffer(hlen)
  5991. k.fill(0)
  5992. k = createHmac(algo, k)
  5993. .update(v)
  5994. .update(new Buffer([0]))
  5995. .update(x)
  5996. .update(hbits)
  5997. .digest()
  5998. v = createHmac(algo, k)
  5999. .update(v)
  6000. .digest()
  6001. k = createHmac(algo, k)
  6002. .update(v)
  6003. .update(new Buffer([1]))
  6004. .update(x)
  6005. .update(hbits)
  6006. .digest()
  6007. v = createHmac(algo, k)
  6008. .update(v)
  6009. .digest()
  6010. return {
  6011. k: k,
  6012. v: v
  6013. }
  6014. }
  6015. function bits2int (obits, q) {
  6016. var bits = new BN(obits)
  6017. var shift = (obits.length << 3) - q.bitLength()
  6018. if (shift > 0) {
  6019. bits.ishrn(shift)
  6020. }
  6021. return bits
  6022. }
  6023. function bits2octets (bits, q) {
  6024. bits = bits2int(bits, q)
  6025. bits = bits.mod(q)
  6026. var out = new Buffer(bits.toArray())
  6027. if (out.length < q.byteLength()) {
  6028. var zeros = new Buffer(q.byteLength() - out.length)
  6029. zeros.fill(0)
  6030. out = Buffer.concat([zeros, out])
  6031. }
  6032. return out
  6033. }
  6034. function makeKey (q, kv, algo) {
  6035. var t, k
  6036. do {
  6037. t = new Buffer('')
  6038. while (t.length * 8 < q.bitLength()) {
  6039. kv.v = createHmac(algo, kv.k)
  6040. .update(kv.v)
  6041. .digest()
  6042. t = Buffer.concat([t, kv.v])
  6043. }
  6044. k = bits2int(t, q)
  6045. kv.k = createHmac(algo, kv.k)
  6046. .update(kv.v)
  6047. .update(new Buffer([0]))
  6048. .digest()
  6049. kv.v = createHmac(algo, kv.k)
  6050. .update(kv.v)
  6051. .digest()
  6052. } while (k.cmp(q) !== -1)
  6053. return k
  6054. }
  6055. function makeR (g, k, p, q) {
  6056. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q)
  6057. }
  6058. module.exports = sign
  6059. module.exports.getKey = getKey
  6060. module.exports.makeKey = makeKey
  6061. }).call(this,require("buffer").Buffer)
  6062. },{"./curves":42,"bn.js":18,"browserify-rsa":39,"buffer":46,"create-hmac":53,"elliptic":65,"parse-asn1":103}],44:[function(require,module,exports){
  6063. (function (Buffer){
  6064. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  6065. var curves = require('./curves')
  6066. var elliptic = require('elliptic')
  6067. var parseKeys = require('parse-asn1')
  6068. var BN = require('bn.js')
  6069. var EC = elliptic.ec
  6070. function verify (sig, hash, key, signType) {
  6071. var pub = parseKeys(key)
  6072. if (pub.type === 'ec') {
  6073. if (signType !== 'ecdsa') {
  6074. throw new Error('wrong public key type')
  6075. }
  6076. return ecVerify(sig, hash, pub)
  6077. } else if (pub.type === 'dsa') {
  6078. if (signType !== 'dsa') {
  6079. throw new Error('wrong public key type')
  6080. }
  6081. return dsaVerify(sig, hash, pub)
  6082. } else {
  6083. if (signType !== 'rsa') {
  6084. throw new Error('wrong public key type')
  6085. }
  6086. }
  6087. var len = pub.modulus.byteLength()
  6088. var pad = [ 1 ]
  6089. var padNum = 0
  6090. while (hash.length + pad.length + 2 < len) {
  6091. pad.push(0xff)
  6092. padNum++
  6093. }
  6094. pad.push(0x00)
  6095. var i = -1
  6096. while (++i < hash.length) {
  6097. pad.push(hash[i])
  6098. }
  6099. pad = new Buffer(pad)
  6100. var red = BN.mont(pub.modulus)
  6101. sig = new BN(sig).toRed(red)
  6102. sig = sig.redPow(new BN(pub.publicExponent))
  6103. sig = new Buffer(sig.fromRed().toArray())
  6104. var out = 0
  6105. if (padNum < 8) {
  6106. out = 1
  6107. }
  6108. len = Math.min(sig.length, pad.length)
  6109. if (sig.length !== pad.length) {
  6110. out = 1
  6111. }
  6112. i = -1
  6113. while (++i < len) {
  6114. out |= (sig[i] ^ pad[i])
  6115. }
  6116. return out === 0
  6117. }
  6118. function ecVerify (sig, hash, pub) {
  6119. var curveId = curves[pub.data.algorithm.curve.join('.')]
  6120. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'))
  6121. var curve = new EC(curveId)
  6122. var pubkey = pub.data.subjectPrivateKey.data
  6123. return curve.verify(hash, sig, pubkey)
  6124. }
  6125. function dsaVerify (sig, hash, pub) {
  6126. var p = pub.data.p
  6127. var q = pub.data.q
  6128. var g = pub.data.g
  6129. var y = pub.data.pub_key
  6130. var unpacked = parseKeys.signature.decode(sig, 'der')
  6131. var s = unpacked.s
  6132. var r = unpacked.r
  6133. checkValue(s, q)
  6134. checkValue(r, q)
  6135. var montp = BN.mont(p)
  6136. var w = s.invm(q)
  6137. var v = g.toRed(montp)
  6138. .redPow(new BN(hash).mul(w).mod(q))
  6139. .fromRed()
  6140. .mul(
  6141. y.toRed(montp)
  6142. .redPow(r.mul(w).mod(q))
  6143. .fromRed()
  6144. ).mod(p).mod(q)
  6145. return !v.cmp(r)
  6146. }
  6147. function checkValue (b, q) {
  6148. if (b.cmpn(0) <= 0) {
  6149. throw new Error('invalid sig')
  6150. }
  6151. if (b.cmp(q) >= q) {
  6152. throw new Error('invalid sig')
  6153. }
  6154. }
  6155. module.exports = verify
  6156. }).call(this,require("buffer").Buffer)
  6157. },{"./curves":42,"bn.js":18,"buffer":46,"elliptic":65,"parse-asn1":103}],45:[function(require,module,exports){
  6158. (function (Buffer){
  6159. module.exports = function xor (a, b) {
  6160. var length = Math.min(a.length, b.length)
  6161. var buffer = new Buffer(length)
  6162. for (var i = 0; i < length; ++i) {
  6163. buffer[i] = a[i] ^ b[i]
  6164. }
  6165. return buffer
  6166. }
  6167. }).call(this,require("buffer").Buffer)
  6168. },{"buffer":46}],46:[function(require,module,exports){
  6169. (function (global){
  6170. /*!
  6171. * The buffer module from node.js, for the browser.
  6172. *
  6173. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6174. * @license MIT
  6175. */
  6176. /* eslint-disable no-proto */
  6177. 'use strict'
  6178. var base64 = require('base64-js')
  6179. var ieee754 = require('ieee754')
  6180. var isArray = require('isarray')
  6181. exports.Buffer = Buffer
  6182. exports.SlowBuffer = SlowBuffer
  6183. exports.INSPECT_MAX_BYTES = 50
  6184. /**
  6185. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6186. * === true Use Uint8Array implementation (fastest)
  6187. * === false Use Object implementation (most compatible, even IE6)
  6188. *
  6189. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6190. * Opera 11.6+, iOS 4.2+.
  6191. *
  6192. * Due to various browser bugs, sometimes the Object implementation will be used even
  6193. * when the browser supports typed arrays.
  6194. *
  6195. * Note:
  6196. *
  6197. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6198. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6199. *
  6200. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6201. *
  6202. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6203. * incorrect length in some situations.
  6204. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6205. * get the Object implementation, which is slower but behaves correctly.
  6206. */
  6207. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  6208. ? global.TYPED_ARRAY_SUPPORT
  6209. : typedArraySupport()
  6210. /*
  6211. * Export kMaxLength after typed array support is determined.
  6212. */
  6213. exports.kMaxLength = kMaxLength()
  6214. function typedArraySupport () {
  6215. try {
  6216. var arr = new Uint8Array(1)
  6217. arr.foo = function () { return 42 }
  6218. return arr.foo() === 42 && // typed array instances can be augmented
  6219. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  6220. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  6221. } catch (e) {
  6222. return false
  6223. }
  6224. }
  6225. function kMaxLength () {
  6226. return Buffer.TYPED_ARRAY_SUPPORT
  6227. ? 0x7fffffff
  6228. : 0x3fffffff
  6229. }
  6230. function createBuffer (that, length) {
  6231. if (kMaxLength() < length) {
  6232. throw new RangeError('Invalid typed array length')
  6233. }
  6234. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6235. // Return an augmented `Uint8Array` instance, for best performance
  6236. that = new Uint8Array(length)
  6237. that.__proto__ = Buffer.prototype
  6238. } else {
  6239. // Fallback: Return an object instance of the Buffer class
  6240. if (that === null) {
  6241. that = new Buffer(length)
  6242. }
  6243. that.length = length
  6244. }
  6245. return that
  6246. }
  6247. /**
  6248. * The Buffer constructor returns instances of `Uint8Array` that have their
  6249. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6250. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6251. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6252. * returns a single octet.
  6253. *
  6254. * The `Uint8Array` prototype remains unmodified.
  6255. */
  6256. function Buffer (arg, encodingOrOffset, length) {
  6257. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6258. return new Buffer(arg, encodingOrOffset, length)
  6259. }
  6260. // Common case.
  6261. if (typeof arg === 'number') {
  6262. if (typeof encodingOrOffset === 'string') {
  6263. throw new Error(
  6264. 'If encoding is specified then the first argument must be a string'
  6265. )
  6266. }
  6267. return allocUnsafe(this, arg)
  6268. }
  6269. return from(this, arg, encodingOrOffset, length)
  6270. }
  6271. Buffer.poolSize = 8192 // not used by this implementation
  6272. // TODO: Legacy, not needed anymore. Remove in next major version.
  6273. Buffer._augment = function (arr) {
  6274. arr.__proto__ = Buffer.prototype
  6275. return arr
  6276. }
  6277. function from (that, value, encodingOrOffset, length) {
  6278. if (typeof value === 'number') {
  6279. throw new TypeError('"value" argument must not be a number')
  6280. }
  6281. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6282. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6283. }
  6284. if (typeof value === 'string') {
  6285. return fromString(that, value, encodingOrOffset)
  6286. }
  6287. return fromObject(that, value)
  6288. }
  6289. /**
  6290. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6291. * if value is a number.
  6292. * Buffer.from(str[, encoding])
  6293. * Buffer.from(array)
  6294. * Buffer.from(buffer)
  6295. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6296. **/
  6297. Buffer.from = function (value, encodingOrOffset, length) {
  6298. return from(null, value, encodingOrOffset, length)
  6299. }
  6300. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6301. Buffer.prototype.__proto__ = Uint8Array.prototype
  6302. Buffer.__proto__ = Uint8Array
  6303. if (typeof Symbol !== 'undefined' && Symbol.species &&
  6304. Buffer[Symbol.species] === Buffer) {
  6305. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  6306. Object.defineProperty(Buffer, Symbol.species, {
  6307. value: null,
  6308. configurable: true
  6309. })
  6310. }
  6311. }
  6312. function assertSize (size) {
  6313. if (typeof size !== 'number') {
  6314. throw new TypeError('"size" argument must be a number')
  6315. }
  6316. }
  6317. function alloc (that, size, fill, encoding) {
  6318. assertSize(size)
  6319. if (size <= 0) {
  6320. return createBuffer(that, size)
  6321. }
  6322. if (fill !== undefined) {
  6323. // Only pay attention to encoding if it's a string. This
  6324. // prevents accidentally sending in a number that would
  6325. // be interpretted as a start offset.
  6326. return typeof encoding === 'string'
  6327. ? createBuffer(that, size).fill(fill, encoding)
  6328. : createBuffer(that, size).fill(fill)
  6329. }
  6330. return createBuffer(that, size)
  6331. }
  6332. /**
  6333. * Creates a new filled Buffer instance.
  6334. * alloc(size[, fill[, encoding]])
  6335. **/
  6336. Buffer.alloc = function (size, fill, encoding) {
  6337. return alloc(null, size, fill, encoding)
  6338. }
  6339. function allocUnsafe (that, size) {
  6340. assertSize(size)
  6341. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  6342. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6343. for (var i = 0; i < size; i++) {
  6344. that[i] = 0
  6345. }
  6346. }
  6347. return that
  6348. }
  6349. /**
  6350. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6351. * */
  6352. Buffer.allocUnsafe = function (size) {
  6353. return allocUnsafe(null, size)
  6354. }
  6355. /**
  6356. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6357. */
  6358. Buffer.allocUnsafeSlow = function (size) {
  6359. return allocUnsafe(null, size)
  6360. }
  6361. function fromString (that, string, encoding) {
  6362. if (typeof encoding !== 'string' || encoding === '') {
  6363. encoding = 'utf8'
  6364. }
  6365. if (!Buffer.isEncoding(encoding)) {
  6366. throw new TypeError('"encoding" must be a valid string encoding')
  6367. }
  6368. var length = byteLength(string, encoding) | 0
  6369. that = createBuffer(that, length)
  6370. that.write(string, encoding)
  6371. return that
  6372. }
  6373. function fromArrayLike (that, array) {
  6374. var length = checked(array.length) | 0
  6375. that = createBuffer(that, length)
  6376. for (var i = 0; i < length; i += 1) {
  6377. that[i] = array[i] & 255
  6378. }
  6379. return that
  6380. }
  6381. function fromArrayBuffer (that, array, byteOffset, length) {
  6382. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  6383. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6384. throw new RangeError('\'offset\' is out of bounds')
  6385. }
  6386. if (array.byteLength < byteOffset + (length || 0)) {
  6387. throw new RangeError('\'length\' is out of bounds')
  6388. }
  6389. if (length === undefined) {
  6390. array = new Uint8Array(array, byteOffset)
  6391. } else {
  6392. array = new Uint8Array(array, byteOffset, length)
  6393. }
  6394. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6395. // Return an augmented `Uint8Array` instance, for best performance
  6396. that = array
  6397. that.__proto__ = Buffer.prototype
  6398. } else {
  6399. // Fallback: Return an object instance of the Buffer class
  6400. that = fromArrayLike(that, array)
  6401. }
  6402. return that
  6403. }
  6404. function fromObject (that, obj) {
  6405. if (Buffer.isBuffer(obj)) {
  6406. var len = checked(obj.length) | 0
  6407. that = createBuffer(that, len)
  6408. if (that.length === 0) {
  6409. return that
  6410. }
  6411. obj.copy(that, 0, 0, len)
  6412. return that
  6413. }
  6414. if (obj) {
  6415. if ((typeof ArrayBuffer !== 'undefined' &&
  6416. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6417. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6418. return createBuffer(that, 0)
  6419. }
  6420. return fromArrayLike(that, obj)
  6421. }
  6422. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6423. return fromArrayLike(that, obj.data)
  6424. }
  6425. }
  6426. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  6427. }
  6428. function checked (length) {
  6429. // Note: cannot use `length < kMaxLength` here because that fails when
  6430. // length is NaN (which is otherwise coerced to zero.)
  6431. if (length >= kMaxLength()) {
  6432. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  6433. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  6434. }
  6435. return length | 0
  6436. }
  6437. function SlowBuffer (length) {
  6438. if (+length != length) { // eslint-disable-line eqeqeq
  6439. length = 0
  6440. }
  6441. return Buffer.alloc(+length)
  6442. }
  6443. Buffer.isBuffer = function isBuffer (b) {
  6444. return !!(b != null && b._isBuffer)
  6445. }
  6446. Buffer.compare = function compare (a, b) {
  6447. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  6448. throw new TypeError('Arguments must be Buffers')
  6449. }
  6450. if (a === b) return 0
  6451. var x = a.length
  6452. var y = b.length
  6453. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  6454. if (a[i] !== b[i]) {
  6455. x = a[i]
  6456. y = b[i]
  6457. break
  6458. }
  6459. }
  6460. if (x < y) return -1
  6461. if (y < x) return 1
  6462. return 0
  6463. }
  6464. Buffer.isEncoding = function isEncoding (encoding) {
  6465. switch (String(encoding).toLowerCase()) {
  6466. case 'hex':
  6467. case 'utf8':
  6468. case 'utf-8':
  6469. case 'ascii':
  6470. case 'binary':
  6471. case 'base64':
  6472. case 'raw':
  6473. case 'ucs2':
  6474. case 'ucs-2':
  6475. case 'utf16le':
  6476. case 'utf-16le':
  6477. return true
  6478. default:
  6479. return false
  6480. }
  6481. }
  6482. Buffer.concat = function concat (list, length) {
  6483. if (!isArray(list)) {
  6484. throw new TypeError('"list" argument must be an Array of Buffers')
  6485. }
  6486. if (list.length === 0) {
  6487. return Buffer.alloc(0)
  6488. }
  6489. var i
  6490. if (length === undefined) {
  6491. length = 0
  6492. for (i = 0; i < list.length; i++) {
  6493. length += list[i].length
  6494. }
  6495. }
  6496. var buffer = Buffer.allocUnsafe(length)
  6497. var pos = 0
  6498. for (i = 0; i < list.length; i++) {
  6499. var buf = list[i]
  6500. if (!Buffer.isBuffer(buf)) {
  6501. throw new TypeError('"list" argument must be an Array of Buffers')
  6502. }
  6503. buf.copy(buffer, pos)
  6504. pos += buf.length
  6505. }
  6506. return buffer
  6507. }
  6508. function byteLength (string, encoding) {
  6509. if (Buffer.isBuffer(string)) {
  6510. return string.length
  6511. }
  6512. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  6513. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  6514. return string.byteLength
  6515. }
  6516. if (typeof string !== 'string') {
  6517. string = '' + string
  6518. }
  6519. var len = string.length
  6520. if (len === 0) return 0
  6521. // Use a for loop to avoid recursion
  6522. var loweredCase = false
  6523. for (;;) {
  6524. switch (encoding) {
  6525. case 'ascii':
  6526. case 'binary':
  6527. // Deprecated
  6528. case 'raw':
  6529. case 'raws':
  6530. return len
  6531. case 'utf8':
  6532. case 'utf-8':
  6533. case undefined:
  6534. return utf8ToBytes(string).length
  6535. case 'ucs2':
  6536. case 'ucs-2':
  6537. case 'utf16le':
  6538. case 'utf-16le':
  6539. return len * 2
  6540. case 'hex':
  6541. return len >>> 1
  6542. case 'base64':
  6543. return base64ToBytes(string).length
  6544. default:
  6545. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  6546. encoding = ('' + encoding).toLowerCase()
  6547. loweredCase = true
  6548. }
  6549. }
  6550. }
  6551. Buffer.byteLength = byteLength
  6552. function slowToString (encoding, start, end) {
  6553. var loweredCase = false
  6554. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  6555. // property of a typed array.
  6556. // This behaves neither like String nor Uint8Array in that we set start/end
  6557. // to their upper/lower bounds if the value passed is out of range.
  6558. // undefined is handled specially as per ECMA-262 6th Edition,
  6559. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  6560. if (start === undefined || start < 0) {
  6561. start = 0
  6562. }
  6563. // Return early if start > this.length. Done here to prevent potential uint32
  6564. // coercion fail below.
  6565. if (start > this.length) {
  6566. return ''
  6567. }
  6568. if (end === undefined || end > this.length) {
  6569. end = this.length
  6570. }
  6571. if (end <= 0) {
  6572. return ''
  6573. }
  6574. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  6575. end >>>= 0
  6576. start >>>= 0
  6577. if (end <= start) {
  6578. return ''
  6579. }
  6580. if (!encoding) encoding = 'utf8'
  6581. while (true) {
  6582. switch (encoding) {
  6583. case 'hex':
  6584. return hexSlice(this, start, end)
  6585. case 'utf8':
  6586. case 'utf-8':
  6587. return utf8Slice(this, start, end)
  6588. case 'ascii':
  6589. return asciiSlice(this, start, end)
  6590. case 'binary':
  6591. return binarySlice(this, start, end)
  6592. case 'base64':
  6593. return base64Slice(this, start, end)
  6594. case 'ucs2':
  6595. case 'ucs-2':
  6596. case 'utf16le':
  6597. case 'utf-16le':
  6598. return utf16leSlice(this, start, end)
  6599. default:
  6600. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6601. encoding = (encoding + '').toLowerCase()
  6602. loweredCase = true
  6603. }
  6604. }
  6605. }
  6606. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  6607. // Buffer instances.
  6608. Buffer.prototype._isBuffer = true
  6609. function swap (b, n, m) {
  6610. var i = b[n]
  6611. b[n] = b[m]
  6612. b[m] = i
  6613. }
  6614. Buffer.prototype.swap16 = function swap16 () {
  6615. var len = this.length
  6616. if (len % 2 !== 0) {
  6617. throw new RangeError('Buffer size must be a multiple of 16-bits')
  6618. }
  6619. for (var i = 0; i < len; i += 2) {
  6620. swap(this, i, i + 1)
  6621. }
  6622. return this
  6623. }
  6624. Buffer.prototype.swap32 = function swap32 () {
  6625. var len = this.length
  6626. if (len % 4 !== 0) {
  6627. throw new RangeError('Buffer size must be a multiple of 32-bits')
  6628. }
  6629. for (var i = 0; i < len; i += 4) {
  6630. swap(this, i, i + 3)
  6631. swap(this, i + 1, i + 2)
  6632. }
  6633. return this
  6634. }
  6635. Buffer.prototype.toString = function toString () {
  6636. var length = this.length | 0
  6637. if (length === 0) return ''
  6638. if (arguments.length === 0) return utf8Slice(this, 0, length)
  6639. return slowToString.apply(this, arguments)
  6640. }
  6641. Buffer.prototype.equals = function equals (b) {
  6642. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  6643. if (this === b) return true
  6644. return Buffer.compare(this, b) === 0
  6645. }
  6646. Buffer.prototype.inspect = function inspect () {
  6647. var str = ''
  6648. var max = exports.INSPECT_MAX_BYTES
  6649. if (this.length > 0) {
  6650. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  6651. if (this.length > max) str += ' ... '
  6652. }
  6653. return '<Buffer ' + str + '>'
  6654. }
  6655. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  6656. if (!Buffer.isBuffer(target)) {
  6657. throw new TypeError('Argument must be a Buffer')
  6658. }
  6659. if (start === undefined) {
  6660. start = 0
  6661. }
  6662. if (end === undefined) {
  6663. end = target ? target.length : 0
  6664. }
  6665. if (thisStart === undefined) {
  6666. thisStart = 0
  6667. }
  6668. if (thisEnd === undefined) {
  6669. thisEnd = this.length
  6670. }
  6671. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  6672. throw new RangeError('out of range index')
  6673. }
  6674. if (thisStart >= thisEnd && start >= end) {
  6675. return 0
  6676. }
  6677. if (thisStart >= thisEnd) {
  6678. return -1
  6679. }
  6680. if (start >= end) {
  6681. return 1
  6682. }
  6683. start >>>= 0
  6684. end >>>= 0
  6685. thisStart >>>= 0
  6686. thisEnd >>>= 0
  6687. if (this === target) return 0
  6688. var x = thisEnd - thisStart
  6689. var y = end - start
  6690. var len = Math.min(x, y)
  6691. var thisCopy = this.slice(thisStart, thisEnd)
  6692. var targetCopy = target.slice(start, end)
  6693. for (var i = 0; i < len; ++i) {
  6694. if (thisCopy[i] !== targetCopy[i]) {
  6695. x = thisCopy[i]
  6696. y = targetCopy[i]
  6697. break
  6698. }
  6699. }
  6700. if (x < y) return -1
  6701. if (y < x) return 1
  6702. return 0
  6703. }
  6704. function arrayIndexOf (arr, val, byteOffset, encoding) {
  6705. var indexSize = 1
  6706. var arrLength = arr.length
  6707. var valLength = val.length
  6708. if (encoding !== undefined) {
  6709. encoding = String(encoding).toLowerCase()
  6710. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  6711. encoding === 'utf16le' || encoding === 'utf-16le') {
  6712. if (arr.length < 2 || val.length < 2) {
  6713. return -1
  6714. }
  6715. indexSize = 2
  6716. arrLength /= 2
  6717. valLength /= 2
  6718. byteOffset /= 2
  6719. }
  6720. }
  6721. function read (buf, i) {
  6722. if (indexSize === 1) {
  6723. return buf[i]
  6724. } else {
  6725. return buf.readUInt16BE(i * indexSize)
  6726. }
  6727. }
  6728. var foundIndex = -1
  6729. for (var i = 0; byteOffset + i < arrLength; i++) {
  6730. if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  6731. if (foundIndex === -1) foundIndex = i
  6732. if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
  6733. } else {
  6734. if (foundIndex !== -1) i -= i - foundIndex
  6735. foundIndex = -1
  6736. }
  6737. }
  6738. return -1
  6739. }
  6740. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  6741. if (typeof byteOffset === 'string') {
  6742. encoding = byteOffset
  6743. byteOffset = 0
  6744. } else if (byteOffset > 0x7fffffff) {
  6745. byteOffset = 0x7fffffff
  6746. } else if (byteOffset < -0x80000000) {
  6747. byteOffset = -0x80000000
  6748. }
  6749. byteOffset >>= 0
  6750. if (this.length === 0) return -1
  6751. if (byteOffset >= this.length) return -1
  6752. // Negative offsets start from the end of the buffer
  6753. if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
  6754. if (typeof val === 'string') {
  6755. val = Buffer.from(val, encoding)
  6756. }
  6757. if (Buffer.isBuffer(val)) {
  6758. // special case: looking for empty string/buffer always fails
  6759. if (val.length === 0) {
  6760. return -1
  6761. }
  6762. return arrayIndexOf(this, val, byteOffset, encoding)
  6763. }
  6764. if (typeof val === 'number') {
  6765. if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
  6766. return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
  6767. }
  6768. return arrayIndexOf(this, [ val ], byteOffset, encoding)
  6769. }
  6770. throw new TypeError('val must be string, number or Buffer')
  6771. }
  6772. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  6773. return this.indexOf(val, byteOffset, encoding) !== -1
  6774. }
  6775. function hexWrite (buf, string, offset, length) {
  6776. offset = Number(offset) || 0
  6777. var remaining = buf.length - offset
  6778. if (!length) {
  6779. length = remaining
  6780. } else {
  6781. length = Number(length)
  6782. if (length > remaining) {
  6783. length = remaining
  6784. }
  6785. }
  6786. // must be an even number of digits
  6787. var strLen = string.length
  6788. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  6789. if (length > strLen / 2) {
  6790. length = strLen / 2
  6791. }
  6792. for (var i = 0; i < length; i++) {
  6793. var parsed = parseInt(string.substr(i * 2, 2), 16)
  6794. if (isNaN(parsed)) return i
  6795. buf[offset + i] = parsed
  6796. }
  6797. return i
  6798. }
  6799. function utf8Write (buf, string, offset, length) {
  6800. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  6801. }
  6802. function asciiWrite (buf, string, offset, length) {
  6803. return blitBuffer(asciiToBytes(string), buf, offset, length)
  6804. }
  6805. function binaryWrite (buf, string, offset, length) {
  6806. return asciiWrite(buf, string, offset, length)
  6807. }
  6808. function base64Write (buf, string, offset, length) {
  6809. return blitBuffer(base64ToBytes(string), buf, offset, length)
  6810. }
  6811. function ucs2Write (buf, string, offset, length) {
  6812. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  6813. }
  6814. Buffer.prototype.write = function write (string, offset, length, encoding) {
  6815. // Buffer#write(string)
  6816. if (offset === undefined) {
  6817. encoding = 'utf8'
  6818. length = this.length
  6819. offset = 0
  6820. // Buffer#write(string, encoding)
  6821. } else if (length === undefined && typeof offset === 'string') {
  6822. encoding = offset
  6823. length = this.length
  6824. offset = 0
  6825. // Buffer#write(string, offset[, length][, encoding])
  6826. } else if (isFinite(offset)) {
  6827. offset = offset | 0
  6828. if (isFinite(length)) {
  6829. length = length | 0
  6830. if (encoding === undefined) encoding = 'utf8'
  6831. } else {
  6832. encoding = length
  6833. length = undefined
  6834. }
  6835. // legacy write(string, encoding, offset, length) - remove in v0.13
  6836. } else {
  6837. throw new Error(
  6838. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  6839. )
  6840. }
  6841. var remaining = this.length - offset
  6842. if (length === undefined || length > remaining) length = remaining
  6843. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  6844. throw new RangeError('Attempt to write outside buffer bounds')
  6845. }
  6846. if (!encoding) encoding = 'utf8'
  6847. var loweredCase = false
  6848. for (;;) {
  6849. switch (encoding) {
  6850. case 'hex':
  6851. return hexWrite(this, string, offset, length)
  6852. case 'utf8':
  6853. case 'utf-8':
  6854. return utf8Write(this, string, offset, length)
  6855. case 'ascii':
  6856. return asciiWrite(this, string, offset, length)
  6857. case 'binary':
  6858. return binaryWrite(this, string, offset, length)
  6859. case 'base64':
  6860. // Warning: maxLength not taken into account in base64Write
  6861. return base64Write(this, string, offset, length)
  6862. case 'ucs2':
  6863. case 'ucs-2':
  6864. case 'utf16le':
  6865. case 'utf-16le':
  6866. return ucs2Write(this, string, offset, length)
  6867. default:
  6868. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  6869. encoding = ('' + encoding).toLowerCase()
  6870. loweredCase = true
  6871. }
  6872. }
  6873. }
  6874. Buffer.prototype.toJSON = function toJSON () {
  6875. return {
  6876. type: 'Buffer',
  6877. data: Array.prototype.slice.call(this._arr || this, 0)
  6878. }
  6879. }
  6880. function base64Slice (buf, start, end) {
  6881. if (start === 0 && end === buf.length) {
  6882. return base64.fromByteArray(buf)
  6883. } else {
  6884. return base64.fromByteArray(buf.slice(start, end))
  6885. }
  6886. }
  6887. function utf8Slice (buf, start, end) {
  6888. end = Math.min(buf.length, end)
  6889. var res = []
  6890. var i = start
  6891. while (i < end) {
  6892. var firstByte = buf[i]
  6893. var codePoint = null
  6894. var bytesPerSequence = (firstByte > 0xEF) ? 4
  6895. : (firstByte > 0xDF) ? 3
  6896. : (firstByte > 0xBF) ? 2
  6897. : 1
  6898. if (i + bytesPerSequence <= end) {
  6899. var secondByte, thirdByte, fourthByte, tempCodePoint
  6900. switch (bytesPerSequence) {
  6901. case 1:
  6902. if (firstByte < 0x80) {
  6903. codePoint = firstByte
  6904. }
  6905. break
  6906. case 2:
  6907. secondByte = buf[i + 1]
  6908. if ((secondByte & 0xC0) === 0x80) {
  6909. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  6910. if (tempCodePoint > 0x7F) {
  6911. codePoint = tempCodePoint
  6912. }
  6913. }
  6914. break
  6915. case 3:
  6916. secondByte = buf[i + 1]
  6917. thirdByte = buf[i + 2]
  6918. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  6919. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  6920. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  6921. codePoint = tempCodePoint
  6922. }
  6923. }
  6924. break
  6925. case 4:
  6926. secondByte = buf[i + 1]
  6927. thirdByte = buf[i + 2]
  6928. fourthByte = buf[i + 3]
  6929. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  6930. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  6931. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  6932. codePoint = tempCodePoint
  6933. }
  6934. }
  6935. }
  6936. }
  6937. if (codePoint === null) {
  6938. // we did not generate a valid codePoint so insert a
  6939. // replacement char (U+FFFD) and advance only 1 byte
  6940. codePoint = 0xFFFD
  6941. bytesPerSequence = 1
  6942. } else if (codePoint > 0xFFFF) {
  6943. // encode to utf16 (surrogate pair dance)
  6944. codePoint -= 0x10000
  6945. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  6946. codePoint = 0xDC00 | codePoint & 0x3FF
  6947. }
  6948. res.push(codePoint)
  6949. i += bytesPerSequence
  6950. }
  6951. return decodeCodePointsArray(res)
  6952. }
  6953. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  6954. // the lowest limit is Chrome, with 0x10000 args.
  6955. // We go 1 magnitude less, for safety
  6956. var MAX_ARGUMENTS_LENGTH = 0x1000
  6957. function decodeCodePointsArray (codePoints) {
  6958. var len = codePoints.length
  6959. if (len <= MAX_ARGUMENTS_LENGTH) {
  6960. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  6961. }
  6962. // Decode in chunks to avoid "call stack size exceeded".
  6963. var res = ''
  6964. var i = 0
  6965. while (i < len) {
  6966. res += String.fromCharCode.apply(
  6967. String,
  6968. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  6969. )
  6970. }
  6971. return res
  6972. }
  6973. function asciiSlice (buf, start, end) {
  6974. var ret = ''
  6975. end = Math.min(buf.length, end)
  6976. for (var i = start; i < end; i++) {
  6977. ret += String.fromCharCode(buf[i] & 0x7F)
  6978. }
  6979. return ret
  6980. }
  6981. function binarySlice (buf, start, end) {
  6982. var ret = ''
  6983. end = Math.min(buf.length, end)
  6984. for (var i = start; i < end; i++) {
  6985. ret += String.fromCharCode(buf[i])
  6986. }
  6987. return ret
  6988. }
  6989. function hexSlice (buf, start, end) {
  6990. var len = buf.length
  6991. if (!start || start < 0) start = 0
  6992. if (!end || end < 0 || end > len) end = len
  6993. var out = ''
  6994. for (var i = start; i < end; i++) {
  6995. out += toHex(buf[i])
  6996. }
  6997. return out
  6998. }
  6999. function utf16leSlice (buf, start, end) {
  7000. var bytes = buf.slice(start, end)
  7001. var res = ''
  7002. for (var i = 0; i < bytes.length; i += 2) {
  7003. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  7004. }
  7005. return res
  7006. }
  7007. Buffer.prototype.slice = function slice (start, end) {
  7008. var len = this.length
  7009. start = ~~start
  7010. end = end === undefined ? len : ~~end
  7011. if (start < 0) {
  7012. start += len
  7013. if (start < 0) start = 0
  7014. } else if (start > len) {
  7015. start = len
  7016. }
  7017. if (end < 0) {
  7018. end += len
  7019. if (end < 0) end = 0
  7020. } else if (end > len) {
  7021. end = len
  7022. }
  7023. if (end < start) end = start
  7024. var newBuf
  7025. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7026. newBuf = this.subarray(start, end)
  7027. newBuf.__proto__ = Buffer.prototype
  7028. } else {
  7029. var sliceLen = end - start
  7030. newBuf = new Buffer(sliceLen, undefined)
  7031. for (var i = 0; i < sliceLen; i++) {
  7032. newBuf[i] = this[i + start]
  7033. }
  7034. }
  7035. return newBuf
  7036. }
  7037. /*
  7038. * Need to make sure that buffer isn't trying to write out of bounds.
  7039. */
  7040. function checkOffset (offset, ext, length) {
  7041. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7042. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7043. }
  7044. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7045. offset = offset | 0
  7046. byteLength = byteLength | 0
  7047. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7048. var val = this[offset]
  7049. var mul = 1
  7050. var i = 0
  7051. while (++i < byteLength && (mul *= 0x100)) {
  7052. val += this[offset + i] * mul
  7053. }
  7054. return val
  7055. }
  7056. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7057. offset = offset | 0
  7058. byteLength = byteLength | 0
  7059. if (!noAssert) {
  7060. checkOffset(offset, byteLength, this.length)
  7061. }
  7062. var val = this[offset + --byteLength]
  7063. var mul = 1
  7064. while (byteLength > 0 && (mul *= 0x100)) {
  7065. val += this[offset + --byteLength] * mul
  7066. }
  7067. return val
  7068. }
  7069. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7070. if (!noAssert) checkOffset(offset, 1, this.length)
  7071. return this[offset]
  7072. }
  7073. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7074. if (!noAssert) checkOffset(offset, 2, this.length)
  7075. return this[offset] | (this[offset + 1] << 8)
  7076. }
  7077. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7078. if (!noAssert) checkOffset(offset, 2, this.length)
  7079. return (this[offset] << 8) | this[offset + 1]
  7080. }
  7081. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7082. if (!noAssert) checkOffset(offset, 4, this.length)
  7083. return ((this[offset]) |
  7084. (this[offset + 1] << 8) |
  7085. (this[offset + 2] << 16)) +
  7086. (this[offset + 3] * 0x1000000)
  7087. }
  7088. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7089. if (!noAssert) checkOffset(offset, 4, this.length)
  7090. return (this[offset] * 0x1000000) +
  7091. ((this[offset + 1] << 16) |
  7092. (this[offset + 2] << 8) |
  7093. this[offset + 3])
  7094. }
  7095. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7096. offset = offset | 0
  7097. byteLength = byteLength | 0
  7098. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7099. var val = this[offset]
  7100. var mul = 1
  7101. var i = 0
  7102. while (++i < byteLength && (mul *= 0x100)) {
  7103. val += this[offset + i] * mul
  7104. }
  7105. mul *= 0x80
  7106. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7107. return val
  7108. }
  7109. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7110. offset = offset | 0
  7111. byteLength = byteLength | 0
  7112. if (!noAssert) checkOffset(offset, byteLength, this.length)
  7113. var i = byteLength
  7114. var mul = 1
  7115. var val = this[offset + --i]
  7116. while (i > 0 && (mul *= 0x100)) {
  7117. val += this[offset + --i] * mul
  7118. }
  7119. mul *= 0x80
  7120. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  7121. return val
  7122. }
  7123. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7124. if (!noAssert) checkOffset(offset, 1, this.length)
  7125. if (!(this[offset] & 0x80)) return (this[offset])
  7126. return ((0xff - this[offset] + 1) * -1)
  7127. }
  7128. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7129. if (!noAssert) checkOffset(offset, 2, this.length)
  7130. var val = this[offset] | (this[offset + 1] << 8)
  7131. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7132. }
  7133. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7134. if (!noAssert) checkOffset(offset, 2, this.length)
  7135. var val = this[offset + 1] | (this[offset] << 8)
  7136. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7137. }
  7138. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7139. if (!noAssert) checkOffset(offset, 4, this.length)
  7140. return (this[offset]) |
  7141. (this[offset + 1] << 8) |
  7142. (this[offset + 2] << 16) |
  7143. (this[offset + 3] << 24)
  7144. }
  7145. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7146. if (!noAssert) checkOffset(offset, 4, this.length)
  7147. return (this[offset] << 24) |
  7148. (this[offset + 1] << 16) |
  7149. (this[offset + 2] << 8) |
  7150. (this[offset + 3])
  7151. }
  7152. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7153. if (!noAssert) checkOffset(offset, 4, this.length)
  7154. return ieee754.read(this, offset, true, 23, 4)
  7155. }
  7156. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7157. if (!noAssert) checkOffset(offset, 4, this.length)
  7158. return ieee754.read(this, offset, false, 23, 4)
  7159. }
  7160. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7161. if (!noAssert) checkOffset(offset, 8, this.length)
  7162. return ieee754.read(this, offset, true, 52, 8)
  7163. }
  7164. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7165. if (!noAssert) checkOffset(offset, 8, this.length)
  7166. return ieee754.read(this, offset, false, 52, 8)
  7167. }
  7168. function checkInt (buf, value, offset, ext, max, min) {
  7169. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7170. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7171. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7172. }
  7173. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7174. value = +value
  7175. offset = offset | 0
  7176. byteLength = byteLength | 0
  7177. if (!noAssert) {
  7178. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7179. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7180. }
  7181. var mul = 1
  7182. var i = 0
  7183. this[offset] = value & 0xFF
  7184. while (++i < byteLength && (mul *= 0x100)) {
  7185. this[offset + i] = (value / mul) & 0xFF
  7186. }
  7187. return offset + byteLength
  7188. }
  7189. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7190. value = +value
  7191. offset = offset | 0
  7192. byteLength = byteLength | 0
  7193. if (!noAssert) {
  7194. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  7195. checkInt(this, value, offset, byteLength, maxBytes, 0)
  7196. }
  7197. var i = byteLength - 1
  7198. var mul = 1
  7199. this[offset + i] = value & 0xFF
  7200. while (--i >= 0 && (mul *= 0x100)) {
  7201. this[offset + i] = (value / mul) & 0xFF
  7202. }
  7203. return offset + byteLength
  7204. }
  7205. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7206. value = +value
  7207. offset = offset | 0
  7208. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  7209. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7210. this[offset] = (value & 0xff)
  7211. return offset + 1
  7212. }
  7213. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7214. if (value < 0) value = 0xffff + value + 1
  7215. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  7216. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7217. (littleEndian ? i : 1 - i) * 8
  7218. }
  7219. }
  7220. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7221. value = +value
  7222. offset = offset | 0
  7223. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7224. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7225. this[offset] = (value & 0xff)
  7226. this[offset + 1] = (value >>> 8)
  7227. } else {
  7228. objectWriteUInt16(this, value, offset, true)
  7229. }
  7230. return offset + 2
  7231. }
  7232. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7233. value = +value
  7234. offset = offset | 0
  7235. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  7236. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7237. this[offset] = (value >>> 8)
  7238. this[offset + 1] = (value & 0xff)
  7239. } else {
  7240. objectWriteUInt16(this, value, offset, false)
  7241. }
  7242. return offset + 2
  7243. }
  7244. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7245. if (value < 0) value = 0xffffffff + value + 1
  7246. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  7247. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  7248. }
  7249. }
  7250. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7251. value = +value
  7252. offset = offset | 0
  7253. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7254. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7255. this[offset + 3] = (value >>> 24)
  7256. this[offset + 2] = (value >>> 16)
  7257. this[offset + 1] = (value >>> 8)
  7258. this[offset] = (value & 0xff)
  7259. } else {
  7260. objectWriteUInt32(this, value, offset, true)
  7261. }
  7262. return offset + 4
  7263. }
  7264. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7265. value = +value
  7266. offset = offset | 0
  7267. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  7268. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7269. this[offset] = (value >>> 24)
  7270. this[offset + 1] = (value >>> 16)
  7271. this[offset + 2] = (value >>> 8)
  7272. this[offset + 3] = (value & 0xff)
  7273. } else {
  7274. objectWriteUInt32(this, value, offset, false)
  7275. }
  7276. return offset + 4
  7277. }
  7278. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7279. value = +value
  7280. offset = offset | 0
  7281. if (!noAssert) {
  7282. var limit = Math.pow(2, 8 * byteLength - 1)
  7283. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7284. }
  7285. var i = 0
  7286. var mul = 1
  7287. var sub = 0
  7288. this[offset] = value & 0xFF
  7289. while (++i < byteLength && (mul *= 0x100)) {
  7290. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7291. sub = 1
  7292. }
  7293. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7294. }
  7295. return offset + byteLength
  7296. }
  7297. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7298. value = +value
  7299. offset = offset | 0
  7300. if (!noAssert) {
  7301. var limit = Math.pow(2, 8 * byteLength - 1)
  7302. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  7303. }
  7304. var i = byteLength - 1
  7305. var mul = 1
  7306. var sub = 0
  7307. this[offset + i] = value & 0xFF
  7308. while (--i >= 0 && (mul *= 0x100)) {
  7309. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7310. sub = 1
  7311. }
  7312. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  7313. }
  7314. return offset + byteLength
  7315. }
  7316. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7317. value = +value
  7318. offset = offset | 0
  7319. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  7320. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  7321. if (value < 0) value = 0xff + value + 1
  7322. this[offset] = (value & 0xff)
  7323. return offset + 1
  7324. }
  7325. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7326. value = +value
  7327. offset = offset | 0
  7328. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7329. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7330. this[offset] = (value & 0xff)
  7331. this[offset + 1] = (value >>> 8)
  7332. } else {
  7333. objectWriteUInt16(this, value, offset, true)
  7334. }
  7335. return offset + 2
  7336. }
  7337. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7338. value = +value
  7339. offset = offset | 0
  7340. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  7341. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7342. this[offset] = (value >>> 8)
  7343. this[offset + 1] = (value & 0xff)
  7344. } else {
  7345. objectWriteUInt16(this, value, offset, false)
  7346. }
  7347. return offset + 2
  7348. }
  7349. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7350. value = +value
  7351. offset = offset | 0
  7352. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7353. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7354. this[offset] = (value & 0xff)
  7355. this[offset + 1] = (value >>> 8)
  7356. this[offset + 2] = (value >>> 16)
  7357. this[offset + 3] = (value >>> 24)
  7358. } else {
  7359. objectWriteUInt32(this, value, offset, true)
  7360. }
  7361. return offset + 4
  7362. }
  7363. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7364. value = +value
  7365. offset = offset | 0
  7366. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  7367. if (value < 0) value = 0xffffffff + value + 1
  7368. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7369. this[offset] = (value >>> 24)
  7370. this[offset + 1] = (value >>> 16)
  7371. this[offset + 2] = (value >>> 8)
  7372. this[offset + 3] = (value & 0xff)
  7373. } else {
  7374. objectWriteUInt32(this, value, offset, false)
  7375. }
  7376. return offset + 4
  7377. }
  7378. function checkIEEE754 (buf, value, offset, ext, max, min) {
  7379. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7380. if (offset < 0) throw new RangeError('Index out of range')
  7381. }
  7382. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  7383. if (!noAssert) {
  7384. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  7385. }
  7386. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  7387. return offset + 4
  7388. }
  7389. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  7390. return writeFloat(this, value, offset, true, noAssert)
  7391. }
  7392. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  7393. return writeFloat(this, value, offset, false, noAssert)
  7394. }
  7395. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  7396. if (!noAssert) {
  7397. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  7398. }
  7399. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  7400. return offset + 8
  7401. }
  7402. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  7403. return writeDouble(this, value, offset, true, noAssert)
  7404. }
  7405. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  7406. return writeDouble(this, value, offset, false, noAssert)
  7407. }
  7408. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7409. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  7410. if (!start) start = 0
  7411. if (!end && end !== 0) end = this.length
  7412. if (targetStart >= target.length) targetStart = target.length
  7413. if (!targetStart) targetStart = 0
  7414. if (end > 0 && end < start) end = start
  7415. // Copy 0 bytes; we're done
  7416. if (end === start) return 0
  7417. if (target.length === 0 || this.length === 0) return 0
  7418. // Fatal error conditions
  7419. if (targetStart < 0) {
  7420. throw new RangeError('targetStart out of bounds')
  7421. }
  7422. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  7423. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  7424. // Are we oob?
  7425. if (end > this.length) end = this.length
  7426. if (target.length - targetStart < end - start) {
  7427. end = target.length - targetStart + start
  7428. }
  7429. var len = end - start
  7430. var i
  7431. if (this === target && start < targetStart && targetStart < end) {
  7432. // descending copy from end
  7433. for (i = len - 1; i >= 0; i--) {
  7434. target[i + targetStart] = this[i + start]
  7435. }
  7436. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  7437. // ascending copy from start
  7438. for (i = 0; i < len; i++) {
  7439. target[i + targetStart] = this[i + start]
  7440. }
  7441. } else {
  7442. Uint8Array.prototype.set.call(
  7443. target,
  7444. this.subarray(start, start + len),
  7445. targetStart
  7446. )
  7447. }
  7448. return len
  7449. }
  7450. // Usage:
  7451. // buffer.fill(number[, offset[, end]])
  7452. // buffer.fill(buffer[, offset[, end]])
  7453. // buffer.fill(string[, offset[, end]][, encoding])
  7454. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  7455. // Handle string cases:
  7456. if (typeof val === 'string') {
  7457. if (typeof start === 'string') {
  7458. encoding = start
  7459. start = 0
  7460. end = this.length
  7461. } else if (typeof end === 'string') {
  7462. encoding = end
  7463. end = this.length
  7464. }
  7465. if (val.length === 1) {
  7466. var code = val.charCodeAt(0)
  7467. if (code < 256) {
  7468. val = code
  7469. }
  7470. }
  7471. if (encoding !== undefined && typeof encoding !== 'string') {
  7472. throw new TypeError('encoding must be a string')
  7473. }
  7474. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  7475. throw new TypeError('Unknown encoding: ' + encoding)
  7476. }
  7477. } else if (typeof val === 'number') {
  7478. val = val & 255
  7479. }
  7480. // Invalid ranges are not set to a default, so can range check early.
  7481. if (start < 0 || this.length < start || this.length < end) {
  7482. throw new RangeError('Out of range index')
  7483. }
  7484. if (end <= start) {
  7485. return this
  7486. }
  7487. start = start >>> 0
  7488. end = end === undefined ? this.length : end >>> 0
  7489. if (!val) val = 0
  7490. var i
  7491. if (typeof val === 'number') {
  7492. for (i = start; i < end; i++) {
  7493. this[i] = val
  7494. }
  7495. } else {
  7496. var bytes = Buffer.isBuffer(val)
  7497. ? val
  7498. : utf8ToBytes(new Buffer(val, encoding).toString())
  7499. var len = bytes.length
  7500. for (i = 0; i < end - start; i++) {
  7501. this[i + start] = bytes[i % len]
  7502. }
  7503. }
  7504. return this
  7505. }
  7506. // HELPER FUNCTIONS
  7507. // ================
  7508. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  7509. function base64clean (str) {
  7510. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  7511. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  7512. // Node converts strings with length < 2 to ''
  7513. if (str.length < 2) return ''
  7514. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  7515. while (str.length % 4 !== 0) {
  7516. str = str + '='
  7517. }
  7518. return str
  7519. }
  7520. function stringtrim (str) {
  7521. if (str.trim) return str.trim()
  7522. return str.replace(/^\s+|\s+$/g, '')
  7523. }
  7524. function toHex (n) {
  7525. if (n < 16) return '0' + n.toString(16)
  7526. return n.toString(16)
  7527. }
  7528. function utf8ToBytes (string, units) {
  7529. units = units || Infinity
  7530. var codePoint
  7531. var length = string.length
  7532. var leadSurrogate = null
  7533. var bytes = []
  7534. for (var i = 0; i < length; i++) {
  7535. codePoint = string.charCodeAt(i)
  7536. // is surrogate component
  7537. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  7538. // last char was a lead
  7539. if (!leadSurrogate) {
  7540. // no lead yet
  7541. if (codePoint > 0xDBFF) {
  7542. // unexpected trail
  7543. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7544. continue
  7545. } else if (i + 1 === length) {
  7546. // unpaired lead
  7547. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7548. continue
  7549. }
  7550. // valid lead
  7551. leadSurrogate = codePoint
  7552. continue
  7553. }
  7554. // 2 leads in a row
  7555. if (codePoint < 0xDC00) {
  7556. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7557. leadSurrogate = codePoint
  7558. continue
  7559. }
  7560. // valid surrogate pair
  7561. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  7562. } else if (leadSurrogate) {
  7563. // valid bmp char, but last char was a lead
  7564. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  7565. }
  7566. leadSurrogate = null
  7567. // encode utf8
  7568. if (codePoint < 0x80) {
  7569. if ((units -= 1) < 0) break
  7570. bytes.push(codePoint)
  7571. } else if (codePoint < 0x800) {
  7572. if ((units -= 2) < 0) break
  7573. bytes.push(
  7574. codePoint >> 0x6 | 0xC0,
  7575. codePoint & 0x3F | 0x80
  7576. )
  7577. } else if (codePoint < 0x10000) {
  7578. if ((units -= 3) < 0) break
  7579. bytes.push(
  7580. codePoint >> 0xC | 0xE0,
  7581. codePoint >> 0x6 & 0x3F | 0x80,
  7582. codePoint & 0x3F | 0x80
  7583. )
  7584. } else if (codePoint < 0x110000) {
  7585. if ((units -= 4) < 0) break
  7586. bytes.push(
  7587. codePoint >> 0x12 | 0xF0,
  7588. codePoint >> 0xC & 0x3F | 0x80,
  7589. codePoint >> 0x6 & 0x3F | 0x80,
  7590. codePoint & 0x3F | 0x80
  7591. )
  7592. } else {
  7593. throw new Error('Invalid code point')
  7594. }
  7595. }
  7596. return bytes
  7597. }
  7598. function asciiToBytes (str) {
  7599. var byteArray = []
  7600. for (var i = 0; i < str.length; i++) {
  7601. // Node's code seems to be doing this and not & 0x7F..
  7602. byteArray.push(str.charCodeAt(i) & 0xFF)
  7603. }
  7604. return byteArray
  7605. }
  7606. function utf16leToBytes (str, units) {
  7607. var c, hi, lo
  7608. var byteArray = []
  7609. for (var i = 0; i < str.length; i++) {
  7610. if ((units -= 2) < 0) break
  7611. c = str.charCodeAt(i)
  7612. hi = c >> 8
  7613. lo = c % 256
  7614. byteArray.push(lo)
  7615. byteArray.push(hi)
  7616. }
  7617. return byteArray
  7618. }
  7619. function base64ToBytes (str) {
  7620. return base64.toByteArray(base64clean(str))
  7621. }
  7622. function blitBuffer (src, dst, offset, length) {
  7623. for (var i = 0; i < length; i++) {
  7624. if ((i + offset >= dst.length) || (i >= src.length)) break
  7625. dst[i + offset] = src[i]
  7626. }
  7627. return i
  7628. }
  7629. function isnan (val) {
  7630. return val !== val // eslint-disable-line no-self-compare
  7631. }
  7632. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7633. },{"base64-js":17,"ieee754":90,"isarray":94}],47:[function(require,module,exports){
  7634. (function (Buffer){
  7635. var Transform = require('stream').Transform
  7636. var inherits = require('inherits')
  7637. var StringDecoder = require('string_decoder').StringDecoder
  7638. module.exports = CipherBase
  7639. inherits(CipherBase, Transform)
  7640. function CipherBase (hashMode) {
  7641. Transform.call(this)
  7642. this.hashMode = typeof hashMode === 'string'
  7643. if (this.hashMode) {
  7644. this[hashMode] = this._finalOrDigest
  7645. } else {
  7646. this.final = this._finalOrDigest
  7647. }
  7648. this._decoder = null
  7649. this._encoding = null
  7650. }
  7651. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  7652. if (typeof data === 'string') {
  7653. data = new Buffer(data, inputEnc)
  7654. }
  7655. var outData = this._update(data)
  7656. if (this.hashMode) {
  7657. return this
  7658. }
  7659. if (outputEnc) {
  7660. outData = this._toString(outData, outputEnc)
  7661. }
  7662. return outData
  7663. }
  7664. CipherBase.prototype.setAutoPadding = function () {}
  7665. CipherBase.prototype.getAuthTag = function () {
  7666. throw new Error('trying to get auth tag in unsupported state')
  7667. }
  7668. CipherBase.prototype.setAuthTag = function () {
  7669. throw new Error('trying to set auth tag in unsupported state')
  7670. }
  7671. CipherBase.prototype.setAAD = function () {
  7672. throw new Error('trying to set aad in unsupported state')
  7673. }
  7674. CipherBase.prototype._transform = function (data, _, next) {
  7675. var err
  7676. try {
  7677. if (this.hashMode) {
  7678. this._update(data)
  7679. } else {
  7680. this.push(this._update(data))
  7681. }
  7682. } catch (e) {
  7683. err = e
  7684. } finally {
  7685. next(err)
  7686. }
  7687. }
  7688. CipherBase.prototype._flush = function (done) {
  7689. var err
  7690. try {
  7691. this.push(this._final())
  7692. } catch (e) {
  7693. err = e
  7694. } finally {
  7695. done(err)
  7696. }
  7697. }
  7698. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  7699. var outData = this._final() || new Buffer('')
  7700. if (outputEnc) {
  7701. outData = this._toString(outData, outputEnc, true)
  7702. }
  7703. return outData
  7704. }
  7705. CipherBase.prototype._toString = function (value, enc, final) {
  7706. if (!this._decoder) {
  7707. this._decoder = new StringDecoder(enc)
  7708. this._encoding = enc
  7709. }
  7710. if (this._encoding !== enc) {
  7711. throw new Error('can\'t switch encodings')
  7712. }
  7713. var out = this._decoder.write(value)
  7714. if (final) {
  7715. out += this._decoder.end()
  7716. }
  7717. return out
  7718. }
  7719. }).call(this,require("buffer").Buffer)
  7720. },{"buffer":46,"inherits":92,"stream":137,"string_decoder":138}],48:[function(require,module,exports){
  7721. (function (Buffer){
  7722. // Copyright Joyent, Inc. and other Node contributors.
  7723. //
  7724. // Permission is hereby granted, free of charge, to any person obtaining a
  7725. // copy of this software and associated documentation files (the
  7726. // "Software"), to deal in the Software without restriction, including
  7727. // without limitation the rights to use, copy, modify, merge, publish,
  7728. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7729. // persons to whom the Software is furnished to do so, subject to the
  7730. // following conditions:
  7731. //
  7732. // The above copyright notice and this permission notice shall be included
  7733. // in all copies or substantial portions of the Software.
  7734. //
  7735. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7736. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7737. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7738. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7739. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7740. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7741. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7742. // NOTE: These type checking functions intentionally don't use `instanceof`
  7743. // because it is fragile and can be easily faked with `Object.create()`.
  7744. function isArray(arg) {
  7745. if (Array.isArray) {
  7746. return Array.isArray(arg);
  7747. }
  7748. return objectToString(arg) === '[object Array]';
  7749. }
  7750. exports.isArray = isArray;
  7751. function isBoolean(arg) {
  7752. return typeof arg === 'boolean';
  7753. }
  7754. exports.isBoolean = isBoolean;
  7755. function isNull(arg) {
  7756. return arg === null;
  7757. }
  7758. exports.isNull = isNull;
  7759. function isNullOrUndefined(arg) {
  7760. return arg == null;
  7761. }
  7762. exports.isNullOrUndefined = isNullOrUndefined;
  7763. function isNumber(arg) {
  7764. return typeof arg === 'number';
  7765. }
  7766. exports.isNumber = isNumber;
  7767. function isString(arg) {
  7768. return typeof arg === 'string';
  7769. }
  7770. exports.isString = isString;
  7771. function isSymbol(arg) {
  7772. return typeof arg === 'symbol';
  7773. }
  7774. exports.isSymbol = isSymbol;
  7775. function isUndefined(arg) {
  7776. return arg === void 0;
  7777. }
  7778. exports.isUndefined = isUndefined;
  7779. function isRegExp(re) {
  7780. return objectToString(re) === '[object RegExp]';
  7781. }
  7782. exports.isRegExp = isRegExp;
  7783. function isObject(arg) {
  7784. return typeof arg === 'object' && arg !== null;
  7785. }
  7786. exports.isObject = isObject;
  7787. function isDate(d) {
  7788. return objectToString(d) === '[object Date]';
  7789. }
  7790. exports.isDate = isDate;
  7791. function isError(e) {
  7792. return (objectToString(e) === '[object Error]' || e instanceof Error);
  7793. }
  7794. exports.isError = isError;
  7795. function isFunction(arg) {
  7796. return typeof arg === 'function';
  7797. }
  7798. exports.isFunction = isFunction;
  7799. function isPrimitive(arg) {
  7800. return arg === null ||
  7801. typeof arg === 'boolean' ||
  7802. typeof arg === 'number' ||
  7803. typeof arg === 'string' ||
  7804. typeof arg === 'symbol' || // ES6 symbol
  7805. typeof arg === 'undefined';
  7806. }
  7807. exports.isPrimitive = isPrimitive;
  7808. exports.isBuffer = Buffer.isBuffer;
  7809. function objectToString(o) {
  7810. return Object.prototype.toString.call(o);
  7811. }
  7812. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  7813. },{"../../is-buffer/index.js":93}],49:[function(require,module,exports){
  7814. (function (Buffer){
  7815. var elliptic = require('elliptic');
  7816. var BN = require('bn.js');
  7817. module.exports = function createECDH(curve) {
  7818. return new ECDH(curve);
  7819. };
  7820. var aliases = {
  7821. secp256k1: {
  7822. name: 'secp256k1',
  7823. byteLength: 32
  7824. },
  7825. secp224r1: {
  7826. name: 'p224',
  7827. byteLength: 28
  7828. },
  7829. prime256v1: {
  7830. name: 'p256',
  7831. byteLength: 32
  7832. },
  7833. prime192v1: {
  7834. name: 'p192',
  7835. byteLength: 24
  7836. },
  7837. ed25519: {
  7838. name: 'ed25519',
  7839. byteLength: 32
  7840. },
  7841. secp384r1: {
  7842. name: 'p384',
  7843. byteLength: 48
  7844. },
  7845. secp521r1: {
  7846. name: 'p521',
  7847. byteLength: 66
  7848. }
  7849. };
  7850. aliases.p224 = aliases.secp224r1;
  7851. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  7852. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  7853. aliases.p384 = aliases.secp384r1;
  7854. aliases.p521 = aliases.secp521r1;
  7855. function ECDH(curve) {
  7856. this.curveType = aliases[curve];
  7857. if (!this.curveType ) {
  7858. this.curveType = {
  7859. name: curve
  7860. };
  7861. }
  7862. this.curve = new elliptic.ec(this.curveType.name);
  7863. this.keys = void 0;
  7864. }
  7865. ECDH.prototype.generateKeys = function (enc, format) {
  7866. this.keys = this.curve.genKeyPair();
  7867. return this.getPublicKey(enc, format);
  7868. };
  7869. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  7870. inenc = inenc || 'utf8';
  7871. if (!Buffer.isBuffer(other)) {
  7872. other = new Buffer(other, inenc);
  7873. }
  7874. var otherPub = this.curve.keyFromPublic(other).getPublic();
  7875. var out = otherPub.mul(this.keys.getPrivate()).getX();
  7876. return formatReturnValue(out, enc, this.curveType.byteLength);
  7877. };
  7878. ECDH.prototype.getPublicKey = function (enc, format) {
  7879. var key = this.keys.getPublic(format === 'compressed', true);
  7880. if (format === 'hybrid') {
  7881. if (key[key.length - 1] % 2) {
  7882. key[0] = 7;
  7883. } else {
  7884. key [0] = 6;
  7885. }
  7886. }
  7887. return formatReturnValue(key, enc);
  7888. };
  7889. ECDH.prototype.getPrivateKey = function (enc) {
  7890. return formatReturnValue(this.keys.getPrivate(), enc);
  7891. };
  7892. ECDH.prototype.setPublicKey = function (pub, enc) {
  7893. enc = enc || 'utf8';
  7894. if (!Buffer.isBuffer(pub)) {
  7895. pub = new Buffer(pub, enc);
  7896. }
  7897. this.keys._importPublic(pub);
  7898. return this;
  7899. };
  7900. ECDH.prototype.setPrivateKey = function (priv, enc) {
  7901. enc = enc || 'utf8';
  7902. if (!Buffer.isBuffer(priv)) {
  7903. priv = new Buffer(priv, enc);
  7904. }
  7905. var _priv = new BN(priv);
  7906. _priv = _priv.toString(16);
  7907. this.keys._importPrivate(_priv);
  7908. return this;
  7909. };
  7910. function formatReturnValue(bn, enc, len) {
  7911. if (!Array.isArray(bn)) {
  7912. bn = bn.toArray();
  7913. }
  7914. var buf = new Buffer(bn);
  7915. if (len && buf.length < len) {
  7916. var zeros = new Buffer(len - buf.length);
  7917. zeros.fill(0);
  7918. buf = Buffer.concat([zeros, buf]);
  7919. }
  7920. if (!enc) {
  7921. return buf;
  7922. } else {
  7923. return buf.toString(enc);
  7924. }
  7925. }
  7926. }).call(this,require("buffer").Buffer)
  7927. },{"bn.js":18,"buffer":46,"elliptic":65}],50:[function(require,module,exports){
  7928. (function (Buffer){
  7929. 'use strict';
  7930. var inherits = require('inherits')
  7931. var md5 = require('./md5')
  7932. var rmd160 = require('ripemd160')
  7933. var sha = require('sha.js')
  7934. var Base = require('cipher-base')
  7935. function HashNoConstructor(hash) {
  7936. Base.call(this, 'digest')
  7937. this._hash = hash
  7938. this.buffers = []
  7939. }
  7940. inherits(HashNoConstructor, Base)
  7941. HashNoConstructor.prototype._update = function (data) {
  7942. this.buffers.push(data)
  7943. }
  7944. HashNoConstructor.prototype._final = function () {
  7945. var buf = Buffer.concat(this.buffers)
  7946. var r = this._hash(buf)
  7947. this.buffers = null
  7948. return r
  7949. }
  7950. function Hash(hash) {
  7951. Base.call(this, 'digest')
  7952. this._hash = hash
  7953. }
  7954. inherits(Hash, Base)
  7955. Hash.prototype._update = function (data) {
  7956. this._hash.update(data)
  7957. }
  7958. Hash.prototype._final = function () {
  7959. return this._hash.digest()
  7960. }
  7961. module.exports = function createHash (alg) {
  7962. alg = alg.toLowerCase()
  7963. if ('md5' === alg) return new HashNoConstructor(md5)
  7964. if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
  7965. return new Hash(sha(alg))
  7966. }
  7967. }).call(this,require("buffer").Buffer)
  7968. },{"./md5":52,"buffer":46,"cipher-base":47,"inherits":92,"ripemd160":128,"sha.js":130}],51:[function(require,module,exports){
  7969. (function (Buffer){
  7970. 'use strict';
  7971. var intSize = 4;
  7972. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  7973. var chrsz = 8;
  7974. function toArray(buf, bigEndian) {
  7975. if ((buf.length % intSize) !== 0) {
  7976. var len = buf.length + (intSize - (buf.length % intSize));
  7977. buf = Buffer.concat([buf, zeroBuffer], len);
  7978. }
  7979. var arr = [];
  7980. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  7981. for (var i = 0; i < buf.length; i += intSize) {
  7982. arr.push(fn.call(buf, i));
  7983. }
  7984. return arr;
  7985. }
  7986. function toBuffer(arr, size, bigEndian) {
  7987. var buf = new Buffer(size);
  7988. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  7989. for (var i = 0; i < arr.length; i++) {
  7990. fn.call(buf, arr[i], i * 4, true);
  7991. }
  7992. return buf;
  7993. }
  7994. function hash(buf, fn, hashSize, bigEndian) {
  7995. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  7996. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  7997. return toBuffer(arr, hashSize, bigEndian);
  7998. }
  7999. exports.hash = hash;
  8000. }).call(this,require("buffer").Buffer)
  8001. },{"buffer":46}],52:[function(require,module,exports){
  8002. 'use strict';
  8003. /*
  8004. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  8005. * Digest Algorithm, as defined in RFC 1321.
  8006. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  8007. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  8008. * Distributed under the BSD License
  8009. * See http://pajhome.org.uk/crypt/md5 for more info.
  8010. */
  8011. var helpers = require('./helpers');
  8012. /*
  8013. * Calculate the MD5 of an array of little-endian words, and a bit length
  8014. */
  8015. function core_md5(x, len)
  8016. {
  8017. /* append padding */
  8018. x[len >> 5] |= 0x80 << ((len) % 32);
  8019. x[(((len + 64) >>> 9) << 4) + 14] = len;
  8020. var a = 1732584193;
  8021. var b = -271733879;
  8022. var c = -1732584194;
  8023. var d = 271733878;
  8024. for(var i = 0; i < x.length; i += 16)
  8025. {
  8026. var olda = a;
  8027. var oldb = b;
  8028. var oldc = c;
  8029. var oldd = d;
  8030. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  8031. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  8032. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  8033. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  8034. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  8035. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  8036. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  8037. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  8038. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  8039. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  8040. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  8041. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  8042. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  8043. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  8044. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  8045. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  8046. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  8047. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  8048. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  8049. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  8050. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  8051. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  8052. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  8053. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  8054. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  8055. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  8056. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  8057. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  8058. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  8059. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  8060. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  8061. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  8062. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  8063. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  8064. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  8065. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  8066. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  8067. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  8068. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  8069. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  8070. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  8071. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  8072. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  8073. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  8074. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  8075. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  8076. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  8077. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  8078. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  8079. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  8080. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  8081. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  8082. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  8083. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  8084. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  8085. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  8086. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  8087. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  8088. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  8089. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  8090. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  8091. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  8092. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  8093. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  8094. a = safe_add(a, olda);
  8095. b = safe_add(b, oldb);
  8096. c = safe_add(c, oldc);
  8097. d = safe_add(d, oldd);
  8098. }
  8099. return Array(a, b, c, d);
  8100. }
  8101. /*
  8102. * These functions implement the four basic operations the algorithm uses.
  8103. */
  8104. function md5_cmn(q, a, b, x, s, t)
  8105. {
  8106. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  8107. }
  8108. function md5_ff(a, b, c, d, x, s, t)
  8109. {
  8110. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  8111. }
  8112. function md5_gg(a, b, c, d, x, s, t)
  8113. {
  8114. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  8115. }
  8116. function md5_hh(a, b, c, d, x, s, t)
  8117. {
  8118. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  8119. }
  8120. function md5_ii(a, b, c, d, x, s, t)
  8121. {
  8122. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  8123. }
  8124. /*
  8125. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  8126. * to work around bugs in some JS interpreters.
  8127. */
  8128. function safe_add(x, y)
  8129. {
  8130. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  8131. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  8132. return (msw << 16) | (lsw & 0xFFFF);
  8133. }
  8134. /*
  8135. * Bitwise rotate a 32-bit number to the left.
  8136. */
  8137. function bit_rol(num, cnt)
  8138. {
  8139. return (num << cnt) | (num >>> (32 - cnt));
  8140. }
  8141. module.exports = function md5(buf) {
  8142. return helpers.hash(buf, core_md5, 16);
  8143. };
  8144. },{"./helpers":51}],53:[function(require,module,exports){
  8145. (function (Buffer){
  8146. 'use strict';
  8147. var createHash = require('create-hash/browser');
  8148. var inherits = require('inherits')
  8149. var Transform = require('stream').Transform
  8150. var ZEROS = new Buffer(128)
  8151. ZEROS.fill(0)
  8152. function Hmac(alg, key) {
  8153. Transform.call(this)
  8154. alg = alg.toLowerCase()
  8155. if (typeof key === 'string') {
  8156. key = new Buffer(key)
  8157. }
  8158. var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
  8159. this._alg = alg
  8160. this._key = key
  8161. if (key.length > blocksize) {
  8162. key = createHash(alg).update(key).digest()
  8163. } else if (key.length < blocksize) {
  8164. key = Buffer.concat([key, ZEROS], blocksize)
  8165. }
  8166. var ipad = this._ipad = new Buffer(blocksize)
  8167. var opad = this._opad = new Buffer(blocksize)
  8168. for (var i = 0; i < blocksize; i++) {
  8169. ipad[i] = key[i] ^ 0x36
  8170. opad[i] = key[i] ^ 0x5C
  8171. }
  8172. this._hash = createHash(alg).update(ipad)
  8173. }
  8174. inherits(Hmac, Transform)
  8175. Hmac.prototype.update = function (data, enc) {
  8176. this._hash.update(data, enc)
  8177. return this
  8178. }
  8179. Hmac.prototype._transform = function (data, _, next) {
  8180. this._hash.update(data)
  8181. next()
  8182. }
  8183. Hmac.prototype._flush = function (next) {
  8184. this.push(this.digest())
  8185. next()
  8186. }
  8187. Hmac.prototype.digest = function (enc) {
  8188. var h = this._hash.digest()
  8189. return createHash(this._alg).update(this._opad).update(h).digest(enc)
  8190. }
  8191. module.exports = function createHmac(alg, key) {
  8192. return new Hmac(alg, key)
  8193. }
  8194. }).call(this,require("buffer").Buffer)
  8195. },{"buffer":46,"create-hash/browser":50,"inherits":92,"stream":137}],54:[function(require,module,exports){
  8196. 'use strict'
  8197. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
  8198. exports.createHash = exports.Hash = require('create-hash')
  8199. exports.createHmac = exports.Hmac = require('create-hmac')
  8200. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos')))
  8201. exports.getHashes = function () {
  8202. return hashes
  8203. }
  8204. var p = require('pbkdf2')
  8205. exports.pbkdf2 = p.pbkdf2
  8206. exports.pbkdf2Sync = p.pbkdf2Sync
  8207. var aes = require('browserify-cipher')
  8208. ;[
  8209. 'Cipher',
  8210. 'createCipher',
  8211. 'Cipheriv',
  8212. 'createCipheriv',
  8213. 'Decipher',
  8214. 'createDecipher',
  8215. 'Decipheriv',
  8216. 'createDecipheriv',
  8217. 'getCiphers',
  8218. 'listCiphers'
  8219. ].forEach(function (key) {
  8220. exports[key] = aes[key]
  8221. })
  8222. var dh = require('diffie-hellman')
  8223. ;[
  8224. 'DiffieHellmanGroup',
  8225. 'createDiffieHellmanGroup',
  8226. 'getDiffieHellman',
  8227. 'createDiffieHellman',
  8228. 'DiffieHellman'
  8229. ].forEach(function (key) {
  8230. exports[key] = dh[key]
  8231. })
  8232. var sign = require('browserify-sign')
  8233. ;[
  8234. 'createSign',
  8235. 'Sign',
  8236. 'createVerify',
  8237. 'Verify'
  8238. ].forEach(function (key) {
  8239. exports[key] = sign[key]
  8240. })
  8241. exports.createECDH = require('create-ecdh')
  8242. var publicEncrypt = require('public-encrypt')
  8243. ;[
  8244. 'publicEncrypt',
  8245. 'privateEncrypt',
  8246. 'publicDecrypt',
  8247. 'privateDecrypt'
  8248. ].forEach(function (key) {
  8249. exports[key] = publicEncrypt[key]
  8250. })
  8251. // the least I can do is make error messages for the rest of the node.js/crypto api.
  8252. ;[
  8253. 'createCredentials'
  8254. ].forEach(function (name) {
  8255. exports[name] = function () {
  8256. throw new Error([
  8257. 'sorry, ' + name + ' is not implemented yet',
  8258. 'we accept pull requests',
  8259. 'https://github.com/crypto-browserify/crypto-browserify'
  8260. ].join('\n'))
  8261. }
  8262. })
  8263. },{"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){
  8264. 'use strict';
  8265. exports.utils = require('./des/utils');
  8266. exports.Cipher = require('./des/cipher');
  8267. exports.DES = require('./des/des');
  8268. exports.CBC = require('./des/cbc');
  8269. exports.EDE = require('./des/ede');
  8270. },{"./des/cbc":56,"./des/cipher":57,"./des/des":58,"./des/ede":59,"./des/utils":60}],56:[function(require,module,exports){
  8271. 'use strict';
  8272. var assert = require('minimalistic-assert');
  8273. var inherits = require('inherits');
  8274. var proto = {};
  8275. function CBCState(iv) {
  8276. assert.equal(iv.length, 8, 'Invalid IV length');
  8277. this.iv = new Array(8);
  8278. for (var i = 0; i < this.iv.length; i++)
  8279. this.iv[i] = iv[i];
  8280. }
  8281. function instantiate(Base) {
  8282. function CBC(options) {
  8283. Base.call(this, options);
  8284. this._cbcInit();
  8285. }
  8286. inherits(CBC, Base);
  8287. var keys = Object.keys(proto);
  8288. for (var i = 0; i < keys.length; i++) {
  8289. var key = keys[i];
  8290. CBC.prototype[key] = proto[key];
  8291. }
  8292. CBC.create = function create(options) {
  8293. return new CBC(options);
  8294. };
  8295. return CBC;
  8296. }
  8297. exports.instantiate = instantiate;
  8298. proto._cbcInit = function _cbcInit() {
  8299. var state = new CBCState(this.options.iv);
  8300. this._cbcState = state;
  8301. };
  8302. proto._update = function _update(inp, inOff, out, outOff) {
  8303. var state = this._cbcState;
  8304. var superProto = this.constructor.super_.prototype;
  8305. var iv = state.iv;
  8306. if (this.type === 'encrypt') {
  8307. for (var i = 0; i < this.blockSize; i++)
  8308. iv[i] ^= inp[inOff + i];
  8309. superProto._update.call(this, iv, 0, out, outOff);
  8310. for (var i = 0; i < this.blockSize; i++)
  8311. iv[i] = out[outOff + i];
  8312. } else {
  8313. superProto._update.call(this, inp, inOff, out, outOff);
  8314. for (var i = 0; i < this.blockSize; i++)
  8315. out[outOff + i] ^= iv[i];
  8316. for (var i = 0; i < this.blockSize; i++)
  8317. iv[i] = inp[inOff + i];
  8318. }
  8319. };
  8320. },{"inherits":92,"minimalistic-assert":99}],57:[function(require,module,exports){
  8321. 'use strict';
  8322. var assert = require('minimalistic-assert');
  8323. function Cipher(options) {
  8324. this.options = options;
  8325. this.type = this.options.type;
  8326. this.blockSize = 8;
  8327. this._init();
  8328. this.buffer = new Array(this.blockSize);
  8329. this.bufferOff = 0;
  8330. }
  8331. module.exports = Cipher;
  8332. Cipher.prototype._init = function _init() {
  8333. // Might be overrided
  8334. };
  8335. Cipher.prototype.update = function update(data) {
  8336. if (data.length === 0)
  8337. return [];
  8338. if (this.type === 'decrypt')
  8339. return this._updateDecrypt(data);
  8340. else
  8341. return this._updateEncrypt(data);
  8342. };
  8343. Cipher.prototype._buffer = function _buffer(data, off) {
  8344. // Append data to buffer
  8345. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  8346. for (var i = 0; i < min; i++)
  8347. this.buffer[this.bufferOff + i] = data[off + i];
  8348. this.bufferOff += min;
  8349. // Shift next
  8350. return min;
  8351. };
  8352. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  8353. this._update(this.buffer, 0, out, off);
  8354. this.bufferOff = 0;
  8355. return this.blockSize;
  8356. };
  8357. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  8358. var inputOff = 0;
  8359. var outputOff = 0;
  8360. var count = ((this.bufferOff + data.length) / this.blockSize) | 0;
  8361. var out = new Array(count * this.blockSize);
  8362. if (this.bufferOff !== 0) {
  8363. inputOff += this._buffer(data, inputOff);
  8364. if (this.bufferOff === this.buffer.length)
  8365. outputOff += this._flushBuffer(out, outputOff);
  8366. }
  8367. // Write blocks
  8368. var max = data.length - ((data.length - inputOff) % this.blockSize);
  8369. for (; inputOff < max; inputOff += this.blockSize) {
  8370. this._update(data, inputOff, out, outputOff);
  8371. outputOff += this.blockSize;
  8372. }
  8373. // Queue rest
  8374. for (; inputOff < data.length; inputOff++, this.bufferOff++)
  8375. this.buffer[this.bufferOff] = data[inputOff];
  8376. return out;
  8377. };
  8378. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  8379. var inputOff = 0;
  8380. var outputOff = 0;
  8381. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  8382. var out = new Array(count * this.blockSize);
  8383. // TODO(indutny): optimize it, this is far from optimal
  8384. for (; count > 0; count--) {
  8385. inputOff += this._buffer(data, inputOff);
  8386. outputOff += this._flushBuffer(out, outputOff);
  8387. }
  8388. // Buffer rest of the input
  8389. inputOff += this._buffer(data, inputOff);
  8390. return out;
  8391. };
  8392. Cipher.prototype.final = function final(buffer) {
  8393. var first;
  8394. if (buffer)
  8395. first = this.update(buffer);
  8396. var last;
  8397. if (this.type === 'encrypt')
  8398. last = this._finalEncrypt();
  8399. else
  8400. last = this._finalDecrypt();
  8401. if (first)
  8402. return first.concat(last);
  8403. else
  8404. return last;
  8405. };
  8406. Cipher.prototype._pad = function _pad(buffer, off) {
  8407. if (off === 0)
  8408. return false;
  8409. while (off < buffer.length)
  8410. buffer[off++] = 0;
  8411. return true;
  8412. };
  8413. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  8414. if (!this._pad(this.buffer, this.bufferOff))
  8415. return [];
  8416. var out = new Array(this.blockSize);
  8417. this._update(this.buffer, 0, out, 0);
  8418. return out;
  8419. };
  8420. Cipher.prototype._unpad = function _unpad(buffer) {
  8421. return buffer;
  8422. };
  8423. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  8424. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  8425. var out = new Array(this.blockSize);
  8426. this._flushBuffer(out, 0);
  8427. return this._unpad(out);
  8428. };
  8429. },{"minimalistic-assert":99}],58:[function(require,module,exports){
  8430. 'use strict';
  8431. var assert = require('minimalistic-assert');
  8432. var inherits = require('inherits');
  8433. var des = require('../des');
  8434. var utils = des.utils;
  8435. var Cipher = des.Cipher;
  8436. function DESState() {
  8437. this.tmp = new Array(2);
  8438. this.keys = null;
  8439. }
  8440. function DES(options) {
  8441. Cipher.call(this, options);
  8442. var state = new DESState();
  8443. this._desState = state;
  8444. this.deriveKeys(state, options.key);
  8445. }
  8446. inherits(DES, Cipher);
  8447. module.exports = DES;
  8448. DES.create = function create(options) {
  8449. return new DES(options);
  8450. };
  8451. var shiftTable = [
  8452. 1, 1, 2, 2, 2, 2, 2, 2,
  8453. 1, 2, 2, 2, 2, 2, 2, 1
  8454. ];
  8455. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  8456. state.keys = new Array(16 * 2);
  8457. assert.equal(key.length, this.blockSize, 'Invalid key length');
  8458. var kL = utils.readUInt32BE(key, 0);
  8459. var kR = utils.readUInt32BE(key, 4);
  8460. utils.pc1(kL, kR, state.tmp, 0);
  8461. kL = state.tmp[0];
  8462. kR = state.tmp[1];
  8463. for (var i = 0; i < state.keys.length; i += 2) {
  8464. var shift = shiftTable[i >>> 1];
  8465. kL = utils.r28shl(kL, shift);
  8466. kR = utils.r28shl(kR, shift);
  8467. utils.pc2(kL, kR, state.keys, i);
  8468. }
  8469. };
  8470. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  8471. var state = this._desState;
  8472. var l = utils.readUInt32BE(inp, inOff);
  8473. var r = utils.readUInt32BE(inp, inOff + 4);
  8474. // Initial Permutation
  8475. utils.ip(l, r, state.tmp, 0);
  8476. l = state.tmp[0];
  8477. r = state.tmp[1];
  8478. if (this.type === 'encrypt')
  8479. this._encrypt(state, l, r, state.tmp, 0);
  8480. else
  8481. this._decrypt(state, l, r, state.tmp, 0);
  8482. l = state.tmp[0];
  8483. r = state.tmp[1];
  8484. utils.writeUInt32BE(out, l, outOff);
  8485. utils.writeUInt32BE(out, r, outOff + 4);
  8486. };
  8487. DES.prototype._pad = function _pad(buffer, off) {
  8488. var value = buffer.length - off;
  8489. for (var i = off; i < buffer.length; i++)
  8490. buffer[i] = value;
  8491. return true;
  8492. };
  8493. DES.prototype._unpad = function _unpad(buffer) {
  8494. var pad = buffer[buffer.length - 1];
  8495. for (var i = buffer.length - pad; i < buffer.length; i++)
  8496. assert.equal(buffer[i], pad);
  8497. return buffer.slice(0, buffer.length - pad);
  8498. };
  8499. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  8500. var l = lStart;
  8501. var r = rStart;
  8502. // Apply f() x16 times
  8503. for (var i = 0; i < state.keys.length; i += 2) {
  8504. var keyL = state.keys[i];
  8505. var keyR = state.keys[i + 1];
  8506. // f(r, k)
  8507. utils.expand(r, state.tmp, 0);
  8508. keyL ^= state.tmp[0];
  8509. keyR ^= state.tmp[1];
  8510. var s = utils.substitute(keyL, keyR);
  8511. var f = utils.permute(s);
  8512. var t = r;
  8513. r = (l ^ f) >>> 0;
  8514. l = t;
  8515. }
  8516. // Reverse Initial Permutation
  8517. utils.rip(r, l, out, off);
  8518. };
  8519. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  8520. var l = rStart;
  8521. var r = lStart;
  8522. // Apply f() x16 times
  8523. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  8524. var keyL = state.keys[i];
  8525. var keyR = state.keys[i + 1];
  8526. // f(r, k)
  8527. utils.expand(l, state.tmp, 0);
  8528. keyL ^= state.tmp[0];
  8529. keyR ^= state.tmp[1];
  8530. var s = utils.substitute(keyL, keyR);
  8531. var f = utils.permute(s);
  8532. var t = l;
  8533. l = (r ^ f) >>> 0;
  8534. r = t;
  8535. }
  8536. // Reverse Initial Permutation
  8537. utils.rip(l, r, out, off);
  8538. };
  8539. },{"../des":55,"inherits":92,"minimalistic-assert":99}],59:[function(require,module,exports){
  8540. 'use strict';
  8541. var assert = require('minimalistic-assert');
  8542. var inherits = require('inherits');
  8543. var des = require('../des');
  8544. var Cipher = des.Cipher;
  8545. var DES = des.DES;
  8546. function EDEState(type, key) {
  8547. assert.equal(key.length, 24, 'Invalid key length');
  8548. var k1 = key.slice(0, 8);
  8549. var k2 = key.slice(8, 16);
  8550. var k3 = key.slice(16, 24);
  8551. if (type === 'encrypt') {
  8552. this.ciphers = [
  8553. DES.create({ type: 'encrypt', key: k1 }),
  8554. DES.create({ type: 'decrypt', key: k2 }),
  8555. DES.create({ type: 'encrypt', key: k3 })
  8556. ];
  8557. } else {
  8558. this.ciphers = [
  8559. DES.create({ type: 'decrypt', key: k3 }),
  8560. DES.create({ type: 'encrypt', key: k2 }),
  8561. DES.create({ type: 'decrypt', key: k1 })
  8562. ];
  8563. }
  8564. }
  8565. function EDE(options) {
  8566. Cipher.call(this, options);
  8567. var state = new EDEState(this.type, this.options.key);
  8568. this._edeState = state;
  8569. }
  8570. inherits(EDE, Cipher);
  8571. module.exports = EDE;
  8572. EDE.create = function create(options) {
  8573. return new EDE(options);
  8574. };
  8575. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  8576. var state = this._edeState;
  8577. state.ciphers[0]._update(inp, inOff, out, outOff);
  8578. state.ciphers[1]._update(out, outOff, out, outOff);
  8579. state.ciphers[2]._update(out, outOff, out, outOff);
  8580. };
  8581. EDE.prototype._pad = DES.prototype._pad;
  8582. EDE.prototype._unpad = DES.prototype._unpad;
  8583. },{"../des":55,"inherits":92,"minimalistic-assert":99}],60:[function(require,module,exports){
  8584. 'use strict';
  8585. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  8586. var res = (bytes[0 + off] << 24) |
  8587. (bytes[1 + off] << 16) |
  8588. (bytes[2 + off] << 8) |
  8589. bytes[3 + off];
  8590. return res >>> 0;
  8591. };
  8592. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  8593. bytes[0 + off] = value >>> 24;
  8594. bytes[1 + off] = (value >>> 16) & 0xff;
  8595. bytes[2 + off] = (value >>> 8) & 0xff;
  8596. bytes[3 + off] = value & 0xff;
  8597. };
  8598. exports.ip = function ip(inL, inR, out, off) {
  8599. var outL = 0;
  8600. var outR = 0;
  8601. for (var i = 6; i >= 0; i -= 2) {
  8602. for (var j = 0; j <= 24; j += 8) {
  8603. outL <<= 1;
  8604. outL |= (inR >>> (j + i)) & 1;
  8605. }
  8606. for (var j = 0; j <= 24; j += 8) {
  8607. outL <<= 1;
  8608. outL |= (inL >>> (j + i)) & 1;
  8609. }
  8610. }
  8611. for (var i = 6; i >= 0; i -= 2) {
  8612. for (var j = 1; j <= 25; j += 8) {
  8613. outR <<= 1;
  8614. outR |= (inR >>> (j + i)) & 1;
  8615. }
  8616. for (var j = 1; j <= 25; j += 8) {
  8617. outR <<= 1;
  8618. outR |= (inL >>> (j + i)) & 1;
  8619. }
  8620. }
  8621. out[off + 0] = outL >>> 0;
  8622. out[off + 1] = outR >>> 0;
  8623. };
  8624. exports.rip = function rip(inL, inR, out, off) {
  8625. var outL = 0;
  8626. var outR = 0;
  8627. for (var i = 0; i < 4; i++) {
  8628. for (var j = 24; j >= 0; j -= 8) {
  8629. outL <<= 1;
  8630. outL |= (inR >>> (j + i)) & 1;
  8631. outL <<= 1;
  8632. outL |= (inL >>> (j + i)) & 1;
  8633. }
  8634. }
  8635. for (var i = 4; i < 8; i++) {
  8636. for (var j = 24; j >= 0; j -= 8) {
  8637. outR <<= 1;
  8638. outR |= (inR >>> (j + i)) & 1;
  8639. outR <<= 1;
  8640. outR |= (inL >>> (j + i)) & 1;
  8641. }
  8642. }
  8643. out[off + 0] = outL >>> 0;
  8644. out[off + 1] = outR >>> 0;
  8645. };
  8646. exports.pc1 = function pc1(inL, inR, out, off) {
  8647. var outL = 0;
  8648. var outR = 0;
  8649. // 7, 15, 23, 31, 39, 47, 55, 63
  8650. // 6, 14, 22, 30, 39, 47, 55, 63
  8651. // 5, 13, 21, 29, 39, 47, 55, 63
  8652. // 4, 12, 20, 28
  8653. for (var i = 7; i >= 5; i--) {
  8654. for (var j = 0; j <= 24; j += 8) {
  8655. outL <<= 1;
  8656. outL |= (inR >> (j + i)) & 1;
  8657. }
  8658. for (var j = 0; j <= 24; j += 8) {
  8659. outL <<= 1;
  8660. outL |= (inL >> (j + i)) & 1;
  8661. }
  8662. }
  8663. for (var j = 0; j <= 24; j += 8) {
  8664. outL <<= 1;
  8665. outL |= (inR >> (j + i)) & 1;
  8666. }
  8667. // 1, 9, 17, 25, 33, 41, 49, 57
  8668. // 2, 10, 18, 26, 34, 42, 50, 58
  8669. // 3, 11, 19, 27, 35, 43, 51, 59
  8670. // 36, 44, 52, 60
  8671. for (var i = 1; i <= 3; i++) {
  8672. for (var j = 0; j <= 24; j += 8) {
  8673. outR <<= 1;
  8674. outR |= (inR >> (j + i)) & 1;
  8675. }
  8676. for (var j = 0; j <= 24; j += 8) {
  8677. outR <<= 1;
  8678. outR |= (inL >> (j + i)) & 1;
  8679. }
  8680. }
  8681. for (var j = 0; j <= 24; j += 8) {
  8682. outR <<= 1;
  8683. outR |= (inL >> (j + i)) & 1;
  8684. }
  8685. out[off + 0] = outL >>> 0;
  8686. out[off + 1] = outR >>> 0;
  8687. };
  8688. exports.r28shl = function r28shl(num, shift) {
  8689. return ((num << shift) & 0xfffffff) | (num >>> (28 - shift));
  8690. };
  8691. var pc2table = [
  8692. // inL => outL
  8693. 14, 11, 17, 4, 27, 23, 25, 0,
  8694. 13, 22, 7, 18, 5, 9, 16, 24,
  8695. 2, 20, 12, 21, 1, 8, 15, 26,
  8696. // inR => outR
  8697. 15, 4, 25, 19, 9, 1, 26, 16,
  8698. 5, 11, 23, 8, 12, 7, 17, 0,
  8699. 22, 3, 10, 14, 6, 20, 27, 24
  8700. ];
  8701. exports.pc2 = function pc2(inL, inR, out, off) {
  8702. var outL = 0;
  8703. var outR = 0;
  8704. var len = pc2table.length >>> 1;
  8705. for (var i = 0; i < len; i++) {
  8706. outL <<= 1;
  8707. outL |= (inL >>> pc2table[i]) & 0x1;
  8708. }
  8709. for (var i = len; i < pc2table.length; i++) {
  8710. outR <<= 1;
  8711. outR |= (inR >>> pc2table[i]) & 0x1;
  8712. }
  8713. out[off + 0] = outL >>> 0;
  8714. out[off + 1] = outR >>> 0;
  8715. };
  8716. exports.expand = function expand(r, out, off) {
  8717. var outL = 0;
  8718. var outR = 0;
  8719. outL = ((r & 1) << 5) | (r >>> 27);
  8720. for (var i = 23; i >= 15; i -= 4) {
  8721. outL <<= 6;
  8722. outL |= (r >>> i) & 0x3f;
  8723. }
  8724. for (var i = 11; i >= 3; i -= 4) {
  8725. outR |= (r >>> i) & 0x3f;
  8726. outR <<= 6;
  8727. }
  8728. outR |= ((r & 0x1f) << 1) | (r >>> 31);
  8729. out[off + 0] = outL >>> 0;
  8730. out[off + 1] = outR >>> 0;
  8731. };
  8732. var sTable = [
  8733. 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
  8734. 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
  8735. 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
  8736. 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13,
  8737. 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
  8738. 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
  8739. 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
  8740. 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9,
  8741. 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
  8742. 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
  8743. 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
  8744. 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12,
  8745. 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
  8746. 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
  8747. 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
  8748. 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14,
  8749. 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
  8750. 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
  8751. 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
  8752. 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3,
  8753. 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
  8754. 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
  8755. 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
  8756. 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13,
  8757. 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
  8758. 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
  8759. 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
  8760. 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12,
  8761. 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
  8762. 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
  8763. 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
  8764. 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
  8765. ];
  8766. exports.substitute = function substitute(inL, inR) {
  8767. var out = 0;
  8768. for (var i = 0; i < 4; i++) {
  8769. var b = (inL >>> (18 - i * 6)) & 0x3f;
  8770. var sb = sTable[i * 0x40 + b];
  8771. out <<= 4;
  8772. out |= sb;
  8773. }
  8774. for (var i = 0; i < 4; i++) {
  8775. var b = (inR >>> (18 - i * 6)) & 0x3f;
  8776. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  8777. out <<= 4;
  8778. out |= sb;
  8779. }
  8780. return out >>> 0;
  8781. };
  8782. var permuteTable = [
  8783. 16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
  8784. 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7
  8785. ];
  8786. exports.permute = function permute(num) {
  8787. var out = 0;
  8788. for (var i = 0; i < permuteTable.length; i++) {
  8789. out <<= 1;
  8790. out |= (num >>> permuteTable[i]) & 0x1;
  8791. }
  8792. return out >>> 0;
  8793. };
  8794. exports.padSplit = function padSplit(num, size, group) {
  8795. var str = num.toString(2);
  8796. while (str.length < size)
  8797. str = '0' + str;
  8798. var out = [];
  8799. for (var i = 0; i < size; i += group)
  8800. out.push(str.slice(i, i + group));
  8801. return out.join(' ');
  8802. };
  8803. },{}],61:[function(require,module,exports){
  8804. (function (Buffer){
  8805. var generatePrime = require('./lib/generatePrime')
  8806. var primes = require('./lib/primes.json')
  8807. var DH = require('./lib/dh')
  8808. function getDiffieHellman (mod) {
  8809. var prime = new Buffer(primes[mod].prime, 'hex')
  8810. var gen = new Buffer(primes[mod].gen, 'hex')
  8811. return new DH(prime, gen)
  8812. }
  8813. var ENCODINGS = {
  8814. 'binary': true, 'hex': true, 'base64': true
  8815. }
  8816. function createDiffieHellman (prime, enc, generator, genc) {
  8817. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  8818. return createDiffieHellman(prime, 'binary', enc, generator)
  8819. }
  8820. enc = enc || 'binary'
  8821. genc = genc || 'binary'
  8822. generator = generator || new Buffer([2])
  8823. if (!Buffer.isBuffer(generator)) {
  8824. generator = new Buffer(generator, genc)
  8825. }
  8826. if (typeof prime === 'number') {
  8827. return new DH(generatePrime(prime, generator), generator, true)
  8828. }
  8829. if (!Buffer.isBuffer(prime)) {
  8830. prime = new Buffer(prime, enc)
  8831. }
  8832. return new DH(prime, generator, true)
  8833. }
  8834. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
  8835. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman
  8836. }).call(this,require("buffer").Buffer)
  8837. },{"./lib/dh":62,"./lib/generatePrime":63,"./lib/primes.json":64,"buffer":46}],62:[function(require,module,exports){
  8838. (function (Buffer){
  8839. var BN = require('bn.js');
  8840. var MillerRabin = require('miller-rabin');
  8841. var millerRabin = new MillerRabin();
  8842. var TWENTYFOUR = new BN(24);
  8843. var ELEVEN = new BN(11);
  8844. var TEN = new BN(10);
  8845. var THREE = new BN(3);
  8846. var SEVEN = new BN(7);
  8847. var primes = require('./generatePrime');
  8848. var randomBytes = require('randombytes');
  8849. module.exports = DH;
  8850. function setPublicKey(pub, enc) {
  8851. enc = enc || 'utf8';
  8852. if (!Buffer.isBuffer(pub)) {
  8853. pub = new Buffer(pub, enc);
  8854. }
  8855. this._pub = new BN(pub);
  8856. return this;
  8857. }
  8858. function setPrivateKey(priv, enc) {
  8859. enc = enc || 'utf8';
  8860. if (!Buffer.isBuffer(priv)) {
  8861. priv = new Buffer(priv, enc);
  8862. }
  8863. this._priv = new BN(priv);
  8864. return this;
  8865. }
  8866. var primeCache = {};
  8867. function checkPrime(prime, generator) {
  8868. var gen = generator.toString('hex');
  8869. var hex = [gen, prime.toString(16)].join('_');
  8870. if (hex in primeCache) {
  8871. return primeCache[hex];
  8872. }
  8873. var error = 0;
  8874. if (prime.isEven() ||
  8875. !primes.simpleSieve ||
  8876. !primes.fermatTest(prime) ||
  8877. !millerRabin.test(prime)) {
  8878. //not a prime so +1
  8879. error += 1;
  8880. if (gen === '02' || gen === '05') {
  8881. // we'd be able to check the generator
  8882. // it would fail so +8
  8883. error += 8;
  8884. } else {
  8885. //we wouldn't be able to test the generator
  8886. // so +4
  8887. error += 4;
  8888. }
  8889. primeCache[hex] = error;
  8890. return error;
  8891. }
  8892. if (!millerRabin.test(prime.shrn(1))) {
  8893. //not a safe prime
  8894. error += 2;
  8895. }
  8896. var rem;
  8897. switch (gen) {
  8898. case '02':
  8899. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  8900. // unsuidable generator
  8901. error += 8;
  8902. }
  8903. break;
  8904. case '05':
  8905. rem = prime.mod(TEN);
  8906. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  8907. // prime mod 10 needs to equal 3 or 7
  8908. error += 8;
  8909. }
  8910. break;
  8911. default:
  8912. error += 4;
  8913. }
  8914. primeCache[hex] = error;
  8915. return error;
  8916. }
  8917. function DH(prime, generator, malleable) {
  8918. this.setGenerator(generator);
  8919. this.__prime = new BN(prime);
  8920. this._prime = BN.mont(this.__prime);
  8921. this._primeLen = prime.length;
  8922. this._pub = undefined;
  8923. this._priv = undefined;
  8924. this._primeCode = undefined;
  8925. if (malleable) {
  8926. this.setPublicKey = setPublicKey;
  8927. this.setPrivateKey = setPrivateKey;
  8928. } else {
  8929. this._primeCode = 8;
  8930. }
  8931. }
  8932. Object.defineProperty(DH.prototype, 'verifyError', {
  8933. enumerable: true,
  8934. get: function () {
  8935. if (typeof this._primeCode !== 'number') {
  8936. this._primeCode = checkPrime(this.__prime, this.__gen);
  8937. }
  8938. return this._primeCode;
  8939. }
  8940. });
  8941. DH.prototype.generateKeys = function () {
  8942. if (!this._priv) {
  8943. this._priv = new BN(randomBytes(this._primeLen));
  8944. }
  8945. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  8946. return this.getPublicKey();
  8947. };
  8948. DH.prototype.computeSecret = function (other) {
  8949. other = new BN(other);
  8950. other = other.toRed(this._prime);
  8951. var secret = other.redPow(this._priv).fromRed();
  8952. var out = new Buffer(secret.toArray());
  8953. var prime = this.getPrime();
  8954. if (out.length < prime.length) {
  8955. var front = new Buffer(prime.length - out.length);
  8956. front.fill(0);
  8957. out = Buffer.concat([front, out]);
  8958. }
  8959. return out;
  8960. };
  8961. DH.prototype.getPublicKey = function getPublicKey(enc) {
  8962. return formatReturnValue(this._pub, enc);
  8963. };
  8964. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  8965. return formatReturnValue(this._priv, enc);
  8966. };
  8967. DH.prototype.getPrime = function (enc) {
  8968. return formatReturnValue(this.__prime, enc);
  8969. };
  8970. DH.prototype.getGenerator = function (enc) {
  8971. return formatReturnValue(this._gen, enc);
  8972. };
  8973. DH.prototype.setGenerator = function (gen, enc) {
  8974. enc = enc || 'utf8';
  8975. if (!Buffer.isBuffer(gen)) {
  8976. gen = new Buffer(gen, enc);
  8977. }
  8978. this.__gen = gen;
  8979. this._gen = new BN(gen);
  8980. return this;
  8981. };
  8982. function formatReturnValue(bn, enc) {
  8983. var buf = new Buffer(bn.toArray());
  8984. if (!enc) {
  8985. return buf;
  8986. } else {
  8987. return buf.toString(enc);
  8988. }
  8989. }
  8990. }).call(this,require("buffer").Buffer)
  8991. },{"./generatePrime":63,"bn.js":18,"buffer":46,"miller-rabin":98,"randombytes":117}],63:[function(require,module,exports){
  8992. var randomBytes = require('randombytes');
  8993. module.exports = findPrime;
  8994. findPrime.simpleSieve = simpleSieve;
  8995. findPrime.fermatTest = fermatTest;
  8996. var BN = require('bn.js');
  8997. var TWENTYFOUR = new BN(24);
  8998. var MillerRabin = require('miller-rabin');
  8999. var millerRabin = new MillerRabin();
  9000. var ONE = new BN(1);
  9001. var TWO = new BN(2);
  9002. var FIVE = new BN(5);
  9003. var SIXTEEN = new BN(16);
  9004. var EIGHT = new BN(8);
  9005. var TEN = new BN(10);
  9006. var THREE = new BN(3);
  9007. var SEVEN = new BN(7);
  9008. var ELEVEN = new BN(11);
  9009. var FOUR = new BN(4);
  9010. var TWELVE = new BN(12);
  9011. var primes = null;
  9012. function _getPrimes() {
  9013. if (primes !== null)
  9014. return primes;
  9015. var limit = 0x100000;
  9016. var res = [];
  9017. res[0] = 2;
  9018. for (var i = 1, k = 3; k < limit; k += 2) {
  9019. var sqrt = Math.ceil(Math.sqrt(k));
  9020. for (var j = 0; j < i && res[j] <= sqrt; j++)
  9021. if (k % res[j] === 0)
  9022. break;
  9023. if (i !== j && res[j] <= sqrt)
  9024. continue;
  9025. res[i++] = k;
  9026. }
  9027. primes = res;
  9028. return res;
  9029. }
  9030. function simpleSieve(p) {
  9031. var primes = _getPrimes();
  9032. for (var i = 0; i < primes.length; i++)
  9033. if (p.modn(primes[i]) === 0) {
  9034. if (p.cmpn(primes[i]) === 0) {
  9035. return true;
  9036. } else {
  9037. return false;
  9038. }
  9039. }
  9040. return true;
  9041. }
  9042. function fermatTest(p) {
  9043. var red = BN.mont(p);
  9044. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  9045. }
  9046. function findPrime(bits, gen) {
  9047. if (bits < 16) {
  9048. // this is what openssl does
  9049. if (gen === 2 || gen === 5) {
  9050. return new BN([0x8c, 0x7b]);
  9051. } else {
  9052. return new BN([0x8c, 0x27]);
  9053. }
  9054. }
  9055. gen = new BN(gen);
  9056. var num, n2;
  9057. while (true) {
  9058. num = new BN(randomBytes(Math.ceil(bits / 8)));
  9059. while (num.bitLength() > bits) {
  9060. num.ishrn(1);
  9061. }
  9062. if (num.isEven()) {
  9063. num.iadd(ONE);
  9064. }
  9065. if (!num.testn(1)) {
  9066. num.iadd(TWO);
  9067. }
  9068. if (!gen.cmp(TWO)) {
  9069. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  9070. num.iadd(FOUR);
  9071. }
  9072. } else if (!gen.cmp(FIVE)) {
  9073. while (num.mod(TEN).cmp(THREE)) {
  9074. num.iadd(FOUR);
  9075. }
  9076. }
  9077. n2 = num.shrn(1);
  9078. if (simpleSieve(n2) && simpleSieve(num) &&
  9079. fermatTest(n2) && fermatTest(num) &&
  9080. millerRabin.test(n2) && millerRabin.test(num)) {
  9081. return num;
  9082. }
  9083. }
  9084. }
  9085. },{"bn.js":18,"miller-rabin":98,"randombytes":117}],64:[function(require,module,exports){
  9086. module.exports={
  9087. "modp1": {
  9088. "gen": "02",
  9089. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
  9090. },
  9091. "modp2": {
  9092. "gen": "02",
  9093. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
  9094. },
  9095. "modp5": {
  9096. "gen": "02",
  9097. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
  9098. },
  9099. "modp14": {
  9100. "gen": "02",
  9101. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
  9102. },
  9103. "modp15": {
  9104. "gen": "02",
  9105. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
  9106. },
  9107. "modp16": {
  9108. "gen": "02",
  9109. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
  9110. },
  9111. "modp17": {
  9112. "gen": "02",
  9113. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
  9114. },
  9115. "modp18": {
  9116. "gen": "02",
  9117. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
  9118. }
  9119. }
  9120. },{}],65:[function(require,module,exports){
  9121. 'use strict';
  9122. var elliptic = exports;
  9123. elliptic.version = require('../package.json').version;
  9124. elliptic.utils = require('./elliptic/utils');
  9125. elliptic.rand = require('brorand');
  9126. elliptic.hmacDRBG = require('./elliptic/hmac-drbg');
  9127. elliptic.curve = require('./elliptic/curve');
  9128. elliptic.curves = require('./elliptic/curves');
  9129. // Protocols
  9130. elliptic.ec = require('./elliptic/ec');
  9131. elliptic.eddsa = require('./elliptic/eddsa');
  9132. },{"../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){
  9133. 'use strict';
  9134. var BN = require('bn.js');
  9135. var elliptic = require('../../elliptic');
  9136. var utils = elliptic.utils;
  9137. var getNAF = utils.getNAF;
  9138. var getJSF = utils.getJSF;
  9139. var assert = utils.assert;
  9140. function BaseCurve(type, conf) {
  9141. this.type = type;
  9142. this.p = new BN(conf.p, 16);
  9143. // Use Montgomery, when there is no fast reduction for the prime
  9144. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
  9145. // Useful for many curves
  9146. this.zero = new BN(0).toRed(this.red);
  9147. this.one = new BN(1).toRed(this.red);
  9148. this.two = new BN(2).toRed(this.red);
  9149. // Curve configuration, optional
  9150. this.n = conf.n && new BN(conf.n, 16);
  9151. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
  9152. // Temporary arrays
  9153. this._wnafT1 = new Array(4);
  9154. this._wnafT2 = new Array(4);
  9155. this._wnafT3 = new Array(4);
  9156. this._wnafT4 = new Array(4);
  9157. }
  9158. module.exports = BaseCurve;
  9159. BaseCurve.prototype.point = function point() {
  9160. throw new Error('Not implemented');
  9161. };
  9162. BaseCurve.prototype.validate = function validate() {
  9163. throw new Error('Not implemented');
  9164. };
  9165. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  9166. assert(p.precomputed);
  9167. var doubles = p._getDoubles();
  9168. var naf = getNAF(k, 1);
  9169. var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
  9170. I /= 3;
  9171. // Translate into more windowed form
  9172. var repr = [];
  9173. for (var j = 0; j < naf.length; j += doubles.step) {
  9174. var nafW = 0;
  9175. for (var k = j + doubles.step - 1; k >= j; k--)
  9176. nafW = (nafW << 1) + naf[k];
  9177. repr.push(nafW);
  9178. }
  9179. var a = this.jpoint(null, null, null);
  9180. var b = this.jpoint(null, null, null);
  9181. for (var i = I; i > 0; i--) {
  9182. for (var j = 0; j < repr.length; j++) {
  9183. var nafW = repr[j];
  9184. if (nafW === i)
  9185. b = b.mixedAdd(doubles.points[j]);
  9186. else if (nafW === -i)
  9187. b = b.mixedAdd(doubles.points[j].neg());
  9188. }
  9189. a = a.add(b);
  9190. }
  9191. return a.toP();
  9192. };
  9193. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  9194. var w = 4;
  9195. // Precompute window
  9196. var nafPoints = p._getNAFPoints(w);
  9197. w = nafPoints.wnd;
  9198. var wnd = nafPoints.points;
  9199. // Get NAF form
  9200. var naf = getNAF(k, w);
  9201. // Add `this`*(N+1) for every w-NAF index
  9202. var acc = this.jpoint(null, null, null);
  9203. for (var i = naf.length - 1; i >= 0; i--) {
  9204. // Count zeroes
  9205. for (var k = 0; i >= 0 && naf[i] === 0; i--)
  9206. k++;
  9207. if (i >= 0)
  9208. k++;
  9209. acc = acc.dblp(k);
  9210. if (i < 0)
  9211. break;
  9212. var z = naf[i];
  9213. assert(z !== 0);
  9214. if (p.type === 'affine') {
  9215. // J +- P
  9216. if (z > 0)
  9217. acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
  9218. else
  9219. acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
  9220. } else {
  9221. // J +- J
  9222. if (z > 0)
  9223. acc = acc.add(wnd[(z - 1) >> 1]);
  9224. else
  9225. acc = acc.add(wnd[(-z - 1) >> 1].neg());
  9226. }
  9227. }
  9228. return p.type === 'affine' ? acc.toP() : acc;
  9229. };
  9230. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
  9231. points,
  9232. coeffs,
  9233. len) {
  9234. var wndWidth = this._wnafT1;
  9235. var wnd = this._wnafT2;
  9236. var naf = this._wnafT3;
  9237. // Fill all arrays
  9238. var max = 0;
  9239. for (var i = 0; i < len; i++) {
  9240. var p = points[i];
  9241. var nafPoints = p._getNAFPoints(defW);
  9242. wndWidth[i] = nafPoints.wnd;
  9243. wnd[i] = nafPoints.points;
  9244. }
  9245. // Comb small window NAFs
  9246. for (var i = len - 1; i >= 1; i -= 2) {
  9247. var a = i - 1;
  9248. var b = i;
  9249. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  9250. naf[a] = getNAF(coeffs[a], wndWidth[a]);
  9251. naf[b] = getNAF(coeffs[b], wndWidth[b]);
  9252. max = Math.max(naf[a].length, max);
  9253. max = Math.max(naf[b].length, max);
  9254. continue;
  9255. }
  9256. var comb = [
  9257. points[a], /* 1 */
  9258. null, /* 3 */
  9259. null, /* 5 */
  9260. points[b] /* 7 */
  9261. ];
  9262. // Try to avoid Projective points, if possible
  9263. if (points[a].y.cmp(points[b].y) === 0) {
  9264. comb[1] = points[a].add(points[b]);
  9265. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  9266. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  9267. comb[1] = points[a].toJ().mixedAdd(points[b]);
  9268. comb[2] = points[a].add(points[b].neg());
  9269. } else {
  9270. comb[1] = points[a].toJ().mixedAdd(points[b]);
  9271. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  9272. }
  9273. var index = [
  9274. -3, /* -1 -1 */
  9275. -1, /* -1 0 */
  9276. -5, /* -1 1 */
  9277. -7, /* 0 -1 */
  9278. 0, /* 0 0 */
  9279. 7, /* 0 1 */
  9280. 5, /* 1 -1 */
  9281. 1, /* 1 0 */
  9282. 3 /* 1 1 */
  9283. ];
  9284. var jsf = getJSF(coeffs[a], coeffs[b]);
  9285. max = Math.max(jsf[0].length, max);
  9286. naf[a] = new Array(max);
  9287. naf[b] = new Array(max);
  9288. for (var j = 0; j < max; j++) {
  9289. var ja = jsf[0][j] | 0;
  9290. var jb = jsf[1][j] | 0;
  9291. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  9292. naf[b][j] = 0;
  9293. wnd[a] = comb;
  9294. }
  9295. }
  9296. var acc = this.jpoint(null, null, null);
  9297. var tmp = this._wnafT4;
  9298. for (var i = max; i >= 0; i--) {
  9299. var k = 0;
  9300. while (i >= 0) {
  9301. var zero = true;
  9302. for (var j = 0; j < len; j++) {
  9303. tmp[j] = naf[j][i] | 0;
  9304. if (tmp[j] !== 0)
  9305. zero = false;
  9306. }
  9307. if (!zero)
  9308. break;
  9309. k++;
  9310. i--;
  9311. }
  9312. if (i >= 0)
  9313. k++;
  9314. acc = acc.dblp(k);
  9315. if (i < 0)
  9316. break;
  9317. for (var j = 0; j < len; j++) {
  9318. var z = tmp[j];
  9319. var p;
  9320. if (z === 0)
  9321. continue;
  9322. else if (z > 0)
  9323. p = wnd[j][(z - 1) >> 1];
  9324. else if (z < 0)
  9325. p = wnd[j][(-z - 1) >> 1].neg();
  9326. if (p.type === 'affine')
  9327. acc = acc.mixedAdd(p);
  9328. else
  9329. acc = acc.add(p);
  9330. }
  9331. }
  9332. // Zeroify references
  9333. for (var i = 0; i < len; i++)
  9334. wnd[i] = null;
  9335. return acc.toP();
  9336. };
  9337. function BasePoint(curve, type) {
  9338. this.curve = curve;
  9339. this.type = type;
  9340. this.precomputed = null;
  9341. }
  9342. BaseCurve.BasePoint = BasePoint;
  9343. BasePoint.prototype.eq = function eq(/*other*/) {
  9344. throw new Error('Not implemented');
  9345. };
  9346. BasePoint.prototype.validate = function validate() {
  9347. return this.curve.validate(this);
  9348. };
  9349. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  9350. bytes = utils.toArray(bytes, enc);
  9351. var len = this.p.byteLength();
  9352. if (bytes[0] === 0x04 && bytes.length - 1 === 2 * len) {
  9353. return this.point(bytes.slice(1, 1 + len),
  9354. bytes.slice(1 + len, 1 + 2 * len));
  9355. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
  9356. bytes.length - 1 === len) {
  9357. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  9358. }
  9359. throw new Error('Unknown point format');
  9360. };
  9361. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  9362. return this.encode(enc, true);
  9363. };
  9364. BasePoint.prototype._encode = function _encode(compact) {
  9365. var len = this.curve.p.byteLength();
  9366. var x = this.getX().toArray('be', len);
  9367. if (compact)
  9368. return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
  9369. return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
  9370. };
  9371. BasePoint.prototype.encode = function encode(enc, compact) {
  9372. return utils.encode(this._encode(compact), enc);
  9373. };
  9374. BasePoint.prototype.precompute = function precompute(power) {
  9375. if (this.precomputed)
  9376. return this;
  9377. var precomputed = {
  9378. doubles: null,
  9379. naf: null,
  9380. beta: null
  9381. };
  9382. precomputed.naf = this._getNAFPoints(8);
  9383. precomputed.doubles = this._getDoubles(4, power);
  9384. precomputed.beta = this._getBeta();
  9385. this.precomputed = precomputed;
  9386. return this;
  9387. };
  9388. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  9389. if (!this.precomputed)
  9390. return false;
  9391. var doubles = this.precomputed.doubles;
  9392. if (!doubles)
  9393. return false;
  9394. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  9395. };
  9396. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  9397. if (this.precomputed && this.precomputed.doubles)
  9398. return this.precomputed.doubles;
  9399. var doubles = [ this ];
  9400. var acc = this;
  9401. for (var i = 0; i < power; i += step) {
  9402. for (var j = 0; j < step; j++)
  9403. acc = acc.dbl();
  9404. doubles.push(acc);
  9405. }
  9406. return {
  9407. step: step,
  9408. points: doubles
  9409. };
  9410. };
  9411. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  9412. if (this.precomputed && this.precomputed.naf)
  9413. return this.precomputed.naf;
  9414. var res = [ this ];
  9415. var max = (1 << wnd) - 1;
  9416. var dbl = max === 1 ? null : this.dbl();
  9417. for (var i = 1; i < max; i++)
  9418. res[i] = res[i - 1].add(dbl);
  9419. return {
  9420. wnd: wnd,
  9421. points: res
  9422. };
  9423. };
  9424. BasePoint.prototype._getBeta = function _getBeta() {
  9425. return null;
  9426. };
  9427. BasePoint.prototype.dblp = function dblp(k) {
  9428. var r = this;
  9429. for (var i = 0; i < k; i++)
  9430. r = r.dbl();
  9431. return r;
  9432. };
  9433. },{"../../elliptic":65,"bn.js":18}],67:[function(require,module,exports){
  9434. 'use strict';
  9435. var curve = require('../curve');
  9436. var elliptic = require('../../elliptic');
  9437. var BN = require('bn.js');
  9438. var inherits = require('inherits');
  9439. var Base = curve.base;
  9440. var assert = elliptic.utils.assert;
  9441. function EdwardsCurve(conf) {
  9442. // NOTE: Important as we are creating point in Base.call()
  9443. this.twisted = (conf.a | 0) !== 1;
  9444. this.mOneA = this.twisted && (conf.a | 0) === -1;
  9445. this.extended = this.mOneA;
  9446. Base.call(this, 'edwards', conf);
  9447. this.a = new BN(conf.a, 16).umod(this.red.m);
  9448. this.a = this.a.toRed(this.red);
  9449. this.c = new BN(conf.c, 16).toRed(this.red);
  9450. this.c2 = this.c.redSqr();
  9451. this.d = new BN(conf.d, 16).toRed(this.red);
  9452. this.dd = this.d.redAdd(this.d);
  9453. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  9454. this.oneC = (conf.c | 0) === 1;
  9455. }
  9456. inherits(EdwardsCurve, Base);
  9457. module.exports = EdwardsCurve;
  9458. EdwardsCurve.prototype._mulA = function _mulA(num) {
  9459. if (this.mOneA)
  9460. return num.redNeg();
  9461. else
  9462. return this.a.redMul(num);
  9463. };
  9464. EdwardsCurve.prototype._mulC = function _mulC(num) {
  9465. if (this.oneC)
  9466. return num;
  9467. else
  9468. return this.c.redMul(num);
  9469. };
  9470. // Just for compatibility with Short curve
  9471. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  9472. return this.point(x, y, z, t);
  9473. };
  9474. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  9475. x = new BN(x, 16);
  9476. if (!x.red)
  9477. x = x.toRed(this.red);
  9478. var x2 = x.redSqr();
  9479. var rhs = this.c2.redSub(this.a.redMul(x2));
  9480. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  9481. var y2 = rhs.redMul(lhs.redInvm());
  9482. var y = y2.redSqrt();
  9483. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
  9484. throw new Error('invalid point');
  9485. var isOdd = y.fromRed().isOdd();
  9486. if (odd && !isOdd || !odd && isOdd)
  9487. y = y.redNeg();
  9488. return this.point(x, y);
  9489. };
  9490. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  9491. y = new BN(y, 16);
  9492. if (!y.red)
  9493. y = y.toRed(this.red);
  9494. // x^2 = (y^2 - 1) / (d y^2 + 1)
  9495. var y2 = y.redSqr();
  9496. var lhs = y2.redSub(this.one);
  9497. var rhs = y2.redMul(this.d).redAdd(this.one);
  9498. var x2 = lhs.redMul(rhs.redInvm());
  9499. if (x2.cmp(this.zero) === 0) {
  9500. if (odd)
  9501. throw new Error('invalid point');
  9502. else
  9503. return this.point(this.zero, y);
  9504. }
  9505. var x = x2.redSqrt();
  9506. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
  9507. throw new Error('invalid point');
  9508. if (x.isOdd() !== odd)
  9509. x = x.redNeg();
  9510. return this.point(x, y);
  9511. };
  9512. EdwardsCurve.prototype.validate = function validate(point) {
  9513. if (point.isInfinity())
  9514. return true;
  9515. // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  9516. point.normalize();
  9517. var x2 = point.x.redSqr();
  9518. var y2 = point.y.redSqr();
  9519. var lhs = x2.redMul(this.a).redAdd(y2);
  9520. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  9521. return lhs.cmp(rhs) === 0;
  9522. };
  9523. function Point(curve, x, y, z, t) {
  9524. Base.BasePoint.call(this, curve, 'projective');
  9525. if (x === null && y === null && z === null) {
  9526. this.x = this.curve.zero;
  9527. this.y = this.curve.one;
  9528. this.z = this.curve.one;
  9529. this.t = this.curve.zero;
  9530. this.zOne = true;
  9531. } else {
  9532. this.x = new BN(x, 16);
  9533. this.y = new BN(y, 16);
  9534. this.z = z ? new BN(z, 16) : this.curve.one;
  9535. this.t = t && new BN(t, 16);
  9536. if (!this.x.red)
  9537. this.x = this.x.toRed(this.curve.red);
  9538. if (!this.y.red)
  9539. this.y = this.y.toRed(this.curve.red);
  9540. if (!this.z.red)
  9541. this.z = this.z.toRed(this.curve.red);
  9542. if (this.t && !this.t.red)
  9543. this.t = this.t.toRed(this.curve.red);
  9544. this.zOne = this.z === this.curve.one;
  9545. // Use extended coordinates
  9546. if (this.curve.extended && !this.t) {
  9547. this.t = this.x.redMul(this.y);
  9548. if (!this.zOne)
  9549. this.t = this.t.redMul(this.z.redInvm());
  9550. }
  9551. }
  9552. }
  9553. inherits(Point, Base.BasePoint);
  9554. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  9555. return Point.fromJSON(this, obj);
  9556. };
  9557. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  9558. return new Point(this, x, y, z, t);
  9559. };
  9560. Point.fromJSON = function fromJSON(curve, obj) {
  9561. return new Point(curve, obj[0], obj[1], obj[2]);
  9562. };
  9563. Point.prototype.inspect = function inspect() {
  9564. if (this.isInfinity())
  9565. return '<EC Point Infinity>';
  9566. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  9567. ' y: ' + this.y.fromRed().toString(16, 2) +
  9568. ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  9569. };
  9570. Point.prototype.isInfinity = function isInfinity() {
  9571. // XXX This code assumes that zero is always zero in red
  9572. return this.x.cmpn(0) === 0 &&
  9573. this.y.cmp(this.z) === 0;
  9574. };
  9575. Point.prototype._extDbl = function _extDbl() {
  9576. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  9577. // #doubling-dbl-2008-hwcd
  9578. // 4M + 4S
  9579. // A = X1^2
  9580. var a = this.x.redSqr();
  9581. // B = Y1^2
  9582. var b = this.y.redSqr();
  9583. // C = 2 * Z1^2
  9584. var c = this.z.redSqr();
  9585. c = c.redIAdd(c);
  9586. // D = a * A
  9587. var d = this.curve._mulA(a);
  9588. // E = (X1 + Y1)^2 - A - B
  9589. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
  9590. // G = D + B
  9591. var g = d.redAdd(b);
  9592. // F = G - C
  9593. var f = g.redSub(c);
  9594. // H = D - B
  9595. var h = d.redSub(b);
  9596. // X3 = E * F
  9597. var nx = e.redMul(f);
  9598. // Y3 = G * H
  9599. var ny = g.redMul(h);
  9600. // T3 = E * H
  9601. var nt = e.redMul(h);
  9602. // Z3 = F * G
  9603. var nz = f.redMul(g);
  9604. return this.curve.point(nx, ny, nz, nt);
  9605. };
  9606. Point.prototype._projDbl = function _projDbl() {
  9607. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  9608. // #doubling-dbl-2008-bbjlp
  9609. // #doubling-dbl-2007-bl
  9610. // and others
  9611. // Generally 3M + 4S or 2M + 4S
  9612. // B = (X1 + Y1)^2
  9613. var b = this.x.redAdd(this.y).redSqr();
  9614. // C = X1^2
  9615. var c = this.x.redSqr();
  9616. // D = Y1^2
  9617. var d = this.y.redSqr();
  9618. var nx;
  9619. var ny;
  9620. var nz;
  9621. if (this.curve.twisted) {
  9622. // E = a * C
  9623. var e = this.curve._mulA(c);
  9624. // F = E + D
  9625. var f = e.redAdd(d);
  9626. if (this.zOne) {
  9627. // X3 = (B - C - D) * (F - 2)
  9628. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
  9629. // Y3 = F * (E - D)
  9630. ny = f.redMul(e.redSub(d));
  9631. // Z3 = F^2 - 2 * F
  9632. nz = f.redSqr().redSub(f).redSub(f);
  9633. } else {
  9634. // H = Z1^2
  9635. var h = this.z.redSqr();
  9636. // J = F - 2 * H
  9637. var j = f.redSub(h).redISub(h);
  9638. // X3 = (B-C-D)*J
  9639. nx = b.redSub(c).redISub(d).redMul(j);
  9640. // Y3 = F * (E - D)
  9641. ny = f.redMul(e.redSub(d));
  9642. // Z3 = F * J
  9643. nz = f.redMul(j);
  9644. }
  9645. } else {
  9646. // E = C + D
  9647. var e = c.redAdd(d);
  9648. // H = (c * Z1)^2
  9649. var h = this.curve._mulC(this.c.redMul(this.z)).redSqr();
  9650. // J = E - 2 * H
  9651. var j = e.redSub(h).redSub(h);
  9652. // X3 = c * (B - E) * J
  9653. nx = this.curve._mulC(b.redISub(e)).redMul(j);
  9654. // Y3 = c * E * (C - D)
  9655. ny = this.curve._mulC(e).redMul(c.redISub(d));
  9656. // Z3 = E * J
  9657. nz = e.redMul(j);
  9658. }
  9659. return this.curve.point(nx, ny, nz);
  9660. };
  9661. Point.prototype.dbl = function dbl() {
  9662. if (this.isInfinity())
  9663. return this;
  9664. // Double in extended coordinates
  9665. if (this.curve.extended)
  9666. return this._extDbl();
  9667. else
  9668. return this._projDbl();
  9669. };
  9670. Point.prototype._extAdd = function _extAdd(p) {
  9671. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  9672. // #addition-add-2008-hwcd-3
  9673. // 8M
  9674. // A = (Y1 - X1) * (Y2 - X2)
  9675. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
  9676. // B = (Y1 + X1) * (Y2 + X2)
  9677. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
  9678. // C = T1 * k * T2
  9679. var c = this.t.redMul(this.curve.dd).redMul(p.t);
  9680. // D = Z1 * 2 * Z2
  9681. var d = this.z.redMul(p.z.redAdd(p.z));
  9682. // E = B - A
  9683. var e = b.redSub(a);
  9684. // F = D - C
  9685. var f = d.redSub(c);
  9686. // G = D + C
  9687. var g = d.redAdd(c);
  9688. // H = B + A
  9689. var h = b.redAdd(a);
  9690. // X3 = E * F
  9691. var nx = e.redMul(f);
  9692. // Y3 = G * H
  9693. var ny = g.redMul(h);
  9694. // T3 = E * H
  9695. var nt = e.redMul(h);
  9696. // Z3 = F * G
  9697. var nz = f.redMul(g);
  9698. return this.curve.point(nx, ny, nz, nt);
  9699. };
  9700. Point.prototype._projAdd = function _projAdd(p) {
  9701. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  9702. // #addition-add-2008-bbjlp
  9703. // #addition-add-2007-bl
  9704. // 10M + 1S
  9705. // A = Z1 * Z2
  9706. var a = this.z.redMul(p.z);
  9707. // B = A^2
  9708. var b = a.redSqr();
  9709. // C = X1 * X2
  9710. var c = this.x.redMul(p.x);
  9711. // D = Y1 * Y2
  9712. var d = this.y.redMul(p.y);
  9713. // E = d * C * D
  9714. var e = this.curve.d.redMul(c).redMul(d);
  9715. // F = B - E
  9716. var f = b.redSub(e);
  9717. // G = B + E
  9718. var g = b.redAdd(e);
  9719. // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  9720. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  9721. var nx = a.redMul(f).redMul(tmp);
  9722. var ny;
  9723. var nz;
  9724. if (this.curve.twisted) {
  9725. // Y3 = A * G * (D - a * C)
  9726. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
  9727. // Z3 = F * G
  9728. nz = f.redMul(g);
  9729. } else {
  9730. // Y3 = A * G * (D - C)
  9731. ny = a.redMul(g).redMul(d.redSub(c));
  9732. // Z3 = c * F * G
  9733. nz = this.curve._mulC(f).redMul(g);
  9734. }
  9735. return this.curve.point(nx, ny, nz);
  9736. };
  9737. Point.prototype.add = function add(p) {
  9738. if (this.isInfinity())
  9739. return p;
  9740. if (p.isInfinity())
  9741. return this;
  9742. if (this.curve.extended)
  9743. return this._extAdd(p);
  9744. else
  9745. return this._projAdd(p);
  9746. };
  9747. Point.prototype.mul = function mul(k) {
  9748. if (this._hasDoubles(k))
  9749. return this.curve._fixedNafMul(this, k);
  9750. else
  9751. return this.curve._wnafMul(this, k);
  9752. };
  9753. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  9754. return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2);
  9755. };
  9756. Point.prototype.normalize = function normalize() {
  9757. if (this.zOne)
  9758. return this;
  9759. // Normalize coordinates
  9760. var zi = this.z.redInvm();
  9761. this.x = this.x.redMul(zi);
  9762. this.y = this.y.redMul(zi);
  9763. if (this.t)
  9764. this.t = this.t.redMul(zi);
  9765. this.z = this.curve.one;
  9766. this.zOne = true;
  9767. return this;
  9768. };
  9769. Point.prototype.neg = function neg() {
  9770. return this.curve.point(this.x.redNeg(),
  9771. this.y,
  9772. this.z,
  9773. this.t && this.t.redNeg());
  9774. };
  9775. Point.prototype.getX = function getX() {
  9776. this.normalize();
  9777. return this.x.fromRed();
  9778. };
  9779. Point.prototype.getY = function getY() {
  9780. this.normalize();
  9781. return this.y.fromRed();
  9782. };
  9783. Point.prototype.eq = function eq(other) {
  9784. return this === other ||
  9785. this.getX().cmp(other.getX()) === 0 &&
  9786. this.getY().cmp(other.getY()) === 0;
  9787. };
  9788. // Compatibility with BaseCurve
  9789. Point.prototype.toP = Point.prototype.normalize;
  9790. Point.prototype.mixedAdd = Point.prototype.add;
  9791. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],68:[function(require,module,exports){
  9792. 'use strict';
  9793. var curve = exports;
  9794. curve.base = require('./base');
  9795. curve.short = require('./short');
  9796. curve.mont = require('./mont');
  9797. curve.edwards = require('./edwards');
  9798. },{"./base":66,"./edwards":67,"./mont":69,"./short":70}],69:[function(require,module,exports){
  9799. 'use strict';
  9800. var curve = require('../curve');
  9801. var BN = require('bn.js');
  9802. var inherits = require('inherits');
  9803. var Base = curve.base;
  9804. var elliptic = require('../../elliptic');
  9805. var utils = elliptic.utils;
  9806. function MontCurve(conf) {
  9807. Base.call(this, 'mont', conf);
  9808. this.a = new BN(conf.a, 16).toRed(this.red);
  9809. this.b = new BN(conf.b, 16).toRed(this.red);
  9810. this.i4 = new BN(4).toRed(this.red).redInvm();
  9811. this.two = new BN(2).toRed(this.red);
  9812. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  9813. }
  9814. inherits(MontCurve, Base);
  9815. module.exports = MontCurve;
  9816. MontCurve.prototype.validate = function validate(point) {
  9817. var x = point.normalize().x;
  9818. var x2 = x.redSqr();
  9819. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  9820. var y = rhs.redSqrt();
  9821. return y.redSqr().cmp(rhs) === 0;
  9822. };
  9823. function Point(curve, x, z) {
  9824. Base.BasePoint.call(this, curve, 'projective');
  9825. if (x === null && z === null) {
  9826. this.x = this.curve.one;
  9827. this.z = this.curve.zero;
  9828. } else {
  9829. this.x = new BN(x, 16);
  9830. this.z = new BN(z, 16);
  9831. if (!this.x.red)
  9832. this.x = this.x.toRed(this.curve.red);
  9833. if (!this.z.red)
  9834. this.z = this.z.toRed(this.curve.red);
  9835. }
  9836. }
  9837. inherits(Point, Base.BasePoint);
  9838. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  9839. return this.point(utils.toArray(bytes, enc), 1);
  9840. };
  9841. MontCurve.prototype.point = function point(x, z) {
  9842. return new Point(this, x, z);
  9843. };
  9844. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  9845. return Point.fromJSON(this, obj);
  9846. };
  9847. Point.prototype.precompute = function precompute() {
  9848. // No-op
  9849. };
  9850. Point.prototype._encode = function _encode() {
  9851. return this.getX().toArray('be', this.curve.p.byteLength());
  9852. };
  9853. Point.fromJSON = function fromJSON(curve, obj) {
  9854. return new Point(curve, obj[0], obj[1] || curve.one);
  9855. };
  9856. Point.prototype.inspect = function inspect() {
  9857. if (this.isInfinity())
  9858. return '<EC Point Infinity>';
  9859. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  9860. ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  9861. };
  9862. Point.prototype.isInfinity = function isInfinity() {
  9863. // XXX This code assumes that zero is always zero in red
  9864. return this.z.cmpn(0) === 0;
  9865. };
  9866. Point.prototype.dbl = function dbl() {
  9867. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  9868. // 2M + 2S + 4A
  9869. // A = X1 + Z1
  9870. var a = this.x.redAdd(this.z);
  9871. // AA = A^2
  9872. var aa = a.redSqr();
  9873. // B = X1 - Z1
  9874. var b = this.x.redSub(this.z);
  9875. // BB = B^2
  9876. var bb = b.redSqr();
  9877. // C = AA - BB
  9878. var c = aa.redSub(bb);
  9879. // X3 = AA * BB
  9880. var nx = aa.redMul(bb);
  9881. // Z3 = C * (BB + A24 * C)
  9882. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  9883. return this.curve.point(nx, nz);
  9884. };
  9885. Point.prototype.add = function add() {
  9886. throw new Error('Not supported on Montgomery curve');
  9887. };
  9888. Point.prototype.diffAdd = function diffAdd(p, diff) {
  9889. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  9890. // 4M + 2S + 6A
  9891. // A = X2 + Z2
  9892. var a = this.x.redAdd(this.z);
  9893. // B = X2 - Z2
  9894. var b = this.x.redSub(this.z);
  9895. // C = X3 + Z3
  9896. var c = p.x.redAdd(p.z);
  9897. // D = X3 - Z3
  9898. var d = p.x.redSub(p.z);
  9899. // DA = D * A
  9900. var da = d.redMul(a);
  9901. // CB = C * B
  9902. var cb = c.redMul(b);
  9903. // X5 = Z1 * (DA + CB)^2
  9904. var nx = diff.z.redMul(da.redAdd(cb).redSqr());
  9905. // Z5 = X1 * (DA - CB)^2
  9906. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  9907. return this.curve.point(nx, nz);
  9908. };
  9909. Point.prototype.mul = function mul(k) {
  9910. var t = k.clone();
  9911. var a = this; // (N / 2) * Q + Q
  9912. var b = this.curve.point(null, null); // (N / 2) * Q
  9913. var c = this; // Q
  9914. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
  9915. bits.push(t.andln(1));
  9916. for (var i = bits.length - 1; i >= 0; i--) {
  9917. if (bits[i] === 0) {
  9918. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  9919. a = a.diffAdd(b, c);
  9920. // N * Q = 2 * ((N / 2) * Q + Q))
  9921. b = b.dbl();
  9922. } else {
  9923. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  9924. b = a.diffAdd(b, c);
  9925. // N * Q + Q = 2 * ((N / 2) * Q + Q)
  9926. a = a.dbl();
  9927. }
  9928. }
  9929. return b;
  9930. };
  9931. Point.prototype.mulAdd = function mulAdd() {
  9932. throw new Error('Not supported on Montgomery curve');
  9933. };
  9934. Point.prototype.eq = function eq(other) {
  9935. return this.getX().cmp(other.getX()) === 0;
  9936. };
  9937. Point.prototype.normalize = function normalize() {
  9938. this.x = this.x.redMul(this.z.redInvm());
  9939. this.z = this.curve.one;
  9940. return this;
  9941. };
  9942. Point.prototype.getX = function getX() {
  9943. // Normalize coordinates
  9944. this.normalize();
  9945. return this.x.fromRed();
  9946. };
  9947. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],70:[function(require,module,exports){
  9948. 'use strict';
  9949. var curve = require('../curve');
  9950. var elliptic = require('../../elliptic');
  9951. var BN = require('bn.js');
  9952. var inherits = require('inherits');
  9953. var Base = curve.base;
  9954. var assert = elliptic.utils.assert;
  9955. function ShortCurve(conf) {
  9956. Base.call(this, 'short', conf);
  9957. this.a = new BN(conf.a, 16).toRed(this.red);
  9958. this.b = new BN(conf.b, 16).toRed(this.red);
  9959. this.tinv = this.two.redInvm();
  9960. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  9961. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
  9962. // If the curve is endomorphic, precalculate beta and lambda
  9963. this.endo = this._getEndomorphism(conf);
  9964. this._endoWnafT1 = new Array(4);
  9965. this._endoWnafT2 = new Array(4);
  9966. }
  9967. inherits(ShortCurve, Base);
  9968. module.exports = ShortCurve;
  9969. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  9970. // No efficient endomorphism
  9971. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
  9972. return;
  9973. // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  9974. var beta;
  9975. var lambda;
  9976. if (conf.beta) {
  9977. beta = new BN(conf.beta, 16).toRed(this.red);
  9978. } else {
  9979. var betas = this._getEndoRoots(this.p);
  9980. // Choose the smallest beta
  9981. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  9982. beta = beta.toRed(this.red);
  9983. }
  9984. if (conf.lambda) {
  9985. lambda = new BN(conf.lambda, 16);
  9986. } else {
  9987. // Choose the lambda that is matching selected beta
  9988. var lambdas = this._getEndoRoots(this.n);
  9989. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  9990. lambda = lambdas[0];
  9991. } else {
  9992. lambda = lambdas[1];
  9993. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  9994. }
  9995. }
  9996. // Get basis vectors, used for balanced length-two representation
  9997. var basis;
  9998. if (conf.basis) {
  9999. basis = conf.basis.map(function(vec) {
  10000. return {
  10001. a: new BN(vec.a, 16),
  10002. b: new BN(vec.b, 16)
  10003. };
  10004. });
  10005. } else {
  10006. basis = this._getEndoBasis(lambda);
  10007. }
  10008. return {
  10009. beta: beta,
  10010. lambda: lambda,
  10011. basis: basis
  10012. };
  10013. };
  10014. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  10015. // Find roots of for x^2 + x + 1 in F
  10016. // Root = (-1 +- Sqrt(-3)) / 2
  10017. //
  10018. var red = num === this.p ? this.red : BN.mont(num);
  10019. var tinv = new BN(2).toRed(red).redInvm();
  10020. var ntinv = tinv.redNeg();
  10021. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  10022. var l1 = ntinv.redAdd(s).fromRed();
  10023. var l2 = ntinv.redSub(s).fromRed();
  10024. return [ l1, l2 ];
  10025. };
  10026. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  10027. // aprxSqrt >= sqrt(this.n)
  10028. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
  10029. // 3.74
  10030. // Run EGCD, until r(L + 1) < aprxSqrt
  10031. var u = lambda;
  10032. var v = this.n.clone();
  10033. var x1 = new BN(1);
  10034. var y1 = new BN(0);
  10035. var x2 = new BN(0);
  10036. var y2 = new BN(1);
  10037. // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  10038. var a0;
  10039. var b0;
  10040. // First vector
  10041. var a1;
  10042. var b1;
  10043. // Second vector
  10044. var a2;
  10045. var b2;
  10046. var prevR;
  10047. var i = 0;
  10048. var r;
  10049. var x;
  10050. while (u.cmpn(0) !== 0) {
  10051. var q = v.div(u);
  10052. r = v.sub(q.mul(u));
  10053. x = x2.sub(q.mul(x1));
  10054. var y = y2.sub(q.mul(y1));
  10055. if (!a1 && r.cmp(aprxSqrt) < 0) {
  10056. a0 = prevR.neg();
  10057. b0 = x1;
  10058. a1 = r.neg();
  10059. b1 = x;
  10060. } else if (a1 && ++i === 2) {
  10061. break;
  10062. }
  10063. prevR = r;
  10064. v = u;
  10065. u = r;
  10066. x2 = x1;
  10067. x1 = x;
  10068. y2 = y1;
  10069. y1 = y;
  10070. }
  10071. a2 = r.neg();
  10072. b2 = x;
  10073. var len1 = a1.sqr().add(b1.sqr());
  10074. var len2 = a2.sqr().add(b2.sqr());
  10075. if (len2.cmp(len1) >= 0) {
  10076. a2 = a0;
  10077. b2 = b0;
  10078. }
  10079. // Normalize signs
  10080. if (a1.negative) {
  10081. a1 = a1.neg();
  10082. b1 = b1.neg();
  10083. }
  10084. if (a2.negative) {
  10085. a2 = a2.neg();
  10086. b2 = b2.neg();
  10087. }
  10088. return [
  10089. { a: a1, b: b1 },
  10090. { a: a2, b: b2 }
  10091. ];
  10092. };
  10093. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  10094. var basis = this.endo.basis;
  10095. var v1 = basis[0];
  10096. var v2 = basis[1];
  10097. var c1 = v2.b.mul(k).divRound(this.n);
  10098. var c2 = v1.b.neg().mul(k).divRound(this.n);
  10099. var p1 = c1.mul(v1.a);
  10100. var p2 = c2.mul(v2.a);
  10101. var q1 = c1.mul(v1.b);
  10102. var q2 = c2.mul(v2.b);
  10103. // Calculate answer
  10104. var k1 = k.sub(p1).sub(p2);
  10105. var k2 = q1.add(q2).neg();
  10106. return { k1: k1, k2: k2 };
  10107. };
  10108. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  10109. x = new BN(x, 16);
  10110. if (!x.red)
  10111. x = x.toRed(this.red);
  10112. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  10113. var y = y2.redSqrt();
  10114. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
  10115. throw new Error('invalid point');
  10116. // XXX Is there any way to tell if the number is odd without converting it
  10117. // to non-red form?
  10118. var isOdd = y.fromRed().isOdd();
  10119. if (odd && !isOdd || !odd && isOdd)
  10120. y = y.redNeg();
  10121. return this.point(x, y);
  10122. };
  10123. ShortCurve.prototype.validate = function validate(point) {
  10124. if (point.inf)
  10125. return true;
  10126. var x = point.x;
  10127. var y = point.y;
  10128. var ax = this.a.redMul(x);
  10129. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  10130. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  10131. };
  10132. ShortCurve.prototype._endoWnafMulAdd =
  10133. function _endoWnafMulAdd(points, coeffs) {
  10134. var npoints = this._endoWnafT1;
  10135. var ncoeffs = this._endoWnafT2;
  10136. for (var i = 0; i < points.length; i++) {
  10137. var split = this._endoSplit(coeffs[i]);
  10138. var p = points[i];
  10139. var beta = p._getBeta();
  10140. if (split.k1.negative) {
  10141. split.k1.ineg();
  10142. p = p.neg(true);
  10143. }
  10144. if (split.k2.negative) {
  10145. split.k2.ineg();
  10146. beta = beta.neg(true);
  10147. }
  10148. npoints[i * 2] = p;
  10149. npoints[i * 2 + 1] = beta;
  10150. ncoeffs[i * 2] = split.k1;
  10151. ncoeffs[i * 2 + 1] = split.k2;
  10152. }
  10153. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2);
  10154. // Clean-up references to points and coefficients
  10155. for (var j = 0; j < i * 2; j++) {
  10156. npoints[j] = null;
  10157. ncoeffs[j] = null;
  10158. }
  10159. return res;
  10160. };
  10161. function Point(curve, x, y, isRed) {
  10162. Base.BasePoint.call(this, curve, 'affine');
  10163. if (x === null && y === null) {
  10164. this.x = null;
  10165. this.y = null;
  10166. this.inf = true;
  10167. } else {
  10168. this.x = new BN(x, 16);
  10169. this.y = new BN(y, 16);
  10170. // Force redgomery representation when loading from JSON
  10171. if (isRed) {
  10172. this.x.forceRed(this.curve.red);
  10173. this.y.forceRed(this.curve.red);
  10174. }
  10175. if (!this.x.red)
  10176. this.x = this.x.toRed(this.curve.red);
  10177. if (!this.y.red)
  10178. this.y = this.y.toRed(this.curve.red);
  10179. this.inf = false;
  10180. }
  10181. }
  10182. inherits(Point, Base.BasePoint);
  10183. ShortCurve.prototype.point = function point(x, y, isRed) {
  10184. return new Point(this, x, y, isRed);
  10185. };
  10186. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  10187. return Point.fromJSON(this, obj, red);
  10188. };
  10189. Point.prototype._getBeta = function _getBeta() {
  10190. if (!this.curve.endo)
  10191. return;
  10192. var pre = this.precomputed;
  10193. if (pre && pre.beta)
  10194. return pre.beta;
  10195. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  10196. if (pre) {
  10197. var curve = this.curve;
  10198. var endoMul = function(p) {
  10199. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  10200. };
  10201. pre.beta = beta;
  10202. beta.precomputed = {
  10203. beta: null,
  10204. naf: pre.naf && {
  10205. wnd: pre.naf.wnd,
  10206. points: pre.naf.points.map(endoMul)
  10207. },
  10208. doubles: pre.doubles && {
  10209. step: pre.doubles.step,
  10210. points: pre.doubles.points.map(endoMul)
  10211. }
  10212. };
  10213. }
  10214. return beta;
  10215. };
  10216. Point.prototype.toJSON = function toJSON() {
  10217. if (!this.precomputed)
  10218. return [ this.x, this.y ];
  10219. return [ this.x, this.y, this.precomputed && {
  10220. doubles: this.precomputed.doubles && {
  10221. step: this.precomputed.doubles.step,
  10222. points: this.precomputed.doubles.points.slice(1)
  10223. },
  10224. naf: this.precomputed.naf && {
  10225. wnd: this.precomputed.naf.wnd,
  10226. points: this.precomputed.naf.points.slice(1)
  10227. }
  10228. } ];
  10229. };
  10230. Point.fromJSON = function fromJSON(curve, obj, red) {
  10231. if (typeof obj === 'string')
  10232. obj = JSON.parse(obj);
  10233. var res = curve.point(obj[0], obj[1], red);
  10234. if (!obj[2])
  10235. return res;
  10236. function obj2point(obj) {
  10237. return curve.point(obj[0], obj[1], red);
  10238. }
  10239. var pre = obj[2];
  10240. res.precomputed = {
  10241. beta: null,
  10242. doubles: pre.doubles && {
  10243. step: pre.doubles.step,
  10244. points: [ res ].concat(pre.doubles.points.map(obj2point))
  10245. },
  10246. naf: pre.naf && {
  10247. wnd: pre.naf.wnd,
  10248. points: [ res ].concat(pre.naf.points.map(obj2point))
  10249. }
  10250. };
  10251. return res;
  10252. };
  10253. Point.prototype.inspect = function inspect() {
  10254. if (this.isInfinity())
  10255. return '<EC Point Infinity>';
  10256. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
  10257. ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  10258. };
  10259. Point.prototype.isInfinity = function isInfinity() {
  10260. return this.inf;
  10261. };
  10262. Point.prototype.add = function add(p) {
  10263. // O + P = P
  10264. if (this.inf)
  10265. return p;
  10266. // P + O = P
  10267. if (p.inf)
  10268. return this;
  10269. // P + P = 2P
  10270. if (this.eq(p))
  10271. return this.dbl();
  10272. // P + (-P) = O
  10273. if (this.neg().eq(p))
  10274. return this.curve.point(null, null);
  10275. // P + Q = O
  10276. if (this.x.cmp(p.x) === 0)
  10277. return this.curve.point(null, null);
  10278. var c = this.y.redSub(p.y);
  10279. if (c.cmpn(0) !== 0)
  10280. c = c.redMul(this.x.redSub(p.x).redInvm());
  10281. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  10282. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  10283. return this.curve.point(nx, ny);
  10284. };
  10285. Point.prototype.dbl = function dbl() {
  10286. if (this.inf)
  10287. return this;
  10288. // 2P = O
  10289. var ys1 = this.y.redAdd(this.y);
  10290. if (ys1.cmpn(0) === 0)
  10291. return this.curve.point(null, null);
  10292. var a = this.curve.a;
  10293. var x2 = this.x.redSqr();
  10294. var dyinv = ys1.redInvm();
  10295. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  10296. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  10297. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  10298. return this.curve.point(nx, ny);
  10299. };
  10300. Point.prototype.getX = function getX() {
  10301. return this.x.fromRed();
  10302. };
  10303. Point.prototype.getY = function getY() {
  10304. return this.y.fromRed();
  10305. };
  10306. Point.prototype.mul = function mul(k) {
  10307. k = new BN(k, 16);
  10308. if (this._hasDoubles(k))
  10309. return this.curve._fixedNafMul(this, k);
  10310. else if (this.curve.endo)
  10311. return this.curve._endoWnafMulAdd([ this ], [ k ]);
  10312. else
  10313. return this.curve._wnafMul(this, k);
  10314. };
  10315. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  10316. var points = [ this, p2 ];
  10317. var coeffs = [ k1, k2 ];
  10318. if (this.curve.endo)
  10319. return this.curve._endoWnafMulAdd(points, coeffs);
  10320. else
  10321. return this.curve._wnafMulAdd(1, points, coeffs, 2);
  10322. };
  10323. Point.prototype.eq = function eq(p) {
  10324. return this === p ||
  10325. this.inf === p.inf &&
  10326. (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  10327. };
  10328. Point.prototype.neg = function neg(_precompute) {
  10329. if (this.inf)
  10330. return this;
  10331. var res = this.curve.point(this.x, this.y.redNeg());
  10332. if (_precompute && this.precomputed) {
  10333. var pre = this.precomputed;
  10334. var negate = function(p) {
  10335. return p.neg();
  10336. };
  10337. res.precomputed = {
  10338. naf: pre.naf && {
  10339. wnd: pre.naf.wnd,
  10340. points: pre.naf.points.map(negate)
  10341. },
  10342. doubles: pre.doubles && {
  10343. step: pre.doubles.step,
  10344. points: pre.doubles.points.map(negate)
  10345. }
  10346. };
  10347. }
  10348. return res;
  10349. };
  10350. Point.prototype.toJ = function toJ() {
  10351. if (this.inf)
  10352. return this.curve.jpoint(null, null, null);
  10353. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  10354. return res;
  10355. };
  10356. function JPoint(curve, x, y, z) {
  10357. Base.BasePoint.call(this, curve, 'jacobian');
  10358. if (x === null && y === null && z === null) {
  10359. this.x = this.curve.one;
  10360. this.y = this.curve.one;
  10361. this.z = new BN(0);
  10362. } else {
  10363. this.x = new BN(x, 16);
  10364. this.y = new BN(y, 16);
  10365. this.z = new BN(z, 16);
  10366. }
  10367. if (!this.x.red)
  10368. this.x = this.x.toRed(this.curve.red);
  10369. if (!this.y.red)
  10370. this.y = this.y.toRed(this.curve.red);
  10371. if (!this.z.red)
  10372. this.z = this.z.toRed(this.curve.red);
  10373. this.zOne = this.z === this.curve.one;
  10374. }
  10375. inherits(JPoint, Base.BasePoint);
  10376. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  10377. return new JPoint(this, x, y, z);
  10378. };
  10379. JPoint.prototype.toP = function toP() {
  10380. if (this.isInfinity())
  10381. return this.curve.point(null, null);
  10382. var zinv = this.z.redInvm();
  10383. var zinv2 = zinv.redSqr();
  10384. var ax = this.x.redMul(zinv2);
  10385. var ay = this.y.redMul(zinv2).redMul(zinv);
  10386. return this.curve.point(ax, ay);
  10387. };
  10388. JPoint.prototype.neg = function neg() {
  10389. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  10390. };
  10391. JPoint.prototype.add = function add(p) {
  10392. // O + P = P
  10393. if (this.isInfinity())
  10394. return p;
  10395. // P + O = P
  10396. if (p.isInfinity())
  10397. return this;
  10398. // 12M + 4S + 7A
  10399. var pz2 = p.z.redSqr();
  10400. var z2 = this.z.redSqr();
  10401. var u1 = this.x.redMul(pz2);
  10402. var u2 = p.x.redMul(z2);
  10403. var s1 = this.y.redMul(pz2.redMul(p.z));
  10404. var s2 = p.y.redMul(z2.redMul(this.z));
  10405. var h = u1.redSub(u2);
  10406. var r = s1.redSub(s2);
  10407. if (h.cmpn(0) === 0) {
  10408. if (r.cmpn(0) !== 0)
  10409. return this.curve.jpoint(null, null, null);
  10410. else
  10411. return this.dbl();
  10412. }
  10413. var h2 = h.redSqr();
  10414. var h3 = h2.redMul(h);
  10415. var v = u1.redMul(h2);
  10416. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  10417. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  10418. var nz = this.z.redMul(p.z).redMul(h);
  10419. return this.curve.jpoint(nx, ny, nz);
  10420. };
  10421. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  10422. // O + P = P
  10423. if (this.isInfinity())
  10424. return p.toJ();
  10425. // P + O = P
  10426. if (p.isInfinity())
  10427. return this;
  10428. // 8M + 3S + 7A
  10429. var z2 = this.z.redSqr();
  10430. var u1 = this.x;
  10431. var u2 = p.x.redMul(z2);
  10432. var s1 = this.y;
  10433. var s2 = p.y.redMul(z2).redMul(this.z);
  10434. var h = u1.redSub(u2);
  10435. var r = s1.redSub(s2);
  10436. if (h.cmpn(0) === 0) {
  10437. if (r.cmpn(0) !== 0)
  10438. return this.curve.jpoint(null, null, null);
  10439. else
  10440. return this.dbl();
  10441. }
  10442. var h2 = h.redSqr();
  10443. var h3 = h2.redMul(h);
  10444. var v = u1.redMul(h2);
  10445. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  10446. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  10447. var nz = this.z.redMul(h);
  10448. return this.curve.jpoint(nx, ny, nz);
  10449. };
  10450. JPoint.prototype.dblp = function dblp(pow) {
  10451. if (pow === 0)
  10452. return this;
  10453. if (this.isInfinity())
  10454. return this;
  10455. if (!pow)
  10456. return this.dbl();
  10457. if (this.curve.zeroA || this.curve.threeA) {
  10458. var r = this;
  10459. for (var i = 0; i < pow; i++)
  10460. r = r.dbl();
  10461. return r;
  10462. }
  10463. // 1M + 2S + 1A + N * (4S + 5M + 8A)
  10464. // N = 1 => 6M + 6S + 9A
  10465. var a = this.curve.a;
  10466. var tinv = this.curve.tinv;
  10467. var jx = this.x;
  10468. var jy = this.y;
  10469. var jz = this.z;
  10470. var jz4 = jz.redSqr().redSqr();
  10471. // Reuse results
  10472. var jyd = jy.redAdd(jy);
  10473. for (var i = 0; i < pow; i++) {
  10474. var jx2 = jx.redSqr();
  10475. var jyd2 = jyd.redSqr();
  10476. var jyd4 = jyd2.redSqr();
  10477. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  10478. var t1 = jx.redMul(jyd2);
  10479. var nx = c.redSqr().redISub(t1.redAdd(t1));
  10480. var t2 = t1.redISub(nx);
  10481. var dny = c.redMul(t2);
  10482. dny = dny.redIAdd(dny).redISub(jyd4);
  10483. var nz = jyd.redMul(jz);
  10484. if (i + 1 < pow)
  10485. jz4 = jz4.redMul(jyd4);
  10486. jx = nx;
  10487. jz = nz;
  10488. jyd = dny;
  10489. }
  10490. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  10491. };
  10492. JPoint.prototype.dbl = function dbl() {
  10493. if (this.isInfinity())
  10494. return this;
  10495. if (this.curve.zeroA)
  10496. return this._zeroDbl();
  10497. else if (this.curve.threeA)
  10498. return this._threeDbl();
  10499. else
  10500. return this._dbl();
  10501. };
  10502. JPoint.prototype._zeroDbl = function _zeroDbl() {
  10503. var nx;
  10504. var ny;
  10505. var nz;
  10506. // Z = 1
  10507. if (this.zOne) {
  10508. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  10509. // #doubling-mdbl-2007-bl
  10510. // 1M + 5S + 14A
  10511. // XX = X1^2
  10512. var xx = this.x.redSqr();
  10513. // YY = Y1^2
  10514. var yy = this.y.redSqr();
  10515. // YYYY = YY^2
  10516. var yyyy = yy.redSqr();
  10517. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  10518. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10519. s = s.redIAdd(s);
  10520. // M = 3 * XX + a; a = 0
  10521. var m = xx.redAdd(xx).redIAdd(xx);
  10522. // T = M ^ 2 - 2*S
  10523. var t = m.redSqr().redISub(s).redISub(s);
  10524. // 8 * YYYY
  10525. var yyyy8 = yyyy.redIAdd(yyyy);
  10526. yyyy8 = yyyy8.redIAdd(yyyy8);
  10527. yyyy8 = yyyy8.redIAdd(yyyy8);
  10528. // X3 = T
  10529. nx = t;
  10530. // Y3 = M * (S - T) - 8 * YYYY
  10531. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  10532. // Z3 = 2*Y1
  10533. nz = this.y.redAdd(this.y);
  10534. } else {
  10535. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  10536. // #doubling-dbl-2009-l
  10537. // 2M + 5S + 13A
  10538. // A = X1^2
  10539. var a = this.x.redSqr();
  10540. // B = Y1^2
  10541. var b = this.y.redSqr();
  10542. // C = B^2
  10543. var c = b.redSqr();
  10544. // D = 2 * ((X1 + B)^2 - A - C)
  10545. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  10546. d = d.redIAdd(d);
  10547. // E = 3 * A
  10548. var e = a.redAdd(a).redIAdd(a);
  10549. // F = E^2
  10550. var f = e.redSqr();
  10551. // 8 * C
  10552. var c8 = c.redIAdd(c);
  10553. c8 = c8.redIAdd(c8);
  10554. c8 = c8.redIAdd(c8);
  10555. // X3 = F - 2 * D
  10556. nx = f.redISub(d).redISub(d);
  10557. // Y3 = E * (D - X3) - 8 * C
  10558. ny = e.redMul(d.redISub(nx)).redISub(c8);
  10559. // Z3 = 2 * Y1 * Z1
  10560. nz = this.y.redMul(this.z);
  10561. nz = nz.redIAdd(nz);
  10562. }
  10563. return this.curve.jpoint(nx, ny, nz);
  10564. };
  10565. JPoint.prototype._threeDbl = function _threeDbl() {
  10566. var nx;
  10567. var ny;
  10568. var nz;
  10569. // Z = 1
  10570. if (this.zOne) {
  10571. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  10572. // #doubling-mdbl-2007-bl
  10573. // 1M + 5S + 15A
  10574. // XX = X1^2
  10575. var xx = this.x.redSqr();
  10576. // YY = Y1^2
  10577. var yy = this.y.redSqr();
  10578. // YYYY = YY^2
  10579. var yyyy = yy.redSqr();
  10580. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  10581. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10582. s = s.redIAdd(s);
  10583. // M = 3 * XX + a
  10584. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
  10585. // T = M^2 - 2 * S
  10586. var t = m.redSqr().redISub(s).redISub(s);
  10587. // X3 = T
  10588. nx = t;
  10589. // Y3 = M * (S - T) - 8 * YYYY
  10590. var yyyy8 = yyyy.redIAdd(yyyy);
  10591. yyyy8 = yyyy8.redIAdd(yyyy8);
  10592. yyyy8 = yyyy8.redIAdd(yyyy8);
  10593. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  10594. // Z3 = 2 * Y1
  10595. nz = this.y.redAdd(this.y);
  10596. } else {
  10597. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  10598. // 3M + 5S
  10599. // delta = Z1^2
  10600. var delta = this.z.redSqr();
  10601. // gamma = Y1^2
  10602. var gamma = this.y.redSqr();
  10603. // beta = X1 * gamma
  10604. var beta = this.x.redMul(gamma);
  10605. // alpha = 3 * (X1 - delta) * (X1 + delta)
  10606. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  10607. alpha = alpha.redAdd(alpha).redIAdd(alpha);
  10608. // X3 = alpha^2 - 8 * beta
  10609. var beta4 = beta.redIAdd(beta);
  10610. beta4 = beta4.redIAdd(beta4);
  10611. var beta8 = beta4.redAdd(beta4);
  10612. nx = alpha.redSqr().redISub(beta8);
  10613. // Z3 = (Y1 + Z1)^2 - gamma - delta
  10614. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
  10615. // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  10616. var ggamma8 = gamma.redSqr();
  10617. ggamma8 = ggamma8.redIAdd(ggamma8);
  10618. ggamma8 = ggamma8.redIAdd(ggamma8);
  10619. ggamma8 = ggamma8.redIAdd(ggamma8);
  10620. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  10621. }
  10622. return this.curve.jpoint(nx, ny, nz);
  10623. };
  10624. JPoint.prototype._dbl = function _dbl() {
  10625. var a = this.curve.a;
  10626. // 4M + 6S + 10A
  10627. var jx = this.x;
  10628. var jy = this.y;
  10629. var jz = this.z;
  10630. var jz4 = jz.redSqr().redSqr();
  10631. var jx2 = jx.redSqr();
  10632. var jy2 = jy.redSqr();
  10633. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  10634. var jxd4 = jx.redAdd(jx);
  10635. jxd4 = jxd4.redIAdd(jxd4);
  10636. var t1 = jxd4.redMul(jy2);
  10637. var nx = c.redSqr().redISub(t1.redAdd(t1));
  10638. var t2 = t1.redISub(nx);
  10639. var jyd8 = jy2.redSqr();
  10640. jyd8 = jyd8.redIAdd(jyd8);
  10641. jyd8 = jyd8.redIAdd(jyd8);
  10642. jyd8 = jyd8.redIAdd(jyd8);
  10643. var ny = c.redMul(t2).redISub(jyd8);
  10644. var nz = jy.redAdd(jy).redMul(jz);
  10645. return this.curve.jpoint(nx, ny, nz);
  10646. };
  10647. JPoint.prototype.trpl = function trpl() {
  10648. if (!this.curve.zeroA)
  10649. return this.dbl().add(this);
  10650. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  10651. // 5M + 10S + ...
  10652. // XX = X1^2
  10653. var xx = this.x.redSqr();
  10654. // YY = Y1^2
  10655. var yy = this.y.redSqr();
  10656. // ZZ = Z1^2
  10657. var zz = this.z.redSqr();
  10658. // YYYY = YY^2
  10659. var yyyy = yy.redSqr();
  10660. // M = 3 * XX + a * ZZ2; a = 0
  10661. var m = xx.redAdd(xx).redIAdd(xx);
  10662. // MM = M^2
  10663. var mm = m.redSqr();
  10664. // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  10665. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  10666. e = e.redIAdd(e);
  10667. e = e.redAdd(e).redIAdd(e);
  10668. e = e.redISub(mm);
  10669. // EE = E^2
  10670. var ee = e.redSqr();
  10671. // T = 16*YYYY
  10672. var t = yyyy.redIAdd(yyyy);
  10673. t = t.redIAdd(t);
  10674. t = t.redIAdd(t);
  10675. t = t.redIAdd(t);
  10676. // U = (M + E)^2 - MM - EE - T
  10677. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
  10678. // X3 = 4 * (X1 * EE - 4 * YY * U)
  10679. var yyu4 = yy.redMul(u);
  10680. yyu4 = yyu4.redIAdd(yyu4);
  10681. yyu4 = yyu4.redIAdd(yyu4);
  10682. var nx = this.x.redMul(ee).redISub(yyu4);
  10683. nx = nx.redIAdd(nx);
  10684. nx = nx.redIAdd(nx);
  10685. // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  10686. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  10687. ny = ny.redIAdd(ny);
  10688. ny = ny.redIAdd(ny);
  10689. ny = ny.redIAdd(ny);
  10690. // Z3 = (Z1 + E)^2 - ZZ - EE
  10691. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  10692. return this.curve.jpoint(nx, ny, nz);
  10693. };
  10694. JPoint.prototype.mul = function mul(k, kbase) {
  10695. k = new BN(k, kbase);
  10696. return this.curve._wnafMul(this, k);
  10697. };
  10698. JPoint.prototype.eq = function eq(p) {
  10699. if (p.type === 'affine')
  10700. return this.eq(p.toJ());
  10701. if (this === p)
  10702. return true;
  10703. // x1 * z2^2 == x2 * z1^2
  10704. var z2 = this.z.redSqr();
  10705. var pz2 = p.z.redSqr();
  10706. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
  10707. return false;
  10708. // y1 * z2^3 == y2 * z1^3
  10709. var z3 = z2.redMul(this.z);
  10710. var pz3 = pz2.redMul(p.z);
  10711. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  10712. };
  10713. JPoint.prototype.inspect = function inspect() {
  10714. if (this.isInfinity())
  10715. return '<EC JPoint Infinity>';
  10716. return '<EC JPoint x: ' + this.x.toString(16, 2) +
  10717. ' y: ' + this.y.toString(16, 2) +
  10718. ' z: ' + this.z.toString(16, 2) + '>';
  10719. };
  10720. JPoint.prototype.isInfinity = function isInfinity() {
  10721. // XXX This code assumes that zero is always zero in red
  10722. return this.z.cmpn(0) === 0;
  10723. };
  10724. },{"../../elliptic":65,"../curve":68,"bn.js":18,"inherits":92}],71:[function(require,module,exports){
  10725. 'use strict';
  10726. var curves = exports;
  10727. var hash = require('hash.js');
  10728. var elliptic = require('../elliptic');
  10729. var assert = elliptic.utils.assert;
  10730. function PresetCurve(options) {
  10731. if (options.type === 'short')
  10732. this.curve = new elliptic.curve.short(options);
  10733. else if (options.type === 'edwards')
  10734. this.curve = new elliptic.curve.edwards(options);
  10735. else
  10736. this.curve = new elliptic.curve.mont(options);
  10737. this.g = this.curve.g;
  10738. this.n = this.curve.n;
  10739. this.hash = options.hash;
  10740. assert(this.g.validate(), 'Invalid curve');
  10741. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  10742. }
  10743. curves.PresetCurve = PresetCurve;
  10744. function defineCurve(name, options) {
  10745. Object.defineProperty(curves, name, {
  10746. configurable: true,
  10747. enumerable: true,
  10748. get: function() {
  10749. var curve = new PresetCurve(options);
  10750. Object.defineProperty(curves, name, {
  10751. configurable: true,
  10752. enumerable: true,
  10753. value: curve
  10754. });
  10755. return curve;
  10756. }
  10757. });
  10758. }
  10759. defineCurve('p192', {
  10760. type: 'short',
  10761. prime: 'p192',
  10762. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  10763. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  10764. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  10765. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  10766. hash: hash.sha256,
  10767. gRed: false,
  10768. g: [
  10769. '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
  10770. '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
  10771. ]
  10772. });
  10773. defineCurve('p224', {
  10774. type: 'short',
  10775. prime: 'p224',
  10776. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  10777. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  10778. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  10779. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  10780. hash: hash.sha256,
  10781. gRed: false,
  10782. g: [
  10783. 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
  10784. 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
  10785. ]
  10786. });
  10787. defineCurve('p256', {
  10788. type: 'short',
  10789. prime: null,
  10790. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  10791. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  10792. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  10793. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  10794. hash: hash.sha256,
  10795. gRed: false,
  10796. g: [
  10797. '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
  10798. '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
  10799. ]
  10800. });
  10801. defineCurve('p384', {
  10802. type: 'short',
  10803. prime: null,
  10804. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10805. 'fffffffe ffffffff 00000000 00000000 ffffffff',
  10806. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10807. 'fffffffe ffffffff 00000000 00000000 fffffffc',
  10808. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
  10809. '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  10810. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
  10811. 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  10812. hash: hash.sha384,
  10813. gRed: false,
  10814. g: [
  10815. 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
  10816. '5502f25d bf55296c 3a545e38 72760ab7',
  10817. '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
  10818. '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
  10819. ]
  10820. });
  10821. defineCurve('p521', {
  10822. type: 'short',
  10823. prime: null,
  10824. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10825. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10826. 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  10827. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10828. 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10829. 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  10830. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
  10831. '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
  10832. '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  10833. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
  10834. 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
  10835. 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  10836. hash: hash.sha512,
  10837. gRed: false,
  10838. g: [
  10839. '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
  10840. '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
  10841. 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
  10842. '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
  10843. '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
  10844. '3fad0761 353c7086 a272c240 88be9476 9fd16650'
  10845. ]
  10846. });
  10847. defineCurve('curve25519', {
  10848. type: 'mont',
  10849. prime: 'p25519',
  10850. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  10851. a: '76d06',
  10852. b: '0',
  10853. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  10854. hash: hash.sha256,
  10855. gRed: false,
  10856. g: [
  10857. '9'
  10858. ]
  10859. });
  10860. defineCurve('ed25519', {
  10861. type: 'edwards',
  10862. prime: 'p25519',
  10863. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  10864. a: '-1',
  10865. c: '1',
  10866. // -121665 * (121666^(-1)) (mod P)
  10867. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  10868. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  10869. hash: hash.sha256,
  10870. gRed: false,
  10871. g: [
  10872. '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
  10873. // 4/5
  10874. '6666666666666666666666666666666666666666666666666666666666666658'
  10875. ]
  10876. });
  10877. var pre;
  10878. try {
  10879. pre = require('./precomputed/secp256k1');
  10880. } catch (e) {
  10881. pre = undefined;
  10882. }
  10883. defineCurve('secp256k1', {
  10884. type: 'short',
  10885. prime: 'k256',
  10886. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  10887. a: '0',
  10888. b: '7',
  10889. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  10890. h: '1',
  10891. hash: hash.sha256,
  10892. // Precomputed endomorphism
  10893. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  10894. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  10895. basis: [
  10896. {
  10897. a: '3086d221a7d46bcde86c90e49284eb15',
  10898. b: '-e4437ed6010e88286f547fa90abfe4c3'
  10899. },
  10900. {
  10901. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  10902. b: '3086d221a7d46bcde86c90e49284eb15'
  10903. }
  10904. ],
  10905. gRed: false,
  10906. g: [
  10907. '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
  10908. '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
  10909. pre
  10910. ]
  10911. });
  10912. },{"../elliptic":65,"./precomputed/secp256k1":79,"hash.js":84}],72:[function(require,module,exports){
  10913. 'use strict';
  10914. var BN = require('bn.js');
  10915. var elliptic = require('../../elliptic');
  10916. var utils = elliptic.utils;
  10917. var assert = utils.assert;
  10918. var KeyPair = require('./key');
  10919. var Signature = require('./signature');
  10920. function EC(options) {
  10921. if (!(this instanceof EC))
  10922. return new EC(options);
  10923. // Shortcut `elliptic.ec(curve-name)`
  10924. if (typeof options === 'string') {
  10925. assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options);
  10926. options = elliptic.curves[options];
  10927. }
  10928. // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  10929. if (options instanceof elliptic.curves.PresetCurve)
  10930. options = { curve: options };
  10931. this.curve = options.curve.curve;
  10932. this.n = this.curve.n;
  10933. this.nh = this.n.ushrn(1);
  10934. this.g = this.curve.g;
  10935. // Point on curve
  10936. this.g = options.curve.g;
  10937. this.g.precompute(options.curve.n.bitLength() + 1);
  10938. // Hash for function for DRBG
  10939. this.hash = options.hash || options.curve.hash;
  10940. }
  10941. module.exports = EC;
  10942. EC.prototype.keyPair = function keyPair(options) {
  10943. return new KeyPair(this, options);
  10944. };
  10945. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  10946. return KeyPair.fromPrivate(this, priv, enc);
  10947. };
  10948. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  10949. return KeyPair.fromPublic(this, pub, enc);
  10950. };
  10951. EC.prototype.genKeyPair = function genKeyPair(options) {
  10952. if (!options)
  10953. options = {};
  10954. // Instantiate Hmac_DRBG
  10955. var drbg = new elliptic.hmacDRBG({
  10956. hash: this.hash,
  10957. pers: options.pers,
  10958. entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
  10959. nonce: this.n.toArray()
  10960. });
  10961. var bytes = this.n.byteLength();
  10962. var ns2 = this.n.sub(new BN(2));
  10963. do {
  10964. var priv = new BN(drbg.generate(bytes));
  10965. if (priv.cmp(ns2) > 0)
  10966. continue;
  10967. priv.iaddn(1);
  10968. return this.keyFromPrivate(priv);
  10969. } while (true);
  10970. };
  10971. EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
  10972. var delta = msg.byteLength() * 8 - this.n.bitLength();
  10973. if (delta > 0)
  10974. msg = msg.ushrn(delta);
  10975. if (!truncOnly && msg.cmp(this.n) >= 0)
  10976. return msg.sub(this.n);
  10977. else
  10978. return msg;
  10979. };
  10980. EC.prototype.sign = function sign(msg, key, enc, options) {
  10981. if (typeof enc === 'object') {
  10982. options = enc;
  10983. enc = null;
  10984. }
  10985. if (!options)
  10986. options = {};
  10987. key = this.keyFromPrivate(key, enc);
  10988. msg = this._truncateToN(new BN(msg, 16));
  10989. // Zero-extend key to provide enough entropy
  10990. var bytes = this.n.byteLength();
  10991. var bkey = key.getPrivate().toArray('be', bytes);
  10992. // Zero-extend nonce to have the same byte size as N
  10993. var nonce = msg.toArray('be', bytes);
  10994. // Instantiate Hmac_DRBG
  10995. var drbg = new elliptic.hmacDRBG({
  10996. hash: this.hash,
  10997. entropy: bkey,
  10998. nonce: nonce,
  10999. pers: options.pers,
  11000. persEnc: options.persEnc
  11001. });
  11002. // Number of bytes to generate
  11003. var ns1 = this.n.sub(new BN(1));
  11004. for (var iter = 0; true; iter++) {
  11005. var k = options.k ?
  11006. options.k(iter) :
  11007. new BN(drbg.generate(this.n.byteLength()));
  11008. k = this._truncateToN(k, true);
  11009. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
  11010. continue;
  11011. var kp = this.g.mul(k);
  11012. if (kp.isInfinity())
  11013. continue;
  11014. var kpX = kp.getX();
  11015. var r = kpX.umod(this.n);
  11016. if (r.cmpn(0) === 0)
  11017. continue;
  11018. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  11019. s = s.umod(this.n);
  11020. if (s.cmpn(0) === 0)
  11021. continue;
  11022. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
  11023. (kpX.cmp(r) !== 0 ? 2 : 0);
  11024. // Use complement of `s`, if it is > `n / 2`
  11025. if (options.canonical && s.cmp(this.nh) > 0) {
  11026. s = this.n.sub(s);
  11027. recoveryParam ^= 1;
  11028. }
  11029. return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
  11030. }
  11031. };
  11032. EC.prototype.verify = function verify(msg, signature, key, enc) {
  11033. msg = this._truncateToN(new BN(msg, 16));
  11034. key = this.keyFromPublic(key, enc);
  11035. signature = new Signature(signature, 'hex');
  11036. // Perform primitive values validation
  11037. var r = signature.r;
  11038. var s = signature.s;
  11039. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
  11040. return false;
  11041. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
  11042. return false;
  11043. // Validate signature
  11044. var sinv = s.invm(this.n);
  11045. var u1 = sinv.mul(msg).umod(this.n);
  11046. var u2 = sinv.mul(r).umod(this.n);
  11047. var p = this.g.mulAdd(u1, key.getPublic(), u2);
  11048. if (p.isInfinity())
  11049. return false;
  11050. return p.getX().umod(this.n).cmp(r) === 0;
  11051. };
  11052. EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
  11053. assert((3 & j) === j, 'The recovery param is more than two bits');
  11054. signature = new Signature(signature, enc);
  11055. var n = this.n;
  11056. var e = new BN(msg);
  11057. var r = signature.r;
  11058. var s = signature.s;
  11059. // A set LSB signifies that the y-coordinate is odd
  11060. var isYOdd = j & 1;
  11061. var isSecondKey = j >> 1;
  11062. if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
  11063. throw new Error('Unable to find sencond key candinate');
  11064. // 1.1. Let x = r + jn.
  11065. if (isSecondKey)
  11066. r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
  11067. else
  11068. r = this.curve.pointFromX(r, isYOdd);
  11069. var eNeg = n.sub(e);
  11070. // 1.6.1 Compute Q = r^-1 (sR - eG)
  11071. // Q = r^-1 (sR + -eG)
  11072. var rInv = signature.r.invm(n);
  11073. return this.g.mulAdd(eNeg, r, s).mul(rInv);
  11074. };
  11075. EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
  11076. signature = new Signature(signature, enc);
  11077. if (signature.recoveryParam !== null)
  11078. return signature.recoveryParam;
  11079. for (var i = 0; i < 4; i++) {
  11080. var Qprime;
  11081. try {
  11082. Qprime = this.recoverPubKey(e, signature, i);
  11083. } catch (e) {
  11084. continue;
  11085. }
  11086. if (Qprime.eq(Q))
  11087. return i;
  11088. }
  11089. throw new Error('Unable to find valid recovery factor');
  11090. };
  11091. },{"../../elliptic":65,"./key":73,"./signature":74,"bn.js":18}],73:[function(require,module,exports){
  11092. 'use strict';
  11093. var BN = require('bn.js');
  11094. function KeyPair(ec, options) {
  11095. this.ec = ec;
  11096. this.priv = null;
  11097. this.pub = null;
  11098. // KeyPair(ec, { priv: ..., pub: ... })
  11099. if (options.priv)
  11100. this._importPrivate(options.priv, options.privEnc);
  11101. if (options.pub)
  11102. this._importPublic(options.pub, options.pubEnc);
  11103. }
  11104. module.exports = KeyPair;
  11105. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  11106. if (pub instanceof KeyPair)
  11107. return pub;
  11108. return new KeyPair(ec, {
  11109. pub: pub,
  11110. pubEnc: enc
  11111. });
  11112. };
  11113. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  11114. if (priv instanceof KeyPair)
  11115. return priv;
  11116. return new KeyPair(ec, {
  11117. priv: priv,
  11118. privEnc: enc
  11119. });
  11120. };
  11121. KeyPair.prototype.validate = function validate() {
  11122. var pub = this.getPublic();
  11123. if (pub.isInfinity())
  11124. return { result: false, reason: 'Invalid public key' };
  11125. if (!pub.validate())
  11126. return { result: false, reason: 'Public key is not a point' };
  11127. if (!pub.mul(this.ec.curve.n).isInfinity())
  11128. return { result: false, reason: 'Public key * N != O' };
  11129. return { result: true, reason: null };
  11130. };
  11131. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  11132. // compact is optional argument
  11133. if (typeof compact === 'string') {
  11134. enc = compact;
  11135. compact = null;
  11136. }
  11137. if (!this.pub)
  11138. this.pub = this.ec.g.mul(this.priv);
  11139. if (!enc)
  11140. return this.pub;
  11141. return this.pub.encode(enc, compact);
  11142. };
  11143. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  11144. if (enc === 'hex')
  11145. return this.priv.toString(16, 2);
  11146. else
  11147. return this.priv;
  11148. };
  11149. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  11150. this.priv = new BN(key, enc || 16);
  11151. // Ensure that the priv won't be bigger than n, otherwise we may fail
  11152. // in fixed multiplication method
  11153. this.priv = this.priv.umod(this.ec.curve.n);
  11154. };
  11155. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  11156. if (key.x || key.y) {
  11157. this.pub = this.ec.curve.point(key.x, key.y);
  11158. return;
  11159. }
  11160. this.pub = this.ec.curve.decodePoint(key, enc);
  11161. };
  11162. // ECDH
  11163. KeyPair.prototype.derive = function derive(pub) {
  11164. return pub.mul(this.priv).getX();
  11165. };
  11166. // ECDSA
  11167. KeyPair.prototype.sign = function sign(msg, enc, options) {
  11168. return this.ec.sign(msg, this, enc, options);
  11169. };
  11170. KeyPair.prototype.verify = function verify(msg, signature) {
  11171. return this.ec.verify(msg, signature, this);
  11172. };
  11173. KeyPair.prototype.inspect = function inspect() {
  11174. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
  11175. ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  11176. };
  11177. },{"bn.js":18}],74:[function(require,module,exports){
  11178. 'use strict';
  11179. var BN = require('bn.js');
  11180. var elliptic = require('../../elliptic');
  11181. var utils = elliptic.utils;
  11182. var assert = utils.assert;
  11183. function Signature(options, enc) {
  11184. if (options instanceof Signature)
  11185. return options;
  11186. if (this._importDER(options, enc))
  11187. return;
  11188. assert(options.r && options.s, 'Signature without r or s');
  11189. this.r = new BN(options.r, 16);
  11190. this.s = new BN(options.s, 16);
  11191. if (options.recoveryParam === undefined)
  11192. this.recoveryParam = null;
  11193. else
  11194. this.recoveryParam = options.recoveryParam;
  11195. }
  11196. module.exports = Signature;
  11197. function Position() {
  11198. this.place = 0;
  11199. }
  11200. function getLength(buf, p) {
  11201. var initial = buf[p.place++];
  11202. if (!(initial & 0x80)) {
  11203. return initial;
  11204. }
  11205. var octetLen = initial & 0xf;
  11206. var val = 0;
  11207. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  11208. val <<= 8;
  11209. val |= buf[off];
  11210. }
  11211. p.place = off;
  11212. return val;
  11213. }
  11214. function rmPadding(buf) {
  11215. var i = 0;
  11216. var len = buf.length - 1;
  11217. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  11218. i++;
  11219. }
  11220. if (i === 0) {
  11221. return buf;
  11222. }
  11223. return buf.slice(i);
  11224. }
  11225. Signature.prototype._importDER = function _importDER(data, enc) {
  11226. data = utils.toArray(data, enc);
  11227. var p = new Position();
  11228. if (data[p.place++] !== 0x30) {
  11229. return false;
  11230. }
  11231. var len = getLength(data, p);
  11232. if ((len + p.place) !== data.length) {
  11233. return false;
  11234. }
  11235. if (data[p.place++] !== 0x02) {
  11236. return false;
  11237. }
  11238. var rlen = getLength(data, p);
  11239. var r = data.slice(p.place, rlen + p.place);
  11240. p.place += rlen;
  11241. if (data[p.place++] !== 0x02) {
  11242. return false;
  11243. }
  11244. var slen = getLength(data, p);
  11245. if (data.length !== slen + p.place) {
  11246. return false;
  11247. }
  11248. var s = data.slice(p.place, slen + p.place);
  11249. if (r[0] === 0 && (r[1] & 0x80)) {
  11250. r = r.slice(1);
  11251. }
  11252. if (s[0] === 0 && (s[1] & 0x80)) {
  11253. s = s.slice(1);
  11254. }
  11255. this.r = new BN(r);
  11256. this.s = new BN(s);
  11257. this.recoveryParam = null;
  11258. return true;
  11259. };
  11260. function constructLength(arr, len) {
  11261. if (len < 0x80) {
  11262. arr.push(len);
  11263. return;
  11264. }
  11265. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  11266. arr.push(octets | 0x80);
  11267. while (--octets) {
  11268. arr.push((len >>> (octets << 3)) & 0xff);
  11269. }
  11270. arr.push(len);
  11271. }
  11272. Signature.prototype.toDER = function toDER(enc) {
  11273. var r = this.r.toArray();
  11274. var s = this.s.toArray();
  11275. // Pad values
  11276. if (r[0] & 0x80)
  11277. r = [ 0 ].concat(r);
  11278. // Pad values
  11279. if (s[0] & 0x80)
  11280. s = [ 0 ].concat(s);
  11281. r = rmPadding(r);
  11282. s = rmPadding(s);
  11283. while (!s[0] && !(s[1] & 0x80)) {
  11284. s = s.slice(1);
  11285. }
  11286. var arr = [ 0x02 ];
  11287. constructLength(arr, r.length);
  11288. arr = arr.concat(r);
  11289. arr.push(0x02);
  11290. constructLength(arr, s.length);
  11291. var backHalf = arr.concat(s);
  11292. var res = [ 0x30 ];
  11293. constructLength(res, backHalf.length);
  11294. res = res.concat(backHalf);
  11295. return utils.encode(res, enc);
  11296. };
  11297. },{"../../elliptic":65,"bn.js":18}],75:[function(require,module,exports){
  11298. 'use strict';
  11299. var hash = require('hash.js');
  11300. var elliptic = require('../../elliptic');
  11301. var utils = elliptic.utils;
  11302. var assert = utils.assert;
  11303. var parseBytes = utils.parseBytes;
  11304. var KeyPair = require('./key');
  11305. var Signature = require('./signature');
  11306. function EDDSA(curve) {
  11307. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  11308. if (!(this instanceof EDDSA))
  11309. return new EDDSA(curve);
  11310. var curve = elliptic.curves[curve].curve;
  11311. this.curve = curve;
  11312. this.g = curve.g;
  11313. this.g.precompute(curve.n.bitLength() + 1);
  11314. this.pointClass = curve.point().constructor;
  11315. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  11316. this.hash = hash.sha512;
  11317. }
  11318. module.exports = EDDSA;
  11319. /**
  11320. * @param {Array|String} message - message bytes
  11321. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  11322. * @returns {Signature} - signature
  11323. */
  11324. EDDSA.prototype.sign = function sign(message, secret) {
  11325. message = parseBytes(message);
  11326. var key = this.keyFromSecret(secret);
  11327. var r = this.hashInt(key.messagePrefix(), message);
  11328. var R = this.g.mul(r);
  11329. var Rencoded = this.encodePoint(R);
  11330. var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
  11331. .mul(key.priv());
  11332. var S = r.add(s_).umod(this.curve.n);
  11333. return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
  11334. };
  11335. /**
  11336. * @param {Array} message - message bytes
  11337. * @param {Array|String|Signature} sig - sig bytes
  11338. * @param {Array|String|Point|KeyPair} pub - public key
  11339. * @returns {Boolean} - true if public key matches sig of message
  11340. */
  11341. EDDSA.prototype.verify = function verify(message, sig, pub) {
  11342. message = parseBytes(message);
  11343. sig = this.makeSignature(sig);
  11344. var key = this.keyFromPublic(pub);
  11345. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  11346. var SG = this.g.mul(sig.S());
  11347. var RplusAh = sig.R().add(key.pub().mul(h));
  11348. return RplusAh.eq(SG);
  11349. };
  11350. EDDSA.prototype.hashInt = function hashInt() {
  11351. var hash = this.hash();
  11352. for (var i = 0; i < arguments.length; i++)
  11353. hash.update(arguments[i]);
  11354. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  11355. };
  11356. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  11357. return KeyPair.fromPublic(this, pub);
  11358. };
  11359. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  11360. return KeyPair.fromSecret(this, secret);
  11361. };
  11362. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  11363. if (sig instanceof Signature)
  11364. return sig;
  11365. return new Signature(this, sig);
  11366. };
  11367. /**
  11368. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  11369. *
  11370. * EDDSA defines methods for encoding and decoding points and integers. These are
  11371. * helper convenience methods, that pass along to utility functions implied
  11372. * parameters.
  11373. *
  11374. */
  11375. EDDSA.prototype.encodePoint = function encodePoint(point) {
  11376. var enc = point.getY().toArray('le', this.encodingLength);
  11377. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  11378. return enc;
  11379. };
  11380. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  11381. bytes = utils.parseBytes(bytes);
  11382. var lastIx = bytes.length - 1;
  11383. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  11384. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  11385. var y = utils.intFromLE(normed);
  11386. return this.curve.pointFromY(y, xIsOdd);
  11387. };
  11388. EDDSA.prototype.encodeInt = function encodeInt(num) {
  11389. return num.toArray('le', this.encodingLength);
  11390. };
  11391. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  11392. return utils.intFromLE(bytes);
  11393. };
  11394. EDDSA.prototype.isPoint = function isPoint(val) {
  11395. return val instanceof this.pointClass;
  11396. };
  11397. },{"../../elliptic":65,"./key":76,"./signature":77,"hash.js":84}],76:[function(require,module,exports){
  11398. 'use strict';
  11399. var elliptic = require('../../elliptic');
  11400. var utils = elliptic.utils;
  11401. var assert = utils.assert;
  11402. var parseBytes = utils.parseBytes;
  11403. var cachedProperty = utils.cachedProperty;
  11404. /**
  11405. * @param {EDDSA} eddsa - instance
  11406. * @param {Object} params - public/private key parameters
  11407. *
  11408. * @param {Array<Byte>} [params.secret] - secret seed bytes
  11409. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  11410. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  11411. *
  11412. */
  11413. function KeyPair(eddsa, params) {
  11414. this.eddsa = eddsa;
  11415. this._secret = parseBytes(params.secret);
  11416. if (eddsa.isPoint(params.pub))
  11417. this._pub = params.pub;
  11418. else
  11419. this._pubBytes = parseBytes(params.pub);
  11420. }
  11421. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  11422. if (pub instanceof KeyPair)
  11423. return pub;
  11424. return new KeyPair(eddsa, { pub: pub });
  11425. };
  11426. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  11427. if (secret instanceof KeyPair)
  11428. return secret;
  11429. return new KeyPair(eddsa, { secret: secret });
  11430. };
  11431. KeyPair.prototype.secret = function secret() {
  11432. return this._secret;
  11433. };
  11434. cachedProperty(KeyPair, function pubBytes() {
  11435. return this.eddsa.encodePoint(this.pub());
  11436. });
  11437. cachedProperty(KeyPair, function pub() {
  11438. if (this._pubBytes)
  11439. return this.eddsa.decodePoint(this._pubBytes);
  11440. return this.eddsa.g.mul(this.priv());
  11441. });
  11442. cachedProperty(KeyPair, function privBytes() {
  11443. var eddsa = this.eddsa;
  11444. var hash = this.hash();
  11445. var lastIx = eddsa.encodingLength - 1;
  11446. var a = hash.slice(0, eddsa.encodingLength);
  11447. a[0] &= 248;
  11448. a[lastIx] &= 127;
  11449. a[lastIx] |= 64;
  11450. return a;
  11451. });
  11452. cachedProperty(KeyPair, function priv() {
  11453. return this.eddsa.decodeInt(this.privBytes());
  11454. });
  11455. cachedProperty(KeyPair, function hash() {
  11456. return this.eddsa.hash().update(this.secret()).digest();
  11457. });
  11458. cachedProperty(KeyPair, function messagePrefix() {
  11459. return this.hash().slice(this.eddsa.encodingLength);
  11460. });
  11461. KeyPair.prototype.sign = function sign(message) {
  11462. assert(this._secret, 'KeyPair can only verify');
  11463. return this.eddsa.sign(message, this);
  11464. };
  11465. KeyPair.prototype.verify = function verify(message, sig) {
  11466. return this.eddsa.verify(message, sig, this);
  11467. };
  11468. KeyPair.prototype.getSecret = function getSecret(enc) {
  11469. assert(this._secret, 'KeyPair is public only');
  11470. return utils.encode(this.secret(), enc);
  11471. };
  11472. KeyPair.prototype.getPublic = function getPublic(enc) {
  11473. return utils.encode(this.pubBytes(), enc);
  11474. };
  11475. module.exports = KeyPair;
  11476. },{"../../elliptic":65}],77:[function(require,module,exports){
  11477. 'use strict';
  11478. var BN = require('bn.js');
  11479. var elliptic = require('../../elliptic');
  11480. var utils = elliptic.utils;
  11481. var assert = utils.assert;
  11482. var cachedProperty = utils.cachedProperty;
  11483. var parseBytes = utils.parseBytes;
  11484. /**
  11485. * @param {EDDSA} eddsa - eddsa instance
  11486. * @param {Array<Bytes>|Object} sig -
  11487. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  11488. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  11489. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  11490. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  11491. */
  11492. function Signature(eddsa, sig) {
  11493. this.eddsa = eddsa;
  11494. if (typeof sig !== 'object')
  11495. sig = parseBytes(sig);
  11496. if (Array.isArray(sig)) {
  11497. sig = {
  11498. R: sig.slice(0, eddsa.encodingLength),
  11499. S: sig.slice(eddsa.encodingLength)
  11500. };
  11501. }
  11502. assert(sig.R && sig.S, 'Signature without R or S');
  11503. if (eddsa.isPoint(sig.R))
  11504. this._R = sig.R;
  11505. if (sig.S instanceof BN)
  11506. this._S = sig.S;
  11507. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  11508. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  11509. }
  11510. cachedProperty(Signature, function S() {
  11511. return this.eddsa.decodeInt(this.Sencoded());
  11512. });
  11513. cachedProperty(Signature, function R() {
  11514. return this.eddsa.decodePoint(this.Rencoded());
  11515. });
  11516. cachedProperty(Signature, function Rencoded() {
  11517. return this.eddsa.encodePoint(this.R());
  11518. });
  11519. cachedProperty(Signature, function Sencoded() {
  11520. return this.eddsa.encodeInt(this.S());
  11521. });
  11522. Signature.prototype.toBytes = function toBytes() {
  11523. return this.Rencoded().concat(this.Sencoded());
  11524. };
  11525. Signature.prototype.toHex = function toHex() {
  11526. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  11527. };
  11528. module.exports = Signature;
  11529. },{"../../elliptic":65,"bn.js":18}],78:[function(require,module,exports){
  11530. 'use strict';
  11531. var hash = require('hash.js');
  11532. var elliptic = require('../elliptic');
  11533. var utils = elliptic.utils;
  11534. var assert = utils.assert;
  11535. function HmacDRBG(options) {
  11536. if (!(this instanceof HmacDRBG))
  11537. return new HmacDRBG(options);
  11538. this.hash = options.hash;
  11539. this.predResist = !!options.predResist;
  11540. this.outLen = this.hash.outSize;
  11541. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  11542. this.reseed = null;
  11543. this.reseedInterval = null;
  11544. this.K = null;
  11545. this.V = null;
  11546. var entropy = utils.toArray(options.entropy, options.entropyEnc);
  11547. var nonce = utils.toArray(options.nonce, options.nonceEnc);
  11548. var pers = utils.toArray(options.pers, options.persEnc);
  11549. assert(entropy.length >= (this.minEntropy / 8),
  11550. 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  11551. this._init(entropy, nonce, pers);
  11552. }
  11553. module.exports = HmacDRBG;
  11554. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  11555. var seed = entropy.concat(nonce).concat(pers);
  11556. this.K = new Array(this.outLen / 8);
  11557. this.V = new Array(this.outLen / 8);
  11558. for (var i = 0; i < this.V.length; i++) {
  11559. this.K[i] = 0x00;
  11560. this.V[i] = 0x01;
  11561. }
  11562. this._update(seed);
  11563. this.reseed = 1;
  11564. this.reseedInterval = 0x1000000000000; // 2^48
  11565. };
  11566. HmacDRBG.prototype._hmac = function hmac() {
  11567. return new hash.hmac(this.hash, this.K);
  11568. };
  11569. HmacDRBG.prototype._update = function update(seed) {
  11570. var kmac = this._hmac()
  11571. .update(this.V)
  11572. .update([ 0x00 ]);
  11573. if (seed)
  11574. kmac = kmac.update(seed);
  11575. this.K = kmac.digest();
  11576. this.V = this._hmac().update(this.V).digest();
  11577. if (!seed)
  11578. return;
  11579. this.K = this._hmac()
  11580. .update(this.V)
  11581. .update([ 0x01 ])
  11582. .update(seed)
  11583. .digest();
  11584. this.V = this._hmac().update(this.V).digest();
  11585. };
  11586. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  11587. // Optional entropy enc
  11588. if (typeof entropyEnc !== 'string') {
  11589. addEnc = add;
  11590. add = entropyEnc;
  11591. entropyEnc = null;
  11592. }
  11593. entropy = utils.toBuffer(entropy, entropyEnc);
  11594. add = utils.toBuffer(add, addEnc);
  11595. assert(entropy.length >= (this.minEntropy / 8),
  11596. 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  11597. this._update(entropy.concat(add || []));
  11598. this.reseed = 1;
  11599. };
  11600. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  11601. if (this.reseed > this.reseedInterval)
  11602. throw new Error('Reseed is required');
  11603. // Optional encoding
  11604. if (typeof enc !== 'string') {
  11605. addEnc = add;
  11606. add = enc;
  11607. enc = null;
  11608. }
  11609. // Optional additional data
  11610. if (add) {
  11611. add = utils.toArray(add, addEnc);
  11612. this._update(add);
  11613. }
  11614. var temp = [];
  11615. while (temp.length < len) {
  11616. this.V = this._hmac().update(this.V).digest();
  11617. temp = temp.concat(this.V);
  11618. }
  11619. var res = temp.slice(0, len);
  11620. this._update(add);
  11621. this.reseed++;
  11622. return utils.encode(res, enc);
  11623. };
  11624. },{"../elliptic":65,"hash.js":84}],79:[function(require,module,exports){
  11625. module.exports = {
  11626. doubles: {
  11627. step: 4,
  11628. points: [
  11629. [
  11630. 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
  11631. 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
  11632. ],
  11633. [
  11634. '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
  11635. '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
  11636. ],
  11637. [
  11638. '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
  11639. 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
  11640. ],
  11641. [
  11642. '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
  11643. '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
  11644. ],
  11645. [
  11646. '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
  11647. '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
  11648. ],
  11649. [
  11650. '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
  11651. '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
  11652. ],
  11653. [
  11654. 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
  11655. '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
  11656. ],
  11657. [
  11658. '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
  11659. 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
  11660. ],
  11661. [
  11662. 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
  11663. '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
  11664. ],
  11665. [
  11666. 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
  11667. 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
  11668. ],
  11669. [
  11670. 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
  11671. '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
  11672. ],
  11673. [
  11674. '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
  11675. '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
  11676. ],
  11677. [
  11678. '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
  11679. '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
  11680. ],
  11681. [
  11682. '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
  11683. '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
  11684. ],
  11685. [
  11686. '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
  11687. '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
  11688. ],
  11689. [
  11690. '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
  11691. '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
  11692. ],
  11693. [
  11694. '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
  11695. '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
  11696. ],
  11697. [
  11698. '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
  11699. '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
  11700. ],
  11701. [
  11702. '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
  11703. 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
  11704. ],
  11705. [
  11706. 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
  11707. '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
  11708. ],
  11709. [
  11710. 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
  11711. '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
  11712. ],
  11713. [
  11714. '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
  11715. '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
  11716. ],
  11717. [
  11718. '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
  11719. '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
  11720. ],
  11721. [
  11722. 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
  11723. '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
  11724. ],
  11725. [
  11726. '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
  11727. 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
  11728. ],
  11729. [
  11730. 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
  11731. '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
  11732. ],
  11733. [
  11734. 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
  11735. 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
  11736. ],
  11737. [
  11738. 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
  11739. '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
  11740. ],
  11741. [
  11742. 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
  11743. 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
  11744. ],
  11745. [
  11746. 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
  11747. '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
  11748. ],
  11749. [
  11750. '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
  11751. 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
  11752. ],
  11753. [
  11754. '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
  11755. '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
  11756. ],
  11757. [
  11758. 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
  11759. '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
  11760. ],
  11761. [
  11762. '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
  11763. 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
  11764. ],
  11765. [
  11766. 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
  11767. '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
  11768. ],
  11769. [
  11770. 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
  11771. '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
  11772. ],
  11773. [
  11774. 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
  11775. 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
  11776. ],
  11777. [
  11778. '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
  11779. '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
  11780. ],
  11781. [
  11782. '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
  11783. '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
  11784. ],
  11785. [
  11786. '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
  11787. 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
  11788. ],
  11789. [
  11790. '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
  11791. '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
  11792. ],
  11793. [
  11794. 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
  11795. '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
  11796. ],
  11797. [
  11798. '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
  11799. '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
  11800. ],
  11801. [
  11802. '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
  11803. 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
  11804. ],
  11805. [
  11806. '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
  11807. '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
  11808. ],
  11809. [
  11810. 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
  11811. '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
  11812. ],
  11813. [
  11814. '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
  11815. 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
  11816. ],
  11817. [
  11818. 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
  11819. 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
  11820. ],
  11821. [
  11822. 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
  11823. '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
  11824. ],
  11825. [
  11826. '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
  11827. 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
  11828. ],
  11829. [
  11830. '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
  11831. 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
  11832. ],
  11833. [
  11834. 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
  11835. '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
  11836. ],
  11837. [
  11838. 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
  11839. '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
  11840. ],
  11841. [
  11842. 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
  11843. '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
  11844. ],
  11845. [
  11846. '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
  11847. 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
  11848. ],
  11849. [
  11850. '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
  11851. '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
  11852. ],
  11853. [
  11854. 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
  11855. 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
  11856. ],
  11857. [
  11858. '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
  11859. 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
  11860. ],
  11861. [
  11862. '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
  11863. '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
  11864. ],
  11865. [
  11866. '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
  11867. '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
  11868. ],
  11869. [
  11870. 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
  11871. 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
  11872. ],
  11873. [
  11874. '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
  11875. '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
  11876. ],
  11877. [
  11878. '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
  11879. '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
  11880. ],
  11881. [
  11882. 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
  11883. '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
  11884. ],
  11885. [
  11886. 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
  11887. 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
  11888. ]
  11889. ]
  11890. },
  11891. naf: {
  11892. wnd: 7,
  11893. points: [
  11894. [
  11895. 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
  11896. '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
  11897. ],
  11898. [
  11899. '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
  11900. 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
  11901. ],
  11902. [
  11903. '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
  11904. '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
  11905. ],
  11906. [
  11907. 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
  11908. 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
  11909. ],
  11910. [
  11911. '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
  11912. 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
  11913. ],
  11914. [
  11915. 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
  11916. 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
  11917. ],
  11918. [
  11919. 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
  11920. '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
  11921. ],
  11922. [
  11923. 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
  11924. '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
  11925. ],
  11926. [
  11927. '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
  11928. '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
  11929. ],
  11930. [
  11931. '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
  11932. '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
  11933. ],
  11934. [
  11935. '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
  11936. '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
  11937. ],
  11938. [
  11939. '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
  11940. '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
  11941. ],
  11942. [
  11943. 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
  11944. 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
  11945. ],
  11946. [
  11947. 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
  11948. '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
  11949. ],
  11950. [
  11951. '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
  11952. 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
  11953. ],
  11954. [
  11955. '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
  11956. 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
  11957. ],
  11958. [
  11959. '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
  11960. '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
  11961. ],
  11962. [
  11963. '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
  11964. '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
  11965. ],
  11966. [
  11967. '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
  11968. '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
  11969. ],
  11970. [
  11971. '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
  11972. 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
  11973. ],
  11974. [
  11975. 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
  11976. 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
  11977. ],
  11978. [
  11979. '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
  11980. '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
  11981. ],
  11982. [
  11983. '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
  11984. '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
  11985. ],
  11986. [
  11987. 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
  11988. 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
  11989. ],
  11990. [
  11991. '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
  11992. '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
  11993. ],
  11994. [
  11995. 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
  11996. 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
  11997. ],
  11998. [
  11999. 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
  12000. 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
  12001. ],
  12002. [
  12003. '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
  12004. '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
  12005. ],
  12006. [
  12007. '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
  12008. '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
  12009. ],
  12010. [
  12011. '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
  12012. '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
  12013. ],
  12014. [
  12015. 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
  12016. '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
  12017. ],
  12018. [
  12019. '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
  12020. '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
  12021. ],
  12022. [
  12023. 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
  12024. '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
  12025. ],
  12026. [
  12027. '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
  12028. 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
  12029. ],
  12030. [
  12031. '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
  12032. 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
  12033. ],
  12034. [
  12035. 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
  12036. 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
  12037. ],
  12038. [
  12039. '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
  12040. '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
  12041. ],
  12042. [
  12043. '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
  12044. 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
  12045. ],
  12046. [
  12047. 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
  12048. 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
  12049. ],
  12050. [
  12051. '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
  12052. '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
  12053. ],
  12054. [
  12055. '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
  12056. 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
  12057. ],
  12058. [
  12059. '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
  12060. '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
  12061. ],
  12062. [
  12063. '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
  12064. 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
  12065. ],
  12066. [
  12067. 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
  12068. '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
  12069. ],
  12070. [
  12071. '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
  12072. '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
  12073. ],
  12074. [
  12075. '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
  12076. 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
  12077. ],
  12078. [
  12079. '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
  12080. 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
  12081. ],
  12082. [
  12083. 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
  12084. 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
  12085. ],
  12086. [
  12087. 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
  12088. 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
  12089. ],
  12090. [
  12091. '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
  12092. '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
  12093. ],
  12094. [
  12095. '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
  12096. '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
  12097. ],
  12098. [
  12099. 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
  12100. '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
  12101. ],
  12102. [
  12103. 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
  12104. 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
  12105. ],
  12106. [
  12107. '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
  12108. '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
  12109. ],
  12110. [
  12111. '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
  12112. '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
  12113. ],
  12114. [
  12115. 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
  12116. '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
  12117. ],
  12118. [
  12119. '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
  12120. '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
  12121. ],
  12122. [
  12123. 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
  12124. 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
  12125. ],
  12126. [
  12127. '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
  12128. 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
  12129. ],
  12130. [
  12131. '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
  12132. '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
  12133. ],
  12134. [
  12135. 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
  12136. '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
  12137. ],
  12138. [
  12139. 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
  12140. '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
  12141. ],
  12142. [
  12143. '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
  12144. '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
  12145. ],
  12146. [
  12147. '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
  12148. '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
  12149. ],
  12150. [
  12151. '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
  12152. 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
  12153. ],
  12154. [
  12155. '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
  12156. 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
  12157. ],
  12158. [
  12159. '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
  12160. '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
  12161. ],
  12162. [
  12163. '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
  12164. '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
  12165. ],
  12166. [
  12167. '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
  12168. '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
  12169. ],
  12170. [
  12171. '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
  12172. 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
  12173. ],
  12174. [
  12175. 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
  12176. 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
  12177. ],
  12178. [
  12179. '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
  12180. 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
  12181. ],
  12182. [
  12183. 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
  12184. '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
  12185. ],
  12186. [
  12187. 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
  12188. '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
  12189. ],
  12190. [
  12191. 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
  12192. '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
  12193. ],
  12194. [
  12195. 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
  12196. '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
  12197. ],
  12198. [
  12199. '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
  12200. 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
  12201. ],
  12202. [
  12203. '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
  12204. '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
  12205. ],
  12206. [
  12207. '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
  12208. 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
  12209. ],
  12210. [
  12211. 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
  12212. 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
  12213. ],
  12214. [
  12215. 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
  12216. '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
  12217. ],
  12218. [
  12219. 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
  12220. 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
  12221. ],
  12222. [
  12223. 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
  12224. '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
  12225. ],
  12226. [
  12227. '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
  12228. '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
  12229. ],
  12230. [
  12231. 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
  12232. '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
  12233. ],
  12234. [
  12235. 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
  12236. '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
  12237. ],
  12238. [
  12239. '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
  12240. '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
  12241. ],
  12242. [
  12243. '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
  12244. 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
  12245. ],
  12246. [
  12247. 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
  12248. '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
  12249. ],
  12250. [
  12251. 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
  12252. '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
  12253. ],
  12254. [
  12255. 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
  12256. '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
  12257. ],
  12258. [
  12259. '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
  12260. '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
  12261. ],
  12262. [
  12263. 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
  12264. 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
  12265. ],
  12266. [
  12267. '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
  12268. 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
  12269. ],
  12270. [
  12271. 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
  12272. 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
  12273. ],
  12274. [
  12275. 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
  12276. '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
  12277. ],
  12278. [
  12279. '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
  12280. 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
  12281. ],
  12282. [
  12283. 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
  12284. '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
  12285. ],
  12286. [
  12287. 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
  12288. '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
  12289. ],
  12290. [
  12291. 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
  12292. '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
  12293. ],
  12294. [
  12295. '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
  12296. 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
  12297. ],
  12298. [
  12299. '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
  12300. 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
  12301. ],
  12302. [
  12303. 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
  12304. '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
  12305. ],
  12306. [
  12307. '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
  12308. 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
  12309. ],
  12310. [
  12311. '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
  12312. '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
  12313. ],
  12314. [
  12315. '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
  12316. 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
  12317. ],
  12318. [
  12319. 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
  12320. 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
  12321. ],
  12322. [
  12323. '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
  12324. 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
  12325. ],
  12326. [
  12327. '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
  12328. '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
  12329. ],
  12330. [
  12331. '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
  12332. 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
  12333. ],
  12334. [
  12335. '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
  12336. '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
  12337. ],
  12338. [
  12339. 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
  12340. 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
  12341. ],
  12342. [
  12343. '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
  12344. '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
  12345. ],
  12346. [
  12347. 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
  12348. '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
  12349. ],
  12350. [
  12351. '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
  12352. '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
  12353. ],
  12354. [
  12355. 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
  12356. 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
  12357. ],
  12358. [
  12359. 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
  12360. '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
  12361. ],
  12362. [
  12363. 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
  12364. 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
  12365. ],
  12366. [
  12367. '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
  12368. 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
  12369. ],
  12370. [
  12371. '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
  12372. '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
  12373. ],
  12374. [
  12375. '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
  12376. 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
  12377. ],
  12378. [
  12379. '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
  12380. '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
  12381. ],
  12382. [
  12383. '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
  12384. '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
  12385. ],
  12386. [
  12387. '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
  12388. 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
  12389. ],
  12390. [
  12391. '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
  12392. '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
  12393. ],
  12394. [
  12395. '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
  12396. '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
  12397. ],
  12398. [
  12399. '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
  12400. '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
  12401. ]
  12402. ]
  12403. }
  12404. };
  12405. },{}],80:[function(require,module,exports){
  12406. 'use strict';
  12407. var utils = exports;
  12408. var BN = require('bn.js');
  12409. utils.assert = function assert(val, msg) {
  12410. if (!val)
  12411. throw new Error(msg || 'Assertion failed');
  12412. };
  12413. function toArray(msg, enc) {
  12414. if (Array.isArray(msg))
  12415. return msg.slice();
  12416. if (!msg)
  12417. return [];
  12418. var res = [];
  12419. if (typeof msg !== 'string') {
  12420. for (var i = 0; i < msg.length; i++)
  12421. res[i] = msg[i] | 0;
  12422. return res;
  12423. }
  12424. if (!enc) {
  12425. for (var i = 0; i < msg.length; i++) {
  12426. var c = msg.charCodeAt(i);
  12427. var hi = c >> 8;
  12428. var lo = c & 0xff;
  12429. if (hi)
  12430. res.push(hi, lo);
  12431. else
  12432. res.push(lo);
  12433. }
  12434. } else if (enc === 'hex') {
  12435. msg = msg.replace(/[^a-z0-9]+/ig, '');
  12436. if (msg.length % 2 !== 0)
  12437. msg = '0' + msg;
  12438. for (var i = 0; i < msg.length; i += 2)
  12439. res.push(parseInt(msg[i] + msg[i + 1], 16));
  12440. }
  12441. return res;
  12442. }
  12443. utils.toArray = toArray;
  12444. function zero2(word) {
  12445. if (word.length === 1)
  12446. return '0' + word;
  12447. else
  12448. return word;
  12449. }
  12450. utils.zero2 = zero2;
  12451. function toHex(msg) {
  12452. var res = '';
  12453. for (var i = 0; i < msg.length; i++)
  12454. res += zero2(msg[i].toString(16));
  12455. return res;
  12456. }
  12457. utils.toHex = toHex;
  12458. utils.encode = function encode(arr, enc) {
  12459. if (enc === 'hex')
  12460. return toHex(arr);
  12461. else
  12462. return arr;
  12463. };
  12464. // Represent num in a w-NAF form
  12465. function getNAF(num, w) {
  12466. var naf = [];
  12467. var ws = 1 << (w + 1);
  12468. var k = num.clone();
  12469. while (k.cmpn(1) >= 0) {
  12470. var z;
  12471. if (k.isOdd()) {
  12472. var mod = k.andln(ws - 1);
  12473. if (mod > (ws >> 1) - 1)
  12474. z = (ws >> 1) - mod;
  12475. else
  12476. z = mod;
  12477. k.isubn(z);
  12478. } else {
  12479. z = 0;
  12480. }
  12481. naf.push(z);
  12482. // Optimization, shift by word if possible
  12483. var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
  12484. for (var i = 1; i < shift; i++)
  12485. naf.push(0);
  12486. k.iushrn(shift);
  12487. }
  12488. return naf;
  12489. }
  12490. utils.getNAF = getNAF;
  12491. // Represent k1, k2 in a Joint Sparse Form
  12492. function getJSF(k1, k2) {
  12493. var jsf = [
  12494. [],
  12495. []
  12496. ];
  12497. k1 = k1.clone();
  12498. k2 = k2.clone();
  12499. var d1 = 0;
  12500. var d2 = 0;
  12501. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  12502. // First phase
  12503. var m14 = (k1.andln(3) + d1) & 3;
  12504. var m24 = (k2.andln(3) + d2) & 3;
  12505. if (m14 === 3)
  12506. m14 = -1;
  12507. if (m24 === 3)
  12508. m24 = -1;
  12509. var u1;
  12510. if ((m14 & 1) === 0) {
  12511. u1 = 0;
  12512. } else {
  12513. var m8 = (k1.andln(7) + d1) & 7;
  12514. if ((m8 === 3 || m8 === 5) && m24 === 2)
  12515. u1 = -m14;
  12516. else
  12517. u1 = m14;
  12518. }
  12519. jsf[0].push(u1);
  12520. var u2;
  12521. if ((m24 & 1) === 0) {
  12522. u2 = 0;
  12523. } else {
  12524. var m8 = (k2.andln(7) + d2) & 7;
  12525. if ((m8 === 3 || m8 === 5) && m14 === 2)
  12526. u2 = -m24;
  12527. else
  12528. u2 = m24;
  12529. }
  12530. jsf[1].push(u2);
  12531. // Second phase
  12532. if (2 * d1 === u1 + 1)
  12533. d1 = 1 - d1;
  12534. if (2 * d2 === u2 + 1)
  12535. d2 = 1 - d2;
  12536. k1.iushrn(1);
  12537. k2.iushrn(1);
  12538. }
  12539. return jsf;
  12540. }
  12541. utils.getJSF = getJSF;
  12542. function cachedProperty(obj, computer) {
  12543. var name = computer.name;
  12544. var key = '_' + name;
  12545. obj.prototype[name] = function cachedProperty() {
  12546. return this[key] !== undefined ? this[key] :
  12547. this[key] = computer.call(this);
  12548. };
  12549. }
  12550. utils.cachedProperty = cachedProperty;
  12551. function parseBytes(bytes) {
  12552. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
  12553. bytes;
  12554. }
  12555. utils.parseBytes = parseBytes;
  12556. function intFromLE(bytes) {
  12557. return new BN(bytes, 'hex', 'le');
  12558. }
  12559. utils.intFromLE = intFromLE;
  12560. },{"bn.js":18}],81:[function(require,module,exports){
  12561. module.exports={
  12562. "_args": [
  12563. [
  12564. "elliptic@^6.0.0",
  12565. "/home/guillaume/workspace/lesspass/extension/node_modules/browserify-sign"
  12566. ]
  12567. ],
  12568. "_from": "elliptic@>=6.0.0 <7.0.0",
  12569. "_id": "elliptic@6.2.3",
  12570. "_inCache": true,
  12571. "_installable": true,
  12572. "_location": "/elliptic",
  12573. "_nodeVersion": "5.4.1",
  12574. "_npmUser": {
  12575. "email": "fedor@indutny.com",
  12576. "name": "indutny"
  12577. },
  12578. "_npmVersion": "3.3.12",
  12579. "_phantomChildren": {},
  12580. "_requested": {
  12581. "name": "elliptic",
  12582. "raw": "elliptic@^6.0.0",
  12583. "rawSpec": "^6.0.0",
  12584. "scope": null,
  12585. "spec": ">=6.0.0 <7.0.0",
  12586. "type": "range"
  12587. },
  12588. "_requiredBy": [
  12589. "/browserify-sign",
  12590. "/create-ecdh"
  12591. ],
  12592. "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.2.3.tgz",
  12593. "_shasum": "18e46d7306b0951275a2d42063270a14b74ebe99",
  12594. "_shrinkwrap": null,
  12595. "_spec": "elliptic@^6.0.0",
  12596. "_where": "/home/guillaume/workspace/lesspass/extension/node_modules/browserify-sign",
  12597. "author": {
  12598. "email": "fedor@indutny.com",
  12599. "name": "Fedor Indutny"
  12600. },
  12601. "bugs": {
  12602. "url": "https://github.com/indutny/elliptic/issues"
  12603. },
  12604. "dependencies": {
  12605. "bn.js": "^4.0.0",
  12606. "brorand": "^1.0.1",
  12607. "hash.js": "^1.0.0",
  12608. "inherits": "^2.0.1"
  12609. },
  12610. "description": "EC cryptography",
  12611. "devDependencies": {
  12612. "coveralls": "^2.11.3",
  12613. "istanbul": "^0.4.2",
  12614. "jscs": "^2.9.0",
  12615. "jshint": "^2.6.0",
  12616. "mocha": "^2.1.0"
  12617. },
  12618. "directories": {},
  12619. "dist": {
  12620. "shasum": "18e46d7306b0951275a2d42063270a14b74ebe99",
  12621. "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.2.3.tgz"
  12622. },
  12623. "files": [
  12624. "lib"
  12625. ],
  12626. "gitHead": "c32f20b22b420eb6af3c6dda28963deb7facf823",
  12627. "homepage": "https://github.com/indutny/elliptic",
  12628. "keywords": [
  12629. "Cryptography",
  12630. "EC",
  12631. "Elliptic",
  12632. "curve"
  12633. ],
  12634. "license": "MIT",
  12635. "main": "lib/elliptic.js",
  12636. "maintainers": [
  12637. {
  12638. "name": "indutny",
  12639. "email": "fedor@indutny.com"
  12640. }
  12641. ],
  12642. "name": "elliptic",
  12643. "optionalDependencies": {},
  12644. "readme": "ERROR: No README data found!",
  12645. "repository": {
  12646. "type": "git",
  12647. "url": "git+ssh://git@github.com/indutny/elliptic.git"
  12648. },
  12649. "scripts": {
  12650. "coverage": "npm run unit --coverage",
  12651. "coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
  12652. "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/*.js",
  12653. "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/*.js",
  12654. "lint": "npm run jscs && npm run jshint",
  12655. "test": "npm run lint && npm run unit",
  12656. "unit": "istanbul test _mocha --reporter=spec test/*-test.js"
  12657. },
  12658. "version": "6.2.3"
  12659. }
  12660. },{}],82:[function(require,module,exports){
  12661. // Copyright Joyent, Inc. and other Node contributors.
  12662. //
  12663. // Permission is hereby granted, free of charge, to any person obtaining a
  12664. // copy of this software and associated documentation files (the
  12665. // "Software"), to deal in the Software without restriction, including
  12666. // without limitation the rights to use, copy, modify, merge, publish,
  12667. // distribute, sublicense, and/or sell copies of the Software, and to permit
  12668. // persons to whom the Software is furnished to do so, subject to the
  12669. // following conditions:
  12670. //
  12671. // The above copyright notice and this permission notice shall be included
  12672. // in all copies or substantial portions of the Software.
  12673. //
  12674. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12675. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12676. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  12677. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  12678. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  12679. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  12680. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  12681. function EventEmitter() {
  12682. this._events = this._events || {};
  12683. this._maxListeners = this._maxListeners || undefined;
  12684. }
  12685. module.exports = EventEmitter;
  12686. // Backwards-compat with node 0.10.x
  12687. EventEmitter.EventEmitter = EventEmitter;
  12688. EventEmitter.prototype._events = undefined;
  12689. EventEmitter.prototype._maxListeners = undefined;
  12690. // By default EventEmitters will print a warning if more than 10 listeners are
  12691. // added to it. This is a useful default which helps finding memory leaks.
  12692. EventEmitter.defaultMaxListeners = 10;
  12693. // Obviously not all Emitters should be limited to 10. This function allows
  12694. // that to be increased. Set to zero for unlimited.
  12695. EventEmitter.prototype.setMaxListeners = function(n) {
  12696. if (!isNumber(n) || n < 0 || isNaN(n))
  12697. throw TypeError('n must be a positive number');
  12698. this._maxListeners = n;
  12699. return this;
  12700. };
  12701. EventEmitter.prototype.emit = function(type) {
  12702. var er, handler, len, args, i, listeners;
  12703. if (!this._events)
  12704. this._events = {};
  12705. // If there is no 'error' event listener then throw.
  12706. if (type === 'error') {
  12707. if (!this._events.error ||
  12708. (isObject(this._events.error) && !this._events.error.length)) {
  12709. er = arguments[1];
  12710. if (er instanceof Error) {
  12711. throw er; // Unhandled 'error' event
  12712. }
  12713. throw TypeError('Uncaught, unspecified "error" event.');
  12714. }
  12715. }
  12716. handler = this._events[type];
  12717. if (isUndefined(handler))
  12718. return false;
  12719. if (isFunction(handler)) {
  12720. switch (arguments.length) {
  12721. // fast cases
  12722. case 1:
  12723. handler.call(this);
  12724. break;
  12725. case 2:
  12726. handler.call(this, arguments[1]);
  12727. break;
  12728. case 3:
  12729. handler.call(this, arguments[1], arguments[2]);
  12730. break;
  12731. // slower
  12732. default:
  12733. args = Array.prototype.slice.call(arguments, 1);
  12734. handler.apply(this, args);
  12735. }
  12736. } else if (isObject(handler)) {
  12737. args = Array.prototype.slice.call(arguments, 1);
  12738. listeners = handler.slice();
  12739. len = listeners.length;
  12740. for (i = 0; i < len; i++)
  12741. listeners[i].apply(this, args);
  12742. }
  12743. return true;
  12744. };
  12745. EventEmitter.prototype.addListener = function(type, listener) {
  12746. var m;
  12747. if (!isFunction(listener))
  12748. throw TypeError('listener must be a function');
  12749. if (!this._events)
  12750. this._events = {};
  12751. // To avoid recursion in the case that type === "newListener"! Before
  12752. // adding it to the listeners, first emit "newListener".
  12753. if (this._events.newListener)
  12754. this.emit('newListener', type,
  12755. isFunction(listener.listener) ?
  12756. listener.listener : listener);
  12757. if (!this._events[type])
  12758. // Optimize the case of one listener. Don't need the extra array object.
  12759. this._events[type] = listener;
  12760. else if (isObject(this._events[type]))
  12761. // If we've already got an array, just append.
  12762. this._events[type].push(listener);
  12763. else
  12764. // Adding the second element, need to change to array.
  12765. this._events[type] = [this._events[type], listener];
  12766. // Check for listener leak
  12767. if (isObject(this._events[type]) && !this._events[type].warned) {
  12768. if (!isUndefined(this._maxListeners)) {
  12769. m = this._maxListeners;
  12770. } else {
  12771. m = EventEmitter.defaultMaxListeners;
  12772. }
  12773. if (m && m > 0 && this._events[type].length > m) {
  12774. this._events[type].warned = true;
  12775. console.error('(node) warning: possible EventEmitter memory ' +
  12776. 'leak detected. %d listeners added. ' +
  12777. 'Use emitter.setMaxListeners() to increase limit.',
  12778. this._events[type].length);
  12779. if (typeof console.trace === 'function') {
  12780. // not supported in IE 10
  12781. console.trace();
  12782. }
  12783. }
  12784. }
  12785. return this;
  12786. };
  12787. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  12788. EventEmitter.prototype.once = function(type, listener) {
  12789. if (!isFunction(listener))
  12790. throw TypeError('listener must be a function');
  12791. var fired = false;
  12792. function g() {
  12793. this.removeListener(type, g);
  12794. if (!fired) {
  12795. fired = true;
  12796. listener.apply(this, arguments);
  12797. }
  12798. }
  12799. g.listener = listener;
  12800. this.on(type, g);
  12801. return this;
  12802. };
  12803. // emits a 'removeListener' event iff the listener was removed
  12804. EventEmitter.prototype.removeListener = function(type, listener) {
  12805. var list, position, length, i;
  12806. if (!isFunction(listener))
  12807. throw TypeError('listener must be a function');
  12808. if (!this._events || !this._events[type])
  12809. return this;
  12810. list = this._events[type];
  12811. length = list.length;
  12812. position = -1;
  12813. if (list === listener ||
  12814. (isFunction(list.listener) && list.listener === listener)) {
  12815. delete this._events[type];
  12816. if (this._events.removeListener)
  12817. this.emit('removeListener', type, listener);
  12818. } else if (isObject(list)) {
  12819. for (i = length; i-- > 0;) {
  12820. if (list[i] === listener ||
  12821. (list[i].listener && list[i].listener === listener)) {
  12822. position = i;
  12823. break;
  12824. }
  12825. }
  12826. if (position < 0)
  12827. return this;
  12828. if (list.length === 1) {
  12829. list.length = 0;
  12830. delete this._events[type];
  12831. } else {
  12832. list.splice(position, 1);
  12833. }
  12834. if (this._events.removeListener)
  12835. this.emit('removeListener', type, listener);
  12836. }
  12837. return this;
  12838. };
  12839. EventEmitter.prototype.removeAllListeners = function(type) {
  12840. var key, listeners;
  12841. if (!this._events)
  12842. return this;
  12843. // not listening for removeListener, no need to emit
  12844. if (!this._events.removeListener) {
  12845. if (arguments.length === 0)
  12846. this._events = {};
  12847. else if (this._events[type])
  12848. delete this._events[type];
  12849. return this;
  12850. }
  12851. // emit removeListener for all listeners on all events
  12852. if (arguments.length === 0) {
  12853. for (key in this._events) {
  12854. if (key === 'removeListener') continue;
  12855. this.removeAllListeners(key);
  12856. }
  12857. this.removeAllListeners('removeListener');
  12858. this._events = {};
  12859. return this;
  12860. }
  12861. listeners = this._events[type];
  12862. if (isFunction(listeners)) {
  12863. this.removeListener(type, listeners);
  12864. } else if (listeners) {
  12865. // LIFO order
  12866. while (listeners.length)
  12867. this.removeListener(type, listeners[listeners.length - 1]);
  12868. }
  12869. delete this._events[type];
  12870. return this;
  12871. };
  12872. EventEmitter.prototype.listeners = function(type) {
  12873. var ret;
  12874. if (!this._events || !this._events[type])
  12875. ret = [];
  12876. else if (isFunction(this._events[type]))
  12877. ret = [this._events[type]];
  12878. else
  12879. ret = this._events[type].slice();
  12880. return ret;
  12881. };
  12882. EventEmitter.prototype.listenerCount = function(type) {
  12883. if (this._events) {
  12884. var evlistener = this._events[type];
  12885. if (isFunction(evlistener))
  12886. return 1;
  12887. else if (evlistener)
  12888. return evlistener.length;
  12889. }
  12890. return 0;
  12891. };
  12892. EventEmitter.listenerCount = function(emitter, type) {
  12893. return emitter.listenerCount(type);
  12894. };
  12895. function isFunction(arg) {
  12896. return typeof arg === 'function';
  12897. }
  12898. function isNumber(arg) {
  12899. return typeof arg === 'number';
  12900. }
  12901. function isObject(arg) {
  12902. return typeof arg === 'object' && arg !== null;
  12903. }
  12904. function isUndefined(arg) {
  12905. return arg === void 0;
  12906. }
  12907. },{}],83:[function(require,module,exports){
  12908. (function (Buffer){
  12909. var md5 = require('create-hash/md5')
  12910. module.exports = EVP_BytesToKey
  12911. function EVP_BytesToKey (password, salt, keyLen, ivLen) {
  12912. if (!Buffer.isBuffer(password)) {
  12913. password = new Buffer(password, 'binary')
  12914. }
  12915. if (salt && !Buffer.isBuffer(salt)) {
  12916. salt = new Buffer(salt, 'binary')
  12917. }
  12918. keyLen = keyLen / 8
  12919. ivLen = ivLen || 0
  12920. var ki = 0
  12921. var ii = 0
  12922. var key = new Buffer(keyLen)
  12923. var iv = new Buffer(ivLen)
  12924. var addmd = 0
  12925. var md_buf
  12926. var i
  12927. var bufs = []
  12928. while (true) {
  12929. if (addmd++ > 0) {
  12930. bufs.push(md_buf)
  12931. }
  12932. bufs.push(password)
  12933. if (salt) {
  12934. bufs.push(salt)
  12935. }
  12936. md_buf = md5(Buffer.concat(bufs))
  12937. bufs = []
  12938. i = 0
  12939. if (keyLen > 0) {
  12940. while (true) {
  12941. if (keyLen === 0) {
  12942. break
  12943. }
  12944. if (i === md_buf.length) {
  12945. break
  12946. }
  12947. key[ki++] = md_buf[i]
  12948. keyLen--
  12949. i++
  12950. }
  12951. }
  12952. if (ivLen > 0 && i !== md_buf.length) {
  12953. while (true) {
  12954. if (ivLen === 0) {
  12955. break
  12956. }
  12957. if (i === md_buf.length) {
  12958. break
  12959. }
  12960. iv[ii++] = md_buf[i]
  12961. ivLen--
  12962. i++
  12963. }
  12964. }
  12965. if (keyLen === 0 && ivLen === 0) {
  12966. break
  12967. }
  12968. }
  12969. for (i = 0; i < md_buf.length; i++) {
  12970. md_buf[i] = 0
  12971. }
  12972. return {
  12973. key: key,
  12974. iv: iv
  12975. }
  12976. }
  12977. }).call(this,require("buffer").Buffer)
  12978. },{"buffer":46,"create-hash/md5":52}],84:[function(require,module,exports){
  12979. var hash = exports;
  12980. hash.utils = require('./hash/utils');
  12981. hash.common = require('./hash/common');
  12982. hash.sha = require('./hash/sha');
  12983. hash.ripemd = require('./hash/ripemd');
  12984. hash.hmac = require('./hash/hmac');
  12985. // Proxy hash functions to the main object
  12986. hash.sha1 = hash.sha.sha1;
  12987. hash.sha256 = hash.sha.sha256;
  12988. hash.sha224 = hash.sha.sha224;
  12989. hash.sha384 = hash.sha.sha384;
  12990. hash.sha512 = hash.sha.sha512;
  12991. hash.ripemd160 = hash.ripemd.ripemd160;
  12992. },{"./hash/common":85,"./hash/hmac":86,"./hash/ripemd":87,"./hash/sha":88,"./hash/utils":89}],85:[function(require,module,exports){
  12993. var hash = require('../hash');
  12994. var utils = hash.utils;
  12995. var assert = utils.assert;
  12996. function BlockHash() {
  12997. this.pending = null;
  12998. this.pendingTotal = 0;
  12999. this.blockSize = this.constructor.blockSize;
  13000. this.outSize = this.constructor.outSize;
  13001. this.hmacStrength = this.constructor.hmacStrength;
  13002. this.padLength = this.constructor.padLength / 8;
  13003. this.endian = 'big';
  13004. this._delta8 = this.blockSize / 8;
  13005. this._delta32 = this.blockSize / 32;
  13006. }
  13007. exports.BlockHash = BlockHash;
  13008. BlockHash.prototype.update = function update(msg, enc) {
  13009. // Convert message to array, pad it, and join into 32bit blocks
  13010. msg = utils.toArray(msg, enc);
  13011. if (!this.pending)
  13012. this.pending = msg;
  13013. else
  13014. this.pending = this.pending.concat(msg);
  13015. this.pendingTotal += msg.length;
  13016. // Enough data, try updating
  13017. if (this.pending.length >= this._delta8) {
  13018. msg = this.pending;
  13019. // Process pending data in blocks
  13020. var r = msg.length % this._delta8;
  13021. this.pending = msg.slice(msg.length - r, msg.length);
  13022. if (this.pending.length === 0)
  13023. this.pending = null;
  13024. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  13025. for (var i = 0; i < msg.length; i += this._delta32)
  13026. this._update(msg, i, i + this._delta32);
  13027. }
  13028. return this;
  13029. };
  13030. BlockHash.prototype.digest = function digest(enc) {
  13031. this.update(this._pad());
  13032. assert(this.pending === null);
  13033. return this._digest(enc);
  13034. };
  13035. BlockHash.prototype._pad = function pad() {
  13036. var len = this.pendingTotal;
  13037. var bytes = this._delta8;
  13038. var k = bytes - ((len + this.padLength) % bytes);
  13039. var res = new Array(k + this.padLength);
  13040. res[0] = 0x80;
  13041. for (var i = 1; i < k; i++)
  13042. res[i] = 0;
  13043. // Append length
  13044. len <<= 3;
  13045. if (this.endian === 'big') {
  13046. for (var t = 8; t < this.padLength; t++)
  13047. res[i++] = 0;
  13048. res[i++] = 0;
  13049. res[i++] = 0;
  13050. res[i++] = 0;
  13051. res[i++] = 0;
  13052. res[i++] = (len >>> 24) & 0xff;
  13053. res[i++] = (len >>> 16) & 0xff;
  13054. res[i++] = (len >>> 8) & 0xff;
  13055. res[i++] = len & 0xff;
  13056. } else {
  13057. res[i++] = len & 0xff;
  13058. res[i++] = (len >>> 8) & 0xff;
  13059. res[i++] = (len >>> 16) & 0xff;
  13060. res[i++] = (len >>> 24) & 0xff;
  13061. res[i++] = 0;
  13062. res[i++] = 0;
  13063. res[i++] = 0;
  13064. res[i++] = 0;
  13065. for (var t = 8; t < this.padLength; t++)
  13066. res[i++] = 0;
  13067. }
  13068. return res;
  13069. };
  13070. },{"../hash":84}],86:[function(require,module,exports){
  13071. var hmac = exports;
  13072. var hash = require('../hash');
  13073. var utils = hash.utils;
  13074. var assert = utils.assert;
  13075. function Hmac(hash, key, enc) {
  13076. if (!(this instanceof Hmac))
  13077. return new Hmac(hash, key, enc);
  13078. this.Hash = hash;
  13079. this.blockSize = hash.blockSize / 8;
  13080. this.outSize = hash.outSize / 8;
  13081. this.inner = null;
  13082. this.outer = null;
  13083. this._init(utils.toArray(key, enc));
  13084. }
  13085. module.exports = Hmac;
  13086. Hmac.prototype._init = function init(key) {
  13087. // Shorten key, if needed
  13088. if (key.length > this.blockSize)
  13089. key = new this.Hash().update(key).digest();
  13090. assert(key.length <= this.blockSize);
  13091. // Add padding to key
  13092. for (var i = key.length; i < this.blockSize; i++)
  13093. key.push(0);
  13094. for (var i = 0; i < key.length; i++)
  13095. key[i] ^= 0x36;
  13096. this.inner = new this.Hash().update(key);
  13097. // 0x36 ^ 0x5c = 0x6a
  13098. for (var i = 0; i < key.length; i++)
  13099. key[i] ^= 0x6a;
  13100. this.outer = new this.Hash().update(key);
  13101. };
  13102. Hmac.prototype.update = function update(msg, enc) {
  13103. this.inner.update(msg, enc);
  13104. return this;
  13105. };
  13106. Hmac.prototype.digest = function digest(enc) {
  13107. this.outer.update(this.inner.digest());
  13108. return this.outer.digest(enc);
  13109. };
  13110. },{"../hash":84}],87:[function(require,module,exports){
  13111. var hash = require('../hash');
  13112. var utils = hash.utils;
  13113. var rotl32 = utils.rotl32;
  13114. var sum32 = utils.sum32;
  13115. var sum32_3 = utils.sum32_3;
  13116. var sum32_4 = utils.sum32_4;
  13117. var BlockHash = hash.common.BlockHash;
  13118. function RIPEMD160() {
  13119. if (!(this instanceof RIPEMD160))
  13120. return new RIPEMD160();
  13121. BlockHash.call(this);
  13122. this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
  13123. this.endian = 'little';
  13124. }
  13125. utils.inherits(RIPEMD160, BlockHash);
  13126. exports.ripemd160 = RIPEMD160;
  13127. RIPEMD160.blockSize = 512;
  13128. RIPEMD160.outSize = 160;
  13129. RIPEMD160.hmacStrength = 192;
  13130. RIPEMD160.padLength = 64;
  13131. RIPEMD160.prototype._update = function update(msg, start) {
  13132. var A = this.h[0];
  13133. var B = this.h[1];
  13134. var C = this.h[2];
  13135. var D = this.h[3];
  13136. var E = this.h[4];
  13137. var Ah = A;
  13138. var Bh = B;
  13139. var Ch = C;
  13140. var Dh = D;
  13141. var Eh = E;
  13142. for (var j = 0; j < 80; j++) {
  13143. var T = sum32(
  13144. rotl32(
  13145. sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
  13146. s[j]),
  13147. E);
  13148. A = E;
  13149. E = D;
  13150. D = rotl32(C, 10);
  13151. C = B;
  13152. B = T;
  13153. T = sum32(
  13154. rotl32(
  13155. sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
  13156. sh[j]),
  13157. Eh);
  13158. Ah = Eh;
  13159. Eh = Dh;
  13160. Dh = rotl32(Ch, 10);
  13161. Ch = Bh;
  13162. Bh = T;
  13163. }
  13164. T = sum32_3(this.h[1], C, Dh);
  13165. this.h[1] = sum32_3(this.h[2], D, Eh);
  13166. this.h[2] = sum32_3(this.h[3], E, Ah);
  13167. this.h[3] = sum32_3(this.h[4], A, Bh);
  13168. this.h[4] = sum32_3(this.h[0], B, Ch);
  13169. this.h[0] = T;
  13170. };
  13171. RIPEMD160.prototype._digest = function digest(enc) {
  13172. if (enc === 'hex')
  13173. return utils.toHex32(this.h, 'little');
  13174. else
  13175. return utils.split32(this.h, 'little');
  13176. };
  13177. function f(j, x, y, z) {
  13178. if (j <= 15)
  13179. return x ^ y ^ z;
  13180. else if (j <= 31)
  13181. return (x & y) | ((~x) & z);
  13182. else if (j <= 47)
  13183. return (x | (~y)) ^ z;
  13184. else if (j <= 63)
  13185. return (x & z) | (y & (~z));
  13186. else
  13187. return x ^ (y | (~z));
  13188. }
  13189. function K(j) {
  13190. if (j <= 15)
  13191. return 0x00000000;
  13192. else if (j <= 31)
  13193. return 0x5a827999;
  13194. else if (j <= 47)
  13195. return 0x6ed9eba1;
  13196. else if (j <= 63)
  13197. return 0x8f1bbcdc;
  13198. else
  13199. return 0xa953fd4e;
  13200. }
  13201. function Kh(j) {
  13202. if (j <= 15)
  13203. return 0x50a28be6;
  13204. else if (j <= 31)
  13205. return 0x5c4dd124;
  13206. else if (j <= 47)
  13207. return 0x6d703ef3;
  13208. else if (j <= 63)
  13209. return 0x7a6d76e9;
  13210. else
  13211. return 0x00000000;
  13212. }
  13213. var r = [
  13214. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  13215. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  13216. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  13217. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  13218. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  13219. ];
  13220. var rh = [
  13221. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  13222. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  13223. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  13224. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  13225. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  13226. ];
  13227. var s = [
  13228. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  13229. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  13230. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  13231. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  13232. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  13233. ];
  13234. var sh = [
  13235. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  13236. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  13237. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  13238. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  13239. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  13240. ];
  13241. },{"../hash":84}],88:[function(require,module,exports){
  13242. var hash = require('../hash');
  13243. var utils = hash.utils;
  13244. var assert = utils.assert;
  13245. var rotr32 = utils.rotr32;
  13246. var rotl32 = utils.rotl32;
  13247. var sum32 = utils.sum32;
  13248. var sum32_4 = utils.sum32_4;
  13249. var sum32_5 = utils.sum32_5;
  13250. var rotr64_hi = utils.rotr64_hi;
  13251. var rotr64_lo = utils.rotr64_lo;
  13252. var shr64_hi = utils.shr64_hi;
  13253. var shr64_lo = utils.shr64_lo;
  13254. var sum64 = utils.sum64;
  13255. var sum64_hi = utils.sum64_hi;
  13256. var sum64_lo = utils.sum64_lo;
  13257. var sum64_4_hi = utils.sum64_4_hi;
  13258. var sum64_4_lo = utils.sum64_4_lo;
  13259. var sum64_5_hi = utils.sum64_5_hi;
  13260. var sum64_5_lo = utils.sum64_5_lo;
  13261. var BlockHash = hash.common.BlockHash;
  13262. var sha256_K = [
  13263. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  13264. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  13265. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  13266. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  13267. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  13268. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  13269. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  13270. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  13271. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  13272. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  13273. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  13274. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  13275. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  13276. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  13277. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  13278. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  13279. ];
  13280. var sha512_K = [
  13281. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  13282. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  13283. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  13284. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  13285. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  13286. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  13287. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  13288. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  13289. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  13290. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  13291. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  13292. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  13293. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  13294. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  13295. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  13296. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  13297. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  13298. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  13299. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  13300. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  13301. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  13302. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  13303. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  13304. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  13305. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  13306. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  13307. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  13308. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  13309. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  13310. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  13311. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  13312. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  13313. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  13314. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  13315. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  13316. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  13317. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  13318. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  13319. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  13320. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  13321. ];
  13322. var sha1_K = [
  13323. 0x5A827999, 0x6ED9EBA1,
  13324. 0x8F1BBCDC, 0xCA62C1D6
  13325. ];
  13326. function SHA256() {
  13327. if (!(this instanceof SHA256))
  13328. return new SHA256();
  13329. BlockHash.call(this);
  13330. this.h = [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  13331. 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ];
  13332. this.k = sha256_K;
  13333. this.W = new Array(64);
  13334. }
  13335. utils.inherits(SHA256, BlockHash);
  13336. exports.sha256 = SHA256;
  13337. SHA256.blockSize = 512;
  13338. SHA256.outSize = 256;
  13339. SHA256.hmacStrength = 192;
  13340. SHA256.padLength = 64;
  13341. SHA256.prototype._update = function _update(msg, start) {
  13342. var W = this.W;
  13343. for (var i = 0; i < 16; i++)
  13344. W[i] = msg[start + i];
  13345. for (; i < W.length; i++)
  13346. W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  13347. var a = this.h[0];
  13348. var b = this.h[1];
  13349. var c = this.h[2];
  13350. var d = this.h[3];
  13351. var e = this.h[4];
  13352. var f = this.h[5];
  13353. var g = this.h[6];
  13354. var h = this.h[7];
  13355. assert(this.k.length === W.length);
  13356. for (var i = 0; i < W.length; i++) {
  13357. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  13358. var T2 = sum32(s0_256(a), maj32(a, b, c));
  13359. h = g;
  13360. g = f;
  13361. f = e;
  13362. e = sum32(d, T1);
  13363. d = c;
  13364. c = b;
  13365. b = a;
  13366. a = sum32(T1, T2);
  13367. }
  13368. this.h[0] = sum32(this.h[0], a);
  13369. this.h[1] = sum32(this.h[1], b);
  13370. this.h[2] = sum32(this.h[2], c);
  13371. this.h[3] = sum32(this.h[3], d);
  13372. this.h[4] = sum32(this.h[4], e);
  13373. this.h[5] = sum32(this.h[5], f);
  13374. this.h[6] = sum32(this.h[6], g);
  13375. this.h[7] = sum32(this.h[7], h);
  13376. };
  13377. SHA256.prototype._digest = function digest(enc) {
  13378. if (enc === 'hex')
  13379. return utils.toHex32(this.h, 'big');
  13380. else
  13381. return utils.split32(this.h, 'big');
  13382. };
  13383. function SHA224() {
  13384. if (!(this instanceof SHA224))
  13385. return new SHA224();
  13386. SHA256.call(this);
  13387. this.h = [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  13388. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
  13389. }
  13390. utils.inherits(SHA224, SHA256);
  13391. exports.sha224 = SHA224;
  13392. SHA224.blockSize = 512;
  13393. SHA224.outSize = 224;
  13394. SHA224.hmacStrength = 192;
  13395. SHA224.padLength = 64;
  13396. SHA224.prototype._digest = function digest(enc) {
  13397. // Just truncate output
  13398. if (enc === 'hex')
  13399. return utils.toHex32(this.h.slice(0, 7), 'big');
  13400. else
  13401. return utils.split32(this.h.slice(0, 7), 'big');
  13402. };
  13403. function SHA512() {
  13404. if (!(this instanceof SHA512))
  13405. return new SHA512();
  13406. BlockHash.call(this);
  13407. this.h = [ 0x6a09e667, 0xf3bcc908,
  13408. 0xbb67ae85, 0x84caa73b,
  13409. 0x3c6ef372, 0xfe94f82b,
  13410. 0xa54ff53a, 0x5f1d36f1,
  13411. 0x510e527f, 0xade682d1,
  13412. 0x9b05688c, 0x2b3e6c1f,
  13413. 0x1f83d9ab, 0xfb41bd6b,
  13414. 0x5be0cd19, 0x137e2179 ];
  13415. this.k = sha512_K;
  13416. this.W = new Array(160);
  13417. }
  13418. utils.inherits(SHA512, BlockHash);
  13419. exports.sha512 = SHA512;
  13420. SHA512.blockSize = 1024;
  13421. SHA512.outSize = 512;
  13422. SHA512.hmacStrength = 192;
  13423. SHA512.padLength = 128;
  13424. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  13425. var W = this.W;
  13426. // 32 x 32bit words
  13427. for (var i = 0; i < 32; i++)
  13428. W[i] = msg[start + i];
  13429. for (; i < W.length; i += 2) {
  13430. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  13431. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  13432. var c1_hi = W[i - 14]; // i - 7
  13433. var c1_lo = W[i - 13];
  13434. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  13435. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  13436. var c3_hi = W[i - 32]; // i - 16
  13437. var c3_lo = W[i - 31];
  13438. W[i] = sum64_4_hi(c0_hi, c0_lo,
  13439. c1_hi, c1_lo,
  13440. c2_hi, c2_lo,
  13441. c3_hi, c3_lo);
  13442. W[i + 1] = sum64_4_lo(c0_hi, c0_lo,
  13443. c1_hi, c1_lo,
  13444. c2_hi, c2_lo,
  13445. c3_hi, c3_lo);
  13446. }
  13447. };
  13448. SHA512.prototype._update = function _update(msg, start) {
  13449. this._prepareBlock(msg, start);
  13450. var W = this.W;
  13451. var ah = this.h[0];
  13452. var al = this.h[1];
  13453. var bh = this.h[2];
  13454. var bl = this.h[3];
  13455. var ch = this.h[4];
  13456. var cl = this.h[5];
  13457. var dh = this.h[6];
  13458. var dl = this.h[7];
  13459. var eh = this.h[8];
  13460. var el = this.h[9];
  13461. var fh = this.h[10];
  13462. var fl = this.h[11];
  13463. var gh = this.h[12];
  13464. var gl = this.h[13];
  13465. var hh = this.h[14];
  13466. var hl = this.h[15];
  13467. assert(this.k.length === W.length);
  13468. for (var i = 0; i < W.length; i += 2) {
  13469. var c0_hi = hh;
  13470. var c0_lo = hl;
  13471. var c1_hi = s1_512_hi(eh, el);
  13472. var c1_lo = s1_512_lo(eh, el);
  13473. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  13474. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  13475. var c3_hi = this.k[i];
  13476. var c3_lo = this.k[i + 1];
  13477. var c4_hi = W[i];
  13478. var c4_lo = W[i + 1];
  13479. var T1_hi = sum64_5_hi(c0_hi, c0_lo,
  13480. c1_hi, c1_lo,
  13481. c2_hi, c2_lo,
  13482. c3_hi, c3_lo,
  13483. c4_hi, c4_lo);
  13484. var T1_lo = sum64_5_lo(c0_hi, c0_lo,
  13485. c1_hi, c1_lo,
  13486. c2_hi, c2_lo,
  13487. c3_hi, c3_lo,
  13488. c4_hi, c4_lo);
  13489. var c0_hi = s0_512_hi(ah, al);
  13490. var c0_lo = s0_512_lo(ah, al);
  13491. var c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  13492. var c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  13493. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  13494. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  13495. hh = gh;
  13496. hl = gl;
  13497. gh = fh;
  13498. gl = fl;
  13499. fh = eh;
  13500. fl = el;
  13501. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  13502. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  13503. dh = ch;
  13504. dl = cl;
  13505. ch = bh;
  13506. cl = bl;
  13507. bh = ah;
  13508. bl = al;
  13509. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  13510. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  13511. }
  13512. sum64(this.h, 0, ah, al);
  13513. sum64(this.h, 2, bh, bl);
  13514. sum64(this.h, 4, ch, cl);
  13515. sum64(this.h, 6, dh, dl);
  13516. sum64(this.h, 8, eh, el);
  13517. sum64(this.h, 10, fh, fl);
  13518. sum64(this.h, 12, gh, gl);
  13519. sum64(this.h, 14, hh, hl);
  13520. };
  13521. SHA512.prototype._digest = function digest(enc) {
  13522. if (enc === 'hex')
  13523. return utils.toHex32(this.h, 'big');
  13524. else
  13525. return utils.split32(this.h, 'big');
  13526. };
  13527. function SHA384() {
  13528. if (!(this instanceof SHA384))
  13529. return new SHA384();
  13530. SHA512.call(this);
  13531. this.h = [ 0xcbbb9d5d, 0xc1059ed8,
  13532. 0x629a292a, 0x367cd507,
  13533. 0x9159015a, 0x3070dd17,
  13534. 0x152fecd8, 0xf70e5939,
  13535. 0x67332667, 0xffc00b31,
  13536. 0x8eb44a87, 0x68581511,
  13537. 0xdb0c2e0d, 0x64f98fa7,
  13538. 0x47b5481d, 0xbefa4fa4 ];
  13539. }
  13540. utils.inherits(SHA384, SHA512);
  13541. exports.sha384 = SHA384;
  13542. SHA384.blockSize = 1024;
  13543. SHA384.outSize = 384;
  13544. SHA384.hmacStrength = 192;
  13545. SHA384.padLength = 128;
  13546. SHA384.prototype._digest = function digest(enc) {
  13547. if (enc === 'hex')
  13548. return utils.toHex32(this.h.slice(0, 12), 'big');
  13549. else
  13550. return utils.split32(this.h.slice(0, 12), 'big');
  13551. };
  13552. function SHA1() {
  13553. if (!(this instanceof SHA1))
  13554. return new SHA1();
  13555. BlockHash.call(this);
  13556. this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe,
  13557. 0x10325476, 0xc3d2e1f0 ];
  13558. this.W = new Array(80);
  13559. }
  13560. utils.inherits(SHA1, BlockHash);
  13561. exports.sha1 = SHA1;
  13562. SHA1.blockSize = 512;
  13563. SHA1.outSize = 160;
  13564. SHA1.hmacStrength = 80;
  13565. SHA1.padLength = 64;
  13566. SHA1.prototype._update = function _update(msg, start) {
  13567. var W = this.W;
  13568. for (var i = 0; i < 16; i++)
  13569. W[i] = msg[start + i];
  13570. for(; i < W.length; i++)
  13571. W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  13572. var a = this.h[0];
  13573. var b = this.h[1];
  13574. var c = this.h[2];
  13575. var d = this.h[3];
  13576. var e = this.h[4];
  13577. for (var i = 0; i < W.length; i++) {
  13578. var s = ~~(i / 20);
  13579. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  13580. e = d;
  13581. d = c;
  13582. c = rotl32(b, 30);
  13583. b = a;
  13584. a = t;
  13585. }
  13586. this.h[0] = sum32(this.h[0], a);
  13587. this.h[1] = sum32(this.h[1], b);
  13588. this.h[2] = sum32(this.h[2], c);
  13589. this.h[3] = sum32(this.h[3], d);
  13590. this.h[4] = sum32(this.h[4], e);
  13591. };
  13592. SHA1.prototype._digest = function digest(enc) {
  13593. if (enc === 'hex')
  13594. return utils.toHex32(this.h, 'big');
  13595. else
  13596. return utils.split32(this.h, 'big');
  13597. };
  13598. function ch32(x, y, z) {
  13599. return (x & y) ^ ((~x) & z);
  13600. }
  13601. function maj32(x, y, z) {
  13602. return (x & y) ^ (x & z) ^ (y & z);
  13603. }
  13604. function p32(x, y, z) {
  13605. return x ^ y ^ z;
  13606. }
  13607. function s0_256(x) {
  13608. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  13609. }
  13610. function s1_256(x) {
  13611. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  13612. }
  13613. function g0_256(x) {
  13614. return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
  13615. }
  13616. function g1_256(x) {
  13617. return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
  13618. }
  13619. function ft_1(s, x, y, z) {
  13620. if (s === 0)
  13621. return ch32(x, y, z);
  13622. if (s === 1 || s === 3)
  13623. return p32(x, y, z);
  13624. if (s === 2)
  13625. return maj32(x, y, z);
  13626. }
  13627. function ch64_hi(xh, xl, yh, yl, zh, zl) {
  13628. var r = (xh & yh) ^ ((~xh) & zh);
  13629. if (r < 0)
  13630. r += 0x100000000;
  13631. return r;
  13632. }
  13633. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  13634. var r = (xl & yl) ^ ((~xl) & zl);
  13635. if (r < 0)
  13636. r += 0x100000000;
  13637. return r;
  13638. }
  13639. function maj64_hi(xh, xl, yh, yl, zh, zl) {
  13640. var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
  13641. if (r < 0)
  13642. r += 0x100000000;
  13643. return r;
  13644. }
  13645. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  13646. var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
  13647. if (r < 0)
  13648. r += 0x100000000;
  13649. return r;
  13650. }
  13651. function s0_512_hi(xh, xl) {
  13652. var c0_hi = rotr64_hi(xh, xl, 28);
  13653. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  13654. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  13655. var r = c0_hi ^ c1_hi ^ c2_hi;
  13656. if (r < 0)
  13657. r += 0x100000000;
  13658. return r;
  13659. }
  13660. function s0_512_lo(xh, xl) {
  13661. var c0_lo = rotr64_lo(xh, xl, 28);
  13662. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  13663. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  13664. var r = c0_lo ^ c1_lo ^ c2_lo;
  13665. if (r < 0)
  13666. r += 0x100000000;
  13667. return r;
  13668. }
  13669. function s1_512_hi(xh, xl) {
  13670. var c0_hi = rotr64_hi(xh, xl, 14);
  13671. var c1_hi = rotr64_hi(xh, xl, 18);
  13672. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  13673. var r = c0_hi ^ c1_hi ^ c2_hi;
  13674. if (r < 0)
  13675. r += 0x100000000;
  13676. return r;
  13677. }
  13678. function s1_512_lo(xh, xl) {
  13679. var c0_lo = rotr64_lo(xh, xl, 14);
  13680. var c1_lo = rotr64_lo(xh, xl, 18);
  13681. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  13682. var r = c0_lo ^ c1_lo ^ c2_lo;
  13683. if (r < 0)
  13684. r += 0x100000000;
  13685. return r;
  13686. }
  13687. function g0_512_hi(xh, xl) {
  13688. var c0_hi = rotr64_hi(xh, xl, 1);
  13689. var c1_hi = rotr64_hi(xh, xl, 8);
  13690. var c2_hi = shr64_hi(xh, xl, 7);
  13691. var r = c0_hi ^ c1_hi ^ c2_hi;
  13692. if (r < 0)
  13693. r += 0x100000000;
  13694. return r;
  13695. }
  13696. function g0_512_lo(xh, xl) {
  13697. var c0_lo = rotr64_lo(xh, xl, 1);
  13698. var c1_lo = rotr64_lo(xh, xl, 8);
  13699. var c2_lo = shr64_lo(xh, xl, 7);
  13700. var r = c0_lo ^ c1_lo ^ c2_lo;
  13701. if (r < 0)
  13702. r += 0x100000000;
  13703. return r;
  13704. }
  13705. function g1_512_hi(xh, xl) {
  13706. var c0_hi = rotr64_hi(xh, xl, 19);
  13707. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  13708. var c2_hi = shr64_hi(xh, xl, 6);
  13709. var r = c0_hi ^ c1_hi ^ c2_hi;
  13710. if (r < 0)
  13711. r += 0x100000000;
  13712. return r;
  13713. }
  13714. function g1_512_lo(xh, xl) {
  13715. var c0_lo = rotr64_lo(xh, xl, 19);
  13716. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  13717. var c2_lo = shr64_lo(xh, xl, 6);
  13718. var r = c0_lo ^ c1_lo ^ c2_lo;
  13719. if (r < 0)
  13720. r += 0x100000000;
  13721. return r;
  13722. }
  13723. },{"../hash":84}],89:[function(require,module,exports){
  13724. var utils = exports;
  13725. var inherits = require('inherits');
  13726. function toArray(msg, enc) {
  13727. if (Array.isArray(msg))
  13728. return msg.slice();
  13729. if (!msg)
  13730. return [];
  13731. var res = [];
  13732. if (typeof msg === 'string') {
  13733. if (!enc) {
  13734. for (var i = 0; i < msg.length; i++) {
  13735. var c = msg.charCodeAt(i);
  13736. var hi = c >> 8;
  13737. var lo = c & 0xff;
  13738. if (hi)
  13739. res.push(hi, lo);
  13740. else
  13741. res.push(lo);
  13742. }
  13743. } else if (enc === 'hex') {
  13744. msg = msg.replace(/[^a-z0-9]+/ig, '');
  13745. if (msg.length % 2 !== 0)
  13746. msg = '0' + msg;
  13747. for (var i = 0; i < msg.length; i += 2)
  13748. res.push(parseInt(msg[i] + msg[i + 1], 16));
  13749. }
  13750. } else {
  13751. for (var i = 0; i < msg.length; i++)
  13752. res[i] = msg[i] | 0;
  13753. }
  13754. return res;
  13755. }
  13756. utils.toArray = toArray;
  13757. function toHex(msg) {
  13758. var res = '';
  13759. for (var i = 0; i < msg.length; i++)
  13760. res += zero2(msg[i].toString(16));
  13761. return res;
  13762. }
  13763. utils.toHex = toHex;
  13764. function htonl(w) {
  13765. var res = (w >>> 24) |
  13766. ((w >>> 8) & 0xff00) |
  13767. ((w << 8) & 0xff0000) |
  13768. ((w & 0xff) << 24);
  13769. return res >>> 0;
  13770. }
  13771. utils.htonl = htonl;
  13772. function toHex32(msg, endian) {
  13773. var res = '';
  13774. for (var i = 0; i < msg.length; i++) {
  13775. var w = msg[i];
  13776. if (endian === 'little')
  13777. w = htonl(w);
  13778. res += zero8(w.toString(16));
  13779. }
  13780. return res;
  13781. }
  13782. utils.toHex32 = toHex32;
  13783. function zero2(word) {
  13784. if (word.length === 1)
  13785. return '0' + word;
  13786. else
  13787. return word;
  13788. }
  13789. utils.zero2 = zero2;
  13790. function zero8(word) {
  13791. if (word.length === 7)
  13792. return '0' + word;
  13793. else if (word.length === 6)
  13794. return '00' + word;
  13795. else if (word.length === 5)
  13796. return '000' + word;
  13797. else if (word.length === 4)
  13798. return '0000' + word;
  13799. else if (word.length === 3)
  13800. return '00000' + word;
  13801. else if (word.length === 2)
  13802. return '000000' + word;
  13803. else if (word.length === 1)
  13804. return '0000000' + word;
  13805. else
  13806. return word;
  13807. }
  13808. utils.zero8 = zero8;
  13809. function join32(msg, start, end, endian) {
  13810. var len = end - start;
  13811. assert(len % 4 === 0);
  13812. var res = new Array(len / 4);
  13813. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  13814. var w;
  13815. if (endian === 'big')
  13816. w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
  13817. else
  13818. w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
  13819. res[i] = w >>> 0;
  13820. }
  13821. return res;
  13822. }
  13823. utils.join32 = join32;
  13824. function split32(msg, endian) {
  13825. var res = new Array(msg.length * 4);
  13826. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  13827. var m = msg[i];
  13828. if (endian === 'big') {
  13829. res[k] = m >>> 24;
  13830. res[k + 1] = (m >>> 16) & 0xff;
  13831. res[k + 2] = (m >>> 8) & 0xff;
  13832. res[k + 3] = m & 0xff;
  13833. } else {
  13834. res[k + 3] = m >>> 24;
  13835. res[k + 2] = (m >>> 16) & 0xff;
  13836. res[k + 1] = (m >>> 8) & 0xff;
  13837. res[k] = m & 0xff;
  13838. }
  13839. }
  13840. return res;
  13841. }
  13842. utils.split32 = split32;
  13843. function rotr32(w, b) {
  13844. return (w >>> b) | (w << (32 - b));
  13845. }
  13846. utils.rotr32 = rotr32;
  13847. function rotl32(w, b) {
  13848. return (w << b) | (w >>> (32 - b));
  13849. }
  13850. utils.rotl32 = rotl32;
  13851. function sum32(a, b) {
  13852. return (a + b) >>> 0;
  13853. }
  13854. utils.sum32 = sum32;
  13855. function sum32_3(a, b, c) {
  13856. return (a + b + c) >>> 0;
  13857. }
  13858. utils.sum32_3 = sum32_3;
  13859. function sum32_4(a, b, c, d) {
  13860. return (a + b + c + d) >>> 0;
  13861. }
  13862. utils.sum32_4 = sum32_4;
  13863. function sum32_5(a, b, c, d, e) {
  13864. return (a + b + c + d + e) >>> 0;
  13865. }
  13866. utils.sum32_5 = sum32_5;
  13867. function assert(cond, msg) {
  13868. if (!cond)
  13869. throw new Error(msg || 'Assertion failed');
  13870. }
  13871. utils.assert = assert;
  13872. utils.inherits = inherits;
  13873. function sum64(buf, pos, ah, al) {
  13874. var bh = buf[pos];
  13875. var bl = buf[pos + 1];
  13876. var lo = (al + bl) >>> 0;
  13877. var hi = (lo < al ? 1 : 0) + ah + bh;
  13878. buf[pos] = hi >>> 0;
  13879. buf[pos + 1] = lo;
  13880. }
  13881. exports.sum64 = sum64;
  13882. function sum64_hi(ah, al, bh, bl) {
  13883. var lo = (al + bl) >>> 0;
  13884. var hi = (lo < al ? 1 : 0) + ah + bh;
  13885. return hi >>> 0;
  13886. };
  13887. exports.sum64_hi = sum64_hi;
  13888. function sum64_lo(ah, al, bh, bl) {
  13889. var lo = al + bl;
  13890. return lo >>> 0;
  13891. };
  13892. exports.sum64_lo = sum64_lo;
  13893. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  13894. var carry = 0;
  13895. var lo = al;
  13896. lo = (lo + bl) >>> 0;
  13897. carry += lo < al ? 1 : 0;
  13898. lo = (lo + cl) >>> 0;
  13899. carry += lo < cl ? 1 : 0;
  13900. lo = (lo + dl) >>> 0;
  13901. carry += lo < dl ? 1 : 0;
  13902. var hi = ah + bh + ch + dh + carry;
  13903. return hi >>> 0;
  13904. };
  13905. exports.sum64_4_hi = sum64_4_hi;
  13906. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  13907. var lo = al + bl + cl + dl;
  13908. return lo >>> 0;
  13909. };
  13910. exports.sum64_4_lo = sum64_4_lo;
  13911. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  13912. var carry = 0;
  13913. var lo = al;
  13914. lo = (lo + bl) >>> 0;
  13915. carry += lo < al ? 1 : 0;
  13916. lo = (lo + cl) >>> 0;
  13917. carry += lo < cl ? 1 : 0;
  13918. lo = (lo + dl) >>> 0;
  13919. carry += lo < dl ? 1 : 0;
  13920. lo = (lo + el) >>> 0;
  13921. carry += lo < el ? 1 : 0;
  13922. var hi = ah + bh + ch + dh + eh + carry;
  13923. return hi >>> 0;
  13924. };
  13925. exports.sum64_5_hi = sum64_5_hi;
  13926. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  13927. var lo = al + bl + cl + dl + el;
  13928. return lo >>> 0;
  13929. };
  13930. exports.sum64_5_lo = sum64_5_lo;
  13931. function rotr64_hi(ah, al, num) {
  13932. var r = (al << (32 - num)) | (ah >>> num);
  13933. return r >>> 0;
  13934. };
  13935. exports.rotr64_hi = rotr64_hi;
  13936. function rotr64_lo(ah, al, num) {
  13937. var r = (ah << (32 - num)) | (al >>> num);
  13938. return r >>> 0;
  13939. };
  13940. exports.rotr64_lo = rotr64_lo;
  13941. function shr64_hi(ah, al, num) {
  13942. return ah >>> num;
  13943. };
  13944. exports.shr64_hi = shr64_hi;
  13945. function shr64_lo(ah, al, num) {
  13946. var r = (ah << (32 - num)) | (al >>> num);
  13947. return r >>> 0;
  13948. };
  13949. exports.shr64_lo = shr64_lo;
  13950. },{"inherits":92}],90:[function(require,module,exports){
  13951. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  13952. var e, m
  13953. var eLen = nBytes * 8 - mLen - 1
  13954. var eMax = (1 << eLen) - 1
  13955. var eBias = eMax >> 1
  13956. var nBits = -7
  13957. var i = isLE ? (nBytes - 1) : 0
  13958. var d = isLE ? -1 : 1
  13959. var s = buffer[offset + i]
  13960. i += d
  13961. e = s & ((1 << (-nBits)) - 1)
  13962. s >>= (-nBits)
  13963. nBits += eLen
  13964. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  13965. m = e & ((1 << (-nBits)) - 1)
  13966. e >>= (-nBits)
  13967. nBits += mLen
  13968. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  13969. if (e === 0) {
  13970. e = 1 - eBias
  13971. } else if (e === eMax) {
  13972. return m ? NaN : ((s ? -1 : 1) * Infinity)
  13973. } else {
  13974. m = m + Math.pow(2, mLen)
  13975. e = e - eBias
  13976. }
  13977. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  13978. }
  13979. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  13980. var e, m, c
  13981. var eLen = nBytes * 8 - mLen - 1
  13982. var eMax = (1 << eLen) - 1
  13983. var eBias = eMax >> 1
  13984. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  13985. var i = isLE ? 0 : (nBytes - 1)
  13986. var d = isLE ? 1 : -1
  13987. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  13988. value = Math.abs(value)
  13989. if (isNaN(value) || value === Infinity) {
  13990. m = isNaN(value) ? 1 : 0
  13991. e = eMax
  13992. } else {
  13993. e = Math.floor(Math.log(value) / Math.LN2)
  13994. if (value * (c = Math.pow(2, -e)) < 1) {
  13995. e--
  13996. c *= 2
  13997. }
  13998. if (e + eBias >= 1) {
  13999. value += rt / c
  14000. } else {
  14001. value += rt * Math.pow(2, 1 - eBias)
  14002. }
  14003. if (value * c >= 2) {
  14004. e++
  14005. c /= 2
  14006. }
  14007. if (e + eBias >= eMax) {
  14008. m = 0
  14009. e = eMax
  14010. } else if (e + eBias >= 1) {
  14011. m = (value * c - 1) * Math.pow(2, mLen)
  14012. e = e + eBias
  14013. } else {
  14014. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  14015. e = 0
  14016. }
  14017. }
  14018. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  14019. e = (e << mLen) | m
  14020. eLen += mLen
  14021. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  14022. buffer[offset + i - d] |= s * 128
  14023. }
  14024. },{}],91:[function(require,module,exports){
  14025. var indexOf = [].indexOf;
  14026. module.exports = function(arr, obj){
  14027. if (indexOf) return arr.indexOf(obj);
  14028. for (var i = 0; i < arr.length; ++i) {
  14029. if (arr[i] === obj) return i;
  14030. }
  14031. return -1;
  14032. };
  14033. },{}],92:[function(require,module,exports){
  14034. if (typeof Object.create === 'function') {
  14035. // implementation from standard node.js 'util' module
  14036. module.exports = function inherits(ctor, superCtor) {
  14037. ctor.super_ = superCtor
  14038. ctor.prototype = Object.create(superCtor.prototype, {
  14039. constructor: {
  14040. value: ctor,
  14041. enumerable: false,
  14042. writable: true,
  14043. configurable: true
  14044. }
  14045. });
  14046. };
  14047. } else {
  14048. // old school shim for old browsers
  14049. module.exports = function inherits(ctor, superCtor) {
  14050. ctor.super_ = superCtor
  14051. var TempCtor = function () {}
  14052. TempCtor.prototype = superCtor.prototype
  14053. ctor.prototype = new TempCtor()
  14054. ctor.prototype.constructor = ctor
  14055. }
  14056. }
  14057. },{}],93:[function(require,module,exports){
  14058. /**
  14059. * Determine if an object is Buffer
  14060. *
  14061. * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  14062. * License: MIT
  14063. *
  14064. * `npm install is-buffer`
  14065. */
  14066. module.exports = function (obj) {
  14067. return !!(obj != null &&
  14068. (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
  14069. (obj.constructor &&
  14070. typeof obj.constructor.isBuffer === 'function' &&
  14071. obj.constructor.isBuffer(obj))
  14072. ))
  14073. }
  14074. },{}],94:[function(require,module,exports){
  14075. var toString = {}.toString;
  14076. module.exports = Array.isArray || function (arr) {
  14077. return toString.call(arr) == '[object Array]';
  14078. };
  14079. },{}],95:[function(require,module,exports){
  14080. 'use strict';
  14081. var text = require('./text');
  14082. var passwordGenerator = require('./password-generator');
  14083. module.exports = {
  14084. createPassword: createPassword,
  14085. createMasterPassword: passwordGenerator.createMasterPassword
  14086. };
  14087. function createPassword(masterPassword, entry) {
  14088. var hash = passwordGenerator._createHash(masterPassword, entry);
  14089. var template = passwordGenerator._getTemplate(entry.password.settings);
  14090. return text._encode(hash, template);
  14091. }
  14092. },{"./password-generator":96,"./text":97}],96:[function(require,module,exports){
  14093. 'use strict';
  14094. var crypto = require('crypto');
  14095. module.exports = {
  14096. createMasterPassword: createMasterPassword,
  14097. _getTemplate: _getTemplate,
  14098. _createHash: _createHash
  14099. };
  14100. function createMasterPassword(email, password) {
  14101. return new Promise(function (resolve, reject) {
  14102. var iterations = 8192;
  14103. var keylen = 32;
  14104. crypto.pbkdf2(password, email, iterations, keylen, 'sha256', function (error, key) {
  14105. if (error) {
  14106. reject('error in pbkdf2');
  14107. } else {
  14108. resolve(key.toString('hex'));
  14109. }
  14110. });
  14111. });
  14112. }
  14113. function _getTemplate() {
  14114. var passwordTypes = arguments.length <= 0 || arguments[0] === undefined ? ['strong'] : arguments[0];
  14115. var passwordTypesInfo = {
  14116. lowercase: { value: 'vc', order: 1 },
  14117. uppercase: { value: 'VC', order: 2 },
  14118. numbers: { value: 'n', order: 3 },
  14119. symbols: { value: 's', order: 4 },
  14120. strong: { value: 'Cvcvns', order: 5 }
  14121. };
  14122. return passwordTypes.map(function (passwordType) {
  14123. return passwordTypesInfo[passwordType];
  14124. }).sort(function (passwordType1, passwordType2) {
  14125. return passwordType1.order > passwordType2.order;
  14126. }).map(function (passwordType) {
  14127. return passwordType.value;
  14128. }).join('');
  14129. }
  14130. function _createHash(masterPassword, _ref) {
  14131. var site = _ref.site;
  14132. var _ref$password = _ref.password;
  14133. var password = _ref$password === undefined ? { length: 12, counter: 1 } : _ref$password;
  14134. var salt = site + password.counter.toString();
  14135. var hash = crypto.createHmac('sha256', masterPassword).update(salt).digest('hex');
  14136. return hash.substring(0, password.length);
  14137. }
  14138. },{"crypto":54}],97:[function(require,module,exports){
  14139. "use strict";
  14140. module.exports = {
  14141. _getCharType: _getCharType,
  14142. _getPasswordChar: _getPasswordChar,
  14143. _encode: _encode,
  14144. _string2charCodes: _string2charCodes
  14145. };
  14146. function _getCharType(template, index) {
  14147. return template[index % template.length];
  14148. }
  14149. function _getPasswordChar(charType, index) {
  14150. var passwordsChars = {
  14151. V: "AEIOUY",
  14152. C: "BCDFGHJKLMNPQRSTVWXZ",
  14153. v: "aeiouy",
  14154. c: "bcdfghjklmnpqrstvwxz",
  14155. A: "AEIOUYBCDFGHJKLMNPQRSTVWXZ",
  14156. a: "AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz",
  14157. n: "0123456789",
  14158. s: "@&%?,=[]_:-+*$#!'^~;()/.",
  14159. x: "AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!'^~;()/."
  14160. };
  14161. var passwordChar = passwordsChars[charType];
  14162. return passwordChar[index % passwordChar.length];
  14163. }
  14164. function _encode(hash, template) {
  14165. var password = '';
  14166. _string2charCodes(hash).map(function (charCode, index) {
  14167. var charType = _getCharType(template, index);
  14168. password += _getPasswordChar(charType, charCode);
  14169. });
  14170. return password;
  14171. }
  14172. function _string2charCodes(text) {
  14173. var charCodes = [];
  14174. for (var i = 0; i < text.length; i++) {
  14175. charCodes.push(text.charCodeAt(i));
  14176. }
  14177. return charCodes;
  14178. }
  14179. },{}],98:[function(require,module,exports){
  14180. var bn = require('bn.js');
  14181. var brorand = require('brorand');
  14182. function MillerRabin(rand) {
  14183. this.rand = rand || new brorand.Rand();
  14184. }
  14185. module.exports = MillerRabin;
  14186. MillerRabin.create = function create(rand) {
  14187. return new MillerRabin(rand);
  14188. };
  14189. MillerRabin.prototype._rand = function _rand(n) {
  14190. var len = n.bitLength();
  14191. var buf = this.rand.generate(Math.ceil(len / 8));
  14192. // Set low bits
  14193. buf[0] |= 3;
  14194. // Mask high bits
  14195. var mask = len & 0x7;
  14196. if (mask !== 0)
  14197. buf[buf.length - 1] >>= 7 - mask;
  14198. return new bn(buf);
  14199. }
  14200. MillerRabin.prototype.test = function test(n, k, cb) {
  14201. var len = n.bitLength();
  14202. var red = bn.mont(n);
  14203. var rone = new bn(1).toRed(red);
  14204. if (!k)
  14205. k = Math.max(1, (len / 48) | 0);
  14206. // Find d and s, (n - 1) = (2 ^ s) * d;
  14207. var n1 = n.subn(1);
  14208. var n2 = n1.subn(1);
  14209. for (var s = 0; !n1.testn(s); s++) {}
  14210. var d = n.shrn(s);
  14211. var rn1 = n1.toRed(red);
  14212. var prime = true;
  14213. for (; k > 0; k--) {
  14214. var a = this._rand(n2);
  14215. if (cb)
  14216. cb(a);
  14217. var x = a.toRed(red).redPow(d);
  14218. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
  14219. continue;
  14220. for (var i = 1; i < s; i++) {
  14221. x = x.redSqr();
  14222. if (x.cmp(rone) === 0)
  14223. return false;
  14224. if (x.cmp(rn1) === 0)
  14225. break;
  14226. }
  14227. if (i === s)
  14228. return false;
  14229. }
  14230. return prime;
  14231. };
  14232. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  14233. var len = n.bitLength();
  14234. var red = bn.mont(n);
  14235. var rone = new bn(1).toRed(red);
  14236. if (!k)
  14237. k = Math.max(1, (len / 48) | 0);
  14238. // Find d and s, (n - 1) = (2 ^ s) * d;
  14239. var n1 = n.subn(1);
  14240. var n2 = n1.subn(1);
  14241. for (var s = 0; !n1.testn(s); s++) {}
  14242. var d = n.shrn(s);
  14243. var rn1 = n1.toRed(red);
  14244. for (; k > 0; k--) {
  14245. var a = this._rand(n2);
  14246. var g = n.gcd(a);
  14247. if (g.cmpn(1) !== 0)
  14248. return g;
  14249. var x = a.toRed(red).redPow(d);
  14250. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
  14251. continue;
  14252. for (var i = 1; i < s; i++) {
  14253. x = x.redSqr();
  14254. if (x.cmp(rone) === 0)
  14255. return x.fromRed().subn(1).gcd(n);
  14256. if (x.cmp(rn1) === 0)
  14257. break;
  14258. }
  14259. if (i === s) {
  14260. x = x.redSqr();
  14261. return x.fromRed().subn(1).gcd(n);
  14262. }
  14263. }
  14264. return false;
  14265. };
  14266. },{"bn.js":18,"brorand":19}],99:[function(require,module,exports){
  14267. module.exports = assert;
  14268. function assert(val, msg) {
  14269. if (!val)
  14270. throw new Error(msg || 'Assertion failed');
  14271. }
  14272. assert.equal = function assertEqual(l, r, msg) {
  14273. if (l != r)
  14274. throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
  14275. };
  14276. },{}],100:[function(require,module,exports){
  14277. module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
  14278. "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
  14279. "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
  14280. "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
  14281. "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
  14282. "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
  14283. "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
  14284. "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
  14285. "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
  14286. "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
  14287. "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
  14288. "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
  14289. }
  14290. },{}],101:[function(require,module,exports){
  14291. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  14292. // Fedor, you are amazing.
  14293. var asn1 = require('asn1.js')
  14294. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  14295. this.seq().obj(
  14296. this.key('version').int(),
  14297. this.key('modulus').int(),
  14298. this.key('publicExponent').int(),
  14299. this.key('privateExponent').int(),
  14300. this.key('prime1').int(),
  14301. this.key('prime2').int(),
  14302. this.key('exponent1').int(),
  14303. this.key('exponent2').int(),
  14304. this.key('coefficient').int()
  14305. )
  14306. })
  14307. exports.RSAPrivateKey = RSAPrivateKey
  14308. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  14309. this.seq().obj(
  14310. this.key('modulus').int(),
  14311. this.key('publicExponent').int()
  14312. )
  14313. })
  14314. exports.RSAPublicKey = RSAPublicKey
  14315. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  14316. this.seq().obj(
  14317. this.key('algorithm').use(AlgorithmIdentifier),
  14318. this.key('subjectPublicKey').bitstr()
  14319. )
  14320. })
  14321. exports.PublicKey = PublicKey
  14322. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  14323. this.seq().obj(
  14324. this.key('algorithm').objid(),
  14325. this.key('none').null_().optional(),
  14326. this.key('curve').objid().optional(),
  14327. this.key('params').seq().obj(
  14328. this.key('p').int(),
  14329. this.key('q').int(),
  14330. this.key('g').int()
  14331. ).optional()
  14332. )
  14333. })
  14334. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  14335. this.seq().obj(
  14336. this.key('version').int(),
  14337. this.key('algorithm').use(AlgorithmIdentifier),
  14338. this.key('subjectPrivateKey').octstr()
  14339. )
  14340. })
  14341. exports.PrivateKey = PrivateKeyInfo
  14342. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  14343. this.seq().obj(
  14344. this.key('algorithm').seq().obj(
  14345. this.key('id').objid(),
  14346. this.key('decrypt').seq().obj(
  14347. this.key('kde').seq().obj(
  14348. this.key('id').objid(),
  14349. this.key('kdeparams').seq().obj(
  14350. this.key('salt').octstr(),
  14351. this.key('iters').int()
  14352. )
  14353. ),
  14354. this.key('cipher').seq().obj(
  14355. this.key('algo').objid(),
  14356. this.key('iv').octstr()
  14357. )
  14358. )
  14359. ),
  14360. this.key('subjectPrivateKey').octstr()
  14361. )
  14362. })
  14363. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
  14364. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  14365. this.seq().obj(
  14366. this.key('version').int(),
  14367. this.key('p').int(),
  14368. this.key('q').int(),
  14369. this.key('g').int(),
  14370. this.key('pub_key').int(),
  14371. this.key('priv_key').int()
  14372. )
  14373. })
  14374. exports.DSAPrivateKey = DSAPrivateKey
  14375. exports.DSAparam = asn1.define('DSAparam', function () {
  14376. this.int()
  14377. })
  14378. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  14379. this.seq().obj(
  14380. this.key('version').int(),
  14381. this.key('privateKey').octstr(),
  14382. this.key('parameters').optional().explicit(0).use(ECParameters),
  14383. this.key('publicKey').optional().explicit(1).bitstr()
  14384. )
  14385. })
  14386. exports.ECPrivateKey = ECPrivateKey
  14387. var ECParameters = asn1.define('ECParameters', function () {
  14388. this.choice({
  14389. namedCurve: this.objid()
  14390. })
  14391. })
  14392. exports.signature = asn1.define('signature', function () {
  14393. this.seq().obj(
  14394. this.key('r').int(),
  14395. this.key('s').int()
  14396. )
  14397. })
  14398. },{"asn1.js":3}],102:[function(require,module,exports){
  14399. (function (Buffer){
  14400. // adapted from https://github.com/apatil/pemstrip
  14401. 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
  14402. var startRegex = /^-----BEGIN (.*) KEY-----\r?\n/m
  14403. var fullRegex = /^-----BEGIN (.*) KEY-----\r?\n([0-9A-z\n\r\+\/\=]+)\r?\n-----END \1 KEY-----$/m
  14404. var evp = require('evp_bytestokey')
  14405. var ciphers = require('browserify-aes')
  14406. module.exports = function (okey, password) {
  14407. var key = okey.toString()
  14408. var match = key.match(findProc)
  14409. var decrypted
  14410. if (!match) {
  14411. var match2 = key.match(fullRegex)
  14412. decrypted = new Buffer(match2[2].replace(/\r?\n/g, ''), 'base64')
  14413. } else {
  14414. var suite = 'aes' + match[1]
  14415. var iv = new Buffer(match[2], 'hex')
  14416. var cipherText = new Buffer(match[3].replace(/\r?\n/g, ''), 'base64')
  14417. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key
  14418. var out = []
  14419. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv)
  14420. out.push(cipher.update(cipherText))
  14421. out.push(cipher.final())
  14422. decrypted = Buffer.concat(out)
  14423. }
  14424. var tag = key.match(startRegex)[1] + ' KEY'
  14425. return {
  14426. tag: tag,
  14427. data: decrypted
  14428. }
  14429. }
  14430. }).call(this,require("buffer").Buffer)
  14431. },{"browserify-aes":23,"buffer":46,"evp_bytestokey":83}],103:[function(require,module,exports){
  14432. (function (Buffer){
  14433. var asn1 = require('./asn1')
  14434. var aesid = require('./aesid.json')
  14435. var fixProc = require('./fixProc')
  14436. var ciphers = require('browserify-aes')
  14437. var compat = require('pbkdf2')
  14438. module.exports = parseKeys
  14439. function parseKeys (buffer) {
  14440. var password
  14441. if (typeof buffer === 'object' && !Buffer.isBuffer(buffer)) {
  14442. password = buffer.passphrase
  14443. buffer = buffer.key
  14444. }
  14445. if (typeof buffer === 'string') {
  14446. buffer = new Buffer(buffer)
  14447. }
  14448. var stripped = fixProc(buffer, password)
  14449. var type = stripped.tag
  14450. var data = stripped.data
  14451. var subtype, ndata
  14452. switch (type) {
  14453. case 'PUBLIC KEY':
  14454. ndata = asn1.PublicKey.decode(data, 'der')
  14455. subtype = ndata.algorithm.algorithm.join('.')
  14456. switch (subtype) {
  14457. case '1.2.840.113549.1.1.1':
  14458. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der')
  14459. case '1.2.840.10045.2.1':
  14460. ndata.subjectPrivateKey = ndata.subjectPublicKey
  14461. return {
  14462. type: 'ec',
  14463. data: ndata
  14464. }
  14465. case '1.2.840.10040.4.1':
  14466. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der')
  14467. return {
  14468. type: 'dsa',
  14469. data: ndata.algorithm.params
  14470. }
  14471. default: throw new Error('unknown key id ' + subtype)
  14472. }
  14473. throw new Error('unknown key type ' + type)
  14474. case 'ENCRYPTED PRIVATE KEY':
  14475. data = asn1.EncryptedPrivateKey.decode(data, 'der')
  14476. data = decrypt(data, password)
  14477. // falls through
  14478. case 'PRIVATE KEY':
  14479. ndata = asn1.PrivateKey.decode(data, 'der')
  14480. subtype = ndata.algorithm.algorithm.join('.')
  14481. switch (subtype) {
  14482. case '1.2.840.113549.1.1.1':
  14483. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der')
  14484. case '1.2.840.10045.2.1':
  14485. return {
  14486. curve: ndata.algorithm.curve,
  14487. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  14488. }
  14489. case '1.2.840.10040.4.1':
  14490. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der')
  14491. return {
  14492. type: 'dsa',
  14493. params: ndata.algorithm.params
  14494. }
  14495. default: throw new Error('unknown key id ' + subtype)
  14496. }
  14497. throw new Error('unknown key type ' + type)
  14498. case 'RSA PUBLIC KEY':
  14499. return asn1.RSAPublicKey.decode(data, 'der')
  14500. case 'RSA PRIVATE KEY':
  14501. return asn1.RSAPrivateKey.decode(data, 'der')
  14502. case 'DSA PRIVATE KEY':
  14503. return {
  14504. type: 'dsa',
  14505. params: asn1.DSAPrivateKey.decode(data, 'der')
  14506. }
  14507. case 'EC PRIVATE KEY':
  14508. data = asn1.ECPrivateKey.decode(data, 'der')
  14509. return {
  14510. curve: data.parameters.value,
  14511. privateKey: data.privateKey
  14512. }
  14513. default: throw new Error('unknown key type ' + type)
  14514. }
  14515. }
  14516. parseKeys.signature = asn1.signature
  14517. function decrypt (data, password) {
  14518. var salt = data.algorithm.decrypt.kde.kdeparams.salt
  14519. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10)
  14520. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')]
  14521. var iv = data.algorithm.decrypt.cipher.iv
  14522. var cipherText = data.subjectPrivateKey
  14523. var keylen = parseInt(algo.split('-')[1], 10) / 8
  14524. var key = compat.pbkdf2Sync(password, salt, iters, keylen)
  14525. var cipher = ciphers.createDecipheriv(algo, key, iv)
  14526. var out = []
  14527. out.push(cipher.update(cipherText))
  14528. out.push(cipher.final())
  14529. return Buffer.concat(out)
  14530. }
  14531. }).call(this,require("buffer").Buffer)
  14532. },{"./aesid.json":100,"./asn1":101,"./fixProc":102,"browserify-aes":23,"buffer":46,"pbkdf2":104}],104:[function(require,module,exports){
  14533. (function (Buffer){
  14534. var createHmac = require('create-hmac')
  14535. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  14536. exports.pbkdf2 = pbkdf2
  14537. function pbkdf2 (password, salt, iterations, keylen, digest, callback) {
  14538. if (typeof digest === 'function') {
  14539. callback = digest
  14540. digest = undefined
  14541. }
  14542. if (typeof callback !== 'function') {
  14543. throw new Error('No callback provided to pbkdf2')
  14544. }
  14545. var result = pbkdf2Sync(password, salt, iterations, keylen, digest)
  14546. setTimeout(function () {
  14547. callback(undefined, result)
  14548. })
  14549. }
  14550. exports.pbkdf2Sync = pbkdf2Sync
  14551. function pbkdf2Sync (password, salt, iterations, keylen, digest) {
  14552. if (typeof iterations !== 'number') {
  14553. throw new TypeError('Iterations not a number')
  14554. }
  14555. if (iterations < 0) {
  14556. throw new TypeError('Bad iterations')
  14557. }
  14558. if (typeof keylen !== 'number') {
  14559. throw new TypeError('Key length not a number')
  14560. }
  14561. if (keylen < 0 || keylen > MAX_ALLOC) {
  14562. throw new TypeError('Bad key length')
  14563. }
  14564. digest = digest || 'sha1'
  14565. if (!Buffer.isBuffer(password)) password = new Buffer(password, 'binary')
  14566. if (!Buffer.isBuffer(salt)) salt = new Buffer(salt, 'binary')
  14567. var hLen
  14568. var l = 1
  14569. var DK = new Buffer(keylen)
  14570. var block1 = new Buffer(salt.length + 4)
  14571. salt.copy(block1, 0, 0, salt.length)
  14572. var r
  14573. var T
  14574. for (var i = 1; i <= l; i++) {
  14575. block1.writeUInt32BE(i, salt.length)
  14576. var U = createHmac(digest, password).update(block1).digest()
  14577. if (!hLen) {
  14578. hLen = U.length
  14579. T = new Buffer(hLen)
  14580. l = Math.ceil(keylen / hLen)
  14581. r = keylen - (l - 1) * hLen
  14582. }
  14583. U.copy(T, 0, 0, hLen)
  14584. for (var j = 1; j < iterations; j++) {
  14585. U = createHmac(digest, password).update(U).digest()
  14586. for (var k = 0; k < hLen; k++) {
  14587. T[k] ^= U[k]
  14588. }
  14589. }
  14590. var destPos = (i - 1) * hLen
  14591. var len = (i === l ? r : hLen)
  14592. T.copy(DK, destPos, 0, len)
  14593. }
  14594. return DK
  14595. }
  14596. }).call(this,require("buffer").Buffer)
  14597. },{"buffer":46,"create-hmac":53}],105:[function(require,module,exports){
  14598. (function (process){
  14599. 'use strict';
  14600. if (!process.version ||
  14601. process.version.indexOf('v0.') === 0 ||
  14602. process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  14603. module.exports = nextTick;
  14604. } else {
  14605. module.exports = process.nextTick;
  14606. }
  14607. function nextTick(fn, arg1, arg2, arg3) {
  14608. if (typeof fn !== 'function') {
  14609. throw new TypeError('"callback" argument must be a function');
  14610. }
  14611. var len = arguments.length;
  14612. var args, i;
  14613. switch (len) {
  14614. case 0:
  14615. case 1:
  14616. return process.nextTick(fn);
  14617. case 2:
  14618. return process.nextTick(function afterTickOne() {
  14619. fn.call(null, arg1);
  14620. });
  14621. case 3:
  14622. return process.nextTick(function afterTickTwo() {
  14623. fn.call(null, arg1, arg2);
  14624. });
  14625. case 4:
  14626. return process.nextTick(function afterTickThree() {
  14627. fn.call(null, arg1, arg2, arg3);
  14628. });
  14629. default:
  14630. args = new Array(len - 1);
  14631. i = 0;
  14632. while (i < args.length) {
  14633. args[i++] = arguments[i];
  14634. }
  14635. return process.nextTick(function afterTick() {
  14636. fn.apply(null, args);
  14637. });
  14638. }
  14639. }
  14640. }).call(this,require('_process'))
  14641. },{"_process":106}],106:[function(require,module,exports){
  14642. // shim for using process in browser
  14643. var process = module.exports = {};
  14644. var queue = [];
  14645. var draining = false;
  14646. var currentQueue;
  14647. var queueIndex = -1;
  14648. function cleanUpNextTick() {
  14649. if (!draining || !currentQueue) {
  14650. return;
  14651. }
  14652. draining = false;
  14653. if (currentQueue.length) {
  14654. queue = currentQueue.concat(queue);
  14655. } else {
  14656. queueIndex = -1;
  14657. }
  14658. if (queue.length) {
  14659. drainQueue();
  14660. }
  14661. }
  14662. function drainQueue() {
  14663. if (draining) {
  14664. return;
  14665. }
  14666. var timeout = setTimeout(cleanUpNextTick);
  14667. draining = true;
  14668. var len = queue.length;
  14669. while(len) {
  14670. currentQueue = queue;
  14671. queue = [];
  14672. while (++queueIndex < len) {
  14673. if (currentQueue) {
  14674. currentQueue[queueIndex].run();
  14675. }
  14676. }
  14677. queueIndex = -1;
  14678. len = queue.length;
  14679. }
  14680. currentQueue = null;
  14681. draining = false;
  14682. clearTimeout(timeout);
  14683. }
  14684. process.nextTick = function (fun) {
  14685. var args = new Array(arguments.length - 1);
  14686. if (arguments.length > 1) {
  14687. for (var i = 1; i < arguments.length; i++) {
  14688. args[i - 1] = arguments[i];
  14689. }
  14690. }
  14691. queue.push(new Item(fun, args));
  14692. if (queue.length === 1 && !draining) {
  14693. setTimeout(drainQueue, 0);
  14694. }
  14695. };
  14696. // v8 likes predictible objects
  14697. function Item(fun, array) {
  14698. this.fun = fun;
  14699. this.array = array;
  14700. }
  14701. Item.prototype.run = function () {
  14702. this.fun.apply(null, this.array);
  14703. };
  14704. process.title = 'browser';
  14705. process.browser = true;
  14706. process.env = {};
  14707. process.argv = [];
  14708. process.version = ''; // empty string to avoid regexp issues
  14709. process.versions = {};
  14710. function noop() {}
  14711. process.on = noop;
  14712. process.addListener = noop;
  14713. process.once = noop;
  14714. process.off = noop;
  14715. process.removeListener = noop;
  14716. process.removeAllListeners = noop;
  14717. process.emit = noop;
  14718. process.binding = function (name) {
  14719. throw new Error('process.binding is not supported');
  14720. };
  14721. process.cwd = function () { return '/' };
  14722. process.chdir = function (dir) {
  14723. throw new Error('process.chdir is not supported');
  14724. };
  14725. process.umask = function() { return 0; };
  14726. },{}],107:[function(require,module,exports){
  14727. exports.publicEncrypt = require('./publicEncrypt');
  14728. exports.privateDecrypt = require('./privateDecrypt');
  14729. exports.privateEncrypt = function privateEncrypt(key, buf) {
  14730. return exports.publicEncrypt(key, buf, true);
  14731. };
  14732. exports.publicDecrypt = function publicDecrypt(key, buf) {
  14733. return exports.privateDecrypt(key, buf, true);
  14734. };
  14735. },{"./privateDecrypt":109,"./publicEncrypt":110}],108:[function(require,module,exports){
  14736. (function (Buffer){
  14737. var createHash = require('create-hash');
  14738. module.exports = function (seed, len) {
  14739. var t = new Buffer('');
  14740. var i = 0, c;
  14741. while (t.length < len) {
  14742. c = i2ops(i++);
  14743. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  14744. }
  14745. return t.slice(0, len);
  14746. };
  14747. function i2ops(c) {
  14748. var out = new Buffer(4);
  14749. out.writeUInt32BE(c,0);
  14750. return out;
  14751. }
  14752. }).call(this,require("buffer").Buffer)
  14753. },{"buffer":46,"create-hash":50}],109:[function(require,module,exports){
  14754. (function (Buffer){
  14755. var parseKeys = require('parse-asn1');
  14756. var mgf = require('./mgf');
  14757. var xor = require('./xor');
  14758. var bn = require('bn.js');
  14759. var crt = require('browserify-rsa');
  14760. var createHash = require('create-hash');
  14761. var withPublic = require('./withPublic');
  14762. module.exports = function privateDecrypt(private_key, enc, reverse) {
  14763. var padding;
  14764. if (private_key.padding) {
  14765. padding = private_key.padding;
  14766. } else if (reverse) {
  14767. padding = 1;
  14768. } else {
  14769. padding = 4;
  14770. }
  14771. var key = parseKeys(private_key);
  14772. var k = key.modulus.byteLength();
  14773. if (enc.length > k || new bn(enc).cmp(key.modulus) >= 0) {
  14774. throw new Error('decryption error');
  14775. }
  14776. var msg;
  14777. if (reverse) {
  14778. msg = withPublic(new bn(enc), key);
  14779. } else {
  14780. msg = crt(enc, key);
  14781. }
  14782. var zBuffer = new Buffer(k - msg.length);
  14783. zBuffer.fill(0);
  14784. msg = Buffer.concat([zBuffer, msg], k);
  14785. if (padding === 4) {
  14786. return oaep(key, msg);
  14787. } else if (padding === 1) {
  14788. return pkcs1(key, msg, reverse);
  14789. } else if (padding === 3) {
  14790. return msg;
  14791. } else {
  14792. throw new Error('unknown padding');
  14793. }
  14794. };
  14795. function oaep(key, msg){
  14796. var n = key.modulus;
  14797. var k = key.modulus.byteLength();
  14798. var mLen = msg.length;
  14799. var iHash = createHash('sha1').update(new Buffer('')).digest();
  14800. var hLen = iHash.length;
  14801. var hLen2 = 2 * hLen;
  14802. if (msg[0] !== 0) {
  14803. throw new Error('decryption error');
  14804. }
  14805. var maskedSeed = msg.slice(1, hLen + 1);
  14806. var maskedDb = msg.slice(hLen + 1);
  14807. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  14808. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  14809. if (compare(iHash, db.slice(0, hLen))) {
  14810. throw new Error('decryption error');
  14811. }
  14812. var i = hLen;
  14813. while (db[i] === 0) {
  14814. i++;
  14815. }
  14816. if (db[i++] !== 1) {
  14817. throw new Error('decryption error');
  14818. }
  14819. return db.slice(i);
  14820. }
  14821. function pkcs1(key, msg, reverse){
  14822. var p1 = msg.slice(0, 2);
  14823. var i = 2;
  14824. var status = 0;
  14825. while (msg[i++] !== 0) {
  14826. if (i >= msg.length) {
  14827. status++;
  14828. break;
  14829. }
  14830. }
  14831. var ps = msg.slice(2, i - 1);
  14832. var p2 = msg.slice(i - 1, i);
  14833. if ((p1.toString('hex') !== '0002' && !reverse) || (p1.toString('hex') !== '0001' && reverse)){
  14834. status++;
  14835. }
  14836. if (ps.length < 8) {
  14837. status++;
  14838. }
  14839. if (status) {
  14840. throw new Error('decryption error');
  14841. }
  14842. return msg.slice(i);
  14843. }
  14844. function compare(a, b){
  14845. a = new Buffer(a);
  14846. b = new Buffer(b);
  14847. var dif = 0;
  14848. var len = a.length;
  14849. if (a.length !== b.length) {
  14850. dif++;
  14851. len = Math.min(a.length, b.length);
  14852. }
  14853. var i = -1;
  14854. while (++i < len) {
  14855. dif += (a[i] ^ b[i]);
  14856. }
  14857. return dif;
  14858. }
  14859. }).call(this,require("buffer").Buffer)
  14860. },{"./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){
  14861. (function (Buffer){
  14862. var parseKeys = require('parse-asn1');
  14863. var randomBytes = require('randombytes');
  14864. var createHash = require('create-hash');
  14865. var mgf = require('./mgf');
  14866. var xor = require('./xor');
  14867. var bn = require('bn.js');
  14868. var withPublic = require('./withPublic');
  14869. var crt = require('browserify-rsa');
  14870. var constants = {
  14871. RSA_PKCS1_OAEP_PADDING: 4,
  14872. RSA_PKCS1_PADDIN: 1,
  14873. RSA_NO_PADDING: 3
  14874. };
  14875. module.exports = function publicEncrypt(public_key, msg, reverse) {
  14876. var padding;
  14877. if (public_key.padding) {
  14878. padding = public_key.padding;
  14879. } else if (reverse) {
  14880. padding = 1;
  14881. } else {
  14882. padding = 4;
  14883. }
  14884. var key = parseKeys(public_key);
  14885. var paddedMsg;
  14886. if (padding === 4) {
  14887. paddedMsg = oaep(key, msg);
  14888. } else if (padding === 1) {
  14889. paddedMsg = pkcs1(key, msg, reverse);
  14890. } else if (padding === 3) {
  14891. paddedMsg = new bn(msg);
  14892. if (paddedMsg.cmp(key.modulus) >= 0) {
  14893. throw new Error('data too long for modulus');
  14894. }
  14895. } else {
  14896. throw new Error('unknown padding');
  14897. }
  14898. if (reverse) {
  14899. return crt(paddedMsg, key);
  14900. } else {
  14901. return withPublic(paddedMsg, key);
  14902. }
  14903. };
  14904. function oaep(key, msg){
  14905. var k = key.modulus.byteLength();
  14906. var mLen = msg.length;
  14907. var iHash = createHash('sha1').update(new Buffer('')).digest();
  14908. var hLen = iHash.length;
  14909. var hLen2 = 2 * hLen;
  14910. if (mLen > k - hLen2 - 2) {
  14911. throw new Error('message too long');
  14912. }
  14913. var ps = new Buffer(k - mLen - hLen2 - 2);
  14914. ps.fill(0);
  14915. var dblen = k - hLen - 1;
  14916. var seed = randomBytes(hLen);
  14917. var maskedDb = xor(Buffer.concat([iHash, ps, new Buffer([1]), msg], dblen), mgf(seed, dblen));
  14918. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  14919. return new bn(Buffer.concat([new Buffer([0]), maskedSeed, maskedDb], k));
  14920. }
  14921. function pkcs1(key, msg, reverse){
  14922. var mLen = msg.length;
  14923. var k = key.modulus.byteLength();
  14924. if (mLen > k - 11) {
  14925. throw new Error('message too long');
  14926. }
  14927. var ps;
  14928. if (reverse) {
  14929. ps = new Buffer(k - mLen - 3);
  14930. ps.fill(0xff);
  14931. } else {
  14932. ps = nonZero(k - mLen - 3);
  14933. }
  14934. return new bn(Buffer.concat([new Buffer([0, reverse?1:2]), ps, new Buffer([0]), msg], k));
  14935. }
  14936. function nonZero(len, crypto) {
  14937. var out = new Buffer(len);
  14938. var i = 0;
  14939. var cache = randomBytes(len*2);
  14940. var cur = 0;
  14941. var num;
  14942. while (i < len) {
  14943. if (cur === cache.length) {
  14944. cache = randomBytes(len*2);
  14945. cur = 0;
  14946. }
  14947. num = cache[cur++];
  14948. if (num) {
  14949. out[i++] = num;
  14950. }
  14951. }
  14952. return out;
  14953. }
  14954. }).call(this,require("buffer").Buffer)
  14955. },{"./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){
  14956. (function (Buffer){
  14957. var bn = require('bn.js');
  14958. function withPublic(paddedMsg, key) {
  14959. return new Buffer(paddedMsg
  14960. .toRed(bn.mont(key.modulus))
  14961. .redPow(new bn(key.publicExponent))
  14962. .fromRed()
  14963. .toArray());
  14964. }
  14965. module.exports = withPublic;
  14966. }).call(this,require("buffer").Buffer)
  14967. },{"bn.js":18,"buffer":46}],112:[function(require,module,exports){
  14968. module.exports = function xor(a, b) {
  14969. var len = a.length;
  14970. var i = -1;
  14971. while (++i < len) {
  14972. a[i] ^= b[i];
  14973. }
  14974. return a
  14975. };
  14976. },{}],113:[function(require,module,exports){
  14977. (function (global){
  14978. /*! https://mths.be/punycode v1.4.1 by @mathias */
  14979. ;(function(root) {
  14980. /** Detect free variables */
  14981. var freeExports = typeof exports == 'object' && exports &&
  14982. !exports.nodeType && exports;
  14983. var freeModule = typeof module == 'object' && module &&
  14984. !module.nodeType && module;
  14985. var freeGlobal = typeof global == 'object' && global;
  14986. if (
  14987. freeGlobal.global === freeGlobal ||
  14988. freeGlobal.window === freeGlobal ||
  14989. freeGlobal.self === freeGlobal
  14990. ) {
  14991. root = freeGlobal;
  14992. }
  14993. /**
  14994. * The `punycode` object.
  14995. * @name punycode
  14996. * @type Object
  14997. */
  14998. var punycode,
  14999. /** Highest positive signed 32-bit float value */
  15000. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  15001. /** Bootstring parameters */
  15002. base = 36,
  15003. tMin = 1,
  15004. tMax = 26,
  15005. skew = 38,
  15006. damp = 700,
  15007. initialBias = 72,
  15008. initialN = 128, // 0x80
  15009. delimiter = '-', // '\x2D'
  15010. /** Regular expressions */
  15011. regexPunycode = /^xn--/,
  15012. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  15013. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  15014. /** Error messages */
  15015. errors = {
  15016. 'overflow': 'Overflow: input needs wider integers to process',
  15017. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  15018. 'invalid-input': 'Invalid input'
  15019. },
  15020. /** Convenience shortcuts */
  15021. baseMinusTMin = base - tMin,
  15022. floor = Math.floor,
  15023. stringFromCharCode = String.fromCharCode,
  15024. /** Temporary variable */
  15025. key;
  15026. /*--------------------------------------------------------------------------*/
  15027. /**
  15028. * A generic error utility function.
  15029. * @private
  15030. * @param {String} type The error type.
  15031. * @returns {Error} Throws a `RangeError` with the applicable error message.
  15032. */
  15033. function error(type) {
  15034. throw new RangeError(errors[type]);
  15035. }
  15036. /**
  15037. * A generic `Array#map` utility function.
  15038. * @private
  15039. * @param {Array} array The array to iterate over.
  15040. * @param {Function} callback The function that gets called for every array
  15041. * item.
  15042. * @returns {Array} A new array of values returned by the callback function.
  15043. */
  15044. function map(array, fn) {
  15045. var length = array.length;
  15046. var result = [];
  15047. while (length--) {
  15048. result[length] = fn(array[length]);
  15049. }
  15050. return result;
  15051. }
  15052. /**
  15053. * A simple `Array#map`-like wrapper to work with domain name strings or email
  15054. * addresses.
  15055. * @private
  15056. * @param {String} domain The domain name or email address.
  15057. * @param {Function} callback The function that gets called for every
  15058. * character.
  15059. * @returns {Array} A new string of characters returned by the callback
  15060. * function.
  15061. */
  15062. function mapDomain(string, fn) {
  15063. var parts = string.split('@');
  15064. var result = '';
  15065. if (parts.length > 1) {
  15066. // In email addresses, only the domain name should be punycoded. Leave
  15067. // the local part (i.e. everything up to `@`) intact.
  15068. result = parts[0] + '@';
  15069. string = parts[1];
  15070. }
  15071. // Avoid `split(regex)` for IE8 compatibility. See #17.
  15072. string = string.replace(regexSeparators, '\x2E');
  15073. var labels = string.split('.');
  15074. var encoded = map(labels, fn).join('.');
  15075. return result + encoded;
  15076. }
  15077. /**
  15078. * Creates an array containing the numeric code points of each Unicode
  15079. * character in the string. While JavaScript uses UCS-2 internally,
  15080. * this function will convert a pair of surrogate halves (each of which
  15081. * UCS-2 exposes as separate characters) into a single code point,
  15082. * matching UTF-16.
  15083. * @see `punycode.ucs2.encode`
  15084. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  15085. * @memberOf punycode.ucs2
  15086. * @name decode
  15087. * @param {String} string The Unicode input string (UCS-2).
  15088. * @returns {Array} The new array of code points.
  15089. */
  15090. function ucs2decode(string) {
  15091. var output = [],
  15092. counter = 0,
  15093. length = string.length,
  15094. value,
  15095. extra;
  15096. while (counter < length) {
  15097. value = string.charCodeAt(counter++);
  15098. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  15099. // high surrogate, and there is a next character
  15100. extra = string.charCodeAt(counter++);
  15101. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  15102. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  15103. } else {
  15104. // unmatched surrogate; only append this code unit, in case the next
  15105. // code unit is the high surrogate of a surrogate pair
  15106. output.push(value);
  15107. counter--;
  15108. }
  15109. } else {
  15110. output.push(value);
  15111. }
  15112. }
  15113. return output;
  15114. }
  15115. /**
  15116. * Creates a string based on an array of numeric code points.
  15117. * @see `punycode.ucs2.decode`
  15118. * @memberOf punycode.ucs2
  15119. * @name encode
  15120. * @param {Array} codePoints The array of numeric code points.
  15121. * @returns {String} The new Unicode string (UCS-2).
  15122. */
  15123. function ucs2encode(array) {
  15124. return map(array, function(value) {
  15125. var output = '';
  15126. if (value > 0xFFFF) {
  15127. value -= 0x10000;
  15128. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  15129. value = 0xDC00 | value & 0x3FF;
  15130. }
  15131. output += stringFromCharCode(value);
  15132. return output;
  15133. }).join('');
  15134. }
  15135. /**
  15136. * Converts a basic code point into a digit/integer.
  15137. * @see `digitToBasic()`
  15138. * @private
  15139. * @param {Number} codePoint The basic numeric code point value.
  15140. * @returns {Number} The numeric value of a basic code point (for use in
  15141. * representing integers) in the range `0` to `base - 1`, or `base` if
  15142. * the code point does not represent a value.
  15143. */
  15144. function basicToDigit(codePoint) {
  15145. if (codePoint - 48 < 10) {
  15146. return codePoint - 22;
  15147. }
  15148. if (codePoint - 65 < 26) {
  15149. return codePoint - 65;
  15150. }
  15151. if (codePoint - 97 < 26) {
  15152. return codePoint - 97;
  15153. }
  15154. return base;
  15155. }
  15156. /**
  15157. * Converts a digit/integer into a basic code point.
  15158. * @see `basicToDigit()`
  15159. * @private
  15160. * @param {Number} digit The numeric value of a basic code point.
  15161. * @returns {Number} The basic code point whose value (when used for
  15162. * representing integers) is `digit`, which needs to be in the range
  15163. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  15164. * used; else, the lowercase form is used. The behavior is undefined
  15165. * if `flag` is non-zero and `digit` has no uppercase form.
  15166. */
  15167. function digitToBasic(digit, flag) {
  15168. // 0..25 map to ASCII a..z or A..Z
  15169. // 26..35 map to ASCII 0..9
  15170. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  15171. }
  15172. /**
  15173. * Bias adaptation function as per section 3.4 of RFC 3492.
  15174. * https://tools.ietf.org/html/rfc3492#section-3.4
  15175. * @private
  15176. */
  15177. function adapt(delta, numPoints, firstTime) {
  15178. var k = 0;
  15179. delta = firstTime ? floor(delta / damp) : delta >> 1;
  15180. delta += floor(delta / numPoints);
  15181. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  15182. delta = floor(delta / baseMinusTMin);
  15183. }
  15184. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  15185. }
  15186. /**
  15187. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  15188. * symbols.
  15189. * @memberOf punycode
  15190. * @param {String} input The Punycode string of ASCII-only symbols.
  15191. * @returns {String} The resulting string of Unicode symbols.
  15192. */
  15193. function decode(input) {
  15194. // Don't use UCS-2
  15195. var output = [],
  15196. inputLength = input.length,
  15197. out,
  15198. i = 0,
  15199. n = initialN,
  15200. bias = initialBias,
  15201. basic,
  15202. j,
  15203. index,
  15204. oldi,
  15205. w,
  15206. k,
  15207. digit,
  15208. t,
  15209. /** Cached calculation results */
  15210. baseMinusT;
  15211. // Handle the basic code points: let `basic` be the number of input code
  15212. // points before the last delimiter, or `0` if there is none, then copy
  15213. // the first basic code points to the output.
  15214. basic = input.lastIndexOf(delimiter);
  15215. if (basic < 0) {
  15216. basic = 0;
  15217. }
  15218. for (j = 0; j < basic; ++j) {
  15219. // if it's not a basic code point
  15220. if (input.charCodeAt(j) >= 0x80) {
  15221. error('not-basic');
  15222. }
  15223. output.push(input.charCodeAt(j));
  15224. }
  15225. // Main decoding loop: start just after the last delimiter if any basic code
  15226. // points were copied; start at the beginning otherwise.
  15227. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  15228. // `index` is the index of the next character to be consumed.
  15229. // Decode a generalized variable-length integer into `delta`,
  15230. // which gets added to `i`. The overflow checking is easier
  15231. // if we increase `i` as we go, then subtract off its starting
  15232. // value at the end to obtain `delta`.
  15233. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  15234. if (index >= inputLength) {
  15235. error('invalid-input');
  15236. }
  15237. digit = basicToDigit(input.charCodeAt(index++));
  15238. if (digit >= base || digit > floor((maxInt - i) / w)) {
  15239. error('overflow');
  15240. }
  15241. i += digit * w;
  15242. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  15243. if (digit < t) {
  15244. break;
  15245. }
  15246. baseMinusT = base - t;
  15247. if (w > floor(maxInt / baseMinusT)) {
  15248. error('overflow');
  15249. }
  15250. w *= baseMinusT;
  15251. }
  15252. out = output.length + 1;
  15253. bias = adapt(i - oldi, out, oldi == 0);
  15254. // `i` was supposed to wrap around from `out` to `0`,
  15255. // incrementing `n` each time, so we'll fix that now:
  15256. if (floor(i / out) > maxInt - n) {
  15257. error('overflow');
  15258. }
  15259. n += floor(i / out);
  15260. i %= out;
  15261. // Insert `n` at position `i` of the output
  15262. output.splice(i++, 0, n);
  15263. }
  15264. return ucs2encode(output);
  15265. }
  15266. /**
  15267. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  15268. * Punycode string of ASCII-only symbols.
  15269. * @memberOf punycode
  15270. * @param {String} input The string of Unicode symbols.
  15271. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  15272. */
  15273. function encode(input) {
  15274. var n,
  15275. delta,
  15276. handledCPCount,
  15277. basicLength,
  15278. bias,
  15279. j,
  15280. m,
  15281. q,
  15282. k,
  15283. t,
  15284. currentValue,
  15285. output = [],
  15286. /** `inputLength` will hold the number of code points in `input`. */
  15287. inputLength,
  15288. /** Cached calculation results */
  15289. handledCPCountPlusOne,
  15290. baseMinusT,
  15291. qMinusT;
  15292. // Convert the input in UCS-2 to Unicode
  15293. input = ucs2decode(input);
  15294. // Cache the length
  15295. inputLength = input.length;
  15296. // Initialize the state
  15297. n = initialN;
  15298. delta = 0;
  15299. bias = initialBias;
  15300. // Handle the basic code points
  15301. for (j = 0; j < inputLength; ++j) {
  15302. currentValue = input[j];
  15303. if (currentValue < 0x80) {
  15304. output.push(stringFromCharCode(currentValue));
  15305. }
  15306. }
  15307. handledCPCount = basicLength = output.length;
  15308. // `handledCPCount` is the number of code points that have been handled;
  15309. // `basicLength` is the number of basic code points.
  15310. // Finish the basic string - if it is not empty - with a delimiter
  15311. if (basicLength) {
  15312. output.push(delimiter);
  15313. }
  15314. // Main encoding loop:
  15315. while (handledCPCount < inputLength) {
  15316. // All non-basic code points < n have been handled already. Find the next
  15317. // larger one:
  15318. for (m = maxInt, j = 0; j < inputLength; ++j) {
  15319. currentValue = input[j];
  15320. if (currentValue >= n && currentValue < m) {
  15321. m = currentValue;
  15322. }
  15323. }
  15324. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  15325. // but guard against overflow
  15326. handledCPCountPlusOne = handledCPCount + 1;
  15327. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  15328. error('overflow');
  15329. }
  15330. delta += (m - n) * handledCPCountPlusOne;
  15331. n = m;
  15332. for (j = 0; j < inputLength; ++j) {
  15333. currentValue = input[j];
  15334. if (currentValue < n && ++delta > maxInt) {
  15335. error('overflow');
  15336. }
  15337. if (currentValue == n) {
  15338. // Represent delta as a generalized variable-length integer
  15339. for (q = delta, k = base; /* no condition */; k += base) {
  15340. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  15341. if (q < t) {
  15342. break;
  15343. }
  15344. qMinusT = q - t;
  15345. baseMinusT = base - t;
  15346. output.push(
  15347. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  15348. );
  15349. q = floor(qMinusT / baseMinusT);
  15350. }
  15351. output.push(stringFromCharCode(digitToBasic(q, 0)));
  15352. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  15353. delta = 0;
  15354. ++handledCPCount;
  15355. }
  15356. }
  15357. ++delta;
  15358. ++n;
  15359. }
  15360. return output.join('');
  15361. }
  15362. /**
  15363. * Converts a Punycode string representing a domain name or an email address
  15364. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  15365. * it doesn't matter if you call it on a string that has already been
  15366. * converted to Unicode.
  15367. * @memberOf punycode
  15368. * @param {String} input The Punycoded domain name or email address to
  15369. * convert to Unicode.
  15370. * @returns {String} The Unicode representation of the given Punycode
  15371. * string.
  15372. */
  15373. function toUnicode(input) {
  15374. return mapDomain(input, function(string) {
  15375. return regexPunycode.test(string)
  15376. ? decode(string.slice(4).toLowerCase())
  15377. : string;
  15378. });
  15379. }
  15380. /**
  15381. * Converts a Unicode string representing a domain name or an email address to
  15382. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  15383. * i.e. it doesn't matter if you call it with a domain that's already in
  15384. * ASCII.
  15385. * @memberOf punycode
  15386. * @param {String} input The domain name or email address to convert, as a
  15387. * Unicode string.
  15388. * @returns {String} The Punycode representation of the given domain name or
  15389. * email address.
  15390. */
  15391. function toASCII(input) {
  15392. return mapDomain(input, function(string) {
  15393. return regexNonASCII.test(string)
  15394. ? 'xn--' + encode(string)
  15395. : string;
  15396. });
  15397. }
  15398. /*--------------------------------------------------------------------------*/
  15399. /** Define the public API */
  15400. punycode = {
  15401. /**
  15402. * A string representing the current Punycode.js version number.
  15403. * @memberOf punycode
  15404. * @type String
  15405. */
  15406. 'version': '1.4.1',
  15407. /**
  15408. * An object of methods to convert from JavaScript's internal character
  15409. * representation (UCS-2) to Unicode code points, and back.
  15410. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  15411. * @memberOf punycode
  15412. * @type Object
  15413. */
  15414. 'ucs2': {
  15415. 'decode': ucs2decode,
  15416. 'encode': ucs2encode
  15417. },
  15418. 'decode': decode,
  15419. 'encode': encode,
  15420. 'toASCII': toASCII,
  15421. 'toUnicode': toUnicode
  15422. };
  15423. /** Expose `punycode` */
  15424. // Some AMD build optimizers, like r.js, check for specific condition patterns
  15425. // like the following:
  15426. if (
  15427. typeof define == 'function' &&
  15428. typeof define.amd == 'object' &&
  15429. define.amd
  15430. ) {
  15431. define('punycode', function() {
  15432. return punycode;
  15433. });
  15434. } else if (freeExports && freeModule) {
  15435. if (module.exports == freeExports) {
  15436. // in Node.js, io.js, or RingoJS v0.8.0+
  15437. freeModule.exports = punycode;
  15438. } else {
  15439. // in Narwhal or RingoJS v0.7.0-
  15440. for (key in punycode) {
  15441. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  15442. }
  15443. }
  15444. } else {
  15445. // in Rhino or a web browser
  15446. root.punycode = punycode;
  15447. }
  15448. }(this));
  15449. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  15450. },{}],114:[function(require,module,exports){
  15451. // Copyright Joyent, Inc. and other Node contributors.
  15452. //
  15453. // Permission is hereby granted, free of charge, to any person obtaining a
  15454. // copy of this software and associated documentation files (the
  15455. // "Software"), to deal in the Software without restriction, including
  15456. // without limitation the rights to use, copy, modify, merge, publish,
  15457. // distribute, sublicense, and/or sell copies of the Software, and to permit
  15458. // persons to whom the Software is furnished to do so, subject to the
  15459. // following conditions:
  15460. //
  15461. // The above copyright notice and this permission notice shall be included
  15462. // in all copies or substantial portions of the Software.
  15463. //
  15464. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15465. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15466. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  15467. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15468. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15469. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  15470. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  15471. 'use strict';
  15472. // If obj.hasOwnProperty has been overridden, then calling
  15473. // obj.hasOwnProperty(prop) will break.
  15474. // See: https://github.com/joyent/node/issues/1707
  15475. function hasOwnProperty(obj, prop) {
  15476. return Object.prototype.hasOwnProperty.call(obj, prop);
  15477. }
  15478. module.exports = function(qs, sep, eq, options) {
  15479. sep = sep || '&';
  15480. eq = eq || '=';
  15481. var obj = {};
  15482. if (typeof qs !== 'string' || qs.length === 0) {
  15483. return obj;
  15484. }
  15485. var regexp = /\+/g;
  15486. qs = qs.split(sep);
  15487. var maxKeys = 1000;
  15488. if (options && typeof options.maxKeys === 'number') {
  15489. maxKeys = options.maxKeys;
  15490. }
  15491. var len = qs.length;
  15492. // maxKeys <= 0 means that we should not limit keys count
  15493. if (maxKeys > 0 && len > maxKeys) {
  15494. len = maxKeys;
  15495. }
  15496. for (var i = 0; i < len; ++i) {
  15497. var x = qs[i].replace(regexp, '%20'),
  15498. idx = x.indexOf(eq),
  15499. kstr, vstr, k, v;
  15500. if (idx >= 0) {
  15501. kstr = x.substr(0, idx);
  15502. vstr = x.substr(idx + 1);
  15503. } else {
  15504. kstr = x;
  15505. vstr = '';
  15506. }
  15507. k = decodeURIComponent(kstr);
  15508. v = decodeURIComponent(vstr);
  15509. if (!hasOwnProperty(obj, k)) {
  15510. obj[k] = v;
  15511. } else if (isArray(obj[k])) {
  15512. obj[k].push(v);
  15513. } else {
  15514. obj[k] = [obj[k], v];
  15515. }
  15516. }
  15517. return obj;
  15518. };
  15519. var isArray = Array.isArray || function (xs) {
  15520. return Object.prototype.toString.call(xs) === '[object Array]';
  15521. };
  15522. },{}],115:[function(require,module,exports){
  15523. // Copyright Joyent, Inc. and other Node contributors.
  15524. //
  15525. // Permission is hereby granted, free of charge, to any person obtaining a
  15526. // copy of this software and associated documentation files (the
  15527. // "Software"), to deal in the Software without restriction, including
  15528. // without limitation the rights to use, copy, modify, merge, publish,
  15529. // distribute, sublicense, and/or sell copies of the Software, and to permit
  15530. // persons to whom the Software is furnished to do so, subject to the
  15531. // following conditions:
  15532. //
  15533. // The above copyright notice and this permission notice shall be included
  15534. // in all copies or substantial portions of the Software.
  15535. //
  15536. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15537. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15538. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  15539. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15540. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15541. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  15542. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  15543. 'use strict';
  15544. var stringifyPrimitive = function(v) {
  15545. switch (typeof v) {
  15546. case 'string':
  15547. return v;
  15548. case 'boolean':
  15549. return v ? 'true' : 'false';
  15550. case 'number':
  15551. return isFinite(v) ? v : '';
  15552. default:
  15553. return '';
  15554. }
  15555. };
  15556. module.exports = function(obj, sep, eq, name) {
  15557. sep = sep || '&';
  15558. eq = eq || '=';
  15559. if (obj === null) {
  15560. obj = undefined;
  15561. }
  15562. if (typeof obj === 'object') {
  15563. return map(objectKeys(obj), function(k) {
  15564. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  15565. if (isArray(obj[k])) {
  15566. return map(obj[k], function(v) {
  15567. return ks + encodeURIComponent(stringifyPrimitive(v));
  15568. }).join(sep);
  15569. } else {
  15570. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  15571. }
  15572. }).join(sep);
  15573. }
  15574. if (!name) return '';
  15575. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  15576. encodeURIComponent(stringifyPrimitive(obj));
  15577. };
  15578. var isArray = Array.isArray || function (xs) {
  15579. return Object.prototype.toString.call(xs) === '[object Array]';
  15580. };
  15581. function map (xs, f) {
  15582. if (xs.map) return xs.map(f);
  15583. var res = [];
  15584. for (var i = 0; i < xs.length; i++) {
  15585. res.push(f(xs[i], i));
  15586. }
  15587. return res;
  15588. }
  15589. var objectKeys = Object.keys || function (obj) {
  15590. var res = [];
  15591. for (var key in obj) {
  15592. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  15593. }
  15594. return res;
  15595. };
  15596. },{}],116:[function(require,module,exports){
  15597. 'use strict';
  15598. exports.decode = exports.parse = require('./decode');
  15599. exports.encode = exports.stringify = require('./encode');
  15600. },{"./decode":114,"./encode":115}],117:[function(require,module,exports){
  15601. (function (process,global,Buffer){
  15602. 'use strict'
  15603. function oldBrowser () {
  15604. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
  15605. }
  15606. var crypto = global.crypto || global.msCrypto
  15607. if (crypto && crypto.getRandomValues) {
  15608. module.exports = randomBytes
  15609. } else {
  15610. module.exports = oldBrowser
  15611. }
  15612. function randomBytes (size, cb) {
  15613. // phantomjs needs to throw
  15614. if (size > 65536) throw new Error('requested too many random bytes')
  15615. // in case browserify isn't using the Uint8Array version
  15616. var rawBytes = new global.Uint8Array(size)
  15617. // This will not work in older browsers.
  15618. // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  15619. if (size > 0) { // getRandomValues fails on IE if size == 0
  15620. crypto.getRandomValues(rawBytes)
  15621. }
  15622. // phantomjs doesn't like a buffer being passed here
  15623. var bytes = new Buffer(rawBytes.buffer)
  15624. if (typeof cb === 'function') {
  15625. return process.nextTick(function () {
  15626. cb(null, bytes)
  15627. })
  15628. }
  15629. return bytes
  15630. }
  15631. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
  15632. },{"_process":106,"buffer":46}],118:[function(require,module,exports){
  15633. module.exports = require("./lib/_stream_duplex.js")
  15634. },{"./lib/_stream_duplex.js":119}],119:[function(require,module,exports){
  15635. // a duplex stream is just a stream that is both readable and writable.
  15636. // Since JS doesn't have multiple prototypal inheritance, this class
  15637. // prototypally inherits from Readable, and then parasitically from
  15638. // Writable.
  15639. 'use strict';
  15640. /*<replacement>*/
  15641. var objectKeys = Object.keys || function (obj) {
  15642. var keys = [];
  15643. for (var key in obj) {
  15644. keys.push(key);
  15645. }return keys;
  15646. };
  15647. /*</replacement>*/
  15648. module.exports = Duplex;
  15649. /*<replacement>*/
  15650. var processNextTick = require('process-nextick-args');
  15651. /*</replacement>*/
  15652. /*<replacement>*/
  15653. var util = require('core-util-is');
  15654. util.inherits = require('inherits');
  15655. /*</replacement>*/
  15656. var Readable = require('./_stream_readable');
  15657. var Writable = require('./_stream_writable');
  15658. util.inherits(Duplex, Readable);
  15659. var keys = objectKeys(Writable.prototype);
  15660. for (var v = 0; v < keys.length; v++) {
  15661. var method = keys[v];
  15662. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  15663. }
  15664. function Duplex(options) {
  15665. if (!(this instanceof Duplex)) return new Duplex(options);
  15666. Readable.call(this, options);
  15667. Writable.call(this, options);
  15668. if (options && options.readable === false) this.readable = false;
  15669. if (options && options.writable === false) this.writable = false;
  15670. this.allowHalfOpen = true;
  15671. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  15672. this.once('end', onend);
  15673. }
  15674. // the no-half-open enforcer
  15675. function onend() {
  15676. // if we allow half-open state, or if the writable side ended,
  15677. // then we're ok.
  15678. if (this.allowHalfOpen || this._writableState.ended) return;
  15679. // no more data can be written.
  15680. // But allow more writes to happen in this tick.
  15681. processNextTick(onEndNT, this);
  15682. }
  15683. function onEndNT(self) {
  15684. self.end();
  15685. }
  15686. function forEach(xs, f) {
  15687. for (var i = 0, l = xs.length; i < l; i++) {
  15688. f(xs[i], i);
  15689. }
  15690. }
  15691. },{"./_stream_readable":121,"./_stream_writable":123,"core-util-is":48,"inherits":92,"process-nextick-args":105}],120:[function(require,module,exports){
  15692. // a passthrough stream.
  15693. // basically just the most minimal sort of Transform stream.
  15694. // Every written chunk gets output as-is.
  15695. 'use strict';
  15696. module.exports = PassThrough;
  15697. var Transform = require('./_stream_transform');
  15698. /*<replacement>*/
  15699. var util = require('core-util-is');
  15700. util.inherits = require('inherits');
  15701. /*</replacement>*/
  15702. util.inherits(PassThrough, Transform);
  15703. function PassThrough(options) {
  15704. if (!(this instanceof PassThrough)) return new PassThrough(options);
  15705. Transform.call(this, options);
  15706. }
  15707. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  15708. cb(null, chunk);
  15709. };
  15710. },{"./_stream_transform":122,"core-util-is":48,"inherits":92}],121:[function(require,module,exports){
  15711. (function (process){
  15712. 'use strict';
  15713. module.exports = Readable;
  15714. /*<replacement>*/
  15715. var processNextTick = require('process-nextick-args');
  15716. /*</replacement>*/
  15717. /*<replacement>*/
  15718. var isArray = require('isarray');
  15719. /*</replacement>*/
  15720. /*<replacement>*/
  15721. var Buffer = require('buffer').Buffer;
  15722. /*</replacement>*/
  15723. Readable.ReadableState = ReadableState;
  15724. var EE = require('events');
  15725. /*<replacement>*/
  15726. var EElistenerCount = function (emitter, type) {
  15727. return emitter.listeners(type).length;
  15728. };
  15729. /*</replacement>*/
  15730. /*<replacement>*/
  15731. var Stream;
  15732. (function () {
  15733. try {
  15734. Stream = require('st' + 'ream');
  15735. } catch (_) {} finally {
  15736. if (!Stream) Stream = require('events').EventEmitter;
  15737. }
  15738. })();
  15739. /*</replacement>*/
  15740. var Buffer = require('buffer').Buffer;
  15741. /*<replacement>*/
  15742. var util = require('core-util-is');
  15743. util.inherits = require('inherits');
  15744. /*</replacement>*/
  15745. /*<replacement>*/
  15746. var debugUtil = require('util');
  15747. var debug = undefined;
  15748. if (debugUtil && debugUtil.debuglog) {
  15749. debug = debugUtil.debuglog('stream');
  15750. } else {
  15751. debug = function () {};
  15752. }
  15753. /*</replacement>*/
  15754. var StringDecoder;
  15755. util.inherits(Readable, Stream);
  15756. var Duplex;
  15757. function ReadableState(options, stream) {
  15758. Duplex = Duplex || require('./_stream_duplex');
  15759. options = options || {};
  15760. // object stream flag. Used to make read(n) ignore n and to
  15761. // make all the buffer merging and length checks go away
  15762. this.objectMode = !!options.objectMode;
  15763. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  15764. // the point at which it stops calling _read() to fill the buffer
  15765. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  15766. var hwm = options.highWaterMark;
  15767. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  15768. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  15769. // cast to ints.
  15770. this.highWaterMark = ~ ~this.highWaterMark;
  15771. this.buffer = [];
  15772. this.length = 0;
  15773. this.pipes = null;
  15774. this.pipesCount = 0;
  15775. this.flowing = null;
  15776. this.ended = false;
  15777. this.endEmitted = false;
  15778. this.reading = false;
  15779. // a flag to be able to tell if the onwrite cb is called immediately,
  15780. // or on a later tick. We set this to true at first, because any
  15781. // actions that shouldn't happen until "later" should generally also
  15782. // not happen before the first write call.
  15783. this.sync = true;
  15784. // whenever we return null, then we set a flag to say
  15785. // that we're awaiting a 'readable' event emission.
  15786. this.needReadable = false;
  15787. this.emittedReadable = false;
  15788. this.readableListening = false;
  15789. this.resumeScheduled = false;
  15790. // Crypto is kind of old and crusty. Historically, its default string
  15791. // encoding is 'binary' so we have to make this configurable.
  15792. // Everything else in the universe uses 'utf8', though.
  15793. this.defaultEncoding = options.defaultEncoding || 'utf8';
  15794. // when piping, we only care about 'readable' events that happen
  15795. // after read()ing all the bytes and not getting any pushback.
  15796. this.ranOut = false;
  15797. // the number of writers that are awaiting a drain event in .pipe()s
  15798. this.awaitDrain = 0;
  15799. // if true, a maybeReadMore has been scheduled
  15800. this.readingMore = false;
  15801. this.decoder = null;
  15802. this.encoding = null;
  15803. if (options.encoding) {
  15804. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  15805. this.decoder = new StringDecoder(options.encoding);
  15806. this.encoding = options.encoding;
  15807. }
  15808. }
  15809. var Duplex;
  15810. function Readable(options) {
  15811. Duplex = Duplex || require('./_stream_duplex');
  15812. if (!(this instanceof Readable)) return new Readable(options);
  15813. this._readableState = new ReadableState(options, this);
  15814. // legacy
  15815. this.readable = true;
  15816. if (options && typeof options.read === 'function') this._read = options.read;
  15817. Stream.call(this);
  15818. }
  15819. // Manually shove something into the read() buffer.
  15820. // This returns true if the highWaterMark has not been hit yet,
  15821. // similar to how Writable.write() returns true if you should
  15822. // write() some more.
  15823. Readable.prototype.push = function (chunk, encoding) {
  15824. var state = this._readableState;
  15825. if (!state.objectMode && typeof chunk === 'string') {
  15826. encoding = encoding || state.defaultEncoding;
  15827. if (encoding !== state.encoding) {
  15828. chunk = new Buffer(chunk, encoding);
  15829. encoding = '';
  15830. }
  15831. }
  15832. return readableAddChunk(this, state, chunk, encoding, false);
  15833. };
  15834. // Unshift should *always* be something directly out of read()
  15835. Readable.prototype.unshift = function (chunk) {
  15836. var state = this._readableState;
  15837. return readableAddChunk(this, state, chunk, '', true);
  15838. };
  15839. Readable.prototype.isPaused = function () {
  15840. return this._readableState.flowing === false;
  15841. };
  15842. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  15843. var er = chunkInvalid(state, chunk);
  15844. if (er) {
  15845. stream.emit('error', er);
  15846. } else if (chunk === null) {
  15847. state.reading = false;
  15848. onEofChunk(stream, state);
  15849. } else if (state.objectMode || chunk && chunk.length > 0) {
  15850. if (state.ended && !addToFront) {
  15851. var e = new Error('stream.push() after EOF');
  15852. stream.emit('error', e);
  15853. } else if (state.endEmitted && addToFront) {
  15854. var e = new Error('stream.unshift() after end event');
  15855. stream.emit('error', e);
  15856. } else {
  15857. var skipAdd;
  15858. if (state.decoder && !addToFront && !encoding) {
  15859. chunk = state.decoder.write(chunk);
  15860. skipAdd = !state.objectMode && chunk.length === 0;
  15861. }
  15862. if (!addToFront) state.reading = false;
  15863. // Don't add to the buffer if we've decoded to an empty string chunk and
  15864. // we're not in object mode
  15865. if (!skipAdd) {
  15866. // if we want the data now, just emit it.
  15867. if (state.flowing && state.length === 0 && !state.sync) {
  15868. stream.emit('data', chunk);
  15869. stream.read(0);
  15870. } else {
  15871. // update the buffer info.
  15872. state.length += state.objectMode ? 1 : chunk.length;
  15873. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  15874. if (state.needReadable) emitReadable(stream);
  15875. }
  15876. }
  15877. maybeReadMore(stream, state);
  15878. }
  15879. } else if (!addToFront) {
  15880. state.reading = false;
  15881. }
  15882. return needMoreData(state);
  15883. }
  15884. // if it's past the high water mark, we can push in some more.
  15885. // Also, if we have no data yet, we can stand some
  15886. // more bytes. This is to work around cases where hwm=0,
  15887. // such as the repl. Also, if the push() triggered a
  15888. // readable event, and the user called read(largeNumber) such that
  15889. // needReadable was set, then we ought to push more, so that another
  15890. // 'readable' event will be triggered.
  15891. function needMoreData(state) {
  15892. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  15893. }
  15894. // backwards compatibility.
  15895. Readable.prototype.setEncoding = function (enc) {
  15896. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  15897. this._readableState.decoder = new StringDecoder(enc);
  15898. this._readableState.encoding = enc;
  15899. return this;
  15900. };
  15901. // Don't raise the hwm > 8MB
  15902. var MAX_HWM = 0x800000;
  15903. function computeNewHighWaterMark(n) {
  15904. if (n >= MAX_HWM) {
  15905. n = MAX_HWM;
  15906. } else {
  15907. // Get the next highest power of 2
  15908. n--;
  15909. n |= n >>> 1;
  15910. n |= n >>> 2;
  15911. n |= n >>> 4;
  15912. n |= n >>> 8;
  15913. n |= n >>> 16;
  15914. n++;
  15915. }
  15916. return n;
  15917. }
  15918. function howMuchToRead(n, state) {
  15919. if (state.length === 0 && state.ended) return 0;
  15920. if (state.objectMode) return n === 0 ? 0 : 1;
  15921. if (n === null || isNaN(n)) {
  15922. // only flow one buffer at a time
  15923. if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length;
  15924. }
  15925. if (n <= 0) return 0;
  15926. // If we're asking for more than the target buffer level,
  15927. // then raise the water mark. Bump up to the next highest
  15928. // power of 2, to prevent increasing it excessively in tiny
  15929. // amounts.
  15930. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  15931. // don't have that much. return null, unless we've ended.
  15932. if (n > state.length) {
  15933. if (!state.ended) {
  15934. state.needReadable = true;
  15935. return 0;
  15936. } else {
  15937. return state.length;
  15938. }
  15939. }
  15940. return n;
  15941. }
  15942. // you can override either this method, or the async _read(n) below.
  15943. Readable.prototype.read = function (n) {
  15944. debug('read', n);
  15945. var state = this._readableState;
  15946. var nOrig = n;
  15947. if (typeof n !== 'number' || n > 0) state.emittedReadable = false;
  15948. // if we're doing read(0) to trigger a readable event, but we
  15949. // already have a bunch of data in the buffer, then just trigger
  15950. // the 'readable' event and move on.
  15951. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  15952. debug('read: emitReadable', state.length, state.ended);
  15953. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  15954. return null;
  15955. }
  15956. n = howMuchToRead(n, state);
  15957. // if we've ended, and we're now clear, then finish it up.
  15958. if (n === 0 && state.ended) {
  15959. if (state.length === 0) endReadable(this);
  15960. return null;
  15961. }
  15962. // All the actual chunk generation logic needs to be
  15963. // *below* the call to _read. The reason is that in certain
  15964. // synthetic stream cases, such as passthrough streams, _read
  15965. // may be a completely synchronous operation which may change
  15966. // the state of the read buffer, providing enough data when
  15967. // before there was *not* enough.
  15968. //
  15969. // So, the steps are:
  15970. // 1. Figure out what the state of things will be after we do
  15971. // a read from the buffer.
  15972. //
  15973. // 2. If that resulting state will trigger a _read, then call _read.
  15974. // Note that this may be asynchronous, or synchronous. Yes, it is
  15975. // deeply ugly to write APIs this way, but that still doesn't mean
  15976. // that the Readable class should behave improperly, as streams are
  15977. // designed to be sync/async agnostic.
  15978. // Take note if the _read call is sync or async (ie, if the read call
  15979. // has returned yet), so that we know whether or not it's safe to emit
  15980. // 'readable' etc.
  15981. //
  15982. // 3. Actually pull the requested chunks out of the buffer and return.
  15983. // if we need a readable event, then we need to do some reading.
  15984. var doRead = state.needReadable;
  15985. debug('need readable', doRead);
  15986. // if we currently have less than the highWaterMark, then also read some
  15987. if (state.length === 0 || state.length - n < state.highWaterMark) {
  15988. doRead = true;
  15989. debug('length less than watermark', doRead);
  15990. }
  15991. // however, if we've ended, then there's no point, and if we're already
  15992. // reading, then it's unnecessary.
  15993. if (state.ended || state.reading) {
  15994. doRead = false;
  15995. debug('reading or ended', doRead);
  15996. }
  15997. if (doRead) {
  15998. debug('do read');
  15999. state.reading = true;
  16000. state.sync = true;
  16001. // if the length is currently zero, then we *need* a readable event.
  16002. if (state.length === 0) state.needReadable = true;
  16003. // call internal read method
  16004. this._read(state.highWaterMark);
  16005. state.sync = false;
  16006. }
  16007. // If _read pushed data synchronously, then `reading` will be false,
  16008. // and we need to re-evaluate how much data we can return to the user.
  16009. if (doRead && !state.reading) n = howMuchToRead(nOrig, state);
  16010. var ret;
  16011. if (n > 0) ret = fromList(n, state);else ret = null;
  16012. if (ret === null) {
  16013. state.needReadable = true;
  16014. n = 0;
  16015. }
  16016. state.length -= n;
  16017. // If we have nothing in the buffer, then we want to know
  16018. // as soon as we *do* get something into the buffer.
  16019. if (state.length === 0 && !state.ended) state.needReadable = true;
  16020. // If we tried to read() past the EOF, then emit end on the next tick.
  16021. if (nOrig !== n && state.ended && state.length === 0) endReadable(this);
  16022. if (ret !== null) this.emit('data', ret);
  16023. return ret;
  16024. };
  16025. function chunkInvalid(state, chunk) {
  16026. var er = null;
  16027. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  16028. er = new TypeError('Invalid non-string/buffer chunk');
  16029. }
  16030. return er;
  16031. }
  16032. function onEofChunk(stream, state) {
  16033. if (state.ended) return;
  16034. if (state.decoder) {
  16035. var chunk = state.decoder.end();
  16036. if (chunk && chunk.length) {
  16037. state.buffer.push(chunk);
  16038. state.length += state.objectMode ? 1 : chunk.length;
  16039. }
  16040. }
  16041. state.ended = true;
  16042. // emit 'readable' now to make sure it gets picked up.
  16043. emitReadable(stream);
  16044. }
  16045. // Don't emit readable right away in sync mode, because this can trigger
  16046. // another read() call => stack overflow. This way, it might trigger
  16047. // a nextTick recursion warning, but that's not so bad.
  16048. function emitReadable(stream) {
  16049. var state = stream._readableState;
  16050. state.needReadable = false;
  16051. if (!state.emittedReadable) {
  16052. debug('emitReadable', state.flowing);
  16053. state.emittedReadable = true;
  16054. if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
  16055. }
  16056. }
  16057. function emitReadable_(stream) {
  16058. debug('emit readable');
  16059. stream.emit('readable');
  16060. flow(stream);
  16061. }
  16062. // at this point, the user has presumably seen the 'readable' event,
  16063. // and called read() to consume some data. that may have triggered
  16064. // in turn another _read(n) call, in which case reading = true if
  16065. // it's in progress.
  16066. // However, if we're not ended, or reading, and the length < hwm,
  16067. // then go ahead and try to read some more preemptively.
  16068. function maybeReadMore(stream, state) {
  16069. if (!state.readingMore) {
  16070. state.readingMore = true;
  16071. processNextTick(maybeReadMore_, stream, state);
  16072. }
  16073. }
  16074. function maybeReadMore_(stream, state) {
  16075. var len = state.length;
  16076. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  16077. debug('maybeReadMore read 0');
  16078. stream.read(0);
  16079. if (len === state.length)
  16080. // didn't get any data, stop spinning.
  16081. break;else len = state.length;
  16082. }
  16083. state.readingMore = false;
  16084. }
  16085. // abstract method. to be overridden in specific implementation classes.
  16086. // call cb(er, data) where data is <= n in length.
  16087. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  16088. // arbitrary, and perhaps not very meaningful.
  16089. Readable.prototype._read = function (n) {
  16090. this.emit('error', new Error('not implemented'));
  16091. };
  16092. Readable.prototype.pipe = function (dest, pipeOpts) {
  16093. var src = this;
  16094. var state = this._readableState;
  16095. switch (state.pipesCount) {
  16096. case 0:
  16097. state.pipes = dest;
  16098. break;
  16099. case 1:
  16100. state.pipes = [state.pipes, dest];
  16101. break;
  16102. default:
  16103. state.pipes.push(dest);
  16104. break;
  16105. }
  16106. state.pipesCount += 1;
  16107. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  16108. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  16109. var endFn = doEnd ? onend : cleanup;
  16110. if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
  16111. dest.on('unpipe', onunpipe);
  16112. function onunpipe(readable) {
  16113. debug('onunpipe');
  16114. if (readable === src) {
  16115. cleanup();
  16116. }
  16117. }
  16118. function onend() {
  16119. debug('onend');
  16120. dest.end();
  16121. }
  16122. // when the dest drains, it reduces the awaitDrain counter
  16123. // on the source. This would be more elegant with a .once()
  16124. // handler in flow(), but adding and removing repeatedly is
  16125. // too slow.
  16126. var ondrain = pipeOnDrain(src);
  16127. dest.on('drain', ondrain);
  16128. var cleanedUp = false;
  16129. function cleanup() {
  16130. debug('cleanup');
  16131. // cleanup event handlers once the pipe is broken
  16132. dest.removeListener('close', onclose);
  16133. dest.removeListener('finish', onfinish);
  16134. dest.removeListener('drain', ondrain);
  16135. dest.removeListener('error', onerror);
  16136. dest.removeListener('unpipe', onunpipe);
  16137. src.removeListener('end', onend);
  16138. src.removeListener('end', cleanup);
  16139. src.removeListener('data', ondata);
  16140. cleanedUp = true;
  16141. // if the reader is waiting for a drain event from this
  16142. // specific writer, then it would cause it to never start
  16143. // flowing again.
  16144. // So, if this is awaiting a drain, then we just call it now.
  16145. // If we don't know, then assume that we are waiting for one.
  16146. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  16147. }
  16148. src.on('data', ondata);
  16149. function ondata(chunk) {
  16150. debug('ondata');
  16151. var ret = dest.write(chunk);
  16152. if (false === ret) {
  16153. // If the user unpiped during `dest.write()`, it is possible
  16154. // to get stuck in a permanently paused state if that write
  16155. // also returned false.
  16156. if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) {
  16157. debug('false write response, pause', src._readableState.awaitDrain);
  16158. src._readableState.awaitDrain++;
  16159. }
  16160. src.pause();
  16161. }
  16162. }
  16163. // if the dest has an error, then stop piping into it.
  16164. // however, don't suppress the throwing behavior for this.
  16165. function onerror(er) {
  16166. debug('onerror', er);
  16167. unpipe();
  16168. dest.removeListener('error', onerror);
  16169. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  16170. }
  16171. // This is a brutally ugly hack to make sure that our error handler
  16172. // is attached before any userland ones. NEVER DO THIS.
  16173. 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];
  16174. // Both close and finish should trigger unpipe, but only once.
  16175. function onclose() {
  16176. dest.removeListener('finish', onfinish);
  16177. unpipe();
  16178. }
  16179. dest.once('close', onclose);
  16180. function onfinish() {
  16181. debug('onfinish');
  16182. dest.removeListener('close', onclose);
  16183. unpipe();
  16184. }
  16185. dest.once('finish', onfinish);
  16186. function unpipe() {
  16187. debug('unpipe');
  16188. src.unpipe(dest);
  16189. }
  16190. // tell the dest that it's being piped to
  16191. dest.emit('pipe', src);
  16192. // start the flow if it hasn't been started already.
  16193. if (!state.flowing) {
  16194. debug('pipe resume');
  16195. src.resume();
  16196. }
  16197. return dest;
  16198. };
  16199. function pipeOnDrain(src) {
  16200. return function () {
  16201. var state = src._readableState;
  16202. debug('pipeOnDrain', state.awaitDrain);
  16203. if (state.awaitDrain) state.awaitDrain--;
  16204. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  16205. state.flowing = true;
  16206. flow(src);
  16207. }
  16208. };
  16209. }
  16210. Readable.prototype.unpipe = function (dest) {
  16211. var state = this._readableState;
  16212. // if we're not piping anywhere, then do nothing.
  16213. if (state.pipesCount === 0) return this;
  16214. // just one destination. most common case.
  16215. if (state.pipesCount === 1) {
  16216. // passed in one, but it's not the right one.
  16217. if (dest && dest !== state.pipes) return this;
  16218. if (!dest) dest = state.pipes;
  16219. // got a match.
  16220. state.pipes = null;
  16221. state.pipesCount = 0;
  16222. state.flowing = false;
  16223. if (dest) dest.emit('unpipe', this);
  16224. return this;
  16225. }
  16226. // slow case. multiple pipe destinations.
  16227. if (!dest) {
  16228. // remove all.
  16229. var dests = state.pipes;
  16230. var len = state.pipesCount;
  16231. state.pipes = null;
  16232. state.pipesCount = 0;
  16233. state.flowing = false;
  16234. for (var _i = 0; _i < len; _i++) {
  16235. dests[_i].emit('unpipe', this);
  16236. }return this;
  16237. }
  16238. // try to find the right one.
  16239. var i = indexOf(state.pipes, dest);
  16240. if (i === -1) return this;
  16241. state.pipes.splice(i, 1);
  16242. state.pipesCount -= 1;
  16243. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  16244. dest.emit('unpipe', this);
  16245. return this;
  16246. };
  16247. // set up data events if they are asked for
  16248. // Ensure readable listeners eventually get something
  16249. Readable.prototype.on = function (ev, fn) {
  16250. var res = Stream.prototype.on.call(this, ev, fn);
  16251. // If listening to data, and it has not explicitly been paused,
  16252. // then call resume to start the flow of data on the next tick.
  16253. if (ev === 'data' && false !== this._readableState.flowing) {
  16254. this.resume();
  16255. }
  16256. if (ev === 'readable' && !this._readableState.endEmitted) {
  16257. var state = this._readableState;
  16258. if (!state.readableListening) {
  16259. state.readableListening = true;
  16260. state.emittedReadable = false;
  16261. state.needReadable = true;
  16262. if (!state.reading) {
  16263. processNextTick(nReadingNextTick, this);
  16264. } else if (state.length) {
  16265. emitReadable(this, state);
  16266. }
  16267. }
  16268. }
  16269. return res;
  16270. };
  16271. Readable.prototype.addListener = Readable.prototype.on;
  16272. function nReadingNextTick(self) {
  16273. debug('readable nexttick read 0');
  16274. self.read(0);
  16275. }
  16276. // pause() and resume() are remnants of the legacy readable stream API
  16277. // If the user uses them, then switch into old mode.
  16278. Readable.prototype.resume = function () {
  16279. var state = this._readableState;
  16280. if (!state.flowing) {
  16281. debug('resume');
  16282. state.flowing = true;
  16283. resume(this, state);
  16284. }
  16285. return this;
  16286. };
  16287. function resume(stream, state) {
  16288. if (!state.resumeScheduled) {
  16289. state.resumeScheduled = true;
  16290. processNextTick(resume_, stream, state);
  16291. }
  16292. }
  16293. function resume_(stream, state) {
  16294. if (!state.reading) {
  16295. debug('resume read 0');
  16296. stream.read(0);
  16297. }
  16298. state.resumeScheduled = false;
  16299. stream.emit('resume');
  16300. flow(stream);
  16301. if (state.flowing && !state.reading) stream.read(0);
  16302. }
  16303. Readable.prototype.pause = function () {
  16304. debug('call pause flowing=%j', this._readableState.flowing);
  16305. if (false !== this._readableState.flowing) {
  16306. debug('pause');
  16307. this._readableState.flowing = false;
  16308. this.emit('pause');
  16309. }
  16310. return this;
  16311. };
  16312. function flow(stream) {
  16313. var state = stream._readableState;
  16314. debug('flow', state.flowing);
  16315. if (state.flowing) {
  16316. do {
  16317. var chunk = stream.read();
  16318. } while (null !== chunk && state.flowing);
  16319. }
  16320. }
  16321. // wrap an old-style stream as the async data source.
  16322. // This is *not* part of the readable stream interface.
  16323. // It is an ugly unfortunate mess of history.
  16324. Readable.prototype.wrap = function (stream) {
  16325. var state = this._readableState;
  16326. var paused = false;
  16327. var self = this;
  16328. stream.on('end', function () {
  16329. debug('wrapped end');
  16330. if (state.decoder && !state.ended) {
  16331. var chunk = state.decoder.end();
  16332. if (chunk && chunk.length) self.push(chunk);
  16333. }
  16334. self.push(null);
  16335. });
  16336. stream.on('data', function (chunk) {
  16337. debug('wrapped data');
  16338. if (state.decoder) chunk = state.decoder.write(chunk);
  16339. // don't skip over falsy values in objectMode
  16340. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  16341. var ret = self.push(chunk);
  16342. if (!ret) {
  16343. paused = true;
  16344. stream.pause();
  16345. }
  16346. });
  16347. // proxy all the other methods.
  16348. // important when wrapping filters and duplexes.
  16349. for (var i in stream) {
  16350. if (this[i] === undefined && typeof stream[i] === 'function') {
  16351. this[i] = function (method) {
  16352. return function () {
  16353. return stream[method].apply(stream, arguments);
  16354. };
  16355. }(i);
  16356. }
  16357. }
  16358. // proxy certain important events.
  16359. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  16360. forEach(events, function (ev) {
  16361. stream.on(ev, self.emit.bind(self, ev));
  16362. });
  16363. // when we try to consume some more bytes, simply unpause the
  16364. // underlying stream.
  16365. self._read = function (n) {
  16366. debug('wrapped _read', n);
  16367. if (paused) {
  16368. paused = false;
  16369. stream.resume();
  16370. }
  16371. };
  16372. return self;
  16373. };
  16374. // exposed for testing purposes only.
  16375. Readable._fromList = fromList;
  16376. // Pluck off n bytes from an array of buffers.
  16377. // Length is the combined lengths of all the buffers in the list.
  16378. function fromList(n, state) {
  16379. var list = state.buffer;
  16380. var length = state.length;
  16381. var stringMode = !!state.decoder;
  16382. var objectMode = !!state.objectMode;
  16383. var ret;
  16384. // nothing in the list, definitely empty.
  16385. if (list.length === 0) return null;
  16386. if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) {
  16387. // read it all, truncate the array.
  16388. if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length);
  16389. list.length = 0;
  16390. } else {
  16391. // read just some of it.
  16392. if (n < list[0].length) {
  16393. // just take a part of the first list item.
  16394. // slice is the same for buffers and strings.
  16395. var buf = list[0];
  16396. ret = buf.slice(0, n);
  16397. list[0] = buf.slice(n);
  16398. } else if (n === list[0].length) {
  16399. // first list is a perfect match
  16400. ret = list.shift();
  16401. } else {
  16402. // complex case.
  16403. // we have enough to cover it, but it spans past the first buffer.
  16404. if (stringMode) ret = '';else ret = new Buffer(n);
  16405. var c = 0;
  16406. for (var i = 0, l = list.length; i < l && c < n; i++) {
  16407. var buf = list[0];
  16408. var cpy = Math.min(n - c, buf.length);
  16409. if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy);
  16410. if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift();
  16411. c += cpy;
  16412. }
  16413. }
  16414. }
  16415. return ret;
  16416. }
  16417. function endReadable(stream) {
  16418. var state = stream._readableState;
  16419. // If we get here before consuming all the bytes, then that is a
  16420. // bug in node. Should never happen.
  16421. if (state.length > 0) throw new Error('endReadable called on non-empty stream');
  16422. if (!state.endEmitted) {
  16423. state.ended = true;
  16424. processNextTick(endReadableNT, state, stream);
  16425. }
  16426. }
  16427. function endReadableNT(state, stream) {
  16428. // Check that we didn't get one last unshift.
  16429. if (!state.endEmitted && state.length === 0) {
  16430. state.endEmitted = true;
  16431. stream.readable = false;
  16432. stream.emit('end');
  16433. }
  16434. }
  16435. function forEach(xs, f) {
  16436. for (var i = 0, l = xs.length; i < l; i++) {
  16437. f(xs[i], i);
  16438. }
  16439. }
  16440. function indexOf(xs, x) {
  16441. for (var i = 0, l = xs.length; i < l; i++) {
  16442. if (xs[i] === x) return i;
  16443. }
  16444. return -1;
  16445. }
  16446. }).call(this,require('_process'))
  16447. },{"./_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){
  16448. // a transform stream is a readable/writable stream where you do
  16449. // something with the data. Sometimes it's called a "filter",
  16450. // but that's not a great name for it, since that implies a thing where
  16451. // some bits pass through, and others are simply ignored. (That would
  16452. // be a valid example of a transform, of course.)
  16453. //
  16454. // While the output is causally related to the input, it's not a
  16455. // necessarily symmetric or synchronous transformation. For example,
  16456. // a zlib stream might take multiple plain-text writes(), and then
  16457. // emit a single compressed chunk some time in the future.
  16458. //
  16459. // Here's how this works:
  16460. //
  16461. // The Transform stream has all the aspects of the readable and writable
  16462. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  16463. // internally, and returns false if there's a lot of pending writes
  16464. // buffered up. When you call read(), that calls _read(n) until
  16465. // there's enough pending readable data buffered up.
  16466. //
  16467. // In a transform stream, the written data is placed in a buffer. When
  16468. // _read(n) is called, it transforms the queued up data, calling the
  16469. // buffered _write cb's as it consumes chunks. If consuming a single
  16470. // written chunk would result in multiple output chunks, then the first
  16471. // outputted bit calls the readcb, and subsequent chunks just go into
  16472. // the read buffer, and will cause it to emit 'readable' if necessary.
  16473. //
  16474. // This way, back-pressure is actually determined by the reading side,
  16475. // since _read has to be called to start processing a new chunk. However,
  16476. // a pathological inflate type of transform can cause excessive buffering
  16477. // here. For example, imagine a stream where every byte of input is
  16478. // interpreted as an integer from 0-255, and then results in that many
  16479. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  16480. // 1kb of data being output. In this case, you could write a very small
  16481. // amount of input, and end up with a very large amount of output. In
  16482. // such a pathological inflating mechanism, there'd be no way to tell
  16483. // the system to stop doing the transform. A single 4MB write could
  16484. // cause the system to run out of memory.
  16485. //
  16486. // However, even in such a pathological case, only a single written chunk
  16487. // would be consumed, and then the rest would wait (un-transformed) until
  16488. // the results of the previous transformed chunk were consumed.
  16489. 'use strict';
  16490. module.exports = Transform;
  16491. var Duplex = require('./_stream_duplex');
  16492. /*<replacement>*/
  16493. var util = require('core-util-is');
  16494. util.inherits = require('inherits');
  16495. /*</replacement>*/
  16496. util.inherits(Transform, Duplex);
  16497. function TransformState(stream) {
  16498. this.afterTransform = function (er, data) {
  16499. return afterTransform(stream, er, data);
  16500. };
  16501. this.needTransform = false;
  16502. this.transforming = false;
  16503. this.writecb = null;
  16504. this.writechunk = null;
  16505. this.writeencoding = null;
  16506. }
  16507. function afterTransform(stream, er, data) {
  16508. var ts = stream._transformState;
  16509. ts.transforming = false;
  16510. var cb = ts.writecb;
  16511. if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
  16512. ts.writechunk = null;
  16513. ts.writecb = null;
  16514. if (data !== null && data !== undefined) stream.push(data);
  16515. cb(er);
  16516. var rs = stream._readableState;
  16517. rs.reading = false;
  16518. if (rs.needReadable || rs.length < rs.highWaterMark) {
  16519. stream._read(rs.highWaterMark);
  16520. }
  16521. }
  16522. function Transform(options) {
  16523. if (!(this instanceof Transform)) return new Transform(options);
  16524. Duplex.call(this, options);
  16525. this._transformState = new TransformState(this);
  16526. // when the writable side finishes, then flush out anything remaining.
  16527. var stream = this;
  16528. // start out asking for a readable event once data is transformed.
  16529. this._readableState.needReadable = true;
  16530. // we have implemented the _read method, and done the other things
  16531. // that Readable wants before the first _read call, so unset the
  16532. // sync guard flag.
  16533. this._readableState.sync = false;
  16534. if (options) {
  16535. if (typeof options.transform === 'function') this._transform = options.transform;
  16536. if (typeof options.flush === 'function') this._flush = options.flush;
  16537. }
  16538. this.once('prefinish', function () {
  16539. if (typeof this._flush === 'function') this._flush(function (er) {
  16540. done(stream, er);
  16541. });else done(stream);
  16542. });
  16543. }
  16544. Transform.prototype.push = function (chunk, encoding) {
  16545. this._transformState.needTransform = false;
  16546. return Duplex.prototype.push.call(this, chunk, encoding);
  16547. };
  16548. // This is the part where you do stuff!
  16549. // override this function in implementation classes.
  16550. // 'chunk' is an input chunk.
  16551. //
  16552. // Call `push(newChunk)` to pass along transformed output
  16553. // to the readable side. You may call 'push' zero or more times.
  16554. //
  16555. // Call `cb(err)` when you are done with this chunk. If you pass
  16556. // an error, then that'll put the hurt on the whole operation. If you
  16557. // never call cb(), then you'll never get another chunk.
  16558. Transform.prototype._transform = function (chunk, encoding, cb) {
  16559. throw new Error('not implemented');
  16560. };
  16561. Transform.prototype._write = function (chunk, encoding, cb) {
  16562. var ts = this._transformState;
  16563. ts.writecb = cb;
  16564. ts.writechunk = chunk;
  16565. ts.writeencoding = encoding;
  16566. if (!ts.transforming) {
  16567. var rs = this._readableState;
  16568. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  16569. }
  16570. };
  16571. // Doesn't matter what the args are here.
  16572. // _transform does all the work.
  16573. // That we got here means that the readable side wants more data.
  16574. Transform.prototype._read = function (n) {
  16575. var ts = this._transformState;
  16576. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  16577. ts.transforming = true;
  16578. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  16579. } else {
  16580. // mark that we need a transform, so that any data that comes in
  16581. // will get processed, now that we've asked for it.
  16582. ts.needTransform = true;
  16583. }
  16584. };
  16585. function done(stream, er) {
  16586. if (er) return stream.emit('error', er);
  16587. // if there's nothing in the write buffer, then that means
  16588. // that nothing more will ever be provided
  16589. var ws = stream._writableState;
  16590. var ts = stream._transformState;
  16591. if (ws.length) throw new Error('calling transform done when ws.length != 0');
  16592. if (ts.transforming) throw new Error('calling transform done when still transforming');
  16593. return stream.push(null);
  16594. }
  16595. },{"./_stream_duplex":119,"core-util-is":48,"inherits":92}],123:[function(require,module,exports){
  16596. (function (process){
  16597. // A bit simpler than readable streams.
  16598. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  16599. // the drain event emission and buffering.
  16600. 'use strict';
  16601. module.exports = Writable;
  16602. /*<replacement>*/
  16603. var processNextTick = require('process-nextick-args');
  16604. /*</replacement>*/
  16605. /*<replacement>*/
  16606. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
  16607. /*</replacement>*/
  16608. /*<replacement>*/
  16609. var Buffer = require('buffer').Buffer;
  16610. /*</replacement>*/
  16611. Writable.WritableState = WritableState;
  16612. /*<replacement>*/
  16613. var util = require('core-util-is');
  16614. util.inherits = require('inherits');
  16615. /*</replacement>*/
  16616. /*<replacement>*/
  16617. var internalUtil = {
  16618. deprecate: require('util-deprecate')
  16619. };
  16620. /*</replacement>*/
  16621. /*<replacement>*/
  16622. var Stream;
  16623. (function () {
  16624. try {
  16625. Stream = require('st' + 'ream');
  16626. } catch (_) {} finally {
  16627. if (!Stream) Stream = require('events').EventEmitter;
  16628. }
  16629. })();
  16630. /*</replacement>*/
  16631. var Buffer = require('buffer').Buffer;
  16632. util.inherits(Writable, Stream);
  16633. function nop() {}
  16634. function WriteReq(chunk, encoding, cb) {
  16635. this.chunk = chunk;
  16636. this.encoding = encoding;
  16637. this.callback = cb;
  16638. this.next = null;
  16639. }
  16640. var Duplex;
  16641. function WritableState(options, stream) {
  16642. Duplex = Duplex || require('./_stream_duplex');
  16643. options = options || {};
  16644. // object stream flag to indicate whether or not this stream
  16645. // contains buffers or objects.
  16646. this.objectMode = !!options.objectMode;
  16647. if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  16648. // the point at which write() starts returning false
  16649. // Note: 0 is a valid value, means that we always return false if
  16650. // the entire buffer is not flushed immediately on write()
  16651. var hwm = options.highWaterMark;
  16652. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  16653. this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
  16654. // cast to ints.
  16655. this.highWaterMark = ~ ~this.highWaterMark;
  16656. this.needDrain = false;
  16657. // at the start of calling end()
  16658. this.ending = false;
  16659. // when end() has been called, and returned
  16660. this.ended = false;
  16661. // when 'finish' is emitted
  16662. this.finished = false;
  16663. // should we decode strings into buffers before passing to _write?
  16664. // this is here so that some node-core streams can optimize string
  16665. // handling at a lower level.
  16666. var noDecode = options.decodeStrings === false;
  16667. this.decodeStrings = !noDecode;
  16668. // Crypto is kind of old and crusty. Historically, its default string
  16669. // encoding is 'binary' so we have to make this configurable.
  16670. // Everything else in the universe uses 'utf8', though.
  16671. this.defaultEncoding = options.defaultEncoding || 'utf8';
  16672. // not an actual buffer we keep track of, but a measurement
  16673. // of how much we're waiting to get pushed to some underlying
  16674. // socket or file.
  16675. this.length = 0;
  16676. // a flag to see when we're in the middle of a write.
  16677. this.writing = false;
  16678. // when true all writes will be buffered until .uncork() call
  16679. this.corked = 0;
  16680. // a flag to be able to tell if the onwrite cb is called immediately,
  16681. // or on a later tick. We set this to true at first, because any
  16682. // actions that shouldn't happen until "later" should generally also
  16683. // not happen before the first write call.
  16684. this.sync = true;
  16685. // a flag to know if we're processing previously buffered items, which
  16686. // may call the _write() callback in the same tick, so that we don't
  16687. // end up in an overlapped onwrite situation.
  16688. this.bufferProcessing = false;
  16689. // the callback that's passed to _write(chunk,cb)
  16690. this.onwrite = function (er) {
  16691. onwrite(stream, er);
  16692. };
  16693. // the callback that the user supplies to write(chunk,encoding,cb)
  16694. this.writecb = null;
  16695. // the amount that is being written when _write is called.
  16696. this.writelen = 0;
  16697. this.bufferedRequest = null;
  16698. this.lastBufferedRequest = null;
  16699. // number of pending user-supplied write callbacks
  16700. // this must be 0 before 'finish' can be emitted
  16701. this.pendingcb = 0;
  16702. // emit prefinish if the only thing we're waiting for is _write cbs
  16703. // This is relevant for synchronous Transform streams
  16704. this.prefinished = false;
  16705. // True if the error was already emitted and should not be thrown again
  16706. this.errorEmitted = false;
  16707. // count buffered requests
  16708. this.bufferedRequestCount = 0;
  16709. // create the two objects needed to store the corked requests
  16710. // they are not a linked list, as no new elements are inserted in there
  16711. this.corkedRequestsFree = new CorkedRequest(this);
  16712. this.corkedRequestsFree.next = new CorkedRequest(this);
  16713. }
  16714. WritableState.prototype.getBuffer = function writableStateGetBuffer() {
  16715. var current = this.bufferedRequest;
  16716. var out = [];
  16717. while (current) {
  16718. out.push(current);
  16719. current = current.next;
  16720. }
  16721. return out;
  16722. };
  16723. (function () {
  16724. try {
  16725. Object.defineProperty(WritableState.prototype, 'buffer', {
  16726. get: internalUtil.deprecate(function () {
  16727. return this.getBuffer();
  16728. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
  16729. });
  16730. } catch (_) {}
  16731. })();
  16732. var Duplex;
  16733. function Writable(options) {
  16734. Duplex = Duplex || require('./_stream_duplex');
  16735. // Writable ctor is applied to Duplexes, though they're not
  16736. // instanceof Writable, they're instanceof Readable.
  16737. if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options);
  16738. this._writableState = new WritableState(options, this);
  16739. // legacy.
  16740. this.writable = true;
  16741. if (options) {
  16742. if (typeof options.write === 'function') this._write = options.write;
  16743. if (typeof options.writev === 'function') this._writev = options.writev;
  16744. }
  16745. Stream.call(this);
  16746. }
  16747. // Otherwise people can pipe Writable streams, which is just wrong.
  16748. Writable.prototype.pipe = function () {
  16749. this.emit('error', new Error('Cannot pipe. Not readable.'));
  16750. };
  16751. function writeAfterEnd(stream, cb) {
  16752. var er = new Error('write after end');
  16753. // TODO: defer error events consistently everywhere, not just the cb
  16754. stream.emit('error', er);
  16755. processNextTick(cb, er);
  16756. }
  16757. // If we get something that is not a buffer, string, null, or undefined,
  16758. // and we're not in objectMode, then that's an error.
  16759. // Otherwise stream chunks are all considered to be of length=1, and the
  16760. // watermarks determine how many objects to keep in the buffer, rather than
  16761. // how many bytes or characters.
  16762. function validChunk(stream, state, chunk, cb) {
  16763. var valid = true;
  16764. if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
  16765. var er = new TypeError('Invalid non-string/buffer chunk');
  16766. stream.emit('error', er);
  16767. processNextTick(cb, er);
  16768. valid = false;
  16769. }
  16770. return valid;
  16771. }
  16772. Writable.prototype.write = function (chunk, encoding, cb) {
  16773. var state = this._writableState;
  16774. var ret = false;
  16775. if (typeof encoding === 'function') {
  16776. cb = encoding;
  16777. encoding = null;
  16778. }
  16779. if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  16780. if (typeof cb !== 'function') cb = nop;
  16781. if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
  16782. state.pendingcb++;
  16783. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  16784. }
  16785. return ret;
  16786. };
  16787. Writable.prototype.cork = function () {
  16788. var state = this._writableState;
  16789. state.corked++;
  16790. };
  16791. Writable.prototype.uncork = function () {
  16792. var state = this._writableState;
  16793. if (state.corked) {
  16794. state.corked--;
  16795. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  16796. }
  16797. };
  16798. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  16799. // node::ParseEncoding() requires lower case.
  16800. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  16801. 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);
  16802. this._writableState.defaultEncoding = encoding;
  16803. };
  16804. function decodeChunk(state, chunk, encoding) {
  16805. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  16806. chunk = new Buffer(chunk, encoding);
  16807. }
  16808. return chunk;
  16809. }
  16810. // if we're already writing something, then just put this
  16811. // in the queue, and wait our turn. Otherwise, call _write
  16812. // If we return false, then we need a drain event, so set that flag.
  16813. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  16814. chunk = decodeChunk(state, chunk, encoding);
  16815. if (Buffer.isBuffer(chunk)) encoding = 'buffer';
  16816. var len = state.objectMode ? 1 : chunk.length;
  16817. state.length += len;
  16818. var ret = state.length < state.highWaterMark;
  16819. // we must ensure that previous needDrain will not be reset to false.
  16820. if (!ret) state.needDrain = true;
  16821. if (state.writing || state.corked) {
  16822. var last = state.lastBufferedRequest;
  16823. state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
  16824. if (last) {
  16825. last.next = state.lastBufferedRequest;
  16826. } else {
  16827. state.bufferedRequest = state.lastBufferedRequest;
  16828. }
  16829. state.bufferedRequestCount += 1;
  16830. } else {
  16831. doWrite(stream, state, false, len, chunk, encoding, cb);
  16832. }
  16833. return ret;
  16834. }
  16835. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  16836. state.writelen = len;
  16837. state.writecb = cb;
  16838. state.writing = true;
  16839. state.sync = true;
  16840. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  16841. state.sync = false;
  16842. }
  16843. function onwriteError(stream, state, sync, er, cb) {
  16844. --state.pendingcb;
  16845. if (sync) processNextTick(cb, er);else cb(er);
  16846. stream._writableState.errorEmitted = true;
  16847. stream.emit('error', er);
  16848. }
  16849. function onwriteStateUpdate(state) {
  16850. state.writing = false;
  16851. state.writecb = null;
  16852. state.length -= state.writelen;
  16853. state.writelen = 0;
  16854. }
  16855. function onwrite(stream, er) {
  16856. var state = stream._writableState;
  16857. var sync = state.sync;
  16858. var cb = state.writecb;
  16859. onwriteStateUpdate(state);
  16860. if (er) onwriteError(stream, state, sync, er, cb);else {
  16861. // Check if we're actually ready to finish, but don't emit yet
  16862. var finished = needFinish(state);
  16863. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  16864. clearBuffer(stream, state);
  16865. }
  16866. if (sync) {
  16867. /*<replacement>*/
  16868. asyncWrite(afterWrite, stream, state, finished, cb);
  16869. /*</replacement>*/
  16870. } else {
  16871. afterWrite(stream, state, finished, cb);
  16872. }
  16873. }
  16874. }
  16875. function afterWrite(stream, state, finished, cb) {
  16876. if (!finished) onwriteDrain(stream, state);
  16877. state.pendingcb--;
  16878. cb();
  16879. finishMaybe(stream, state);
  16880. }
  16881. // Must force callback to be called on nextTick, so that we don't
  16882. // emit 'drain' before the write() consumer gets the 'false' return
  16883. // value, and has a chance to attach a 'drain' listener.
  16884. function onwriteDrain(stream, state) {
  16885. if (state.length === 0 && state.needDrain) {
  16886. state.needDrain = false;
  16887. stream.emit('drain');
  16888. }
  16889. }
  16890. // if there's something in the buffer waiting, then process it
  16891. function clearBuffer(stream, state) {
  16892. state.bufferProcessing = true;
  16893. var entry = state.bufferedRequest;
  16894. if (stream._writev && entry && entry.next) {
  16895. // Fast case, write everything using _writev()
  16896. var l = state.bufferedRequestCount;
  16897. var buffer = new Array(l);
  16898. var holder = state.corkedRequestsFree;
  16899. holder.entry = entry;
  16900. var count = 0;
  16901. while (entry) {
  16902. buffer[count] = entry;
  16903. entry = entry.next;
  16904. count += 1;
  16905. }
  16906. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  16907. // doWrite is always async, defer these to save a bit of time
  16908. // as the hot path ends with doWrite
  16909. state.pendingcb++;
  16910. state.lastBufferedRequest = null;
  16911. state.corkedRequestsFree = holder.next;
  16912. holder.next = null;
  16913. } else {
  16914. // Slow case, write chunks one-by-one
  16915. while (entry) {
  16916. var chunk = entry.chunk;
  16917. var encoding = entry.encoding;
  16918. var cb = entry.callback;
  16919. var len = state.objectMode ? 1 : chunk.length;
  16920. doWrite(stream, state, false, len, chunk, encoding, cb);
  16921. entry = entry.next;
  16922. // if we didn't call the onwrite immediately, then
  16923. // it means that we need to wait until it does.
  16924. // also, that means that the chunk and cb are currently
  16925. // being processed, so move the buffer counter past them.
  16926. if (state.writing) {
  16927. break;
  16928. }
  16929. }
  16930. if (entry === null) state.lastBufferedRequest = null;
  16931. }
  16932. state.bufferedRequestCount = 0;
  16933. state.bufferedRequest = entry;
  16934. state.bufferProcessing = false;
  16935. }
  16936. Writable.prototype._write = function (chunk, encoding, cb) {
  16937. cb(new Error('not implemented'));
  16938. };
  16939. Writable.prototype._writev = null;
  16940. Writable.prototype.end = function (chunk, encoding, cb) {
  16941. var state = this._writableState;
  16942. if (typeof chunk === 'function') {
  16943. cb = chunk;
  16944. chunk = null;
  16945. encoding = null;
  16946. } else if (typeof encoding === 'function') {
  16947. cb = encoding;
  16948. encoding = null;
  16949. }
  16950. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  16951. // .end() fully uncorks
  16952. if (state.corked) {
  16953. state.corked = 1;
  16954. this.uncork();
  16955. }
  16956. // ignore unnecessary end() calls.
  16957. if (!state.ending && !state.finished) endWritable(this, state, cb);
  16958. };
  16959. function needFinish(state) {
  16960. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  16961. }
  16962. function prefinish(stream, state) {
  16963. if (!state.prefinished) {
  16964. state.prefinished = true;
  16965. stream.emit('prefinish');
  16966. }
  16967. }
  16968. function finishMaybe(stream, state) {
  16969. var need = needFinish(state);
  16970. if (need) {
  16971. if (state.pendingcb === 0) {
  16972. prefinish(stream, state);
  16973. state.finished = true;
  16974. stream.emit('finish');
  16975. } else {
  16976. prefinish(stream, state);
  16977. }
  16978. }
  16979. return need;
  16980. }
  16981. function endWritable(stream, state, cb) {
  16982. state.ending = true;
  16983. finishMaybe(stream, state);
  16984. if (cb) {
  16985. if (state.finished) processNextTick(cb);else stream.once('finish', cb);
  16986. }
  16987. state.ended = true;
  16988. stream.writable = false;
  16989. }
  16990. // It seems a linked list but it is not
  16991. // there will be only 2 of these for each stream
  16992. function CorkedRequest(state) {
  16993. var _this = this;
  16994. this.next = null;
  16995. this.entry = null;
  16996. this.finish = function (err) {
  16997. var entry = _this.entry;
  16998. _this.entry = null;
  16999. while (entry) {
  17000. var cb = entry.callback;
  17001. state.pendingcb--;
  17002. cb(err);
  17003. entry = entry.next;
  17004. }
  17005. if (state.corkedRequestsFree) {
  17006. state.corkedRequestsFree.next = _this;
  17007. } else {
  17008. state.corkedRequestsFree = _this;
  17009. }
  17010. };
  17011. }
  17012. }).call(this,require('_process'))
  17013. },{"./_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){
  17014. module.exports = require("./lib/_stream_passthrough.js")
  17015. },{"./lib/_stream_passthrough.js":120}],125:[function(require,module,exports){
  17016. (function (process){
  17017. var Stream = (function (){
  17018. try {
  17019. return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
  17020. } catch(_){}
  17021. }());
  17022. exports = module.exports = require('./lib/_stream_readable.js');
  17023. exports.Stream = Stream || exports;
  17024. exports.Readable = exports;
  17025. exports.Writable = require('./lib/_stream_writable.js');
  17026. exports.Duplex = require('./lib/_stream_duplex.js');
  17027. exports.Transform = require('./lib/_stream_transform.js');
  17028. exports.PassThrough = require('./lib/_stream_passthrough.js');
  17029. if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
  17030. module.exports = Stream;
  17031. }
  17032. }).call(this,require('_process'))
  17033. },{"./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){
  17034. module.exports = require("./lib/_stream_transform.js")
  17035. },{"./lib/_stream_transform.js":122}],127:[function(require,module,exports){
  17036. module.exports = require("./lib/_stream_writable.js")
  17037. },{"./lib/_stream_writable.js":123}],128:[function(require,module,exports){
  17038. (function (Buffer){
  17039. /*
  17040. CryptoJS v3.1.2
  17041. code.google.com/p/crypto-js
  17042. (c) 2009-2013 by Jeff Mott. All rights reserved.
  17043. code.google.com/p/crypto-js/wiki/License
  17044. */
  17045. /** @preserve
  17046. (c) 2012 by Cédric Mesnil. All rights reserved.
  17047. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  17048. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  17049. - 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.
  17050. 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.
  17051. */
  17052. // constants table
  17053. var zl = [
  17054. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  17055. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  17056. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  17057. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  17058. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
  17059. ]
  17060. var zr = [
  17061. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  17062. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  17063. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  17064. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  17065. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
  17066. ]
  17067. var sl = [
  17068. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  17069. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  17070. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  17071. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  17072. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
  17073. ]
  17074. var sr = [
  17075. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  17076. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  17077. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  17078. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  17079. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
  17080. ]
  17081. var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
  17082. var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
  17083. function bytesToWords (bytes) {
  17084. var words = []
  17085. for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
  17086. words[b >>> 5] |= bytes[i] << (24 - b % 32)
  17087. }
  17088. return words
  17089. }
  17090. function wordsToBytes (words) {
  17091. var bytes = []
  17092. for (var b = 0; b < words.length * 32; b += 8) {
  17093. bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
  17094. }
  17095. return bytes
  17096. }
  17097. function processBlock (H, M, offset) {
  17098. // swap endian
  17099. for (var i = 0; i < 16; i++) {
  17100. var offset_i = offset + i
  17101. var M_offset_i = M[offset_i]
  17102. // Swap
  17103. M[offset_i] = (
  17104. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  17105. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  17106. )
  17107. }
  17108. // Working variables
  17109. var al, bl, cl, dl, el
  17110. var ar, br, cr, dr, er
  17111. ar = al = H[0]
  17112. br = bl = H[1]
  17113. cr = cl = H[2]
  17114. dr = dl = H[3]
  17115. er = el = H[4]
  17116. // computation
  17117. var t
  17118. for (i = 0; i < 80; i += 1) {
  17119. t = (al + M[offset + zl[i]]) | 0
  17120. if (i < 16) {
  17121. t += f1(bl, cl, dl) + hl[0]
  17122. } else if (i < 32) {
  17123. t += f2(bl, cl, dl) + hl[1]
  17124. } else if (i < 48) {
  17125. t += f3(bl, cl, dl) + hl[2]
  17126. } else if (i < 64) {
  17127. t += f4(bl, cl, dl) + hl[3]
  17128. } else {// if (i<80) {
  17129. t += f5(bl, cl, dl) + hl[4]
  17130. }
  17131. t = t | 0
  17132. t = rotl(t, sl[i])
  17133. t = (t + el) | 0
  17134. al = el
  17135. el = dl
  17136. dl = rotl(cl, 10)
  17137. cl = bl
  17138. bl = t
  17139. t = (ar + M[offset + zr[i]]) | 0
  17140. if (i < 16) {
  17141. t += f5(br, cr, dr) + hr[0]
  17142. } else if (i < 32) {
  17143. t += f4(br, cr, dr) + hr[1]
  17144. } else if (i < 48) {
  17145. t += f3(br, cr, dr) + hr[2]
  17146. } else if (i < 64) {
  17147. t += f2(br, cr, dr) + hr[3]
  17148. } else {// if (i<80) {
  17149. t += f1(br, cr, dr) + hr[4]
  17150. }
  17151. t = t | 0
  17152. t = rotl(t, sr[i])
  17153. t = (t + er) | 0
  17154. ar = er
  17155. er = dr
  17156. dr = rotl(cr, 10)
  17157. cr = br
  17158. br = t
  17159. }
  17160. // intermediate hash value
  17161. t = (H[1] + cl + dr) | 0
  17162. H[1] = (H[2] + dl + er) | 0
  17163. H[2] = (H[3] + el + ar) | 0
  17164. H[3] = (H[4] + al + br) | 0
  17165. H[4] = (H[0] + bl + cr) | 0
  17166. H[0] = t
  17167. }
  17168. function f1 (x, y, z) {
  17169. return ((x) ^ (y) ^ (z))
  17170. }
  17171. function f2 (x, y, z) {
  17172. return (((x) & (y)) | ((~x) & (z)))
  17173. }
  17174. function f3 (x, y, z) {
  17175. return (((x) | (~(y))) ^ (z))
  17176. }
  17177. function f4 (x, y, z) {
  17178. return (((x) & (z)) | ((y) & (~(z))))
  17179. }
  17180. function f5 (x, y, z) {
  17181. return ((x) ^ ((y) | (~(z))))
  17182. }
  17183. function rotl (x, n) {
  17184. return (x << n) | (x >>> (32 - n))
  17185. }
  17186. function ripemd160 (message) {
  17187. var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
  17188. if (typeof message === 'string') {
  17189. message = new Buffer(message, 'utf8')
  17190. }
  17191. var m = bytesToWords(message)
  17192. var nBitsLeft = message.length * 8
  17193. var nBitsTotal = message.length * 8
  17194. // Add padding
  17195. m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
  17196. m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  17197. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
  17198. (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
  17199. )
  17200. for (var i = 0; i < m.length; i += 16) {
  17201. processBlock(H, m, i)
  17202. }
  17203. // swap endian
  17204. for (i = 0; i < 5; i++) {
  17205. // shortcut
  17206. var H_i = H[i]
  17207. // Swap
  17208. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  17209. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
  17210. }
  17211. var digestbytes = wordsToBytes(H)
  17212. return new Buffer(digestbytes)
  17213. }
  17214. module.exports = ripemd160
  17215. }).call(this,require("buffer").Buffer)
  17216. },{"buffer":46}],129:[function(require,module,exports){
  17217. (function (Buffer){
  17218. // prototype class for hash functions
  17219. function Hash (blockSize, finalSize) {
  17220. this._block = new Buffer(blockSize)
  17221. this._finalSize = finalSize
  17222. this._blockSize = blockSize
  17223. this._len = 0
  17224. this._s = 0
  17225. }
  17226. Hash.prototype.update = function (data, enc) {
  17227. if (typeof data === 'string') {
  17228. enc = enc || 'utf8'
  17229. data = new Buffer(data, enc)
  17230. }
  17231. var l = this._len += data.length
  17232. var s = this._s || 0
  17233. var f = 0
  17234. var buffer = this._block
  17235. while (s < l) {
  17236. var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
  17237. var ch = (t - f)
  17238. for (var i = 0; i < ch; i++) {
  17239. buffer[(s % this._blockSize) + i] = data[i + f]
  17240. }
  17241. s += ch
  17242. f += ch
  17243. if ((s % this._blockSize) === 0) {
  17244. this._update(buffer)
  17245. }
  17246. }
  17247. this._s = s
  17248. return this
  17249. }
  17250. Hash.prototype.digest = function (enc) {
  17251. // Suppose the length of the message M, in bits, is l
  17252. var l = this._len * 8
  17253. // Append the bit 1 to the end of the message
  17254. this._block[this._len % this._blockSize] = 0x80
  17255. // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
  17256. this._block.fill(0, this._len % this._blockSize + 1)
  17257. if (l % (this._blockSize * 8) >= this._finalSize * 8) {
  17258. this._update(this._block)
  17259. this._block.fill(0)
  17260. }
  17261. // to this append the block which is equal to the number l written in binary
  17262. // TODO: handle case where l is > Math.pow(2, 29)
  17263. this._block.writeInt32BE(l, this._blockSize - 4)
  17264. var hash = this._update(this._block) || this._hash()
  17265. return enc ? hash.toString(enc) : hash
  17266. }
  17267. Hash.prototype._update = function () {
  17268. throw new Error('_update must be implemented by subclass')
  17269. }
  17270. module.exports = Hash
  17271. }).call(this,require("buffer").Buffer)
  17272. },{"buffer":46}],130:[function(require,module,exports){
  17273. var exports = module.exports = function SHA (algorithm) {
  17274. algorithm = algorithm.toLowerCase()
  17275. var Algorithm = exports[algorithm]
  17276. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
  17277. return new Algorithm()
  17278. }
  17279. exports.sha = require('./sha')
  17280. exports.sha1 = require('./sha1')
  17281. exports.sha224 = require('./sha224')
  17282. exports.sha256 = require('./sha256')
  17283. exports.sha384 = require('./sha384')
  17284. exports.sha512 = require('./sha512')
  17285. },{"./sha":131,"./sha1":132,"./sha224":133,"./sha256":134,"./sha384":135,"./sha512":136}],131:[function(require,module,exports){
  17286. (function (Buffer){
  17287. /*
  17288. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  17289. * in FIPS PUB 180-1
  17290. * This source code is derived from sha1.js of the same repository.
  17291. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  17292. * operation was added.
  17293. */
  17294. var inherits = require('inherits')
  17295. var Hash = require('./hash')
  17296. var K = [
  17297. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  17298. ]
  17299. var W = new Array(80)
  17300. function Sha () {
  17301. this.init()
  17302. this._w = W
  17303. Hash.call(this, 64, 56)
  17304. }
  17305. inherits(Sha, Hash)
  17306. Sha.prototype.init = function () {
  17307. this._a = 0x67452301
  17308. this._b = 0xefcdab89
  17309. this._c = 0x98badcfe
  17310. this._d = 0x10325476
  17311. this._e = 0xc3d2e1f0
  17312. return this
  17313. }
  17314. function rotl5 (num) {
  17315. return (num << 5) | (num >>> 27)
  17316. }
  17317. function rotl30 (num) {
  17318. return (num << 30) | (num >>> 2)
  17319. }
  17320. function ft (s, b, c, d) {
  17321. if (s === 0) return (b & c) | ((~b) & d)
  17322. if (s === 2) return (b & c) | (b & d) | (c & d)
  17323. return b ^ c ^ d
  17324. }
  17325. Sha.prototype._update = function (M) {
  17326. var W = this._w
  17327. var a = this._a | 0
  17328. var b = this._b | 0
  17329. var c = this._c | 0
  17330. var d = this._d | 0
  17331. var e = this._e | 0
  17332. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17333. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
  17334. for (var j = 0; j < 80; ++j) {
  17335. var s = ~~(j / 20)
  17336. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  17337. e = d
  17338. d = c
  17339. c = rotl30(b)
  17340. b = a
  17341. a = t
  17342. }
  17343. this._a = (a + this._a) | 0
  17344. this._b = (b + this._b) | 0
  17345. this._c = (c + this._c) | 0
  17346. this._d = (d + this._d) | 0
  17347. this._e = (e + this._e) | 0
  17348. }
  17349. Sha.prototype._hash = function () {
  17350. var H = new Buffer(20)
  17351. H.writeInt32BE(this._a | 0, 0)
  17352. H.writeInt32BE(this._b | 0, 4)
  17353. H.writeInt32BE(this._c | 0, 8)
  17354. H.writeInt32BE(this._d | 0, 12)
  17355. H.writeInt32BE(this._e | 0, 16)
  17356. return H
  17357. }
  17358. module.exports = Sha
  17359. }).call(this,require("buffer").Buffer)
  17360. },{"./hash":129,"buffer":46,"inherits":92}],132:[function(require,module,exports){
  17361. (function (Buffer){
  17362. /*
  17363. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  17364. * in FIPS PUB 180-1
  17365. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  17366. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17367. * Distributed under the BSD License
  17368. * See http://pajhome.org.uk/crypt/md5 for details.
  17369. */
  17370. var inherits = require('inherits')
  17371. var Hash = require('./hash')
  17372. var K = [
  17373. 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
  17374. ]
  17375. var W = new Array(80)
  17376. function Sha1 () {
  17377. this.init()
  17378. this._w = W
  17379. Hash.call(this, 64, 56)
  17380. }
  17381. inherits(Sha1, Hash)
  17382. Sha1.prototype.init = function () {
  17383. this._a = 0x67452301
  17384. this._b = 0xefcdab89
  17385. this._c = 0x98badcfe
  17386. this._d = 0x10325476
  17387. this._e = 0xc3d2e1f0
  17388. return this
  17389. }
  17390. function rotl1 (num) {
  17391. return (num << 1) | (num >>> 31)
  17392. }
  17393. function rotl5 (num) {
  17394. return (num << 5) | (num >>> 27)
  17395. }
  17396. function rotl30 (num) {
  17397. return (num << 30) | (num >>> 2)
  17398. }
  17399. function ft (s, b, c, d) {
  17400. if (s === 0) return (b & c) | ((~b) & d)
  17401. if (s === 2) return (b & c) | (b & d) | (c & d)
  17402. return b ^ c ^ d
  17403. }
  17404. Sha1.prototype._update = function (M) {
  17405. var W = this._w
  17406. var a = this._a | 0
  17407. var b = this._b | 0
  17408. var c = this._c | 0
  17409. var d = this._d | 0
  17410. var e = this._e | 0
  17411. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17412. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
  17413. for (var j = 0; j < 80; ++j) {
  17414. var s = ~~(j / 20)
  17415. var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
  17416. e = d
  17417. d = c
  17418. c = rotl30(b)
  17419. b = a
  17420. a = t
  17421. }
  17422. this._a = (a + this._a) | 0
  17423. this._b = (b + this._b) | 0
  17424. this._c = (c + this._c) | 0
  17425. this._d = (d + this._d) | 0
  17426. this._e = (e + this._e) | 0
  17427. }
  17428. Sha1.prototype._hash = function () {
  17429. var H = new Buffer(20)
  17430. H.writeInt32BE(this._a | 0, 0)
  17431. H.writeInt32BE(this._b | 0, 4)
  17432. H.writeInt32BE(this._c | 0, 8)
  17433. H.writeInt32BE(this._d | 0, 12)
  17434. H.writeInt32BE(this._e | 0, 16)
  17435. return H
  17436. }
  17437. module.exports = Sha1
  17438. }).call(this,require("buffer").Buffer)
  17439. },{"./hash":129,"buffer":46,"inherits":92}],133:[function(require,module,exports){
  17440. (function (Buffer){
  17441. /**
  17442. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  17443. * in FIPS 180-2
  17444. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  17445. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17446. *
  17447. */
  17448. var inherits = require('inherits')
  17449. var Sha256 = require('./sha256')
  17450. var Hash = require('./hash')
  17451. var W = new Array(64)
  17452. function Sha224 () {
  17453. this.init()
  17454. this._w = W // new Array(64)
  17455. Hash.call(this, 64, 56)
  17456. }
  17457. inherits(Sha224, Sha256)
  17458. Sha224.prototype.init = function () {
  17459. this._a = 0xc1059ed8
  17460. this._b = 0x367cd507
  17461. this._c = 0x3070dd17
  17462. this._d = 0xf70e5939
  17463. this._e = 0xffc00b31
  17464. this._f = 0x68581511
  17465. this._g = 0x64f98fa7
  17466. this._h = 0xbefa4fa4
  17467. return this
  17468. }
  17469. Sha224.prototype._hash = function () {
  17470. var H = new Buffer(28)
  17471. H.writeInt32BE(this._a, 0)
  17472. H.writeInt32BE(this._b, 4)
  17473. H.writeInt32BE(this._c, 8)
  17474. H.writeInt32BE(this._d, 12)
  17475. H.writeInt32BE(this._e, 16)
  17476. H.writeInt32BE(this._f, 20)
  17477. H.writeInt32BE(this._g, 24)
  17478. return H
  17479. }
  17480. module.exports = Sha224
  17481. }).call(this,require("buffer").Buffer)
  17482. },{"./hash":129,"./sha256":134,"buffer":46,"inherits":92}],134:[function(require,module,exports){
  17483. (function (Buffer){
  17484. /**
  17485. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  17486. * in FIPS 180-2
  17487. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  17488. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  17489. *
  17490. */
  17491. var inherits = require('inherits')
  17492. var Hash = require('./hash')
  17493. var K = [
  17494. 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
  17495. 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
  17496. 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
  17497. 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
  17498. 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
  17499. 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
  17500. 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
  17501. 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
  17502. 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
  17503. 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
  17504. 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
  17505. 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
  17506. 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
  17507. 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
  17508. 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
  17509. 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
  17510. ]
  17511. var W = new Array(64)
  17512. function Sha256 () {
  17513. this.init()
  17514. this._w = W // new Array(64)
  17515. Hash.call(this, 64, 56)
  17516. }
  17517. inherits(Sha256, Hash)
  17518. Sha256.prototype.init = function () {
  17519. this._a = 0x6a09e667
  17520. this._b = 0xbb67ae85
  17521. this._c = 0x3c6ef372
  17522. this._d = 0xa54ff53a
  17523. this._e = 0x510e527f
  17524. this._f = 0x9b05688c
  17525. this._g = 0x1f83d9ab
  17526. this._h = 0x5be0cd19
  17527. return this
  17528. }
  17529. function ch (x, y, z) {
  17530. return z ^ (x & (y ^ z))
  17531. }
  17532. function maj (x, y, z) {
  17533. return (x & y) | (z & (x | y))
  17534. }
  17535. function sigma0 (x) {
  17536. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
  17537. }
  17538. function sigma1 (x) {
  17539. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
  17540. }
  17541. function gamma0 (x) {
  17542. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
  17543. }
  17544. function gamma1 (x) {
  17545. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
  17546. }
  17547. Sha256.prototype._update = function (M) {
  17548. var W = this._w
  17549. var a = this._a | 0
  17550. var b = this._b | 0
  17551. var c = this._c | 0
  17552. var d = this._d | 0
  17553. var e = this._e | 0
  17554. var f = this._f | 0
  17555. var g = this._g | 0
  17556. var h = this._h | 0
  17557. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
  17558. for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
  17559. for (var j = 0; j < 64; ++j) {
  17560. var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
  17561. var T2 = (sigma0(a) + maj(a, b, c)) | 0
  17562. h = g
  17563. g = f
  17564. f = e
  17565. e = (d + T1) | 0
  17566. d = c
  17567. c = b
  17568. b = a
  17569. a = (T1 + T2) | 0
  17570. }
  17571. this._a = (a + this._a) | 0
  17572. this._b = (b + this._b) | 0
  17573. this._c = (c + this._c) | 0
  17574. this._d = (d + this._d) | 0
  17575. this._e = (e + this._e) | 0
  17576. this._f = (f + this._f) | 0
  17577. this._g = (g + this._g) | 0
  17578. this._h = (h + this._h) | 0
  17579. }
  17580. Sha256.prototype._hash = function () {
  17581. var H = new Buffer(32)
  17582. H.writeInt32BE(this._a, 0)
  17583. H.writeInt32BE(this._b, 4)
  17584. H.writeInt32BE(this._c, 8)
  17585. H.writeInt32BE(this._d, 12)
  17586. H.writeInt32BE(this._e, 16)
  17587. H.writeInt32BE(this._f, 20)
  17588. H.writeInt32BE(this._g, 24)
  17589. H.writeInt32BE(this._h, 28)
  17590. return H
  17591. }
  17592. module.exports = Sha256
  17593. }).call(this,require("buffer").Buffer)
  17594. },{"./hash":129,"buffer":46,"inherits":92}],135:[function(require,module,exports){
  17595. (function (Buffer){
  17596. var inherits = require('inherits')
  17597. var SHA512 = require('./sha512')
  17598. var Hash = require('./hash')
  17599. var W = new Array(160)
  17600. function Sha384 () {
  17601. this.init()
  17602. this._w = W
  17603. Hash.call(this, 128, 112)
  17604. }
  17605. inherits(Sha384, SHA512)
  17606. Sha384.prototype.init = function () {
  17607. this._ah = 0xcbbb9d5d
  17608. this._bh = 0x629a292a
  17609. this._ch = 0x9159015a
  17610. this._dh = 0x152fecd8
  17611. this._eh = 0x67332667
  17612. this._fh = 0x8eb44a87
  17613. this._gh = 0xdb0c2e0d
  17614. this._hh = 0x47b5481d
  17615. this._al = 0xc1059ed8
  17616. this._bl = 0x367cd507
  17617. this._cl = 0x3070dd17
  17618. this._dl = 0xf70e5939
  17619. this._el = 0xffc00b31
  17620. this._fl = 0x68581511
  17621. this._gl = 0x64f98fa7
  17622. this._hl = 0xbefa4fa4
  17623. return this
  17624. }
  17625. Sha384.prototype._hash = function () {
  17626. var H = new Buffer(48)
  17627. function writeInt64BE (h, l, offset) {
  17628. H.writeInt32BE(h, offset)
  17629. H.writeInt32BE(l, offset + 4)
  17630. }
  17631. writeInt64BE(this._ah, this._al, 0)
  17632. writeInt64BE(this._bh, this._bl, 8)
  17633. writeInt64BE(this._ch, this._cl, 16)
  17634. writeInt64BE(this._dh, this._dl, 24)
  17635. writeInt64BE(this._eh, this._el, 32)
  17636. writeInt64BE(this._fh, this._fl, 40)
  17637. return H
  17638. }
  17639. module.exports = Sha384
  17640. }).call(this,require("buffer").Buffer)
  17641. },{"./hash":129,"./sha512":136,"buffer":46,"inherits":92}],136:[function(require,module,exports){
  17642. (function (Buffer){
  17643. var inherits = require('inherits')
  17644. var Hash = require('./hash')
  17645. var K = [
  17646. 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
  17647. 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
  17648. 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
  17649. 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
  17650. 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
  17651. 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
  17652. 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
  17653. 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
  17654. 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
  17655. 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
  17656. 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
  17657. 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
  17658. 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
  17659. 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
  17660. 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
  17661. 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
  17662. 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
  17663. 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
  17664. 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
  17665. 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
  17666. 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
  17667. 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
  17668. 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
  17669. 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
  17670. 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
  17671. 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
  17672. 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
  17673. 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
  17674. 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
  17675. 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
  17676. 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
  17677. 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
  17678. 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
  17679. 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
  17680. 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
  17681. 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
  17682. 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
  17683. 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
  17684. 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
  17685. 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
  17686. ]
  17687. var W = new Array(160)
  17688. function Sha512 () {
  17689. this.init()
  17690. this._w = W
  17691. Hash.call(this, 128, 112)
  17692. }
  17693. inherits(Sha512, Hash)
  17694. Sha512.prototype.init = function () {
  17695. this._ah = 0x6a09e667
  17696. this._bh = 0xbb67ae85
  17697. this._ch = 0x3c6ef372
  17698. this._dh = 0xa54ff53a
  17699. this._eh = 0x510e527f
  17700. this._fh = 0x9b05688c
  17701. this._gh = 0x1f83d9ab
  17702. this._hh = 0x5be0cd19
  17703. this._al = 0xf3bcc908
  17704. this._bl = 0x84caa73b
  17705. this._cl = 0xfe94f82b
  17706. this._dl = 0x5f1d36f1
  17707. this._el = 0xade682d1
  17708. this._fl = 0x2b3e6c1f
  17709. this._gl = 0xfb41bd6b
  17710. this._hl = 0x137e2179
  17711. return this
  17712. }
  17713. function Ch (x, y, z) {
  17714. return z ^ (x & (y ^ z))
  17715. }
  17716. function maj (x, y, z) {
  17717. return (x & y) | (z & (x | y))
  17718. }
  17719. function sigma0 (x, xl) {
  17720. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
  17721. }
  17722. function sigma1 (x, xl) {
  17723. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
  17724. }
  17725. function Gamma0 (x, xl) {
  17726. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
  17727. }
  17728. function Gamma0l (x, xl) {
  17729. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
  17730. }
  17731. function Gamma1 (x, xl) {
  17732. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
  17733. }
  17734. function Gamma1l (x, xl) {
  17735. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
  17736. }
  17737. function getCarry (a, b) {
  17738. return (a >>> 0) < (b >>> 0) ? 1 : 0
  17739. }
  17740. Sha512.prototype._update = function (M) {
  17741. var W = this._w
  17742. var ah = this._ah | 0
  17743. var bh = this._bh | 0
  17744. var ch = this._ch | 0
  17745. var dh = this._dh | 0
  17746. var eh = this._eh | 0
  17747. var fh = this._fh | 0
  17748. var gh = this._gh | 0
  17749. var hh = this._hh | 0
  17750. var al = this._al | 0
  17751. var bl = this._bl | 0
  17752. var cl = this._cl | 0
  17753. var dl = this._dl | 0
  17754. var el = this._el | 0
  17755. var fl = this._fl | 0
  17756. var gl = this._gl | 0
  17757. var hl = this._hl | 0
  17758. for (var i = 0; i < 32; i += 2) {
  17759. W[i] = M.readInt32BE(i * 4)
  17760. W[i + 1] = M.readInt32BE(i * 4 + 4)
  17761. }
  17762. for (; i < 160; i += 2) {
  17763. var xh = W[i - 15 * 2]
  17764. var xl = W[i - 15 * 2 + 1]
  17765. var gamma0 = Gamma0(xh, xl)
  17766. var gamma0l = Gamma0l(xl, xh)
  17767. xh = W[i - 2 * 2]
  17768. xl = W[i - 2 * 2 + 1]
  17769. var gamma1 = Gamma1(xh, xl)
  17770. var gamma1l = Gamma1l(xl, xh)
  17771. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  17772. var Wi7h = W[i - 7 * 2]
  17773. var Wi7l = W[i - 7 * 2 + 1]
  17774. var Wi16h = W[i - 16 * 2]
  17775. var Wi16l = W[i - 16 * 2 + 1]
  17776. var Wil = (gamma0l + Wi7l) | 0
  17777. var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
  17778. Wil = (Wil + gamma1l) | 0
  17779. Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
  17780. Wil = (Wil + Wi16l) | 0
  17781. Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
  17782. W[i] = Wih
  17783. W[i + 1] = Wil
  17784. }
  17785. for (var j = 0; j < 160; j += 2) {
  17786. Wih = W[j]
  17787. Wil = W[j + 1]
  17788. var majh = maj(ah, bh, ch)
  17789. var majl = maj(al, bl, cl)
  17790. var sigma0h = sigma0(ah, al)
  17791. var sigma0l = sigma0(al, ah)
  17792. var sigma1h = sigma1(eh, el)
  17793. var sigma1l = sigma1(el, eh)
  17794. // t1 = h + sigma1 + ch + K[j] + W[j]
  17795. var Kih = K[j]
  17796. var Kil = K[j + 1]
  17797. var chh = Ch(eh, fh, gh)
  17798. var chl = Ch(el, fl, gl)
  17799. var t1l = (hl + sigma1l) | 0
  17800. var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
  17801. t1l = (t1l + chl) | 0
  17802. t1h = (t1h + chh + getCarry(t1l, chl)) | 0
  17803. t1l = (t1l + Kil) | 0
  17804. t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
  17805. t1l = (t1l + Wil) | 0
  17806. t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
  17807. // t2 = sigma0 + maj
  17808. var t2l = (sigma0l + majl) | 0
  17809. var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
  17810. hh = gh
  17811. hl = gl
  17812. gh = fh
  17813. gl = fl
  17814. fh = eh
  17815. fl = el
  17816. el = (dl + t1l) | 0
  17817. eh = (dh + t1h + getCarry(el, dl)) | 0
  17818. dh = ch
  17819. dl = cl
  17820. ch = bh
  17821. cl = bl
  17822. bh = ah
  17823. bl = al
  17824. al = (t1l + t2l) | 0
  17825. ah = (t1h + t2h + getCarry(al, t1l)) | 0
  17826. }
  17827. this._al = (this._al + al) | 0
  17828. this._bl = (this._bl + bl) | 0
  17829. this._cl = (this._cl + cl) | 0
  17830. this._dl = (this._dl + dl) | 0
  17831. this._el = (this._el + el) | 0
  17832. this._fl = (this._fl + fl) | 0
  17833. this._gl = (this._gl + gl) | 0
  17834. this._hl = (this._hl + hl) | 0
  17835. this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
  17836. this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
  17837. this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
  17838. this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
  17839. this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
  17840. this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
  17841. this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
  17842. this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
  17843. }
  17844. Sha512.prototype._hash = function () {
  17845. var H = new Buffer(64)
  17846. function writeInt64BE (h, l, offset) {
  17847. H.writeInt32BE(h, offset)
  17848. H.writeInt32BE(l, offset + 4)
  17849. }
  17850. writeInt64BE(this._ah, this._al, 0)
  17851. writeInt64BE(this._bh, this._bl, 8)
  17852. writeInt64BE(this._ch, this._cl, 16)
  17853. writeInt64BE(this._dh, this._dl, 24)
  17854. writeInt64BE(this._eh, this._el, 32)
  17855. writeInt64BE(this._fh, this._fl, 40)
  17856. writeInt64BE(this._gh, this._gl, 48)
  17857. writeInt64BE(this._hh, this._hl, 56)
  17858. return H
  17859. }
  17860. module.exports = Sha512
  17861. }).call(this,require("buffer").Buffer)
  17862. },{"./hash":129,"buffer":46,"inherits":92}],137:[function(require,module,exports){
  17863. // Copyright Joyent, Inc. and other Node contributors.
  17864. //
  17865. // Permission is hereby granted, free of charge, to any person obtaining a
  17866. // copy of this software and associated documentation files (the
  17867. // "Software"), to deal in the Software without restriction, including
  17868. // without limitation the rights to use, copy, modify, merge, publish,
  17869. // distribute, sublicense, and/or sell copies of the Software, and to permit
  17870. // persons to whom the Software is furnished to do so, subject to the
  17871. // following conditions:
  17872. //
  17873. // The above copyright notice and this permission notice shall be included
  17874. // in all copies or substantial portions of the Software.
  17875. //
  17876. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17877. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17878. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17879. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17880. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17881. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  17882. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  17883. module.exports = Stream;
  17884. var EE = require('events').EventEmitter;
  17885. var inherits = require('inherits');
  17886. inherits(Stream, EE);
  17887. Stream.Readable = require('readable-stream/readable.js');
  17888. Stream.Writable = require('readable-stream/writable.js');
  17889. Stream.Duplex = require('readable-stream/duplex.js');
  17890. Stream.Transform = require('readable-stream/transform.js');
  17891. Stream.PassThrough = require('readable-stream/passthrough.js');
  17892. // Backwards-compat with node 0.4.x
  17893. Stream.Stream = Stream;
  17894. // old-style streams. Note that the pipe method (the only relevant
  17895. // part of this class) is overridden in the Readable class.
  17896. function Stream() {
  17897. EE.call(this);
  17898. }
  17899. Stream.prototype.pipe = function(dest, options) {
  17900. var source = this;
  17901. function ondata(chunk) {
  17902. if (dest.writable) {
  17903. if (false === dest.write(chunk) && source.pause) {
  17904. source.pause();
  17905. }
  17906. }
  17907. }
  17908. source.on('data', ondata);
  17909. function ondrain() {
  17910. if (source.readable && source.resume) {
  17911. source.resume();
  17912. }
  17913. }
  17914. dest.on('drain', ondrain);
  17915. // If the 'end' option is not supplied, dest.end() will be called when
  17916. // source gets the 'end' or 'close' events. Only dest.end() once.
  17917. if (!dest._isStdio && (!options || options.end !== false)) {
  17918. source.on('end', onend);
  17919. source.on('close', onclose);
  17920. }
  17921. var didOnEnd = false;
  17922. function onend() {
  17923. if (didOnEnd) return;
  17924. didOnEnd = true;
  17925. dest.end();
  17926. }
  17927. function onclose() {
  17928. if (didOnEnd) return;
  17929. didOnEnd = true;
  17930. if (typeof dest.destroy === 'function') dest.destroy();
  17931. }
  17932. // don't leave dangling pipes when there are errors.
  17933. function onerror(er) {
  17934. cleanup();
  17935. if (EE.listenerCount(this, 'error') === 0) {
  17936. throw er; // Unhandled stream error in pipe.
  17937. }
  17938. }
  17939. source.on('error', onerror);
  17940. dest.on('error', onerror);
  17941. // remove all the event listeners that were added.
  17942. function cleanup() {
  17943. source.removeListener('data', ondata);
  17944. dest.removeListener('drain', ondrain);
  17945. source.removeListener('end', onend);
  17946. source.removeListener('close', onclose);
  17947. source.removeListener('error', onerror);
  17948. dest.removeListener('error', onerror);
  17949. source.removeListener('end', cleanup);
  17950. source.removeListener('close', cleanup);
  17951. dest.removeListener('close', cleanup);
  17952. }
  17953. source.on('end', cleanup);
  17954. source.on('close', cleanup);
  17955. dest.on('close', cleanup);
  17956. dest.emit('pipe', source);
  17957. // Allow for unix-like usage: A.pipe(B).pipe(C)
  17958. return dest;
  17959. };
  17960. },{"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){
  17961. // Copyright Joyent, Inc. and other Node contributors.
  17962. //
  17963. // Permission is hereby granted, free of charge, to any person obtaining a
  17964. // copy of this software and associated documentation files (the
  17965. // "Software"), to deal in the Software without restriction, including
  17966. // without limitation the rights to use, copy, modify, merge, publish,
  17967. // distribute, sublicense, and/or sell copies of the Software, and to permit
  17968. // persons to whom the Software is furnished to do so, subject to the
  17969. // following conditions:
  17970. //
  17971. // The above copyright notice and this permission notice shall be included
  17972. // in all copies or substantial portions of the Software.
  17973. //
  17974. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17975. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17976. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17977. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17978. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17979. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  17980. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  17981. var Buffer = require('buffer').Buffer;
  17982. var isBufferEncoding = Buffer.isEncoding
  17983. || function(encoding) {
  17984. switch (encoding && encoding.toLowerCase()) {
  17985. 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;
  17986. default: return false;
  17987. }
  17988. }
  17989. function assertEncoding(encoding) {
  17990. if (encoding && !isBufferEncoding(encoding)) {
  17991. throw new Error('Unknown encoding: ' + encoding);
  17992. }
  17993. }
  17994. // StringDecoder provides an interface for efficiently splitting a series of
  17995. // buffers into a series of JS strings without breaking apart multi-byte
  17996. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  17997. //
  17998. // @TODO Handling all encodings inside a single object makes it very difficult
  17999. // to reason about this code, so it should be split up in the future.
  18000. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  18001. // points as used by CESU-8.
  18002. var StringDecoder = exports.StringDecoder = function(encoding) {
  18003. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  18004. assertEncoding(encoding);
  18005. switch (this.encoding) {
  18006. case 'utf8':
  18007. // CESU-8 represents each of Surrogate Pair by 3-bytes
  18008. this.surrogateSize = 3;
  18009. break;
  18010. case 'ucs2':
  18011. case 'utf16le':
  18012. // UTF-16 represents each of Surrogate Pair by 2-bytes
  18013. this.surrogateSize = 2;
  18014. this.detectIncompleteChar = utf16DetectIncompleteChar;
  18015. break;
  18016. case 'base64':
  18017. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  18018. this.surrogateSize = 3;
  18019. this.detectIncompleteChar = base64DetectIncompleteChar;
  18020. break;
  18021. default:
  18022. this.write = passThroughWrite;
  18023. return;
  18024. }
  18025. // Enough space to store all bytes of a single character. UTF-8 needs 4
  18026. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  18027. this.charBuffer = new Buffer(6);
  18028. // Number of bytes received for the current incomplete multi-byte character.
  18029. this.charReceived = 0;
  18030. // Number of bytes expected for the current incomplete multi-byte character.
  18031. this.charLength = 0;
  18032. };
  18033. // write decodes the given buffer and returns it as JS string that is
  18034. // guaranteed to not contain any partial multi-byte characters. Any partial
  18035. // character found at the end of the buffer is buffered up, and will be
  18036. // returned when calling write again with the remaining bytes.
  18037. //
  18038. // Note: Converting a Buffer containing an orphan surrogate to a String
  18039. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  18040. // Buffer#write) will replace incomplete surrogates with the unicode
  18041. // replacement character. See https://codereview.chromium.org/121173009/ .
  18042. StringDecoder.prototype.write = function(buffer) {
  18043. var charStr = '';
  18044. // if our last write ended with an incomplete multibyte character
  18045. while (this.charLength) {
  18046. // determine how many remaining bytes this buffer has to offer for this char
  18047. var available = (buffer.length >= this.charLength - this.charReceived) ?
  18048. this.charLength - this.charReceived :
  18049. buffer.length;
  18050. // add the new bytes to the char buffer
  18051. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  18052. this.charReceived += available;
  18053. if (this.charReceived < this.charLength) {
  18054. // still not enough chars in this buffer? wait for more ...
  18055. return '';
  18056. }
  18057. // remove bytes belonging to the current character from the buffer
  18058. buffer = buffer.slice(available, buffer.length);
  18059. // get the character that was split
  18060. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  18061. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  18062. var charCode = charStr.charCodeAt(charStr.length - 1);
  18063. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  18064. this.charLength += this.surrogateSize;
  18065. charStr = '';
  18066. continue;
  18067. }
  18068. this.charReceived = this.charLength = 0;
  18069. // if there are no more bytes in this buffer, just emit our char
  18070. if (buffer.length === 0) {
  18071. return charStr;
  18072. }
  18073. break;
  18074. }
  18075. // determine and set charLength / charReceived
  18076. this.detectIncompleteChar(buffer);
  18077. var end = buffer.length;
  18078. if (this.charLength) {
  18079. // buffer the incomplete character bytes we got
  18080. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  18081. end -= this.charReceived;
  18082. }
  18083. charStr += buffer.toString(this.encoding, 0, end);
  18084. var end = charStr.length - 1;
  18085. var charCode = charStr.charCodeAt(end);
  18086. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  18087. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  18088. var size = this.surrogateSize;
  18089. this.charLength += size;
  18090. this.charReceived += size;
  18091. this.charBuffer.copy(this.charBuffer, size, 0, size);
  18092. buffer.copy(this.charBuffer, 0, 0, size);
  18093. return charStr.substring(0, end);
  18094. }
  18095. // or just emit the charStr
  18096. return charStr;
  18097. };
  18098. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  18099. // the end of the given buffer. If so, it sets this.charLength to the byte
  18100. // length that character, and sets this.charReceived to the number of bytes
  18101. // that are available for this character.
  18102. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  18103. // determine how many bytes we have to check at the end of this buffer
  18104. var i = (buffer.length >= 3) ? 3 : buffer.length;
  18105. // Figure out if one of the last i bytes of our buffer announces an
  18106. // incomplete char.
  18107. for (; i > 0; i--) {
  18108. var c = buffer[buffer.length - i];
  18109. // See http://en.wikipedia.org/wiki/UTF-8#Description
  18110. // 110XXXXX
  18111. if (i == 1 && c >> 5 == 0x06) {
  18112. this.charLength = 2;
  18113. break;
  18114. }
  18115. // 1110XXXX
  18116. if (i <= 2 && c >> 4 == 0x0E) {
  18117. this.charLength = 3;
  18118. break;
  18119. }
  18120. // 11110XXX
  18121. if (i <= 3 && c >> 3 == 0x1E) {
  18122. this.charLength = 4;
  18123. break;
  18124. }
  18125. }
  18126. this.charReceived = i;
  18127. };
  18128. StringDecoder.prototype.end = function(buffer) {
  18129. var res = '';
  18130. if (buffer && buffer.length)
  18131. res = this.write(buffer);
  18132. if (this.charReceived) {
  18133. var cr = this.charReceived;
  18134. var buf = this.charBuffer;
  18135. var enc = this.encoding;
  18136. res += buf.slice(0, cr).toString(enc);
  18137. }
  18138. return res;
  18139. };
  18140. function passThroughWrite(buffer) {
  18141. return buffer.toString(this.encoding);
  18142. }
  18143. function utf16DetectIncompleteChar(buffer) {
  18144. this.charReceived = buffer.length % 2;
  18145. this.charLength = this.charReceived ? 2 : 0;
  18146. }
  18147. function base64DetectIncompleteChar(buffer) {
  18148. this.charReceived = buffer.length % 3;
  18149. this.charLength = this.charReceived ? 3 : 0;
  18150. }
  18151. },{"buffer":46}],139:[function(require,module,exports){
  18152. "use strict";
  18153. var tld = require('./lib/tld.js').init();
  18154. tld.rules = require('./rules.json');
  18155. module.exports = tld;
  18156. },{"./lib/tld.js":141,"./rules.json":142}],140:[function(require,module,exports){
  18157. "use strict";
  18158. function Rule (data){
  18159. data = data || {};
  18160. this.exception = data.exception || false;
  18161. this.firstLevel = data.firstLevel || '';
  18162. this.secondLevel = data.secondLevel || null;
  18163. this.isHost = data.isHost || false;
  18164. this.source = data.source || '';
  18165. this.wildcard = data.wildcard || false;
  18166. }
  18167. /**
  18168. * Returns the TLD or SLD (Second Level Domain) pattern for a rule
  18169. *
  18170. * @return {String}
  18171. */
  18172. Rule.prototype.getNormalXld = function getNormalXld(){
  18173. return (this.secondLevel ? '.' + this.secondLevel : '') + '.' + this.firstLevel;
  18174. };
  18175. /**
  18176. * Returns a pattern suitable for normal rule
  18177. * Mostly for internal use
  18178. *
  18179. * @return {String}
  18180. */
  18181. Rule.prototype.getNormalPattern = function getNormalPattern(){
  18182. return (this.secondLevel ? '\\.' + this.secondLevel : '') + '\\.' + this.firstLevel;
  18183. };
  18184. /**
  18185. * Returns a pattern suitable for wildcard rule
  18186. * Mostly for internal use
  18187. *
  18188. * @return {String}
  18189. */
  18190. Rule.prototype.getWildcardPattern = function getWildcardPattern(){
  18191. return '\\.[^\\.]+' + this.getNormalXld().replace(/\./g, '\\.');
  18192. };
  18193. /**
  18194. * Returns a pattern suitable for exception rule
  18195. * Mostly for internal use
  18196. *
  18197. * @return {String}
  18198. */
  18199. Rule.prototype.getExceptionPattern = function getExceptionPattern(){
  18200. return (this.secondLevel || '') + '\\.' + this.firstLevel;
  18201. };
  18202. /**
  18203. * Returns the best pattern possible for a rule
  18204. * You just have to test a value against it to check or extract a hostname
  18205. *
  18206. * @api
  18207. * @param {string|undefined} before
  18208. * @param {string|undefined} after
  18209. * @return {String} A pattern to challenge some string against
  18210. */
  18211. Rule.prototype.getPattern = function getPattern(before, after){
  18212. var pattern = '';
  18213. before = (before === undefined) ? '(': before+'';
  18214. after = (after === undefined) ? ')$': after+'';
  18215. if (this.exception === true){
  18216. pattern = this.getExceptionPattern();
  18217. }
  18218. else if (this.isHost === true) {
  18219. pattern = this.firstLevel;
  18220. }
  18221. else{
  18222. pattern = '[^\\.]+' + (this.wildcard ? this.getWildcardPattern() : this.getNormalPattern());
  18223. }
  18224. return before + pattern + after;
  18225. };
  18226. module.exports = Rule;
  18227. },{}],141:[function(require,module,exports){
  18228. "use strict";
  18229. var Rule = require('./rule.js');
  18230. var URL = require('url');
  18231. /**
  18232. * tld library
  18233. *
  18234. * Useable methods are those documented with an @api in JSDoc
  18235. * See README.md for more explanations on how to use this stuff.
  18236. */
  18237. function tld () {
  18238. /* jshint validthis: true */
  18239. this.validHosts = [];
  18240. this.rules = [];
  18241. }
  18242. tld.init = function init () {
  18243. return new tld();
  18244. };
  18245. function trim(value) {
  18246. return String(value).replace(/(^\s+|\s+$)/g, '');
  18247. }
  18248. // Array.some() polyfill for IE8
  18249. function _someFunction(value, fun /*, thisArg */) {
  18250. 'use strict';
  18251. if (value === void 0 || value === null)
  18252. throw new TypeError();
  18253. var t = Object(value);
  18254. var len = t.length >>> 0;
  18255. if (typeof fun !== 'function') {
  18256. throw new TypeError();
  18257. }
  18258. var thisArg = arguments.length >= 3 ? arguments[2] : void 0;
  18259. for (var i = 0; i < len; i++)
  18260. {
  18261. if (i in t && fun.call(thisArg, t[i], i, t))
  18262. return true;
  18263. }
  18264. return false;
  18265. }
  18266. // Array.map polyfill for IE8
  18267. function _mapFunction(thisVal, fun /*, thisArg */) {
  18268. "use strict";
  18269. if (thisVal === void 0 || thisVal === null)
  18270. throw new TypeError();
  18271. var t = Object(thisVal);
  18272. var len = t.length >>> 0;
  18273. if (typeof fun !== "function") {
  18274. throw new TypeError();
  18275. }
  18276. var res = new Array(len);
  18277. var thisArg = arguments.length >= 3 ? arguments[2] : void 0;
  18278. for (var i = 0; i < len; i++)
  18279. {
  18280. // NOTE: Absolute correctness would demand Object.defineProperty
  18281. // be used. But this method is fairly new, and failure is
  18282. // possible only if Object.prototype or Array.prototype
  18283. // has a property |i| (very unlikely), so use a lesscorrect
  18284. // but more portable alternative.
  18285. if (i in t)
  18286. res[i] = fun.call(thisArg, t[i], i, t);
  18287. }
  18288. return res;
  18289. };
  18290. /**
  18291. * Returns the best rule for a given host based on candidates
  18292. *
  18293. * @static
  18294. * @param host {String} Hostname to check rules against
  18295. * @param rules {Array} List of rules used to work on
  18296. * @return {Object} Candidate object, with a normal and exception state
  18297. */
  18298. tld.getCandidateRule = function getCandidateRule (host, rules, options) {
  18299. var rule = {'normal': null, 'exception': null};
  18300. options = options || { lazy: false };
  18301. _someFunction(rules, function (r) {
  18302. var pattern;
  18303. // sld matching or validHost? escape the loop immediately (except if it's an exception)
  18304. if ('.' + host === r.getNormalXld()) {
  18305. if (options.lazy || r.exception || r.isHost) {
  18306. rule.normal = r;
  18307. }
  18308. return true;
  18309. }
  18310. // otherwise check as a complete host
  18311. // if it's an exception, we want to loop a bit more to a normal rule
  18312. pattern = '.+' + r.getNormalPattern() + '$';
  18313. if ((new RegExp(pattern)).test(host)) {
  18314. rule[r.exception ? 'exception' : 'normal'] = r;
  18315. return !r.exception;
  18316. }
  18317. return false;
  18318. });
  18319. // favouring the exception if encountered
  18320. // previously we were copy-altering a rule, creating inconsistent results based on rule order order
  18321. // @see https://github.com/oncletom/tld.js/pull/35
  18322. if (rule.normal && rule.exception) {
  18323. return rule.exception;
  18324. }
  18325. return rule.normal;
  18326. };
  18327. /**
  18328. * Retrieve a subset of rules for a Top-Level-Domain string
  18329. *
  18330. * @param tld {String} Top-Level-Domain string
  18331. * @return {Array} Rules subset
  18332. */
  18333. tld.prototype.getRulesForTld = function getRulesForTld (tld, default_rule) {
  18334. var exception = '!';
  18335. var wildcard = '*';
  18336. var append_tld_rule = true;
  18337. var rules = this.rules[tld];
  18338. // Already parsed
  18339. // Array.isArray polyfill for IE8
  18340. if (Object.prototype.toString.call(rules) === '[object Array]') {
  18341. return rules;
  18342. }
  18343. // Nothing found, apply some default value
  18344. if (rules === void 0) {
  18345. return default_rule ? [ default_rule ] : [];
  18346. }
  18347. // Parsing needed
  18348. rules = _mapFunction(rules.split('|'), function transformAsRule (sld) {
  18349. var first_bit = sld[0];
  18350. if (first_bit === exception || first_bit === wildcard) {
  18351. sld = sld.slice(1);
  18352. if (!sld) {
  18353. append_tld_rule = false;
  18354. }
  18355. }
  18356. return new Rule({
  18357. "firstLevel": tld,
  18358. "secondLevel": sld,
  18359. "exception": first_bit === exception,
  18360. "wildcard": first_bit === wildcard
  18361. });
  18362. });
  18363. // Always prepend to make it the latest rule to be applied
  18364. if (append_tld_rule) {
  18365. rules.unshift(new Rule({
  18366. "firstLevel": tld
  18367. }));
  18368. }
  18369. this.rules[tld] = rules.reverse();
  18370. return rules;
  18371. };
  18372. /**
  18373. * Checks if the TLD exists for a given host
  18374. *
  18375. * @api
  18376. * @param {string} host
  18377. * @return {boolean}
  18378. */
  18379. tld.prototype.tldExists = function tldExists(host){
  18380. var hostTld;
  18381. host = tld.cleanHostValue(host);
  18382. // Easy case, it's a TLD
  18383. if (this.rules[host]){
  18384. return true;
  18385. }
  18386. // Popping only the TLD of the hostname
  18387. hostTld = tld.extractTldFromHost(host);
  18388. return this.rules[hostTld] !== undefined;
  18389. };
  18390. /**
  18391. * Returns the public suffix (including exact matches)
  18392. *
  18393. * @api
  18394. * @since 1.5
  18395. * @param {string} host
  18396. * @return {String}
  18397. */
  18398. tld.prototype.getPublicSuffix = function getPublicSuffix(host) {
  18399. var hostTld, rules, rule;
  18400. if (host in this.rules){
  18401. return host;
  18402. }
  18403. host = tld.cleanHostValue(host);
  18404. hostTld = tld.extractTldFromHost(host);
  18405. rules = this.getRulesForTld(hostTld);
  18406. rule = tld.getCandidateRule(host, rules, { lazy: true });
  18407. if (rule === null) {
  18408. return null;
  18409. }
  18410. return rule.getNormalXld().slice(1);
  18411. };
  18412. /**
  18413. * Detects the domain based on rules and upon and a host string
  18414. *
  18415. * @api
  18416. * @param {string} host
  18417. * @return {String}
  18418. */
  18419. tld.prototype.getDomain = function getDomain (host) {
  18420. var domain = null, hostTld, rules, rule;
  18421. if (this.isValid(host) === false) {
  18422. return null;
  18423. }
  18424. host = tld.cleanHostValue(host);
  18425. hostTld = tld.extractTldFromHost(host);
  18426. rules = this.getRulesForTld(hostTld, new Rule({"firstLevel": hostTld, "isHost": this.validHosts.indexOf(hostTld) !== -1}));
  18427. rule = tld.getCandidateRule(host, rules);
  18428. if (rule === null) {
  18429. return null;
  18430. }
  18431. host.replace(new RegExp(rule.getPattern()), function (m, d) {
  18432. domain = d;
  18433. });
  18434. return domain;
  18435. };
  18436. /**
  18437. * Returns the subdomain of a host string
  18438. *
  18439. * @api
  18440. * @param {string} host
  18441. * @return {string|null} a subdomain string if any, blank string if subdomain is empty, otherwise null
  18442. */
  18443. tld.prototype.getSubdomain = function getSubdomain(host){
  18444. var domain, r, subdomain;
  18445. host = tld.cleanHostValue(host);
  18446. domain = this.getDomain(host);
  18447. // No domain found? Just abort, abort!
  18448. if (domain === null){
  18449. return null;
  18450. }
  18451. r = '\\.?'+ tld.escapeRegExp(domain)+'$';
  18452. subdomain = host.replace(new RegExp(r, 'i'), '');
  18453. return subdomain;
  18454. };
  18455. /**
  18456. * Checking if a host string is valid
  18457. * It's usually a preliminary check before trying to use getDomain or anything else
  18458. *
  18459. * Beware: it does not check if the TLD exists.
  18460. *
  18461. * @api
  18462. * @param host {String}
  18463. * @return {Boolean}
  18464. */
  18465. tld.prototype.isValid = function isValid (host) {
  18466. return typeof host === 'string' && (this.validHosts.indexOf(host) !== -1 || (host.indexOf('.') !== -1 && host[0] !== '.'));
  18467. };
  18468. /**
  18469. * Utility to cleanup the base host value. Also removes url fragments.
  18470. *
  18471. * Works for:
  18472. * - hostname
  18473. * - //hostname
  18474. * - scheme://hostname
  18475. * - scheme+scheme://hostname
  18476. *
  18477. * @param {string} value
  18478. * @return {String}
  18479. */
  18480. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  18481. var hasPrefixRE = /^(([a-z][a-z0-9+.-]*)?:)?\/\//;
  18482. var invalidHostnameChars = /[^A-Za-z0-9.-]/;
  18483. tld.cleanHostValue = function cleanHostValue(value){
  18484. value = trim(value).toLowerCase();
  18485. var parts = URL.parse(hasPrefixRE.test(value) ? value : '//' + value, null, true);
  18486. if (parts.hostname && !invalidHostnameChars.test(parts.hostname)) { return parts.hostname; }
  18487. if (!invalidHostnameChars.test(value)) { return value; }
  18488. return '';
  18489. };
  18490. /**
  18491. * Utility to extract the TLD from a host string
  18492. *
  18493. * @param {string} host
  18494. * @return {String}
  18495. */
  18496. tld.extractTldFromHost = function extractTldFromHost(host){
  18497. return host.split('.').pop();
  18498. };
  18499. /**
  18500. * Escapes RegExp specific chars.
  18501. *
  18502. * @since 1.3.1
  18503. * @see https://github.com/oncletom/tld.js/pull/33
  18504. * @param {String|Mixed} s
  18505. * @returns {string} Escaped string for a safe use in a `new RegExp` expression
  18506. */
  18507. tld.escapeRegExp = function escapeRegExp(s) {
  18508. return String(s).replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  18509. };
  18510. module.exports = tld;
  18511. },{"./rule.js":140,"url":143}],142:[function(require,module,exports){
  18512. 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":""}
  18513. },{}],143:[function(require,module,exports){
  18514. // Copyright Joyent, Inc. and other Node contributors.
  18515. //
  18516. // Permission is hereby granted, free of charge, to any person obtaining a
  18517. // copy of this software and associated documentation files (the
  18518. // "Software"), to deal in the Software without restriction, including
  18519. // without limitation the rights to use, copy, modify, merge, publish,
  18520. // distribute, sublicense, and/or sell copies of the Software, and to permit
  18521. // persons to whom the Software is furnished to do so, subject to the
  18522. // following conditions:
  18523. //
  18524. // The above copyright notice and this permission notice shall be included
  18525. // in all copies or substantial portions of the Software.
  18526. //
  18527. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18528. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18529. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  18530. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18531. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18532. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18533. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  18534. 'use strict';
  18535. var punycode = require('punycode');
  18536. var util = require('./util');
  18537. exports.parse = urlParse;
  18538. exports.resolve = urlResolve;
  18539. exports.resolveObject = urlResolveObject;
  18540. exports.format = urlFormat;
  18541. exports.Url = Url;
  18542. function Url() {
  18543. this.protocol = null;
  18544. this.slashes = null;
  18545. this.auth = null;
  18546. this.host = null;
  18547. this.port = null;
  18548. this.hostname = null;
  18549. this.hash = null;
  18550. this.search = null;
  18551. this.query = null;
  18552. this.pathname = null;
  18553. this.path = null;
  18554. this.href = null;
  18555. }
  18556. // Reference: RFC 3986, RFC 1808, RFC 2396
  18557. // define these here so at least they only have to be
  18558. // compiled once on the first module load.
  18559. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  18560. portPattern = /:[0-9]*$/,
  18561. // Special case for a simple path URL
  18562. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  18563. // RFC 2396: characters reserved for delimiting URLs.
  18564. // We actually just auto-escape these.
  18565. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  18566. // RFC 2396: characters not allowed for various reasons.
  18567. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  18568. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  18569. autoEscape = ['\''].concat(unwise),
  18570. // Characters that are never ever allowed in a hostname.
  18571. // Note that any invalid chars are also handled, but these
  18572. // are the ones that are *expected* to be seen, so we fast-path
  18573. // them.
  18574. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  18575. hostEndingChars = ['/', '?', '#'],
  18576. hostnameMaxLen = 255,
  18577. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  18578. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  18579. // protocols that can allow "unsafe" and "unwise" chars.
  18580. unsafeProtocol = {
  18581. 'javascript': true,
  18582. 'javascript:': true
  18583. },
  18584. // protocols that never have a hostname.
  18585. hostlessProtocol = {
  18586. 'javascript': true,
  18587. 'javascript:': true
  18588. },
  18589. // protocols that always contain a // bit.
  18590. slashedProtocol = {
  18591. 'http': true,
  18592. 'https': true,
  18593. 'ftp': true,
  18594. 'gopher': true,
  18595. 'file': true,
  18596. 'http:': true,
  18597. 'https:': true,
  18598. 'ftp:': true,
  18599. 'gopher:': true,
  18600. 'file:': true
  18601. },
  18602. querystring = require('querystring');
  18603. function urlParse(url, parseQueryString, slashesDenoteHost) {
  18604. if (url && util.isObject(url) && url instanceof Url) return url;
  18605. var u = new Url;
  18606. u.parse(url, parseQueryString, slashesDenoteHost);
  18607. return u;
  18608. }
  18609. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  18610. if (!util.isString(url)) {
  18611. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  18612. }
  18613. // Copy chrome, IE, opera backslash-handling behavior.
  18614. // Back slashes before the query string get converted to forward slashes
  18615. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  18616. var queryIndex = url.indexOf('?'),
  18617. splitter =
  18618. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  18619. uSplit = url.split(splitter),
  18620. slashRegex = /\\/g;
  18621. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  18622. url = uSplit.join(splitter);
  18623. var rest = url;
  18624. // trim before proceeding.
  18625. // This is to support parse stuff like " http://foo.com \n"
  18626. rest = rest.trim();
  18627. if (!slashesDenoteHost && url.split('#').length === 1) {
  18628. // Try fast path regexp
  18629. var simplePath = simplePathPattern.exec(rest);
  18630. if (simplePath) {
  18631. this.path = rest;
  18632. this.href = rest;
  18633. this.pathname = simplePath[1];
  18634. if (simplePath[2]) {
  18635. this.search = simplePath[2];
  18636. if (parseQueryString) {
  18637. this.query = querystring.parse(this.search.substr(1));
  18638. } else {
  18639. this.query = this.search.substr(1);
  18640. }
  18641. } else if (parseQueryString) {
  18642. this.search = '';
  18643. this.query = {};
  18644. }
  18645. return this;
  18646. }
  18647. }
  18648. var proto = protocolPattern.exec(rest);
  18649. if (proto) {
  18650. proto = proto[0];
  18651. var lowerProto = proto.toLowerCase();
  18652. this.protocol = lowerProto;
  18653. rest = rest.substr(proto.length);
  18654. }
  18655. // figure out if it's got a host
  18656. // user@server is *always* interpreted as a hostname, and url
  18657. // resolution will treat //foo/bar as host=foo,path=bar because that's
  18658. // how the browser resolves relative URLs.
  18659. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  18660. var slashes = rest.substr(0, 2) === '//';
  18661. if (slashes && !(proto && hostlessProtocol[proto])) {
  18662. rest = rest.substr(2);
  18663. this.slashes = true;
  18664. }
  18665. }
  18666. if (!hostlessProtocol[proto] &&
  18667. (slashes || (proto && !slashedProtocol[proto]))) {
  18668. // there's a hostname.
  18669. // the first instance of /, ?, ;, or # ends the host.
  18670. //
  18671. // If there is an @ in the hostname, then non-host chars *are* allowed
  18672. // to the left of the last @ sign, unless some host-ending character
  18673. // comes *before* the @-sign.
  18674. // URLs are obnoxious.
  18675. //
  18676. // ex:
  18677. // http://a@b@c/ => user:a@b host:c
  18678. // http://a@b?@c => user:a host:c path:/?@c
  18679. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  18680. // Review our test case against browsers more comprehensively.
  18681. // find the first instance of any hostEndingChars
  18682. var hostEnd = -1;
  18683. for (var i = 0; i < hostEndingChars.length; i++) {
  18684. var hec = rest.indexOf(hostEndingChars[i]);
  18685. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  18686. hostEnd = hec;
  18687. }
  18688. // at this point, either we have an explicit point where the
  18689. // auth portion cannot go past, or the last @ char is the decider.
  18690. var auth, atSign;
  18691. if (hostEnd === -1) {
  18692. // atSign can be anywhere.
  18693. atSign = rest.lastIndexOf('@');
  18694. } else {
  18695. // atSign must be in auth portion.
  18696. // http://a@b/c@d => host:b auth:a path:/c@d
  18697. atSign = rest.lastIndexOf('@', hostEnd);
  18698. }
  18699. // Now we have a portion which is definitely the auth.
  18700. // Pull that off.
  18701. if (atSign !== -1) {
  18702. auth = rest.slice(0, atSign);
  18703. rest = rest.slice(atSign + 1);
  18704. this.auth = decodeURIComponent(auth);
  18705. }
  18706. // the host is the remaining to the left of the first non-host char
  18707. hostEnd = -1;
  18708. for (var i = 0; i < nonHostChars.length; i++) {
  18709. var hec = rest.indexOf(nonHostChars[i]);
  18710. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  18711. hostEnd = hec;
  18712. }
  18713. // if we still have not hit it, then the entire thing is a host.
  18714. if (hostEnd === -1)
  18715. hostEnd = rest.length;
  18716. this.host = rest.slice(0, hostEnd);
  18717. rest = rest.slice(hostEnd);
  18718. // pull out port.
  18719. this.parseHost();
  18720. // we've indicated that there is a hostname,
  18721. // so even if it's empty, it has to be present.
  18722. this.hostname = this.hostname || '';
  18723. // if hostname begins with [ and ends with ]
  18724. // assume that it's an IPv6 address.
  18725. var ipv6Hostname = this.hostname[0] === '[' &&
  18726. this.hostname[this.hostname.length - 1] === ']';
  18727. // validate a little.
  18728. if (!ipv6Hostname) {
  18729. var hostparts = this.hostname.split(/\./);
  18730. for (var i = 0, l = hostparts.length; i < l; i++) {
  18731. var part = hostparts[i];
  18732. if (!part) continue;
  18733. if (!part.match(hostnamePartPattern)) {
  18734. var newpart = '';
  18735. for (var j = 0, k = part.length; j < k; j++) {
  18736. if (part.charCodeAt(j) > 127) {
  18737. // we replace non-ASCII char with a temporary placeholder
  18738. // we need this to make sure size of hostname is not
  18739. // broken by replacing non-ASCII by nothing
  18740. newpart += 'x';
  18741. } else {
  18742. newpart += part[j];
  18743. }
  18744. }
  18745. // we test again with ASCII char only
  18746. if (!newpart.match(hostnamePartPattern)) {
  18747. var validParts = hostparts.slice(0, i);
  18748. var notHost = hostparts.slice(i + 1);
  18749. var bit = part.match(hostnamePartStart);
  18750. if (bit) {
  18751. validParts.push(bit[1]);
  18752. notHost.unshift(bit[2]);
  18753. }
  18754. if (notHost.length) {
  18755. rest = '/' + notHost.join('.') + rest;
  18756. }
  18757. this.hostname = validParts.join('.');
  18758. break;
  18759. }
  18760. }
  18761. }
  18762. }
  18763. if (this.hostname.length > hostnameMaxLen) {
  18764. this.hostname = '';
  18765. } else {
  18766. // hostnames are always lower case.
  18767. this.hostname = this.hostname.toLowerCase();
  18768. }
  18769. if (!ipv6Hostname) {
  18770. // IDNA Support: Returns a punycoded representation of "domain".
  18771. // It only converts parts of the domain name that
  18772. // have non-ASCII characters, i.e. it doesn't matter if
  18773. // you call it with a domain that already is ASCII-only.
  18774. this.hostname = punycode.toASCII(this.hostname);
  18775. }
  18776. var p = this.port ? ':' + this.port : '';
  18777. var h = this.hostname || '';
  18778. this.host = h + p;
  18779. this.href += this.host;
  18780. // strip [ and ] from the hostname
  18781. // the host field still retains them, though
  18782. if (ipv6Hostname) {
  18783. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  18784. if (rest[0] !== '/') {
  18785. rest = '/' + rest;
  18786. }
  18787. }
  18788. }
  18789. // now rest is set to the post-host stuff.
  18790. // chop off any delim chars.
  18791. if (!unsafeProtocol[lowerProto]) {
  18792. // First, make 100% sure that any "autoEscape" chars get
  18793. // escaped, even if encodeURIComponent doesn't think they
  18794. // need to be.
  18795. for (var i = 0, l = autoEscape.length; i < l; i++) {
  18796. var ae = autoEscape[i];
  18797. if (rest.indexOf(ae) === -1)
  18798. continue;
  18799. var esc = encodeURIComponent(ae);
  18800. if (esc === ae) {
  18801. esc = escape(ae);
  18802. }
  18803. rest = rest.split(ae).join(esc);
  18804. }
  18805. }
  18806. // chop off from the tail first.
  18807. var hash = rest.indexOf('#');
  18808. if (hash !== -1) {
  18809. // got a fragment string.
  18810. this.hash = rest.substr(hash);
  18811. rest = rest.slice(0, hash);
  18812. }
  18813. var qm = rest.indexOf('?');
  18814. if (qm !== -1) {
  18815. this.search = rest.substr(qm);
  18816. this.query = rest.substr(qm + 1);
  18817. if (parseQueryString) {
  18818. this.query = querystring.parse(this.query);
  18819. }
  18820. rest = rest.slice(0, qm);
  18821. } else if (parseQueryString) {
  18822. // no query string, but parseQueryString still requested
  18823. this.search = '';
  18824. this.query = {};
  18825. }
  18826. if (rest) this.pathname = rest;
  18827. if (slashedProtocol[lowerProto] &&
  18828. this.hostname && !this.pathname) {
  18829. this.pathname = '/';
  18830. }
  18831. //to support http.request
  18832. if (this.pathname || this.search) {
  18833. var p = this.pathname || '';
  18834. var s = this.search || '';
  18835. this.path = p + s;
  18836. }
  18837. // finally, reconstruct the href based on what has been validated.
  18838. this.href = this.format();
  18839. return this;
  18840. };
  18841. // format a parsed object into a url string
  18842. function urlFormat(obj) {
  18843. // ensure it's an object, and not a string url.
  18844. // If it's an obj, this is a no-op.
  18845. // this way, you can call url_format() on strings
  18846. // to clean up potentially wonky urls.
  18847. if (util.isString(obj)) obj = urlParse(obj);
  18848. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  18849. return obj.format();
  18850. }
  18851. Url.prototype.format = function() {
  18852. var auth = this.auth || '';
  18853. if (auth) {
  18854. auth = encodeURIComponent(auth);
  18855. auth = auth.replace(/%3A/i, ':');
  18856. auth += '@';
  18857. }
  18858. var protocol = this.protocol || '',
  18859. pathname = this.pathname || '',
  18860. hash = this.hash || '',
  18861. host = false,
  18862. query = '';
  18863. if (this.host) {
  18864. host = auth + this.host;
  18865. } else if (this.hostname) {
  18866. host = auth + (this.hostname.indexOf(':') === -1 ?
  18867. this.hostname :
  18868. '[' + this.hostname + ']');
  18869. if (this.port) {
  18870. host += ':' + this.port;
  18871. }
  18872. }
  18873. if (this.query &&
  18874. util.isObject(this.query) &&
  18875. Object.keys(this.query).length) {
  18876. query = querystring.stringify(this.query);
  18877. }
  18878. var search = this.search || (query && ('?' + query)) || '';
  18879. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  18880. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  18881. // unless they had them to begin with.
  18882. if (this.slashes ||
  18883. (!protocol || slashedProtocol[protocol]) && host !== false) {
  18884. host = '//' + (host || '');
  18885. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  18886. } else if (!host) {
  18887. host = '';
  18888. }
  18889. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  18890. if (search && search.charAt(0) !== '?') search = '?' + search;
  18891. pathname = pathname.replace(/[?#]/g, function(match) {
  18892. return encodeURIComponent(match);
  18893. });
  18894. search = search.replace('#', '%23');
  18895. return protocol + host + pathname + search + hash;
  18896. };
  18897. function urlResolve(source, relative) {
  18898. return urlParse(source, false, true).resolve(relative);
  18899. }
  18900. Url.prototype.resolve = function(relative) {
  18901. return this.resolveObject(urlParse(relative, false, true)).format();
  18902. };
  18903. function urlResolveObject(source, relative) {
  18904. if (!source) return relative;
  18905. return urlParse(source, false, true).resolveObject(relative);
  18906. }
  18907. Url.prototype.resolveObject = function(relative) {
  18908. if (util.isString(relative)) {
  18909. var rel = new Url();
  18910. rel.parse(relative, false, true);
  18911. relative = rel;
  18912. }
  18913. var result = new Url();
  18914. var tkeys = Object.keys(this);
  18915. for (var tk = 0; tk < tkeys.length; tk++) {
  18916. var tkey = tkeys[tk];
  18917. result[tkey] = this[tkey];
  18918. }
  18919. // hash is always overridden, no matter what.
  18920. // even href="" will remove it.
  18921. result.hash = relative.hash;
  18922. // if the relative url is empty, then there's nothing left to do here.
  18923. if (relative.href === '') {
  18924. result.href = result.format();
  18925. return result;
  18926. }
  18927. // hrefs like //foo/bar always cut to the protocol.
  18928. if (relative.slashes && !relative.protocol) {
  18929. // take everything except the protocol from relative
  18930. var rkeys = Object.keys(relative);
  18931. for (var rk = 0; rk < rkeys.length; rk++) {
  18932. var rkey = rkeys[rk];
  18933. if (rkey !== 'protocol')
  18934. result[rkey] = relative[rkey];
  18935. }
  18936. //urlParse appends trailing / to urls like http://www.example.com
  18937. if (slashedProtocol[result.protocol] &&
  18938. result.hostname && !result.pathname) {
  18939. result.path = result.pathname = '/';
  18940. }
  18941. result.href = result.format();
  18942. return result;
  18943. }
  18944. if (relative.protocol && relative.protocol !== result.protocol) {
  18945. // if it's a known url protocol, then changing
  18946. // the protocol does weird things
  18947. // first, if it's not file:, then we MUST have a host,
  18948. // and if there was a path
  18949. // to begin with, then we MUST have a path.
  18950. // if it is file:, then the host is dropped,
  18951. // because that's known to be hostless.
  18952. // anything else is assumed to be absolute.
  18953. if (!slashedProtocol[relative.protocol]) {
  18954. var keys = Object.keys(relative);
  18955. for (var v = 0; v < keys.length; v++) {
  18956. var k = keys[v];
  18957. result[k] = relative[k];
  18958. }
  18959. result.href = result.format();
  18960. return result;
  18961. }
  18962. result.protocol = relative.protocol;
  18963. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  18964. var relPath = (relative.pathname || '').split('/');
  18965. while (relPath.length && !(relative.host = relPath.shift()));
  18966. if (!relative.host) relative.host = '';
  18967. if (!relative.hostname) relative.hostname = '';
  18968. if (relPath[0] !== '') relPath.unshift('');
  18969. if (relPath.length < 2) relPath.unshift('');
  18970. result.pathname = relPath.join('/');
  18971. } else {
  18972. result.pathname = relative.pathname;
  18973. }
  18974. result.search = relative.search;
  18975. result.query = relative.query;
  18976. result.host = relative.host || '';
  18977. result.auth = relative.auth;
  18978. result.hostname = relative.hostname || relative.host;
  18979. result.port = relative.port;
  18980. // to support http.request
  18981. if (result.pathname || result.search) {
  18982. var p = result.pathname || '';
  18983. var s = result.search || '';
  18984. result.path = p + s;
  18985. }
  18986. result.slashes = result.slashes || relative.slashes;
  18987. result.href = result.format();
  18988. return result;
  18989. }
  18990. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  18991. isRelAbs = (
  18992. relative.host ||
  18993. relative.pathname && relative.pathname.charAt(0) === '/'
  18994. ),
  18995. mustEndAbs = (isRelAbs || isSourceAbs ||
  18996. (result.host && relative.pathname)),
  18997. removeAllDots = mustEndAbs,
  18998. srcPath = result.pathname && result.pathname.split('/') || [],
  18999. relPath = relative.pathname && relative.pathname.split('/') || [],
  19000. psychotic = result.protocol && !slashedProtocol[result.protocol];
  19001. // if the url is a non-slashed url, then relative
  19002. // links like ../.. should be able
  19003. // to crawl up to the hostname, as well. This is strange.
  19004. // result.protocol has already been set by now.
  19005. // Later on, put the first path part into the host field.
  19006. if (psychotic) {
  19007. result.hostname = '';
  19008. result.port = null;
  19009. if (result.host) {
  19010. if (srcPath[0] === '') srcPath[0] = result.host;
  19011. else srcPath.unshift(result.host);
  19012. }
  19013. result.host = '';
  19014. if (relative.protocol) {
  19015. relative.hostname = null;
  19016. relative.port = null;
  19017. if (relative.host) {
  19018. if (relPath[0] === '') relPath[0] = relative.host;
  19019. else relPath.unshift(relative.host);
  19020. }
  19021. relative.host = null;
  19022. }
  19023. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  19024. }
  19025. if (isRelAbs) {
  19026. // it's absolute.
  19027. result.host = (relative.host || relative.host === '') ?
  19028. relative.host : result.host;
  19029. result.hostname = (relative.hostname || relative.hostname === '') ?
  19030. relative.hostname : result.hostname;
  19031. result.search = relative.search;
  19032. result.query = relative.query;
  19033. srcPath = relPath;
  19034. // fall through to the dot-handling below.
  19035. } else if (relPath.length) {
  19036. // it's relative
  19037. // throw away the existing file, and take the new path instead.
  19038. if (!srcPath) srcPath = [];
  19039. srcPath.pop();
  19040. srcPath = srcPath.concat(relPath);
  19041. result.search = relative.search;
  19042. result.query = relative.query;
  19043. } else if (!util.isNullOrUndefined(relative.search)) {
  19044. // just pull out the search.
  19045. // like href='?foo'.
  19046. // Put this after the other two cases because it simplifies the booleans
  19047. if (psychotic) {
  19048. result.hostname = result.host = srcPath.shift();
  19049. //occationaly the auth can get stuck only in host
  19050. //this especially happens in cases like
  19051. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  19052. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  19053. result.host.split('@') : false;
  19054. if (authInHost) {
  19055. result.auth = authInHost.shift();
  19056. result.host = result.hostname = authInHost.shift();
  19057. }
  19058. }
  19059. result.search = relative.search;
  19060. result.query = relative.query;
  19061. //to support http.request
  19062. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  19063. result.path = (result.pathname ? result.pathname : '') +
  19064. (result.search ? result.search : '');
  19065. }
  19066. result.href = result.format();
  19067. return result;
  19068. }
  19069. if (!srcPath.length) {
  19070. // no path at all. easy.
  19071. // we've already handled the other stuff above.
  19072. result.pathname = null;
  19073. //to support http.request
  19074. if (result.search) {
  19075. result.path = '/' + result.search;
  19076. } else {
  19077. result.path = null;
  19078. }
  19079. result.href = result.format();
  19080. return result;
  19081. }
  19082. // if a url ENDs in . or .., then it must get a trailing slash.
  19083. // however, if it ends in anything else non-slashy,
  19084. // then it must NOT get a trailing slash.
  19085. var last = srcPath.slice(-1)[0];
  19086. var hasTrailingSlash = (
  19087. (result.host || relative.host || srcPath.length > 1) &&
  19088. (last === '.' || last === '..') || last === '');
  19089. // strip single dots, resolve double dots to parent dir
  19090. // if the path tries to go above the root, `up` ends up > 0
  19091. var up = 0;
  19092. for (var i = srcPath.length; i >= 0; i--) {
  19093. last = srcPath[i];
  19094. if (last === '.') {
  19095. srcPath.splice(i, 1);
  19096. } else if (last === '..') {
  19097. srcPath.splice(i, 1);
  19098. up++;
  19099. } else if (up) {
  19100. srcPath.splice(i, 1);
  19101. up--;
  19102. }
  19103. }
  19104. // if the path is allowed to go above the root, restore leading ..s
  19105. if (!mustEndAbs && !removeAllDots) {
  19106. for (; up--; up) {
  19107. srcPath.unshift('..');
  19108. }
  19109. }
  19110. if (mustEndAbs && srcPath[0] !== '' &&
  19111. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  19112. srcPath.unshift('');
  19113. }
  19114. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  19115. srcPath.push('');
  19116. }
  19117. var isAbsolute = srcPath[0] === '' ||
  19118. (srcPath[0] && srcPath[0].charAt(0) === '/');
  19119. // put the host back
  19120. if (psychotic) {
  19121. result.hostname = result.host = isAbsolute ? '' :
  19122. srcPath.length ? srcPath.shift() : '';
  19123. //occationaly the auth can get stuck only in host
  19124. //this especially happens in cases like
  19125. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  19126. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  19127. result.host.split('@') : false;
  19128. if (authInHost) {
  19129. result.auth = authInHost.shift();
  19130. result.host = result.hostname = authInHost.shift();
  19131. }
  19132. }
  19133. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  19134. if (mustEndAbs && !isAbsolute) {
  19135. srcPath.unshift('');
  19136. }
  19137. if (!srcPath.length) {
  19138. result.pathname = null;
  19139. result.path = null;
  19140. } else {
  19141. result.pathname = srcPath.join('/');
  19142. }
  19143. //to support request.http
  19144. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  19145. result.path = (result.pathname ? result.pathname : '') +
  19146. (result.search ? result.search : '');
  19147. }
  19148. result.auth = relative.auth || result.auth;
  19149. result.slashes = result.slashes || relative.slashes;
  19150. result.href = result.format();
  19151. return result;
  19152. };
  19153. Url.prototype.parseHost = function() {
  19154. var host = this.host;
  19155. var port = portPattern.exec(host);
  19156. if (port) {
  19157. port = port[0];
  19158. if (port !== ':') {
  19159. this.port = port.substr(1);
  19160. }
  19161. host = host.substr(0, host.length - port.length);
  19162. }
  19163. if (host) this.hostname = host;
  19164. };
  19165. },{"./util":144,"punycode":113,"querystring":116}],144:[function(require,module,exports){
  19166. 'use strict';
  19167. module.exports = {
  19168. isString: function(arg) {
  19169. return typeof(arg) === 'string';
  19170. },
  19171. isObject: function(arg) {
  19172. return typeof(arg) === 'object' && arg !== null;
  19173. },
  19174. isNull: function(arg) {
  19175. return arg === null;
  19176. },
  19177. isNullOrUndefined: function(arg) {
  19178. return arg == null;
  19179. }
  19180. };
  19181. },{}],145:[function(require,module,exports){
  19182. (function (global){
  19183. /**
  19184. * Module exports.
  19185. */
  19186. module.exports = deprecate;
  19187. /**
  19188. * Mark that a method should not be used.
  19189. * Returns a modified function which warns once by default.
  19190. *
  19191. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  19192. *
  19193. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  19194. * will throw an Error when invoked.
  19195. *
  19196. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  19197. * will invoke `console.trace()` instead of `console.error()`.
  19198. *
  19199. * @param {Function} fn - the function to deprecate
  19200. * @param {String} msg - the string to print to the console when `fn` is invoked
  19201. * @returns {Function} a new "deprecated" version of `fn`
  19202. * @api public
  19203. */
  19204. function deprecate (fn, msg) {
  19205. if (config('noDeprecation')) {
  19206. return fn;
  19207. }
  19208. var warned = false;
  19209. function deprecated() {
  19210. if (!warned) {
  19211. if (config('throwDeprecation')) {
  19212. throw new Error(msg);
  19213. } else if (config('traceDeprecation')) {
  19214. console.trace(msg);
  19215. } else {
  19216. console.warn(msg);
  19217. }
  19218. warned = true;
  19219. }
  19220. return fn.apply(this, arguments);
  19221. }
  19222. return deprecated;
  19223. }
  19224. /**
  19225. * Checks `localStorage` for boolean values for the given `name`.
  19226. *
  19227. * @param {String} name
  19228. * @returns {Boolean}
  19229. * @api private
  19230. */
  19231. function config (name) {
  19232. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  19233. try {
  19234. if (!global.localStorage) return false;
  19235. } catch (_) {
  19236. return false;
  19237. }
  19238. var val = global.localStorage[name];
  19239. if (null == val) return false;
  19240. return String(val).toLowerCase() === 'true';
  19241. }
  19242. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  19243. },{}],146:[function(require,module,exports){
  19244. var indexOf = require('indexof');
  19245. var Object_keys = function (obj) {
  19246. if (Object.keys) return Object.keys(obj)
  19247. else {
  19248. var res = [];
  19249. for (var key in obj) res.push(key)
  19250. return res;
  19251. }
  19252. };
  19253. var forEach = function (xs, fn) {
  19254. if (xs.forEach) return xs.forEach(fn)
  19255. else for (var i = 0; i < xs.length; i++) {
  19256. fn(xs[i], i, xs);
  19257. }
  19258. };
  19259. var defineProp = (function() {
  19260. try {
  19261. Object.defineProperty({}, '_', {});
  19262. return function(obj, name, value) {
  19263. Object.defineProperty(obj, name, {
  19264. writable: true,
  19265. enumerable: false,
  19266. configurable: true,
  19267. value: value
  19268. })
  19269. };
  19270. } catch(e) {
  19271. return function(obj, name, value) {
  19272. obj[name] = value;
  19273. };
  19274. }
  19275. }());
  19276. var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
  19277. 'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
  19278. 'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
  19279. 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
  19280. 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'];
  19281. function Context() {}
  19282. Context.prototype = {};
  19283. var Script = exports.Script = function NodeScript (code) {
  19284. if (!(this instanceof Script)) return new Script(code);
  19285. this.code = code;
  19286. };
  19287. Script.prototype.runInContext = function (context) {
  19288. if (!(context instanceof Context)) {
  19289. throw new TypeError("needs a 'context' argument.");
  19290. }
  19291. var iframe = document.createElement('iframe');
  19292. if (!iframe.style) iframe.style = {};
  19293. iframe.style.display = 'none';
  19294. document.body.appendChild(iframe);
  19295. var win = iframe.contentWindow;
  19296. var wEval = win.eval, wExecScript = win.execScript;
  19297. if (!wEval && wExecScript) {
  19298. // win.eval() magically appears when this is called in IE:
  19299. wExecScript.call(win, 'null');
  19300. wEval = win.eval;
  19301. }
  19302. forEach(Object_keys(context), function (key) {
  19303. win[key] = context[key];
  19304. });
  19305. forEach(globals, function (key) {
  19306. if (context[key]) {
  19307. win[key] = context[key];
  19308. }
  19309. });
  19310. var winKeys = Object_keys(win);
  19311. var res = wEval.call(win, this.code);
  19312. forEach(Object_keys(win), function (key) {
  19313. // Avoid copying circular objects like `top` and `window` by only
  19314. // updating existing context properties or new properties in the `win`
  19315. // that was only introduced after the eval.
  19316. if (key in context || indexOf(winKeys, key) === -1) {
  19317. context[key] = win[key];
  19318. }
  19319. });
  19320. forEach(globals, function (key) {
  19321. if (!(key in context)) {
  19322. defineProp(context, key, win[key]);
  19323. }
  19324. });
  19325. document.body.removeChild(iframe);
  19326. return res;
  19327. };
  19328. Script.prototype.runInThisContext = function () {
  19329. return eval(this.code); // maybe...
  19330. };
  19331. Script.prototype.runInNewContext = function (context) {
  19332. var ctx = Script.createContext(context);
  19333. var res = this.runInContext(ctx);
  19334. forEach(Object_keys(ctx), function (key) {
  19335. context[key] = ctx[key];
  19336. });
  19337. return res;
  19338. };
  19339. forEach(Object_keys(Script.prototype), function (name) {
  19340. exports[name] = Script[name] = function (code) {
  19341. var s = Script(code);
  19342. return s[name].apply(s, [].slice.call(arguments, 1));
  19343. };
  19344. });
  19345. exports.createScript = function (code) {
  19346. return exports.Script(code);
  19347. };
  19348. exports.createContext = Script.createContext = function (context) {
  19349. var copy = new Context();
  19350. if(typeof context === 'object') {
  19351. forEach(Object_keys(context), function (key) {
  19352. copy[key] = context[key];
  19353. });
  19354. }
  19355. return copy;
  19356. };
  19357. },{"indexof":91}]},{},[1]);