mapexplorer-rails 1.0.0.pre.alpha → 1.0.0.pre.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mapexplorer/rails/version.rb +1 -1
  3. data/vendor/assets/babel-polyfill/README.md +0 -0
  4. data/vendor/assets/babel-polyfill/bower.json +22 -0
  5. data/vendor/assets/babel-polyfill/browser-polyfill.js +5 -0
  6. data/vendor/assets/d3/LICENSE +27 -0
  7. data/vendor/assets/d3/README.md +45 -0
  8. data/vendor/assets/d3/bower.json +7 -0
  9. data/vendor/assets/d3/d3.js +16383 -0
  10. data/vendor/assets/d3/d3.min.js +8 -0
  11. data/vendor/assets/jsrender/MIT-LICENSE.txt +20 -0
  12. data/vendor/assets/jsrender/bower.json +43 -0
  13. data/vendor/assets/jsrender/index.js +8 -0
  14. data/vendor/assets/jsrender/jsrender-node.js +2298 -0
  15. data/vendor/assets/jsrender/jsrender.js +2350 -0
  16. data/vendor/assets/jsrender/jsrender.min.js +4 -0
  17. data/vendor/assets/jsrender/jsrender.min.js.map +1 -0
  18. data/vendor/assets/jsrender/tmplify/index.js +64 -0
  19. data/vendor/assets/mapexplorer-core/LICENSE +21 -0
  20. data/vendor/assets/mapexplorer-core/README.md +235 -0
  21. data/vendor/assets/mapexplorer-core/assets/stylesheets/map.scss +38 -0
  22. data/vendor/assets/mapexplorer-core/assets/stylesheets/mapexplorer-core.scss +3 -0
  23. data/vendor/assets/mapexplorer-core/assets/stylesheets/merkle-path.scss +10 -0
  24. data/vendor/assets/mapexplorer-core/assets/stylesheets/variables.scss +14 -0
  25. data/vendor/assets/mapexplorer-core/bower.json +32 -0
  26. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js +3872 -0
  27. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js.map +1 -0
  28. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.min.js +35 -0
  29. data/vendor/assets/mapexplorer-core/karma.conf.js +117 -0
  30. data/vendor/assets/mapexplorer-core/package.json +85 -0
  31. data/vendor/assets/mapexplorer-core/rollup.bower.config.js +41 -0
  32. data/vendor/assets/mapexplorer-core/rollup.es.config.js +16 -0
  33. data/vendor/assets/mapexplorer-core/rollup.umd.config.js +25 -0
  34. data/vendor/assets/stratumn-sdk/LICENSE +21 -0
  35. data/vendor/assets/stratumn-sdk/README.md +267 -0
  36. data/vendor/assets/stratumn-sdk/bower.json +27 -0
  37. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.js +813 -0
  38. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.js.map +1 -0
  39. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.min.js +2 -0
  40. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.min.js.map +1 -0
  41. data/vendor/assets/stratumn-sdk/examples/browser/index.html +34 -0
  42. data/vendor/assets/stratumn-sdk/package.json +67 -0
  43. data/vendor/assets/stratumn-sdk/rollup.base.config.js +13 -0
  44. data/vendor/assets/stratumn-sdk/rollup.bower.config.js +18 -0
  45. data/vendor/assets/stratumn-sdk/rollup.bower.min.config.js +7 -0
  46. data/vendor/assets/stratumn-sdk/rollup.es.config.js +9 -0
  47. data/vendor/assets/stratumn-sdk/rollup.umd.config.js +10 -0
  48. metadata +46 -1
@@ -0,0 +1,3872 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-hierarchy'), require('d3-transition'), require('d3-ease'), require('d3-selection'), require('d3-zoom'), require('d3-array')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'd3-hierarchy', 'd3-transition', 'd3-ease', 'd3-selection', 'd3-zoom', 'd3-array'], factory) :
4
+ (factory((global.mapexplorerCore = global.mapexplorerCore || {}),global.d3,global.d3,global.d3,global.d3,global.d3,global.d3));
5
+ }(this, (function (exports,d3Hierarchy,d3Transition,d3Ease,d3Selection,d3Zoom,d3Array) { 'use strict';
6
+
7
+ function makeLink(source, target) {
8
+ var margin = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
9
+
10
+ var finalTarget = target || source;
11
+ var targetX = finalTarget.x;
12
+ var targetY = finalTarget.y - margin;
13
+ return "M" + source.y + "," + source.x + "\n C" + (source.y + targetY) / 2 + "," + source.x + " " + (source.y + targetY) / 2 + ",\n " + targetX + " " + targetY + "," + targetX;
14
+ }
15
+
16
+ function finalLink(d, margin) {
17
+ return makeLink(d.source, d.target, margin);
18
+ }
19
+
20
+ function translate(x, y) {
21
+ return "translate(" + y + ", " + x + ")";
22
+ }
23
+
24
+ function parseChainscript(chainscript) {
25
+ return d3Hierarchy.stratify().id(function (d) {
26
+ return d.meta.linkHash;
27
+ }).parentId(function (d) {
28
+ return d.link.meta.prevLinkHash;
29
+ })(chainscript);
30
+ }
31
+
32
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
33
+ return typeof obj;
34
+ } : function (obj) {
35
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
36
+ };
37
+
38
+ var classCallCheck = function (instance, Constructor) {
39
+ if (!(instance instanceof Constructor)) {
40
+ throw new TypeError("Cannot call a class as a function");
41
+ }
42
+ };
43
+
44
+ var createClass = function () {
45
+ function defineProperties(target, props) {
46
+ for (var i = 0; i < props.length; i++) {
47
+ var descriptor = props[i];
48
+ descriptor.enumerable = descriptor.enumerable || false;
49
+ descriptor.configurable = true;
50
+ if ("value" in descriptor) descriptor.writable = true;
51
+ Object.defineProperty(target, descriptor.key, descriptor);
52
+ }
53
+ }
54
+
55
+ return function (Constructor, protoProps, staticProps) {
56
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
57
+ if (staticProps) defineProperties(Constructor, staticProps);
58
+ return Constructor;
59
+ };
60
+ }();
61
+
62
+ var _extends = Object.assign || function (target) {
63
+ for (var i = 1; i < arguments.length; i++) {
64
+ var source = arguments[i];
65
+
66
+ for (var key in source) {
67
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
68
+ target[key] = source[key];
69
+ }
70
+ }
71
+ }
72
+
73
+ return target;
74
+ };
75
+
76
+ var toConsumableArray = function (arr) {
77
+ if (Array.isArray(arr)) {
78
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
79
+
80
+ return arr2;
81
+ } else {
82
+ return Array.from(arr);
83
+ }
84
+ };
85
+
86
+ var margin = { top: 20, right: 120, bottom: 20, left: 120 };
87
+ var height = 800 - margin.top - margin.bottom;
88
+
89
+ var ChainTree = function () {
90
+ function ChainTree(element) {
91
+ var _this = this;
92
+
93
+ classCallCheck(this, ChainTree);
94
+
95
+ this.tree = d3Hierarchy.tree();
96
+
97
+ this.svg = d3Selection.select(element).append('svg');
98
+ this.innerG = this.svg.append('g');
99
+
100
+ this.zoomed = function () {
101
+ return _this.innerG.attr('transform', d3Selection.event.transform);
102
+ };
103
+ }
104
+
105
+ createClass(ChainTree, [{
106
+ key: 'display',
107
+ value: function display(chainscript, options) {
108
+ if (chainscript && chainscript.length) {
109
+ var root = parseChainscript(chainscript);
110
+ this._update(root, options);
111
+ } else {
112
+ this._update(null, options);
113
+ }
114
+ }
115
+ }, {
116
+ key: '_update',
117
+ value: function _update(root, options) {
118
+ var self = this;
119
+ var polygon = options.polygonSize;
120
+ var nodes = root ? root.descendants() : [];
121
+ var links = root ? root.links() : [];
122
+ var maxDepth = d3Array.max(nodes, function (x) {
123
+ return x.depth;
124
+ }) || 0;
125
+ var computedWidth = Math.max(maxDepth * (polygon.width + options.getArrowLength()), 500);
126
+ var treeTransition = d3Transition.transition().duration(options.duration).ease(d3Ease.easeLinear);
127
+
128
+ var branchesCount = nodes.reduce(function (pre, cur) {
129
+ return pre + (cur.children ? Math.max(cur.children.length - 1, 0) : 0);
130
+ }, 1);
131
+ var computedHeight = branchesCount * polygon.height * options.verticalSpacing;
132
+
133
+ this.tree.size([computedHeight, computedWidth]);
134
+ this.svg.attr('width', options.zoomable ? 1200 : computedWidth + margin.right + margin.left + options.getArrowLength()).attr('height', (options.zoomable ? height : computedHeight) + margin.top + margin.bottom);
135
+
136
+ // Compute the new tree layout.
137
+ if (root) {
138
+ root.x0 = computedHeight / 2;
139
+ root.y0 = 0;
140
+ this.tree(root);
141
+ root.each(function (node) {
142
+ node.y += options.getArrowLength();
143
+ });
144
+ }
145
+
146
+ if (options.zoomable) {
147
+ this.svg.call(d3Zoom.zoom().on('zoom', this.zoomed));
148
+ } else {
149
+ this.svg.on('.zoom', null);
150
+ }
151
+ this.innerG.attr('transform', function () {
152
+ return translate(margin.top, margin.left);
153
+ });
154
+
155
+ // Update the links...
156
+ var link = this.innerG.selectAll('path.link').data(links, function key(d) {
157
+ return d ? d.target.id : this.id;
158
+ });
159
+
160
+ link.enter().insert('text').attr('dx', polygon.width + 20).attr('dy', '-0.3em').append('textPath').attr('class', 'textpath').attr('xlink:href', function (d) {
161
+ return '#link-' + d.target.id;
162
+ }).text(options.getLinkText);
163
+
164
+ // Enter any new links at the parent's previous position.
165
+ link.enter().insert('path', 'g').attr('class', 'link').attr('id', function (d) {
166
+ return 'link-' + d.target.id;
167
+ });
168
+
169
+ var linkUpdate = this.innerG.selectAll('path.link:not(.init)').transition(treeTransition);
170
+
171
+ // Transition links to their new position.
172
+ linkUpdate.attr('d', function (d) {
173
+ return finalLink(d, 15);
174
+ });
175
+
176
+ link.exit().remove();
177
+
178
+ // Update the nodes...
179
+ var node = this.innerG.selectAll('g.node').data(nodes, function key(d) {
180
+ return d ? d.id : this.id;
181
+ });
182
+
183
+ // Enter any new nodes at the parent's previous position.
184
+ var nodeEnter = node.enter().append('g').attr('class', function (d) {
185
+ return ['node'].concat(d.data.link.meta.tags).join(' ');
186
+ }).attr('id', function (d) {
187
+ return d.id;
188
+ }).attr('transform', function (d) {
189
+ var origin = d.parent && d.parent.x0 ? d.parent : root;
190
+ return translate(origin.x0, origin.y0);
191
+ }).on('click', function onClick(d) {
192
+ d3Selection.selectAll('g.node').classed('selected', false);
193
+ d3Selection.select(this).classed('selected', true);
194
+ options.onclick(d, function () {
195
+ self.innerG.selectAll('g.node.selected').classed('selected', false);
196
+ }, this);
197
+ });
198
+
199
+ nodeEnter.append('polygon').attr('points', '0,' + polygon.height / 4 + ' ' + polygon.width / 2 + ',' + polygon.height / 2 + ' ' + (polygon.width + ',' + polygon.height / 4 + ' ' + polygon.width + ',' + -polygon.height / 4 + ' ') + (polygon.width / 2 + ',' + -polygon.height / 2 + ' 0,' + -polygon.height / 4));
200
+
201
+ nodeEnter.append('rect').attr('y', -(options.getBoxSize().height / 2)).attr('width', polygon.width).attr('height', options.getBoxSize().height).style('fill-opacity', 1e-6);
202
+
203
+ nodeEnter.append('text').attr('dx', 12).attr('dy', 4).attr('text-anchor', 'begin').text(options.getSegmentText).style('fill-opacity', 1e-6);
204
+
205
+ // Transition nodes to their new position.
206
+ var nodeUpdate = this.svg.selectAll('g.node').transition(treeTransition);
207
+
208
+ nodeUpdate.attr('transform', function (d) {
209
+ return translate(d.x, d.y);
210
+ });
211
+ nodeUpdate.select('text').style('fill-opacity', 1);
212
+ nodeUpdate.select('rect').style('fill-opacity', 1);
213
+
214
+ // Transition exiting nodes to the parent's new position.
215
+ var nodeExit = node.exit(); // .transition(treeTransition);
216
+ nodeExit.select('text').style('fill-opacity', 1e-6);
217
+ nodeExit.attr('transform', function () {
218
+ return translate(0, 0);
219
+ }).remove();
220
+
221
+ this._drawInit(root);
222
+ }
223
+ }, {
224
+ key: '_drawInit',
225
+ value: function _drawInit(root) {
226
+ this.innerG.append('path').attr('class', 'link init').attr('id', 'init-link').attr('d', makeLink({ x: root.x, y: root.y0 }, root, 15));
227
+
228
+ this.innerG.append('text').attr('dx', 20).attr('dy', '-0.3em').append('textPath').attr('class', 'textpath').attr('xlink:href', '#init-link').text('init');
229
+ }
230
+ }]);
231
+ return ChainTree;
232
+ }();
233
+
234
+ function compactHash (hash) {
235
+ return "" + hash.slice(0, 3) + hash.slice(hash.length - 3);
236
+ }
237
+
238
+ var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}
239
+
240
+ function interopDefault(ex) {
241
+ return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
242
+ }
243
+
244
+ function createCommonjsModule(fn, module) {
245
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
246
+ }
247
+
248
+ var index = createCommonjsModule(function (module, exports) {
249
+ (function (root, factory) {
250
+ if (typeof define === 'function' && define.amd) {
251
+ define(factory);
252
+ } else if (typeof exports === 'object') {
253
+ module.exports = factory();
254
+ } else {
255
+ root.deepmerge = factory();
256
+ }
257
+ }(commonjsGlobal, function () {
258
+
259
+ return function deepmerge(target, src) {
260
+ var array = Array.isArray(src);
261
+ var dst = array && [] || {};
262
+
263
+ if (array) {
264
+ target = target || [];
265
+ dst = dst.concat(target);
266
+ src.forEach(function(e, i) {
267
+ if (typeof dst[i] === 'undefined') {
268
+ dst[i] = e;
269
+ } else if (typeof e === 'object') {
270
+ dst[i] = deepmerge(target[i], e);
271
+ } else {
272
+ if (target.indexOf(e) === -1) {
273
+ dst.push(e);
274
+ }
275
+ }
276
+ });
277
+ } else {
278
+ if (target && typeof target === 'object') {
279
+ Object.keys(target).forEach(function (key) {
280
+ dst[key] = target[key];
281
+ })
282
+ }
283
+ Object.keys(src).forEach(function (key) {
284
+ if (typeof src[key] !== 'object' || !src[key]) {
285
+ dst[key] = src[key];
286
+ }
287
+ else {
288
+ if (!target[key]) {
289
+ dst[key] = src[key];
290
+ } else {
291
+ dst[key] = deepmerge(target[key], src[key]);
292
+ }
293
+ }
294
+ });
295
+ }
296
+
297
+ return dst;
298
+ }
299
+
300
+ }));
301
+ });
302
+
303
+ var merge = interopDefault(index);
304
+
305
+ var jsonrequest = createCommonjsModule(function (module) {
306
+ 'use strict';
307
+
308
+ module.exports = {
309
+ processRequest: function(req) {
310
+ var
311
+ contentType = req.header('Content-Type'),
312
+ hasJsonContentType = contentType &&
313
+ contentType.indexOf('application/json') !== -1;
314
+
315
+ if (contentType != null && !hasJsonContentType) {
316
+ return;
317
+ }
318
+
319
+ if (req.body) {
320
+ if (!contentType) {
321
+ req.header('Content-Type', 'application/json');
322
+ }
323
+
324
+ req.body = JSON.stringify(req.body);
325
+ }
326
+ }
327
+ };
328
+ });
329
+
330
+ var jsonrequest$1 = interopDefault(jsonrequest);
331
+ var processRequest$1 = jsonrequest.processRequest;
332
+
333
+ var require$$1 = Object.freeze({
334
+ default: jsonrequest$1,
335
+ processRequest: processRequest$1
336
+ });
337
+
338
+ var jsonresponse = createCommonjsModule(function (module) {
339
+ 'use strict';
340
+
341
+ module.exports = {
342
+ processRequest: function(req) {
343
+ var accept = req.header('Accept');
344
+ if (accept == null) {
345
+ req.header('Accept', 'application/json');
346
+ }
347
+ },
348
+ processResponse: function(res) {
349
+ // Check to see if the contentype is "something/json" or
350
+ // "something/somethingelse+json"
351
+ if (res.contentType && /^.*\/(?:.*\+)?json(;|$)/i.test(res.contentType)) {
352
+ var raw = typeof res.body === 'string' ? res.body : res.text;
353
+ if (raw) {
354
+ res.body = JSON.parse(raw);
355
+ }
356
+ }
357
+ }
358
+ };
359
+ });
360
+
361
+ var jsonresponse$1 = interopDefault(jsonresponse);
362
+ var processRequest$2 = jsonresponse.processRequest;
363
+ var processResponse$1 = jsonresponse.processResponse;
364
+
365
+ var require$$0 = Object.freeze({
366
+ default: jsonresponse$1,
367
+ processRequest: processRequest$2,
368
+ processResponse: processResponse$1
369
+ });
370
+
371
+ var json = createCommonjsModule(function (module) {
372
+ 'use strict';
373
+
374
+ var jsonrequest = interopDefault(require$$1),
375
+ jsonresponse = interopDefault(require$$0);
376
+
377
+ module.exports = {
378
+ processRequest: function(req) {
379
+ jsonrequest.processRequest.call(this, req);
380
+ jsonresponse.processRequest.call(this, req);
381
+ },
382
+ processResponse: function(res) {
383
+ jsonresponse.processResponse.call(this, res);
384
+ }
385
+ };
386
+ });
387
+
388
+ var json$1 = interopDefault(json);
389
+
390
+ var cleanurl = createCommonjsModule(function (module) {
391
+ 'use strict';
392
+
393
+ module.exports = {
394
+ processRequest: function(req) {
395
+ req.url = req.url.replace(/[^%]+/g, function(s) {
396
+ return encodeURI(s);
397
+ });
398
+ }
399
+ };
400
+ });
401
+
402
+ var cleanurl$1 = interopDefault(cleanurl);
403
+ var processRequest$3 = cleanurl.processRequest;
404
+
405
+ var require$$7 = Object.freeze({
406
+ default: cleanurl$1,
407
+ processRequest: processRequest$3
408
+ });
409
+
410
+ var xhrBrowser = createCommonjsModule(function (module) {
411
+ module.exports = window.XMLHttpRequest;
412
+ });
413
+
414
+ var xhrBrowser$1 = interopDefault(xhrBrowser);
415
+
416
+
417
+ var require$$6 = Object.freeze({
418
+ default: xhrBrowser$1
419
+ });
420
+
421
+ var delay = createCommonjsModule(function (module) {
422
+ 'use strict';
423
+
424
+ // Wrap a function in a `setTimeout` call. This is used to guarantee async
425
+ // behavior, which can avoid unexpected errors.
426
+
427
+ module.exports = function(fn) {
428
+ return function() {
429
+ var
430
+ args = Array.prototype.slice.call(arguments, 0),
431
+ newFunc = function() {
432
+ return fn.apply(null, args);
433
+ };
434
+ setTimeout(newFunc, 0);
435
+ };
436
+ };
437
+ });
438
+
439
+ var delay$1 = interopDefault(delay);
440
+
441
+
442
+ var require$$5 = Object.freeze({
443
+ default: delay$1
444
+ });
445
+
446
+ var request$1 = createCommonjsModule(function (module) {
447
+ 'use strict';
448
+
449
+ function Request(optsOrUrl) {
450
+ var opts = typeof optsOrUrl === 'string' ? {url: optsOrUrl} : optsOrUrl || {};
451
+ this.method = opts.method ? opts.method.toUpperCase() : 'GET';
452
+ this.url = opts.url;
453
+ this.headers = opts.headers || {};
454
+ this.body = opts.body;
455
+ this.timeout = opts.timeout || 0;
456
+ this.errorOn404 = opts.errorOn404 != null ? opts.errorOn404 : true;
457
+ this.onload = opts.onload;
458
+ this.onerror = opts.onerror;
459
+ }
460
+
461
+ Request.prototype.abort = function() {
462
+ if (this.aborted) return;
463
+ this.aborted = true;
464
+ this.xhr.abort();
465
+ return this;
466
+ };
467
+
468
+ Request.prototype.header = function(name, value) {
469
+ var k;
470
+ for (k in this.headers) {
471
+ if (this.headers.hasOwnProperty(k)) {
472
+ if (name.toLowerCase() === k.toLowerCase()) {
473
+ if (arguments.length === 1) {
474
+ return this.headers[k];
475
+ }
476
+
477
+ delete this.headers[k];
478
+ break;
479
+ }
480
+ }
481
+ }
482
+ if (value != null) {
483
+ this.headers[name] = value;
484
+ return value;
485
+ }
486
+ };
487
+
488
+
489
+ module.exports = Request;
490
+ });
491
+
492
+ var request$2 = interopDefault(request$1);
493
+
494
+
495
+ var require$$1$1 = Object.freeze({
496
+ default: request$2
497
+ });
498
+
499
+ var index$2 = createCommonjsModule(function (module) {
500
+ module.exports = extend
501
+
502
+ function extend() {
503
+ var target = {}
504
+
505
+ for (var i = 0; i < arguments.length; i++) {
506
+ var source = arguments[i]
507
+
508
+ for (var key in source) {
509
+ if (source.hasOwnProperty(key)) {
510
+ target[key] = source[key]
511
+ }
512
+ }
513
+ }
514
+
515
+ return target
516
+ }
517
+ });
518
+
519
+ var index$3 = interopDefault(index$2);
520
+
521
+
522
+ var require$$0$2 = Object.freeze({
523
+ default: index$3
524
+ });
525
+
526
+ var extractResponseProps = createCommonjsModule(function (module) {
527
+ 'use strict';
528
+
529
+ var extend = interopDefault(require$$0$2);
530
+
531
+ module.exports = function(req) {
532
+ var xhr = req.xhr;
533
+ var props = {request: req, xhr: xhr};
534
+
535
+ // Try to create the response from the request. If the request was aborted,
536
+ // accesssing properties of the XHR may throw an error, so we wrap in a
537
+ // try/catch.
538
+ try {
539
+ var lines, i, m, headers = {};
540
+ if (xhr.getAllResponseHeaders) {
541
+ lines = xhr.getAllResponseHeaders().split('\n');
542
+ for (i = 0; i < lines.length; i++) {
543
+ if ((m = lines[i].match(/\s*([^\s]+):\s+([^\s]+)/))) {
544
+ headers[m[1]] = m[2];
545
+ }
546
+ }
547
+ }
548
+
549
+ props = extend(props, {
550
+ status: xhr.status,
551
+ contentType: xhr.contentType || (xhr.getResponseHeader && xhr.getResponseHeader('Content-Type')),
552
+ headers: headers,
553
+ text: xhr.responseText,
554
+ body: xhr.response || xhr.responseText
555
+ });
556
+ } catch (err) {}
557
+
558
+ return props;
559
+ };
560
+ });
561
+
562
+ var extractResponseProps$1 = interopDefault(extractResponseProps);
563
+
564
+
565
+ var require$$0$1 = Object.freeze({
566
+ default: extractResponseProps$1
567
+ });
568
+
569
+ var response = createCommonjsModule(function (module) {
570
+ 'use strict';
571
+
572
+ var Request = interopDefault(require$$1$1);
573
+ var extractResponseProps = interopDefault(require$$0$1);
574
+
575
+ function Response(props) {
576
+ this.request = props.request;
577
+ this.xhr = props.xhr;
578
+ this.headers = props.headers || {};
579
+ this.status = props.status || 0;
580
+ this.text = props.text;
581
+ this.body = props.body;
582
+ this.contentType = props.contentType;
583
+ this.isHttpError = props.status >= 400;
584
+ }
585
+
586
+ Response.prototype.header = Request.prototype.header;
587
+
588
+ Response.fromRequest = function(req) {
589
+ return new Response(extractResponseProps(req));
590
+ };
591
+
592
+
593
+ module.exports = Response;
594
+ });
595
+
596
+ var response$1 = interopDefault(response);
597
+
598
+
599
+ var require$$2 = Object.freeze({
600
+ default: response$1
601
+ });
602
+
603
+ var error = createCommonjsModule(function (module) {
604
+ 'use strict';
605
+
606
+ var Response = interopDefault(require$$2);
607
+ var extractResponseProps = interopDefault(require$$0$1);
608
+ var extend = interopDefault(require$$0$2);
609
+
610
+ function RequestError(message, props) {
611
+ var err = new Error(message);
612
+ err.name = 'RequestError';
613
+ this.name = err.name;
614
+ this.message = err.message;
615
+ if (err.stack) {
616
+ this.stack = err.stack;
617
+ }
618
+
619
+ this.toString = function() {
620
+ return this.message;
621
+ };
622
+
623
+ for (var k in props) {
624
+ if (props.hasOwnProperty(k)) {
625
+ this[k] = props[k];
626
+ }
627
+ }
628
+ }
629
+
630
+ RequestError.prototype = extend(Error.prototype);
631
+ RequestError.prototype.constructor = RequestError;
632
+
633
+ RequestError.create = function(message, req, props) {
634
+ var err = new RequestError(message, props);
635
+ Response.call(err, extractResponseProps(req));
636
+ return err;
637
+ };
638
+
639
+ module.exports = RequestError;
640
+ });
641
+
642
+ var error$1 = interopDefault(error);
643
+
644
+
645
+ var require$$4 = Object.freeze({
646
+ default: error$1
647
+ });
648
+
649
+ var once = createCommonjsModule(function (module) {
650
+ 'use strict';
651
+
652
+ // A "once" utility.
653
+ module.exports = function(fn) {
654
+ var result, called = false;
655
+ return function() {
656
+ if (!called) {
657
+ called = true;
658
+ result = fn.apply(this, arguments);
659
+ }
660
+ return result;
661
+ };
662
+ };
663
+ });
664
+
665
+ var once$1 = interopDefault(once);
666
+
667
+
668
+ var require$$0$3 = Object.freeze({
669
+ default: once$1
670
+ });
671
+
672
+ var index$1 = createCommonjsModule(function (module) {
673
+ 'use strict';
674
+
675
+ var
676
+ cleanURL = interopDefault(require$$7),
677
+ XHR = interopDefault(require$$6),
678
+ delay = interopDefault(require$$5),
679
+ RequestError = interopDefault(require$$4),
680
+ Response = interopDefault(require$$2),
681
+ Request = interopDefault(require$$1$1),
682
+ extend = interopDefault(require$$0$2),
683
+ once = interopDefault(require$$0$3);
684
+
685
+ var i,
686
+ createError = RequestError.create;
687
+
688
+ function factory(defaults, plugins) {
689
+ defaults = defaults || {};
690
+ plugins = plugins || [];
691
+
692
+ function http(req, cb) {
693
+ var xhr, plugin, done, k, timeoutId, supportsLoadAndErrorEvents;
694
+
695
+ req = new Request(extend(defaults, req));
696
+
697
+ for (i = 0; i < plugins.length; i++) {
698
+ plugin = plugins[i];
699
+ if (plugin.processRequest) {
700
+ plugin.processRequest(req);
701
+ }
702
+ }
703
+
704
+ // Give the plugins a chance to create the XHR object
705
+ for (i = 0; i < plugins.length; i++) {
706
+ plugin = plugins[i];
707
+ if (plugin.createXHR) {
708
+ xhr = plugin.createXHR(req);
709
+ break; // First come, first serve
710
+ }
711
+ }
712
+ xhr = xhr || new XHR();
713
+
714
+ req.xhr = xhr;
715
+
716
+ // Use a single completion callback. This can be called with or without
717
+ // an error. If no error is passed, the request will be examined to see
718
+ // if it was successful.
719
+ done = once(delay(function(rawError) {
720
+ clearTimeout(timeoutId);
721
+ xhr.onload = xhr.onerror = xhr.onabort = xhr.onreadystatechange = xhr.ontimeout = xhr.onprogress = null;
722
+
723
+ var err = getError(req, rawError);
724
+
725
+ var res = err || Response.fromRequest(req);
726
+ for (i = 0; i < plugins.length; i++) {
727
+ plugin = plugins[i];
728
+ if (plugin.processResponse) {
729
+ plugin.processResponse(res);
730
+ }
731
+ }
732
+
733
+ // Invoke callbacks
734
+ if (err && req.onerror) req.onerror(err);
735
+ if (!err && req.onload) req.onload(res);
736
+ if (cb) cb(err, err ? undefined : res);
737
+
738
+ }));
739
+
740
+ supportsLoadAndErrorEvents = ('onload' in xhr) && ('onerror' in xhr);
741
+ xhr.onload = function() { done(); };
742
+ xhr.onerror = done;
743
+ xhr.onabort = function() { done(); };
744
+
745
+ // We'd rather use `onload`, `onerror`, and `onabort` since they're the
746
+ // only way to reliably detect successes and failures but, if they
747
+ // aren't available, we fall back to using `onreadystatechange`.
748
+ xhr.onreadystatechange = function() {
749
+ if (xhr.readyState !== 4) return;
750
+
751
+ if (req.aborted) return done();
752
+
753
+ if (!supportsLoadAndErrorEvents) {
754
+ // Assume a status of 0 is an error. This could be a false
755
+ // positive, but there's no way to tell when using
756
+ // `onreadystatechange` ):
757
+ // See matthewwithanm/react-inlinesvg#10.
758
+
759
+ // Some browsers don't like you reading XHR properties when the
760
+ // XHR has been aborted. In case we've gotten here as a result
761
+ // of that (either our calling `about()` in the timeout handler
762
+ // or the user calling it directly even though they shouldn't),
763
+ // be careful about accessing it.
764
+ var status;
765
+ try {
766
+ status = xhr.status;
767
+ } catch (err) {}
768
+ var err = status === 0 ? new Error('Internal XHR Error') : null;
769
+ return done(err);
770
+ }
771
+ };
772
+
773
+ // IE sometimes fails if you don't specify every handler.
774
+ // See http://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
775
+ xhr.ontimeout = function() { /* noop */ };
776
+ xhr.onprogress = function() { /* noop */ };
777
+
778
+ xhr.open(req.method, req.url);
779
+
780
+ if (req.timeout) {
781
+ // If we use the normal XHR timeout mechanism (`xhr.timeout` and
782
+ // `xhr.ontimeout`), `onreadystatechange` will be triggered before
783
+ // `ontimeout`. There's no way to recognize that it was triggered by
784
+ // a timeout, and we'd be unable to dispatch the right error.
785
+ timeoutId = setTimeout(function() {
786
+ req.timedOut = true;
787
+ done();
788
+ try {
789
+ xhr.abort();
790
+ } catch (err) {}
791
+ }, req.timeout);
792
+ }
793
+
794
+ for (k in req.headers) {
795
+ if (req.headers.hasOwnProperty(k)) {
796
+ xhr.setRequestHeader(k, req.headers[k]);
797
+ }
798
+ }
799
+
800
+ xhr.send(req.body);
801
+
802
+ return req;
803
+ }
804
+
805
+ var method,
806
+ methods = ['get', 'post', 'put', 'head', 'patch', 'delete'],
807
+ verb = function(method) {
808
+ return function(req, cb) {
809
+ req = new Request(req);
810
+ req.method = method;
811
+ return http(req, cb);
812
+ };
813
+ };
814
+ for (i = 0; i < methods.length; i++) {
815
+ method = methods[i];
816
+ http[method] = verb(method);
817
+ }
818
+
819
+ http.plugins = function() {
820
+ return plugins;
821
+ };
822
+
823
+ http.defaults = function(newValues) {
824
+ if (newValues) {
825
+ return factory(extend(defaults, newValues), plugins);
826
+ }
827
+ return defaults;
828
+ };
829
+
830
+ http.use = function() {
831
+ var newPlugins = Array.prototype.slice.call(arguments, 0);
832
+ return factory(defaults, plugins.concat(newPlugins));
833
+ };
834
+
835
+ http.bare = function() {
836
+ return factory();
837
+ };
838
+
839
+ http.Request = Request;
840
+ http.Response = Response;
841
+ http.RequestError = RequestError;
842
+
843
+ return http;
844
+ }
845
+
846
+ module.exports = factory({}, [cleanURL]);
847
+
848
+ /**
849
+ * Analyze the request to see if it represents an error. If so, return it! An
850
+ * original error object can be passed as a hint.
851
+ */
852
+ function getError(req, err) {
853
+ if (req.aborted) return createError('Request aborted', req, {name: 'Abort'});
854
+
855
+ if (req.timedOut) return createError('Request timeout', req, {name: 'Timeout'});
856
+
857
+ var xhr = req.xhr;
858
+ var type = Math.floor(xhr.status / 100);
859
+
860
+ var kind;
861
+ switch (type) {
862
+ case 0:
863
+ case 2:
864
+ // These don't represent errors unless the function was passed an
865
+ // error object explicitly.
866
+ if (!err) return;
867
+ return createError(err.message, req);
868
+ case 4:
869
+ // Sometimes 4XX statuses aren't errors.
870
+ if (xhr.status === 404 && !req.errorOn404) return;
871
+ kind = 'Client';
872
+ break;
873
+ case 5:
874
+ kind = 'Server';
875
+ break;
876
+ default:
877
+ kind = 'HTTP';
878
+ }
879
+ var msg = kind + ' Error: ' +
880
+ 'The server returned a status of ' + xhr.status +
881
+ ' for the request "' +
882
+ req.method.toUpperCase() + ' ' + req.url + '"';
883
+ return createError(msg, req);
884
+ }
885
+ });
886
+
887
+ var httpplease = interopDefault(index$1);
888
+
889
+ function deprecated(oldFunc, newFunc) {
890
+ if (!newFunc) {
891
+ console.warn("WARNING: " + oldFunc + " is deprecated.");
892
+ } else {
893
+ console.warn("WARNING: " + oldFunc + " is deprecated. Please use " + newFunc + " instead.");
894
+ }
895
+ }
896
+
897
+ /**
898
+ * Makes a query string.
899
+ * @param {object} obj - an object of keys
900
+ * @returns {string} a query string
901
+ */
902
+ function makeQueryString(obj) {
903
+ var parts = Object.keys(obj).reduce(function (curr, key) {
904
+ var val = Array.isArray(obj[key]) ? obj[key].join('+') : obj[key];
905
+ curr.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
906
+ return curr;
907
+ }, []);
908
+
909
+ if (parts.length) {
910
+ return '?' + parts.join('&');
911
+ }
912
+
913
+ return '';
914
+ }
915
+
916
+ var request = httpplease.use(json$1);
917
+
918
+ function send(method, url, args) {
919
+ return new Promise(function (resolve, reject) {
920
+ request({ method: method, url: url, body: args }, function (err, res) {
921
+ if (err) {
922
+ var error = err && err.body && err.body.meta && err.body.meta.errorMessage ? new Error(err.body.meta.errorMessage) : err;
923
+ error.status = err.status;
924
+ reject(error);
925
+ } else {
926
+ resolve(res);
927
+ }
928
+ });
929
+ });
930
+ }
931
+
932
+ function get$1(url) {
933
+ return send('GET', url);
934
+ }
935
+
936
+ function post(url, args) {
937
+ return send('POST', url, args);
938
+ }
939
+
940
+ function findSegments(agent) {
941
+ var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
942
+
943
+ return get$1(agent.url + '/segments' + makeQueryString(opts)).then(function (res) {
944
+ return res.body.map(function (obj) {
945
+ return segmentify(agent, obj);
946
+ });
947
+ });
948
+ }
949
+
950
+ function getBranches(agent, prevLinkHash) {
951
+ var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
952
+
953
+ deprecated('Agent#getBranches(agent, prevLinkHash, tags = [])', 'Agent#findSegments(agent, filter)');
954
+
955
+ return findSegments(agent, { prevLinkHash: prevLinkHash, tags: tags });
956
+ }
957
+
958
+ function segmentify(agent, obj) {
959
+ Object.keys(agent.agentInfo.actions).filter(function (key) {
960
+ return ['init'].indexOf(key) < 0;
961
+ }).forEach(function (key) {
962
+ /*eslint-disable*/
963
+ obj[key] = function () {
964
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
965
+ args[_key] = arguments[_key];
966
+ }
967
+
968
+ return post(agent.url + '/segments/' + obj.meta.linkHash + '/' + key, args).then(function (res) {
969
+ return segmentify(agent, res.body);
970
+ });
971
+ };
972
+ });
973
+
974
+ /*eslint-disable*/
975
+ obj.getPrev = function () {
976
+ /*eslint-enable*/
977
+ if (obj.link.meta.prevLinkHash) {
978
+ return agent.getSegment(obj.link.meta.prevLinkHash);
979
+ }
980
+
981
+ return Promise.resolve(null);
982
+ };
983
+
984
+ // Deprecated.
985
+ /*eslint-disable*/
986
+ obj.load = function () {
987
+ /*eslint-enable*/
988
+ deprecated('segment#load()');
989
+ return Promise.resolve(segmentify(agent, {
990
+ link: JSON.parse(JSON.stringify(obj.link)),
991
+ meta: JSON.parse(JSON.stringify(obj.meta))
992
+ }));
993
+ };
994
+
995
+ // Deprecated.
996
+ /*eslint-disable*/
997
+ obj.getBranches = function () {
998
+ for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
999
+ args[_key2] = arguments[_key2];
1000
+ }
1001
+
1002
+ /*eslint-enable*/
1003
+ return getBranches.apply(undefined, [agent, obj.meta.linkHash].concat(args));
1004
+ };
1005
+
1006
+ return obj;
1007
+ }
1008
+
1009
+ function createMap(agent) {
1010
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1011
+ args[_key - 1] = arguments[_key];
1012
+ }
1013
+
1014
+ return post(agent.url + '/segments', args).then(function (res) {
1015
+ return segmentify(agent, res.body);
1016
+ });
1017
+ }
1018
+
1019
+ function getSegment(agent, linkHash) {
1020
+ return get$1(agent.url + '/segments/' + linkHash).then(function (res) {
1021
+ return segmentify(agent, res.body);
1022
+ });
1023
+ }
1024
+
1025
+ function getMapIds(agent) {
1026
+ var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
1027
+
1028
+ return get$1(agent.url + '/maps' + makeQueryString(opts)).then(function (res) {
1029
+ return res.body;
1030
+ });
1031
+ }
1032
+
1033
+ function getLink(agent, hash) {
1034
+ deprecated('Agent#getLink(agent, hash)', 'Agent#getSegment(agent, hash)');
1035
+
1036
+ return getSegment(agent, hash);
1037
+ }
1038
+
1039
+ function getMap(agent, mapId) {
1040
+ var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
1041
+
1042
+ deprecated('getMap(agent, mapId, tags = [])', 'findSegments(agent, filter)');
1043
+
1044
+ return findSegments(agent, { mapId: mapId, tags: tags });
1045
+ }
1046
+
1047
+ // Deprecated.
1048
+ function getAgent(url) {
1049
+ return get$1(url).then(function (res) {
1050
+ var agent = res.body;
1051
+
1052
+ agent.url = url;
1053
+ agent.createMap = createMap.bind(null, agent);
1054
+ agent.getSegment = getSegment.bind(null, agent);
1055
+ agent.findSegments = findSegments.bind(null, agent);
1056
+ agent.getMapIds = getMapIds.bind(null, agent);
1057
+
1058
+ // Deprecated.
1059
+ agent.getBranches = getBranches.bind(null, agent);
1060
+ agent.getLink = getLink.bind(null, agent);
1061
+ agent.getMap = getMap.bind(null, agent);
1062
+
1063
+ return agent;
1064
+ });
1065
+ }
1066
+
1067
+ function fromSegment(obj) {
1068
+ return getAgent(obj.meta.agentUrl || obj.meta.applicationLocation).then(function (agent) {
1069
+ var segment = segmentify(agent, obj);
1070
+ return { agent: agent, segment: segment };
1071
+ });
1072
+ }
1073
+
1074
+ function loadLink(obj) {
1075
+ deprecated('loadLink(obj)', 'fromSegment(obj)');
1076
+
1077
+ return fromSegment(obj).then(function (_ref) {
1078
+ var segment = _ref.segment;
1079
+ return segment;
1080
+ });
1081
+ }
1082
+
1083
+ function resolveLinks(segments) {
1084
+ return Promise.all(segments.map(function (segment) {
1085
+ if (!segment.link.state) {
1086
+ return loadLink(segment).then(function (res) {
1087
+ return merge(res, segment);
1088
+ });
1089
+ }
1090
+ return Promise.resolve(segment);
1091
+ }));
1092
+ }
1093
+
1094
+ function wrap(arrayOrObject) {
1095
+ if (arrayOrObject instanceof Array) {
1096
+ return arrayOrObject;
1097
+ }
1098
+ return [arrayOrObject];
1099
+ }
1100
+
1101
+ function parseIfJson(object) {
1102
+ if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') {
1103
+ object = JSON.parse(object);
1104
+ }
1105
+ return object;
1106
+ }
1107
+
1108
+ function flatten(arr) {
1109
+ var _ref;
1110
+
1111
+ var flat = (_ref = []).concat.apply(_ref, toConsumableArray(arr));
1112
+ return flat.some(Array.isArray) ? flatten(flat) : flat;
1113
+ }
1114
+
1115
+ function tagsSet(chainscript) {
1116
+ return new Set(flatten(chainscript.map(function (segment) {
1117
+ return segment.link.meta.tags;
1118
+ })));
1119
+ }
1120
+
1121
+ var defaultOptions = {
1122
+ withArgs: false,
1123
+ duration: 750,
1124
+ verticalSpacing: 1.2,
1125
+ polygonSize: { width: 78, height: 91 },
1126
+ getBoxSize: function getBoxSize() {
1127
+ var self = this;
1128
+ return { width: self.polygonSize.width, height: 25 };
1129
+ },
1130
+ getArrowLength: function getArrowLength() {
1131
+ return this.polygonSize.width;
1132
+ },
1133
+ getSegmentText: function getSegmentText(node) {
1134
+ return compactHash(node.data.meta.linkHash);
1135
+ },
1136
+ getLinkText: function getLinkText(node) {
1137
+ return node.target.data.link.meta.action + (this.withArgs ? '(' + node.target.data.link.meta.arguments.join(', ') + ')' : '');
1138
+ },
1139
+ onclick: function onclick() {},
1140
+ onTag: function onTag() {}
1141
+ };
1142
+
1143
+ var ChainTreeBuilder = function () {
1144
+ function ChainTreeBuilder(element) {
1145
+ classCallCheck(this, ChainTreeBuilder);
1146
+
1147
+ this.chainTree = new ChainTree(element);
1148
+ }
1149
+
1150
+ createClass(ChainTreeBuilder, [{
1151
+ key: 'build',
1152
+ value: function build(map, options) {
1153
+ var _this = this;
1154
+
1155
+ this.onTag = options.onTag;
1156
+ if (map.id && map.applicationUrl) {
1157
+ return this._load(map).then(function (segments) {
1158
+ return _this._display(segments, options);
1159
+ });
1160
+ } else if (map.chainscript && map.chainscript.length) {
1161
+ try {
1162
+ return resolveLinks(wrap(parseIfJson(map.chainscript))).then(function (segments) {
1163
+ return _this._display(segments, options);
1164
+ });
1165
+ } catch (err) {
1166
+ return Promise.reject(err);
1167
+ }
1168
+ }
1169
+ return Promise.resolve();
1170
+ }
1171
+ }, {
1172
+ key: '_display',
1173
+ value: function _display(segments, options) {
1174
+ this.chainTree.display(segments, _extends({}, defaultOptions, options));
1175
+ this._notifyTags(segments);
1176
+ return segments;
1177
+ }
1178
+ }, {
1179
+ key: '_notifyTags',
1180
+ value: function _notifyTags(chainscript) {
1181
+ tagsSet(chainscript).forEach(this.onTag);
1182
+ }
1183
+ }, {
1184
+ key: '_load',
1185
+ value: function _load(map) {
1186
+ return getAgent(map.applicationUrl).then(function (app) {
1187
+ return app.findSegments({ mapId: map.id });
1188
+ }).catch(function (res) {
1189
+ return console.log(res);
1190
+ });
1191
+ }
1192
+ }]);
1193
+ return ChainTreeBuilder;
1194
+ }();
1195
+
1196
+ var index$4 = createCommonjsModule(function (module) {
1197
+ /*
1198
+ The original version of this code is taken from Douglas Crockford's json2.js:
1199
+ https://github.com/douglascrockford/JSON-js/blob/master/json2.js
1200
+
1201
+ I made some modifications to ensure a canonical output.
1202
+ */
1203
+
1204
+ function f(n) {
1205
+ // Format integers to have at least two digits.
1206
+ return n < 10 ? '0' + n : n;
1207
+ }
1208
+
1209
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
1210
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
1211
+ gap,
1212
+ indent,
1213
+ meta = { // table of character substitutions
1214
+ '\b': '\\b',
1215
+ '\t': '\\t',
1216
+ '\n': '\\n',
1217
+ '\f': '\\f',
1218
+ '\r': '\\r',
1219
+ '"' : '\\"',
1220
+ '\\': '\\\\'
1221
+ },
1222
+ rep;
1223
+
1224
+
1225
+ function quote(string) {
1226
+
1227
+ // If the string contains no control characters, no quote characters, and no
1228
+ // backslash characters, then we can safely slap some quotes around it.
1229
+ // Otherwise we must also replace the offending characters with safe escape
1230
+ // sequences.
1231
+
1232
+ escapable.lastIndex = 0;
1233
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
1234
+ var c = meta[a];
1235
+ return typeof c === 'string'
1236
+ ? c
1237
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
1238
+ }) + '"' : '"' + string + '"';
1239
+ }
1240
+
1241
+
1242
+ function str(key, holder) {
1243
+
1244
+ // Produce a string from holder[key].
1245
+
1246
+ var i, // The loop counter.
1247
+ k, // The member key.
1248
+ v, // The member value.
1249
+ length,
1250
+ mind = gap,
1251
+ partial,
1252
+ value = holder[key];
1253
+
1254
+ // If the value has a toJSON method, call it to obtain a replacement value.
1255
+
1256
+ if (value && typeof value === 'object' &&
1257
+ typeof value.toJSON === 'function') {
1258
+ value = value.toJSON(key);
1259
+ }
1260
+
1261
+ // If we were called with a replacer function, then call the replacer to
1262
+ // obtain a replacement value.
1263
+
1264
+ if (typeof rep === 'function') {
1265
+ value = rep.call(holder, key, value);
1266
+ }
1267
+
1268
+ // What happens next depends on the value's type.
1269
+
1270
+ switch (typeof value) {
1271
+ case 'string':
1272
+ return quote(value);
1273
+
1274
+ case 'number':
1275
+
1276
+ // JSON numbers must be finite. Encode non-finite numbers as null.
1277
+
1278
+ return isFinite(value) ? String(value) : 'null';
1279
+
1280
+ case 'boolean':
1281
+ case 'null':
1282
+
1283
+ // If the value is a boolean or null, convert it to a string. Note:
1284
+ // typeof null does not produce 'null'. The case is included here in
1285
+ // the remote chance that this gets fixed someday.
1286
+
1287
+ return String(value);
1288
+
1289
+ // If the type is 'object', we might be dealing with an object or an array or
1290
+ // null.
1291
+
1292
+ case 'object':
1293
+
1294
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
1295
+ // so watch out for that case.
1296
+
1297
+ if (!value) {
1298
+ return 'null';
1299
+ }
1300
+
1301
+ // Make an array to hold the partial results of stringifying this object value.
1302
+
1303
+ gap += indent;
1304
+ partial = [];
1305
+
1306
+ // Is the value an array?
1307
+
1308
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
1309
+
1310
+ // The value is an array. Stringify every element. Use null as a placeholder
1311
+ // for non-JSON values.
1312
+
1313
+ length = value.length;
1314
+ for (i = 0; i < length; i += 1) {
1315
+ partial[i] = str(i, value) || 'null';
1316
+ }
1317
+
1318
+ // Join all of the elements together, separated with commas, and wrap them in
1319
+ // brackets.
1320
+
1321
+ v = partial.length === 0
1322
+ ? '[]'
1323
+ : gap
1324
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
1325
+ : '[' + partial.join(',') + ']';
1326
+ gap = mind;
1327
+ return v;
1328
+ }
1329
+
1330
+ // If the replacer is an array, use it to select the members to be stringified.
1331
+
1332
+ if (rep && typeof rep === 'object') {
1333
+ length = rep.length;
1334
+ for (i = 0; i < length; i += 1) {
1335
+ if (typeof rep[i] === 'string') {
1336
+ k = rep[i];
1337
+ v = str(k, value);
1338
+ if (v) {
1339
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
1340
+ }
1341
+ }
1342
+ }
1343
+ } else {
1344
+
1345
+ // Otherwise, iterate through all of the keys in the object.
1346
+ var keysSorted = Object.keys(value).sort()
1347
+ for (i in keysSorted) {
1348
+ k = keysSorted[i]
1349
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
1350
+ v = str(k, value);
1351
+ if (v) {
1352
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
1353
+ }
1354
+ }
1355
+ }
1356
+ }
1357
+
1358
+ // Join all of the member texts together, separated with commas,
1359
+ // and wrap them in braces.
1360
+
1361
+ v = partial.length === 0
1362
+ ? '{}'
1363
+ : gap
1364
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
1365
+ : '{' + partial.join(',') + '}';
1366
+ gap = mind;
1367
+ return v;
1368
+ }
1369
+ }
1370
+
1371
+ // If the JSON object does not yet have a stringify method, give it one.
1372
+ var stringify = function (value, replacer, space) {
1373
+
1374
+ // The stringify method takes a value and an optional replacer, and an optional
1375
+ // space parameter, and returns a JSON text. The replacer can be a function
1376
+ // that can replace values, or an array of strings that will select the keys.
1377
+ // A default replacer method can be provided. Use of the space parameter can
1378
+ // produce text that is more easily readable.
1379
+
1380
+ var i;
1381
+ gap = '';
1382
+ indent = '';
1383
+
1384
+ // If the space parameter is a number, make an indent string containing that
1385
+ // many spaces.
1386
+
1387
+ if (typeof space === 'number') {
1388
+ for (i = 0; i < space; i += 1) {
1389
+ indent += ' ';
1390
+ }
1391
+
1392
+ // If the space parameter is a string, it will be used as the indent string.
1393
+
1394
+ } else if (typeof space === 'string') {
1395
+ indent = space;
1396
+ }
1397
+
1398
+ // If there is a replacer, it must be a function or an array.
1399
+ // Otherwise, throw an error.
1400
+
1401
+ rep = replacer;
1402
+ if (replacer && typeof replacer !== 'function' &&
1403
+ (typeof replacer !== 'object' ||
1404
+ typeof replacer.length !== 'number')) {
1405
+ throw new Error('JSON.stringify');
1406
+ }
1407
+
1408
+ // Make a fake root object containing our value under the key of ''.
1409
+ // Return the result of stringifying the value.
1410
+
1411
+ return str('', {'': value});
1412
+ };
1413
+
1414
+ module.exports = stringify
1415
+ });
1416
+
1417
+ var stringify = interopDefault(index$4);
1418
+
1419
+ var sha256 = createCommonjsModule(function (module) {
1420
+ /*
1421
+ * js-sha256 v0.3.0
1422
+ * https://github.com/emn178/js-sha256
1423
+ *
1424
+ * Copyright 2014-2015, emn178@gmail.com
1425
+ *
1426
+ * Licensed under the MIT license:
1427
+ * http://www.opensource.org/licenses/MIT
1428
+ */
1429
+ ;(function(root, undefined) {
1430
+ 'use strict';
1431
+
1432
+ var NODE_JS = typeof(module) != 'undefined';
1433
+ if(NODE_JS) {
1434
+ root = commonjsGlobal;
1435
+ }
1436
+ var TYPED_ARRAY = typeof(Uint8Array) != 'undefined';
1437
+ var HEX_CHARS = '0123456789abcdef'.split('');
1438
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
1439
+ var SHIFT = [24, 16, 8, 0];
1440
+ var K =[0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
1441
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
1442
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
1443
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
1444
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
1445
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
1446
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
1447
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
1448
+
1449
+ var blocks = [];
1450
+
1451
+ var sha224 = function(message) {
1452
+ return sha256(message, true);
1453
+ };
1454
+
1455
+ var sha256 = function(message, is224) {
1456
+ var notString = typeof(message) != 'string';
1457
+ if(notString && message.constructor == root.ArrayBuffer) {
1458
+ message = new Uint8Array(message);
1459
+ }
1460
+
1461
+ var h0, h1, h2, h3, h4, h5, h6, h7, block, code, first = true, end = false,
1462
+ i, j, index = 0, start = 0, bytes = 0, length = message.length,
1463
+ s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
1464
+
1465
+ if(is224) {
1466
+ h0 = 0xc1059ed8;
1467
+ h1 = 0x367cd507;
1468
+ h2 = 0x3070dd17;
1469
+ h3 = 0xf70e5939;
1470
+ h4 = 0xffc00b31;
1471
+ h5 = 0x68581511;
1472
+ h6 = 0x64f98fa7;
1473
+ h7 = 0xbefa4fa4;
1474
+ } else { // 256
1475
+ h0 = 0x6a09e667;
1476
+ h1 = 0xbb67ae85;
1477
+ h2 = 0x3c6ef372;
1478
+ h3 = 0xa54ff53a;
1479
+ h4 = 0x510e527f;
1480
+ h5 = 0x9b05688c;
1481
+ h6 = 0x1f83d9ab;
1482
+ h7 = 0x5be0cd19;
1483
+ }
1484
+ block = 0;
1485
+ do {
1486
+ blocks[0] = block;
1487
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
1488
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
1489
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
1490
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
1491
+ if(notString) {
1492
+ for (i = start;index < length && i < 64; ++index) {
1493
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
1494
+ }
1495
+ } else {
1496
+ for (i = start;index < length && i < 64; ++index) {
1497
+ code = message.charCodeAt(index);
1498
+ if (code < 0x80) {
1499
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
1500
+ } else if (code < 0x800) {
1501
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
1502
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
1503
+ } else if (code < 0xd800 || code >= 0xe000) {
1504
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
1505
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
1506
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
1507
+ } else {
1508
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
1509
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
1510
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
1511
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
1512
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
1513
+ }
1514
+ }
1515
+ }
1516
+ bytes += i - start;
1517
+ start = i - 64;
1518
+ if(index == length) {
1519
+ blocks[i >> 2] |= EXTRA[i & 3];
1520
+ ++index;
1521
+ }
1522
+ block = blocks[16];
1523
+ if(index > length && i < 56) {
1524
+ blocks[15] = bytes << 3;
1525
+ end = true;
1526
+ }
1527
+
1528
+ var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
1529
+ for(j = 16;j < 64;++j) {
1530
+ // rightrotate
1531
+ t1 = blocks[j - 15];
1532
+ s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
1533
+ t1 = blocks[j - 2];
1534
+ s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
1535
+ blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
1536
+ }
1537
+
1538
+ bc = b & c;
1539
+ for(j = 0;j < 64;j += 4) {
1540
+ if(first) {
1541
+ if(is224) {
1542
+ ab = 300032;
1543
+ t1 = blocks[0] - 1413257819;
1544
+ h = t1 - 150054599 << 0;
1545
+ d = t1 + 24177077 << 0;
1546
+ } else {
1547
+ ab = 704751109;
1548
+ t1 = blocks[0] - 210244248;
1549
+ h = t1 - 1521486534 << 0;
1550
+ d = t1 + 143694565 << 0;
1551
+ }
1552
+ first = false;
1553
+ } else {
1554
+ s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
1555
+ s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
1556
+ ab = a & b;
1557
+ maj = ab ^ (a & c) ^ bc;
1558
+ ch = (e & f) ^ (~e & g);
1559
+ t1 = h + s1 + ch + K[j] + blocks[j];
1560
+ t2 = s0 + maj;
1561
+ h = d + t1 << 0;
1562
+ d = t1 + t2 << 0;
1563
+ }
1564
+ s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
1565
+ s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
1566
+ da = d & a;
1567
+ maj = da ^ (d & b) ^ ab;
1568
+ ch = (h & e) ^ (~h & f);
1569
+ t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
1570
+ t2 = s0 + maj;
1571
+ g = c + t1 << 0;
1572
+ c = t1 + t2 << 0;
1573
+ s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
1574
+ s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
1575
+ cd = c & d;
1576
+ maj = cd ^ (c & a) ^ da;
1577
+ ch = (g & h) ^ (~g & e);
1578
+ t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
1579
+ t2 = s0 + maj;
1580
+ f = b + t1 << 0;
1581
+ b = t1 + t2 << 0;
1582
+ s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
1583
+ s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
1584
+ bc = b & c;
1585
+ maj = bc ^ (b & d) ^ cd;
1586
+ ch = (f & g) ^ (~f & h);
1587
+ t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
1588
+ t2 = s0 + maj;
1589
+ e = a + t1 << 0;
1590
+ a = t1 + t2 << 0;
1591
+ }
1592
+
1593
+ h0 = h0 + a << 0;
1594
+ h1 = h1 + b << 0;
1595
+ h2 = h2 + c << 0;
1596
+ h3 = h3 + d << 0;
1597
+ h4 = h4 + e << 0;
1598
+ h5 = h5 + f << 0;
1599
+ h6 = h6 + g << 0;
1600
+ h7 = h7 + h << 0;
1601
+ } while(!end);
1602
+
1603
+ var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
1604
+ HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
1605
+ HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
1606
+ HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
1607
+ HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
1608
+ HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
1609
+ HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
1610
+ HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
1611
+ HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
1612
+ HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
1613
+ HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
1614
+ HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
1615
+ HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
1616
+ HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
1617
+ HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
1618
+ HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
1619
+ HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
1620
+ HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
1621
+ HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
1622
+ HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
1623
+ HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] +
1624
+ HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] +
1625
+ HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] +
1626
+ HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
1627
+ HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] +
1628
+ HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
1629
+ HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
1630
+ HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
1631
+ if(!is224) {
1632
+ hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
1633
+ HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
1634
+ HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
1635
+ HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
1636
+ }
1637
+ return hex;
1638
+ };
1639
+
1640
+ if(!root.JS_SHA256_TEST && NODE_JS) {
1641
+ sha256.sha256 = sha256;
1642
+ sha256.sha224 = sha224;
1643
+ module.exports = sha256;
1644
+ } else if(root) {
1645
+ root.sha256 = sha256;
1646
+ root.sha224 = sha224;
1647
+ }
1648
+ }(commonjsGlobal));
1649
+ });
1650
+
1651
+ var sha256$1 = interopDefault(sha256);
1652
+
1653
+ /**
1654
+ * Canonically hashes a json object.
1655
+ * @param {Object} obj the json object
1656
+ */
1657
+ function hashJson(obj) {
1658
+ return sha256$1(stringify(obj));
1659
+ }
1660
+
1661
+ var _buffer;
1662
+ var _slowbuffer;
1663
+ var _INSPECT_MAX_BYTES;
1664
+ (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(_dereq_,___mod,_expor_){
1665
+ 'use strict'
1666
+
1667
+ _expor_.toByteArray = toByteArray
1668
+ _expor_.fromByteArray = fromByteArray
1669
+
1670
+ var lookup = []
1671
+ var revLookup = []
1672
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
1673
+
1674
+ function init () {
1675
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
1676
+ for (var i = 0, len = code.length; i < len; ++i) {
1677
+ lookup[i] = code[i]
1678
+ revLookup[code.charCodeAt(i)] = i
1679
+ }
1680
+
1681
+ revLookup['-'.charCodeAt(0)] = 62
1682
+ revLookup['_'.charCodeAt(0)] = 63
1683
+ }
1684
+
1685
+ init()
1686
+
1687
+ function toByteArray (b64) {
1688
+ var i, j, l, tmp, placeHolders, arr
1689
+ var len = b64.length
1690
+
1691
+ if (len % 4 > 0) {
1692
+ throw new Error('Invalid string. Length must be a multiple of 4')
1693
+ }
1694
+
1695
+ // the number of equal signs (place holders)
1696
+ // if there are two placeholders, than the two characters before it
1697
+ // represent one byte
1698
+ // if there is only one, then the three characters before it represent 2 bytes
1699
+ // this is just a cheap hack to not do indexOf twice
1700
+ placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
1701
+
1702
+ // base64 is 4/3 + up to two characters of the original data
1703
+ arr = new Arr(len * 3 / 4 - placeHolders)
1704
+
1705
+ // if there are placeholders, only get up to the last complete 4 chars
1706
+ l = placeHolders > 0 ? len - 4 : len
1707
+
1708
+ var L = 0
1709
+
1710
+ for (i = 0, j = 0; i < l; i += 4, j += 3) {
1711
+ tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
1712
+ arr[L++] = (tmp >> 16) & 0xFF
1713
+ arr[L++] = (tmp >> 8) & 0xFF
1714
+ arr[L++] = tmp & 0xFF
1715
+ }
1716
+
1717
+ if (placeHolders === 2) {
1718
+ tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
1719
+ arr[L++] = tmp & 0xFF
1720
+ } else if (placeHolders === 1) {
1721
+ tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
1722
+ arr[L++] = (tmp >> 8) & 0xFF
1723
+ arr[L++] = tmp & 0xFF
1724
+ }
1725
+
1726
+ return arr
1727
+ }
1728
+
1729
+ function tripletToBase64 (num) {
1730
+ return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
1731
+ }
1732
+
1733
+ function encodeChunk (uint8, start, end) {
1734
+ var tmp
1735
+ var output = []
1736
+ for (var i = start; i < end; i += 3) {
1737
+ tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
1738
+ output.push(tripletToBase64(tmp))
1739
+ }
1740
+ return output.join('')
1741
+ }
1742
+
1743
+ function fromByteArray (uint8) {
1744
+ var tmp
1745
+ var len = uint8.length
1746
+ var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
1747
+ var output = ''
1748
+ var parts = []
1749
+ var maxChunkLength = 16383 // must be multiple of 3
1750
+
1751
+ // go through the array every three bytes, we'll deal with trailing stuff later
1752
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
1753
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
1754
+ }
1755
+
1756
+ // pad the end with zeros, but make sure to not forget the extra bytes
1757
+ if (extraBytes === 1) {
1758
+ tmp = uint8[len - 1]
1759
+ output += lookup[tmp >> 2]
1760
+ output += lookup[(tmp << 4) & 0x3F]
1761
+ output += '=='
1762
+ } else if (extraBytes === 2) {
1763
+ tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
1764
+ output += lookup[tmp >> 10]
1765
+ output += lookup[(tmp >> 4) & 0x3F]
1766
+ output += lookup[(tmp << 2) & 0x3F]
1767
+ output += '='
1768
+ }
1769
+
1770
+ parts.push(output)
1771
+
1772
+ return parts.join('')
1773
+ }
1774
+
1775
+ },{}],2:[function(_dereq_,___mod,_expor_){
1776
+ (function (global){
1777
+ /*!
1778
+ * The buffer module from node.js, for the browser.
1779
+ *
1780
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
1781
+ * @license MIT
1782
+ */
1783
+ /* eslint-disable no-proto */
1784
+
1785
+ 'use strict'
1786
+
1787
+ var base64 = _dereq_('base64-js')
1788
+ var ieee754 = _dereq_('ieee754')
1789
+ var isArray = _dereq_('isarray')
1790
+
1791
+ _expor_.Buffer = Buffer
1792
+ _expor_.SlowBuffer = SlowBuffer
1793
+ _expor_.INSPECT_MAX_BYTES = 50
1794
+
1795
+ /**
1796
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
1797
+ * === true Use Uint8Array implementation (fastest)
1798
+ * === false Use Object implementation (most compatible, even IE6)
1799
+ *
1800
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
1801
+ * Opera 11.6+, iOS 4.2+.
1802
+ *
1803
+ * Due to various browser bugs, sometimes the Object implementation will be used even
1804
+ * when the browser supports typed arrays.
1805
+ *
1806
+ * Note:
1807
+ *
1808
+ * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
1809
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
1810
+ *
1811
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
1812
+ *
1813
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
1814
+ * incorrect length in some situations.
1815
+
1816
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
1817
+ * get the Object implementation, which is slower but behaves correctly.
1818
+ */
1819
+ Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
1820
+ ? global.TYPED_ARRAY_SUPPORT
1821
+ : typedArraySupport()
1822
+
1823
+ /*
1824
+ * Export kMaxLength after typed array support is determined.
1825
+ */
1826
+ _expor_.kMaxLength = kMaxLength()
1827
+
1828
+ function typedArraySupport () {
1829
+ try {
1830
+ var arr = new Uint8Array(1)
1831
+ arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
1832
+ return arr.foo() === 42 && // typed array instances can be augmented
1833
+ typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
1834
+ arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
1835
+ } catch (e) {
1836
+ return false
1837
+ }
1838
+ }
1839
+
1840
+ function kMaxLength () {
1841
+ return Buffer.TYPED_ARRAY_SUPPORT
1842
+ ? 0x7fffffff
1843
+ : 0x3fffffff
1844
+ }
1845
+
1846
+ function createBuffer (that, length) {
1847
+ if (kMaxLength() < length) {
1848
+ throw new RangeError('Invalid typed array length')
1849
+ }
1850
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1851
+ // Return an augmented `Uint8Array` instance, for best performance
1852
+ that = new Uint8Array(length)
1853
+ that.__proto__ = Buffer.prototype
1854
+ } else {
1855
+ // Fallback: Return an object instance of the Buffer class
1856
+ if (that === null) {
1857
+ that = new Buffer(length)
1858
+ }
1859
+ that.length = length
1860
+ }
1861
+
1862
+ return that
1863
+ }
1864
+
1865
+ /**
1866
+ * The Buffer constructor returns instances of `Uint8Array` that have their
1867
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
1868
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
1869
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
1870
+ * returns a single octet.
1871
+ *
1872
+ * The `Uint8Array` prototype remains unmodified.
1873
+ */
1874
+
1875
+ function Buffer (arg, encodingOrOffset, length) {
1876
+ if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
1877
+ return new Buffer(arg, encodingOrOffset, length)
1878
+ }
1879
+
1880
+ // Common case.
1881
+ if (typeof arg === 'number') {
1882
+ if (typeof encodingOrOffset === 'string') {
1883
+ throw new Error(
1884
+ 'If encoding is specified then the first argument must be a string'
1885
+ )
1886
+ }
1887
+ return allocUnsafe(this, arg)
1888
+ }
1889
+ return from(this, arg, encodingOrOffset, length)
1890
+ }
1891
+
1892
+ Buffer.poolSize = 8192 // not used by this implementation
1893
+
1894
+ // TODO: Legacy, not needed anymore. Remove in next major version.
1895
+ Buffer._augment = function (arr) {
1896
+ arr.__proto__ = Buffer.prototype
1897
+ return arr
1898
+ }
1899
+
1900
+ function from (that, value, encodingOrOffset, length) {
1901
+ if (typeof value === 'number') {
1902
+ throw new TypeError('"value" argument must not be a number')
1903
+ }
1904
+
1905
+ if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
1906
+ return fromArrayBuffer(that, value, encodingOrOffset, length)
1907
+ }
1908
+
1909
+ if (typeof value === 'string') {
1910
+ return fromString(that, value, encodingOrOffset)
1911
+ }
1912
+
1913
+ return fromObject(that, value)
1914
+ }
1915
+
1916
+ /**
1917
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
1918
+ * if value is a number.
1919
+ * Buffer.from(str[, encoding])
1920
+ * Buffer.from(array)
1921
+ * Buffer.from(buffer)
1922
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
1923
+ **/
1924
+ Buffer.from = function (value, encodingOrOffset, length) {
1925
+ return from(null, value, encodingOrOffset, length)
1926
+ }
1927
+
1928
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1929
+ Buffer.prototype.__proto__ = Uint8Array.prototype
1930
+ Buffer.__proto__ = Uint8Array
1931
+ if (typeof Symbol !== 'undefined' && Symbol.species &&
1932
+ Buffer[Symbol.species] === Buffer) {
1933
+ // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
1934
+ Object.defineProperty(Buffer, Symbol.species, {
1935
+ value: null,
1936
+ configurable: true
1937
+ })
1938
+ }
1939
+ }
1940
+
1941
+ function assertSize (size) {
1942
+ if (typeof size !== 'number') {
1943
+ throw new TypeError('"size" argument must be a number')
1944
+ }
1945
+ }
1946
+
1947
+ function alloc (that, size, fill, encoding) {
1948
+ assertSize(size)
1949
+ if (size <= 0) {
1950
+ return createBuffer(that, size)
1951
+ }
1952
+ if (fill !== undefined) {
1953
+ // Only pay attention to encoding if it's a string. This
1954
+ // prevents accidentally sending in a number that would
1955
+ // be interpretted as a start offset.
1956
+ return typeof encoding === 'string'
1957
+ ? createBuffer(that, size).fill(fill, encoding)
1958
+ : createBuffer(that, size).fill(fill)
1959
+ }
1960
+ return createBuffer(that, size)
1961
+ }
1962
+
1963
+ /**
1964
+ * Creates a new filled Buffer instance.
1965
+ * alloc(size[, fill[, encoding]])
1966
+ **/
1967
+ Buffer.alloc = function (size, fill, encoding) {
1968
+ return alloc(null, size, fill, encoding)
1969
+ }
1970
+
1971
+ function allocUnsafe (that, size) {
1972
+ assertSize(size)
1973
+ that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
1974
+ if (!Buffer.TYPED_ARRAY_SUPPORT) {
1975
+ for (var i = 0; i < size; ++i) {
1976
+ that[i] = 0
1977
+ }
1978
+ }
1979
+ return that
1980
+ }
1981
+
1982
+ /**
1983
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
1984
+ * */
1985
+ Buffer.allocUnsafe = function (size) {
1986
+ return allocUnsafe(null, size)
1987
+ }
1988
+ /**
1989
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
1990
+ */
1991
+ Buffer.allocUnsafeSlow = function (size) {
1992
+ return allocUnsafe(null, size)
1993
+ }
1994
+
1995
+ function fromString (that, string, encoding) {
1996
+ if (typeof encoding !== 'string' || encoding === '') {
1997
+ encoding = 'utf8'
1998
+ }
1999
+
2000
+ if (!Buffer.isEncoding(encoding)) {
2001
+ throw new TypeError('"encoding" must be a valid string encoding')
2002
+ }
2003
+
2004
+ var length = byteLength(string, encoding) | 0
2005
+ that = createBuffer(that, length)
2006
+
2007
+ that.write(string, encoding)
2008
+ return that
2009
+ }
2010
+
2011
+ function fromArrayLike (that, array) {
2012
+ var length = checked(array.length) | 0
2013
+ that = createBuffer(that, length)
2014
+ for (var i = 0; i < length; i += 1) {
2015
+ that[i] = array[i] & 255
2016
+ }
2017
+ return that
2018
+ }
2019
+
2020
+ function fromArrayBuffer (that, array, byteOffset, length) {
2021
+ array.byteLength // this throws if `array` is not a valid ArrayBuffer
2022
+
2023
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
2024
+ throw new RangeError('\'offset\' is out of bounds')
2025
+ }
2026
+
2027
+ if (array.byteLength < byteOffset + (length || 0)) {
2028
+ throw new RangeError('\'length\' is out of bounds')
2029
+ }
2030
+
2031
+ if (byteOffset === undefined && length === undefined) {
2032
+ array = new Uint8Array(array)
2033
+ } else if (length === undefined) {
2034
+ array = new Uint8Array(array, byteOffset)
2035
+ } else {
2036
+ array = new Uint8Array(array, byteOffset, length)
2037
+ }
2038
+
2039
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
2040
+ // Return an augmented `Uint8Array` instance, for best performance
2041
+ that = array
2042
+ that.__proto__ = Buffer.prototype
2043
+ } else {
2044
+ // Fallback: Return an object instance of the Buffer class
2045
+ that = fromArrayLike(that, array)
2046
+ }
2047
+ return that
2048
+ }
2049
+
2050
+ function fromObject (that, obj) {
2051
+ if (Buffer.isBuffer(obj)) {
2052
+ var len = checked(obj.length) | 0
2053
+ that = createBuffer(that, len)
2054
+
2055
+ if (that.length === 0) {
2056
+ return that
2057
+ }
2058
+
2059
+ obj.copy(that, 0, 0, len)
2060
+ return that
2061
+ }
2062
+
2063
+ if (obj) {
2064
+ if ((typeof ArrayBuffer !== 'undefined' &&
2065
+ obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
2066
+ if (typeof obj.length !== 'number' || isnan(obj.length)) {
2067
+ return createBuffer(that, 0)
2068
+ }
2069
+ return fromArrayLike(that, obj)
2070
+ }
2071
+
2072
+ if (obj.type === 'Buffer' && isArray(obj.data)) {
2073
+ return fromArrayLike(that, obj.data)
2074
+ }
2075
+ }
2076
+
2077
+ throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
2078
+ }
2079
+
2080
+ function checked (length) {
2081
+ // Note: cannot use `length < kMaxLength` here because that fails when
2082
+ // length is NaN (which is otherwise coerced to zero.)
2083
+ if (length >= kMaxLength()) {
2084
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
2085
+ 'size: 0x' + kMaxLength().toString(16) + ' bytes')
2086
+ }
2087
+ return length | 0
2088
+ }
2089
+
2090
+ function SlowBuffer (length) {
2091
+ if (+length != length) { // eslint-disable-line eqeqeq
2092
+ length = 0
2093
+ }
2094
+ return Buffer.alloc(+length)
2095
+ }
2096
+
2097
+ Buffer.isBuffer = function isBuffer (b) {
2098
+ return !!(b != null && b._isBuffer)
2099
+ }
2100
+
2101
+ Buffer.compare = function compare (a, b) {
2102
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
2103
+ throw new TypeError('Arguments must be Buffers')
2104
+ }
2105
+
2106
+ if (a === b) return 0
2107
+
2108
+ var x = a.length
2109
+ var y = b.length
2110
+
2111
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
2112
+ if (a[i] !== b[i]) {
2113
+ x = a[i]
2114
+ y = b[i]
2115
+ break
2116
+ }
2117
+ }
2118
+
2119
+ if (x < y) return -1
2120
+ if (y < x) return 1
2121
+ return 0
2122
+ }
2123
+
2124
+ Buffer.isEncoding = function isEncoding (encoding) {
2125
+ switch (String(encoding).toLowerCase()) {
2126
+ case 'hex':
2127
+ case 'utf8':
2128
+ case 'utf-8':
2129
+ case 'ascii':
2130
+ case 'binary':
2131
+ case 'base64':
2132
+ case 'raw':
2133
+ case 'ucs2':
2134
+ case 'ucs-2':
2135
+ case 'utf16le':
2136
+ case 'utf-16le':
2137
+ return true
2138
+ default:
2139
+ return false
2140
+ }
2141
+ }
2142
+
2143
+ Buffer.concat = function concat (list, length) {
2144
+ if (!isArray(list)) {
2145
+ throw new TypeError('"list" argument must be an Array of Buffers')
2146
+ }
2147
+
2148
+ if (list.length === 0) {
2149
+ return Buffer.alloc(0)
2150
+ }
2151
+
2152
+ var i
2153
+ if (length === undefined) {
2154
+ length = 0
2155
+ for (i = 0; i < list.length; ++i) {
2156
+ length += list[i].length
2157
+ }
2158
+ }
2159
+
2160
+ var buffer = Buffer.allocUnsafe(length)
2161
+ var pos = 0
2162
+ for (i = 0; i < list.length; ++i) {
2163
+ var buf = list[i]
2164
+ if (!Buffer.isBuffer(buf)) {
2165
+ throw new TypeError('"list" argument must be an Array of Buffers')
2166
+ }
2167
+ buf.copy(buffer, pos)
2168
+ pos += buf.length
2169
+ }
2170
+ return buffer
2171
+ }
2172
+
2173
+ function byteLength (string, encoding) {
2174
+ if (Buffer.isBuffer(string)) {
2175
+ return string.length
2176
+ }
2177
+ if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
2178
+ (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
2179
+ return string.byteLength
2180
+ }
2181
+ if (typeof string !== 'string') {
2182
+ string = '' + string
2183
+ }
2184
+
2185
+ var len = string.length
2186
+ if (len === 0) return 0
2187
+
2188
+ // Use a for loop to avoid recursion
2189
+ var loweredCase = false
2190
+ for (;;) {
2191
+ switch (encoding) {
2192
+ case 'ascii':
2193
+ case 'binary':
2194
+ case 'raw':
2195
+ case 'raws':
2196
+ return len
2197
+ case 'utf8':
2198
+ case 'utf-8':
2199
+ case undefined:
2200
+ return utf8ToBytes(string).length
2201
+ case 'ucs2':
2202
+ case 'ucs-2':
2203
+ case 'utf16le':
2204
+ case 'utf-16le':
2205
+ return len * 2
2206
+ case 'hex':
2207
+ return len >>> 1
2208
+ case 'base64':
2209
+ return base64ToBytes(string).length
2210
+ default:
2211
+ if (loweredCase) return utf8ToBytes(string).length // assume utf8
2212
+ encoding = ('' + encoding).toLowerCase()
2213
+ loweredCase = true
2214
+ }
2215
+ }
2216
+ }
2217
+ Buffer.byteLength = byteLength
2218
+
2219
+ function slowToString (encoding, start, end) {
2220
+ var loweredCase = false
2221
+
2222
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
2223
+ // property of a typed array.
2224
+
2225
+ // This behaves neither like String nor Uint8Array in that we set start/end
2226
+ // to their upper/lower bounds if the value passed is out of range.
2227
+ // undefined is handled specially as per ECMA-262 6th Edition,
2228
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
2229
+ if (start === undefined || start < 0) {
2230
+ start = 0
2231
+ }
2232
+ // Return early if start > this.length. Done here to prevent potential uint32
2233
+ // coercion fail below.
2234
+ if (start > this.length) {
2235
+ return ''
2236
+ }
2237
+
2238
+ if (end === undefined || end > this.length) {
2239
+ end = this.length
2240
+ }
2241
+
2242
+ if (end <= 0) {
2243
+ return ''
2244
+ }
2245
+
2246
+ // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
2247
+ end >>>= 0
2248
+ start >>>= 0
2249
+
2250
+ if (end <= start) {
2251
+ return ''
2252
+ }
2253
+
2254
+ if (!encoding) encoding = 'utf8'
2255
+
2256
+ while (true) {
2257
+ switch (encoding) {
2258
+ case 'hex':
2259
+ return hexSlice(this, start, end)
2260
+
2261
+ case 'utf8':
2262
+ case 'utf-8':
2263
+ return utf8Slice(this, start, end)
2264
+
2265
+ case 'ascii':
2266
+ return asciiSlice(this, start, end)
2267
+
2268
+ case 'binary':
2269
+ return binarySlice(this, start, end)
2270
+
2271
+ case 'base64':
2272
+ return base64Slice(this, start, end)
2273
+
2274
+ case 'ucs2':
2275
+ case 'ucs-2':
2276
+ case 'utf16le':
2277
+ case 'utf-16le':
2278
+ return utf16leSlice(this, start, end)
2279
+
2280
+ default:
2281
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
2282
+ encoding = (encoding + '').toLowerCase()
2283
+ loweredCase = true
2284
+ }
2285
+ }
2286
+ }
2287
+
2288
+ // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
2289
+ // Buffer instances.
2290
+ Buffer.prototype._isBuffer = true
2291
+
2292
+ function swap (b, n, m) {
2293
+ var i = b[n]
2294
+ b[n] = b[m]
2295
+ b[m] = i
2296
+ }
2297
+
2298
+ Buffer.prototype.swap16 = function swap16 () {
2299
+ var len = this.length
2300
+ if (len % 2 !== 0) {
2301
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
2302
+ }
2303
+ for (var i = 0; i < len; i += 2) {
2304
+ swap(this, i, i + 1)
2305
+ }
2306
+ return this
2307
+ }
2308
+
2309
+ Buffer.prototype.swap32 = function swap32 () {
2310
+ var len = this.length
2311
+ if (len % 4 !== 0) {
2312
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
2313
+ }
2314
+ for (var i = 0; i < len; i += 4) {
2315
+ swap(this, i, i + 3)
2316
+ swap(this, i + 1, i + 2)
2317
+ }
2318
+ return this
2319
+ }
2320
+
2321
+ Buffer.prototype.toString = function toString () {
2322
+ var length = this.length | 0
2323
+ if (length === 0) return ''
2324
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
2325
+ return slowToString.apply(this, arguments)
2326
+ }
2327
+
2328
+ Buffer.prototype.equals = function equals (b) {
2329
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
2330
+ if (this === b) return true
2331
+ return Buffer.compare(this, b) === 0
2332
+ }
2333
+
2334
+ Buffer.prototype.inspect = function inspect () {
2335
+ var str = ''
2336
+ var max = _expor_.INSPECT_MAX_BYTES
2337
+ if (this.length > 0) {
2338
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
2339
+ if (this.length > max) str += ' ... '
2340
+ }
2341
+ return '<Buffer ' + str + '>'
2342
+ }
2343
+
2344
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
2345
+ if (!Buffer.isBuffer(target)) {
2346
+ throw new TypeError('Argument must be a Buffer')
2347
+ }
2348
+
2349
+ if (start === undefined) {
2350
+ start = 0
2351
+ }
2352
+ if (end === undefined) {
2353
+ end = target ? target.length : 0
2354
+ }
2355
+ if (thisStart === undefined) {
2356
+ thisStart = 0
2357
+ }
2358
+ if (thisEnd === undefined) {
2359
+ thisEnd = this.length
2360
+ }
2361
+
2362
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
2363
+ throw new RangeError('out of range index')
2364
+ }
2365
+
2366
+ if (thisStart >= thisEnd && start >= end) {
2367
+ return 0
2368
+ }
2369
+ if (thisStart >= thisEnd) {
2370
+ return -1
2371
+ }
2372
+ if (start >= end) {
2373
+ return 1
2374
+ }
2375
+
2376
+ start >>>= 0
2377
+ end >>>= 0
2378
+ thisStart >>>= 0
2379
+ thisEnd >>>= 0
2380
+
2381
+ if (this === target) return 0
2382
+
2383
+ var x = thisEnd - thisStart
2384
+ var y = end - start
2385
+ var len = Math.min(x, y)
2386
+
2387
+ var thisCopy = this.slice(thisStart, thisEnd)
2388
+ var targetCopy = target.slice(start, end)
2389
+
2390
+ for (var i = 0; i < len; ++i) {
2391
+ if (thisCopy[i] !== targetCopy[i]) {
2392
+ x = thisCopy[i]
2393
+ y = targetCopy[i]
2394
+ break
2395
+ }
2396
+ }
2397
+
2398
+ if (x < y) return -1
2399
+ if (y < x) return 1
2400
+ return 0
2401
+ }
2402
+
2403
+ function arrayIndexOf (arr, val, byteOffset, encoding) {
2404
+ var indexSize = 1
2405
+ var arrLength = arr.length
2406
+ var valLength = val.length
2407
+
2408
+ if (encoding !== undefined) {
2409
+ encoding = String(encoding).toLowerCase()
2410
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
2411
+ encoding === 'utf16le' || encoding === 'utf-16le') {
2412
+ if (arr.length < 2 || val.length < 2) {
2413
+ return -1
2414
+ }
2415
+ indexSize = 2
2416
+ arrLength /= 2
2417
+ valLength /= 2
2418
+ byteOffset /= 2
2419
+ }
2420
+ }
2421
+
2422
+ function read (buf, i) {
2423
+ if (indexSize === 1) {
2424
+ return buf[i]
2425
+ } else {
2426
+ return buf.readUInt16BE(i * indexSize)
2427
+ }
2428
+ }
2429
+
2430
+ var foundIndex = -1
2431
+ for (var i = byteOffset; i < arrLength; ++i) {
2432
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
2433
+ if (foundIndex === -1) foundIndex = i
2434
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
2435
+ } else {
2436
+ if (foundIndex !== -1) i -= i - foundIndex
2437
+ foundIndex = -1
2438
+ }
2439
+ }
2440
+
2441
+ return -1
2442
+ }
2443
+
2444
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
2445
+ if (typeof byteOffset === 'string') {
2446
+ encoding = byteOffset
2447
+ byteOffset = 0
2448
+ } else if (byteOffset > 0x7fffffff) {
2449
+ byteOffset = 0x7fffffff
2450
+ } else if (byteOffset < -0x80000000) {
2451
+ byteOffset = -0x80000000
2452
+ }
2453
+ byteOffset >>= 0
2454
+
2455
+ if (this.length === 0) return -1
2456
+ if (byteOffset >= this.length) return -1
2457
+
2458
+ // Negative offsets start from the end of the buffer
2459
+ if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
2460
+
2461
+ if (typeof val === 'string') {
2462
+ val = Buffer.from(val, encoding)
2463
+ }
2464
+
2465
+ if (Buffer.isBuffer(val)) {
2466
+ // special case: looking for empty string/buffer always fails
2467
+ if (val.length === 0) {
2468
+ return -1
2469
+ }
2470
+ return arrayIndexOf(this, val, byteOffset, encoding)
2471
+ }
2472
+ if (typeof val === 'number') {
2473
+ if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
2474
+ return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
2475
+ }
2476
+ return arrayIndexOf(this, [ val ], byteOffset, encoding)
2477
+ }
2478
+
2479
+ throw new TypeError('val must be string, number or Buffer')
2480
+ }
2481
+
2482
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
2483
+ return this.indexOf(val, byteOffset, encoding) !== -1
2484
+ }
2485
+
2486
+ function hexWrite (buf, string, offset, length) {
2487
+ offset = Number(offset) || 0
2488
+ var remaining = buf.length - offset
2489
+ if (!length) {
2490
+ length = remaining
2491
+ } else {
2492
+ length = Number(length)
2493
+ if (length > remaining) {
2494
+ length = remaining
2495
+ }
2496
+ }
2497
+
2498
+ // must be an even number of digits
2499
+ var strLen = string.length
2500
+ if (strLen % 2 !== 0) throw new Error('Invalid hex string')
2501
+
2502
+ if (length > strLen / 2) {
2503
+ length = strLen / 2
2504
+ }
2505
+ for (var i = 0; i < length; ++i) {
2506
+ var parsed = parseInt(string.substr(i * 2, 2), 16)
2507
+ if (isNaN(parsed)) return i
2508
+ buf[offset + i] = parsed
2509
+ }
2510
+ return i
2511
+ }
2512
+
2513
+ function utf8Write (buf, string, offset, length) {
2514
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
2515
+ }
2516
+
2517
+ function asciiWrite (buf, string, offset, length) {
2518
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
2519
+ }
2520
+
2521
+ function binaryWrite (buf, string, offset, length) {
2522
+ return asciiWrite(buf, string, offset, length)
2523
+ }
2524
+
2525
+ function base64Write (buf, string, offset, length) {
2526
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
2527
+ }
2528
+
2529
+ function ucs2Write (buf, string, offset, length) {
2530
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
2531
+ }
2532
+
2533
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
2534
+ // Buffer#write(string)
2535
+ if (offset === undefined) {
2536
+ encoding = 'utf8'
2537
+ length = this.length
2538
+ offset = 0
2539
+ // Buffer#write(string, encoding)
2540
+ } else if (length === undefined && typeof offset === 'string') {
2541
+ encoding = offset
2542
+ length = this.length
2543
+ offset = 0
2544
+ // Buffer#write(string, offset[, length][, encoding])
2545
+ } else if (isFinite(offset)) {
2546
+ offset = offset | 0
2547
+ if (isFinite(length)) {
2548
+ length = length | 0
2549
+ if (encoding === undefined) encoding = 'utf8'
2550
+ } else {
2551
+ encoding = length
2552
+ length = undefined
2553
+ }
2554
+ // legacy write(string, encoding, offset, length) - remove in v0.13
2555
+ } else {
2556
+ throw new Error(
2557
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
2558
+ )
2559
+ }
2560
+
2561
+ var remaining = this.length - offset
2562
+ if (length === undefined || length > remaining) length = remaining
2563
+
2564
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
2565
+ throw new RangeError('Attempt to write outside buffer bounds')
2566
+ }
2567
+
2568
+ if (!encoding) encoding = 'utf8'
2569
+
2570
+ var loweredCase = false
2571
+ for (;;) {
2572
+ switch (encoding) {
2573
+ case 'hex':
2574
+ return hexWrite(this, string, offset, length)
2575
+
2576
+ case 'utf8':
2577
+ case 'utf-8':
2578
+ return utf8Write(this, string, offset, length)
2579
+
2580
+ case 'ascii':
2581
+ return asciiWrite(this, string, offset, length)
2582
+
2583
+ case 'binary':
2584
+ return binaryWrite(this, string, offset, length)
2585
+
2586
+ case 'base64':
2587
+ // Warning: maxLength not taken into account in base64Write
2588
+ return base64Write(this, string, offset, length)
2589
+
2590
+ case 'ucs2':
2591
+ case 'ucs-2':
2592
+ case 'utf16le':
2593
+ case 'utf-16le':
2594
+ return ucs2Write(this, string, offset, length)
2595
+
2596
+ default:
2597
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
2598
+ encoding = ('' + encoding).toLowerCase()
2599
+ loweredCase = true
2600
+ }
2601
+ }
2602
+ }
2603
+
2604
+ Buffer.prototype.toJSON = function toJSON () {
2605
+ return {
2606
+ type: 'Buffer',
2607
+ data: Array.prototype.slice.call(this._arr || this, 0)
2608
+ }
2609
+ }
2610
+
2611
+ function base64Slice (buf, start, end) {
2612
+ if (start === 0 && end === buf.length) {
2613
+ return base64.fromByteArray(buf)
2614
+ } else {
2615
+ return base64.fromByteArray(buf.slice(start, end))
2616
+ }
2617
+ }
2618
+
2619
+ function utf8Slice (buf, start, end) {
2620
+ end = Math.min(buf.length, end)
2621
+ var res = []
2622
+
2623
+ var i = start
2624
+ while (i < end) {
2625
+ var firstByte = buf[i]
2626
+ var codePoint = null
2627
+ var bytesPerSequence = (firstByte > 0xEF) ? 4
2628
+ : (firstByte > 0xDF) ? 3
2629
+ : (firstByte > 0xBF) ? 2
2630
+ : 1
2631
+
2632
+ if (i + bytesPerSequence <= end) {
2633
+ var secondByte, thirdByte, fourthByte, tempCodePoint
2634
+
2635
+ switch (bytesPerSequence) {
2636
+ case 1:
2637
+ if (firstByte < 0x80) {
2638
+ codePoint = firstByte
2639
+ }
2640
+ break
2641
+ case 2:
2642
+ secondByte = buf[i + 1]
2643
+ if ((secondByte & 0xC0) === 0x80) {
2644
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
2645
+ if (tempCodePoint > 0x7F) {
2646
+ codePoint = tempCodePoint
2647
+ }
2648
+ }
2649
+ break
2650
+ case 3:
2651
+ secondByte = buf[i + 1]
2652
+ thirdByte = buf[i + 2]
2653
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
2654
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
2655
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
2656
+ codePoint = tempCodePoint
2657
+ }
2658
+ }
2659
+ break
2660
+ case 4:
2661
+ secondByte = buf[i + 1]
2662
+ thirdByte = buf[i + 2]
2663
+ fourthByte = buf[i + 3]
2664
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
2665
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
2666
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
2667
+ codePoint = tempCodePoint
2668
+ }
2669
+ }
2670
+ }
2671
+ }
2672
+
2673
+ if (codePoint === null) {
2674
+ // we did not generate a valid codePoint so insert a
2675
+ // replacement char (U+FFFD) and advance only 1 byte
2676
+ codePoint = 0xFFFD
2677
+ bytesPerSequence = 1
2678
+ } else if (codePoint > 0xFFFF) {
2679
+ // encode to utf16 (surrogate pair dance)
2680
+ codePoint -= 0x10000
2681
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800)
2682
+ codePoint = 0xDC00 | codePoint & 0x3FF
2683
+ }
2684
+
2685
+ res.push(codePoint)
2686
+ i += bytesPerSequence
2687
+ }
2688
+
2689
+ return decodeCodePointsArray(res)
2690
+ }
2691
+
2692
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
2693
+ // the lowest limit is Chrome, with 0x10000 args.
2694
+ // We go 1 magnitude less, for safety
2695
+ var MAX_ARGUMENTS_LENGTH = 0x1000
2696
+
2697
+ function decodeCodePointsArray (codePoints) {
2698
+ var len = codePoints.length
2699
+ if (len <= MAX_ARGUMENTS_LENGTH) {
2700
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
2701
+ }
2702
+
2703
+ // Decode in chunks to avoid "call stack size exceeded".
2704
+ var res = ''
2705
+ var i = 0
2706
+ while (i < len) {
2707
+ res += String.fromCharCode.apply(
2708
+ String,
2709
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
2710
+ )
2711
+ }
2712
+ return res
2713
+ }
2714
+
2715
+ function asciiSlice (buf, start, end) {
2716
+ var ret = ''
2717
+ end = Math.min(buf.length, end)
2718
+
2719
+ for (var i = start; i < end; ++i) {
2720
+ ret += String.fromCharCode(buf[i] & 0x7F)
2721
+ }
2722
+ return ret
2723
+ }
2724
+
2725
+ function binarySlice (buf, start, end) {
2726
+ var ret = ''
2727
+ end = Math.min(buf.length, end)
2728
+
2729
+ for (var i = start; i < end; ++i) {
2730
+ ret += String.fromCharCode(buf[i])
2731
+ }
2732
+ return ret
2733
+ }
2734
+
2735
+ function hexSlice (buf, start, end) {
2736
+ var len = buf.length
2737
+
2738
+ if (!start || start < 0) start = 0
2739
+ if (!end || end < 0 || end > len) end = len
2740
+
2741
+ var out = ''
2742
+ for (var i = start; i < end; ++i) {
2743
+ out += toHex(buf[i])
2744
+ }
2745
+ return out
2746
+ }
2747
+
2748
+ function utf16leSlice (buf, start, end) {
2749
+ var bytes = buf.slice(start, end)
2750
+ var res = ''
2751
+ for (var i = 0; i < bytes.length; i += 2) {
2752
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
2753
+ }
2754
+ return res
2755
+ }
2756
+
2757
+ Buffer.prototype.slice = function slice (start, end) {
2758
+ var len = this.length
2759
+ start = ~~start
2760
+ end = end === undefined ? len : ~~end
2761
+
2762
+ if (start < 0) {
2763
+ start += len
2764
+ if (start < 0) start = 0
2765
+ } else if (start > len) {
2766
+ start = len
2767
+ }
2768
+
2769
+ if (end < 0) {
2770
+ end += len
2771
+ if (end < 0) end = 0
2772
+ } else if (end > len) {
2773
+ end = len
2774
+ }
2775
+
2776
+ if (end < start) end = start
2777
+
2778
+ var newBuf
2779
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
2780
+ newBuf = this.subarray(start, end)
2781
+ newBuf.__proto__ = Buffer.prototype
2782
+ } else {
2783
+ var sliceLen = end - start
2784
+ newBuf = new Buffer(sliceLen, undefined)
2785
+ for (var i = 0; i < sliceLen; ++i) {
2786
+ newBuf[i] = this[i + start]
2787
+ }
2788
+ }
2789
+
2790
+ return newBuf
2791
+ }
2792
+
2793
+ /*
2794
+ * Need to make sure that buffer isn't trying to write out of bounds.
2795
+ */
2796
+ function checkOffset (offset, ext, length) {
2797
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
2798
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
2799
+ }
2800
+
2801
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
2802
+ offset = offset | 0
2803
+ byteLength = byteLength | 0
2804
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
2805
+
2806
+ var val = this[offset]
2807
+ var mul = 1
2808
+ var i = 0
2809
+ while (++i < byteLength && (mul *= 0x100)) {
2810
+ val += this[offset + i] * mul
2811
+ }
2812
+
2813
+ return val
2814
+ }
2815
+
2816
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
2817
+ offset = offset | 0
2818
+ byteLength = byteLength | 0
2819
+ if (!noAssert) {
2820
+ checkOffset(offset, byteLength, this.length)
2821
+ }
2822
+
2823
+ var val = this[offset + --byteLength]
2824
+ var mul = 1
2825
+ while (byteLength > 0 && (mul *= 0x100)) {
2826
+ val += this[offset + --byteLength] * mul
2827
+ }
2828
+
2829
+ return val
2830
+ }
2831
+
2832
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
2833
+ if (!noAssert) checkOffset(offset, 1, this.length)
2834
+ return this[offset]
2835
+ }
2836
+
2837
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
2838
+ if (!noAssert) checkOffset(offset, 2, this.length)
2839
+ return this[offset] | (this[offset + 1] << 8)
2840
+ }
2841
+
2842
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
2843
+ if (!noAssert) checkOffset(offset, 2, this.length)
2844
+ return (this[offset] << 8) | this[offset + 1]
2845
+ }
2846
+
2847
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
2848
+ if (!noAssert) checkOffset(offset, 4, this.length)
2849
+
2850
+ return ((this[offset]) |
2851
+ (this[offset + 1] << 8) |
2852
+ (this[offset + 2] << 16)) +
2853
+ (this[offset + 3] * 0x1000000)
2854
+ }
2855
+
2856
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
2857
+ if (!noAssert) checkOffset(offset, 4, this.length)
2858
+
2859
+ return (this[offset] * 0x1000000) +
2860
+ ((this[offset + 1] << 16) |
2861
+ (this[offset + 2] << 8) |
2862
+ this[offset + 3])
2863
+ }
2864
+
2865
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
2866
+ offset = offset | 0
2867
+ byteLength = byteLength | 0
2868
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
2869
+
2870
+ var val = this[offset]
2871
+ var mul = 1
2872
+ var i = 0
2873
+ while (++i < byteLength && (mul *= 0x100)) {
2874
+ val += this[offset + i] * mul
2875
+ }
2876
+ mul *= 0x80
2877
+
2878
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
2879
+
2880
+ return val
2881
+ }
2882
+
2883
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
2884
+ offset = offset | 0
2885
+ byteLength = byteLength | 0
2886
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
2887
+
2888
+ var i = byteLength
2889
+ var mul = 1
2890
+ var val = this[offset + --i]
2891
+ while (i > 0 && (mul *= 0x100)) {
2892
+ val += this[offset + --i] * mul
2893
+ }
2894
+ mul *= 0x80
2895
+
2896
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
2897
+
2898
+ return val
2899
+ }
2900
+
2901
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
2902
+ if (!noAssert) checkOffset(offset, 1, this.length)
2903
+ if (!(this[offset] & 0x80)) return (this[offset])
2904
+ return ((0xff - this[offset] + 1) * -1)
2905
+ }
2906
+
2907
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
2908
+ if (!noAssert) checkOffset(offset, 2, this.length)
2909
+ var val = this[offset] | (this[offset + 1] << 8)
2910
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
2911
+ }
2912
+
2913
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
2914
+ if (!noAssert) checkOffset(offset, 2, this.length)
2915
+ var val = this[offset + 1] | (this[offset] << 8)
2916
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
2917
+ }
2918
+
2919
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
2920
+ if (!noAssert) checkOffset(offset, 4, this.length)
2921
+
2922
+ return (this[offset]) |
2923
+ (this[offset + 1] << 8) |
2924
+ (this[offset + 2] << 16) |
2925
+ (this[offset + 3] << 24)
2926
+ }
2927
+
2928
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
2929
+ if (!noAssert) checkOffset(offset, 4, this.length)
2930
+
2931
+ return (this[offset] << 24) |
2932
+ (this[offset + 1] << 16) |
2933
+ (this[offset + 2] << 8) |
2934
+ (this[offset + 3])
2935
+ }
2936
+
2937
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
2938
+ if (!noAssert) checkOffset(offset, 4, this.length)
2939
+ return ieee754.read(this, offset, true, 23, 4)
2940
+ }
2941
+
2942
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
2943
+ if (!noAssert) checkOffset(offset, 4, this.length)
2944
+ return ieee754.read(this, offset, false, 23, 4)
2945
+ }
2946
+
2947
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
2948
+ if (!noAssert) checkOffset(offset, 8, this.length)
2949
+ return ieee754.read(this, offset, true, 52, 8)
2950
+ }
2951
+
2952
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
2953
+ if (!noAssert) checkOffset(offset, 8, this.length)
2954
+ return ieee754.read(this, offset, false, 52, 8)
2955
+ }
2956
+
2957
+ function checkInt (buf, value, offset, ext, max, min) {
2958
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
2959
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
2960
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
2961
+ }
2962
+
2963
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
2964
+ value = +value
2965
+ offset = offset | 0
2966
+ byteLength = byteLength | 0
2967
+ if (!noAssert) {
2968
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
2969
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
2970
+ }
2971
+
2972
+ var mul = 1
2973
+ var i = 0
2974
+ this[offset] = value & 0xFF
2975
+ while (++i < byteLength && (mul *= 0x100)) {
2976
+ this[offset + i] = (value / mul) & 0xFF
2977
+ }
2978
+
2979
+ return offset + byteLength
2980
+ }
2981
+
2982
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
2983
+ value = +value
2984
+ offset = offset | 0
2985
+ byteLength = byteLength | 0
2986
+ if (!noAssert) {
2987
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
2988
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
2989
+ }
2990
+
2991
+ var i = byteLength - 1
2992
+ var mul = 1
2993
+ this[offset + i] = value & 0xFF
2994
+ while (--i >= 0 && (mul *= 0x100)) {
2995
+ this[offset + i] = (value / mul) & 0xFF
2996
+ }
2997
+
2998
+ return offset + byteLength
2999
+ }
3000
+
3001
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
3002
+ value = +value
3003
+ offset = offset | 0
3004
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
3005
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
3006
+ this[offset] = (value & 0xff)
3007
+ return offset + 1
3008
+ }
3009
+
3010
+ function objectWriteUInt16 (buf, value, offset, littleEndian) {
3011
+ if (value < 0) value = 0xffff + value + 1
3012
+ for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
3013
+ buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
3014
+ (littleEndian ? i : 1 - i) * 8
3015
+ }
3016
+ }
3017
+
3018
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
3019
+ value = +value
3020
+ offset = offset | 0
3021
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
3022
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3023
+ this[offset] = (value & 0xff)
3024
+ this[offset + 1] = (value >>> 8)
3025
+ } else {
3026
+ objectWriteUInt16(this, value, offset, true)
3027
+ }
3028
+ return offset + 2
3029
+ }
3030
+
3031
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
3032
+ value = +value
3033
+ offset = offset | 0
3034
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
3035
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3036
+ this[offset] = (value >>> 8)
3037
+ this[offset + 1] = (value & 0xff)
3038
+ } else {
3039
+ objectWriteUInt16(this, value, offset, false)
3040
+ }
3041
+ return offset + 2
3042
+ }
3043
+
3044
+ function objectWriteUInt32 (buf, value, offset, littleEndian) {
3045
+ if (value < 0) value = 0xffffffff + value + 1
3046
+ for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
3047
+ buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
3048
+ }
3049
+ }
3050
+
3051
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
3052
+ value = +value
3053
+ offset = offset | 0
3054
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
3055
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3056
+ this[offset + 3] = (value >>> 24)
3057
+ this[offset + 2] = (value >>> 16)
3058
+ this[offset + 1] = (value >>> 8)
3059
+ this[offset] = (value & 0xff)
3060
+ } else {
3061
+ objectWriteUInt32(this, value, offset, true)
3062
+ }
3063
+ return offset + 4
3064
+ }
3065
+
3066
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
3067
+ value = +value
3068
+ offset = offset | 0
3069
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
3070
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3071
+ this[offset] = (value >>> 24)
3072
+ this[offset + 1] = (value >>> 16)
3073
+ this[offset + 2] = (value >>> 8)
3074
+ this[offset + 3] = (value & 0xff)
3075
+ } else {
3076
+ objectWriteUInt32(this, value, offset, false)
3077
+ }
3078
+ return offset + 4
3079
+ }
3080
+
3081
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
3082
+ value = +value
3083
+ offset = offset | 0
3084
+ if (!noAssert) {
3085
+ var limit = Math.pow(2, 8 * byteLength - 1)
3086
+
3087
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
3088
+ }
3089
+
3090
+ var i = 0
3091
+ var mul = 1
3092
+ var sub = 0
3093
+ this[offset] = value & 0xFF
3094
+ while (++i < byteLength && (mul *= 0x100)) {
3095
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
3096
+ sub = 1
3097
+ }
3098
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
3099
+ }
3100
+
3101
+ return offset + byteLength
3102
+ }
3103
+
3104
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
3105
+ value = +value
3106
+ offset = offset | 0
3107
+ if (!noAssert) {
3108
+ var limit = Math.pow(2, 8 * byteLength - 1)
3109
+
3110
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
3111
+ }
3112
+
3113
+ var i = byteLength - 1
3114
+ var mul = 1
3115
+ var sub = 0
3116
+ this[offset + i] = value & 0xFF
3117
+ while (--i >= 0 && (mul *= 0x100)) {
3118
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
3119
+ sub = 1
3120
+ }
3121
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
3122
+ }
3123
+
3124
+ return offset + byteLength
3125
+ }
3126
+
3127
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
3128
+ value = +value
3129
+ offset = offset | 0
3130
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
3131
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
3132
+ if (value < 0) value = 0xff + value + 1
3133
+ this[offset] = (value & 0xff)
3134
+ return offset + 1
3135
+ }
3136
+
3137
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
3138
+ value = +value
3139
+ offset = offset | 0
3140
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
3141
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3142
+ this[offset] = (value & 0xff)
3143
+ this[offset + 1] = (value >>> 8)
3144
+ } else {
3145
+ objectWriteUInt16(this, value, offset, true)
3146
+ }
3147
+ return offset + 2
3148
+ }
3149
+
3150
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
3151
+ value = +value
3152
+ offset = offset | 0
3153
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
3154
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3155
+ this[offset] = (value >>> 8)
3156
+ this[offset + 1] = (value & 0xff)
3157
+ } else {
3158
+ objectWriteUInt16(this, value, offset, false)
3159
+ }
3160
+ return offset + 2
3161
+ }
3162
+
3163
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
3164
+ value = +value
3165
+ offset = offset | 0
3166
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
3167
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3168
+ this[offset] = (value & 0xff)
3169
+ this[offset + 1] = (value >>> 8)
3170
+ this[offset + 2] = (value >>> 16)
3171
+ this[offset + 3] = (value >>> 24)
3172
+ } else {
3173
+ objectWriteUInt32(this, value, offset, true)
3174
+ }
3175
+ return offset + 4
3176
+ }
3177
+
3178
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
3179
+ value = +value
3180
+ offset = offset | 0
3181
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
3182
+ if (value < 0) value = 0xffffffff + value + 1
3183
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
3184
+ this[offset] = (value >>> 24)
3185
+ this[offset + 1] = (value >>> 16)
3186
+ this[offset + 2] = (value >>> 8)
3187
+ this[offset + 3] = (value & 0xff)
3188
+ } else {
3189
+ objectWriteUInt32(this, value, offset, false)
3190
+ }
3191
+ return offset + 4
3192
+ }
3193
+
3194
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
3195
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
3196
+ if (offset < 0) throw new RangeError('Index out of range')
3197
+ }
3198
+
3199
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
3200
+ if (!noAssert) {
3201
+ checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
3202
+ }
3203
+ ieee754.write(buf, value, offset, littleEndian, 23, 4)
3204
+ return offset + 4
3205
+ }
3206
+
3207
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
3208
+ return writeFloat(this, value, offset, true, noAssert)
3209
+ }
3210
+
3211
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
3212
+ return writeFloat(this, value, offset, false, noAssert)
3213
+ }
3214
+
3215
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
3216
+ if (!noAssert) {
3217
+ checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
3218
+ }
3219
+ ieee754.write(buf, value, offset, littleEndian, 52, 8)
3220
+ return offset + 8
3221
+ }
3222
+
3223
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
3224
+ return writeDouble(this, value, offset, true, noAssert)
3225
+ }
3226
+
3227
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
3228
+ return writeDouble(this, value, offset, false, noAssert)
3229
+ }
3230
+
3231
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
3232
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
3233
+ if (!start) start = 0
3234
+ if (!end && end !== 0) end = this.length
3235
+ if (targetStart >= target.length) targetStart = target.length
3236
+ if (!targetStart) targetStart = 0
3237
+ if (end > 0 && end < start) end = start
3238
+
3239
+ // Copy 0 bytes; we're done
3240
+ if (end === start) return 0
3241
+ if (target.length === 0 || this.length === 0) return 0
3242
+
3243
+ // Fatal error conditions
3244
+ if (targetStart < 0) {
3245
+ throw new RangeError('targetStart out of bounds')
3246
+ }
3247
+ if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
3248
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
3249
+
3250
+ // Are we oob?
3251
+ if (end > this.length) end = this.length
3252
+ if (target.length - targetStart < end - start) {
3253
+ end = target.length - targetStart + start
3254
+ }
3255
+
3256
+ var len = end - start
3257
+ var i
3258
+
3259
+ if (this === target && start < targetStart && targetStart < end) {
3260
+ // descending copy from end
3261
+ for (i = len - 1; i >= 0; --i) {
3262
+ target[i + targetStart] = this[i + start]
3263
+ }
3264
+ } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
3265
+ // ascending copy from start
3266
+ for (i = 0; i < len; ++i) {
3267
+ target[i + targetStart] = this[i + start]
3268
+ }
3269
+ } else {
3270
+ Uint8Array.prototype.set.call(
3271
+ target,
3272
+ this.subarray(start, start + len),
3273
+ targetStart
3274
+ )
3275
+ }
3276
+
3277
+ return len
3278
+ }
3279
+
3280
+ // Usage:
3281
+ // buffer.fill(number[, offset[, end]])
3282
+ // buffer.fill(buffer[, offset[, end]])
3283
+ // buffer.fill(string[, offset[, end]][, encoding])
3284
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
3285
+ // Handle string cases:
3286
+ if (typeof val === 'string') {
3287
+ if (typeof start === 'string') {
3288
+ encoding = start
3289
+ start = 0
3290
+ end = this.length
3291
+ } else if (typeof end === 'string') {
3292
+ encoding = end
3293
+ end = this.length
3294
+ }
3295
+ if (val.length === 1) {
3296
+ var code = val.charCodeAt(0)
3297
+ if (code < 256) {
3298
+ val = code
3299
+ }
3300
+ }
3301
+ if (encoding !== undefined && typeof encoding !== 'string') {
3302
+ throw new TypeError('encoding must be a string')
3303
+ }
3304
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
3305
+ throw new TypeError('Unknown encoding: ' + encoding)
3306
+ }
3307
+ } else if (typeof val === 'number') {
3308
+ val = val & 255
3309
+ }
3310
+
3311
+ // Invalid ranges are not set to a default, so can range check early.
3312
+ if (start < 0 || this.length < start || this.length < end) {
3313
+ throw new RangeError('Out of range index')
3314
+ }
3315
+
3316
+ if (end <= start) {
3317
+ return this
3318
+ }
3319
+
3320
+ start = start >>> 0
3321
+ end = end === undefined ? this.length : end >>> 0
3322
+
3323
+ if (!val) val = 0
3324
+
3325
+ var i
3326
+ if (typeof val === 'number') {
3327
+ for (i = start; i < end; ++i) {
3328
+ this[i] = val
3329
+ }
3330
+ } else {
3331
+ var bytes = Buffer.isBuffer(val)
3332
+ ? val
3333
+ : utf8ToBytes(new Buffer(val, encoding).toString())
3334
+ var len = bytes.length
3335
+ for (i = 0; i < end - start; ++i) {
3336
+ this[i + start] = bytes[i % len]
3337
+ }
3338
+ }
3339
+
3340
+ return this
3341
+ }
3342
+
3343
+ // HELPER FUNCTIONS
3344
+ // ================
3345
+
3346
+ var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
3347
+
3348
+ function base64clean (str) {
3349
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
3350
+ str = stringtrim(str).replace(INVALID_BASE64_RE, '')
3351
+ // Node converts strings with length < 2 to ''
3352
+ if (str.length < 2) return ''
3353
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
3354
+ while (str.length % 4 !== 0) {
3355
+ str = str + '='
3356
+ }
3357
+ return str
3358
+ }
3359
+
3360
+ function stringtrim (str) {
3361
+ if (str.trim) return str.trim()
3362
+ return str.replace(/^\s+|\s+$/g, '')
3363
+ }
3364
+
3365
+ function toHex (n) {
3366
+ if (n < 16) return '0' + n.toString(16)
3367
+ return n.toString(16)
3368
+ }
3369
+
3370
+ function utf8ToBytes (string, units) {
3371
+ units = units || Infinity
3372
+ var codePoint
3373
+ var length = string.length
3374
+ var leadSurrogate = null
3375
+ var bytes = []
3376
+
3377
+ for (var i = 0; i < length; ++i) {
3378
+ codePoint = string.charCodeAt(i)
3379
+
3380
+ // is surrogate component
3381
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
3382
+ // last char was a lead
3383
+ if (!leadSurrogate) {
3384
+ // no lead yet
3385
+ if (codePoint > 0xDBFF) {
3386
+ // unexpected trail
3387
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
3388
+ continue
3389
+ } else if (i + 1 === length) {
3390
+ // unpaired lead
3391
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
3392
+ continue
3393
+ }
3394
+
3395
+ // valid lead
3396
+ leadSurrogate = codePoint
3397
+
3398
+ continue
3399
+ }
3400
+
3401
+ // 2 leads in a row
3402
+ if (codePoint < 0xDC00) {
3403
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
3404
+ leadSurrogate = codePoint
3405
+ continue
3406
+ }
3407
+
3408
+ // valid surrogate pair
3409
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
3410
+ } else if (leadSurrogate) {
3411
+ // valid bmp char, but last char was a lead
3412
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
3413
+ }
3414
+
3415
+ leadSurrogate = null
3416
+
3417
+ // encode utf8
3418
+ if (codePoint < 0x80) {
3419
+ if ((units -= 1) < 0) break
3420
+ bytes.push(codePoint)
3421
+ } else if (codePoint < 0x800) {
3422
+ if ((units -= 2) < 0) break
3423
+ bytes.push(
3424
+ codePoint >> 0x6 | 0xC0,
3425
+ codePoint & 0x3F | 0x80
3426
+ )
3427
+ } else if (codePoint < 0x10000) {
3428
+ if ((units -= 3) < 0) break
3429
+ bytes.push(
3430
+ codePoint >> 0xC | 0xE0,
3431
+ codePoint >> 0x6 & 0x3F | 0x80,
3432
+ codePoint & 0x3F | 0x80
3433
+ )
3434
+ } else if (codePoint < 0x110000) {
3435
+ if ((units -= 4) < 0) break
3436
+ bytes.push(
3437
+ codePoint >> 0x12 | 0xF0,
3438
+ codePoint >> 0xC & 0x3F | 0x80,
3439
+ codePoint >> 0x6 & 0x3F | 0x80,
3440
+ codePoint & 0x3F | 0x80
3441
+ )
3442
+ } else {
3443
+ throw new Error('Invalid code point')
3444
+ }
3445
+ }
3446
+
3447
+ return bytes
3448
+ }
3449
+
3450
+ function asciiToBytes (str) {
3451
+ var byteArray = []
3452
+ for (var i = 0; i < str.length; ++i) {
3453
+ // Node's code seems to be doing this and not & 0x7F..
3454
+ byteArray.push(str.charCodeAt(i) & 0xFF)
3455
+ }
3456
+ return byteArray
3457
+ }
3458
+
3459
+ function utf16leToBytes (str, units) {
3460
+ var c, hi, lo
3461
+ var byteArray = []
3462
+ for (var i = 0; i < str.length; ++i) {
3463
+ if ((units -= 2) < 0) break
3464
+
3465
+ c = str.charCodeAt(i)
3466
+ hi = c >> 8
3467
+ lo = c % 256
3468
+ byteArray.push(lo)
3469
+ byteArray.push(hi)
3470
+ }
3471
+
3472
+ return byteArray
3473
+ }
3474
+
3475
+ function base64ToBytes (str) {
3476
+ return base64.toByteArray(base64clean(str))
3477
+ }
3478
+
3479
+ function blitBuffer (src, dst, offset, length) {
3480
+ for (var i = 0; i < length; ++i) {
3481
+ if ((i + offset >= dst.length) || (i >= src.length)) break
3482
+ dst[i + offset] = src[i]
3483
+ }
3484
+ return i
3485
+ }
3486
+
3487
+ function isnan (val) {
3488
+ return val !== val // eslint-disable-line no-self-compare
3489
+ }
3490
+
3491
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
3492
+ },{"base64-js":1,"ieee754":3,"isarray":4}],3:[function(_dereq_,___mod,_expor_){
3493
+ _expor_.read = function (buffer, offset, isLE, mLen, nBytes) {
3494
+ var e, m
3495
+ var eLen = nBytes * 8 - mLen - 1
3496
+ var eMax = (1 << eLen) - 1
3497
+ var eBias = eMax >> 1
3498
+ var nBits = -7
3499
+ var i = isLE ? (nBytes - 1) : 0
3500
+ var d = isLE ? -1 : 1
3501
+ var s = buffer[offset + i]
3502
+
3503
+ i += d
3504
+
3505
+ e = s & ((1 << (-nBits)) - 1)
3506
+ s >>= (-nBits)
3507
+ nBits += eLen
3508
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
3509
+
3510
+ m = e & ((1 << (-nBits)) - 1)
3511
+ e >>= (-nBits)
3512
+ nBits += mLen
3513
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
3514
+
3515
+ if (e === 0) {
3516
+ e = 1 - eBias
3517
+ } else if (e === eMax) {
3518
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
3519
+ } else {
3520
+ m = m + Math.pow(2, mLen)
3521
+ e = e - eBias
3522
+ }
3523
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
3524
+ }
3525
+
3526
+ _expor_.write = function (buffer, value, offset, isLE, mLen, nBytes) {
3527
+ var e, m, c
3528
+ var eLen = nBytes * 8 - mLen - 1
3529
+ var eMax = (1 << eLen) - 1
3530
+ var eBias = eMax >> 1
3531
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
3532
+ var i = isLE ? 0 : (nBytes - 1)
3533
+ var d = isLE ? 1 : -1
3534
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
3535
+
3536
+ value = Math.abs(value)
3537
+
3538
+ if (isNaN(value) || value === Infinity) {
3539
+ m = isNaN(value) ? 1 : 0
3540
+ e = eMax
3541
+ } else {
3542
+ e = Math.floor(Math.log(value) / Math.LN2)
3543
+ if (value * (c = Math.pow(2, -e)) < 1) {
3544
+ e--
3545
+ c *= 2
3546
+ }
3547
+ if (e + eBias >= 1) {
3548
+ value += rt / c
3549
+ } else {
3550
+ value += rt * Math.pow(2, 1 - eBias)
3551
+ }
3552
+ if (value * c >= 2) {
3553
+ e++
3554
+ c /= 2
3555
+ }
3556
+
3557
+ if (e + eBias >= eMax) {
3558
+ m = 0
3559
+ e = eMax
3560
+ } else if (e + eBias >= 1) {
3561
+ m = (value * c - 1) * Math.pow(2, mLen)
3562
+ e = e + eBias
3563
+ } else {
3564
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
3565
+ e = 0
3566
+ }
3567
+ }
3568
+
3569
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
3570
+
3571
+ e = (e << mLen) | m
3572
+ eLen += mLen
3573
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
3574
+
3575
+ buffer[offset + i - d] |= s * 128
3576
+ }
3577
+
3578
+ },{}],4:[function(_dereq_,___mod,_expor_){
3579
+ var toString = {}.toString;
3580
+
3581
+ ___mod.exports = Array.isArray || function (arr) {
3582
+ return toString.call(arr) == '[object Array]';
3583
+ };
3584
+
3585
+ },{}],5:[function(_dereq_,___mod,_expor_){
3586
+ var buf = _dereq_('buffer');
3587
+ _buffer = buf.Buffer;
3588
+ _slowbuffer = buf.SlowBuffer;
3589
+ _INSPECT_MAX_BYTES = buf._INSPECT_MAX_BYTES;
3590
+
3591
+ },{"buffer":2}]},{},[5]);
3592
+
3593
+ function computeMerkleParent(left, right) {
3594
+ if (right) {
3595
+ return sha256$1(_buffer.concat([new _buffer(left, 'hex'), new _buffer(right, 'hex')]));
3596
+ }
3597
+ return left;
3598
+ }
3599
+
3600
+ var blockCypherCache = {};
3601
+
3602
+ var SegmentValidator = function () {
3603
+ function SegmentValidator(segment) {
3604
+ classCallCheck(this, SegmentValidator);
3605
+
3606
+ this.segment = segment;
3607
+ }
3608
+
3609
+ createClass(SegmentValidator, [{
3610
+ key: 'validate',
3611
+ value: function validate(errors) {
3612
+ errors.linkHash.push(this._validateLinkHash());
3613
+ errors.stateHash.push(this._validateStateHash());
3614
+ errors.merklePath.push(this._validateMerklePath());
3615
+ errors.fossil.push(this._validateFossil());
3616
+ }
3617
+ }, {
3618
+ key: '_validateLinkHash',
3619
+ value: function _validateLinkHash() {
3620
+ var computed = hashJson(this.segment.link);
3621
+ var actual = this.segment.meta.linkHash;
3622
+ if (computed !== actual) {
3623
+ return 'LinkHash computed: ' + computed + ', Found: ' + actual;
3624
+ }
3625
+ return null;
3626
+ }
3627
+ }, {
3628
+ key: '_validateStateHash',
3629
+ value: function _validateStateHash() {
3630
+ if (this.segment.link.state) {
3631
+ var computed = hashJson(this.segment.link.state);
3632
+ var actual = this.segment.link.meta.stateHash;
3633
+ if (computed !== actual) {
3634
+ return 'StateHash computed: ' + computed + ', Found: ' + actual;
3635
+ }
3636
+ }
3637
+ return null;
3638
+ }
3639
+ }, {
3640
+ key: '_validateMerklePath',
3641
+ value: function _validateMerklePath() {
3642
+ var _this = this;
3643
+
3644
+ var evidence = this.segment.meta.evidence;
3645
+ if (evidence) {
3646
+ if (evidence.state === 'COMPLETE') {
3647
+ var _ret = function () {
3648
+ var previous = _this.segment.meta.linkHash;
3649
+
3650
+ var error = void 0;
3651
+ evidence.merklePath.every(function (merkleNode) {
3652
+ if (merkleNode.left === previous || merkleNode.right === previous) {
3653
+ var computedParent = computeMerkleParent(merkleNode.left, merkleNode.right);
3654
+
3655
+ if (computedParent !== merkleNode.parent) {
3656
+ error = 'Invalid Merkle Node ' + JSON.stringify(merkleNode) + ': ' + ('computed parent: ' + computedParent);
3657
+ return false;
3658
+ }
3659
+ previous = merkleNode.parent;
3660
+ return true;
3661
+ }
3662
+ error = 'Invalid Merkle Node ' + JSON.stringify(merkleNode) + ': ' + ('previous hash (' + previous + ') not found');
3663
+ return false;
3664
+ });
3665
+
3666
+ if (error) {
3667
+ return {
3668
+ v: error
3669
+ };
3670
+ }
3671
+
3672
+ var lastMerkleNode = evidence.merklePath[evidence.merklePath.length - 1];
3673
+ if (lastMerkleNode.parent !== evidence.merkleRoot) {
3674
+ return {
3675
+ v: 'Invalid Merkle Root ' + evidence.merkleRoot + ': not found in Merkle Path'
3676
+ };
3677
+ }
3678
+ }();
3679
+
3680
+ if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
3681
+ }
3682
+ }
3683
+ return null;
3684
+ }
3685
+ }, {
3686
+ key: '_validateFossil',
3687
+ value: function _validateFossil() {
3688
+ var _this2 = this;
3689
+
3690
+ var txId = this.segment.meta.evidence.transactions['bitcoin:main'];
3691
+ return this._getFossil(txId).then(function (res) {
3692
+ var body = JSON.parse(res.xhr.response);
3693
+ if (!body.outputs.find(function (output) {
3694
+ return output.data_hex === _this2.segment.meta.evidence.merkleRoot;
3695
+ })) {
3696
+ return 'Merkle root not found in transaction data';
3697
+ }
3698
+ return null;
3699
+ });
3700
+ }
3701
+ }, {
3702
+ key: '_getFossil',
3703
+ value: function _getFossil(txId) {
3704
+ if (blockCypherCache[txId]) {
3705
+ return Promise.resolve(blockCypherCache[txId]);
3706
+ }
3707
+
3708
+ var p = new Promise(function (resolve, reject) {
3709
+ return httpplease.get('https://api.blockcypher.com/v1/btc/main/txs/' + txId, function (err, res) {
3710
+ return err ? reject(err) : resolve(res);
3711
+ });
3712
+ });
3713
+ blockCypherCache[txId] = p;
3714
+ return p;
3715
+ }
3716
+ }]);
3717
+ return SegmentValidator;
3718
+ }();
3719
+
3720
+ var ChainValidator = function () {
3721
+ function ChainValidator(chainscript) {
3722
+ classCallCheck(this, ChainValidator);
3723
+
3724
+ this.chainscript = chainscript;
3725
+ this.errors = {
3726
+ linkHash: [],
3727
+ stateHash: [],
3728
+ merklePath: [],
3729
+ fossil: []
3730
+ };
3731
+ }
3732
+
3733
+ createClass(ChainValidator, [{
3734
+ key: 'validate',
3735
+ value: function validate() {
3736
+ var _this = this;
3737
+
3738
+ try {
3739
+ return resolveLinks(wrap(parseIfJson(this.chainscript))).then(function (segments) {
3740
+ wrap(segments).forEach(function (segment) {
3741
+ return new SegmentValidator(segment).validate(_this.errors);
3742
+ });
3743
+ return _this.errors;
3744
+ });
3745
+ } catch (err) {
3746
+ return Promise.reject(err);
3747
+ }
3748
+ }
3749
+ }]);
3750
+ return ChainValidator;
3751
+ }();
3752
+
3753
+ var margin$1 = { top: 10, right: 5, bottom: 20, left: 5 };
3754
+ var height$1 = 350 - margin$1.top - margin$1.bottom;
3755
+ var width = 400 - margin$1.left - margin$1.right;
3756
+
3757
+ var MerklePathTree = function () {
3758
+ function MerklePathTree(element) {
3759
+ classCallCheck(this, MerklePathTree);
3760
+
3761
+ this.tree = d3Hierarchy.tree().size([width, height$1]);
3762
+ this.svg = d3Selection.select(element).append('svg').attr('width', width + margin$1.right + margin$1.left).attr('height', height$1 + margin$1.top + margin$1.bottom);
3763
+ this.innerG = this.svg.append('g').attr('transform', function () {
3764
+ return translate(margin$1.top, margin$1.left);
3765
+ });
3766
+ this.root = null;
3767
+ }
3768
+
3769
+ createClass(MerklePathTree, [{
3770
+ key: 'display',
3771
+ value: function display(merklePath) {
3772
+ if (merklePath && merklePath.length) {
3773
+ this.root = this._parse(merklePath);
3774
+ this._update(this.root.descendants(), this.root.links());
3775
+ } else {
3776
+ this.root = null;
3777
+ this._update([], []);
3778
+ }
3779
+ }
3780
+ }, {
3781
+ key: '_parse',
3782
+ value: function _parse(merklePath) {
3783
+ var nodes = [];
3784
+
3785
+ merklePath.forEach(function (path, index) {
3786
+ nodes.push({
3787
+ id: path.left + '-' + index,
3788
+ name: path.left,
3789
+ parentId: path.parent + '-' + (index + 1)
3790
+ });
3791
+ if (path.right) {
3792
+ nodes.push({
3793
+ id: path.right + '-' + index,
3794
+ name: path.right,
3795
+ parentId: path.parent + '-' + (index + 1)
3796
+ });
3797
+ }
3798
+ });
3799
+
3800
+ var root = merklePath[merklePath.length - 1].parent;
3801
+ nodes.push({
3802
+ id: root + '-' + merklePath.length,
3803
+ name: root
3804
+ });
3805
+
3806
+ return d3Hierarchy.stratify()(nodes);
3807
+ }
3808
+ }, {
3809
+ key: '_update',
3810
+ value: function _update(nodes, links) {
3811
+ // Compute the new tree layout.
3812
+ if (this.root) {
3813
+ this.tree(this.root);
3814
+ }
3815
+
3816
+ // Update the nodes…
3817
+ var node = this.innerG.selectAll('g.node').data(nodes, function key(d) {
3818
+ return d ? d.id : this.id;
3819
+ });
3820
+
3821
+ // Enter any new nodes at the parent's previous position.
3822
+ var nodeEnter = node.enter().append('g').attr('class', 'node').attr('transform', function (d) {
3823
+ return translate(d.y, d.x);
3824
+ });
3825
+
3826
+ nodeEnter.append('circle').attr('r', 10);
3827
+
3828
+ nodeEnter.append('text').attr('dx', 0).attr('dy', 5).attr('text-anchor', 'middle').text(function (d) {
3829
+ return compactHash(d.data.name);
3830
+ });
3831
+
3832
+ nodeEnter.on('mouseover', function go(d) {
3833
+ d3Selection.select(this).select('text').text(d.data.name);
3834
+ }).on('mouseout', function go(d) {
3835
+ d3Selection.select(this).select('text').text(compactHash(d.data.name));
3836
+ });
3837
+
3838
+ node.exit().remove();
3839
+
3840
+ // Update the links...
3841
+ var link = this.innerG.selectAll('path.link').data(links, function key(d) {
3842
+ return d ? d.target.id : this.id;
3843
+ });
3844
+
3845
+ // Enter any new links at the parent's previous position.
3846
+ link.enter().insert('path', 'g').attr('class', 'link').attr('id', function (d) {
3847
+ return d.target.id;
3848
+ }).attr('d', function (d) {
3849
+ return makeLink({ x: d.source.y, y: d.source.x }, { x: d.target.y, y: d.target.x });
3850
+ });
3851
+
3852
+ // Transition exiting nodes to the parent's new position.
3853
+ link.exit().remove();
3854
+ }
3855
+ }]);
3856
+ return MerklePathTree;
3857
+ }();
3858
+
3859
+ exports.ChainTreeBuilder = ChainTreeBuilder;
3860
+ exports.defaultOptions = defaultOptions;
3861
+ exports.ChainTree = ChainTree;
3862
+ exports.ChainValidator = ChainValidator;
3863
+ exports.SegmentValidator = SegmentValidator;
3864
+ exports.MerklePathTree = MerklePathTree;
3865
+ exports.compactHash = compactHash;
3866
+ exports.parseChainscript = parseChainscript;
3867
+ exports.resolveLinks = resolveLinks;
3868
+
3869
+ Object.defineProperty(exports, '__esModule', { value: true });
3870
+
3871
+ })));
3872
+ //# sourceMappingURL=mapexplorer-core.js.map