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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +202 -0
  3. data/README.md +1 -1
  4. data/app/assets/javascripts/mapexplorer-rails.js +16 -0
  5. data/app/assets/stylesheets/mapexplorer-rails.scss +16 -0
  6. data/app/helpers/mapexplorer_helper.rb +14 -0
  7. data/config/routes.rb +14 -0
  8. data/lib/mapexplorer/rails.rb +14 -0
  9. data/lib/mapexplorer/rails/engine.rb +14 -0
  10. data/lib/mapexplorer/rails/version.rb +15 -1
  11. data/lib/tasks/mapexplorer/rails_tasks.rake +14 -0
  12. data/vendor/assets/mapexplorer-core/LICENSE +202 -21
  13. data/vendor/assets/mapexplorer-core/LICENSE_HEADER +15 -0
  14. data/vendor/assets/mapexplorer-core/bower.json +1 -1
  15. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js +1552 -330
  16. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js.map +1 -1
  17. data/vendor/assets/mapexplorer-core/karma.conf.js +4 -2
  18. data/vendor/assets/mapexplorer-core/package-lock.json +3486 -0
  19. data/vendor/assets/mapexplorer-core/package.json +8 -8
  20. data/vendor/assets/mapexplorer-core/update-license-headers.sh +20 -0
  21. data/vendor/assets/stratumn-agent-client/LICENSE +202 -0
  22. data/vendor/assets/stratumn-agent-client/LICENSE_HEADER +15 -0
  23. data/vendor/assets/stratumn-agent-client/README.md +268 -0
  24. data/vendor/assets/stratumn-agent-client/bower.json +27 -0
  25. data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.js +1449 -0
  26. data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.js.map +1 -0
  27. data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.min.js +2 -0
  28. data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.min.js.map +1 -0
  29. data/vendor/assets/stratumn-agent-client/examples/browser/index.html +34 -0
  30. data/vendor/assets/stratumn-agent-client/package.json +69 -0
  31. data/vendor/assets/stratumn-agent-client/rollup.base.config.js +13 -0
  32. data/vendor/assets/stratumn-agent-client/rollup.bower.config.js +18 -0
  33. data/vendor/assets/stratumn-agent-client/rollup.bower.min.config.js +7 -0
  34. data/vendor/assets/stratumn-agent-client/rollup.es.config.js +9 -0
  35. data/vendor/assets/stratumn-agent-client/rollup.umd.config.js +10 -0
  36. data/vendor/assets/stratumn-agent-client/update-license-headers.sh +20 -0
  37. metadata +25 -7
  38. data/MIT-LICENSE +0 -20
  39. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.min.js +0 -35
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2017 Stratumn SAS. All rights reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
@@ -27,6 +27,6 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "d3": "^4.1.1",
30
- "stratumn-sdk": "alpha"
30
+ "stratumn-agent-client": "1.9.0"
31
31
  }
32
32
  }
@@ -4,8 +4,24 @@
4
4
  (factory((global.mapexplorerCore = global.mapexplorerCore || {}),global.d3,global.d3,global.d3,global.d3,global.d3,global.d3));
5
5
  }(this, (function (exports,d3Hierarchy,d3Transition,d3Ease,d3Selection,d3Zoom,d3Array) { 'use strict';
6
6
 
7
+ /*
8
+ Copyright 2017 Stratumn SAS. All rights reserved.
9
+
10
+ Licensed under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License.
12
+ You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software
17
+ distributed under the License is distributed on an "AS IS" BASIS,
18
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ See the License for the specific language governing permissions and
20
+ limitations under the License.
21
+ */
22
+
7
23
  function makeLink(source, target) {
8
- var margin = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
24
+ var margin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
9
25
 
10
26
  var finalTarget = target || source;
11
27
  var targetX = finalTarget.x;
@@ -21,20 +37,149 @@ function translate(x, y) {
21
37
  return "translate(" + y + ", " + x + ")";
22
38
  }
23
39
 
40
+ /*
41
+ Copyright 2017 Stratumn SAS. All rights reserved.
42
+
43
+ Licensed under the Apache License, Version 2.0 (the "License");
44
+ you may not use this file except in compliance with the License.
45
+ You may obtain a copy of the License at
46
+
47
+ http://www.apache.org/licenses/LICENSE-2.0
48
+
49
+ Unless required by applicable law or agreed to in writing, software
50
+ distributed under the License is distributed on an "AS IS" BASIS,
51
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
+ See the License for the specific language governing permissions and
53
+ limitations under the License.
54
+ */
55
+
24
56
  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);
57
+ return d3Hierarchy.stratify().id(function (d) {
58
+ return d.meta.linkHash;
59
+ }).parentId(function (d) {
60
+ return d.link.meta.prevLinkHash;
61
+ })(chainscript);
30
62
  }
31
63
 
32
64
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
33
65
  return typeof obj;
34
66
  } : function (obj) {
35
- return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
67
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
36
68
  };
37
69
 
70
+ var asyncGenerator = function () {
71
+ function AwaitValue(value) {
72
+ this.value = value;
73
+ }
74
+
75
+ function AsyncGenerator(gen) {
76
+ var front, back;
77
+
78
+ function send(key, arg) {
79
+ return new Promise(function (resolve, reject) {
80
+ var request = {
81
+ key: key,
82
+ arg: arg,
83
+ resolve: resolve,
84
+ reject: reject,
85
+ next: null
86
+ };
87
+
88
+ if (back) {
89
+ back = back.next = request;
90
+ } else {
91
+ front = back = request;
92
+ resume(key, arg);
93
+ }
94
+ });
95
+ }
96
+
97
+ function resume(key, arg) {
98
+ try {
99
+ var result = gen[key](arg);
100
+ var value = result.value;
101
+
102
+ if (value instanceof AwaitValue) {
103
+ Promise.resolve(value.value).then(function (arg) {
104
+ resume("next", arg);
105
+ }, function (arg) {
106
+ resume("throw", arg);
107
+ });
108
+ } else {
109
+ settle(result.done ? "return" : "normal", result.value);
110
+ }
111
+ } catch (err) {
112
+ settle("throw", err);
113
+ }
114
+ }
115
+
116
+ function settle(type, value) {
117
+ switch (type) {
118
+ case "return":
119
+ front.resolve({
120
+ value: value,
121
+ done: true
122
+ });
123
+ break;
124
+
125
+ case "throw":
126
+ front.reject(value);
127
+ break;
128
+
129
+ default:
130
+ front.resolve({
131
+ value: value,
132
+ done: false
133
+ });
134
+ break;
135
+ }
136
+
137
+ front = front.next;
138
+
139
+ if (front) {
140
+ resume(front.key, front.arg);
141
+ } else {
142
+ back = null;
143
+ }
144
+ }
145
+
146
+ this._invoke = send;
147
+
148
+ if (typeof gen.return !== "function") {
149
+ this.return = undefined;
150
+ }
151
+ }
152
+
153
+ if (typeof Symbol === "function" && Symbol.asyncIterator) {
154
+ AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
155
+ return this;
156
+ };
157
+ }
158
+
159
+ AsyncGenerator.prototype.next = function (arg) {
160
+ return this._invoke("next", arg);
161
+ };
162
+
163
+ AsyncGenerator.prototype.throw = function (arg) {
164
+ return this._invoke("throw", arg);
165
+ };
166
+
167
+ AsyncGenerator.prototype.return = function (arg) {
168
+ return this._invoke("return", arg);
169
+ };
170
+
171
+ return {
172
+ wrap: function (fn) {
173
+ return function () {
174
+ return new AsyncGenerator(fn.apply(this, arguments));
175
+ };
176
+ },
177
+ await: function (value) {
178
+ return new AwaitValue(value);
179
+ }
180
+ };
181
+ }();
182
+
38
183
  var classCallCheck = function (instance, Constructor) {
39
184
  if (!(instance instanceof Constructor)) {
40
185
  throw new TypeError("Cannot call a class as a function");
@@ -83,6 +228,22 @@ var toConsumableArray = function (arr) {
83
228
  }
84
229
  };
85
230
 
231
+ /*
232
+ Copyright 2017 Stratumn SAS. All rights reserved.
233
+
234
+ Licensed under the Apache License, Version 2.0 (the "License");
235
+ you may not use this file except in compliance with the License.
236
+ You may obtain a copy of the License at
237
+
238
+ http://www.apache.org/licenses/LICENSE-2.0
239
+
240
+ Unless required by applicable law or agreed to in writing, software
241
+ distributed under the License is distributed on an "AS IS" BASIS,
242
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
243
+ See the License for the specific language governing permissions and
244
+ limitations under the License.
245
+ */
246
+
86
247
  var margin = { top: 20, right: 120, bottom: 20, left: 120 };
87
248
  var height = 800 - margin.top - margin.bottom;
88
249
 
@@ -231,6 +392,22 @@ var ChainTree = function () {
231
392
  return ChainTree;
232
393
  }();
233
394
 
395
+ /*
396
+ Copyright 2017 Stratumn SAS. All rights reserved.
397
+
398
+ Licensed under the Apache License, Version 2.0 (the "License");
399
+ you may not use this file except in compliance with the License.
400
+ You may obtain a copy of the License at
401
+
402
+ http://www.apache.org/licenses/LICENSE-2.0
403
+
404
+ Unless required by applicable law or agreed to in writing, software
405
+ distributed under the License is distributed on an "AS IS" BASIS,
406
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
407
+ See the License for the specific language governing permissions and
408
+ limitations under the License.
409
+ */
410
+
234
411
  function compactHash (hash) {
235
412
  return "" + hash.slice(0, 3) + hash.slice(hash.length - 3);
236
413
  }
@@ -302,6 +479,424 @@ return function deepmerge(target, src) {
302
479
 
303
480
  var merge = interopDefault(index);
304
481
 
482
+ var global$1 = typeof global !== "undefined" ? global :
483
+ typeof self !== "undefined" ? self :
484
+ typeof window !== "undefined" ? window : {}
485
+
486
+ // shim for using process in browser
487
+ // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
488
+
489
+ function defaultSetTimout() {
490
+ throw new Error('setTimeout has not been defined');
491
+ }
492
+ function defaultClearTimeout () {
493
+ throw new Error('clearTimeout has not been defined');
494
+ }
495
+ var cachedSetTimeout = defaultSetTimout;
496
+ var cachedClearTimeout = defaultClearTimeout;
497
+ if (typeof global$1.setTimeout === 'function') {
498
+ cachedSetTimeout = setTimeout;
499
+ }
500
+ if (typeof global$1.clearTimeout === 'function') {
501
+ cachedClearTimeout = clearTimeout;
502
+ }
503
+
504
+ function runTimeout(fun) {
505
+ if (cachedSetTimeout === setTimeout) {
506
+ //normal enviroments in sane situations
507
+ return setTimeout(fun, 0);
508
+ }
509
+ // if setTimeout wasn't available but was latter defined
510
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
511
+ cachedSetTimeout = setTimeout;
512
+ return setTimeout(fun, 0);
513
+ }
514
+ try {
515
+ // when when somebody has screwed with setTimeout but no I.E. maddness
516
+ return cachedSetTimeout(fun, 0);
517
+ } catch(e){
518
+ try {
519
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
520
+ return cachedSetTimeout.call(null, fun, 0);
521
+ } catch(e){
522
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
523
+ return cachedSetTimeout.call(this, fun, 0);
524
+ }
525
+ }
526
+
527
+
528
+ }
529
+ function runClearTimeout(marker) {
530
+ if (cachedClearTimeout === clearTimeout) {
531
+ //normal enviroments in sane situations
532
+ return clearTimeout(marker);
533
+ }
534
+ // if clearTimeout wasn't available but was latter defined
535
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
536
+ cachedClearTimeout = clearTimeout;
537
+ return clearTimeout(marker);
538
+ }
539
+ try {
540
+ // when when somebody has screwed with setTimeout but no I.E. maddness
541
+ return cachedClearTimeout(marker);
542
+ } catch (e){
543
+ try {
544
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
545
+ return cachedClearTimeout.call(null, marker);
546
+ } catch (e){
547
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
548
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
549
+ return cachedClearTimeout.call(this, marker);
550
+ }
551
+ }
552
+
553
+
554
+
555
+ }
556
+ var queue = [];
557
+ var draining = false;
558
+ var currentQueue;
559
+ var queueIndex = -1;
560
+
561
+ function cleanUpNextTick() {
562
+ if (!draining || !currentQueue) {
563
+ return;
564
+ }
565
+ draining = false;
566
+ if (currentQueue.length) {
567
+ queue = currentQueue.concat(queue);
568
+ } else {
569
+ queueIndex = -1;
570
+ }
571
+ if (queue.length) {
572
+ drainQueue();
573
+ }
574
+ }
575
+
576
+ function drainQueue() {
577
+ if (draining) {
578
+ return;
579
+ }
580
+ var timeout = runTimeout(cleanUpNextTick);
581
+ draining = true;
582
+
583
+ var len = queue.length;
584
+ while(len) {
585
+ currentQueue = queue;
586
+ queue = [];
587
+ while (++queueIndex < len) {
588
+ if (currentQueue) {
589
+ currentQueue[queueIndex].run();
590
+ }
591
+ }
592
+ queueIndex = -1;
593
+ len = queue.length;
594
+ }
595
+ currentQueue = null;
596
+ draining = false;
597
+ runClearTimeout(timeout);
598
+ }
599
+ function nextTick(fun) {
600
+ var args = new Array(arguments.length - 1);
601
+ if (arguments.length > 1) {
602
+ for (var i = 1; i < arguments.length; i++) {
603
+ args[i - 1] = arguments[i];
604
+ }
605
+ }
606
+ queue.push(new Item(fun, args));
607
+ if (queue.length === 1 && !draining) {
608
+ runTimeout(drainQueue);
609
+ }
610
+ }
611
+ // v8 likes predictible objects
612
+ function Item(fun, array) {
613
+ this.fun = fun;
614
+ this.array = array;
615
+ }
616
+ Item.prototype.run = function () {
617
+ this.fun.apply(null, this.array);
618
+ };
619
+ var title = 'browser';
620
+ var platform = 'browser';
621
+ var browser = true;
622
+ var env = {};
623
+ var argv = [];
624
+ var version = ''; // empty string to avoid regexp issues
625
+ var versions = {};
626
+ var release = {};
627
+ var config$1 = {};
628
+
629
+ function noop() {}
630
+
631
+ var on = noop;
632
+ var addListener = noop;
633
+ var once = noop;
634
+ var off = noop;
635
+ var removeListener = noop;
636
+ var removeAllListeners = noop;
637
+ var emit = noop;
638
+
639
+ function binding(name) {
640
+ throw new Error('process.binding is not supported');
641
+ }
642
+
643
+ function cwd () { return '/' }
644
+ function chdir (dir) {
645
+ throw new Error('process.chdir is not supported');
646
+ };
647
+ function umask() { return 0; }
648
+
649
+ // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
650
+ var performance = global$1.performance || {}
651
+ var performanceNow =
652
+ performance.now ||
653
+ performance.mozNow ||
654
+ performance.msNow ||
655
+ performance.oNow ||
656
+ performance.webkitNow ||
657
+ function(){ return (new Date()).getTime() }
658
+
659
+ // generate timestamp or delta
660
+ // see http://nodejs.org/api/process.html#process_process_hrtime
661
+ function hrtime(previousTimestamp){
662
+ var clocktime = performanceNow.call(performance)*1e-3
663
+ var seconds = Math.floor(clocktime)
664
+ var nanoseconds = Math.floor((clocktime%1)*1e9)
665
+ if (previousTimestamp) {
666
+ seconds = seconds - previousTimestamp[0]
667
+ nanoseconds = nanoseconds - previousTimestamp[1]
668
+ if (nanoseconds<0) {
669
+ seconds--
670
+ nanoseconds += 1e9
671
+ }
672
+ }
673
+ return [seconds,nanoseconds]
674
+ }
675
+
676
+ var startTime = new Date();
677
+ function uptime() {
678
+ var currentTime = new Date();
679
+ var dif = currentTime - startTime;
680
+ return dif / 1000;
681
+ }
682
+
683
+ var process = {
684
+ nextTick: nextTick,
685
+ title: title,
686
+ browser: browser,
687
+ env: env,
688
+ argv: argv,
689
+ version: version,
690
+ versions: versions,
691
+ on: on,
692
+ addListener: addListener,
693
+ once: once,
694
+ off: off,
695
+ removeListener: removeListener,
696
+ removeAllListeners: removeAllListeners,
697
+ emit: emit,
698
+ binding: binding,
699
+ cwd: cwd,
700
+ chdir: chdir,
701
+ umask: umask,
702
+ hrtime: hrtime,
703
+ platform: platform,
704
+ release: release,
705
+ config: config$1,
706
+ uptime: uptime
707
+ };
708
+
709
+ var setImmediate$1 = createCommonjsModule(function (module) {
710
+ (function (global, undefined) {
711
+ "use strict";
712
+
713
+ if (global.setImmediate) {
714
+ return;
715
+ }
716
+
717
+ var nextHandle = 1; // Spec says greater than zero
718
+ var tasksByHandle = {};
719
+ var currentlyRunningATask = false;
720
+ var doc = global.document;
721
+ var registerImmediate;
722
+
723
+ function setImmediate(callback) {
724
+ // Callback can either be a function or a string
725
+ if (typeof callback !== "function") {
726
+ callback = new Function("" + callback);
727
+ }
728
+ // Copy function arguments
729
+ var args = new Array(arguments.length - 1);
730
+ for (var i = 0; i < args.length; i++) {
731
+ args[i] = arguments[i + 1];
732
+ }
733
+ // Store and register the task
734
+ var task = { callback: callback, args: args };
735
+ tasksByHandle[nextHandle] = task;
736
+ registerImmediate(nextHandle);
737
+ return nextHandle++;
738
+ }
739
+
740
+ function clearImmediate(handle) {
741
+ delete tasksByHandle[handle];
742
+ }
743
+
744
+ function run(task) {
745
+ var callback = task.callback;
746
+ var args = task.args;
747
+ switch (args.length) {
748
+ case 0:
749
+ callback();
750
+ break;
751
+ case 1:
752
+ callback(args[0]);
753
+ break;
754
+ case 2:
755
+ callback(args[0], args[1]);
756
+ break;
757
+ case 3:
758
+ callback(args[0], args[1], args[2]);
759
+ break;
760
+ default:
761
+ callback.apply(undefined, args);
762
+ break;
763
+ }
764
+ }
765
+
766
+ function runIfPresent(handle) {
767
+ // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
768
+ // So if we're currently running a task, we'll need to delay this invocation.
769
+ if (currentlyRunningATask) {
770
+ // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
771
+ // "too much recursion" error.
772
+ setTimeout(runIfPresent, 0, handle);
773
+ } else {
774
+ var task = tasksByHandle[handle];
775
+ if (task) {
776
+ currentlyRunningATask = true;
777
+ try {
778
+ run(task);
779
+ } finally {
780
+ clearImmediate(handle);
781
+ currentlyRunningATask = false;
782
+ }
783
+ }
784
+ }
785
+ }
786
+
787
+ function installNextTickImplementation() {
788
+ registerImmediate = function(handle) {
789
+ nextTick(function () { runIfPresent(handle); });
790
+ };
791
+ }
792
+
793
+ function canUsePostMessage() {
794
+ // The test against `importScripts` prevents this implementation from being installed inside a web worker,
795
+ // where `global.postMessage` means something completely different and can't be used for this purpose.
796
+ if (global.postMessage && !global.importScripts) {
797
+ var postMessageIsAsynchronous = true;
798
+ var oldOnMessage = global.onmessage;
799
+ global.onmessage = function() {
800
+ postMessageIsAsynchronous = false;
801
+ };
802
+ global.postMessage("", "*");
803
+ global.onmessage = oldOnMessage;
804
+ return postMessageIsAsynchronous;
805
+ }
806
+ }
807
+
808
+ function installPostMessageImplementation() {
809
+ // Installs an event handler on `global` for the `message` event: see
810
+ // * https://developer.mozilla.org/en/DOM/window.postMessage
811
+ // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
812
+
813
+ var messagePrefix = "setImmediate$" + Math.random() + "$";
814
+ var onGlobalMessage = function(event) {
815
+ if (event.source === global &&
816
+ typeof event.data === "string" &&
817
+ event.data.indexOf(messagePrefix) === 0) {
818
+ runIfPresent(+event.data.slice(messagePrefix.length));
819
+ }
820
+ };
821
+
822
+ if (global.addEventListener) {
823
+ global.addEventListener("message", onGlobalMessage, false);
824
+ } else {
825
+ global.attachEvent("onmessage", onGlobalMessage);
826
+ }
827
+
828
+ registerImmediate = function(handle) {
829
+ global.postMessage(messagePrefix + handle, "*");
830
+ };
831
+ }
832
+
833
+ function installMessageChannelImplementation() {
834
+ var channel = new MessageChannel();
835
+ channel.port1.onmessage = function(event) {
836
+ var handle = event.data;
837
+ runIfPresent(handle);
838
+ };
839
+
840
+ registerImmediate = function(handle) {
841
+ channel.port2.postMessage(handle);
842
+ };
843
+ }
844
+
845
+ function installReadyStateChangeImplementation() {
846
+ var html = doc.documentElement;
847
+ registerImmediate = function(handle) {
848
+ // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
849
+ // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
850
+ var script = doc.createElement("script");
851
+ script.onreadystatechange = function () {
852
+ runIfPresent(handle);
853
+ script.onreadystatechange = null;
854
+ html.removeChild(script);
855
+ script = null;
856
+ };
857
+ html.appendChild(script);
858
+ };
859
+ }
860
+
861
+ function installSetTimeoutImplementation() {
862
+ registerImmediate = function(handle) {
863
+ setTimeout(runIfPresent, 0, handle);
864
+ };
865
+ }
866
+
867
+ // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
868
+ var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
869
+ attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
870
+
871
+ // Don't get fooled by e.g. browserify environments.
872
+ if ({}.toString.call(global.process) === "[object process]") {
873
+ // For Node.js before 0.9
874
+ installNextTickImplementation();
875
+
876
+ } else if (canUsePostMessage()) {
877
+ // For non-IE10 modern browsers
878
+ installPostMessageImplementation();
879
+
880
+ } else if (global.MessageChannel) {
881
+ // For web workers, where supported
882
+ installMessageChannelImplementation();
883
+
884
+ } else if (doc && "onreadystatechange" in doc.createElement("script")) {
885
+ // For IE 6–8
886
+ installReadyStateChangeImplementation();
887
+
888
+ } else {
889
+ // For older browsers
890
+ installSetTimeoutImplementation();
891
+ }
892
+
893
+ attachTo.setImmediate = setImmediate;
894
+ attachTo.clearImmediate = clearImmediate;
895
+ }(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
896
+ });
897
+
898
+ interopDefault(setImmediate$1);
899
+
305
900
  var jsonrequest = createCommonjsModule(function (module) {
306
901
  'use strict';
307
902
 
@@ -646,7 +1241,7 @@ var require$$4 = Object.freeze({
646
1241
  default: error$1
647
1242
  });
648
1243
 
649
- var once = createCommonjsModule(function (module) {
1244
+ var once$1 = createCommonjsModule(function (module) {
650
1245
  'use strict';
651
1246
 
652
1247
  // A "once" utility.
@@ -662,11 +1257,11 @@ module.exports = function(fn) {
662
1257
  };
663
1258
  });
664
1259
 
665
- var once$1 = interopDefault(once);
1260
+ var once$2 = interopDefault(once$1);
666
1261
 
667
1262
 
668
1263
  var require$$0$3 = Object.freeze({
669
- default: once$1
1264
+ default: once$2
670
1265
  });
671
1266
 
672
1267
  var index$1 = createCommonjsModule(function (module) {
@@ -886,6 +1481,22 @@ function getError(req, err) {
886
1481
 
887
1482
  var httpplease = interopDefault(index$1);
888
1483
 
1484
+ /*
1485
+ Copyright 2017 Stratumn SAS. All rights reserved.
1486
+
1487
+ Licensed under the Apache License, Version 2.0 (the "License");
1488
+ you may not use this file except in compliance with the License.
1489
+ You may obtain a copy of the License at
1490
+
1491
+ http://www.apache.org/licenses/LICENSE-2.0
1492
+
1493
+ Unless required by applicable law or agreed to in writing, software
1494
+ distributed under the License is distributed on an "AS IS" BASIS,
1495
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1496
+ See the License for the specific language governing permissions and
1497
+ limitations under the License.
1498
+ */
1499
+
889
1500
  function deprecated(oldFunc, newFunc) {
890
1501
  if (!newFunc) {
891
1502
  console.warn("WARNING: " + oldFunc + " is deprecated.");
@@ -894,6 +1505,22 @@ function deprecated(oldFunc, newFunc) {
894
1505
  }
895
1506
  }
896
1507
 
1508
+ /*
1509
+ Copyright 2017 Stratumn SAS. All rights reserved.
1510
+
1511
+ Licensed under the Apache License, Version 2.0 (the "License");
1512
+ you may not use this file except in compliance with the License.
1513
+ You may obtain a copy of the License at
1514
+
1515
+ http://www.apache.org/licenses/LICENSE-2.0
1516
+
1517
+ Unless required by applicable law or agreed to in writing, software
1518
+ distributed under the License is distributed on an "AS IS" BASIS,
1519
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1520
+ See the License for the specific language governing permissions and
1521
+ limitations under the License.
1522
+ */
1523
+
897
1524
  /**
898
1525
  * Makes a query string.
899
1526
  * @param {object} obj - an object of keys
@@ -913,6 +1540,65 @@ function makeQueryString(obj) {
913
1540
  return '';
914
1541
  }
915
1542
 
1543
+ /*
1544
+ Copyright 2017 Stratumn SAS. All rights reserved.
1545
+
1546
+ Licensed under the Apache License, Version 2.0 (the "License");
1547
+ you may not use this file except in compliance with the License.
1548
+ You may obtain a copy of the License at
1549
+
1550
+ http://www.apache.org/licenses/LICENSE-2.0
1551
+
1552
+ Unless required by applicable law or agreed to in writing, software
1553
+ distributed under the License is distributed on an "AS IS" BASIS,
1554
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1555
+ See the License for the specific language governing permissions and
1556
+ limitations under the License.
1557
+ */
1558
+
1559
+ /**
1560
+ * Calls a function that returns a Promise until a condition is reached
1561
+ * @param {function} condition - while condition is true body will keep being called
1562
+ * @param {function} body - a function that is repeatedly called while condition is true
1563
+ * @returns {Promise} a Promise that resolves when the condition is no longer true
1564
+ */
1565
+ function promiseWhile(condition, body) {
1566
+ return new Promise(function (resolve, reject) {
1567
+ function loop() {
1568
+ body().then(function () {
1569
+ // When the result of calling `condition` is no longer true, we are
1570
+ // done.
1571
+ if (!condition()) {
1572
+ resolve();
1573
+ } else {
1574
+ loop();
1575
+ }
1576
+ }).catch(reject);
1577
+ }
1578
+
1579
+ // Start running the loop in the next tick so that this function is
1580
+ // completely async. It would be unexpected if `body` was called
1581
+ // synchronously the first time.
1582
+ setImmediate(loop);
1583
+ });
1584
+ }
1585
+
1586
+ /*
1587
+ Copyright 2017 Stratumn SAS. All rights reserved.
1588
+
1589
+ Licensed under the Apache License, Version 2.0 (the "License");
1590
+ you may not use this file except in compliance with the License.
1591
+ You may obtain a copy of the License at
1592
+
1593
+ http://www.apache.org/licenses/LICENSE-2.0
1594
+
1595
+ Unless required by applicable law or agreed to in writing, software
1596
+ distributed under the License is distributed on an "AS IS" BASIS,
1597
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1598
+ See the License for the specific language governing permissions and
1599
+ limitations under the License.
1600
+ */
1601
+
916
1602
  var request = httpplease.use(json$1);
917
1603
 
918
1604
  function send(method, url, args) {
@@ -937,8 +1623,168 @@ function post(url, args) {
937
1623
  return send('POST', url, args);
938
1624
  }
939
1625
 
1626
+ var asyncGenerator$1 = function () {
1627
+ function AwaitValue(value) {
1628
+ this.value = value;
1629
+ }
1630
+
1631
+ function AsyncGenerator(gen) {
1632
+ var front, back;
1633
+
1634
+ function send(key, arg) {
1635
+ return new Promise(function (resolve, reject) {
1636
+ var request = {
1637
+ key: key,
1638
+ arg: arg,
1639
+ resolve: resolve,
1640
+ reject: reject,
1641
+ next: null
1642
+ };
1643
+
1644
+ if (back) {
1645
+ back = back.next = request;
1646
+ } else {
1647
+ front = back = request;
1648
+ resume(key, arg);
1649
+ }
1650
+ });
1651
+ }
1652
+
1653
+ function resume(key, arg) {
1654
+ try {
1655
+ var result = gen[key](arg);
1656
+ var value = result.value;
1657
+
1658
+ if (value instanceof AwaitValue) {
1659
+ Promise.resolve(value.value).then(function (arg) {
1660
+ resume("next", arg);
1661
+ }, function (arg) {
1662
+ resume("throw", arg);
1663
+ });
1664
+ } else {
1665
+ settle(result.done ? "return" : "normal", result.value);
1666
+ }
1667
+ } catch (err) {
1668
+ settle("throw", err);
1669
+ }
1670
+ }
1671
+
1672
+ function settle(type, value) {
1673
+ switch (type) {
1674
+ case "return":
1675
+ front.resolve({
1676
+ value: value,
1677
+ done: true
1678
+ });
1679
+ break;
1680
+
1681
+ case "throw":
1682
+ front.reject(value);
1683
+ break;
1684
+
1685
+ default:
1686
+ front.resolve({
1687
+ value: value,
1688
+ done: false
1689
+ });
1690
+ break;
1691
+ }
1692
+
1693
+ front = front.next;
1694
+
1695
+ if (front) {
1696
+ resume(front.key, front.arg);
1697
+ } else {
1698
+ back = null;
1699
+ }
1700
+ }
1701
+
1702
+ this._invoke = send;
1703
+
1704
+ if (typeof gen.return !== "function") {
1705
+ this.return = undefined;
1706
+ }
1707
+ }
1708
+
1709
+ if (typeof Symbol === "function" && Symbol.asyncIterator) {
1710
+ AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
1711
+ return this;
1712
+ };
1713
+ }
1714
+
1715
+ AsyncGenerator.prototype.next = function (arg) {
1716
+ return this._invoke("next", arg);
1717
+ };
1718
+
1719
+ AsyncGenerator.prototype.throw = function (arg) {
1720
+ return this._invoke("throw", arg);
1721
+ };
1722
+
1723
+ AsyncGenerator.prototype.return = function (arg) {
1724
+ return this._invoke("return", arg);
1725
+ };
1726
+
1727
+ return {
1728
+ wrap: function (fn) {
1729
+ return function () {
1730
+ return new AsyncGenerator(fn.apply(this, arguments));
1731
+ };
1732
+ },
1733
+ await: function (value) {
1734
+ return new AwaitValue(value);
1735
+ }
1736
+ };
1737
+ }();
1738
+
1739
+ var toConsumableArray$1 = function (arr) {
1740
+ if (Array.isArray(arr)) {
1741
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
1742
+
1743
+ return arr2;
1744
+ } else {
1745
+ return Array.from(arr);
1746
+ }
1747
+ };
1748
+
1749
+ /*
1750
+ Copyright 2017 Stratumn SAS. All rights reserved.
1751
+
1752
+ Licensed under the Apache License, Version 2.0 (the "License");
1753
+ you may not use this file except in compliance with the License.
1754
+ You may obtain a copy of the License at
1755
+
1756
+ http://www.apache.org/licenses/LICENSE-2.0
1757
+
1758
+ Unless required by applicable law or agreed to in writing, software
1759
+ distributed under the License is distributed on an "AS IS" BASIS,
1760
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1761
+ See the License for the specific language governing permissions and
1762
+ limitations under the License.
1763
+ */
1764
+
1765
+ var DEFAULT_BATCH_SIZE = 20;
1766
+
940
1767
  function findSegments(agent) {
941
- var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
1768
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1769
+
1770
+ var options = Object.assign({}, opts);
1771
+ if (opts.limit === -1) {
1772
+ options.limit = options.batchSize || DEFAULT_BATCH_SIZE;
1773
+ delete options.batchSize;
1774
+ options.offset = 0;
1775
+ var segments = [];
1776
+
1777
+ return promiseWhile(function () {
1778
+ return segments.length === options.limit;
1779
+ }, function () {
1780
+ return findSegments(agent, options).then(function (newSegments) {
1781
+ segments.push.apply(segments, toConsumableArray$1(newSegments));
1782
+ options.offset += options.limit;
1783
+ });
1784
+ }).then(function () {
1785
+ return segments;
1786
+ });
1787
+ }
942
1788
 
943
1789
  return get$1(agent.url + '/segments' + makeQueryString(opts)).then(function (res) {
944
1790
  return res.body.map(function (obj) {
@@ -947,14 +1793,46 @@ function findSegments(agent) {
947
1793
  });
948
1794
  }
949
1795
 
1796
+ /*
1797
+ Copyright 2017 Stratumn SAS. All rights reserved.
1798
+
1799
+ Licensed under the Apache License, Version 2.0 (the "License");
1800
+ you may not use this file except in compliance with the License.
1801
+ You may obtain a copy of the License at
1802
+
1803
+ http://www.apache.org/licenses/LICENSE-2.0
1804
+
1805
+ Unless required by applicable law or agreed to in writing, software
1806
+ distributed under the License is distributed on an "AS IS" BASIS,
1807
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1808
+ See the License for the specific language governing permissions and
1809
+ limitations under the License.
1810
+ */
1811
+
950
1812
  function getBranches(agent, prevLinkHash) {
951
- var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
1813
+ var tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
952
1814
 
953
1815
  deprecated('Agent#getBranches(agent, prevLinkHash, tags = [])', 'Agent#findSegments(agent, filter)');
954
1816
 
955
1817
  return findSegments(agent, { prevLinkHash: prevLinkHash, tags: tags });
956
1818
  }
957
1819
 
1820
+ /*
1821
+ Copyright 2017 Stratumn SAS. All rights reserved.
1822
+
1823
+ Licensed under the Apache License, Version 2.0 (the "License");
1824
+ you may not use this file except in compliance with the License.
1825
+ You may obtain a copy of the License at
1826
+
1827
+ http://www.apache.org/licenses/LICENSE-2.0
1828
+
1829
+ Unless required by applicable law or agreed to in writing, software
1830
+ distributed under the License is distributed on an "AS IS" BASIS,
1831
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1832
+ See the License for the specific language governing permissions and
1833
+ limitations under the License.
1834
+ */
1835
+
958
1836
  function segmentify(agent, obj) {
959
1837
  Object.keys(agent.agentInfo.actions).filter(function (key) {
960
1838
  return ['init'].indexOf(key) < 0;
@@ -1006,6 +1884,22 @@ function segmentify(agent, obj) {
1006
1884
  return obj;
1007
1885
  }
1008
1886
 
1887
+ /*
1888
+ Copyright 2017 Stratumn SAS. All rights reserved.
1889
+
1890
+ Licensed under the Apache License, Version 2.0 (the "License");
1891
+ you may not use this file except in compliance with the License.
1892
+ You may obtain a copy of the License at
1893
+
1894
+ http://www.apache.org/licenses/LICENSE-2.0
1895
+
1896
+ Unless required by applicable law or agreed to in writing, software
1897
+ distributed under the License is distributed on an "AS IS" BASIS,
1898
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1899
+ See the License for the specific language governing permissions and
1900
+ limitations under the License.
1901
+ */
1902
+
1009
1903
  function createMap(agent) {
1010
1904
  for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1011
1905
  args[_key - 1] = arguments[_key];
@@ -1016,34 +1910,114 @@ function createMap(agent) {
1016
1910
  });
1017
1911
  }
1018
1912
 
1913
+ /*
1914
+ Copyright 2017 Stratumn SAS. All rights reserved.
1915
+
1916
+ Licensed under the Apache License, Version 2.0 (the "License");
1917
+ you may not use this file except in compliance with the License.
1918
+ You may obtain a copy of the License at
1919
+
1920
+ http://www.apache.org/licenses/LICENSE-2.0
1921
+
1922
+ Unless required by applicable law or agreed to in writing, software
1923
+ distributed under the License is distributed on an "AS IS" BASIS,
1924
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1925
+ See the License for the specific language governing permissions and
1926
+ limitations under the License.
1927
+ */
1928
+
1019
1929
  function getSegment(agent, linkHash) {
1020
1930
  return get$1(agent.url + '/segments/' + linkHash).then(function (res) {
1021
1931
  return segmentify(agent, res.body);
1022
1932
  });
1023
1933
  }
1024
1934
 
1935
+ /*
1936
+ Copyright 2017 Stratumn SAS. All rights reserved.
1937
+
1938
+ Licensed under the Apache License, Version 2.0 (the "License");
1939
+ you may not use this file except in compliance with the License.
1940
+ You may obtain a copy of the License at
1941
+
1942
+ http://www.apache.org/licenses/LICENSE-2.0
1943
+
1944
+ Unless required by applicable law or agreed to in writing, software
1945
+ distributed under the License is distributed on an "AS IS" BASIS,
1946
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1947
+ See the License for the specific language governing permissions and
1948
+ limitations under the License.
1949
+ */
1950
+
1025
1951
  function getMapIds(agent) {
1026
- var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
1952
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1027
1953
 
1028
1954
  return get$1(agent.url + '/maps' + makeQueryString(opts)).then(function (res) {
1029
1955
  return res.body;
1030
1956
  });
1031
1957
  }
1032
1958
 
1959
+ /*
1960
+ Copyright 2017 Stratumn SAS. All rights reserved.
1961
+
1962
+ Licensed under the Apache License, Version 2.0 (the "License");
1963
+ you may not use this file except in compliance with the License.
1964
+ You may obtain a copy of the License at
1965
+
1966
+ http://www.apache.org/licenses/LICENSE-2.0
1967
+
1968
+ Unless required by applicable law or agreed to in writing, software
1969
+ distributed under the License is distributed on an "AS IS" BASIS,
1970
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1971
+ See the License for the specific language governing permissions and
1972
+ limitations under the License.
1973
+ */
1974
+
1033
1975
  function getLink(agent, hash) {
1034
1976
  deprecated('Agent#getLink(agent, hash)', 'Agent#getSegment(agent, hash)');
1035
1977
 
1036
1978
  return getSegment(agent, hash);
1037
1979
  }
1038
1980
 
1981
+ /*
1982
+ Copyright 2017 Stratumn SAS. All rights reserved.
1983
+
1984
+ Licensed under the Apache License, Version 2.0 (the "License");
1985
+ you may not use this file except in compliance with the License.
1986
+ You may obtain a copy of the License at
1987
+
1988
+ http://www.apache.org/licenses/LICENSE-2.0
1989
+
1990
+ Unless required by applicable law or agreed to in writing, software
1991
+ distributed under the License is distributed on an "AS IS" BASIS,
1992
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1993
+ See the License for the specific language governing permissions and
1994
+ limitations under the License.
1995
+ */
1996
+
1039
1997
  function getMap(agent, mapId) {
1040
- var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
1998
+ var tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
1041
1999
 
1042
2000
  deprecated('getMap(agent, mapId, tags = [])', 'findSegments(agent, filter)');
1043
2001
 
1044
2002
  return findSegments(agent, { mapId: mapId, tags: tags });
1045
2003
  }
1046
2004
 
2005
+ /*
2006
+ Copyright 2017 Stratumn SAS. All rights reserved.
2007
+
2008
+ Licensed under the Apache License, Version 2.0 (the "License");
2009
+ you may not use this file except in compliance with the License.
2010
+ You may obtain a copy of the License at
2011
+
2012
+ http://www.apache.org/licenses/LICENSE-2.0
2013
+
2014
+ Unless required by applicable law or agreed to in writing, software
2015
+ distributed under the License is distributed on an "AS IS" BASIS,
2016
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2017
+ See the License for the specific language governing permissions and
2018
+ limitations under the License.
2019
+ */
2020
+
1047
2021
  // Deprecated.
1048
2022
  function getAgent(url) {
1049
2023
  return get$1(url).then(function (res) {
@@ -1064,6 +2038,22 @@ function getAgent(url) {
1064
2038
  });
1065
2039
  }
1066
2040
 
2041
+ /*
2042
+ Copyright 2017 Stratumn SAS. All rights reserved.
2043
+
2044
+ Licensed under the Apache License, Version 2.0 (the "License");
2045
+ you may not use this file except in compliance with the License.
2046
+ You may obtain a copy of the License at
2047
+
2048
+ http://www.apache.org/licenses/LICENSE-2.0
2049
+
2050
+ Unless required by applicable law or agreed to in writing, software
2051
+ distributed under the License is distributed on an "AS IS" BASIS,
2052
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2053
+ See the License for the specific language governing permissions and
2054
+ limitations under the License.
2055
+ */
2056
+
1067
2057
  function fromSegment(obj) {
1068
2058
  return getAgent(obj.meta.agentUrl || obj.meta.applicationLocation).then(function (agent) {
1069
2059
  var segment = segmentify(agent, obj);
@@ -1071,6 +2061,22 @@ function fromSegment(obj) {
1071
2061
  });
1072
2062
  }
1073
2063
 
2064
+ /*
2065
+ Copyright 2017 Stratumn SAS. All rights reserved.
2066
+
2067
+ Licensed under the Apache License, Version 2.0 (the "License");
2068
+ you may not use this file except in compliance with the License.
2069
+ You may obtain a copy of the License at
2070
+
2071
+ http://www.apache.org/licenses/LICENSE-2.0
2072
+
2073
+ Unless required by applicable law or agreed to in writing, software
2074
+ distributed under the License is distributed on an "AS IS" BASIS,
2075
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2076
+ See the License for the specific language governing permissions and
2077
+ limitations under the License.
2078
+ */
2079
+
1074
2080
  function loadLink(obj) {
1075
2081
  deprecated('loadLink(obj)', 'fromSegment(obj)');
1076
2082
 
@@ -1080,6 +2086,22 @@ function loadLink(obj) {
1080
2086
  });
1081
2087
  }
1082
2088
 
2089
+ /*
2090
+ Copyright 2017 Stratumn SAS. All rights reserved.
2091
+
2092
+ Licensed under the Apache License, Version 2.0 (the "License");
2093
+ you may not use this file except in compliance with the License.
2094
+ You may obtain a copy of the License at
2095
+
2096
+ http://www.apache.org/licenses/LICENSE-2.0
2097
+
2098
+ Unless required by applicable law or agreed to in writing, software
2099
+ distributed under the License is distributed on an "AS IS" BASIS,
2100
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2101
+ See the License for the specific language governing permissions and
2102
+ limitations under the License.
2103
+ */
2104
+
1083
2105
  function resolveLinks(segments) {
1084
2106
  return Promise.all(segments.map(function (segment) {
1085
2107
  if (!segment.link.state) {
@@ -1091,6 +2113,22 @@ function resolveLinks(segments) {
1091
2113
  }));
1092
2114
  }
1093
2115
 
2116
+ /*
2117
+ Copyright 2017 Stratumn SAS. All rights reserved.
2118
+
2119
+ Licensed under the Apache License, Version 2.0 (the "License");
2120
+ you may not use this file except in compliance with the License.
2121
+ You may obtain a copy of the License at
2122
+
2123
+ http://www.apache.org/licenses/LICENSE-2.0
2124
+
2125
+ Unless required by applicable law or agreed to in writing, software
2126
+ distributed under the License is distributed on an "AS IS" BASIS,
2127
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2128
+ See the License for the specific language governing permissions and
2129
+ limitations under the License.
2130
+ */
2131
+
1094
2132
  function wrap(arrayOrObject) {
1095
2133
  if (arrayOrObject instanceof Array) {
1096
2134
  return arrayOrObject;
@@ -1098,6 +2136,22 @@ function wrap(arrayOrObject) {
1098
2136
  return [arrayOrObject];
1099
2137
  }
1100
2138
 
2139
+ /*
2140
+ Copyright 2017 Stratumn SAS. All rights reserved.
2141
+
2142
+ Licensed under the Apache License, Version 2.0 (the "License");
2143
+ you may not use this file except in compliance with the License.
2144
+ You may obtain a copy of the License at
2145
+
2146
+ http://www.apache.org/licenses/LICENSE-2.0
2147
+
2148
+ Unless required by applicable law or agreed to in writing, software
2149
+ distributed under the License is distributed on an "AS IS" BASIS,
2150
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2151
+ See the License for the specific language governing permissions and
2152
+ limitations under the License.
2153
+ */
2154
+
1101
2155
  function parseIfJson(object) {
1102
2156
  if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') {
1103
2157
  object = JSON.parse(object);
@@ -1105,6 +2159,22 @@ function parseIfJson(object) {
1105
2159
  return object;
1106
2160
  }
1107
2161
 
2162
+ /*
2163
+ Copyright 2017 Stratumn SAS. All rights reserved.
2164
+
2165
+ Licensed under the Apache License, Version 2.0 (the "License");
2166
+ you may not use this file except in compliance with the License.
2167
+ You may obtain a copy of the License at
2168
+
2169
+ http://www.apache.org/licenses/LICENSE-2.0
2170
+
2171
+ Unless required by applicable law or agreed to in writing, software
2172
+ distributed under the License is distributed on an "AS IS" BASIS,
2173
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2174
+ See the License for the specific language governing permissions and
2175
+ limitations under the License.
2176
+ */
2177
+
1108
2178
  function flatten(arr) {
1109
2179
  var _ref;
1110
2180
 
@@ -1112,12 +2182,44 @@ function flatten(arr) {
1112
2182
  return flat.some(Array.isArray) ? flatten(flat) : flat;
1113
2183
  }
1114
2184
 
2185
+ /*
2186
+ Copyright 2017 Stratumn SAS. All rights reserved.
2187
+
2188
+ Licensed under the Apache License, Version 2.0 (the "License");
2189
+ you may not use this file except in compliance with the License.
2190
+ You may obtain a copy of the License at
2191
+
2192
+ http://www.apache.org/licenses/LICENSE-2.0
2193
+
2194
+ Unless required by applicable law or agreed to in writing, software
2195
+ distributed under the License is distributed on an "AS IS" BASIS,
2196
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2197
+ See the License for the specific language governing permissions and
2198
+ limitations under the License.
2199
+ */
2200
+
1115
2201
  function tagsSet(chainscript) {
1116
2202
  return new Set(flatten(chainscript.map(function (segment) {
1117
2203
  return segment.link.meta.tags;
1118
2204
  })));
1119
2205
  }
1120
2206
 
2207
+ /*
2208
+ Copyright 2017 Stratumn SAS. All rights reserved.
2209
+
2210
+ Licensed under the Apache License, Version 2.0 (the "License");
2211
+ you may not use this file except in compliance with the License.
2212
+ You may obtain a copy of the License at
2213
+
2214
+ http://www.apache.org/licenses/LICENSE-2.0
2215
+
2216
+ Unless required by applicable law or agreed to in writing, software
2217
+ distributed under the License is distributed on an "AS IS" BASIS,
2218
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2219
+ See the License for the specific language governing permissions and
2220
+ limitations under the License.
2221
+ */
2222
+
1121
2223
  var defaultOptions = {
1122
2224
  withArgs: false,
1123
2225
  duration: 750,
@@ -1184,7 +2286,7 @@ var ChainTreeBuilder = function () {
1184
2286
  key: '_load',
1185
2287
  value: function _load(map) {
1186
2288
  return getAgent(map.applicationUrl).then(function (app) {
1187
- return app.findSegments({ mapId: map.id });
2289
+ return app.findSegments({ mapId: map.id, limit: -1 });
1188
2290
  }).catch(function (res) {
1189
2291
  return console.log(res);
1190
2292
  });
@@ -1417,23 +2519,22 @@ module.exports = stringify
1417
2519
  var stringify = interopDefault(index$4);
1418
2520
 
1419
2521
  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
2522
+ /**
2523
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
1425
2524
  *
1426
- * Licensed under the MIT license:
1427
- * http://www.opensource.org/licenses/MIT
2525
+ * @version 0.3.2
2526
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
2527
+ * @copyright Chen, Yi-Cyuan 2014-2016
2528
+ * @license MIT
1428
2529
  */
1429
- ;(function(root, undefined) {
2530
+ (function (root) {
1430
2531
  'use strict';
1431
2532
 
1432
- var NODE_JS = typeof(module) != 'undefined';
1433
- if(NODE_JS) {
2533
+ var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
2534
+ if (NODE_JS) {
1434
2535
  root = commonjsGlobal;
1435
2536
  }
1436
- var TYPED_ARRAY = typeof(Uint8Array) != 'undefined';
2537
+ var COMMON_JS = !root.JS_SHA256_TEST && typeof module == 'object' && module.exports;
1437
2538
  var HEX_CHARS = '0123456789abcdef'.split('');
1438
2539
  var EXTRA = [-2147483648, 8388608, 32768, 128];
1439
2540
  var SHIFT = [24, 16, 8, 0];
@@ -1448,13 +2549,13 @@ var sha256 = createCommonjsModule(function (module) {
1448
2549
 
1449
2550
  var blocks = [];
1450
2551
 
1451
- var sha224 = function(message) {
2552
+ var sha224 = function (message) {
1452
2553
  return sha256(message, true);
1453
2554
  };
1454
2555
 
1455
- var sha256 = function(message, is224) {
1456
- var notString = typeof(message) != 'string';
1457
- if(notString && message.constructor == root.ArrayBuffer) {
2556
+ var sha256 = function (message, is224) {
2557
+ var notString = typeof message != 'string';
2558
+ if (notString && message.constructor == root.ArrayBuffer) {
1458
2559
  message = new Uint8Array(message);
1459
2560
  }
1460
2561
 
@@ -1462,7 +2563,7 @@ var sha256 = createCommonjsModule(function (module) {
1462
2563
  i, j, index = 0, start = 0, bytes = 0, length = message.length,
1463
2564
  s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
1464
2565
 
1465
- if(is224) {
2566
+ if (is224) {
1466
2567
  h0 = 0xc1059ed8;
1467
2568
  h1 = 0x367cd507;
1468
2569
  h2 = 0x3070dd17;
@@ -1488,12 +2589,12 @@ var sha256 = createCommonjsModule(function (module) {
1488
2589
  blocks[4] = blocks[5] = blocks[6] = blocks[7] =
1489
2590
  blocks[8] = blocks[9] = blocks[10] = blocks[11] =
1490
2591
  blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
1491
- if(notString) {
1492
- for (i = start;index < length && i < 64; ++index) {
2592
+ if (notString) {
2593
+ for (i = start;index < length && i < 64;++index) {
1493
2594
  blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
1494
2595
  }
1495
2596
  } else {
1496
- for (i = start;index < length && i < 64; ++index) {
2597
+ for (i = start;index < length && i < 64;++index) {
1497
2598
  code = message.charCodeAt(index);
1498
2599
  if (code < 0x80) {
1499
2600
  blocks[i >> 2] |= code << SHIFT[i++ & 3];
@@ -1515,18 +2616,18 @@ var sha256 = createCommonjsModule(function (module) {
1515
2616
  }
1516
2617
  bytes += i - start;
1517
2618
  start = i - 64;
1518
- if(index == length) {
2619
+ if (index == length) {
1519
2620
  blocks[i >> 2] |= EXTRA[i & 3];
1520
2621
  ++index;
1521
2622
  }
1522
2623
  block = blocks[16];
1523
- if(index > length && i < 56) {
2624
+ if (index > length && i < 56) {
1524
2625
  blocks[15] = bytes << 3;
1525
2626
  end = true;
1526
2627
  }
1527
2628
 
1528
2629
  var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
1529
- for(j = 16;j < 64;++j) {
2630
+ for (j = 16;j < 64;++j) {
1530
2631
  // rightrotate
1531
2632
  t1 = blocks[j - 15];
1532
2633
  s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
@@ -1536,9 +2637,9 @@ var sha256 = createCommonjsModule(function (module) {
1536
2637
  }
1537
2638
 
1538
2639
  bc = b & c;
1539
- for(j = 0;j < 64;j += 4) {
1540
- if(first) {
1541
- if(is224) {
2640
+ for (j = 0;j < 64;j += 4) {
2641
+ if (first) {
2642
+ if (is224) {
1542
2643
  ab = 300032;
1543
2644
  t1 = blocks[0] - 1413257819;
1544
2645
  h = t1 - 150054599 << 0;
@@ -1598,7 +2699,7 @@ var sha256 = createCommonjsModule(function (module) {
1598
2699
  h5 = h5 + f << 0;
1599
2700
  h6 = h6 + g << 0;
1600
2701
  h7 = h7 + h << 0;
1601
- } while(!end);
2702
+ } while (!end);
1602
2703
 
1603
2704
  var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
1604
2705
  HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
@@ -1628,7 +2729,7 @@ var sha256 = createCommonjsModule(function (module) {
1628
2729
  HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
1629
2730
  HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
1630
2731
  HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
1631
- if(!is224) {
2732
+ if (!is224) {
1632
2733
  hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
1633
2734
  HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
1634
2735
  HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
@@ -1637,11 +2738,11 @@ var sha256 = createCommonjsModule(function (module) {
1637
2738
  return hex;
1638
2739
  };
1639
2740
 
1640
- if(!root.JS_SHA256_TEST && NODE_JS) {
2741
+ if (COMMON_JS) {
1641
2742
  sha256.sha256 = sha256;
1642
2743
  sha256.sha224 = sha224;
1643
2744
  module.exports = sha256;
1644
- } else if(root) {
2745
+ } else if (root) {
1645
2746
  root.sha256 = sha256;
1646
2747
  root.sha224 = sha224;
1647
2748
  }
@@ -1650,6 +2751,22 @@ var sha256 = createCommonjsModule(function (module) {
1650
2751
 
1651
2752
  var sha256$1 = interopDefault(sha256);
1652
2753
 
2754
+ /*
2755
+ Copyright 2017 Stratumn SAS. All rights reserved.
2756
+
2757
+ Licensed under the Apache License, Version 2.0 (the "License");
2758
+ you may not use this file except in compliance with the License.
2759
+ You may obtain a copy of the License at
2760
+
2761
+ http://www.apache.org/licenses/LICENSE-2.0
2762
+
2763
+ Unless required by applicable law or agreed to in writing, software
2764
+ distributed under the License is distributed on an "AS IS" BASIS,
2765
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2766
+ See the License for the specific language governing permissions and
2767
+ limitations under the License.
2768
+ */
2769
+
1653
2770
  /**
1654
2771
  * Canonically hashes a json object.
1655
2772
  * @param {Object} obj the json object
@@ -1658,20 +2775,12 @@ function hashJson(obj) {
1658
2775
  return sha256$1(stringify(obj));
1659
2776
  }
1660
2777
 
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
2778
  var lookup = []
1671
2779
  var revLookup = []
1672
2780
  var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
1673
-
2781
+ var inited = false;
1674
2782
  function init () {
2783
+ inited = true;
1675
2784
  var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
1676
2785
  for (var i = 0, len = code.length; i < len; ++i) {
1677
2786
  lookup[i] = code[i]
@@ -1682,9 +2791,10 @@ function init () {
1682
2791
  revLookup['_'.charCodeAt(0)] = 63
1683
2792
  }
1684
2793
 
1685
- init()
1686
-
1687
2794
  function toByteArray (b64) {
2795
+ if (!inited) {
2796
+ init();
2797
+ }
1688
2798
  var i, j, l, tmp, placeHolders, arr
1689
2799
  var len = b64.length
1690
2800
 
@@ -1730,50 +2840,142 @@ function tripletToBase64 (num) {
1730
2840
  return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
1731
2841
  }
1732
2842
 
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))
2843
+ function encodeChunk (uint8, start, end) {
2844
+ var tmp
2845
+ var output = []
2846
+ for (var i = start; i < end; i += 3) {
2847
+ tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
2848
+ output.push(tripletToBase64(tmp))
2849
+ }
2850
+ return output.join('')
2851
+ }
2852
+
2853
+ function fromByteArray (uint8) {
2854
+ if (!inited) {
2855
+ init();
2856
+ }
2857
+ var tmp
2858
+ var len = uint8.length
2859
+ var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
2860
+ var output = ''
2861
+ var parts = []
2862
+ var maxChunkLength = 16383 // must be multiple of 3
2863
+
2864
+ // go through the array every three bytes, we'll deal with trailing stuff later
2865
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
2866
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
2867
+ }
2868
+
2869
+ // pad the end with zeros, but make sure to not forget the extra bytes
2870
+ if (extraBytes === 1) {
2871
+ tmp = uint8[len - 1]
2872
+ output += lookup[tmp >> 2]
2873
+ output += lookup[(tmp << 4) & 0x3F]
2874
+ output += '=='
2875
+ } else if (extraBytes === 2) {
2876
+ tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
2877
+ output += lookup[tmp >> 10]
2878
+ output += lookup[(tmp >> 4) & 0x3F]
2879
+ output += lookup[(tmp << 2) & 0x3F]
2880
+ output += '='
2881
+ }
2882
+
2883
+ parts.push(output)
2884
+
2885
+ return parts.join('')
2886
+ }
2887
+
2888
+ function read (buffer, offset, isLE, mLen, nBytes) {
2889
+ var e, m
2890
+ var eLen = nBytes * 8 - mLen - 1
2891
+ var eMax = (1 << eLen) - 1
2892
+ var eBias = eMax >> 1
2893
+ var nBits = -7
2894
+ var i = isLE ? (nBytes - 1) : 0
2895
+ var d = isLE ? -1 : 1
2896
+ var s = buffer[offset + i]
2897
+
2898
+ i += d
2899
+
2900
+ e = s & ((1 << (-nBits)) - 1)
2901
+ s >>= (-nBits)
2902
+ nBits += eLen
2903
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
2904
+
2905
+ m = e & ((1 << (-nBits)) - 1)
2906
+ e >>= (-nBits)
2907
+ nBits += mLen
2908
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
2909
+
2910
+ if (e === 0) {
2911
+ e = 1 - eBias
2912
+ } else if (e === eMax) {
2913
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
2914
+ } else {
2915
+ m = m + Math.pow(2, mLen)
2916
+ e = e - eBias
2917
+ }
2918
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
2919
+ }
2920
+
2921
+ function write (buffer, value, offset, isLE, mLen, nBytes) {
2922
+ var e, m, c
2923
+ var eLen = nBytes * 8 - mLen - 1
2924
+ var eMax = (1 << eLen) - 1
2925
+ var eBias = eMax >> 1
2926
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
2927
+ var i = isLE ? 0 : (nBytes - 1)
2928
+ var d = isLE ? 1 : -1
2929
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
2930
+
2931
+ value = Math.abs(value)
2932
+
2933
+ if (isNaN(value) || value === Infinity) {
2934
+ m = isNaN(value) ? 1 : 0
2935
+ e = eMax
2936
+ } else {
2937
+ e = Math.floor(Math.log(value) / Math.LN2)
2938
+ if (value * (c = Math.pow(2, -e)) < 1) {
2939
+ e--
2940
+ c *= 2
2941
+ }
2942
+ if (e + eBias >= 1) {
2943
+ value += rt / c
2944
+ } else {
2945
+ value += rt * Math.pow(2, 1 - eBias)
2946
+ }
2947
+ if (value * c >= 2) {
2948
+ e++
2949
+ c /= 2
2950
+ }
2951
+
2952
+ if (e + eBias >= eMax) {
2953
+ m = 0
2954
+ e = eMax
2955
+ } else if (e + eBias >= 1) {
2956
+ m = (value * c - 1) * Math.pow(2, mLen)
2957
+ e = e + eBias
2958
+ } else {
2959
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
2960
+ e = 0
2961
+ }
1739
2962
  }
1740
- return output.join('')
1741
- }
1742
2963
 
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
2964
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
1750
2965
 
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
- }
2966
+ e = (e << mLen) | m
2967
+ eLen += mLen
2968
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
1755
2969
 
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
- }
2970
+ buffer[offset + i - d] |= s * 128
2971
+ }
1769
2972
 
1770
- parts.push(output)
2973
+ var toString = {}.toString;
1771
2974
 
1772
- return parts.join('')
1773
- }
2975
+ var isArray = Array.isArray || function (arr) {
2976
+ return toString.call(arr) == '[object Array]';
2977
+ };
1774
2978
 
1775
- },{}],2:[function(_dereq_,___mod,_expor_){
1776
- (function (global){
1777
2979
  /*!
1778
2980
  * The buffer module from node.js, for the browser.
1779
2981
  *
@@ -1782,15 +2984,8 @@ function fromByteArray (uint8) {
1782
2984
  */
1783
2985
  /* eslint-disable no-proto */
1784
2986
 
1785
- 'use strict'
1786
2987
 
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
2988
+ var INSPECT_MAX_BYTES = 50
1794
2989
 
1795
2990
  /**
1796
2991
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -1816,27 +3011,14 @@ _expor_.INSPECT_MAX_BYTES = 50
1816
3011
  * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
1817
3012
  * get the Object implementation, which is slower but behaves correctly.
1818
3013
  */
1819
- Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
1820
- ? global.TYPED_ARRAY_SUPPORT
1821
- : typedArraySupport()
3014
+ Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
3015
+ ? global$1.TYPED_ARRAY_SUPPORT
3016
+ : true
1822
3017
 
1823
3018
  /*
1824
3019
  * Export kMaxLength after typed array support is determined.
1825
3020
  */
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
-
3021
+ var _kMaxLength = kMaxLength()
1840
3022
  function kMaxLength () {
1841
3023
  return Buffer.TYPED_ARRAY_SUPPORT
1842
3024
  ? 0x7fffffff
@@ -1931,16 +3113,18 @@ if (Buffer.TYPED_ARRAY_SUPPORT) {
1931
3113
  if (typeof Symbol !== 'undefined' && Symbol.species &&
1932
3114
  Buffer[Symbol.species] === Buffer) {
1933
3115
  // 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
- })
3116
+ // Object.defineProperty(Buffer, Symbol.species, {
3117
+ // value: null,
3118
+ // configurable: true
3119
+ // })
1938
3120
  }
1939
3121
  }
1940
3122
 
1941
3123
  function assertSize (size) {
1942
3124
  if (typeof size !== 'number') {
1943
3125
  throw new TypeError('"size" argument must be a number')
3126
+ } else if (size < 0) {
3127
+ throw new RangeError('"size" argument must not be negative')
1944
3128
  }
1945
3129
  }
1946
3130
 
@@ -2004,12 +3188,20 @@ function fromString (that, string, encoding) {
2004
3188
  var length = byteLength(string, encoding) | 0
2005
3189
  that = createBuffer(that, length)
2006
3190
 
2007
- that.write(string, encoding)
3191
+ var actual = that.write(string, encoding)
3192
+
3193
+ if (actual !== length) {
3194
+ // Writing a hex string, for example, that contains invalid characters will
3195
+ // cause everything after the first invalid character to be ignored. (e.g.
3196
+ // 'abxxcd' will be treated as 'ab')
3197
+ that = that.slice(0, actual)
3198
+ }
3199
+
2008
3200
  return that
2009
3201
  }
2010
3202
 
2011
3203
  function fromArrayLike (that, array) {
2012
- var length = checked(array.length) | 0
3204
+ var length = array.length < 0 ? 0 : checked(array.length) | 0
2013
3205
  that = createBuffer(that, length)
2014
3206
  for (var i = 0; i < length; i += 1) {
2015
3207
  that[i] = array[i] & 255
@@ -2048,7 +3240,7 @@ function fromArrayBuffer (that, array, byteOffset, length) {
2048
3240
  }
2049
3241
 
2050
3242
  function fromObject (that, obj) {
2051
- if (Buffer.isBuffer(obj)) {
3243
+ if (internalIsBuffer(obj)) {
2052
3244
  var len = checked(obj.length) | 0
2053
3245
  that = createBuffer(that, len)
2054
3246
 
@@ -2078,7 +3270,7 @@ function fromObject (that, obj) {
2078
3270
  }
2079
3271
 
2080
3272
  function checked (length) {
2081
- // Note: cannot use `length < kMaxLength` here because that fails when
3273
+ // Note: cannot use `length < kMaxLength()` here because that fails when
2082
3274
  // length is NaN (which is otherwise coerced to zero.)
2083
3275
  if (length >= kMaxLength()) {
2084
3276
  throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
@@ -2087,19 +3279,13 @@ function checked (length) {
2087
3279
  return length | 0
2088
3280
  }
2089
3281
 
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) {
3282
+ Buffer.isBuffer = isBuffer;
3283
+ function internalIsBuffer (b) {
2098
3284
  return !!(b != null && b._isBuffer)
2099
3285
  }
2100
3286
 
2101
3287
  Buffer.compare = function compare (a, b) {
2102
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
3288
+ if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
2103
3289
  throw new TypeError('Arguments must be Buffers')
2104
3290
  }
2105
3291
 
@@ -2127,9 +3313,9 @@ Buffer.isEncoding = function isEncoding (encoding) {
2127
3313
  case 'utf8':
2128
3314
  case 'utf-8':
2129
3315
  case 'ascii':
3316
+ case 'latin1':
2130
3317
  case 'binary':
2131
3318
  case 'base64':
2132
- case 'raw':
2133
3319
  case 'ucs2':
2134
3320
  case 'ucs-2':
2135
3321
  case 'utf16le':
@@ -2161,7 +3347,7 @@ Buffer.concat = function concat (list, length) {
2161
3347
  var pos = 0
2162
3348
  for (i = 0; i < list.length; ++i) {
2163
3349
  var buf = list[i]
2164
- if (!Buffer.isBuffer(buf)) {
3350
+ if (!internalIsBuffer(buf)) {
2165
3351
  throw new TypeError('"list" argument must be an Array of Buffers')
2166
3352
  }
2167
3353
  buf.copy(buffer, pos)
@@ -2171,7 +3357,7 @@ Buffer.concat = function concat (list, length) {
2171
3357
  }
2172
3358
 
2173
3359
  function byteLength (string, encoding) {
2174
- if (Buffer.isBuffer(string)) {
3360
+ if (internalIsBuffer(string)) {
2175
3361
  return string.length
2176
3362
  }
2177
3363
  if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
@@ -2190,9 +3376,8 @@ function byteLength (string, encoding) {
2190
3376
  for (;;) {
2191
3377
  switch (encoding) {
2192
3378
  case 'ascii':
3379
+ case 'latin1':
2193
3380
  case 'binary':
2194
- case 'raw':
2195
- case 'raws':
2196
3381
  return len
2197
3382
  case 'utf8':
2198
3383
  case 'utf-8':
@@ -2265,8 +3450,9 @@ function slowToString (encoding, start, end) {
2265
3450
  case 'ascii':
2266
3451
  return asciiSlice(this, start, end)
2267
3452
 
3453
+ case 'latin1':
2268
3454
  case 'binary':
2269
- return binarySlice(this, start, end)
3455
+ return latin1Slice(this, start, end)
2270
3456
 
2271
3457
  case 'base64':
2272
3458
  return base64Slice(this, start, end)
@@ -2318,6 +3504,20 @@ Buffer.prototype.swap32 = function swap32 () {
2318
3504
  return this
2319
3505
  }
2320
3506
 
3507
+ Buffer.prototype.swap64 = function swap64 () {
3508
+ var len = this.length
3509
+ if (len % 8 !== 0) {
3510
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
3511
+ }
3512
+ for (var i = 0; i < len; i += 8) {
3513
+ swap(this, i, i + 7)
3514
+ swap(this, i + 1, i + 6)
3515
+ swap(this, i + 2, i + 5)
3516
+ swap(this, i + 3, i + 4)
3517
+ }
3518
+ return this
3519
+ }
3520
+
2321
3521
  Buffer.prototype.toString = function toString () {
2322
3522
  var length = this.length | 0
2323
3523
  if (length === 0) return ''
@@ -2326,14 +3526,14 @@ Buffer.prototype.toString = function toString () {
2326
3526
  }
2327
3527
 
2328
3528
  Buffer.prototype.equals = function equals (b) {
2329
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
3529
+ if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
2330
3530
  if (this === b) return true
2331
3531
  return Buffer.compare(this, b) === 0
2332
3532
  }
2333
3533
 
2334
3534
  Buffer.prototype.inspect = function inspect () {
2335
3535
  var str = ''
2336
- var max = _expor_.INSPECT_MAX_BYTES
3536
+ var max = INSPECT_MAX_BYTES
2337
3537
  if (this.length > 0) {
2338
3538
  str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
2339
3539
  if (this.length > max) str += ' ... '
@@ -2342,7 +3542,7 @@ Buffer.prototype.inspect = function inspect () {
2342
3542
  }
2343
3543
 
2344
3544
  Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
2345
- if (!Buffer.isBuffer(target)) {
3545
+ if (!internalIsBuffer(target)) {
2346
3546
  throw new TypeError('Argument must be a Buffer')
2347
3547
  }
2348
3548
 
@@ -2400,7 +3600,73 @@ Buffer.prototype.compare = function compare (target, start, end, thisStart, this
2400
3600
  return 0
2401
3601
  }
2402
3602
 
2403
- function arrayIndexOf (arr, val, byteOffset, encoding) {
3603
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
3604
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
3605
+ //
3606
+ // Arguments:
3607
+ // - buffer - a Buffer to search
3608
+ // - val - a string, Buffer, or number
3609
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
3610
+ // - encoding - an optional encoding, relevant is val is a string
3611
+ // - dir - true for indexOf, false for lastIndexOf
3612
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
3613
+ // Empty buffer means no match
3614
+ if (buffer.length === 0) return -1
3615
+
3616
+ // Normalize byteOffset
3617
+ if (typeof byteOffset === 'string') {
3618
+ encoding = byteOffset
3619
+ byteOffset = 0
3620
+ } else if (byteOffset > 0x7fffffff) {
3621
+ byteOffset = 0x7fffffff
3622
+ } else if (byteOffset < -0x80000000) {
3623
+ byteOffset = -0x80000000
3624
+ }
3625
+ byteOffset = +byteOffset // Coerce to Number.
3626
+ if (isNaN(byteOffset)) {
3627
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
3628
+ byteOffset = dir ? 0 : (buffer.length - 1)
3629
+ }
3630
+
3631
+ // Normalize byteOffset: negative offsets start from the end of the buffer
3632
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset
3633
+ if (byteOffset >= buffer.length) {
3634
+ if (dir) return -1
3635
+ else byteOffset = buffer.length - 1
3636
+ } else if (byteOffset < 0) {
3637
+ if (dir) byteOffset = 0
3638
+ else return -1
3639
+ }
3640
+
3641
+ // Normalize val
3642
+ if (typeof val === 'string') {
3643
+ val = Buffer.from(val, encoding)
3644
+ }
3645
+
3646
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
3647
+ if (internalIsBuffer(val)) {
3648
+ // Special case: looking for empty string/buffer always fails
3649
+ if (val.length === 0) {
3650
+ return -1
3651
+ }
3652
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
3653
+ } else if (typeof val === 'number') {
3654
+ val = val & 0xFF // Search for a byte value [0-255]
3655
+ if (Buffer.TYPED_ARRAY_SUPPORT &&
3656
+ typeof Uint8Array.prototype.indexOf === 'function') {
3657
+ if (dir) {
3658
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
3659
+ } else {
3660
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
3661
+ }
3662
+ }
3663
+ return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
3664
+ }
3665
+
3666
+ throw new TypeError('val must be string, number or Buffer')
3667
+ }
3668
+
3669
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
2404
3670
  var indexSize = 1
2405
3671
  var arrLength = arr.length
2406
3672
  var valLength = val.length
@@ -2427,60 +3693,45 @@ function arrayIndexOf (arr, val, byteOffset, encoding) {
2427
3693
  }
2428
3694
  }
2429
3695
 
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
3696
+ var i
3697
+ if (dir) {
3698
+ var foundIndex = -1
3699
+ for (i = byteOffset; i < arrLength; i++) {
3700
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
3701
+ if (foundIndex === -1) foundIndex = i
3702
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
3703
+ } else {
3704
+ if (foundIndex !== -1) i -= i - foundIndex
3705
+ foundIndex = -1
3706
+ }
3707
+ }
3708
+ } else {
3709
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
3710
+ for (i = byteOffset; i >= 0; i--) {
3711
+ var found = true
3712
+ for (var j = 0; j < valLength; j++) {
3713
+ if (read(arr, i + j) !== read(val, j)) {
3714
+ found = false
3715
+ break
3716
+ }
3717
+ }
3718
+ if (found) return i
2438
3719
  }
2439
3720
  }
2440
3721
 
2441
3722
  return -1
2442
3723
  }
2443
3724
 
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
- }
3725
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
3726
+ return this.indexOf(val, byteOffset, encoding) !== -1
3727
+ }
2478
3728
 
2479
- throw new TypeError('val must be string, number or Buffer')
3729
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
3730
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
2480
3731
  }
2481
3732
 
2482
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
2483
- return this.indexOf(val, byteOffset, encoding) !== -1
3733
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
3734
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
2484
3735
  }
2485
3736
 
2486
3737
  function hexWrite (buf, string, offset, length) {
@@ -2497,7 +3748,7 @@ function hexWrite (buf, string, offset, length) {
2497
3748
 
2498
3749
  // must be an even number of digits
2499
3750
  var strLen = string.length
2500
- if (strLen % 2 !== 0) throw new Error('Invalid hex string')
3751
+ if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
2501
3752
 
2502
3753
  if (length > strLen / 2) {
2503
3754
  length = strLen / 2
@@ -2518,7 +3769,7 @@ function asciiWrite (buf, string, offset, length) {
2518
3769
  return blitBuffer(asciiToBytes(string), buf, offset, length)
2519
3770
  }
2520
3771
 
2521
- function binaryWrite (buf, string, offset, length) {
3772
+ function latin1Write (buf, string, offset, length) {
2522
3773
  return asciiWrite(buf, string, offset, length)
2523
3774
  }
2524
3775
 
@@ -2580,8 +3831,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) {
2580
3831
  case 'ascii':
2581
3832
  return asciiWrite(this, string, offset, length)
2582
3833
 
3834
+ case 'latin1':
2583
3835
  case 'binary':
2584
- return binaryWrite(this, string, offset, length)
3836
+ return latin1Write(this, string, offset, length)
2585
3837
 
2586
3838
  case 'base64':
2587
3839
  // Warning: maxLength not taken into account in base64Write
@@ -2610,9 +3862,9 @@ Buffer.prototype.toJSON = function toJSON () {
2610
3862
 
2611
3863
  function base64Slice (buf, start, end) {
2612
3864
  if (start === 0 && end === buf.length) {
2613
- return base64.fromByteArray(buf)
3865
+ return fromByteArray(buf)
2614
3866
  } else {
2615
- return base64.fromByteArray(buf.slice(start, end))
3867
+ return fromByteArray(buf.slice(start, end))
2616
3868
  }
2617
3869
  }
2618
3870
 
@@ -2722,7 +3974,7 @@ function asciiSlice (buf, start, end) {
2722
3974
  return ret
2723
3975
  }
2724
3976
 
2725
- function binarySlice (buf, start, end) {
3977
+ function latin1Slice (buf, start, end) {
2726
3978
  var ret = ''
2727
3979
  end = Math.min(buf.length, end)
2728
3980
 
@@ -2936,26 +4188,26 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
2936
4188
 
2937
4189
  Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
2938
4190
  if (!noAssert) checkOffset(offset, 4, this.length)
2939
- return ieee754.read(this, offset, true, 23, 4)
4191
+ return read(this, offset, true, 23, 4)
2940
4192
  }
2941
4193
 
2942
4194
  Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
2943
4195
  if (!noAssert) checkOffset(offset, 4, this.length)
2944
- return ieee754.read(this, offset, false, 23, 4)
4196
+ return read(this, offset, false, 23, 4)
2945
4197
  }
2946
4198
 
2947
4199
  Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
2948
4200
  if (!noAssert) checkOffset(offset, 8, this.length)
2949
- return ieee754.read(this, offset, true, 52, 8)
4201
+ return read(this, offset, true, 52, 8)
2950
4202
  }
2951
4203
 
2952
4204
  Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
2953
4205
  if (!noAssert) checkOffset(offset, 8, this.length)
2954
- return ieee754.read(this, offset, false, 52, 8)
4206
+ return read(this, offset, false, 52, 8)
2955
4207
  }
2956
4208
 
2957
4209
  function checkInt (buf, value, offset, ext, max, min) {
2958
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
4210
+ if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
2959
4211
  if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
2960
4212
  if (offset + ext > buf.length) throw new RangeError('Index out of range')
2961
4213
  }
@@ -3200,7 +4452,7 @@ function writeFloat (buf, value, offset, littleEndian, noAssert) {
3200
4452
  if (!noAssert) {
3201
4453
  checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
3202
4454
  }
3203
- ieee754.write(buf, value, offset, littleEndian, 23, 4)
4455
+ write(buf, value, offset, littleEndian, 23, 4)
3204
4456
  return offset + 4
3205
4457
  }
3206
4458
 
@@ -3216,7 +4468,7 @@ function writeDouble (buf, value, offset, littleEndian, noAssert) {
3216
4468
  if (!noAssert) {
3217
4469
  checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
3218
4470
  }
3219
- ieee754.write(buf, value, offset, littleEndian, 52, 8)
4471
+ write(buf, value, offset, littleEndian, 52, 8)
3220
4472
  return offset + 8
3221
4473
  }
3222
4474
 
@@ -3328,7 +4580,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
3328
4580
  this[i] = val
3329
4581
  }
3330
4582
  } else {
3331
- var bytes = Buffer.isBuffer(val)
4583
+ var bytes = internalIsBuffer(val)
3332
4584
  ? val
3333
4585
  : utf8ToBytes(new Buffer(val, encoding).toString())
3334
4586
  var len = bytes.length
@@ -3472,8 +4724,9 @@ function utf16leToBytes (str, units) {
3472
4724
  return byteArray
3473
4725
  }
3474
4726
 
4727
+
3475
4728
  function base64ToBytes (str) {
3476
- return base64.toByteArray(base64clean(str))
4729
+ return toByteArray(base64clean(str))
3477
4730
  }
3478
4731
 
3479
4732
  function blitBuffer (src, dst, offset, length) {
@@ -3488,115 +4741,62 @@ function isnan (val) {
3488
4741
  return val !== val // eslint-disable-line no-self-compare
3489
4742
  }
3490
4743
 
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
4744
 
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)
4745
+ // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
4746
+ // The _isBuffer check is for Safari 5-7 support, because it's missing
4747
+ // Object.prototype.constructor. Remove this eventually
4748
+ function isBuffer(obj) {
4749
+ return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
3524
4750
  }
3525
4751
 
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) {}
4752
+ function isFastBuffer (obj) {
4753
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
4754
+ }
3574
4755
 
3575
- buffer[offset + i - d] |= s * 128
4756
+ // For Node v0.10 support. Remove this eventually.
4757
+ function isSlowBuffer (obj) {
4758
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
3576
4759
  }
3577
4760
 
3578
- },{}],4:[function(_dereq_,___mod,_expor_){
3579
- var toString = {}.toString;
4761
+ /*
4762
+ Copyright 2017 Stratumn SAS. All rights reserved.
3580
4763
 
3581
- ___mod.exports = Array.isArray || function (arr) {
3582
- return toString.call(arr) == '[object Array]';
3583
- };
4764
+ Licensed under the Apache License, Version 2.0 (the "License");
4765
+ you may not use this file except in compliance with the License.
4766
+ You may obtain a copy of the License at
3584
4767
 
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;
4768
+ http://www.apache.org/licenses/LICENSE-2.0
3590
4769
 
3591
- },{"buffer":2}]},{},[5]);
4770
+ Unless required by applicable law or agreed to in writing, software
4771
+ distributed under the License is distributed on an "AS IS" BASIS,
4772
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4773
+ See the License for the specific language governing permissions and
4774
+ limitations under the License.
4775
+ */
3592
4776
 
3593
4777
  function computeMerkleParent(left, right) {
3594
4778
  if (right) {
3595
- return sha256$1(_buffer.concat([new _buffer(left, 'hex'), new _buffer(right, 'hex')]));
4779
+ return sha256$1(Buffer.concat([new Buffer(left, 'hex'), new Buffer(right, 'hex')]));
3596
4780
  }
3597
4781
  return left;
3598
4782
  }
3599
4783
 
4784
+ /*
4785
+ Copyright 2017 Stratumn SAS. All rights reserved.
4786
+
4787
+ Licensed under the Apache License, Version 2.0 (the "License");
4788
+ you may not use this file except in compliance with the License.
4789
+ You may obtain a copy of the License at
4790
+
4791
+ http://www.apache.org/licenses/LICENSE-2.0
4792
+
4793
+ Unless required by applicable law or agreed to in writing, software
4794
+ distributed under the License is distributed on an "AS IS" BASIS,
4795
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4796
+ See the License for the specific language governing permissions and
4797
+ limitations under the License.
4798
+ */
4799
+
3600
4800
  var blockCypherCache = {};
3601
4801
 
3602
4802
  var SegmentValidator = function () {
@@ -3639,45 +4839,35 @@ var SegmentValidator = function () {
3639
4839
  }, {
3640
4840
  key: '_validateMerklePath',
3641
4841
  value: function _validateMerklePath() {
3642
- var _this = this;
3643
-
3644
4842
  var evidence = this.segment.meta.evidence;
3645
4843
  if (evidence) {
3646
4844
  if (evidence.state === 'COMPLETE') {
3647
- var _ret = function () {
3648
- var previous = _this.segment.meta.linkHash;
4845
+ var previous = this.segment.meta.linkHash;
3649
4846
 
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);
4847
+ var error = void 0;
4848
+ evidence.merklePath.every(function (merkleNode) {
4849
+ if (merkleNode.left === previous || merkleNode.right === previous) {
4850
+ var computedParent = computeMerkleParent(merkleNode.left, merkleNode.right);
3654
4851
 
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;
4852
+ if (computedParent !== merkleNode.parent) {
4853
+ error = 'Invalid Merkle Node ' + JSON.stringify(merkleNode) + ': ' + ('computed parent: ' + computedParent);
4854
+ return false;
3661
4855
  }
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
- };
4856
+ previous = merkleNode.parent;
4857
+ return true;
3670
4858
  }
4859
+ error = 'Invalid Merkle Node ' + JSON.stringify(merkleNode) + ': ' + ('previous hash (' + previous + ') not found');
4860
+ return false;
4861
+ });
3671
4862
 
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
- }();
4863
+ if (error) {
4864
+ return error;
4865
+ }
3679
4866
 
3680
- if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
4867
+ var lastMerkleNode = evidence.merklePath[evidence.merklePath.length - 1];
4868
+ if (lastMerkleNode.parent !== evidence.merkleRoot) {
4869
+ return 'Invalid Merkle Root ' + evidence.merkleRoot + ': not found in Merkle Path';
4870
+ }
3681
4871
  }
3682
4872
  }
3683
4873
  return null;
@@ -3685,13 +4875,13 @@ var SegmentValidator = function () {
3685
4875
  }, {
3686
4876
  key: '_validateFossil',
3687
4877
  value: function _validateFossil() {
3688
- var _this2 = this;
4878
+ var _this = this;
3689
4879
 
3690
4880
  var txId = this.segment.meta.evidence.transactions['bitcoin:main'];
3691
4881
  return this._getFossil(txId).then(function (res) {
3692
4882
  var body = JSON.parse(res.xhr.response);
3693
4883
  if (!body.outputs.find(function (output) {
3694
- return output.data_hex === _this2.segment.meta.evidence.merkleRoot;
4884
+ return output.data_hex === _this.segment.meta.evidence.merkleRoot;
3695
4885
  })) {
3696
4886
  return 'Merkle root not found in transaction data';
3697
4887
  }
@@ -3717,6 +4907,22 @@ var SegmentValidator = function () {
3717
4907
  return SegmentValidator;
3718
4908
  }();
3719
4909
 
4910
+ /*
4911
+ Copyright 2017 Stratumn SAS. All rights reserved.
4912
+
4913
+ Licensed under the Apache License, Version 2.0 (the "License");
4914
+ you may not use this file except in compliance with the License.
4915
+ You may obtain a copy of the License at
4916
+
4917
+ http://www.apache.org/licenses/LICENSE-2.0
4918
+
4919
+ Unless required by applicable law or agreed to in writing, software
4920
+ distributed under the License is distributed on an "AS IS" BASIS,
4921
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4922
+ See the License for the specific language governing permissions and
4923
+ limitations under the License.
4924
+ */
4925
+
3720
4926
  var ChainValidator = function () {
3721
4927
  function ChainValidator(chainscript) {
3722
4928
  classCallCheck(this, ChainValidator);
@@ -3750,6 +4956,22 @@ var ChainValidator = function () {
3750
4956
  return ChainValidator;
3751
4957
  }();
3752
4958
 
4959
+ /*
4960
+ Copyright 2017 Stratumn SAS. All rights reserved.
4961
+
4962
+ Licensed under the Apache License, Version 2.0 (the "License");
4963
+ you may not use this file except in compliance with the License.
4964
+ You may obtain a copy of the License at
4965
+
4966
+ http://www.apache.org/licenses/LICENSE-2.0
4967
+
4968
+ Unless required by applicable law or agreed to in writing, software
4969
+ distributed under the License is distributed on an "AS IS" BASIS,
4970
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4971
+ See the License for the specific language governing permissions and
4972
+ limitations under the License.
4973
+ */
4974
+
3753
4975
  var margin$1 = { top: 10, right: 5, bottom: 20, left: 5 };
3754
4976
  var height$1 = 350 - margin$1.top - margin$1.bottom;
3755
4977
  var width = 400 - margin$1.left - margin$1.right;