PageSourceSearch

https://thoppe.github.io/Landmark/bower_components/truffle-contract/dist/truffle-contract.js

js thoppe.github.io collected 2026-10-03 10:04:50 UTC 257,042 bytes, 9,165 lines download raw bytes

1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2// TODO: remove web3 requirement
3// Call functions directly on the provider.
4var Web3 = require("web3");
5
6var Blockchain = {
7  parse: function(uri) {
8    var parsed = {};
9    if (uri.indexOf("blockchain://") != 0) return parsed;
10
11    uri = uri.replace("blockchain://", "");
12
13    var pieces = uri.split("/block/");
14
15    parsed.genesis_hash = "0x" + pieces[0];
16    parsed.block_hash = "0x" + pieces[1];
17
18    return parsed;
19  },
20
21  asURI: function(provider, callback) {
22    var web3 = new Web3(provider);
23
24    web3.eth.getBlock(0, function(err, genesis) {
25      if (err) return callback(err);
26
27      web3.eth.getBlock("latest", function(err, latest) {
28        if (err) return callback(err);
29
30        var url = "blockchain://" + genesis.hash.replace("0x", "") + "/block/" + latest.hash.replace("0x", "");
31
32        callback(null, url);
33      });
34    });
35  },
36
37  matches: function(uri, provider, callback) {
38    uri = this.parse(uri);
39
40    var expected_genesis = uri.genesis_hash;
41    var expected_block = uri.block_hash;
42
43    var web3 = new Web3(provider);
44
45    web3.eth.getBlock(0, function(err, block) {
46      if (err) return callback(err);
47      if (block.hash != expected_genesis) return callback(null, false);
48
49      web3.eth.getBlock(expected_block, function(err, block) {
50        // Treat an error as if the block didn't exist. This is because
51        // some clients respond differently.
52        if (err || block == null) {
53          return callback(null, false);
54        }
55
56        callback(null, true);
57      });
58    });
59  }
60};
61
62module.exports = Blockchain;
63
64},{"web3":11}],2:[function(require,module,exports){
65var sha3 = require("crypto-js/sha3");
66var schema_version = require("./package.json").version;
67
68var TruffleSchema = {
69  // Normalize options passed in to be the exact options required
70  // for truffle-contract.
71  //
72  // options can be three things:
73  // - normal object
74  // - contract object
75  // - solc output
76  //
77  // TODO: Is extra_options still necessary?
78  normalizeOptions: function(options, extra_options) {
79    extra_options = extra_options || {};
80    var normalized = {};
81    var expected_keys = [
82      "contract_name",
83      "abi",
84      "binary",
85      "unlinked_binary",
86      "address",
87      "networks",
88      "links",
89      "events",
90      "network_id",
91      "default_network",
92      "updated_at"
93    ];
94
95    // Merge options/contract object first, then extra_options
96    expected_keys.forEach(function(key) {
97      var value;
98
99      try {
100        // Will throw an error if key == address and address doesn't exist.
101        value = options[key];
102
103        if (value != undefined) {
104          normalized[key] = value;
105        }
106      } catch (e) {
107        // Do nothing.
108      }
109
110      try {
111        // Will throw an error if key == address and address doesn't exist.
112        value = extra_options[key];
113
114        if (value != undefined) {
115          normalized[key] = value;
116        }
117      } catch (e) {
118        // Do nothing.
119      }
120    });
121
122    // Now look for solc specific items.
123    if (options.interface != null) {
124      normalized.abi = JSON.parse(options.interface);
125    }
126
127    if (options.bytecode != null) {
128      normalized.unlinked_binary = options.bytecode
129    }
130
131    // Assume any binary passed is the unlinked binary
132    if (normalized.unlinked_binary == null && normalized.binary) {
133      normalized.unlinked_binary = normalized.binary;
134    }
135
136    delete normalized.binary;
137
138    this.copyCustomOptions(options, normalized);
139
140    return normalized;
141  },
142
143  // Generate a proper binary from normalized options, and optionally
144  // merge it with an existing binary.
145  generateBinary: function(options, existing_binary, extra_options) {
146    extra_options = extra_options || {};
147
148    existing_binary = existing_binary || {};
149
150    if (options.overwrite == true) {
151      existing_binary = {};
152    }
153
154    existing_binary.contract_name = options.contract_name || existing_binary.contract_name || "Contract";
155    existing_binary.default_network = options.default_network || existing_binary.default_network;
156
157    existing_binary.abi = options.abi || existing_binary.abi;
158    existing_binary.unlinked_binary = options.unlinked_binary || existing_binary.unlinked_binary;
159
160    // Ensure unlinked binary starts with a 0x
161    if (existing_binary.unlinked_binary && existing_binary.unlinked_binary.indexOf("0x") < 0) {
162      existing_binary.unlinked_binary = "0x" + existing_binary.unlinked_binary;
163    }
164
165    // Merge existing networks with any passed in networks.
166    existing_binary.networks = existing_binary.networks || {};
167    options.networks = options.networks || {};
168    Object.keys(options.networks).forEach(function(network_id) {
169      existing_binary.networks[network_id] = options.networks[network_id];
170    });
171
172    var updated_at = new Date().getTime();
173
174    if (options.network_id) {
175      // Ensure an object exists for this network.
176      existing_binary.networks[options.network_id] = existing_binary.networks[options.network_id] || {};
177
178      var network = existing_binary.networks[options.network_id];
179
180      // Override specific keys
181      network.address = options.address || network.address;
182      network.links = options.links;
183
184      // merge events with any that previously existed
185      network.events = network.events || {};
186      options.events = options.events || {};
187      Object.keys(options.events).forEach(function(event_id) {
188        options.events[event_id] = options.events[event_id];
189      });
190
191      // Now overwrite any events with the most recent data from the ABI.
192      existing_binary.abi.forEach(function(item) {
193        if (item.type != "event") return;
194
195        var signature = item.name + "(" + item.inputs.map(function(param) {return param.type;}).join(",") + ")";
196        network.events["0x" + sha3(signature, {outputLength: 256})] = item;
197      });
198
199      if (extra_options.dirty !== false) {
200        network.updated_at = updated_at;
201      }
202    } else {
203      if (options.address) {
204        throw new Error("Cannot set address without network id");
205      }
206    }
207
208    // Ensure all networks have a `links` object.
209    Object.keys(existing_binary.networks).forEach(function(network_id) {
210      var network = existing_binary.networks[network_id];
211      network.links = network.links || {};
212    });
213
214    existing_binary.schema_version = schema_version;
215
216    if (extra_options.dirty !== false) {
217      existing_binary.updated_at = updated_at;
218    } else {
219      existing_binary.updated_at = options.updated_at || existing_binary.updated_at || updated_at;
220    }
221
222    this.copyCustomOptions(options, existing_binary);
223
224    return existing_binary;
225  },
226
227  copyCustomOptions: function(from, to) {
228    // Now let all x- options through.
229    Object.keys(from).forEach(function(key) {
230      if (key.indexOf("x-") != 0) return;
231
232      try {
233        value = from[key];
234
235        if (value != undefined) {
236          to[key] = value;
237        }
238      } catch (e) {
239        // Do nothing.
240      }
241    });
242  }
243};
244
245module.exports = TruffleSchema;
246
247},{"./package.json":6,"crypto-js/sha3":4}],3:[function(require,module,exports){
248;(function (root, factory) {
249	if (typeof exports === "object") {
250		// CommonJS
251		module.exports = exports = factory();
252	}
253	else if (typeof define === "function" && define.amd) {
254		// AMD
255		define([], factory);
256	}
257	else {
258		// Global (browser)
259		root.CryptoJS = factory();
260	}
261}(this, function () {
262
263	/**
264	 * CryptoJS core components.
265	 */
266	var CryptoJS = CryptoJS || (function (Math, undefined) {
267	    /*
268	     * Local polyfil of Object.create
269	     */
270	    var create = Object.create || (function () {
271	        function F() {};
272
273	        return function (obj) {
274	            var subtype;
275
276	            F.prototype = obj;
277
278	            subtype = new F();
279
280	            F.prototype = null;
281
282	            return subtype;
283	        };
284	    }())
285
286	    /**
287	     * CryptoJS namespace.
288	     */
289	    var C = {};
290
291	    /**
292	     * Library namespace.
293	     */
294	    var C_lib = C.lib = {};
295
296	    /**
297	     * Base object for prototypal inheritance.
298	     */
299	    var Base = C_lib.Base = (function () {
300
301
302	        return {
303	            /**
304	             * Creates a new object that inherits from this object.
305	             *
306	             * @param {Object} overrides Properties to copy into the new object.
307	             *
308	             * @return {Object} The new object.
309	             *
310	             * @static
311	             *
312	             * @example
313	             *
314	             *     var MyType = CryptoJS.lib.Base.extend({
315	             *         field: 'value',
316	             *
317	             *         method: function () {
318	             *         }
319	             *     });
320	             */
321	            extend: function (overrides) {
322	                // Spawn
323	                var subtype = create(this);
324
325	                // Augment
326	                if (overrides) {
327	                    subtype.mixIn(overrides);
328	                }
329
330	                // Create default initializer
331	                if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
332	                    subtype.init = function () {
vendor: 4,336 bytes, lines 333-466
333	                        subtype.$super.init.apply(this, arguments);
334	                    };
335	                }
336
337	                // Initializer's prototype is the subtype object
338	                subtype.init.prototype = subtype;
339
340	                // Reference supertype
341	                subtype.$super = this;
342
343	                return subtype;
344	            },
345
346	            /**
347	             * Extends this object and runs the init method.
348	             * Arguments to create() will be passed to init().
349	             *
350	             * @return {Object} The new object.
351	             *
352	             * @static
353	             *
354	             * @example
355	             *
356	             *     var instance = MyType.create();
357	             */
358	            create: function () {
359	                var instance = this.extend();
360	                instance.init.apply(instance, arguments);
361
362	                return instance;
363	            },
364
365	            /**
366	             * Initializes a newly created object.
367	             * Override this method to add some logic when your objects are created.
368	             *
369	             * @example
370	             *
371	             *     var MyType = CryptoJS.lib.Base.extend({
372	             *         init: function () {
373	             *             // ...
374	             *         }
375	             *     });
376	             */
377	            init: function () {
378	            },
379
380	            /**
381	             * Copies properties into this object.
382	             *
383	             * @param {Object} properties The properties to mix in.
384	             *
385	             * @example
386	             *
387	             *     MyType.mixIn({
388	             *         field: 'value'
389	             *     });
390	             */
391	            mixIn: function (properties) {
392	                for (var propertyName in properties) {
393	                    if (properties.hasOwnProperty(propertyName)) {
394	                        this[propertyName] = properties[propertyName];
395	                    }
396	                }
397
398	                // IE won't copy toString using the loop above
399	                if (properties.hasOwnProperty('toString')) {
400	                    this.toString = properties.toString;
401	                }
402	            },
403
404	            /**
405	             * Creates a copy of this object.
406	             *
407	             * @return {Object} The clone.
408	             *
409	             * @example
410	             *
411	             *     var clone = instance.clone();
412	             */
413	            clone: function () {
414	                return this.init.prototype.extend(this);
415	            }
416	        };
417	    }());
418
419	    /**
420	     * An array of 32-bit words.
421	     *
422	     * @property {Array} words The array of 32-bit words.
423	     * @property {number} sigBytes The number of significant bytes in this word array.
424	     */
425	    var WordArray = C_lib.WordArray = Base.extend({
426	        /**
427	         * Initializes a newly created word array.
428	         *
429	         * @param {Array} words (Optional) An array of 32-bit words.
430	         * @param {number} sigBytes (Optional) The number of significant bytes in the words.
431	         *
432	         * @example
433	         *
434	         *     var wordArray = CryptoJS.lib.WordArray.create();
435	         *     var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
436	         *     var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
437	         */
438	        init: function (words, sigBytes) {
439	            words = this.words = words || [];
440
441	            if (sigBytes != undefined) {
442	                this.sigBytes = sigBytes;
443	            } else {
444	                this.sigBytes = words.length * 4;
445	            }
446	        },
447
448	        /**
449	         * Converts this word array to a string.
450	         *
451	         * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
452	         *
453	         * @return {string} The stringified word array.
454	         *
455	         * @example
456	         *
457	         *     var string = wordArray + '';
458	         *     var string = wordArray.toString();
459	         *     var string = wordArray.toString(CryptoJS.enc.Utf8);
460	         */
461	        toString: function (encoder) {
462	            return (encoder || Hex).stringify(this);
463	        },
464
465	        /**
466	         * Concatenates a word array to this word array.
vendor: 4,335 bytes, lines 467-610
467	         *
468	         * @param {WordArray} wordArray The word array to append.
469	         *
470	         * @return {WordArray} This word array.
471	         *
472	         * @example
473	         *
474	         *     wordArray1.concat(wordArray2);
475	         */
476	        concat: function (wordArray) {
477	            // Shortcuts
478	            var thisWords = this.words;
479	            var thatWords = wordArray.words;
480	            var thisSigBytes = this.sigBytes;
481	            var thatSigBytes = wordArray.sigBytes;
482
483	            // Clamp excess bits
484	            this.clamp();
485
486	            // Concat
487	            if (thisSigBytes % 4) {
488	                // Copy one byte at a time
489	                for (var i = 0; i < thatSigBytes; i++) {
490	                    var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
491	                    thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
492	                }
493	            } else {
494	                // Copy one word at a time
495	                for (var i = 0; i < thatSigBytes; i += 4) {
496	                    thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
497	                }
498	            }
499	            this.sigBytes += thatSigBytes;
500
501	            // Chainable
502	            return this;
503	        },
504
505	        /**
506	         * Removes insignificant bits.
507	         *
508	         * @example
509	         *
510	         *     wordArray.clamp();
511	         */
512	        clamp: function () {
513	            // Shortcuts
514	            var words = this.words;
515	            var sigBytes = this.sigBytes;
516
517	            // Clamp
518	            words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
519	            words.length = Math.ceil(sigBytes / 4);
520	        },
521
522	        /**
523	         * Creates a copy of this word array.
524	         *
525	         * @return {WordArray} The clone.
526	         *
527	         * @example
528	         *
529	         *     var clone = wordArray.clone();
530	         */
531	        clone: function () {
532	            var clone = Base.clone.call(this);
533	            clone.words = this.words.slice(0);
534
535	            return clone;
536	        },
537
538	        /**
539	         * Creates a word array filled with random bytes.
540	         *
541	         * @param {number} nBytes The number of random bytes to generate.
542	         *
543	         * @return {WordArray} The random word array.
544	         *
545	         * @static
546	         *
547	         * @example
548	         *
549	         *     var wordArray = CryptoJS.lib.WordArray.random(16);
550	         */
551	        random: function (nBytes) {
552	            var words = [];
553
554	            var r = (function (m_w) {
555	                var m_w = m_w;
556	                var m_z = 0x3ade68b1;
557	                var mask = 0xffffffff;
558
559	                return function () {
560	                    m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
561	                    m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
562	                    var result = ((m_z << 0x10) + m_w) & mask;
563	                    result /= 0x100000000;
564	                    result += 0.5;
565	                    return result * (Math.random() > .5 ? 1 : -1);
566	                }
567	            });
568
569	            for (var i = 0, rcache; i < nBytes; i += 4) {
570	                var _r = r((rcache || Math.random()) * 0x100000000);
571
572	                rcache = _r() * 0x3ade67b7;
573	                words.push((_r() * 0x100000000) | 0);
574	            }
575
576	            return new WordArray.init(words, nBytes);
577	        }
578	    });
579
580	    /**
581	     * Encoder namespace.
582	     */
583	    var C_enc = C.enc = {};
584
585	    /**
586	     * Hex encoding strategy.
587	     */
588	    var Hex = C_enc.Hex = {
589	        /**
590	         * Converts a word array to a hex string.
591	         *
592	         * @param {WordArray} wordArray The word array.
593	         *
594	         * @return {string} The hex string.
595	         *
596	         * @static
597	         *
598	         * @example
599	         *
600	         *     var hexString = CryptoJS.enc.Hex.stringify(wordArray);
601	         */
602	        stringify: function (wordArray) {
603	            // Shortcuts
604	            var words = wordArray.words;
605	            var sigBytes = wordArray.sigBytes;
606
607	            // Convert
608	            var hexChars = [];
609	            for (var i = 0; i < sigBytes; i++) {
610	                var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
vendor: 3,613 bytes, lines 611-739
611	                hexChars.push((bite >>> 4).toString(16));
612	                hexChars.push((bite & 0x0f).toString(16));
613	            }
614
615	            return hexChars.join('');
616	        },
617
618	        /**
619	         * Converts a hex string to a word array.
620	         *
621	         * @param {string} hexStr The hex string.
622	         *
623	         * @return {WordArray} The word array.
624	         *
625	         * @static
626	         *
627	         * @example
628	         *
629	         *     var wordArray = CryptoJS.enc.Hex.parse(hexString);
630	         */
631	        parse: function (hexStr) {
632	            // Shortcut
633	            var hexStrLength = hexStr.length;
634
635	            // Convert
636	            var words = [];
637	            for (var i = 0; i < hexStrLength; i += 2) {
638	                words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
639	            }
640
641	            return new WordArray.init(words, hexStrLength / 2);
642	        }
643	    };
644
645	    /**
646	     * Latin1 encoding strategy.
647	     */
648	    var Latin1 = C_enc.Latin1 = {
649	        /**
650	         * Converts a word array to a Latin1 string.
651	         *
652	         * @param {WordArray} wordArray The word array.
653	         *
654	         * @return {string} The Latin1 string.
655	         *
656	         * @static
657	         *
658	         * @example
659	         *
660	         *     var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
661	         */
662	        stringify: function (wordArray) {
663	            // Shortcuts
664	            var words = wordArray.words;
665	            var sigBytes = wordArray.sigBytes;
666
667	            // Convert
668	            var latin1Chars = [];
669	            for (var i = 0; i < sigBytes; i++) {
670	                var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
671	                latin1Chars.push(String.fromCharCode(bite));
672	            }
673
674	            return latin1Chars.join('');
675	        },
676
677	        /**
678	         * Converts a Latin1 string to a word array.
679	         *
680	         * @param {string} latin1Str The Latin1 string.
681	         *
682	         * @return {WordArray} The word array.
683	         *
684	         * @static
685	         *
686	         * @example
687	         *
688	         *     var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
689	         */
690	        parse: function (latin1Str) {
691	            // Shortcut
692	            var latin1StrLength = latin1Str.length;
693
694	            // Convert
695	            var words = [];
696	            for (var i = 0; i < latin1StrLength; i++) {
697	                words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
698	            }
699
700	            return new WordArray.init(words, latin1StrLength);
701	        }
702	    };
703
704	    /**
705	     * UTF-8 encoding strategy.
706	     */
707	    var Utf8 = C_enc.Utf8 = {
708	        /**
709	         * Converts a word array to a UTF-8 string.
710	         *
711	         * @param {WordArray} wordArray The word array.
712	         *
713	         * @return {string} The UTF-8 string.
714	         *
715	         * @static
716	         *
717	         * @example
718	         *
719	         *     var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
720	         */
721	        stringify: function (wordArray) {
722	            try {
723	                return decodeURIComponent(escape(Latin1.stringify(wordArray)));
724	            } catch (e) {
725	                throw new Error('Malformed UTF-8 data');
726	            }
727	        },
728
729	        /**
730	         * Converts a UTF-8 string to a word array.
731	         *
732	         * @param {string} utf8Str The UTF-8 string.
733	         *
734	         * @return {WordArray} The word array.
735	         *
736	         * @static
737	         *
738	         * @example
739	         *
vendor: 9,494 bytes, lines 740-1058
740	         *     var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
741	         */
742	        parse: function (utf8Str) {
743	            return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
744	        }
745	    };
746
747	    /**
748	     * Abstract buffered block algorithm template.
749	     *
750	     * The property blockSize must be implemented in a concrete subtype.
751	     *
752	     * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
753	     */
754	    var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
755	        /**
756	         * Resets this block algorithm's data buffer to its initial state.
757	         *
758	         * @example
759	         *
760	         *     bufferedBlockAlgorithm.reset();
761	         */
762	        reset: function () {
763	            // Initial values
764	            this._data = new WordArray.init();
765	            this._nDataBytes = 0;
766	        },
767
768	        /**
769	         * Adds new data to this block algorithm's buffer.
770	         *
771	         * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
772	         *
773	         * @example
774	         *
775	         *     bufferedBlockAlgorithm._append('data');
776	         *     bufferedBlockAlgorithm._append(wordArray);
777	         */
778	        _append: function (data) {
779	            // Convert string to WordArray, else assume WordArray already
780	            if (typeof data == 'string') {
781	                data = Utf8.parse(data);
782	            }
783
784	            // Append
785	            this._data.concat(data);
786	            this._nDataBytes += data.sigBytes;
787	        },
788
789	        /**
790	         * Processes available data blocks.
791	         *
792	         * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
793	         *
794	         * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
795	         *
796	         * @return {WordArray} The processed data.
797	         *
798	         * @example
799	         *
800	         *     var processedData = bufferedBlockAlgorithm._process();
801	         *     var processedData = bufferedBlockAlgorithm._process(!!'flush');
802	         */
803	        _process: function (doFlush) {
804	            // Shortcuts
805	            var data = this._data;
806	            var dataWords = data.words;
807	            var dataSigBytes = data.sigBytes;
808	            var blockSize = this.blockSize;
809	            var blockSizeBytes = blockSize * 4;
810
811	            // Count blocks ready
812	            var nBlocksReady = dataSigBytes / blockSizeBytes;
813	            if (doFlush) {
814	                // Round up to include partial blocks
815	                nBlocksReady = Math.ceil(nBlocksReady);
816	            } else {
817	                // Round down to include only full blocks,
818	                // less the number of blocks that must remain in the buffer
819	                nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
820	            }
821
822	            // Count words ready
823	            var nWordsReady = nBlocksReady * blockSize;
824
825	            // Count bytes ready
826	            var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
827
828	            // Process blocks
829	            if (nWordsReady) {
830	                for (var offset = 0; offset < nWordsReady; offset += blockSize) {
831	                    // Perform concrete-algorithm logic
832	                    this._doProcessBlock(dataWords, offset);
833	                }
834
835	                // Remove processed words
836	                var processedWords = dataWords.splice(0, nWordsReady);
837	                data.sigBytes -= nBytesReady;
838	            }
839
840	            // Return processed words
841	            return new WordArray.init(processedWords, nBytesReady);
842	        },
843
844	        /**
845	         * Creates a copy of this object.
846	         *
847	         * @return {Object} The clone.
848	         *
849	         * @example
850	         *
851	         *     var clone = bufferedBlockAlgorithm.clone();
852	         */
853	        clone: function () {
854	            var clone = Base.clone.call(this);
855	            clone._data = this._data.clone();
856
857	            return clone;
858	        },
859
860	        _minBufferSize: 0
861	    });
862
863	    /**
864	     * Abstract hasher template.
865	     *
866	     * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
867	     */
868	    var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
869	        /**
870	         * Configuration options.
871	         */
872	        cfg: Base.extend(),
873
874	        /**
875	         * Initializes a newly created hasher.
876	         *
877	         * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
878	         *
879	         * @example
880	         *
881	         *     var hasher = CryptoJS.algo.SHA256.create();
882	         */
883	        init: function (cfg) {
884	            // Apply config defaults
885	            this.cfg = this.cfg.extend(cfg);
886
887	            // Set initial values
888	            this.reset();
889	        },
890
891	        /**
892	         * Resets this hasher to its initial state.
893	         *
894	         * @example
895	         *
896	         *     hasher.reset();
897	         */
898	        reset: function () {
899	            // Reset data buffer
900	            BufferedBlockAlgorithm.reset.call(this);
901
902	            // Perform concrete-hasher logic
903	            this._doReset();
904	        },
905
906	        /**
907	         * Updates this hasher with a message.
908	         *
909	         * @param {WordArray|string} messageUpdate The message to append.
910	         *
911	         * @return {Hasher} This hasher.
912	         *
913	         * @example
914	         *
915	         *     hasher.update('message');
916	         *     hasher.update(wordArray);
917	         */
918	        update: function (messageUpdate) {
919	            // Append
920	            this._append(messageUpdate);
921
922	            // Update the hash
923	            this._process();
924
925	            // Chainable
926	            return this;
927	        },
928
929	        /**
930	         * Finalizes the hash computation.
931	         * Note that the finalize operation is effectively a destructive, read-once operation.
932	         *
933	         * @param {WordArray|string} messageUpdate (Optional) A final message update.
934	         *
935	         * @return {WordArray} The hash.
936	         *
937	         * @example
938	         *
939	         *     var hash = hasher.finalize();
940	         *     var hash = hasher.finalize('message');
941	         *     var hash = hasher.finalize(wordArray);
942	         */
943	        finalize: function (messageUpdate) {
944	            // Final message update
945	            if (messageUpdate) {
946	                this._append(messageUpdate);
947	            }
948
949	            // Perform concrete-hasher logic
950	            var hash = this._doFinalize();
951
952	            return hash;
953	        },
954
955	        blockSize: 512/32,
956
957	        /**
958	         * Creates a shortcut function to a hasher's object interface.
959	         *
960	         * @param {Hasher} hasher The hasher to create a helper for.
961	         *
962	         * @return {Function} The shortcut function.
963	         *
964	         * @static
965	         *
966	         * @example
967	         *
968	         *     var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
969	         */
970	        _createHelper: function (hasher) {
971	            return function (message, cfg) {
972	                return new hasher.init(cfg).finalize(message);
973	            };
974	        },
975
976	        /**
977	         * Creates a shortcut function to the HMAC's object interface.
978	         *
979	         * @param {Hasher} hasher The hasher to use in this HMAC helper.
980	         *
981	         * @return {Function} The shortcut function.
982	         *
983	         * @static
984	         *
985	         * @example
986	         *
987	         *     var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
988	         */
989	        _createHmacHelper: function (hasher) {
990	            return function (message, key) {
991	                return new C_algo.HMAC.init(hasher, key).finalize(message);
992	            };
993	        }
994	    });
995
996	    /**
997	     * Algorithm namespace.
998	     */
999	    var C_algo = C.algo = {};
1000
1001	    return C;
1002	}(Math));
1003
1004
1005	return CryptoJS;
1006
1007}));
1008},{}],4:[function(require,module,exports){
1009;(function (root, factory, undef) {
1010	if (typeof exports === "object") {
1011		// CommonJS
1012		module.exports = exports = factory(require("./core"), require("./x64-core"));
1013	}
1014	else if (typeof define === "function" && define.amd) {
1015		// AMD
1016		define(["./core", "./x64-core"], factory);
1017	}
1018	else {
1019		// Global (browser)
1020		factory(root.CryptoJS);
1021	}
1022}(this, function (CryptoJS) {
1023
1024	(function (Math) {
1025	    // Shortcuts
1026	    var C = CryptoJS;
1027	    var C_lib = C.lib;
1028	    var WordArray = C_lib.WordArray;
1029	    var Hasher = C_lib.Hasher;
1030	    var C_x64 = C.x64;
1031	    var X64Word = C_x64.Word;
1032	    var C_algo = C.algo;
1033
1034	    // Constants tables
1035	    var RHO_OFFSETS = [];
1036	    var PI_INDEXES  = [];
1037	    var ROUND_CONSTANTS = [];
1038
1039	    // Compute Constants
1040	    (function () {
1041	        // Compute rho offset constants
1042	        var x = 1, y = 0;
1043	        for (var t = 0; t < 24; t++) {
1044	            RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
1045
1046	            var newX = y % 5;
1047	            var newY = (2 * x + 3 * y) % 5;
1048	            x = newX;
1049	            y = newY;
1050	        }
1051
1052	        // Compute pi index constants
1053	        for (var x = 0; x < 5; x++) {
1054	            for (var y = 0; y < 5; y++) {
1055	                PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
1056	            }
1057	        }
1058
vendor: 15,592 bytes, lines 1059-1549
1059	        // Compute round constants
1060	        var LFSR = 0x01;
1061	        for (var i = 0; i < 24; i++) {
1062	            var roundConstantMsw = 0;
1063	            var roundConstantLsw = 0;
1064
1065	            for (var j = 0; j < 7; j++) {
1066	                if (LFSR & 0x01) {
1067	                    var bitPosition = (1 << j) - 1;
1068	                    if (bitPosition < 32) {
1069	                        roundConstantLsw ^= 1 << bitPosition;
1070	                    } else /* if (bitPosition >= 32) */ {
1071	                        roundConstantMsw ^= 1 << (bitPosition - 32);
1072	                    }
1073	                }
1074
1075	                // Compute next LFSR
1076	                if (LFSR & 0x80) {
1077	                    // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
1078	                    LFSR = (LFSR << 1) ^ 0x71;
1079	                } else {
1080	                    LFSR <<= 1;
1081	                }
1082	            }
1083
1084	            ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
1085	        }
1086	    }());
1087
1088	    // Reusable objects for temporary values
1089	    var T = [];
1090	    (function () {
1091	        for (var i = 0; i < 25; i++) {
1092	            T[i] = X64Word.create();
1093	        }
1094	    }());
1095
1096	    /**
1097	     * SHA-3 hash algorithm.
1098	     */
1099	    var SHA3 = C_algo.SHA3 = Hasher.extend({
1100	        /**
1101	         * Configuration options.
1102	         *
1103	         * @property {number} outputLength
1104	         *   The desired number of bits in the output hash.
1105	         *   Only values permitted are: 224, 256, 384, 512.
1106	         *   Default: 512
1107	         */
1108	        cfg: Hasher.cfg.extend({
1109	            outputLength: 512
1110	        }),
1111
1112	        _doReset: function () {
1113	            var state = this._state = []
1114	            for (var i = 0; i < 25; i++) {
1115	                state[i] = new X64Word.init();
1116	            }
1117
1118	            this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
1119	        },
1120
1121	        _doProcessBlock: function (M, offset) {
1122	            // Shortcuts
1123	            var state = this._state;
1124	            var nBlockSizeLanes = this.blockSize / 2;
1125
1126	            // Absorb
1127	            for (var i = 0; i < nBlockSizeLanes; i++) {
1128	                // Shortcuts
1129	                var M2i  = M[offset + 2 * i];
1130	                var M2i1 = M[offset + 2 * i + 1];
1131
1132	                // Swap endian
1133	                M2i = (
1134	                    (((M2i << 8)  | (M2i >>> 24)) & 0x00ff00ff) |
1135	                    (((M2i << 24) | (M2i >>> 8))  & 0xff00ff00)
1136	                );
1137	                M2i1 = (
1138	                    (((M2i1 << 8)  | (M2i1 >>> 24)) & 0x00ff00ff) |
1139	                    (((M2i1 << 24) | (M2i1 >>> 8))  & 0xff00ff00)
1140	                );
1141
1142	                // Absorb message into state
1143	                var lane = state[i];
1144	                lane.high ^= M2i1;
1145	                lane.low  ^= M2i;
1146	            }
1147
1148	            // Rounds
1149	            for (var round = 0; round < 24; round++) {
1150	                // Theta
1151	                for (var x = 0; x < 5; x++) {
1152	                    // Mix column lanes
1153	                    var tMsw = 0, tLsw = 0;
1154	                    for (var y = 0; y < 5; y++) {
1155	                        var lane = state[x + 5 * y];
1156	                        tMsw ^= lane.high;
1157	                        tLsw ^= lane.low;
1158	                    }
1159
1160	                    // Temporary values
1161	                    var Tx = T[x];
1162	                    Tx.high = tMsw;
1163	                    Tx.low  = tLsw;
1164	                }
1165	                for (var x = 0; x < 5; x++) {
1166	                    // Shortcuts
1167	                    var Tx4 = T[(x + 4) % 5];
1168	                    var Tx1 = T[(x + 1) % 5];
1169	                    var Tx1Msw = Tx1.high;
1170	                    var Tx1Lsw = Tx1.low;
1171
1172	                    // Mix surrounding columns
1173	                    var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
1174	                    var tLsw = Tx4.low  ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
1175	                    for (var y = 0; y < 5; y++) {
1176	                        var lane = state[x + 5 * y];
1177	                        lane.high ^= tMsw;
1178	                        lane.low  ^= tLsw;
1179	                    }
1180	                }
1181
1182	                // Rho Pi
1183	                for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
1184	                    // Shortcuts
1185	                    var lane = state[laneIndex];
1186	                    var laneMsw = lane.high;
1187	                    var laneLsw = lane.low;
1188	                    var rhoOffset = RHO_OFFSETS[laneIndex];
1189
1190	                    // Rotate lanes
1191	                    if (rhoOffset < 32) {
1192	                        var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
1193	                        var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
1194	                    } else /* if (rhoOffset >= 32) */ {
1195	                        var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
1196	                        var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
1197	                    }
1198
1199	                    // Transpose lanes
1200	                    var TPiLane = T[PI_INDEXES[laneIndex]];
1201	                    TPiLane.high = tMsw;
1202	                    TPiLane.low  = tLsw;
1203	                }
1204
1205	                // Rho pi at x = y = 0
1206	                var T0 = T[0];
1207	                var state0 = state[0];
1208	                T0.high = state0.high;
1209	                T0.low  = state0.low;
1210
1211	                // Chi
1212	                for (var x = 0; x < 5; x++) {
1213	                    for (var y = 0; y < 5; y++) {
1214	                        // Shortcuts
1215	                        var laneIndex = x + 5 * y;
1216	                        var lane = state[laneIndex];
1217	                        var TLane = T[laneIndex];
1218	                        var Tx1Lane = T[((x + 1) % 5) + 5 * y];
1219	                        var Tx2Lane = T[((x + 2) % 5) + 5 * y];
1220
1221	                        // Mix rows
1222	                        lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
1223	                        lane.low  = TLane.low  ^ (~Tx1Lane.low  & Tx2Lane.low);
1224	                    }
1225	                }
1226
1227	                // Iota
1228	                var lane = state[0];
1229	                var roundConstant = ROUND_CONSTANTS[round];
1230	                lane.high ^= roundConstant.high;
1231	                lane.low  ^= roundConstant.low;;
1232	            }
1233	        },
1234
1235	        _doFinalize: function () {
1236	            // Shortcuts
1237	            var data = this._data;
1238	            var dataWords = data.words;
1239	            var nBitsTotal = this._nDataBytes * 8;
1240	            var nBitsLeft = data.sigBytes * 8;
1241	            var blockSizeBits = this.blockSize * 32;
1242
1243	            // Add padding
1244	            dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
1245	            dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
1246	            data.sigBytes = dataWords.length * 4;
1247
1248	            // Hash final blocks
1249	            this._process();
1250
1251	            // Shortcuts
1252	            var state = this._state;
1253	            var outputLengthBytes = this.cfg.outputLength / 8;
1254	            var outputLengthLanes = outputLengthBytes / 8;
1255
1256	            // Squeeze
1257	            var hashWords = [];
1258	            for (var i = 0; i < outputLengthLanes; i++) {
1259	                // Shortcuts
1260	                var lane = state[i];
1261	                var laneMsw = lane.high;
1262	                var laneLsw = lane.low;
1263
1264	                // Swap endian
1265	                laneMsw = (
1266	                    (((laneMsw << 8)  | (laneMsw >>> 24)) & 0x00ff00ff) |
1267	                    (((laneMsw << 24) | (laneMsw >>> 8))  & 0xff00ff00)
1268	                );
1269	                laneLsw = (
1270	                    (((laneLsw << 8)  | (laneLsw >>> 24)) & 0x00ff00ff) |
1271	                    (((laneLsw << 24) | (laneLsw >>> 8))  & 0xff00ff00)
1272	                );
1273
1274	                // Squeeze state to retrieve hash
1275	                hashWords.push(laneLsw);
1276	                hashWords.push(laneMsw);
1277	            }
1278
1279	            // Return final computed hash
1280	            return new WordArray.init(hashWords, outputLengthBytes);
1281	        },
1282
1283	        clone: function () {
1284	            var clone = Hasher.clone.call(this);
1285
1286	            var state = clone._state = this._state.slice(0);
1287	            for (var i = 0; i < 25; i++) {
1288	                state[i] = state[i].clone();
1289	            }
1290
1291	            return clone;
1292	        }
1293	    });
1294
1295	    /**
1296	     * Shortcut function to the hasher's object interface.
1297	     *
1298	     * @param {WordArray|string} message The message to hash.
1299	     *
1300	     * @return {WordArray} The hash.
1301	     *
1302	     * @static
1303	     *
1304	     * @example
1305	     *
1306	     *     var hash = CryptoJS.SHA3('message');
1307	     *     var hash = CryptoJS.SHA3(wordArray);
1308	     */
1309	    C.SHA3 = Hasher._createHelper(SHA3);
1310
1311	    /**
1312	     * Shortcut function to the HMAC's object interface.
1313	     *
1314	     * @param {WordArray|string} message The message to hash.
1315	     * @param {WordArray|string} key The secret key.
1316	     *
1317	     * @return {WordArray} The HMAC.
1318	     *
1319	     * @static
1320	     *
1321	     * @example
1322	     *
1323	     *     var hmac = CryptoJS.HmacSHA3(message, key);
1324	     */
1325	    C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
1326	}(Math));
1327
1328
1329	return CryptoJS.SHA3;
1330
1331}));
1332},{"./core":3,"./x64-core":5}],5:[function(require,module,exports){
1333;(function (root, factory) {
1334	if (typeof exports === "object") {
1335		// CommonJS
1336		module.exports = exports = factory(require("./core"));
1337	}
1338	else if (typeof define === "function" && define.amd) {
1339		// AMD
1340		define(["./core"], factory);
1341	}
1342	else {
1343		// Global (browser)
1344		factory(root.CryptoJS);
1345	}
1346}(this, function (CryptoJS) {
1347
1348	(function (undefined) {
1349	    // Shortcuts
1350	    var C = CryptoJS;
1351	    var C_lib = C.lib;
1352	    var Base = C_lib.Base;
1353	    var X32WordArray = C_lib.WordArray;
1354
1355	    /**
1356	     * x64 namespace.
1357	     */
1358	    var C_x64 = C.x64 = {};
1359
1360	    /**
1361	     * A 64-bit word.
1362	     */
1363	    var X64Word = C_x64.Word = Base.extend({
1364	        /**
1365	         * Initializes a newly created 64-bit word.
1366	         *
1367	         * @param {number} high The high 32 bits.
1368	         * @param {number} low The low 32 bits.
1369	         *
1370	         * @example
1371	         *
1372	         *     var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
1373	         */
1374	        init: function (high, low) {
1375	            this.high = high;
1376	            this.low = low;
1377	        }
1378
1379	        /**
1380	         * Bitwise NOTs this word.
1381	         *
1382	         * @return {X64Word} A new x64-Word object after negating.
1383	         *
1384	         * @example
1385	         *
1386	         *     var negated = x64Word.not();
1387	         */
1388	        // not: function () {
1389	            // var high = ~this.high;
1390	            // var low = ~this.low;
1391
1392	            // return X64Word.create(high, low);
1393	        // },
1394
1395	        /**
1396	         * Bitwise ANDs this word with the passed word.
1397	         *
1398	         * @param {X64Word} word The x64-Word to AND with this word.
1399	         *
1400	         * @return {X64Word} A new x64-Word object after ANDing.
1401	         *
1402	         * @example
1403	         *
1404	         *     var anded = x64Word.and(anotherX64Word);
1405	         */
1406	        // and: function (word) {
1407	            // var high = this.high & word.high;
1408	            // var low = this.low & word.low;
1409
1410	            // return X64Word.create(high, low);
1411	        // },
1412
1413	        /**
1414	         * Bitwise ORs this word with the passed word.
1415	         *
1416	         * @param {X64Word} word The x64-Word to OR with this word.
1417	         *
1418	         * @return {X64Word} A new x64-Word object after ORing.
1419	         *
1420	         * @example
1421	         *
1422	         *     var ored = x64Word.or(anotherX64Word);
1423	         */
1424	        // or: function (word) {
1425	            // var high = this.high | word.high;
1426	            // var low = this.low | word.low;
1427
1428	            // return X64Word.create(high, low);
1429	        // },
1430
1431	        /**
1432	         * Bitwise XORs this word with the passed word.
1433	         *
1434	         * @param {X64Word} word The x64-Word to XOR with this word.
1435	         *
1436	         * @return {X64Word} A new x64-Word object after XORing.
1437	         *
1438	         * @example
1439	         *
1440	         *     var xored = x64Word.xor(anotherX64Word);
1441	         */
1442	        // xor: function (word) {
1443	            // var high = this.high ^ word.high;
1444	            // var low = this.low ^ word.low;
1445
1446	            // return X64Word.create(high, low);
1447	        // },
1448
1449	        /**
1450	         * Shifts this word n bits to the left.
1451	         *
1452	         * @param {number} n The number of bits to shift.
1453	         *
1454	         * @return {X64Word} A new x64-Word object after shifting.
1455	         *
1456	         * @example
1457	         *
1458	         *     var shifted = x64Word.shiftL(25);
1459	         */
1460	        // shiftL: function (n) {
1461	            // if (n < 32) {
1462	                // var high = (this.high << n) | (this.low >>> (32 - n));
1463	                // var low = this.low << n;
1464	            // } else {
1465	                // var high = this.low << (n - 32);
1466	                // var low = 0;
1467	            // }
1468
1469	            // return X64Word.create(high, low);
1470	        // },
1471
1472	        /**
1473	         * Shifts this word n bits to the right.
1474	         *
1475	         * @param {number} n The number of bits to shift.
1476	         *
1477	         * @return {X64Word} A new x64-Word object after shifting.
1478	         *
1479	         * @example
1480	         *
1481	         *     var shifted = x64Word.shiftR(7);
1482	         */
1483	        // shiftR: function (n) {
1484	            // if (n < 32) {
1485	                // var low = (this.low >>> n) | (this.high << (32 - n));
1486	                // var high = this.high >>> n;
1487	            // } else {
1488	                // var low = this.high >>> (n - 32);
1489	                // var high = 0;
1490	            // }
1491
1492	            // return X64Word.create(high, low);
1493	        // },
1494
1495	        /**
1496	         * Rotates this word n bits to the left.
1497	         *
1498	         * @param {number} n The number of bits to rotate.
1499	         *
1500	         * @return {X64Word} A new x64-Word object after rotating.
1501	         *
1502	         * @example
1503	         *
1504	         *     var rotated = x64Word.rotL(25);
1505	         */
1506	        // rotL: function (n) {
1507	            // return this.shiftL(n).or(this.shiftR(64 - n));
1508	        // },
1509
1510	        /**
1511	         * Rotates this word n bits to the right.
1512	         *
1513	         * @param {number} n The number of bits to rotate.
1514	         *
1515	         * @return {X64Word} A new x64-Word object after rotating.
1516	         *
1517	         * @example
1518	         *
1519	         *     var rotated = x64Word.rotR(7);
1520	         */
1521	        // rotR: function (n) {
1522	            // return this.shiftR(n).or(this.shiftL(64 - n));
1523	        // },
1524
1525	        /**
1526	         * Adds this word with the passed word.
1527	         *
1528	         * @param {X64Word} word The x64-Word to add with this word.
1529	         *
1530	         * @return {X64Word} A new x64-Word object after adding.
1531	         *
1532	         * @example
1533	         *
1534	         *     var added = x64Word.add(anotherX64Word);
1535	         */
1536	        // add: function (word) {
1537	            // var low = (this.low + word.low) | 0;
1538	            // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
1539	            // var high = (this.high + word.high + carry) | 0;
1540
1541	            // return X64Word.create(high, low);
1542	        // }
1543	    });
1544
1545	    /**
1546	     * An array of 64-bit words.
1547	     *
1548	     * @property {Array} words The array of CryptoJS.x64.Word objects.
1549	     * @property {number} sigBytes The number of significant bytes in this word array.
1550	     */
1551	    var X64WordArray = C_x64.WordArray = Base.extend({
1552	        /**
1553	         * Initializes a newly created word array.
1554	         *
1555	         * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
1556	         * @param {number} sigBytes (Optional) The number of significant bytes in the words.
1557	         *
1558	         * @example
1559	         *
1560	         *     var wordArray = CryptoJS.x64.WordArray.create();
1561	         *
1562	         *     var wordArray = CryptoJS.x64.WordArray.create([
1563	         *         CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1564	         *         CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1565	         *     ]);
1566	         *
1567	         *     var wordArray = CryptoJS.x64.WordArray.create([
1568	         *         CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1569	         *         CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1570	         *     ], 10);
1571	         */
1572	        init: function (words, sigBytes) {
1573	            words = this.words = words || [];
1574
1575	            if (sigBytes != undefined) {
1576	                this.sigBytes = sigBytes;
1577	            } else {
1578	                this.sigBytes = words.length * 8;
1579	            }
1580	        },
1581
1582	        /**
1583	         * Converts this 64-bit word array to a 32-bit word array.
1584	         *
1585	         * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
1586	         *
1587	         * @example
1588	         *
1589	         *     var x32WordArray = x64WordArray.toX32();
1590	         */
1591	        toX32: function () {
1592	            // Shortcuts
1593	            var x64Words = this.words;
1594	            var x64WordsLength = x64Words.length;
1595
1596	            // Convert
1597	            var x32Words = [];
1598	            for (var i = 0; i < x64WordsLength; i++) {
1599	                var x64Word = x64Words[i];
1600	                x32Words.push(x64Word.high);
1601	                x32Words.push(x64Word.low);
1602	            }
1603
1604	            return X32WordArray.create(x32Words, this.sigBytes);
1605	        },
1606
1607	        /**
1608	         * Creates a copy of this word array.
1609	         *
1610	         * @return {X64WordArray} The clone.
1611	         *
1612	         * @example
1613	         *
1614	         *     var clone = x64WordArray.clone();
1615	         */
1616	        clone: function () {
1617	            var clone = Base.clone.call(this);
1618
1619	            // Clone "words" array
1620	            var words = clone.words = this.words.slice(0);
1621
1622	            // Clone each X64Word object
1623	            var wordsLength = words.length;
1624	            for (var i = 0; i < wordsLength; i++) {
1625	                words[i] = words[i].clone();
1626	            }
1627
1628	            return clone;
1629	        }
1630	    });
1631	}());
1632
1633
1634	return CryptoJS;
1635
1636}));
1637},{"./core":3}],6:[function(require,module,exports){
1638module.exports={
1639  "name": "truffle-contract-schema",
1640  "version": "0.0.5",
1641  "description": "JSON schema for contract artifacts",
1642  "main": "index.js",
1643  "scripts": {
1644    "test": "mocha"
1645  },
1646  "repository": {
1647    "type": "git",
1648    "url": "git+https://github.com/trufflesuite/truffle-schema.git"
1649  },
1650  "keywords": [
1651    "ethereum",
1652    "json",
1653    "schema",
1654    "contract",
1655    "artifacts"
1656  ],
1657  "author": "Tim Coulter <[email protected]>",
1658  "license": "MIT",
1659  "bugs": {
1660    "url": "https://github.com/trufflesuite/truffle-schema/issues"
1661  },
1662  "homepage": "https://github.com/trufflesuite/truffle-schema#readme",
1663  "dependencies": {
1664    "crypto-js": "^3.1.9-1"
1665  },
1666  "devDependencies": {
1667    "mocha": "^3.2.0"
1668  }
1669}
1670
1671},{}],7:[function(require,module,exports){
1672(function (global){
1673var ethJSABI = require("ethjs-abi");
1674var BlockchainUtils = require("truffle-blockchain-utils");
1675var Web3 = require("web3");
1676
1677// For browserified version. If browserify gave us an empty version,
1678// look for the one provided by the user.
1679if (typeof Web3 == "object" && Object.keys(Web3).length == 0) {
1680  Web3 = global.Web3;
1681}
1682
1683var contract = (function(module) {
1684
1685  // Planned for future features, logging, etc.
1686  function Provider(provider) {
1687    this.provider = provider;
1688  }
1689
1690  Provider.prototype.send = function() {
1691    return this.provider.send.apply(this.provider, arguments);
1692  };
1693
1694  Provider.prototype.sendAsync = function() {
1695    return this.provider.sendAsync.apply(this.provider, arguments);
1696  };
1697
1698  var BigNumber = (new Web3()).toBigNumber(0).constructor;
1699
1700  var Utils = {
1701    is_object: function(val) {
1702      return typeof val == "object" && !Array.isArray(val);
1703    },
1704    is_big_number: function(val) {
1705      if (typeof val != "object") return false;
1706
1707      // Instanceof won't work because we have multiple versions of Web3.
1708      try {
1709        new BigNumber(val);
1710        return true;
1711      } catch (e) {
1712        return false;
1713      }
1714    },
1715    decodeLogs: function(C, instance, logs) {
1716      return logs.map(function(log) {
1717        var logABI = C.events[log.topics[0]];
1718
1719        if (logABI == null) {
1720          return null;
1721        }
1722
1723        // This function has been adapted from web3's SolidityEvent.decode() method,
1724        // and built to work with ethjs-abi.
1725
1726        var copy = Utils.merge({}, log);
1727
1728        function partialABI(fullABI, indexed) {
1729          var inputs = fullABI.inputs.filter(function (i) {
1730            return i.indexed === indexed;
1731          });
1732
1733          var partial = {
1734            inputs: inputs,
1735            name: fullABI.name,
1736            type: fullABI.type,
1737            anonymous: fullABI.anonymous
1738          };
1739
1740          return partial;
1741        }
1742
1743        var argTopics = logABI.anonymous ? copy.topics : copy.topics.slice(1);
1744        var indexedData = "0x" + argTopics.map(function (topics) { return topics.slice(2); }).join("");
1745        var indexedParams = ethJSABI.decodeEvent(partialABI(logABI, true), indexedData);
1746
1747        var notIndexedData = copy.data;
1748        var notIndexedParams = ethJSABI.decodeEvent(partialABI(logABI, false), notIndexedData);
1749
1750        copy.event = logABI.name;
1751
1752        copy.args = logABI.inputs.reduce(function (acc, current) {
1753          var val = indexedParams[current.name];
1754
1755          if (val === undefined) {
1756            val = notIndexedParams[current.name];
1757          }
1758
1759          acc[current.name] = val;
1760          return acc;
1761        }, {});
1762
1763        Object.keys(copy.args).forEach(function(key) {
1764          var val = copy.args[key];
1765
1766          // We have BN. Convert it to BigNumber
1767          if (val.constructor.isBN) {
1768            copy.args[key] = C.web3.toBigNumber("0x" + val.toString(16));
1769          }
1770        });
1771
1772        delete copy.data;
1773        delete copy.topics;
1774
1775        return copy;
1776      }).filter(function(log) {
1777        return log != null;
1778      });
1779    },
1780    promisifyFunction: function(fn, C) {
1781      var self = this;
1782      return function() {
1783        var instance = this;
1784
1785        var args = Array.prototype.slice.call(arguments);
1786        var tx_params = {};
1787        var last_arg = args[args.length - 1];
1788
1789        // It's only tx_params if it's an object and not a BigNumber.
1790        if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) {
1791          tx_params = args.pop();
1792        }
1793
1794        tx_params = Utils.merge(C.class_defaults, tx_params);
1795
1796        return C.detectNetwork().then(function() {
1797          return new Promise(function(accept, reject) {
1798            var callback = function(error, result) {
1799              if (error != null) {
1800                reject(error);
1801              } else {
1802                accept(result);
1803              }
1804            };
1805            args.push(tx_params, callback);
1806            fn.apply(instance.contract, args);
1807          });
1808        });
1809      };
1810    },
1811    synchronizeFunction: function(fn, instance, C) {
1812      var self = this;
1813      return function() {
1814        var args = Array.prototype.slice.call(arguments);
1815        var tx_params = {};
1816        var last_arg = args[args.length - 1];
1817
1818        // It's only tx_params if it's an object and not a BigNumber.
1819        if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) {
1820          tx_params = args.pop();
1821        }
1822
1823        tx_params = Utils.merge(C.class_defaults, tx_params);
1824
1825        return C.detectNetwork().then(function() {
1826          return new Promise(function(accept, reject) {
1827            var callback = function(error, tx) {
1828              if (error != null) {
1829                reject(error);
1830                return;
1831              }
1832
1833              var timeout = C.synchronization_timeout || 240000;
1834              var start = new Date().getTime();
1835
1836              var make_attempt = function() {
1837                C.web3.eth.getTransactionReceipt(tx, function(err, receipt) {
1838                  if (err) return reject(err);
1839
1840                  if (receipt != null) {
1841                    return accept({
1842                      tx: tx,
1843                      receipt: receipt,
1844                      logs: Utils.decodeLogs(C, instance, receipt.logs)
1845                    });
1846                  }
1847
1848                  if (timeout > 0 && new Date().getTime() - start > timeout) {
1849                    return reject(new Error("Transaction " + tx + " wasn't processed in " + (timeout / 1000) + " seconds!"));
1850                  }
1851
1852                  setTimeout(make_attempt, 1000);
1853                });
1854              };
1855
1856              make_attempt();
1857            };
1858
1859            args.push(tx_params, callback);
1860            fn.apply(self, args);
1861          });
1862        });
1863      };
1864    },
1865    merge: function() {
1866      var merged = {};
1867      var args = Array.prototype.slice.call(arguments);
1868
1869      for (var i = 0; i < args.length; i++) {
1870        var object = args[i];
1871        var keys = Object.keys(object);
1872        for (var j = 0; j < keys.length; j++) {
1873          var key = keys[j];
1874          var value = object[key];
1875          merged[key] = value;
1876        }
1877      }
1878
1879      return merged;
1880    },
1881    parallel: function (arr, callback) {
1882      callback = callback || function () {};
1883      if (!arr.length) {
1884        return callback(null, []);
1885      }
1886      var index = 0;
1887      var results = new Array(arr.length);
1888      arr.forEach(function (fn, position) {
1889        fn(function (err, result) {
1890          if (err) {
1891            callback(err);
1892            callback = function () {};
1893          } else {
1894            index++;
1895            results[position] = result;
1896            if (index >= arr.length) {
1897              callback(null, results);
1898            }
1899          }
1900        });
1901      });
1902    },
1903    bootstrap: function(fn) {
1904      // Add our static methods
1905      Object.keys(fn._static_methods).forEach(function(key) {
1906        fn[key] = fn._static_methods[key].bind(fn);
1907      });
1908
1909      // Add our properties.
1910      Object.keys(fn._properties).forEach(function(key) {
1911        fn.addProp(key, fn._properties[key]);
1912      });
1913
1914      return fn;
1915    }
1916  };
1917
1918  // Accepts a contract object created with web3.eth.contract.
1919  // Optionally, if called without `new`, accepts a network_id and will
1920  // create a new version of the contract abstraction with that network_id set.
1921  function Contract(contract) {
1922    var self = this;
1923    var constructor = this.constructor;
1924    this.abi = constructor.abi;
1925
1926    if (typeof contract == "string") {
1927      var address = contract;
1928      var contract_class = constructor.web3.eth.contract(this.abi);
1929      contract = contract_class.at(address);
1930    }
1931
1932    this.contract = contract;
1933
1934    // Provision our functions.
1935    for (var i = 0; i < this.abi.length; i++) {
1936      var item = this.abi[i];
1937      if (item.type == "function") {
1938        if (item.constant == true) {
1939          this[item.name] = Utils.promisifyFunction(contract[item.name], constructor);
1940        } else {
1941          this[item.name] = Utils.synchronizeFunction(contract[item.name], this, constructor);
1942        }
1943
1944        this[item.name].call = Utils.promisifyFunction(contract[item.name].call, constructor);
1945        this[item.name].sendTransaction = Utils.promisifyFunction(contract[item.name].sendTransaction, constructor);
1946        this[item.name].request = contract[item.name].request;
1947        this[item.name].estimateGas = Utils.promisifyFunction(contract[item.name].estimateGas, constructor);
1948      }
1949
1950      if (item.type == "event") {
1951        this[item.name] = contract[item.name];
1952      }
1953    }
1954
1955    this.sendTransaction = Utils.synchronizeFunction(function(tx_params, callback) {
1956      if (typeof tx_params == "function") {
1957        callback = tx_params;
1958        tx_params = {};
1959      }
1960
1961      tx_params.to = self.address;
1962
1963      constructor.web3.eth.sendTransaction.apply(constructor.web3.eth, [tx_params, callback]);
1964    }, this, constructor);
1965
1966    this.send = function(value) {
1967      return self.sendTransaction({value: value});
1968    };
1969
1970    this.allEvents = contract.allEvents;
1971    this.address = contract.address;
1972    this.transactionHash = contract.transactionHash;
1973  };
1974
1975  Contract._static_methods = {
1976    setProvider: function(provider) {
1977      if (!provider) {
1978        throw new Error("Invalid provider passed to setProvider(); provider is " + provider);
1979      }
1980
1981      var wrapped = new Provider(provider);
1982      this.web3.setProvider(wrapped);
1983      this.currentProvider = provider;
1984    },
1985
1986    new: function() {
1987      var self = this;
1988
1989      if (this.currentProvider == null) {
1990        throw new Error(this.contract_name + " error: Please call setProvider() first before calling new().");
1991      }
1992
1993      var args = Array.prototype.slice.call(arguments);
1994
1995      if (!this.unlinked_binary) {
1996        throw new Error(this._json.contract_name + " error: contract binary not set. Can't deploy new instance.");
1997      }
1998
1999      return self.detectNetwork().then(function(network_id) {
2000        // After the network is set, check to make sure everything's ship shape.
2001        var regex = /__[^_]+_+/g;
2002        var unlinked_libraries = self.binary.match(regex);
2003
2004        if (unlinked_libraries != null) {
2005          unlinked_libraries = unlinked_libraries.map(function(name) {
2006            // Remove underscores
2007            return name.replace(/_/g, "");
2008          }).sort().filter(function(name, index, arr) {
2009            // Remove duplicates
2010            if (index + 1 >= arr.length) {
2011              return true;
2012            }
2013
2014            return name != arr[index + 1];
2015          }).join(", ");
2016
2017          throw new Error(self.contract_name + " contains unresolved libraries. You must deploy and link the following libraries before you can deploy a new version of " + self._json.contract_name + ": " + unlinked_libraries);
2018        }
2019      }).then(function() {
2020        return new Promise(function(accept, reject) {
2021          var contract_class = self.web3.eth.contract(self.abi);
2022          var tx_params = {};
2023          var last_arg = args[args.length - 1];
2024
2025          // It's only tx_params if it's an object and not a BigNumber.
2026          if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) {
2027            tx_params = args.pop();
2028          }
2029
2030          tx_params = Utils.merge(self.class_defaults, tx_params);
2031
2032          if (tx_params.data == null) {
2033            tx_params.data = self.binary;
2034          }
2035
2036          // web3 0.9.0 and above calls new this callback twice.
2037          // Why, I have no idea...
2038          var intermediary = function(err, web3_instance) {
2039            if (err != null) {
2040              reject(err);
2041              return;
2042            }
2043
2044            if (err == null && web3_instance != null && web3_instance.address != null) {
2045              accept(new self(web3_instance));
2046            }
2047          };
2048
2049          args.push(tx_params, intermediary);
2050          contract_class.new.apply(contract_class, args);
2051        });
2052      });
2053    },
2054
2055    at: function(address) {
2056      var self = this;
2057
2058      if (address == null || typeof address != "string" || address.length != 42) {
2059        throw new Error("Invalid address passed to " + this._json.contract_name + ".at(): " + address);
2060      }
2061
2062      var contract = new this(address);
2063
2064      // Add thennable to allow people opt into new recommended usage.
2065      contract.then = function(fn) {
2066        return self.detectNetwork().then(function(network_id) {
2067          var instance = new self(address);
2068
2069          return new Promise(function(accept, reject) {
2070            self.web3.eth.getCode(address, function(err, code) {
2071              if (err) return reject(err);
2072
2073              if (!code || code.replace("0x", "").replace(/0/g, "") === '') {
2074                return reject(new Error("Cannot create instance of " + self.contract_name + "; no code at address " + address));
2075              }
2076
2077              accept(instance);
2078            });
2079          });
2080        }).then(fn);
2081      };
2082
2083      return contract;
2084    },
2085
2086    deployed: function() {
2087      var self = this;
2088      return self.detectNetwork().then(function() {
2089        // We don't have a network config for the one we found
2090        if (self._json.networks[self.network_id] == null) {
2091          throw new Error(self.contract_name + " has not been deployed to detected network (network/artifact mismatch)");
2092        }
2093
2094        // If we found the network but it's not deployed
2095        if (!self.isDeployed()) {
2096          throw new Error(self.contract_name + " has not been deployed to detected network (" + self.network_id + ")");
2097        }
2098
2099        return new self(self.address);
2100      });
2101    },
2102
2103    defaults: function(class_defaults) {
2104      if (this.class_defaults == null) {
2105        this.class_defaults = {};
2106      }
2107
2108      if (class_defaults == null) {
2109        class_defaults = {};
2110      }
2111
2112      var self = this;
2113      Object.keys(class_defaults).forEach(function(key) {
2114        var value = class_defaults[key];
2115        self.class_defaults[key] = value;
2116      });
2117
2118      return this.class_defaults;
2119    },
2120
2121    hasNetwork: function(network_id) {
2122      return this._json.networks[network_id + ""] != null;
2123    },
2124
2125    isDeployed: function() {
2126      if (this.network_id == null) {
2127        return false;
2128      }
2129
2130      if (this._json.networks[this.network_id] == null) {
2131        return false;
2132      }
2133
2134      return !!this.network.address;
2135    },
2136
2137    detectNetwork: function() {
2138      var self = this;
2139
2140      return new Promise(function(accept, reject) {
2141        // Try to detect the network we have artifacts for.
2142        if (self.network_id) {
2143          // We have a network id and a configuration, let's go with it.
2144          if (self.networks[self.network_id] != null) {
2145            return accept(self.network_id);
2146          }
2147        }
2148
2149        self.web3.version.getNetwork(function(err, result) {
2150          if (err) return reject(err);
2151
2152          var network_id = result.toString();
2153
2154          // If we found the network via a number, let's use that.
2155          if (self.hasNetwork(network_id)) {
2156            self.setNetwork(network_id);
2157            return accept();
2158          }
2159
2160          // Otherwise, go through all the networks that are listed as
2161          // blockchain uris and see if they match.
2162          var uris = Object.keys(self._json.networks).filter(function(network) {
2163            return network.indexOf("blockchain://") == 0;
2164          });
2165
2166          var matches = uris.map(function(uri) {
2167            return BlockchainUtils.matches.bind(BlockchainUtils, uri, self.web3.currentProvider);
2168          });
2169
2170          Utils.parallel(matches, function(err, results) {
2171            if (err) return reject(err);
2172
2173            for (var i = 0; i < results.length; i++) {
2174              if (results[i]) {
2175                self.setNetwork(uris[i]);
2176                return accept();
2177              }
2178            }
2179
2180            // We found nothing. Set the network id to whatever the provider states.
2181            self.setNetwork(network_id);
2182
2183            accept();
2184          });
2185
2186        });
2187      });
2188    },
2189
2190    setNetwork: function(network_id) {
2191      if (!network_id) return;
2192      this.network_id = network_id + "";
2193    },
2194
2195    // Overrides the deployed address to null.
2196    // You must call this explicitly so you don't inadvertently do this otherwise.
2197    resetAddress: function() {
2198      delete this.network.address;
2199    },
2200
2201    link: function(name, address) {
2202      var self = this;
2203
2204      if (typeof name == "function") {
2205        var contract = name;
2206
2207        if (contract.isDeployed() == false) {
2208          throw new Error("Cannot link contract without an address.");
2209        }
2210
2211        this.link(contract.contract_name, contract.address);
2212
2213        // Merge events so this contract knows about library's events
2214        Object.keys(contract.events).forEach(function(topic) {
2215          self.network.events[topic] = contract.events[topic];
2216        });
2217
2218        return;
2219      }
2220
2221      if (typeof name == "object") {
2222        var obj = name;
2223        Object.keys(obj).forEach(function(name) {
2224          var a = obj[name];
2225          self.link(name, a);
2226        });
2227        return;
2228      }
2229
2230      if (this._json.networks[this.network_id] == null) {
2231        this._json.networks[this.network_id] = {
2232          events: {},
2233          links: {}
2234        };
2235      }
2236
2237      this.network.links[name] = address;
2238    },
2239
2240    clone: function(options) {
2241      var self = this;
2242      var temp = function TruffleContract() {
2243        this.constructor = temp;
2244        return Contract.apply(this, arguments);
2245      };
2246
2247      var json = options;
2248      var network_id;
2249
2250      if (typeof options != "object") {
2251        json = self._json;
2252        network_id = options;
2253        options = {};
2254      }
2255
2256      temp.prototype = Object.create(self.prototype);
2257
2258      temp._static_methods = this._static_methods;
2259      temp._properties = this._properties;
2260
2261      temp._property_values = {};
2262      temp._json = json || {};
2263
2264      Utils.bootstrap(temp);
2265
2266      temp.web3 = new Web3();
2267      temp.class_defaults = temp.prototype.defaults || {};
2268
2269      if (network_id) {
2270        temp.setNetwork(network_id);
2271      }
2272
2273      // Copy over custom options
2274      Object.keys(options).forEach(function(key) {
2275        if (key.indexOf("x-") != 0) return;
2276        temp[key] = options[key];
2277      });
2278
2279      return temp;
2280    },
2281
2282    addProp: function(key, fn) {
2283      var self = this;
2284
2285      var getter = function() {
2286        if (fn.get != null) {
2287          return fn.get.call(self);
2288        }
2289
2290        return self._property_values[key] || fn.call(self);
2291      }
2292      var setter = function(val) {
2293        if (fn.set != null) {
2294          fn.set.call(self, val);
2295          return;
2296        }
2297
2298        // If there's not a setter, then the property is immutable.
2299        throw new Error(key + " property is immutable");
2300      };
2301
2302      var definition = {};
2303      definition.enumerable = false;
2304      definition.configurable = false;
2305      definition.get = getter;
2306      definition.set = setter;
2307
2308      Object.defineProperty(this, key, definition);
2309    },
2310
2311    toJSON: function() {
2312      return this._json;
2313    }
2314  };
2315
2316  // Getter functions are scoped to Contract object.
2317  Contract._properties = {
2318    contract_name: {
2319      get: function() {
2320        return this._json.contract_name;
2321      },
2322      set: function(val) {
2323        this._json.contract_name = val;
2324      }
2325    },
2326    abi: {
2327      get: function() {
2328        return this._json.abi;
2329      },
2330      set: function(val) {
2331        this._json.abi = val;
2332      }
2333    },
2334    network: function() {
2335      var network_id = this.network_id;
2336
2337      if (network_id == null) {
2338        throw new Error(this.contract_name + " has no network id set, cannot lookup artifact data. Either set the network manually using " + this.contract_name + ".setNetwork(), run " + this.contract_name + ".detectNetwork(), or use new(), at() or deployed() as a thenable which will detect the network automatically.");
2339      }
2340
2341      // TODO: this might be bad; setting a value on a get.
2342      if (this._json.networks[network_id] == null) {
2343        throw new Error(this.contract_name + " has no network configuration for its current network id (" + network_id + ").");
2344      }
2345
2346      return this._json.networks[network_id];
2347    },
2348    networks: function() {
2349      return this._json.networks;
2350    },
2351    address: {
2352      get: function() {
2353        var address = this.network.address;
2354
2355        if (address == null) {
2356          throw new Error("Cannot find deployed address: " + this.contract_name + " not deployed or address not set.");
2357        }
2358
2359        return address;
2360      },
2361      set: function(val) {
2362        if (val == null) {
2363          throw new Error("Cannot set deployed address; malformed value: " + val);
2364        }
2365
2366        var network_id = this.network_id;
2367
2368        if (network_id == null) {
2369          throw new Error(this.contract_name + " has no network id set, cannot lookup artifact data. Either set the network manually using " + this.contract_name + ".setNetwork(), run " + this.contract_name + ".detectNetwork(), or use new(), at() or deployed() as a thenable which will detect the network automatically.");
2370        }
2371
2372        // Create a network if we don't have one.
2373        if (this._json.networks[network_id] == null) {
2374          this._json.networks[network_id] = {
2375            events: {},
2376            links: {}
2377          };
2378        }
2379
2380        // Finally, set the address.
2381        this.network.address = val;
2382      }
2383    },
2384    links: function() {
2385      if (this._json.networks[this.network_id] == null) {
2386        return {};
2387      }
2388
2389      return this.network.links || {};
2390    },
2391    events: function() {
2392      // helper web3; not used for provider
2393      var web3 = new Web3();
2394
2395      var events;
2396
2397      if (this._json.networks[this.network_id] == null) {
2398        events = {};
2399      } else {
2400        events = this.network.events || {};
2401      }
2402
2403      // Merge abi events with whatever's returned.
2404      var abi = this.abi;
2405
2406      abi.forEach(function(item) {
2407        if (item.type != "event") return;
2408
2409        var signature = item.name + "(";
2410
2411        item.inputs.forEach(function(input, index) {
2412          signature += input.type;
2413
2414          if (index < item.inputs.length - 1) {
2415            signature += ",";
2416          }
2417        });
2418
2419        signature += ")";
2420
2421        var topic = web3.sha3(signature);
2422
2423        events[topic] = item;
2424      });
2425
2426      return events;
2427    },
2428    binary: function() {
2429      var self = this;
2430      var binary = this.unlinked_binary;
2431
2432      Object.keys(this.links).forEach(function(library_name) {
2433        var library_address = self.links[library_name];
2434        var regex = new RegExp("__" + library_name + "_+", "g");
2435
2436        binary = binary.replace(regex, library_address.replace("0x", ""));
2437      });
2438
2439      return binary;
2440    },
2441    unlinked_binary: {
2442      get: function() {
2443        return this._json.unlinked_binary;
2444      },
2445      set: function(val) {
2446        // TODO: Ensure 0x prefix.
2447        this._json.unlinked_binary = val;
2448      }
2449    },
2450    schema_version: function() {
2451      return this._json.schema_version;
2452    },
2453    updated_at: function() {
2454      try {
2455        return this.network.updated_at || this._json.updated_at;
2456      } catch (e) {
2457        return this._json.updated_at;
2458      }
2459    }
2460  };
2461
2462  Utils.bootstrap(Contract);
2463
2464  module.exports = Contract;
2465
2466  return Contract;
2467})(module || {});
2468
2469}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2470},{"ethjs-abi":13,"truffle-blockchain-utils":1,"web3":11}],8:[function(require,module,exports){
2471var Schema = require("truffle-contract-schema");
2472var Contract = require("./contract.js");
2473
2474var contract = function(options) {
2475  options = Schema.normalizeOptions(options);
2476  var binary = Schema.generateBinary(options, {}, {dirty: false});
2477
2478  // Note we don't use `new` here at all. This will cause the class to
2479  // "mutate" instead of instantiate an instance.
2480  return Contract.clone(binary);
2481};
2482
2483// To be used to upgrade old .sol.js abstractions
2484contract.fromSolJS = function(soljs_abstraction, ignore_default_network) {
2485  if (ignore_default_network == null) {
2486    ignore_default_network = false;
2487  }
2488
2489  // Find the latest binary
2490  var latest_network = null;
2491  var latest_network_updated_at = 0;
2492
2493  var networks = {};
2494
2495  Object.keys(soljs_abstraction.all_networks).forEach(function(network_name) {
2496
2497    if (network_name == "default") {
2498      if (ignore_default_network == true ) {
2499        return;
2500      } else {
2501        throw new Error(soljs_abstraction.contract_name + " has legacy 'default' network artifacts stored within it. Generally these artifacts were a result of running Truffle on a development environment -- in order to store contracts with truffle-contract, all networks must have an identified id. If you're sure this default network represents your development environment, you can ignore processing of the default network by passing `true` as the second argument to this function. However, if you think this network represents artifacts you'd like to keep (i.e., addresses deployed to the main network), you'll need to edit your .sol.js file yourself and change the default network id to be the id of your desired network. For most people, ignoring the default network is the correct option.");
2502      }
2503    }
2504
2505    if (soljs_abstraction.all_networks[network_name].updated_at > latest_network_updated_at) {
2506      latest_network = network_name;
2507      latest_network_updated_at = soljs_abstraction.all_networks[network_name].updated_at;
2508    }
2509
2510    networks[network_name] = {};
2511
2512    ["address", "events", "links", "updated_at"].forEach(function(key) {
2513      networks[network_name][key] = soljs_abstraction.all_networks[network_name][key];
2514    })
2515  });
2516
2517  latest_network = soljs_abstraction.all_networks[latest_network] || {};
2518
2519  var json = {
2520    contract_name: soljs_abstraction.contract_name,
2521    unlinked_binary: latest_network.unlinked_binary,
2522    abi: latest_network.abi,
2523    networks: networks,
2524    updated_at: latest_network_updated_at == 0 ? undefined : latest_network_updated_at
2525  };
2526
2527  return contract(json);
2528};
2529
2530module.exports = contract;
2531
2532if (typeof window !== "undefined") {
2533  window.TruffleContract = contract;
2534}
2535
2536},{"./contract.js":7,"truffle-contract-schema":2}],9:[function(require,module,exports){
2537'use strict'
2538
2539exports.byteLength = byteLength
2540exports.toByteArray = toByteArray
2541exports.fromByteArray = fromByteArray
2542
2543var lookup = []
2544var revLookup = []
2545var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
2546
2547var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
vendor: 10,384 bytes, lines 2547-2958
2547+/'
2548for (var i = 0, len = code.length; i < len; ++i) {
2549  lookup[i] = code[i]
2550  revLookup[code.charCodeAt(i)] = i
2551}
2552
2553revLookup['-'.charCodeAt(0)] = 62
2554revLookup['_'.charCodeAt(0)] = 63
2555
2556function placeHoldersCount (b64) {
2557  var len = b64.length
2558  if (len % 4 > 0) {
2559    throw new Error('Invalid string. Length must be a multiple of 4')
2560  }
2561
2562  // the number of equal signs (place holders)
2563  // if there are two placeholders, than the two characters before it
2564  // represent one byte
2565  // if there is only one, then the three characters before it represent 2 bytes
2566  // this is just a cheap hack to not do indexOf twice
2567  return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
2568}
2569
2570function byteLength (b64) {
2571  // base64 is 4/3 + up to two characters of the original data
2572  return (b64.length * 3 / 4) - placeHoldersCount(b64)
2573}
2574
2575function toByteArray (b64) {
2576  var i, l, tmp, placeHolders, arr
2577  var len = b64.length
2578  placeHolders = placeHoldersCount(b64)
2579
2580  arr = new Arr((len * 3 / 4) - placeHolders)
2581
2582  // if there are placeholders, only get up to the last complete 4 chars
2583  l = placeHolders > 0 ? len - 4 : len
2584
2585  var L = 0
2586
2587  for (i = 0; i < l; i += 4) {
2588    tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
2589    arr[L++] = (tmp >> 16) & 0xFF
2590    arr[L++] = (tmp >> 8) & 0xFF
2591    arr[L++] = tmp & 0xFF
2592  }
2593
2594  if (placeHolders === 2) {
2595    tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
2596    arr[L++] = tmp & 0xFF
2597  } else if (placeHolders === 1) {
2598    tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
2599    arr[L++] = (tmp >> 8) & 0xFF
2600    arr[L++] = tmp & 0xFF
2601  }
2602
2603  return arr
2604}
2605
2606function tripletToBase64 (num) {
2607  return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
2608}
2609
2610function encodeChunk (uint8, start, end) {
2611  var tmp
2612  var output = []
2613  for (var i = start; i < end; i += 3) {
2614    tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
2615    output.push(tripletToBase64(tmp))
2616  }
2617  return output.join('')
2618}
2619
2620function fromByteArray (uint8) {
2621  var tmp
2622  var len = uint8.length
2623  var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
2624  var output = ''
2625  var parts = []
2626  var maxChunkLength = 16383 // must be multiple of 3
2627
2628  // go through the array every three bytes, we'll deal with trailing stuff later
2629  for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
2630    parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
2631  }
2632
2633  // pad the end with zeros, but make sure to not forget the extra bytes
2634  if (extraBytes === 1) {
2635    tmp = uint8[len - 1]
2636    output += lookup[tmp >> 2]
2637    output += lookup[(tmp << 4) & 0x3F]
2638    output += '=='
2639  } else if (extraBytes === 2) {
2640    tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
2641    output += lookup[tmp >> 10]
2642    output += lookup[(tmp >> 4) & 0x3F]
2643    output += lookup[(tmp << 2) & 0x3F]
2644    output += '='
2645  }
2646
2647  parts.push(output)
2648
2649  return parts.join('')
2650}
2651
2652},{}],10:[function(require,module,exports){
2653(function (module, exports) {
2654  'use strict';
2655
2656  // Utils
2657  function assert (val, msg) {
2658    if (!val) throw new Error(msg || 'Assertion failed');
2659  }
2660
2661  // Could use `inherits` module, but don't want to move from single file
2662  // architecture yet.
2663  function inherits (ctor, superCtor) {
2664    ctor.super_ = superCtor;
2665    var TempCtor = function () {};
2666    TempCtor.prototype = superCtor.prototype;
2667    ctor.prototype = new TempCtor();
2668    ctor.prototype.constructor = ctor;
2669  }
2670
2671  // BN
2672
2673  function BN (number, base, endian) {
2674    if (BN.isBN(number)) {
2675      return number;
2676    }
2677
2678    this.negative = 0;
2679    this.words = null;
2680    this.length = 0;
2681
2682    // Reduction context
2683    this.red = null;
2684
2685    if (number !== null) {
2686      if (base === 'le' || base === 'be') {
2687        endian = base;
2688        base = 10;
2689      }
2690
2691      this._init(number || 0, base || 10, endian || 'be');
2692    }
2693  }
2694  if (typeof module === 'object') {
2695    module.exports = BN;
2696  } else {
2697    exports.BN = BN;
2698  }
2699
2700  BN.BN = BN;
2701  BN.wordSize = 26;
2702
2703  var Buffer;
2704  try {
2705    Buffer = require('buf' + 'fer').Buffer;
2706  } catch (e) {
2707  }
2708
2709  BN.isBN = function isBN (num) {
2710    if (num instanceof BN) {
2711      return true;
2712    }
2713
2714    return num !== null && typeof num === 'object' &&
2715      num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
2716  };
2717
2718  BN.max = function max (left, right) {
2719    if (left.cmp(right) > 0) return left;
2720    return right;
2721  };
2722
2723  BN.min = function min (left, right) {
2724    if (left.cmp(right) < 0) return left;
2725    return right;
2726  };
2727
2728  BN.prototype._init = function init (number, base, endian) {
2729    if (typeof number === 'number') {
2730      return this._initNumber(number, base, endian);
2731    }
2732
2733    if (typeof number === 'object') {
2734      return this._initArray(number, base, endian);
2735    }
2736
2737    if (base === 'hex') {
2738      base = 16;
2739    }
2740    assert(base === (base | 0) && base >= 2 && base <= 36);
2741
2742    number = number.toString().replace(/\s+/g, '');
2743    var start = 0;
2744    if (number[0] === '-') {
2745      start++;
2746    }
2747
2748    if (base === 16) {
2749      this._parseHex(number, start);
2750    } else {
2751      this._parseBase(number, base, start);
2752    }
2753
2754    if (number[0] === '-') {
2755      this.negative = 1;
2756    }
2757
2758    this.strip();
2759
2760    if (endian !== 'le') return;
2761
2762    this._initArray(this.toArray(), base, endian);
2763  };
2764
2765  BN.prototype._initNumber = function _initNumber (number, base, endian) {
2766    if (number < 0) {
2767      this.negative = 1;
2768      number = -number;
2769    }
2770    if (number < 0x4000000) {
2771      this.words = [ number & 0x3ffffff ];
2772      this.length = 1;
2773    } else if (number < 0x10000000000000) {
2774      this.words = [
2775        number & 0x3ffffff,
2776        (number / 0x4000000) & 0x3ffffff
2777      ];
2778      this.length = 2;
2779    } else {
2780      assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
2781      this.words = [
2782        number & 0x3ffffff,
2783        (number / 0x4000000) & 0x3ffffff,
2784        1
2785      ];
2786      this.length = 3;
2787    }
2788
2789    if (endian !== 'le') return;
2790
2791    // Reverse the bytes
2792    this._initArray(this.toArray(), base, endian);
2793  };
2794
2795  BN.prototype._initArray = function _initArray (number, base, endian) {
2796    // Perhaps a Uint8Array
2797    assert(typeof number.length === 'number');
2798    if (number.length <= 0) {
2799      this.words = [ 0 ];
2800      this.length = 1;
2801      return this;
2802    }
2803
2804    this.length = Math.ceil(number.length / 3);
2805    this.words = new Array(this.length);
2806    for (var i = 0; i < this.length; i++) {
2807      this.words[i] = 0;
2808    }
2809
2810    var j, w;
2811    var off = 0;
2812    if (endian === 'be') {
2813      for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
2814        w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
2815        this.words[j] |= (w << off) & 0x3ffffff;
2816        this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
2817        off += 24;
2818        if (off >= 26) {
2819          off -= 26;
2820          j++;
2821        }
2822      }
2823    } else if (endian === 'le') {
2824      for (i = 0, j = 0; i < number.length; i += 3) {
2825        w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
2826        this.words[j] |= (w << off) & 0x3ffffff;
2827        this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
2828        off += 24;
2829        if (off >= 26) {
2830          off -= 26;
2831          j++;
2832        }
2833      }
2834    }
2835    return this.strip();
2836  };
2837
2838  function parseHex (str, start, end) {
2839    var r = 0;
2840    var len = Math.min(str.length, end);
2841    for (var i = start; i < len; i++) {
2842      var c = str.charCodeAt(i) - 48;
2843
2844      r <<= 4;
2845
2846      // 'a' - 'f'
2847      if (c >= 49 && c <= 54) {
2848        r |= c - 49 + 0xa;
2849
2850      // 'A' - 'F'
2851      } else if (c >= 17 && c <= 22) {
2852        r |= c - 17 + 0xa;
2853
2854      // '0' - '9'
2855      } else {
2856        r |= c & 0xf;
2857      }
2858    }
2859    return r;
2860  }
2861
2862  BN.prototype._parseHex = function _parseHex (number, start) {
2863    // Create possibly bigger array to ensure that it fits the number
2864    this.length = Math.ceil((number.length - start) / 6);
2865    this.words = new Array(this.length);
2866    for (var i = 0; i < this.length; i++) {
2867      this.words[i] = 0;
2868    }
2869
2870    var j, w;
2871    // Scan 24-bit chunks and add them to the number
2872    var off = 0;
2873    for (i = number.length - 6, j = 0; i >= start; i -= 6) {
2874      w = parseHex(number, i, i + 6);
2875      this.words[j] |= (w << off) & 0x3ffffff;
2876      // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
2877      this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
2878      off += 24;
2879      if (off >= 26) {
2880        off -= 26;
2881        j++;
2882      }
2883    }
2884    if (i + 6 !== start) {
2885      w = parseHex(number, start, i + 6);
2886      this.words[j] |= (w << off) & 0x3ffffff;
2887      this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
2888    }
2889    this.strip();
2890  };
2891
2892  function parseBase (str, start, end, mul) {
2893    var r = 0;
2894    var len = Math.min(str.length, end);
2895    for (var i = start; i < len; i++) {
2896      var c = str.charCodeAt(i) - 48;
2897
2898      r *= mul;
2899
2900      // 'a'
2901      if (c >= 49) {
2902        r += c - 49 + 0xa;
2903
2904      // 'A'
2905      } else if (c >= 17) {
2906        r += c - 17 + 0xa;
2907
2908      // '0' - '9'
2909      } else {
2910        r += c;
2911      }
2912    }
2913    return r;
2914  }
2915
2916  BN.prototype._parseBase = function _parseBase (number, base, start) {
2917    // Initialize as zero
2918    this.words = [ 0 ];
2919    this.length = 1;
2920
2921    // Find length of limb in base
2922    for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
2923      limbLen++;
2924    }
2925    limbLen--;
2926    limbPow = (limbPow / base) | 0;
2927
2928    var total = number.length - start;
2929    var mod = total % limbLen;
2930    var end = Math.min(total, total - mod) + start;
2931
2932    var word = 0;
2933    for (var i = start; i < end; i += limbLen) {
2934      word = parseBase(number, i, i + limbLen, base);
2935
2936      this.imuln(limbPow);
2937      if (this.words[0] + word < 0x4000000) {
2938        this.words[0] += word;
2939      } else {
2940        this._iaddn(word);
2941      }
2942    }
2943
2944    if (mod !== 0) {
2945      var pow = 1;
2946      word = parseBase(number, i, number.length, base);
2947
2948      for (i = 0; i < mod; i++) {
2949        pow *= base;
2950      }
2951
2952      this.imuln(pow);
2953      if (this.words[0] + word < 0x4000000) {
2954        this.words[0] += word;
2955      } else {
2956        this._iaddn(word);
2957      }
2958    }
vendor: 68,018 bytes, lines 2958-5562
2958
2959  };
2960
2961  BN.prototype.copy = function copy (dest) {
2962    dest.words = new Array(this.length);
2963    for (var i = 0; i < this.length; i++) {
2964      dest.words[i] = this.words[i];
2965    }
2966    dest.length = this.length;
2967    dest.negative = this.negative;
2968    dest.red = this.red;
2969  };
2970
2971  BN.prototype.clone = function clone () {
2972    var r = new BN(null);
2973    this.copy(r);
2974    return r;
2975  };
2976
2977  BN.prototype._expand = function _expand (size) {
2978    while (this.length < size) {
2979      this.words[this.length++] = 0;
2980    }
2981    return this;
2982  };
2983
2984  // Remove leading `0` from `this`
2985  BN.prototype.strip = function strip () {
2986    while (this.length > 1 && this.words[this.length - 1] === 0) {
2987      this.length--;
2988    }
2989    return this._normSign();
2990  };
2991
2992  BN.prototype._normSign = function _normSign () {
2993    // -0 = 0
2994    if (this.length === 1 && this.words[0] === 0) {
2995      this.negative = 0;
2996    }
2997    return this;
2998  };
2999
3000  BN.prototype.inspect = function inspect () {
3001    return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
3002  };
3003
3004  /*
3005
3006  var zeros = [];
3007  var groupSizes = [];
3008  var groupBases = [];
3009
3010  var s = '';
3011  var i = -1;
3012  while (++i < BN.wordSize) {
3013    zeros[i] = s;
3014    s += '0';
3015  }
3016  groupSizes[0] = 0;
3017  groupSizes[1] = 0;
3018  groupBases[0] = 0;
3019  groupBases[1] = 0;
3020  var base = 2 - 1;
3021  while (++base < 36 + 1) {
3022    var groupSize = 0;
3023    var groupBase = 1;
3024    while (groupBase < (1 << BN.wordSize) / base) {
3025      groupBase *= base;
3026      groupSize += 1;
3027    }
3028    groupSizes[base] = groupSize;
3029    groupBases[base] = groupBase;
3030  }
3031
3032  */
3033
3034  var zeros = [
3035    '',
3036    '0',
3037    '00',
3038    '000',
3039    '0000',
3040    '00000',
3041    '000000',
3042    '0000000',
3043    '00000000',
3044    '000000000',
3045    '0000000000',
3046    '00000000000',
3047    '000000000000',
3048    '0000000000000',
3049    '00000000000000',
3050    '000000000000000',
3051    '0000000000000000',
3052    '00000000000000000',
3053    '000000000000000000',
3054    '0000000000000000000',
3055    '00000000000000000000',
3056    '000000000000000000000',
3057    '0000000000000000000000',
3058    '00000000000000000000000',
3059    '000000000000000000000000',
3060    '0000000000000000000000000'
3061  ];
3062
3063  var groupSizes = [
3064    0, 0,
3065    25, 16, 12, 11, 10, 9, 8,
3066    8, 7, 7, 7, 7, 6, 6,
3067    6, 6, 6, 6, 6, 5, 5,
3068    5, 5, 5, 5, 5, 5, 5,
3069    5, 5, 5, 5, 5, 5, 5
3070  ];
3071
3072  var groupBases = [
3073    0, 0,
3074    33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
3075    43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
3076    16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
3077    6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
3078    24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
3079  ];
3080
3081  BN.prototype.toString = function toString (base, padding) {
3082    base = base || 10;
3083    padding = padding | 0 || 1;
3084
3085    var out;
3086    if (base === 16 || base === 'hex') {
3087      out = '';
3088      var off = 0;
3089      var carry = 0;
3090      for (var i = 0; i < this.length; i++) {
3091        var w = this.words[i];
3092        var word = (((w << off) | carry) & 0xffffff).toString(16);
3093        carry = (w >>> (24 - off)) & 0xffffff;
3094        if (carry !== 0 || i !== this.length - 1) {
3095          out = zeros[6 - word.length] + word + out;
3096        } else {
3097          out = word + out;
3098        }
3099        off += 2;
3100        if (off >= 26) {
3101          off -= 26;
3102          i--;
3103        }
3104      }
3105      if (carry !== 0) {
3106        out = carry.toString(16) + out;
3107      }
3108      while (out.length % padding !== 0) {
3109        out = '0' + out;
3110      }
3111      if (this.negative !== 0) {
3112        out = '-' + out;
3113      }
3114      return out;
3115    }
3116
3117    if (base === (base | 0) && base >= 2 && base <= 36) {
3118      // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
3119      var groupSize = groupSizes[base];
3120      // var groupBase = Math.pow(base, groupSize);
3121      var groupBase = groupBases[base];
3122      out = '';
3123      var c = this.clone();
3124      c.negative = 0;
3125      while (!c.isZero()) {
3126        var r = c.modn(groupBase).toString(base);
3127        c = c.idivn(groupBase);
3128
3129        if (!c.isZero()) {
3130          out = zeros[groupSize - r.length] + r + out;
3131        } else {
3132          out = r + out;
3133        }
3134      }
3135      if (this.isZero()) {
3136        out = '0' + out;
3137      }
3138      while (out.length % padding !== 0) {
3139        out = '0' + out;
3140      }
3141      if (this.negative !== 0) {
3142        out = '-' + out;
3143      }
3144      return out;
3145    }
3146
3147    assert(false, 'Base should be between 2 and 36');
3148  };
3149
3150  BN.prototype.toNumber = function toNumber () {
3151    var ret = this.words[0];
3152    if (this.length === 2) {
3153      ret += this.words[1] * 0x4000000;
3154    } else if (this.length === 3 && this.words[2] === 0x01) {
3155      // NOTE: at this stage it is known that the top bit is set
3156      ret += 0x10000000000000 + (this.words[1] * 0x4000000);
3157    } else if (this.length > 2) {
3158      assert(false, 'Number can only safely store up to 53 bits');
3159    }
3160    return (this.negative !== 0) ? -ret : ret;
3161  };
3162
3163  BN.prototype.toJSON = function toJSON () {
3164    return this.toString(16);
3165  };
3166
3167  BN.prototype.toBuffer = function toBuffer (endian, length) {
3168    assert(typeof Buffer !== 'undefined');
3169    return this.toArrayLike(Buffer, endian, length);
3170  };
3171
3172  BN.prototype.toArray = function toArray (endian, length) {
3173    return this.toArrayLike(Array, endian, length);
3174  };
3175
3176  BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
3177    var byteLength = this.byteLength();
3178    var reqLength = length || Math.max(1, byteLength);
3179    assert(byteLength <= reqLength, 'byte array longer than desired length');
3180    assert(reqLength > 0, 'Requested array length <= 0');
3181
3182    this.strip();
3183    var littleEndian = endian === 'le';
3184    var res = new ArrayType(reqLength);
3185
3186    var b, i;
3187    var q = this.clone();
3188    if (!littleEndian) {
3189      // Assume big-endian
3190      for (i = 0; i < reqLength - byteLength; i++) {
3191        res[i] = 0;
3192      }
3193
3194      for (i = 0; !q.isZero(); i++) {
3195        b = q.andln(0xff);
3196        q.iushrn(8);
3197
3198        res[reqLength - i - 1] = b;
3199      }
3200    } else {
3201      for (i = 0; !q.isZero(); i++) {
3202        b = q.andln(0xff);
3203        q.iushrn(8);
3204
3205        res[i] = b;
3206      }
3207
3208      for (; i < reqLength; i++) {
3209        res[i] = 0;
3210      }
3211    }
3212
3213    return res;
3214  };
3215
3216  if (Math.clz32) {
3217    BN.prototype._countBits = function _countBits (w) {
3218      return 32 - Math.clz32(w);
3219    };
3220  } else {
3221    BN.prototype._countBits = function _countBits (w) {
3222      var t = w;
3223      var r = 0;
3224      if (t >= 0x1000) {
3225        r += 13;
3226        t >>>= 13;
3227      }
3228      if (t >= 0x40) {
3229        r += 7;
3230        t >>>= 7;
3231      }
3232      if (t >= 0x8) {
3233        r += 4;
3234        t >>>= 4;
3235      }
3236      if (t >= 0x02) {
3237        r += 2;
3238        t >>>= 2;
3239      }
3240      return r + t;
3241    };
3242  }
3243
3244  BN.prototype._zeroBits = function _zeroBits (w) {
3245    // Short-cut
3246    if (w === 0) return 26;
3247
3248    var t = w;
3249    var r = 0;
3250    if ((t & 0x1fff) === 0) {
3251      r += 13;
3252      t >>>= 13;
3253    }
3254    if ((t & 0x7f) === 0) {
3255      r += 7;
3256      t >>>= 7;
3257    }
3258    if ((t & 0xf) === 0) {
3259      r += 4;
3260      t >>>= 4;
3261    }
3262    if ((t & 0x3) === 0) {
3263      r += 2;
3264      t >>>= 2;
3265    }
3266    if ((t & 0x1) === 0) {
3267      r++;
3268    }
3269    return r;
3270  };
3271
3272  // Return number of used bits in a BN
3273  BN.prototype.bitLength = function bitLength () {
3274    var w = this.words[this.length - 1];
3275    var hi = this._countBits(w);
3276    return (this.length - 1) * 26 + hi;
3277  };
3278
3279  function toBitArray (num) {
3280    var w = new Array(num.bitLength());
3281
3282    for (var bit = 0; bit < w.length; bit++) {
3283      var off = (bit / 26) | 0;
3284      var wbit = bit % 26;
3285
3286      w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
3287    }
3288
3289    return w;
3290  }
3291
3292  // Number of trailing zero bits
3293  BN.prototype.zeroBits = function zeroBits () {
3294    if (this.isZero()) return 0;
3295
3296    var r = 0;
3297    for (var i = 0; i < this.length; i++) {
3298      var b = this._zeroBits(this.words[i]);
3299      r += b;
3300      if (b !== 26) break;
3301    }
3302    return r;
3303  };
3304
3305  BN.prototype.byteLength = function byteLength () {
3306    return Math.ceil(this.bitLength() / 8);
3307  };
3308
3309  BN.prototype.toTwos = function toTwos (width) {
3310    if (this.negative !== 0) {
3311      return this.abs().inotn(width).iaddn(1);
3312    }
3313    return this.clone();
3314  };
3315
3316  BN.prototype.fromTwos = function fromTwos (width) {
3317    if (this.testn(width - 1)) {
3318      return this.notn(width).iaddn(1).ineg();
3319    }
3320    return this.clone();
3321  };
3322
3323  BN.prototype.isNeg = function isNeg () {
3324    return this.negative !== 0;
3325  };
3326
3327  // Return negative clone of `this`
3328  BN.prototype.neg = function neg () {
3329    return this.clone().ineg();
3330  };
3331
3332  BN.prototype.ineg = function ineg () {
3333    if (!this.isZero()) {
3334      this.negative ^= 1;
3335    }
3336
3337    return this;
3338  };
3339
3340  // Or `num` with `this` in-place
3341  BN.prototype.iuor = function iuor (num) {
3342    while (this.length < num.length) {
3343      this.words[this.length++] = 0;
3344    }
3345
3346    for (var i = 0; i < num.length; i++) {
3347      this.words[i] = this.words[i] | num.words[i];
3348    }
3349
3350    return this.strip();
3351  };
3352
3353  BN.prototype.ior = function ior (num) {
3354    assert((this.negative | num.negative) === 0);
3355    return this.iuor(num);
3356  };
3357
3358  // Or `num` with `this`
3359  BN.prototype.or = function or (num) {
3360    if (this.length > num.length) return this.clone().ior(num);
3361    return num.clone().ior(this);
3362  };
3363
3364  BN.prototype.uor = function uor (num) {
3365    if (this.length > num.length) return this.clone().iuor(num);
3366    return num.clone().iuor(this);
3367  };
3368
3369  // And `num` with `this` in-place
3370  BN.prototype.iuand = function iuand (num) {
3371    // b = min-length(num, this)
3372    var b;
3373    if (this.length > num.length) {
3374      b = num;
3375    } else {
3376      b = this;
3377    }
3378
3379    for (var i = 0; i < b.length; i++) {
3380      this.words[i] = this.words[i] & num.words[i];
3381    }
3382
3383    this.length = b.length;
3384
3385    return this.strip();
3386  };
3387
3388  BN.prototype.iand = function iand (num) {
3389    assert((this.negative | num.negative) === 0);
3390    return this.iuand(num);
3391  };
3392
3393  // And `num` with `this`
3394  BN.prototype.and = function and (num) {
3395    if (this.length > num.length) return this.clone().iand(num);
3396    return num.clone().iand(this);
3397  };
3398
3399  BN.prototype.uand = function uand (num) {
3400    if (this.length > num.length) return this.clone().iuand(num);
3401    return num.clone().iuand(this);
3402  };
3403
3404  // Xor `num` with `this` in-place
3405  BN.prototype.iuxor = function iuxor (num) {
3406    // a.length > b.length
3407    var a;
3408    var b;
3409    if (this.length > num.length) {
3410      a = this;
3411      b = num;
3412    } else {
3413      a = num;
3414      b = this;
3415    }
3416
3417    for (var i = 0; i < b.length; i++) {
3418      this.words[i] = a.words[i] ^ b.words[i];
3419    }
3420
3421    if (this !== a) {
3422      for (; i < a.length; i++) {
3423        this.words[i] = a.words[i];
3424      }
3425    }
3426
3427    this.length = a.length;
3428
3429    return this.strip();
3430  };
3431
3432  BN.prototype.ixor = function ixor (num) {
3433    assert((this.negative | num.negative) === 0);
3434    return this.iuxor(num);
3435  };
3436
3437  // Xor `num` with `this`
3438  BN.prototype.xor = function xor (num) {
3439    if (this.length > num.length) return this.clone().ixor(num);
3440    return num.clone().ixor(this);
3441  };
3442
3443  BN.prototype.uxor = function uxor (num) {
3444    if (this.length > num.length) return this.clone().iuxor(num);
3445    return num.clone().iuxor(this);
3446  };
3447
3448  // Not ``this`` with ``width`` bitwidth
3449  BN.prototype.inotn = function inotn (width) {
3450    assert(typeof width === 'number' && width >= 0);
3451
3452    var bytesNeeded = Math.ceil(width / 26) | 0;
3453    var bitsLeft = width % 26;
3454
3455    // Extend the buffer with leading zeroes
3456    this._expand(bytesNeeded);
3457
3458    if (bitsLeft > 0) {
3459      bytesNeeded--;
3460    }
3461
3462    // Handle complete words
3463    for (var i = 0; i < bytesNeeded; i++) {
3464      this.words[i] = ~this.words[i] & 0x3ffffff;
3465    }
3466
3467    // Handle the residue
3468    if (bitsLeft > 0) {
3469      this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
3470    }
3471
3472    // And remove leading zeroes
3473    return this.strip();
3474  };
3475
3476  BN.prototype.notn = function notn (width) {
3477    return this.clone().inotn(width);
3478  };
3479
3480  // Set `bit` of `this`
3481  BN.prototype.setn = function setn (bit, val) {
3482    assert(typeof bit === 'number' && bit >= 0);
3483
3484    var off = (bit / 26) | 0;
3485    var wbit = bit % 26;
3486
3487    this._expand(off + 1);
3488
3489    if (val) {
3490      this.words[off] = this.words[off] | (1 << wbit);
3491    } else {
3492      this.words[off] = this.words[off] & ~(1 << wbit);
3493    }
3494
3495    return this.strip();
3496  };
3497
3498  // Add `num` to `this` in-place
3499  BN.prototype.iadd = function iadd (num) {
3500    var r;
3501
3502    // negative + positive
3503    if (this.negative !== 0 && num.negative === 0) {
3504      this.negative = 0;
3505      r = this.isub(num);
3506      this.negative ^= 1;
3507      return this._normSign();
3508
3509    // positive + negative
3510    } else if (this.negative === 0 && num.negative !== 0) {
3511      num.negative = 0;
3512      r = this.isub(num);
3513      num.negative = 1;
3514      return r._normSign();
3515    }
3516
3517    // a.length > b.length
3518    var a, b;
3519    if (this.length > num.length) {
3520      a = this;
3521      b = num;
3522    } else {
3523      a = num;
3524      b = this;
3525    }
3526
3527    var carry = 0;
3528    for (var i = 0; i < b.length; i++) {
3529      r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
3530      this.words[i] = r & 0x3ffffff;
3531      carry = r >>> 26;
3532    }
3533    for (; carry !== 0 && i < a.length; i++) {
3534      r = (a.words[i] | 0) + carry;
3535      this.words[i] = r & 0x3ffffff;
3536      carry = r >>> 26;
3537    }
3538
3539    this.length = a.length;
3540    if (carry !== 0) {
3541      this.words[this.length] = carry;
3542      this.length++;
3543    // Copy the rest of the words
3544    } else if (a !== this) {
3545      for (; i < a.length; i++) {
3546        this.words[i] = a.words[i];
3547      }
3548    }
3549
3550    return this;
3551  };
3552
3553  // Add `num` to `this`
3554  BN.prototype.add = function add (num) {
3555    var res;
3556    if (num.negative !== 0 && this.negative === 0) {
3557      num.negative = 0;
3558      res = this.sub(num);
3559      num.negative ^= 1;
3560      return res;
3561    } else if (num.negative === 0 && this.negative !== 0) {
3562      this.negative = 0;
3563      res = num.sub(this);
3564      this.negative = 1;
3565      return res;
3566    }
3567
3568    if (this.length > num.length) return this.clone().iadd(num);
3569
3570    return num.clone().iadd(this);
3571  };
3572
3573  // Subtract `num` from `this` in-place
3574  BN.prototype.isub = function isub (num) {
3575    // this - (-num) = this + num
3576    if (num.negative !== 0) {
3577      num.negative = 0;
3578      var r = this.iadd(num);
3579      num.negative = 1;
3580      return r._normSign();
3581
3582    // -this - num = -(this + num)
3583    } else if (this.negative !== 0) {
3584      this.negative = 0;
3585      this.iadd(num);
3586      this.negative = 1;
3587      return this._normSign();
3588    }
3589
3590    // At this point both numbers are positive
3591    var cmp = this.cmp(num);
3592
3593    // Optimization - zeroify
3594    if (cmp === 0) {
3595      this.negative = 0;
3596      this.length = 1;
3597      this.words[0] = 0;
3598      return this;
3599    }
3600
3601    // a > b
3602    var a, b;
3603    if (cmp > 0) {
3604      a = this;
3605      b = num;
3606    } else {
3607      a = num;
3608      b = this;
3609    }
3610
3611    var carry = 0;
3612    for (var i = 0; i < b.length; i++) {
3613      r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
3614      carry = r >> 26;
3615      this.words[i] = r & 0x3ffffff;
3616    }
3617    for (; carry !== 0 && i < a.length; i++) {
3618      r = (a.words[i] | 0) + carry;
3619      carry = r >> 26;
3620      this.words[i] = r & 0x3ffffff;
3621    }
3622
3623    // Copy rest of the words
3624    if (carry === 0 && i < a.length && a !== this) {
3625      for (; i < a.length; i++) {
3626        this.words[i] = a.words[i];
3627      }
3628    }
3629
3630    this.length = Math.max(this.length, i);
3631
3632    if (a !== this) {
3633      this.negative = 1;
3634    }
3635
3636    return this.strip();
3637  };
3638
3639  // Subtract `num` from `this`
3640  BN.prototype.sub = function sub (num) {
3641    return this.clone().isub(num);
3642  };
3643
3644  function smallMulTo (self, num, out) {
3645    out.negative = num.negative ^ self.negative;
3646    var len = (self.length + num.length) | 0;
3647    out.length = len;
3648    len = (len - 1) | 0;
3649
3650    // Peel one iteration (compiler can't do it, because of code complexity)
3651    var a = self.words[0] | 0;
3652    var b = num.words[0] | 0;
3653    var r = a * b;
3654
3655    var lo = r & 0x3ffffff;
3656    var carry = (r / 0x4000000) | 0;
3657    out.words[0] = lo;
3658
3659    for (var k = 1; k < len; k++) {
3660      // Sum all words with the same `i + j = k` and accumulate `ncarry`,
3661      // note that ncarry could be >= 0x3ffffff
3662      var ncarry = carry >>> 26;
3663      var rword = carry & 0x3ffffff;
3664      var maxJ = Math.min(k, num.length - 1);
3665      for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
3666        var i = (k - j) | 0;
3667        a = self.words[i] | 0;
3668        b = num.words[j] | 0;
3669        r = a * b + rword;
3670        ncarry += (r / 0x4000000) | 0;
3671        rword = r & 0x3ffffff;
3672      }
3673      out.words[k] = rword | 0;
3674      carry = ncarry | 0;
3675    }
3676    if (carry !== 0) {
3677      out.words[k] = carry | 0;
3678    } else {
3679      out.length--;
3680    }
3681
3682    return out.strip();
3683  }
3684
3685  // TODO(indutny): it may be reasonable to omit it for users who don't need
3686  // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
3687  // multiplication (like elliptic secp256k1).
3688  var comb10MulTo = function comb10MulTo (self, num, out) {
3689    var a = self.words;
3690    var b = num.words;
3691    var o = out.words;
3692    var c = 0;
3693    var lo;
3694    var mid;
3695    var hi;
3696    var a0 = a[0] | 0;
3697    var al0 = a0 & 0x1fff;
3698    var ah0 = a0 >>> 13;
3699    var a1 = a[1] | 0;
3700    var al1 = a1 & 0x1fff;
3701    var ah1 = a1 >>> 13;
3702    var a2 = a[2] | 0;
3703    var al2 = a2 & 0x1fff;
3704    var ah2 = a2 >>> 13;
3705    var a3 = a[3] | 0;
3706    var al3 = a3 & 0x1fff;
3707    var ah3 = a3 >>> 13;
3708    var a4 = a[4] | 0;
3709    var al4 = a4 & 0x1fff;
3710    var ah4 = a4 >>> 13;
3711    var a5 = a[5] | 0;
3712    var al5 = a5 & 0x1fff;
3713    var ah5 = a5 >>> 13;
3714    var a6 = a[6] | 0;
3715    var al6 = a6 & 0x1fff;
3716    var ah6 = a6 >>> 13;
3717    var a7 = a[7] | 0;
3718    var al7 = a7 & 0x1fff;
3719    var ah7 = a7 >>> 13;
3720    var a8 = a[8] | 0;
3721    var al8 = a8 & 0x1fff;
3722    var ah8 = a8 >>> 13;
3723    var a9 = a[9] | 0;
3724    var al9 = a9 & 0x1fff;
3725    var ah9 = a9 >>> 13;
3726    var b0 = b[0] | 0;
3727    var bl0 = b0 & 0x1fff;
3728    var bh0 = b0 >>> 13;
3729    var b1 = b[1] | 0;
3730    var bl1 = b1 & 0x1fff;
3731    var bh1 = b1 >>> 13;
3732    var b2 = b[2] | 0;
3733    var bl2 = b2 & 0x1fff;
3734    var bh2 = b2 >>> 13;
3735    var b3 = b[3] | 0;
3736    var bl3 = b3 & 0x1fff;
3737    var bh3 = b3 >>> 13;
3738    var b4 = b[4] | 0;
3739    var bl4 = b4 & 0x1fff;
3740    var bh4 = b4 >>> 13;
3741    var b5 = b[5] | 0;
3742    var bl5 = b5 & 0x1fff;
3743    var bh5 = b5 >>> 13;
3744    var b6 = b[6] | 0;
3745    var bl6 = b6 & 0x1fff;
3746    var bh6 = b6 >>> 13;
3747    var b7 = b[7] | 0;
3748    var bl7 = b7 & 0x1fff;
3749    var bh7 = b7 >>> 13;
3750    var b8 = b[8] | 0;
3751    var bl8 = b8 & 0x1fff;
3752    var bh8 = b8 >>> 13;
3753    var b9 = b[9] | 0;
3754    var bl9 = b9 & 0x1fff;
3755    var bh9 = b9 >>> 13;
3756
3757    out.negative = self.negative ^ num.negative;
3758    out.length = 19;
3759    /* k = 0 */
3760    lo = Math.imul(al0, bl0);
3761    mid = Math.imul(al0, bh0);
3762    mid = (mid + Math.imul(ah0, bl0)) | 0;
3763    hi = Math.imul(ah0, bh0);
3764    var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3765    c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
3766    w0 &= 0x3ffffff;
3767    /* k = 1 */
3768    lo = Math.imul(al1, bl0);
3769    mid = Math.imul(al1, bh0);
3770    mid = (mid + Math.imul(ah1, bl0)) | 0;
3771    hi = Math.imul(ah1, bh0);
3772    lo = (lo + Math.imul(al0, bl1)) | 0;
3773    mid = (mid + Math.imul(al0, bh1)) | 0;
3774    mid = (mid + Math.imul(ah0, bl1)) | 0;
3775    hi = (hi + Math.imul(ah0, bh1)) | 0;
3776    var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3777    c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
3778    w1 &= 0x3ffffff;
3779    /* k = 2 */
3780    lo = Math.imul(al2, bl0);
3781    mid = Math.imul(al2, bh0);
3782    mid = (mid + Math.imul(ah2, bl0)) | 0;
3783    hi = Math.imul(ah2, bh0);
3784    lo = (lo + Math.imul(al1, bl1)) | 0;
3785    mid = (mid + Math.imul(al1, bh1)) | 0;
3786    mid = (mid + Math.imul(ah1, bl1)) | 0;
3787    hi = (hi + Math.imul(ah1, bh1)) | 0;
3788    lo = (lo + Math.imul(al0, bl2)) | 0;
3789    mid = (mid + Math.imul(al0, bh2)) | 0;
3790    mid = (mid + Math.imul(ah0, bl2)) | 0;
3791    hi = (hi + Math.imul(ah0, bh2)) | 0;
3792    var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3793    c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
3794    w2 &= 0x3ffffff;
3795    /* k = 3 */
3796    lo = Math.imul(al3, bl0);
3797    mid = Math.imul(al3, bh0);
3798    mid = (mid + Math.imul(ah3, bl0)) | 0;
3799    hi = Math.imul(ah3, bh0);
3800    lo = (lo + Math.imul(al2, bl1)) | 0;
3801    mid = (mid + Math.imul(al2, bh1)) | 0;
3802    mid = (mid + Math.imul(ah2, bl1)) | 0;
3803    hi = (hi + Math.imul(ah2, bh1)) | 0;
3804    lo = (lo + Math.imul(al1, bl2)) | 0;
3805    mid = (mid + Math.imul(al1, bh2)) | 0;
3806    mid = (mid + Math.imul(ah1, bl2)) | 0;
3807    hi = (hi + Math.imul(ah1, bh2)) | 0;
3808    lo = (lo + Math.imul(al0, bl3)) | 0;
3809    mid = (mid + Math.imul(al0, bh3)) | 0;
3810    mid = (mid + Math.imul(ah0, bl3)) | 0;
3811    hi = (hi + Math.imul(ah0, bh3)) | 0;
3812    var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3813    c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
3814    w3 &= 0x3ffffff;
3815    /* k = 4 */
3816    lo = Math.imul(al4, bl0);
3817    mid = Math.imul(al4, bh0);
3818    mid = (mid + Math.imul(ah4, bl0)) | 0;
3819    hi = Math.imul(ah4, bh0);
3820    lo = (lo + Math.imul(al3, bl1)) | 0;
3821    mid = (mid + Math.imul(al3, bh1)) | 0;
3822    mid = (mid + Math.imul(ah3, bl1)) | 0;
3823    hi = (hi + Math.imul(ah3, bh1)) | 0;
3824    lo = (lo + Math.imul(al2, bl2)) | 0;
3825    mid = (mid + Math.imul(al2, bh2)) | 0;
3826    mid = (mid + Math.imul(ah2, bl2)) | 0;
3827    hi = (hi + Math.imul(ah2, bh2)) | 0;
3828    lo = (lo + Math.imul(al1, bl3)) | 0;
3829    mid = (mid + Math.imul(al1, bh3)) | 0;
3830    mid = (mid + Math.imul(ah1, bl3)) | 0;
3831    hi = (hi + Math.imul(ah1, bh3)) | 0;
3832    lo = (lo + Math.imul(al0, bl4)) | 0;
3833    mid = (mid + Math.imul(al0, bh4)) | 0;
3834    mid = (mid + Math.imul(ah0, bl4)) | 0;
3835    hi = (hi + Math.imul(ah0, bh4)) | 0;
3836    var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3837    c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
3838    w4 &= 0x3ffffff;
3839    /* k = 5 */
3840    lo = Math.imul(al5, bl0);
3841    mid = Math.imul(al5, bh0);
3842    mid = (mid + Math.imul(ah5, bl0)) | 0;
3843    hi = Math.imul(ah5, bh0);
3844    lo = (lo + Math.imul(al4, bl1)) | 0;
3845    mid = (mid + Math.imul(al4, bh1)) | 0;
3846    mid = (mid + Math.imul(ah4, bl1)) | 0;
3847    hi = (hi + Math.imul(ah4, bh1)) | 0;
3848    lo = (lo + Math.imul(al3, bl2)) | 0;
3849    mid = (mid + Math.imul(al3, bh2)) | 0;
3850    mid = (mid + Math.imul(ah3, bl2)) | 0;
3851    hi = (hi + Math.imul(ah3, bh2)) | 0;
3852    lo = (lo + Math.imul(al2, bl3)) | 0;
3853    mid = (mid + Math.imul(al2, bh3)) | 0;
3854    mid = (mid + Math.imul(ah2, bl3)) | 0;
3855    hi = (hi + Math.imul(ah2, bh3)) | 0;
3856    lo = (lo + Math.imul(al1, bl4)) | 0;
3857    mid = (mid + Math.imul(al1, bh4)) | 0;
3858    mid = (mid + Math.imul(ah1, bl4)) | 0;
3859    hi = (hi + Math.imul(ah1, bh4)) | 0;
3860    lo = (lo + Math.imul(al0, bl5)) | 0;
3861    mid = (mid + Math.imul(al0, bh5)) | 0;
3862    mid = (mid + Math.imul(ah0, bl5)) | 0;
3863    hi = (hi + Math.imul(ah0, bh5)) | 0;
3864    var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3865    c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
3866    w5 &= 0x3ffffff;
3867    /* k = 6 */
3868    lo = Math.imul(al6, bl0);
3869    mid = Math.imul(al6, bh0);
3870    mid = (mid + Math.imul(ah6, bl0)) | 0;
3871    hi = Math.imul(ah6, bh0);
3872    lo = (lo + Math.imul(al5, bl1)) | 0;
3873    mid = (mid + Math.imul(al5, bh1)) | 0;
3874    mid = (mid + Math.imul(ah5, bl1)) | 0;
3875    hi = (hi + Math.imul(ah5, bh1)) | 0;
3876    lo = (lo + Math.imul(al4, bl2)) | 0;
3877    mid = (mid + Math.imul(al4, bh2)) | 0;
3878    mid = (mid + Math.imul(ah4, bl2)) | 0;
3879    hi = (hi + Math.imul(ah4, bh2)) | 0;
3880    lo = (lo + Math.imul(al3, bl3)) | 0;
3881    mid = (mid + Math.imul(al3, bh3)) | 0;
3882    mid = (mid + Math.imul(ah3, bl3)) | 0;
3883    hi = (hi + Math.imul(ah3, bh3)) | 0;
3884    lo = (lo + Math.imul(al2, bl4)) | 0;
3885    mid = (mid + Math.imul(al2, bh4)) | 0;
3886    mid = (mid + Math.imul(ah2, bl4)) | 0;
3887    hi = (hi + Math.imul(ah2, bh4)) | 0;
3888    lo = (lo + Math.imul(al1, bl5)) | 0;
3889    mid = (mid + Math.imul(al1, bh5)) | 0;
3890    mid = (mid + Math.imul(ah1, bl5)) | 0;
3891    hi = (hi + Math.imul(ah1, bh5)) | 0;
3892    lo = (lo + Math.imul(al0, bl6)) | 0;
3893    mid = (mid + Math.imul(al0, bh6)) | 0;
3894    mid = (mid + Math.imul(ah0, bl6)) | 0;
3895    hi = (hi + Math.imul(ah0, bh6)) | 0;
3896    var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3897    c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
3898    w6 &= 0x3ffffff;
3899    /* k = 7 */
3900    lo = Math.imul(al7, bl0);
3901    mid = Math.imul(al7, bh0);
3902    mid = (mid + Math.imul(ah7, bl0)) | 0;
3903    hi = Math.imul(ah7, bh0);
3904    lo = (lo + Math.imul(al6, bl1)) | 0;
3905    mid = (mid + Math.imul(al6, bh1)) | 0;
3906    mid = (mid + Math.imul(ah6, bl1)) | 0;
3907    hi = (hi + Math.imul(ah6, bh1)) | 0;
3908    lo = (lo + Math.imul(al5, bl2)) | 0;
3909    mid = (mid + Math.imul(al5, bh2)) | 0;
3910    mid = (mid + Math.imul(ah5, bl2)) | 0;
3911    hi = (hi + Math.imul(ah5, bh2)) | 0;
3912    lo = (lo + Math.imul(al4, bl3)) | 0;
3913    mid = (mid + Math.imul(al4, bh3)) | 0;
3914    mid = (mid + Math.imul(ah4, bl3)) | 0;
3915    hi = (hi + Math.imul(ah4, bh3)) | 0;
3916    lo = (lo + Math.imul(al3, bl4)) | 0;
3917    mid = (mid + Math.imul(al3, bh4)) | 0;
3918    mid = (mid + Math.imul(ah3, bl4)) | 0;
3919    hi = (hi + Math.imul(ah3, bh4)) | 0;
3920    lo = (lo + Math.imul(al2, bl5)) | 0;
3921    mid = (mid + Math.imul(al2, bh5)) | 0;
3922    mid = (mid + Math.imul(ah2, bl5)) | 0;
3923    hi = (hi + Math.imul(ah2, bh5)) | 0;
3924    lo = (lo + Math.imul(al1, bl6)) | 0;
3925    mid = (mid + Math.imul(al1, bh6)) | 0;
3926    mid = (mid + Math.imul(ah1, bl6)) | 0;
3927    hi = (hi + Math.imul(ah1, bh6)) | 0;
3928    lo = (lo + Math.imul(al0, bl7)) | 0;
3929    mid = (mid + Math.imul(al0, bh7)) | 0;
3930    mid = (mid + Math.imul(ah0, bl7)) | 0;
3931    hi = (hi + Math.imul(ah0, bh7)) | 0;
3932    var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3933    c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
3934    w7 &= 0x3ffffff;
3935    /* k = 8 */
3936    lo = Math.imul(al8, bl0);
3937    mid = Math.imul(al8, bh0);
3938    mid = (mid + Math.imul(ah8, bl0)) | 0;
3939    hi = Math.imul(ah8, bh0);
3940    lo = (lo + Math.imul(al7, bl1)) | 0;
3941    mid = (mid + Math.imul(al7, bh1)) | 0;
3942    mid = (mid + Math.imul(ah7, bl1)) | 0;
3943    hi = (hi + Math.imul(ah7, bh1)) | 0;
3944    lo = (lo + Math.imul(al6, bl2)) | 0;
3945    mid = (mid + Math.imul(al6, bh2)) | 0;
3946    mid = (mid + Math.imul(ah6, bl2)) | 0;
3947    hi = (hi + Math.imul(ah6, bh2)) | 0;
3948    lo = (lo + Math.imul(al5, bl3)) | 0;
3949    mid = (mid + Math.imul(al5, bh3)) | 0;
3950    mid = (mid + Math.imul(ah5, bl3)) | 0;
3951    hi = (hi + Math.imul(ah5, bh3)) | 0;
3952    lo = (lo + Math.imul(al4, bl4)) | 0;
3953    mid = (mid + Math.imul(al4, bh4)) | 0;
3954    mid = (mid + Math.imul(ah4, bl4)) | 0;
3955    hi = (hi + Math.imul(ah4, bh4)) | 0;
3956    lo = (lo + Math.imul(al3, bl5)) | 0;
3957    mid = (mid + Math.imul(al3, bh5)) | 0;
3958    mid = (mid + Math.imul(ah3, bl5)) | 0;
3959    hi = (hi + Math.imul(ah3, bh5)) | 0;
3960    lo = (lo + Math.imul(al2, bl6)) | 0;
3961    mid = (mid + Math.imul(al2, bh6)) | 0;
3962    mid = (mid + Math.imul(ah2, bl6)) | 0;
3963    hi = (hi + Math.imul(ah2, bh6)) | 0;
3964    lo = (lo + Math.imul(al1, bl7)) | 0;
3965    mid = (mid + Math.imul(al1, bh7)) | 0;
3966    mid = (mid + Math.imul(ah1, bl7)) | 0;
3967    hi = (hi + Math.imul(ah1, bh7)) | 0;
3968    lo = (lo + Math.imul(al0, bl8)) | 0;
3969    mid = (mid + Math.imul(al0, bh8)) | 0;
3970    mid = (mid + Math.imul(ah0, bl8)) | 0;
3971    hi = (hi + Math.imul(ah0, bh8)) | 0;
3972    var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
3973    c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
3974    w8 &= 0x3ffffff;
3975    /* k = 9 */
3976    lo = Math.imul(al9, bl0);
3977    mid = Math.imul(al9, bh0);
3978    mid = (mid + Math.imul(ah9, bl0)) | 0;
3979    hi = Math.imul(ah9, bh0);
3980    lo = (lo + Math.imul(al8, bl1)) | 0;
3981    mid = (mid + Math.imul(al8, bh1)) | 0;
3982    mid = (mid + Math.imul(ah8, bl1)) | 0;
3983    hi = (hi + Math.imul(ah8, bh1)) | 0;
3984    lo = (lo + Math.imul(al7, bl2)) | 0;
3985    mid = (mid + Math.imul(al7, bh2)) | 0;
3986    mid = (mid + Math.imul(ah7, bl2)) | 0;
3987    hi = (hi + Math.imul(ah7, bh2)) | 0;
3988    lo = (lo + Math.imul(al6, bl3)) | 0;
3989    mid = (mid + Math.imul(al6, bh3)) | 0;
3990    mid = (mid + Math.imul(ah6, bl3)) | 0;
3991    hi = (hi + Math.imul(ah6, bh3)) | 0;
3992    lo = (lo + Math.imul(al5, bl4)) | 0;
3993    mid = (mid + Math.imul(al5, bh4)) | 0;
3994    mid = (mid + Math.imul(ah5, bl4)) | 0;
3995    hi = (hi + Math.imul(ah5, bh4)) | 0;
3996    lo = (lo + Math.imul(al4, bl5)) | 0;
3997    mid = (mid + Math.imul(al4, bh5)) | 0;
3998    mid = (mid + Math.imul(ah4, bl5)) | 0;
3999    hi = (hi + Math.imul(ah4, bh5)) | 0;
4000    lo = (lo + Math.imul(al3, bl6)) | 0;
4001    mid = (mid + Math.imul(al3, bh6)) | 0;
4002    mid = (mid + Math.imul(ah3, bl6)) | 0;
4003    hi = (hi + Math.imul(ah3, bh6)) | 0;
4004    lo = (lo + Math.imul(al2, bl7)) | 0;
4005    mid = (mid + Math.imul(al2, bh7)) | 0;
4006    mid = (mid + Math.imul(ah2, bl7)) | 0;
4007    hi = (hi + Math.imul(ah2, bh7)) | 0;
4008    lo = (lo + Math.imul(al1, bl8)) | 0;
4009    mid = (mid + Math.imul(al1, bh8)) | 0;
4010    mid = (mid + Math.imul(ah1, bl8)) | 0;
4011    hi = (hi + Math.imul(ah1, bh8)) | 0;
4012    lo = (lo + Math.imul(al0, bl9)) | 0;
4013    mid = (mid + Math.imul(al0, bh9)) | 0;
4014    mid = (mid + Math.imul(ah0, bl9)) | 0;
4015    hi = (hi + Math.imul(ah0, bh9)) | 0;
4016    var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4017    c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
4018    w9 &= 0x3ffffff;
4019    /* k = 10 */
4020    lo = Math.imul(al9, bl1);
4021    mid = Math.imul(al9, bh1);
4022    mid = (mid + Math.imul(ah9, bl1)) | 0;
4023    hi = Math.imul(ah9, bh1);
4024    lo = (lo + Math.imul(al8, bl2)) | 0;
4025    mid = (mid + Math.imul(al8, bh2)) | 0;
4026    mid = (mid + Math.imul(ah8, bl2)) | 0;
4027    hi = (hi + Math.imul(ah8, bh2)) | 0;
4028    lo = (lo + Math.imul(al7, bl3)) | 0;
4029    mid = (mid + Math.imul(al7, bh3)) | 0;
4030    mid = (mid + Math.imul(ah7, bl3)) | 0;
4031    hi = (hi + Math.imul(ah7, bh3)) | 0;
4032    lo = (lo + Math.imul(al6, bl4)) | 0;
4033    mid = (mid + Math.imul(al6, bh4)) | 0;
4034    mid = (mid + Math.imul(ah6, bl4)) | 0;
4035    hi = (hi + Math.imul(ah6, bh4)) | 0;
4036    lo = (lo + Math.imul(al5, bl5)) | 0;
4037    mid = (mid + Math.imul(al5, bh5)) | 0;
4038    mid = (mid + Math.imul(ah5, bl5)) | 0;
4039    hi = (hi + Math.imul(ah5, bh5)) | 0;
4040    lo = (lo + Math.imul(al4, bl6)) | 0;
4041    mid = (mid + Math.imul(al4, bh6)) | 0;
4042    mid = (mid + Math.imul(ah4, bl6)) | 0;
4043    hi = (hi + Math.imul(ah4, bh6)) | 0;
4044    lo = (lo + Math.imul(al3, bl7)) | 0;
4045    mid = (mid + Math.imul(al3, bh7)) | 0;
4046    mid = (mid + Math.imul(ah3, bl7)) | 0;
4047    hi = (hi + Math.imul(ah3, bh7)) | 0;
4048    lo = (lo + Math.imul(al2, bl8)) | 0;
4049    mid = (mid + Math.imul(al2, bh8)) | 0;
4050    mid = (mid + Math.imul(ah2, bl8)) | 0;
4051    hi = (hi + Math.imul(ah2, bh8)) | 0;
4052    lo = (lo + Math.imul(al1, bl9)) | 0;
4053    mid = (mid + Math.imul(al1, bh9)) | 0;
4054    mid = (mid + Math.imul(ah1, bl9)) | 0;
4055    hi = (hi + Math.imul(ah1, bh9)) | 0;
4056    var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4057    c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
4058    w10 &= 0x3ffffff;
4059    /* k = 11 */
4060    lo = Math.imul(al9, bl2);
4061    mid = Math.imul(al9, bh2);
4062    mid = (mid + Math.imul(ah9, bl2)) | 0;
4063    hi = Math.imul(ah9, bh2);
4064    lo = (lo + Math.imul(al8, bl3)) | 0;
4065    mid = (mid + Math.imul(al8, bh3)) | 0;
4066    mid = (mid + Math.imul(ah8, bl3)) | 0;
4067    hi = (hi + Math.imul(ah8, bh3)) | 0;
4068    lo = (lo + Math.imul(al7, bl4)) | 0;
4069    mid = (mid + Math.imul(al7, bh4)) | 0;
4070    mid = (mid + Math.imul(ah7, bl4)) | 0;
4071    hi = (hi + Math.imul(ah7, bh4)) | 0;
4072    lo = (lo + Math.imul(al6, bl5)) | 0;
4073    mid = (mid + Math.imul(al6, bh5)) | 0;
4074    mid = (mid + Math.imul(ah6, bl5)) | 0;
4075    hi = (hi + Math.imul(ah6, bh5)) | 0;
4076    lo = (lo + Math.imul(al5, bl6)) | 0;
4077    mid = (mid + Math.imul(al5, bh6)) | 0;
4078    mid = (mid + Math.imul(ah5, bl6)) | 0;
4079    hi = (hi + Math.imul(ah5, bh6)) | 0;
4080    lo = (lo + Math.imul(al4, bl7)) | 0;
4081    mid = (mid + Math.imul(al4, bh7)) | 0;
4082    mid = (mid + Math.imul(ah4, bl7)) | 0;
4083    hi = (hi + Math.imul(ah4, bh7)) | 0;
4084    lo = (lo + Math.imul(al3, bl8)) | 0;
4085    mid = (mid + Math.imul(al3, bh8)) | 0;
4086    mid = (mid + Math.imul(ah3, bl8)) | 0;
4087    hi = (hi + Math.imul(ah3, bh8)) | 0;
4088    lo = (lo + Math.imul(al2, bl9)) | 0;
4089    mid = (mid + Math.imul(al2, bh9)) | 0;
4090    mid = (mid + Math.imul(ah2, bl9)) | 0;
4091    hi = (hi + Math.imul(ah2, bh9)) | 0;
4092    var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4093    c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
4094    w11 &= 0x3ffffff;
4095    /* k = 12 */
4096    lo = Math.imul(al9, bl3);
4097    mid = Math.imul(al9, bh3);
4098    mid = (mid + Math.imul(ah9, bl3)) | 0;
4099    hi = Math.imul(ah9, bh3);
4100    lo = (lo + Math.imul(al8, bl4)) | 0;
4101    mid = (mid + Math.imul(al8, bh4)) | 0;
4102    mid = (mid + Math.imul(ah8, bl4)) | 0;
4103    hi = (hi + Math.imul(ah8, bh4)) | 0;
4104    lo = (lo + Math.imul(al7, bl5)) | 0;
4105    mid = (mid + Math.imul(al7, bh5)) | 0;
4106    mid = (mid + Math.imul(ah7, bl5)) | 0;
4107    hi = (hi + Math.imul(ah7, bh5)) | 0;
4108    lo = (lo + Math.imul(al6, bl6)) | 0;
4109    mid = (mid + Math.imul(al6, bh6)) | 0;
4110    mid = (mid + Math.imul(ah6, bl6)) | 0;
4111    hi = (hi + Math.imul(ah6, bh6)) | 0;
4112    lo = (lo + Math.imul(al5, bl7)) | 0;
4113    mid = (mid + Math.imul(al5, bh7)) | 0;
4114    mid = (mid + Math.imul(ah5, bl7)) | 0;
4115    hi = (hi + Math.imul(ah5, bh7)) | 0;
4116    lo = (lo + Math.imul(al4, bl8)) | 0;
4117    mid = (mid + Math.imul(al4, bh8)) | 0;
4118    mid = (mid + Math.imul(ah4, bl8)) | 0;
4119    hi = (hi + Math.imul(ah4, bh8)) | 0;
4120    lo = (lo + Math.imul(al3, bl9)) | 0;
4121    mid = (mid + Math.imul(al3, bh9)) | 0;
4122    mid = (mid + Math.imul(ah3, bl9)) | 0;
4123    hi = (hi + Math.imul(ah3, bh9)) | 0;
4124    var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4125    c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
4126    w12 &= 0x3ffffff;
4127    /* k = 13 */
4128    lo = Math.imul(al9, bl4);
4129    mid = Math.imul(al9, bh4);
4130    mid = (mid + Math.imul(ah9, bl4)) | 0;
4131    hi = Math.imul(ah9, bh4);
4132    lo = (lo + Math.imul(al8, bl5)) | 0;
4133    mid = (mid + Math.imul(al8, bh5)) | 0;
4134    mid = (mid + Math.imul(ah8, bl5)) | 0;
4135    hi = (hi + Math.imul(ah8, bh5)) | 0;
4136    lo = (lo + Math.imul(al7, bl6)) | 0;
4137    mid = (mid + Math.imul(al7, bh6)) | 0;
4138    mid = (mid + Math.imul(ah7, bl6)) | 0;
4139    hi = (hi + Math.imul(ah7, bh6)) | 0;
4140    lo = (lo + Math.imul(al6, bl7)) | 0;
4141    mid = (mid + Math.imul(al6, bh7)) | 0;
4142    mid = (mid + Math.imul(ah6, bl7)) | 0;
4143    hi = (hi + Math.imul(ah6, bh7)) | 0;
4144    lo = (lo + Math.imul(al5, bl8)) | 0;
4145    mid = (mid + Math.imul(al5, bh8)) | 0;
4146    mid = (mid + Math.imul(ah5, bl8)) | 0;
4147    hi = (hi + Math.imul(ah5, bh8)) | 0;
4148    lo = (lo + Math.imul(al4, bl9)) | 0;
4149    mid = (mid + Math.imul(al4, bh9)) | 0;
4150    mid = (mid + Math.imul(ah4, bl9)) | 0;
4151    hi = (hi + Math.imul(ah4, bh9)) | 0;
4152    var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4153    c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
4154    w13 &= 0x3ffffff;
4155    /* k = 14 */
4156    lo = Math.imul(al9, bl5);
4157    mid = Math.imul(al9, bh5);
4158    mid = (mid + Math.imul(ah9, bl5)) | 0;
4159    hi = Math.imul(ah9, bh5);
4160    lo = (lo + Math.imul(al8, bl6)) | 0;
4161    mid = (mid + Math.imul(al8, bh6)) | 0;
4162    mid = (mid + Math.imul(ah8, bl6)) | 0;
4163    hi = (hi + Math.imul(ah8, bh6)) | 0;
4164    lo = (lo + Math.imul(al7, bl7)) | 0;
4165    mid = (mid + Math.imul(al7, bh7)) | 0;
4166    mid = (mid + Math.imul(ah7, bl7)) | 0;
4167    hi = (hi + Math.imul(ah7, bh7)) | 0;
4168    lo = (lo + Math.imul(al6, bl8)) | 0;
4169    mid = (mid + Math.imul(al6, bh8)) | 0;
4170    mid = (mid + Math.imul(ah6, bl8)) | 0;
4171    hi = (hi + Math.imul(ah6, bh8)) | 0;
4172    lo = (lo + Math.imul(al5, bl9)) | 0;
4173    mid = (mid + Math.imul(al5, bh9)) | 0;
4174    mid = (mid + Math.imul(ah5, bl9)) | 0;
4175    hi = (hi + Math.imul(ah5, bh9)) | 0;
4176    var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4177    c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
4178    w14 &= 0x3ffffff;
4179    /* k = 15 */
4180    lo = Math.imul(al9, bl6);
4181    mid = Math.imul(al9, bh6);
4182    mid = (mid + Math.imul(ah9, bl6)) | 0;
4183    hi = Math.imul(ah9, bh6);
4184    lo = (lo + Math.imul(al8, bl7)) | 0;
4185    mid = (mid + Math.imul(al8, bh7)) | 0;
4186    mid = (mid + Math.imul(ah8, bl7)) | 0;
4187    hi = (hi + Math.imul(ah8, bh7)) | 0;
4188    lo = (lo + Math.imul(al7, bl8)) | 0;
4189    mid = (mid + Math.imul(al7, bh8)) | 0;
4190    mid = (mid + Math.imul(ah7, bl8)) | 0;
4191    hi = (hi + Math.imul(ah7, bh8)) | 0;
4192    lo = (lo + Math.imul(al6, bl9)) | 0;
4193    mid = (mid + Math.imul(al6, bh9)) | 0;
4194    mid = (mid + Math.imul(ah6, bl9)) | 0;
4195    hi = (hi + Math.imul(ah6, bh9)) | 0;
4196    var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4197    c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
4198    w15 &= 0x3ffffff;
4199    /* k = 16 */
4200    lo = Math.imul(al9, bl7);
4201    mid = Math.imul(al9, bh7);
4202    mid = (mid + Math.imul(ah9, bl7)) | 0;
4203    hi = Math.imul(ah9, bh7);
4204    lo = (lo + Math.imul(al8, bl8)) | 0;
4205    mid = (mid + Math.imul(al8, bh8)) | 0;
4206    mid = (mid + Math.imul(ah8, bl8)) | 0;
4207    hi = (hi + Math.imul(ah8, bh8)) | 0;
4208    lo = (lo + Math.imul(al7, bl9)) | 0;
4209    mid = (mid + Math.imul(al7, bh9)) | 0;
4210    mid = (mid + Math.imul(ah7, bl9)) | 0;
4211    hi = (hi + Math.imul(ah7, bh9)) | 0;
4212    var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4213    c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
4214    w16 &= 0x3ffffff;
4215    /* k = 17 */
4216    lo = Math.imul(al9, bl8);
4217    mid = Math.imul(al9, bh8);
4218    mid = (mid + Math.imul(ah9, bl8)) | 0;
4219    hi = Math.imul(ah9, bh8);
4220    lo = (lo + Math.imul(al8, bl9)) | 0;
4221    mid = (mid + Math.imul(al8, bh9)) | 0;
4222    mid = (mid + Math.imul(ah8, bl9)) | 0;
4223    hi = (hi + Math.imul(ah8, bh9)) | 0;
4224    var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4225    c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
4226    w17 &= 0x3ffffff;
4227    /* k = 18 */
4228    lo = Math.imul(al9, bl9);
4229    mid = Math.imul(al9, bh9);
4230    mid = (mid + Math.imul(ah9, bl9)) | 0;
4231    hi = Math.imul(ah9, bh9);
4232    var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
4233    c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
4234    w18 &= 0x3ffffff;
4235    o[0] = w0;
4236    o[1] = w1;
4237    o[2] = w2;
4238    o[3] = w3;
4239    o[4] = w4;
4240    o[5] = w5;
4241    o[6] = w6;
4242    o[7] = w7;
4243    o[8] = w8;
4244    o[9] = w9;
4245    o[10] = w10;
4246    o[11] = w11;
4247    o[12] = w12;
4248    o[13] = w13;
4249    o[14] = w14;
4250    o[15] = w15;
4251    o[16] = w16;
4252    o[17] = w17;
4253    o[18] = w18;
4254    if (c !== 0) {
4255      o[19] = c;
4256      out.length++;
4257    }
4258    return out;
4259  };
4260
4261  // Polyfill comb
4262  if (!Math.imul) {
4263    comb10MulTo = smallMulTo;
4264  }
4265
4266  function bigMulTo (self, num, out) {
4267    out.negative = num.negative ^ self.negative;
4268    out.length = self.length + num.length;
4269
4270    var carry = 0;
4271    var hncarry = 0;
4272    for (var k = 0; k < out.length - 1; k++) {
4273      // Sum all words with the same `i + j = k` and accumulate `ncarry`,
4274      // note that ncarry could be >= 0x3ffffff
4275      var ncarry = hncarry;
4276      hncarry = 0;
4277      var rword = carry & 0x3ffffff;
4278      var maxJ = Math.min(k, num.length - 1);
4279      for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
4280        var i = k - j;
4281        var a = self.words[i] | 0;
4282        var b = num.words[j] | 0;
4283        var r = a * b;
4284
4285        var lo = r & 0x3ffffff;
4286        ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
4287        lo = (lo + rword) | 0;
4288        rword = lo & 0x3ffffff;
4289        ncarry = (ncarry + (lo >>> 26)) | 0;
4290
4291        hncarry += ncarry >>> 26;
4292        ncarry &= 0x3ffffff;
4293      }
4294      out.words[k] = rword;
4295      carry = ncarry;
4296      ncarry = hncarry;
4297    }
4298    if (carry !== 0) {
4299      out.words[k] = carry;
4300    } else {
4301      out.length--;
4302    }
4303
4304    return out.strip();
4305  }
4306
4307  function jumboMulTo (self, num, out) {
4308    var fftm = new FFTM();
4309    return fftm.mulp(self, num, out);
4310  }
4311
4312  BN.prototype.mulTo = function mulTo (num, out) {
4313    var res;
4314    var len = this.length + num.length;
4315    if (this.length === 10 && num.length === 10) {
4316      res = comb10MulTo(this, num, out);
4317    } else if (len < 63) {
4318      res = smallMulTo(this, num, out);
4319    } else if (len < 1024) {
4320      res = bigMulTo(this, num, out);
4321    } else {
4322      res = jumboMulTo(this, num, out);
4323    }
4324
4325    return res;
4326  };
4327
4328  // Cooley-Tukey algorithm for FFT
4329  // slightly revisited to rely on looping instead of recursion
4330
4331  function FFTM (x, y) {
4332    this.x = x;
4333    this.y = y;
4334  }
4335
4336  FFTM.prototype.makeRBT = function makeRBT (N) {
4337    var t = new Array(N);
4338    var l = BN.prototype._countBits(N) - 1;
4339    for (var i = 0; i < N; i++) {
4340      t[i] = this.revBin(i, l, N);
4341    }
4342
4343    return t;
4344  };
4345
4346  // Returns binary-reversed representation of `x`
4347  FFTM.prototype.revBin = function revBin (x, l, N) {
4348    if (x === 0 || x === N - 1) return x;
4349
4350    var rb = 0;
4351    for (var i = 0; i < l; i++) {
4352      rb |= (x & 1) << (l - i - 1);
4353      x >>= 1;
4354    }
4355
4356    return rb;
4357  };
4358
4359  // Performs "tweedling" phase, therefore 'emulating'
4360  // behaviour of the recursive algorithm
4361  FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
4362    for (var i = 0; i < N; i++) {
4363      rtws[i] = rws[rbt[i]];
4364      itws[i] = iws[rbt[i]];
4365    }
4366  };
4367
4368  FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
4369    this.permute(rbt, rws, iws, rtws, itws, N);
4370
4371    for (var s = 1; s < N; s <<= 1) {
4372      var l = s << 1;
4373
4374      var rtwdf = Math.cos(2 * Math.PI / l);
4375      var itwdf = Math.sin(2 * Math.PI / l);
4376
4377      for (var p = 0; p < N; p += l) {
4378        var rtwdf_ = rtwdf;
4379        var itwdf_ = itwdf;
4380
4381        for (var j = 0; j < s; j++) {
4382          var re = rtws[p + j];
4383          var ie = itws[p + j];
4384
4385          var ro = rtws[p + j + s];
4386          var io = itws[p + j + s];
4387
4388          var rx = rtwdf_ * ro - itwdf_ * io;
4389
4390          io = rtwdf_ * io + itwdf_ * ro;
4391          ro = rx;
4392
4393          rtws[p + j] = re + ro;
4394          itws[p + j] = ie + io;
4395
4396          rtws[p + j + s] = re - ro;
4397          itws[p + j + s] = ie - io;
4398
4399          /* jshint maxdepth : false */
4400          if (j !== l) {
4401            rx = rtwdf * rtwdf_ - itwdf * itwdf_;
4402
4403            itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
4404            rtwdf_ = rx;
4405          }
4406        }
4407      }
4408    }
4409  };
4410
4411  FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
4412    var N = Math.max(m, n) | 1;
4413    var odd = N & 1;
4414    var i = 0;
4415    for (N = N / 2 | 0; N; N = N >>> 1) {
4416      i++;
4417    }
4418
4419    return 1 << i + 1 + odd;
4420  };
4421
4422  FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
4423    if (N <= 1) return;
4424
4425    for (var i = 0; i < N / 2; i++) {
4426      var t = rws[i];
4427
4428      rws[i] = rws[N - i - 1];
4429      rws[N - i - 1] = t;
4430
4431      t = iws[i];
4432
4433      iws[i] = -iws[N - i - 1];
4434      iws[N - i - 1] = -t;
4435    }
4436  };
4437
4438  FFTM.prototype.normalize13b = function normalize13b (ws, N) {
4439    var carry = 0;
4440    for (var i = 0; i < N / 2; i++) {
4441      var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
4442        Math.round(ws[2 * i] / N) +
4443        carry;
4444
4445      ws[i] = w & 0x3ffffff;
4446
4447      if (w < 0x4000000) {
4448        carry = 0;
4449      } else {
4450        carry = w / 0x4000000 | 0;
4451      }
4452    }
4453
4454    return ws;
4455  };
4456
4457  FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
4458    var carry = 0;
4459    for (var i = 0; i < len; i++) {
4460      carry = carry + (ws[i] | 0);
4461
4462      rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
4463      rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
4464    }
4465
4466    // Pad with zeroes
4467    for (i = 2 * len; i < N; ++i) {
4468      rws[i] = 0;
4469    }
4470
4471    assert(carry === 0);
4472    assert((carry & ~0x1fff) === 0);
4473  };
4474
4475  FFTM.prototype.stub = function stub (N) {
4476    var ph = new Array(N);
4477    for (var i = 0; i < N; i++) {
4478      ph[i] = 0;
4479    }
4480
4481    return ph;
4482  };
4483
4484  FFTM.prototype.mulp = function mulp (x, y, out) {
4485    var N = 2 * this.guessLen13b(x.length, y.length);
4486
4487    var rbt = this.makeRBT(N);
4488
4489    var _ = this.stub(N);
4490
4491    var rws = new Array(N);
4492    var rwst = new Array(N);
4493    var iwst = new Array(N);
4494
4495    var nrws = new Array(N);
4496    var nrwst = new Array(N);
4497    var niwst = new Array(N);
4498
4499    var rmws = out.words;
4500    rmws.length = N;
4501
4502    this.convert13b(x.words, x.length, rws, N);
4503    this.convert13b(y.words, y.length, nrws, N);
4504
4505    this.transform(rws, _, rwst, iwst, N, rbt);
4506    this.transform(nrws, _, nrwst, niwst, N, rbt);
4507
4508    for (var i = 0; i < N; i++) {
4509      var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
4510      iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
4511      rwst[i] = rx;
4512    }
4513
4514    this.conjugate(rwst, iwst, N);
4515    this.transform(rwst, iwst, rmws, _, N, rbt);
4516    this.conjugate(rmws, _, N);
4517    this.normalize13b(rmws, N);
4518
4519    out.negative = x.negative ^ y.negative;
4520    out.length = x.length + y.length;
4521    return out.strip();
4522  };
4523
4524  // Multiply `this` by `num`
4525  BN.prototype.mul = function mul (num) {
4526    var out = new BN(null);
4527    out.words = new Array(this.length + num.length);
4528    return this.mulTo(num, out);
4529  };
4530
4531  // Multiply employing FFT
4532  BN.prototype.mulf = function mulf (num) {
4533    var out = new BN(null);
4534    out.words = new Array(this.length + num.length);
4535    return jumboMulTo(this, num, out);
4536  };
4537
4538  // In-place Multiplication
4539  BN.prototype.imul = function imul (num) {
4540    return this.clone().mulTo(num, this);
4541  };
4542
4543  BN.prototype.imuln = function imuln (num) {
4544    assert(typeof num === 'number');
4545    assert(num < 0x4000000);
4546
4547    // Carry
4548    var carry = 0;
4549    for (var i = 0; i < this.length; i++) {
4550      var w = (this.words[i] | 0) * num;
4551      var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
4552      carry >>= 26;
4553      carry += (w / 0x4000000) | 0;
4554      // NOTE: lo is 27bit maximum
4555      carry += lo >>> 26;
4556      this.words[i] = lo & 0x3ffffff;
4557    }
4558
4559    if (carry !== 0) {
4560      this.words[i] = carry;
4561      this.length++;
4562    }
4563
4564    return this;
4565  };
4566
4567  BN.prototype.muln = function muln (num) {
4568    return this.clone().imuln(num);
4569  };
4570
4571  // `this` * `this`
4572  BN.prototype.sqr = function sqr () {
4573    return this.mul(this);
4574  };
4575
4576  // `this` * `this` in-place
4577  BN.prototype.isqr = function isqr () {
4578    return this.imul(this.clone());
4579  };
4580
4581  // Math.pow(`this`, `num`)
4582  BN.prototype.pow = function pow (num) {
4583    var w = toBitArray(num);
4584    if (w.length === 0) return new BN(1);
4585
4586    // Skip leading zeroes
4587    var res = this;
4588    for (var i = 0; i < w.length; i++, res = res.sqr()) {
4589      if (w[i] !== 0) break;
4590    }
4591
4592    if (++i < w.length) {
4593      for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
4594        if (w[i] === 0) continue;
4595
4596        res = res.mul(q);
4597      }
4598    }
4599
4600    return res;
4601  };
4602
4603  // Shift-left in-place
4604  BN.prototype.iushln = function iushln (bits) {
4605    assert(typeof bits === 'number' && bits >= 0);
4606    var r = bits % 26;
4607    var s = (bits - r) / 26;
4608    var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
4609    var i;
4610
4611    if (r !== 0) {
4612      var carry = 0;
4613
4614      for (i = 0; i < this.length; i++) {
4615        var newCarry = this.words[i] & carryMask;
4616        var c = ((this.words[i] | 0) - newCarry) << r;
4617        this.words[i] = c | carry;
4618        carry = newCarry >>> (26 - r);
4619      }
4620
4621      if (carry) {
4622        this.words[i] = carry;
4623        this.length++;
4624      }
4625    }
4626
4627    if (s !== 0) {
4628      for (i = this.length - 1; i >= 0; i--) {
4629        this.words[i + s] = this.words[i];
4630      }
4631
4632      for (i = 0; i < s; i++) {
4633        this.words[i] = 0;
4634      }
4635
4636      this.length += s;
4637    }
4638
4639    return this.strip();
4640  };
4641
4642  BN.prototype.ishln = function ishln (bits) {
4643    // TODO(indutny): implement me
4644    assert(this.negative === 0);
4645    return this.iushln(bits);
4646  };
4647
4648  // Shift-right in-place
4649  // NOTE: `hint` is a lowest bit before trailing zeroes
4650  // NOTE: if `extended` is present - it will be filled with destroyed bits
4651  BN.prototype.iushrn = function iushrn (bits, hint, extended) {
4652    assert(typeof bits === 'number' && bits >= 0);
4653    var h;
4654    if (hint) {
4655      h = (hint - (hint % 26)) / 26;
4656    } else {
4657      h = 0;
4658    }
4659
4660    var r = bits % 26;
4661    var s = Math.min((bits - r) / 26, this.length);
4662    var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
4663    var maskedWords = extended;
4664
4665    h -= s;
4666    h = Math.max(0, h);
4667
4668    // Extended mode, copy masked part
4669    if (maskedWords) {
4670      for (var i = 0; i < s; i++) {
4671        maskedWords.words[i] = this.words[i];
4672      }
4673      maskedWords.length = s;
4674    }
4675
4676    if (s === 0) {
4677      // No-op, we should not move anything at all
4678    } else if (this.length > s) {
4679      this.length -= s;
4680      for (i = 0; i < this.length; i++) {
4681        this.words[i] = this.words[i + s];
4682      }
4683    } else {
4684      this.words[0] = 0;
4685      this.length = 1;
4686    }
4687
4688    var carry = 0;
4689    for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
4690      var word = this.words[i] | 0;
4691      this.words[i] = (carry << (26 - r)) | (word >>> r);
4692      carry = word & mask;
4693    }
4694
4695    // Push carried bits as a mask
4696    if (maskedWords && carry !== 0) {
4697      maskedWords.words[maskedWords.length++] = carry;
4698    }
4699
4700    if (this.length === 0) {
4701      this.words[0] = 0;
4702      this.length = 1;
4703    }
4704
4705    return this.strip();
4706  };
4707
4708  BN.prototype.ishrn = function ishrn (bits, hint, extended) {
4709    // TODO(indutny): implement me
4710    assert(this.negative === 0);
4711    return this.iushrn(bits, hint, extended);
4712  };
4713
4714  // Shift-left
4715  BN.prototype.shln = function shln (bits) {
4716    return this.clone().ishln(bits);
4717  };
4718
4719  BN.prototype.ushln = function ushln (bits) {
4720    return this.clone().iushln(bits);
4721  };
4722
4723  // Shift-right
4724  BN.prototype.shrn = function shrn (bits) {
4725    return this.clone().ishrn(bits);
4726  };
4727
4728  BN.prototype.ushrn = function ushrn (bits) {
4729    return this.clone().iushrn(bits);
4730  };
4731
4732  // Test if n bit is set
4733  BN.prototype.testn = function testn (bit) {
4734    assert(typeof bit === 'number' && bit >= 0);
4735    var r = bit % 26;
4736    var s = (bit - r) / 26;
4737    var q = 1 << r;
4738
4739    // Fast case: bit is much higher than all existing words
4740    if (this.length <= s) return false;
4741
4742    // Check bit and return
4743    var w = this.words[s];
4744
4745    return !!(w & q);
4746  };
4747
4748  // Return only lowers bits of number (in-place)
4749  BN.prototype.imaskn = function imaskn (bits) {
4750    assert(typeof bits === 'number' && bits >= 0);
4751    var r = bits % 26;
4752    var s = (bits - r) / 26;
4753
4754    assert(this.negative === 0, 'imaskn works only with positive numbers');
4755
4756    if (this.length <= s) {
4757      return this;
4758    }
4759
4760    if (r !== 0) {
4761      s++;
4762    }
4763    this.length = Math.min(s, this.length);
4764
4765    if (r !== 0) {
4766      var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
4767      this.words[this.length - 1] &= mask;
4768    }
4769
4770    return this.strip();
4771  };
4772
4773  // Return only lowers bits of number
4774  BN.prototype.maskn = function maskn (bits) {
4775    return this.clone().imaskn(bits);
4776  };
4777
4778  // Add plain number `num` to `this`
4779  BN.prototype.iaddn = function iaddn (num) {
4780    assert(typeof num === 'number');
4781    assert(num < 0x4000000);
4782    if (num < 0) return this.isubn(-num);
4783
4784    // Possible sign change
4785    if (this.negative !== 0) {
4786      if (this.length === 1 && (this.words[0] | 0) < num) {
4787        this.words[0] = num - (this.words[0] | 0);
4788        this.negative = 0;
4789        return this;
4790      }
4791
4792      this.negative = 0;
4793      this.isubn(num);
4794      this.negative = 1;
4795      return this;
4796    }
4797
4798    // Add without checks
4799    return this._iaddn(num);
4800  };
4801
4802  BN.prototype._iaddn = function _iaddn (num) {
4803    this.words[0] += num;
4804
4805    // Carry
4806    for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
4807      this.words[i] -= 0x4000000;
4808      if (i === this.length - 1) {
4809        this.words[i + 1] = 1;
4810      } else {
4811        this.words[i + 1]++;
4812      }
4813    }
4814    this.length = Math.max(this.length, i + 1);
4815
4816    return this;
4817  };
4818
4819  // Subtract plain number `num` from `this`
4820  BN.prototype.isubn = function isubn (num) {
4821    assert(typeof num === 'number');
4822    assert(num < 0x4000000);
4823    if (num < 0) return this.iaddn(-num);
4824
4825    if (this.negative !== 0) {
4826      this.negative = 0;
4827      this.iaddn(num);
4828      this.negative = 1;
4829      return this;
4830    }
4831
4832    this.words[0] -= num;
4833
4834    if (this.length === 1 && this.words[0] < 0) {
4835      this.words[0] = -this.words[0];
4836      this.negative = 1;
4837    } else {
4838      // Carry
4839      for (var i = 0; i < this.length && this.words[i] < 0; i++) {
4840        this.words[i] += 0x4000000;
4841        this.words[i + 1] -= 1;
4842      }
4843    }
4844
4845    return this.strip();
4846  };
4847
4848  BN.prototype.addn = function addn (num) {
4849    return this.clone().iaddn(num);
4850  };
4851
4852  BN.prototype.subn = function subn (num) {
4853    return this.clone().isubn(num);
4854  };
4855
4856  BN.prototype.iabs = function iabs () {
4857    this.negative = 0;
4858
4859    return this;
4860  };
4861
4862  BN.prototype.abs = function abs () {
4863    return this.clone().iabs();
4864  };
4865
4866  BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
4867    var len = num.length + shift;
4868    var i;
4869
4870    this._expand(len);
4871
4872    var w;
4873    var carry = 0;
4874    for (i = 0; i < num.length; i++) {
4875      w = (this.words[i + shift] | 0) + carry;
4876      var right = (num.words[i] | 0) * mul;
4877      w -= right & 0x3ffffff;
4878      carry = (w >> 26) - ((right / 0x4000000) | 0);
4879      this.words[i + shift] = w & 0x3ffffff;
4880    }
4881    for (; i < this.length - shift; i++) {
4882      w = (this.words[i + shift] | 0) + carry;
4883      carry = w >> 26;
4884      this.words[i + shift] = w & 0x3ffffff;
4885    }
4886
4887    if (carry === 0) return this.strip();
4888
4889    // Subtraction overflow
4890    assert(carry === -1);
4891    carry = 0;
4892    for (i = 0; i < this.length; i++) {
4893      w = -(this.words[i] | 0) + carry;
4894      carry = w >> 26;
4895      this.words[i] = w & 0x3ffffff;
4896    }
4897    this.negative = 1;
4898
4899    return this.strip();
4900  };
4901
4902  BN.prototype._wordDiv = function _wordDiv (num, mode) {
4903    var shift = this.length - num.length;
4904
4905    var a = this.clone();
4906    var b = num;
4907
4908    // Normalize
4909    var bhi = b.words[b.length - 1] | 0;
4910    var bhiBits = this._countBits(bhi);
4911    shift = 26 - bhiBits;
4912    if (shift !== 0) {
4913      b = b.ushln(shift);
4914      a.iushln(shift);
4915      bhi = b.words[b.length - 1] | 0;
4916    }
4917
4918    // Initialize quotient
4919    var m = a.length - b.length;
4920    var q;
4921
4922    if (mode !== 'mod') {
4923      q = new BN(null);
4924      q.length = m + 1;
4925      q.words = new Array(q.length);
4926      for (var i = 0; i < q.length; i++) {
4927        q.words[i] = 0;
4928      }
4929    }
4930
4931    var diff = a.clone()._ishlnsubmul(b, 1, m);
4932    if (diff.negative === 0) {
4933      a = diff;
4934      if (q) {
4935        q.words[m] = 1;
4936      }
4937    }
4938
4939    for (var j = m - 1; j >= 0; j--) {
4940      var qj = (a.words[b.length + j] | 0) * 0x4000000 +
4941        (a.words[b.length + j - 1] | 0);
4942
4943      // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
4944      // (0x7ffffff)
4945      qj = Math.min((qj / bhi) | 0, 0x3ffffff);
4946
4947      a._ishlnsubmul(b, qj, j);
4948      while (a.negative !== 0) {
4949        qj--;
4950        a.negative = 0;
4951        a._ishlnsubmul(b, 1, j);
4952        if (!a.isZero()) {
4953          a.negative ^= 1;
4954        }
4955      }
4956      if (q) {
4957        q.words[j] = qj;
4958      }
4959    }
4960    if (q) {
4961      q.strip();
4962    }
4963    a.strip();
4964
4965    // Denormalize
4966    if (mode !== 'div' && shift !== 0) {
4967      a.iushrn(shift);
4968    }
4969
4970    return {
4971      div: q || null,
4972      mod: a
4973    };
4974  };
4975
4976  // NOTE: 1) `mode` can be set to `mod` to request mod only,
4977  //       to `div` to request div only, or be absent to
4978  //       request both div & mod
4979  //       2) `positive` is true if unsigned mod is requested
4980  BN.prototype.divmod = function divmod (num, mode, positive) {
4981    assert(!num.isZero());
4982
4983    if (this.isZero()) {
4984      return {
4985        div: new BN(0),
4986        mod: new BN(0)
4987      };
4988    }
4989
4990    var div, mod, res;
4991    if (this.negative !== 0 && num.negative === 0) {
4992      res = this.neg().divmod(num, mode);
4993
4994      if (mode !== 'mod') {
4995        div = res.div.neg();
4996      }
4997
4998      if (mode !== 'div') {
4999        mod = res.mod.neg();
5000        if (positive && mod.negative !== 0) {
5001          mod.iadd(num);
5002        }
5003      }
5004
5005      return {
5006        div: div,
5007        mod: mod
5008      };
5009    }
5010
5011    if (this.negative === 0 && num.negative !== 0) {
5012      res = this.divmod(num.neg(), mode);
5013
5014      if (mode !== 'mod') {
5015        div = res.div.neg();
5016      }
5017
5018      return {
5019        div: div,
5020        mod: res.mod
5021      };
5022    }
5023
5024    if ((this.negative & num.negative) !== 0) {
5025      res = this.neg().divmod(num.neg(), mode);
5026
5027      if (mode !== 'div') {
5028        mod = res.mod.neg();
5029        if (positive && mod.negative !== 0) {
5030          mod.isub(num);
5031        }
5032      }
5033
5034      return {
5035        div: res.div,
5036        mod: mod
5037      };
5038    }
5039
5040    // Both numbers are positive at this point
5041
5042    // Strip both numbers to approximate shift value
5043    if (num.length > this.length || this.cmp(num) < 0) {
5044      return {
5045        div: new BN(0),
5046        mod: this
5047      };
5048    }
5049
5050    // Very short reduction
5051    if (num.length === 1) {
5052      if (mode === 'div') {
5053        return {
5054          div: this.divn(num.words[0]),
5055          mod: null
5056        };
5057      }
5058
5059      if (mode === 'mod') {
5060        return {
5061          div: null,
5062          mod: new BN(this.modn(num.words[0]))
5063        };
5064      }
5065
5066      return {
5067        div: this.divn(num.words[0]),
5068        mod: new BN(this.modn(num.words[0]))
5069      };
5070    }
5071
5072    return this._wordDiv(num, mode);
5073  };
5074
5075  // Find `this` / `num`
5076  BN.prototype.div = function div (num) {
5077    return this.divmod(num, 'div', false).div;
5078  };
5079
5080  // Find `this` % `num`
5081  BN.prototype.mod = function mod (num) {
5082    return this.divmod(num, 'mod', false).mod;
5083  };
5084
5085  BN.prototype.umod = function umod (num) {
5086    return this.divmod(num, 'mod', true).mod;
5087  };
5088
5089  // Find Round(`this` / `num`)
5090  BN.prototype.divRound = function divRound (num) {
5091    var dm = this.divmod(num);
5092
5093    // Fast case - exact division
5094    if (dm.mod.isZero()) return dm.div;
5095
5096    var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
5097
5098    var half = num.ushrn(1);
5099    var r2 = num.andln(1);
5100    var cmp = mod.cmp(half);
5101
5102    // Round down
5103    if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
5104
5105    // Round up
5106    return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
5107  };
5108
5109  BN.prototype.modn = function modn (num) {
5110    assert(num <= 0x3ffffff);
5111    var p = (1 << 26) % num;
5112
5113    var acc = 0;
5114    for (var i = this.length - 1; i >= 0; i--) {
5115      acc = (p * acc + (this.words[i] | 0)) % num;
5116    }
5117
5118    return acc;
5119  };
5120
5121  // In-place division by number
5122  BN.prototype.idivn = function idivn (num) {
5123    assert(num <= 0x3ffffff);
5124
5125    var carry = 0;
5126    for (var i = this.length - 1; i >= 0; i--) {
5127      var w = (this.words[i] | 0) + carry * 0x4000000;
5128      this.words[i] = (w / num) | 0;
5129      carry = w % num;
5130    }
5131
5132    return this.strip();
5133  };
5134
5135  BN.prototype.divn = function divn (num) {
5136    return this.clone().idivn(num);
5137  };
5138
5139  BN.prototype.egcd = function egcd (p) {
5140    assert(p.negative === 0);
5141    assert(!p.isZero());
5142
5143    var x = this;
5144    var y = p.clone();
5145
5146    if (x.negative !== 0) {
5147      x = x.umod(p);
5148    } else {
5149      x = x.clone();
5150    }
5151
5152    // A * x + B * y = x
5153    var A = new BN(1);
5154    var B = new BN(0);
5155
5156    // C * x + D * y = y
5157    var C = new BN(0);
5158    var D = new BN(1);
5159
5160    var g = 0;
5161
5162    while (x.isEven() && y.isEven()) {
5163      x.iushrn(1);
5164      y.iushrn(1);
5165      ++g;
5166    }
5167
5168    var yp = y.clone();
5169    var xp = x.clone();
5170
5171    while (!x.isZero()) {
5172      for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
5173      if (i > 0) {
5174        x.iushrn(i);
5175        while (i-- > 0) {
5176          if (A.isOdd() || B.isOdd()) {
5177            A.iadd(yp);
5178            B.isub(xp);
5179          }
5180
5181          A.iushrn(1);
5182          B.iushrn(1);
5183        }
5184      }
5185
5186      for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
5187      if (j > 0) {
5188        y.iushrn(j);
5189        while (j-- > 0) {
5190          if (C.isOdd() || D.isOdd()) {
5191            C.iadd(yp);
5192            D.isub(xp);
5193          }
5194
5195          C.iushrn(1);
5196          D.iushrn(1);
5197        }
5198      }
5199
5200      if (x.cmp(y) >= 0) {
5201        x.isub(y);
5202        A.isub(C);
5203        B.isub(D);
5204      } else {
5205        y.isub(x);
5206        C.isub(A);
5207        D.isub(B);
5208      }
5209    }
5210
5211    return {
5212      a: C,
5213      b: D,
5214      gcd: y.iushln(g)
5215    };
5216  };
5217
5218  // This is reduced incarnation of the binary EEA
5219  // above, designated to invert members of the
5220  // _prime_ fields F(p) at a maximal speed
5221  BN.prototype._invmp = function _invmp (p) {
5222    assert(p.negative === 0);
5223    assert(!p.isZero());
5224
5225    var a = this;
5226    var b = p.clone();
5227
5228    if (a.negative !== 0) {
5229      a = a.umod(p);
5230    } else {
5231      a = a.clone();
5232    }
5233
5234    var x1 = new BN(1);
5235    var x2 = new BN(0);
5236
5237    var delta = b.clone();
5238
5239    while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
5240      for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
5241      if (i > 0) {
5242        a.iushrn(i);
5243        while (i-- > 0) {
5244          if (x1.isOdd()) {
5245            x1.iadd(delta);
5246          }
5247
5248          x1.iushrn(1);
5249        }
5250      }
5251
5252      for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
5253      if (j > 0) {
5254        b.iushrn(j);
5255        while (j-- > 0) {
5256          if (x2.isOdd()) {
5257            x2.iadd(delta);
5258          }
5259
5260          x2.iushrn(1);
5261        }
5262      }
5263
5264      if (a.cmp(b) >= 0) {
5265        a.isub(b);
5266        x1.isub(x2);
5267      } else {
5268        b.isub(a);
5269        x2.isub(x1);
5270      }
5271    }
5272
5273    var res;
5274    if (a.cmpn(1) === 0) {
5275      res = x1;
5276    } else {
5277      res = x2;
5278    }
5279
5280    if (res.cmpn(0) < 0) {
5281      res.iadd(p);
5282    }
5283
5284    return res;
5285  };
5286
5287  BN.prototype.gcd = function gcd (num) {
5288    if (this.isZero()) return num.abs();
5289    if (num.isZero()) return this.abs();
5290
5291    var a = this.clone();
5292    var b = num.clone();
5293    a.negative = 0;
5294    b.negative = 0;
5295
5296    // Remove common factor of two
5297    for (var shift = 0; a.isEven() && b.isEven(); shift++) {
5298      a.iushrn(1);
5299      b.iushrn(1);
5300    }
5301
5302    do {
5303      while (a.isEven()) {
5304        a.iushrn(1);
5305      }
5306      while (b.isEven()) {
5307        b.iushrn(1);
5308      }
5309
5310      var r = a.cmp(b);
5311      if (r < 0) {
5312        // Swap `a` and `b` to make `a` always bigger than `b`
5313        var t = a;
5314        a = b;
5315        b = t;
5316      } else if (r === 0 || b.cmpn(1) === 0) {
5317        break;
5318      }
5319
5320      a.isub(b);
5321    } while (true);
5322
5323    return b.iushln(shift);
5324  };
5325
5326  // Invert number in the field F(num)
5327  BN.prototype.invm = function invm (num) {
5328    return this.egcd(num).a.umod(num);
5329  };
5330
5331  BN.prototype.isEven = function isEven () {
5332    return (this.words[0] & 1) === 0;
5333  };
5334
5335  BN.prototype.isOdd = function isOdd () {
5336    return (this.words[0] & 1) === 1;
5337  };
5338
5339  // And first word and num
5340  BN.prototype.andln = function andln (num) {
5341    return this.words[0] & num;
5342  };
5343
5344  // Increment at the bit position in-line
5345  BN.prototype.bincn = function bincn (bit) {
5346    assert(typeof bit === 'number');
5347    var r = bit % 26;
5348    var s = (bit - r) / 26;
5349    var q = 1 << r;
5350
5351    // Fast case: bit is much higher than all existing words
5352    if (this.length <= s) {
5353      this._expand(s + 1);
5354      this.words[s] |= q;
5355      return this;
5356    }
5357
5358    // Add bit and propagate, if needed
5359    var carry = q;
5360    for (var i = s; carry !== 0 && i < this.length; i++) {
5361      var w = this.words[i] | 0;
5362      w += carry;
5363      carry = w >>> 26;
5364      w &= 0x3ffffff;
5365      this.words[i] = w;
5366    }
5367    if (carry !== 0) {
5368      this.words[i] = carry;
5369      this.length++;
5370    }
5371    return this;
5372  };
5373
5374  BN.prototype.isZero = function isZero () {
5375    return this.length === 1 && this.words[0] === 0;
5376  };
5377
5378  BN.prototype.cmpn = function cmpn (num) {
5379    var negative = num < 0;
5380
5381    if (this.negative !== 0 && !negative) return -1;
5382    if (this.negative === 0 && negative) return 1;
5383
5384    this.strip();
5385
5386    var res;
5387    if (this.length > 1) {
5388      res = 1;
5389    } else {
5390      if (negative) {
5391        num = -num;
5392      }
5393
5394      assert(num <= 0x3ffffff, 'Number is too big');
5395
5396      var w = this.words[0] | 0;
5397      res = w === num ? 0 : w < num ? -1 : 1;
5398    }
5399    if (this.negative !== 0) return -res | 0;
5400    return res;
5401  };
5402
5403  // Compare two numbers and return:
5404  // 1 - if `this` > `num`
5405  // 0 - if `this` == `num`
5406  // -1 - if `this` < `num`
5407  BN.prototype.cmp = function cmp (num) {
5408    if (this.negative !== 0 && num.negative === 0) return -1;
5409    if (this.negative === 0 && num.negative !== 0) return 1;
5410
5411    var res = this.ucmp(num);
5412    if (this.negative !== 0) return -res | 0;
5413    return res;
5414  };
5415
5416  // Unsigned comparison
5417  BN.prototype.ucmp = function ucmp (num) {
5418    // At this point both numbers have the same sign
5419    if (this.length > num.length) return 1;
5420    if (this.length < num.length) return -1;
5421
5422    var res = 0;
5423    for (var i = this.length - 1; i >= 0; i--) {
5424      var a = this.words[i] | 0;
5425      var b = num.words[i] | 0;
5426
5427      if (a === b) continue;
5428      if (a < b) {
5429        res = -1;
5430      } else if (a > b) {
5431        res = 1;
5432      }
5433      break;
5434    }
5435    return res;
5436  };
5437
5438  BN.prototype.gtn = function gtn (num) {
5439    return this.cmpn(num) === 1;
5440  };
5441
5442  BN.prototype.gt = function gt (num) {
5443    return this.cmp(num) === 1;
5444  };
5445
5446  BN.prototype.gten = function gten (num) {
5447    return this.cmpn(num) >= 0;
5448  };
5449
5450  BN.prototype.gte = function gte (num) {
5451    return this.cmp(num) >= 0;
5452  };
5453
5454  BN.prototype.ltn = function ltn (num) {
5455    return this.cmpn(num) === -1;
5456  };
5457
5458  BN.prototype.lt = function lt (num) {
5459    return this.cmp(num) === -1;
5460  };
5461
5462  BN.prototype.lten = function lten (num) {
5463    return this.cmpn(num) <= 0;
5464  };
5465
5466  BN.prototype.lte = function lte (num) {
5467    return this.cmp(num) <= 0;
5468  };
5469
5470  BN.prototype.eqn = function eqn (num) {
5471    return this.cmpn(num) === 0;
5472  };
5473
5474  BN.prototype.eq = function eq (num) {
5475    return this.cmp(num) === 0;
5476  };
5477
5478  //
5479  // A reduce context, could be using montgomery or something better, depending
5480  // on the `m` itself.
5481  //
5482  BN.red = function red (num) {
5483    return new Red(num);
5484  };
5485
5486  BN.prototype.toRed = function toRed (ctx) {
5487    assert(!this.red, 'Already a number in reduction context');
5488    assert(this.negative === 0, 'red works only with positives');
5489    return ctx.convertTo(this)._forceRed(ctx);
5490  };
5491
5492  BN.prototype.fromRed = function fromRed () {
5493    assert(this.red, 'fromRed works only with numbers in reduction context');
5494    return this.red.convertFrom(this);
5495  };
5496
5497  BN.prototype._forceRed = function _forceRed (ctx) {
5498    this.red = ctx;
5499    return this;
5500  };
5501
5502  BN.prototype.forceRed = function forceRed (ctx) {
5503    assert(!this.red, 'Already a number in reduction context');
5504    return this._forceRed(ctx);
5505  };
5506
5507  BN.prototype.redAdd = function redAdd (num) {
5508    assert(this.red, 'redAdd works only with red numbers');
5509    return this.red.add(this, num);
5510  };
5511
5512  BN.prototype.redIAdd = function redIAdd (num) {
5513    assert(this.red, 'redIAdd works only with red numbers');
5514    return this.red.iadd(this, num);
5515  };
5516
5517  BN.prototype.redSub = function redSub (num) {
5518    assert(this.red, 'redSub works only with red numbers');
5519    return this.red.sub(this, num);
5520  };
5521
5522  BN.prototype.redISub = function redISub (num) {
5523    assert(this.red, 'redISub works only with red numbers');
5524    return this.red.isub(this, num);
5525  };
5526
5527  BN.prototype.redShl = function redShl (num) {
5528    assert(this.red, 'redShl works only with red numbers');
5529    return this.red.shl(this, num);
5530  };
5531
5532  BN.prototype.redMul = function redMul (num) {
5533    assert(this.red, 'redMul works only with red numbers');
5534    this.red._verify2(this, num);
5535    return this.red.mul(this, num);
5536  };
5537
5538  BN.prototype.redIMul = function redIMul (num) {
5539    assert(this.red, 'redMul works only with red numbers');
5540    this.red._verify2(this, num);
5541    return this.red.imul(this, num);
5542  };
5543
5544  BN.prototype.redSqr = function redSqr () {
5545    assert(this.red, 'redSqr works only with red numbers');
5546    this.red._verify1(this);
5547    return this.red.sqr(this);
5548  };
5549
5550  BN.prototype.redISqr = function redISqr () {
5551    assert(this.red, 'redISqr works only with red numbers');
5552    this.red._verify1(this);
5553    return this.red.isqr(this);
5554  };
5555
5556  // Square root over p
5557  BN.prototype.redSqrt = function redSqrt () {
5558    assert(this.red, 'redSqrt works only with red numbers');
5559    this.red._verify1(this);
5560    return this.red.sqrt(this);
5561  };
5562
vendor: 8,763 bytes, lines 5563-5942
5563  BN.prototype.redInvm = function redInvm () {
5564    assert(this.red, 'redInvm works only with red numbers');
5565    this.red._verify1(this);
5566    return this.red.invm(this);
5567  };
5568
5569  // Return negative clone of `this` % `red modulo`
5570  BN.prototype.redNeg = function redNeg () {
5571    assert(this.red, 'redNeg works only with red numbers');
5572    this.red._verify1(this);
5573    return this.red.neg(this);
5574  };
5575
5576  BN.prototype.redPow = function redPow (num) {
5577    assert(this.red && !num.red, 'redPow(normalNum)');
5578    this.red._verify1(this);
5579    return this.red.pow(this, num);
5580  };
5581
5582  // Prime numbers with efficient reduction
5583  var primes = {
5584    k256: null,
5585    p224: null,
5586    p192: null,
5587    p25519: null
5588  };
5589
5590  // Pseudo-Mersenne prime
5591  function MPrime (name, p) {
5592    // P = 2 ^ N - K
5593    this.name = name;
5594    this.p = new BN(p, 16);
5595    this.n = this.p.bitLength();
5596    this.k = new BN(1).iushln(this.n).isub(this.p);
5597
5598    this.tmp = this._tmp();
5599  }
5600
5601  MPrime.prototype._tmp = function _tmp () {
5602    var tmp = new BN(null);
5603    tmp.words = new Array(Math.ceil(this.n / 13));
5604    return tmp;
5605  };
5606
5607  MPrime.prototype.ireduce = function ireduce (num) {
5608    // Assumes that `num` is less than `P^2`
5609    // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
5610    var r = num;
5611    var rlen;
5612
5613    do {
5614      this.split(r, this.tmp);
5615      r = this.imulK(r);
5616      r = r.iadd(this.tmp);
5617      rlen = r.bitLength();
5618    } while (rlen > this.n);
5619
5620    var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
5621    if (cmp === 0) {
5622      r.words[0] = 0;
5623      r.length = 1;
5624    } else if (cmp > 0) {
5625      r.isub(this.p);
5626    } else {
5627      r.strip();
5628    }
5629
5630    return r;
5631  };
5632
5633  MPrime.prototype.split = function split (input, out) {
5634    input.iushrn(this.n, 0, out);
5635  };
5636
5637  MPrime.prototype.imulK = function imulK (num) {
5638    return num.imul(this.k);
5639  };
5640
5641  function K256 () {
5642    MPrime.call(
5643      this,
5644      'k256',
5645      'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
5646  }
5647  inherits(K256, MPrime);
5648
5649  K256.prototype.split = function split (input, output) {
5650    // 256 = 9 * 26 + 22
5651    var mask = 0x3fffff;
5652
5653    var outLen = Math.min(input.length, 9);
5654    for (var i = 0; i < outLen; i++) {
5655      output.words[i] = input.words[i];
5656    }
5657    output.length = outLen;
5658
5659    if (input.length <= 9) {
5660      input.words[0] = 0;
5661      input.length = 1;
5662      return;
5663    }
5664
5665    // Shift by 9 limbs
5666    var prev = input.words[9];
5667    output.words[output.length++] = prev & mask;
5668
5669    for (i = 10; i < input.length; i++) {
5670      var next = input.words[i] | 0;
5671      input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
5672      prev = next;
5673    }
5674    prev >>>= 22;
5675    input.words[i - 10] = prev;
5676    if (prev === 0 && input.length > 10) {
5677      input.length -= 10;
5678    } else {
5679      input.length -= 9;
5680    }
5681  };
5682
5683  K256.prototype.imulK = function imulK (num) {
5684    // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
5685    num.words[num.length] = 0;
5686    num.words[num.length + 1] = 0;
5687    num.length += 2;
5688
5689    // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
5690    var lo = 0;
5691    for (var i = 0; i < num.length; i++) {
5692      var w = num.words[i] | 0;
5693      lo += w * 0x3d1;
5694      num.words[i] = lo & 0x3ffffff;
5695      lo = w * 0x40 + ((lo / 0x4000000) | 0);
5696    }
5697
5698    // Fast length reduction
5699    if (num.words[num.length - 1] === 0) {
5700      num.length--;
5701      if (num.words[num.length - 1] === 0) {
5702        num.length--;
5703      }
5704    }
5705    return num;
5706  };
5707
5708  function P224 () {
5709    MPrime.call(
5710      this,
5711      'p224',
5712      'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
5713  }
5714  inherits(P224, MPrime);
5715
5716  function P192 () {
5717    MPrime.call(
5718      this,
5719      'p192',
5720      'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
5721  }
5722  inherits(P192, MPrime);
5723
5724  function P25519 () {
5725    // 2 ^ 255 - 19
5726    MPrime.call(
5727      this,
5728      '25519',
5729      '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
5730  }
5731  inherits(P25519, MPrime);
5732
5733  P25519.prototype.imulK = function imulK (num) {
5734    // K = 0x13
5735    var carry = 0;
5736    for (var i = 0; i < num.length; i++) {
5737      var hi = (num.words[i] | 0) * 0x13 + carry;
5738      var lo = hi & 0x3ffffff;
5739      hi >>>= 26;
5740
5741      num.words[i] = lo;
5742      carry = hi;
5743    }
5744    if (carry !== 0) {
5745      num.words[num.length++] = carry;
5746    }
5747    return num;
5748  };
5749
5750  // Exported mostly for testing purposes, use plain name instead
5751  BN._prime = function prime (name) {
5752    // Cached version of prime
5753    if (primes[name]) return primes[name];
5754
5755    var prime;
5756    if (name === 'k256') {
5757      prime = new K256();
5758    } else if (name === 'p224') {
5759      prime = new P224();
5760    } else if (name === 'p192') {
5761      prime = new P192();
5762    } else if (name === 'p25519') {
5763      prime = new P25519();
5764    } else {
5765      throw new Error('Unknown prime ' + name);
5766    }
5767    primes[name] = prime;
5768
5769    return prime;
5770  };
5771
5772  //
5773  // Base reduction engine
5774  //
5775  function Red (m) {
5776    if (typeof m === 'string') {
5777      var prime = BN._prime(m);
5778      this.m = prime.p;
5779      this.prime = prime;
5780    } else {
5781      assert(m.gtn(1), 'modulus must be greater than 1');
5782      this.m = m;
5783      this.prime = null;
5784    }
5785  }
5786
5787  Red.prototype._verify1 = function _verify1 (a) {
5788    assert(a.negative === 0, 'red works only with positives');
5789    assert(a.red, 'red works only with red numbers');
5790  };
5791
5792  Red.prototype._verify2 = function _verify2 (a, b) {
5793    assert((a.negative | b.negative) === 0, 'red works only with positives');
5794    assert(a.red && a.red === b.red,
5795      'red works only with red numbers');
5796  };
5797
5798  Red.prototype.imod = function imod (a) {
5799    if (this.prime) return this.prime.ireduce(a)._forceRed(this);
5800    return a.umod(this.m)._forceRed(this);
5801  };
5802
5803  Red.prototype.neg = function neg (a) {
5804    if (a.isZero()) {
5805      return a.clone();
5806    }
5807
5808    return this.m.sub(a)._forceRed(this);
5809  };
5810
5811  Red.prototype.add = function add (a, b) {
5812    this._verify2(a, b);
5813
5814    var res = a.add(b);
5815    if (res.cmp(this.m) >= 0) {
5816      res.isub(this.m);
5817    }
5818    return res._forceRed(this);
5819  };
5820
5821  Red.prototype.iadd = function iadd (a, b) {
5822    this._verify2(a, b);
5823
5824    var res = a.iadd(b);
5825    if (res.cmp(this.m) >= 0) {
5826      res.isub(this.m);
5827    }
5828    return res;
5829  };
5830
5831  Red.prototype.sub = function sub (a, b) {
5832    this._verify2(a, b);
5833
5834    var res = a.sub(b);
5835    if (res.cmpn(0) < 0) {
5836      res.iadd(this.m);
5837    }
5838    return res._forceRed(this);
5839  };
5840
5841  Red.prototype.isub = function isub (a, b) {
5842    this._verify2(a, b);
5843
5844    var res = a.isub(b);
5845    if (res.cmpn(0) < 0) {
5846      res.iadd(this.m);
5847    }
5848    return res;
5849  };
5850
5851  Red.prototype.shl = function shl (a, num) {
5852    this._verify1(a);
5853    return this.imod(a.ushln(num));
5854  };
5855
5856  Red.prototype.imul = function imul (a, b) {
5857    this._verify2(a, b);
5858    return this.imod(a.imul(b));
5859  };
5860
5861  Red.prototype.mul = function mul (a, b) {
5862    this._verify2(a, b);
5863    return this.imod(a.mul(b));
5864  };
5865
5866  Red.prototype.isqr = function isqr (a) {
5867    return this.imul(a, a.clone());
5868  };
5869
5870  Red.prototype.sqr = function sqr (a) {
5871    return this.mul(a, a);
5872  };
5873
5874  Red.prototype.sqrt = function sqrt (a) {
5875    if (a.isZero()) return a.clone();
5876
5877    var mod3 = this.m.andln(3);
5878    assert(mod3 % 2 === 1);
5879
5880    // Fast case
5881    if (mod3 === 3) {
5882      var pow = this.m.add(new BN(1)).iushrn(2);
5883      return this.pow(a, pow);
5884    }
5885
5886    // Tonelli-Shanks algorithm (Totally unoptimized and slow)
5887    //
5888    // Find Q and S, that Q * 2 ^ S = (P - 1)
5889    var q = this.m.subn(1);
5890    var s = 0;
5891    while (!q.isZero() && q.andln(1) === 0) {
5892      s++;
5893      q.iushrn(1);
5894    }
5895    assert(!q.isZero());
5896
5897    var one = new BN(1).toRed(this);
5898    var nOne = one.redNeg();
5899
5900    // Find quadratic non-residue
5901    // NOTE: Max is such because of generalized Riemann hypothesis.
5902    var lpow = this.m.subn(1).iushrn(1);
5903    var z = this.m.bitLength();
5904    z = new BN(2 * z * z).toRed(this);
5905
5906    while (this.pow(z, lpow).cmp(nOne) !== 0) {
5907      z.redIAdd(nOne);
5908    }
5909
5910    var c = this.pow(z, q);
5911    var r = this.pow(a, q.addn(1).iushrn(1));
5912    var t = this.pow(a, q);
5913    var m = s;
5914    while (t.cmp(one) !== 0) {
5915      var tmp = t;
5916      for (var i = 0; tmp.cmp(one) !== 0; i++) {
5917        tmp = tmp.redSqr();
5918      }
5919      assert(i < m);
5920      var b = this.pow(c, new BN(1).iushln(m - i - 1));
5921
5922      r = r.redMul(b);
5923      c = b.redSqr();
5924      t = t.redMul(c);
5925      m = i;
5926    }
5927
5928    return r;
5929  };
5930
5931  Red.prototype.invm = function invm (a) {
5932    var inv = a._invmp(this.m);
5933    if (inv.negative !== 0) {
5934      inv.negative = 0;
5935      return this.imod(inv).redNeg();
5936    } else {
5937      return this.imod(inv);
5938    }
5939  };
5940
5941  Red.prototype.pow = function pow (a, num) {
5942    if (num.isZero()) return new BN(1)
vendor: 3,716 bytes, lines 5942-6101
5942;
5943    if (num.cmpn(1) === 0) return a.clone();
5944
5945    var windowSize = 4;
5946    var wnd = new Array(1 << windowSize);
5947    wnd[0] = new BN(1).toRed(this);
5948    wnd[1] = a;
5949    for (var i = 2; i < wnd.length; i++) {
5950      wnd[i] = this.mul(wnd[i - 1], a);
5951    }
5952
5953    var res = wnd[0];
5954    var current = 0;
5955    var currentLen = 0;
5956    var start = num.bitLength() % 26;
5957    if (start === 0) {
5958      start = 26;
5959    }
5960
5961    for (i = num.length - 1; i >= 0; i--) {
5962      var word = num.words[i];
5963      for (var j = start - 1; j >= 0; j--) {
5964        var bit = (word >> j) & 1;
5965        if (res !== wnd[0]) {
5966          res = this.sqr(res);
5967        }
5968
5969        if (bit === 0 && current === 0) {
5970          currentLen = 0;
5971          continue;
5972        }
5973
5974        current <<= 1;
5975        current |= bit;
5976        currentLen++;
5977        if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
5978
5979        res = this.mul(res, wnd[current]);
5980        currentLen = 0;
5981        current = 0;
5982      }
5983      start = 26;
5984    }
5985
5986    return res;
5987  };
5988
5989  Red.prototype.convertTo = function convertTo (num) {
5990    var r = num.umod(this.m);
5991
5992    return r === num ? r.clone() : r;
5993  };
5994
5995  Red.prototype.convertFrom = function convertFrom (num) {
5996    var res = num.clone();
5997    res.red = null;
5998    return res;
5999  };
6000
6001  //
6002  // Montgomery method engine
6003  //
6004
6005  BN.mont = function mont (num) {
6006    return new Mont(num);
6007  };
6008
6009  function Mont (m) {
6010    Red.call(this, m);
6011
6012    this.shift = this.m.bitLength();
6013    if (this.shift % 26 !== 0) {
6014      this.shift += 26 - (this.shift % 26);
6015    }
6016
6017    this.r = new BN(1).iushln(this.shift);
6018    this.r2 = this.imod(this.r.sqr());
6019    this.rinv = this.r._invmp(this.m);
6020
6021    this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
6022    this.minv = this.minv.umod(this.r);
6023    this.minv = this.r.sub(this.minv);
6024  }
6025  inherits(Mont, Red);
6026
6027  Mont.prototype.convertTo = function convertTo (num) {
6028    return this.imod(num.ushln(this.shift));
6029  };
6030
6031  Mont.prototype.convertFrom = function convertFrom (num) {
6032    var r = this.imod(num.mul(this.rinv));
6033    r.red = null;
6034    return r;
6035  };
6036
6037  Mont.prototype.imul = function imul (a, b) {
6038    if (a.isZero() || b.isZero()) {
6039      a.words[0] = 0;
6040      a.length = 1;
6041      return a;
6042    }
6043
6044    var t = a.imul(b);
6045    var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
6046    var u = t.isub(c).iushrn(this.shift);
6047    var res = u;
6048
6049    if (u.cmp(this.m) >= 0) {
6050      res = u.isub(this.m);
6051    } else if (u.cmpn(0) < 0) {
6052      res = u.iadd(this.m);
6053    }
6054
6055    return res._forceRed(this);
6056  };
6057
6058  Mont.prototype.mul = function mul (a, b) {
6059    if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
6060
6061    var t = a.mul(b);
6062    var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
6063    var u = t.isub(c).iushrn(this.shift);
6064    var res = u;
6065    if (u.cmp(this.m) >= 0) {
6066      res = u.isub(this.m);
6067    } else if (u.cmpn(0) < 0) {
6068      res = u.iadd(this.m);
6069    }
6070
6071    return res._forceRed(this);
6072  };
6073
6074  Mont.prototype.invm = function invm (a) {
6075    // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
6076    var res = this.imod(a._invmp(this.m).mul(this.r2));
6077    return res._forceRed(this);
6078  };
6079})(typeof module === 'undefined' || module, this);
6080
6081},{}],11:[function(require,module,exports){
6082
6083},{}],12:[function(require,module,exports){
6084/*!
6085 * The buffer module from node.js, for the browser.
6086 *
6087 * @author   Feross Aboukhadijeh <[email protected]> <http://feross.org>
6088 * @license  MIT
6089 */
6090/* eslint-disable no-proto */
6091
6092'use strict'
6093
6094var base64 = require('base64-js')
6095var ieee754 = require('ieee754')
6096
6097exports.Buffer = Buffer
6098exports.SlowBuffer = SlowBuffer
6099exports.INSPECT_MAX_BYTES = 50
6100
6101var K_MAX_LENGTH = 0x7fffffff
vendor: 10,342 bytes, lines 6102-6494
6102exports.kMaxLength = K_MAX_LENGTH
6103
6104/**
6105 * If `Buffer.TYPED_ARRAY_SUPPORT`:
6106 *   === true    Use Uint8Array implementation (fastest)
6107 *   === false   Print warning and recommend using `buffer` v4.x which has an Object
6108 *               implementation (most compatible, even IE6)
6109 *
6110 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
6111 * Opera 11.6+, iOS 4.2+.
6112 *
6113 * We report that the browser does not support typed arrays if the are not subclassable
6114 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
6115 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
6116 * for __proto__ and has a buggy typed array implementation.
6117 */
6118Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
6119
6120if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
6121    typeof console.error === 'function') {
6122  console.error(
6123    'This browser lacks typed array (Uint8Array) support which is required by ' +
6124    '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
6125  )
6126}
6127
6128function typedArraySupport () {
6129  // Can typed array instances can be augmented?
6130  try {
6131    var arr = new Uint8Array(1)
6132    arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
6133    return arr.foo() === 42
6134  } catch (e) {
6135    return false
6136  }
6137}
6138
6139function createBuffer (length) {
6140  if (length > K_MAX_LENGTH) {
6141    throw new RangeError('Invalid typed array length')
6142  }
6143  // Return an augmented `Uint8Array` instance
6144  var buf = new Uint8Array(length)
6145  buf.__proto__ = Buffer.prototype
6146  return buf
6147}
6148
6149/**
6150 * The Buffer constructor returns instances of `Uint8Array` that have their
6151 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
6152 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
6153 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
6154 * returns a single octet.
6155 *
6156 * The `Uint8Array` prototype remains unmodified.
6157 */
6158
6159function Buffer (arg, encodingOrOffset, length) {
6160  // Common case.
6161  if (typeof arg === 'number') {
6162    if (typeof encodingOrOffset === 'string') {
6163      throw new Error(
6164        'If encoding is specified then the first argument must be a string'
6165      )
6166    }
6167    return allocUnsafe(arg)
6168  }
6169  return from(arg, encodingOrOffset, length)
6170}
6171
6172// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
6173if (typeof Symbol !== 'undefined' && Symbol.species &&
6174    Buffer[Symbol.species] === Buffer) {
6175  Object.defineProperty(Buffer, Symbol.species, {
6176    value: null,
6177    configurable: true,
6178    enumerable: false,
6179    writable: false
6180  })
6181}
6182
6183Buffer.poolSize = 8192 // not used by this implementation
6184
6185function from (value, encodingOrOffset, length) {
6186  if (typeof value === 'number') {
6187    throw new TypeError('"value" argument must not be a number')
6188  }
6189
6190  if (value instanceof ArrayBuffer) {
6191    return fromArrayBuffer(value, encodingOrOffset, length)
6192  }
6193
6194  if (typeof value === 'string') {
6195    return fromString(value, encodingOrOffset)
6196  }
6197
6198  return fromObject(value)
6199}
6200
6201/**
6202 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
6203 * if value is a number.
6204 * Buffer.from(str[, encoding])
6205 * Buffer.from(array)
6206 * Buffer.from(buffer)
6207 * Buffer.from(arrayBuffer[, byteOffset[, length]])
6208 **/
6209Buffer.from = function (value, encodingOrOffset, length) {
6210  return from(value, encodingOrOffset, length)
6211}
6212
6213// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
6214// https://github.com/feross/buffer/pull/148
6215Buffer.prototype.__proto__ = Uint8Array.prototype
6216Buffer.__proto__ = Uint8Array
6217
6218function assertSize (size) {
6219  if (typeof size !== 'number') {
6220    throw new TypeError('"size" argument must be a number')
6221  } else if (size < 0) {
6222    throw new RangeError('"size" argument must not be negative')
6223  }
6224}
6225
6226function alloc (size, fill, encoding) {
6227  assertSize(size)
6228  if (size <= 0) {
6229    return createBuffer(size)
6230  }
6231  if (fill !== undefined) {
6232    // Only pay attention to encoding if it's a string. This
6233    // prevents accidentally sending in a number that would
6234    // be interpretted as a start offset.
6235    return typeof encoding === 'string'
6236      ? createBuffer(size).fill(fill, encoding)
6237      : createBuffer(size).fill(fill)
6238  }
6239  return createBuffer(size)
6240}
6241
6242/**
6243 * Creates a new filled Buffer instance.
6244 * alloc(size[, fill[, encoding]])
6245 **/
6246Buffer.alloc = function (size, fill, encoding) {
6247  return alloc(size, fill, encoding)
6248}
6249
6250function allocUnsafe (size) {
6251  assertSize(size)
6252  return createBuffer(size < 0 ? 0 : checked(size) | 0)
6253}
6254
6255/**
6256 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
6257 * */
6258Buffer.allocUnsafe = function (size) {
6259  return allocUnsafe(size)
6260}
6261/**
6262 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
6263 */
6264Buffer.allocUnsafeSlow = function (size) {
6265  return allocUnsafe(size)
6266}
6267
6268function fromString (string, encoding) {
6269  if (typeof encoding !== 'string' || encoding === '') {
6270    encoding = 'utf8'
6271  }
6272
6273  if (!Buffer.isEncoding(encoding)) {
6274    throw new TypeError('"encoding" must be a valid string encoding')
6275  }
6276
6277  var length = byteLength(string, encoding) | 0
6278  var buf = createBuffer(length)
6279
6280  var actual = buf.write(string, encoding)
6281
6282  if (actual !== length) {
6283    // Writing a hex string, for example, that contains invalid characters will
6284    // cause everything after the first invalid character to be ignored. (e.g.
6285    // 'abxxcd' will be treated as 'ab')
6286    buf = buf.slice(0, actual)
6287  }
6288
6289  return buf
6290}
6291
6292function fromArrayLike (array) {
6293  var length = array.length < 0 ? 0 : checked(array.length) | 0
6294  var buf = createBuffer(length)
6295  for (var i = 0; i < length; i += 1) {
6296    buf[i] = array[i] & 255
6297  }
6298  return buf
6299}
6300
6301function fromArrayBuffer (array, byteOffset, length) {
6302  if (byteOffset < 0 || array.byteLength < byteOffset) {
6303    throw new RangeError('\'offset\' is out of bounds')
6304  }
6305
6306  if (array.byteLength < byteOffset + (length || 0)) {
6307    throw new RangeError('\'length\' is out of bounds')
6308  }
6309
6310  var buf
6311  if (byteOffset === undefined && length === undefined) {
6312    buf = new Uint8Array(array)
6313  } else if (length === undefined) {
6314    buf = new Uint8Array(array, byteOffset)
6315  } else {
6316    buf = new Uint8Array(array, byteOffset, length)
6317  }
6318
6319  // Return an augmented `Uint8Array` instance
6320  buf.__proto__ = Buffer.prototype
6321  return buf
6322}
6323
6324function fromObject (obj) {
6325  if (Buffer.isBuffer(obj)) {
6326    var len = checked(obj.length) | 0
6327    var buf = createBuffer(len)
6328
6329    if (buf.length === 0) {
6330      return buf
6331    }
6332
6333    obj.copy(buf, 0, 0, len)
6334    return buf
6335  }
6336
6337  if (obj) {
6338    if (isArrayBufferView(obj) || 'length' in obj) {
6339      if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
6340        return createBuffer(0)
6341      }
6342      return fromArrayLike(obj)
6343    }
6344
6345    if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
6346      return fromArrayLike(obj.data)
6347    }
6348  }
6349
6350  throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
6351}
6352
6353function checked (length) {
6354  // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
6355  // length is NaN (which is otherwise coerced to zero.)
6356  if (length >= K_MAX_LENGTH) {
6357    throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
6358                         'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
6359  }
6360  return length | 0
6361}
6362
6363function SlowBuffer (length) {
6364  if (+length != length) { // eslint-disable-line eqeqeq
6365    length = 0
6366  }
6367  return Buffer.alloc(+length)
6368}
6369
6370Buffer.isBuffer = function isBuffer (b) {
6371  return b != null && b._isBuffer === true
6372}
6373
6374Buffer.compare = function compare (a, b) {
6375  if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
6376    throw new TypeError('Arguments must be Buffers')
6377  }
6378
6379  if (a === b) return 0
6380
6381  var x = a.length
6382  var y = b.length
6383
6384  for (var i = 0, len = Math.min(x, y); i < len; ++i) {
6385    if (a[i] !== b[i]) {
6386      x = a[i]
6387      y = b[i]
6388      break
6389    }
6390  }
6391
6392  if (x < y) return -1
6393  if (y < x) return 1
6394  return 0
6395}
6396
6397Buffer.isEncoding = function isEncoding (encoding) {
6398  switch (String(encoding).toLowerCase()) {
6399    case 'hex':
6400    case 'utf8':
6401    case 'utf-8':
6402    case 'ascii':
6403    case 'latin1':
6404    case 'binary':
6405    case 'base64':
6406    case 'ucs2':
6407    case 'ucs-2':
6408    case 'utf16le':
6409    case 'utf-16le':
6410      return true
6411    default:
6412      return false
6413  }
6414}
6415
6416Buffer.concat = function concat (list, length) {
6417  if (!Array.isArray(list)) {
6418    throw new TypeError('"list" argument must be an Array of Buffers')
6419  }
6420
6421  if (list.length === 0) {
6422    return Buffer.alloc(0)
6423  }
6424
6425  var i
6426  if (length === undefined) {
6427    length = 0
6428    for (i = 0; i < list.length; ++i) {
6429      length += list[i].length
6430    }
6431  }
6432
6433  var buffer = Buffer.allocUnsafe(length)
6434  var pos = 0
6435  for (i = 0; i < list.length; ++i) {
6436    var buf = list[i]
6437    if (!Buffer.isBuffer(buf)) {
6438      throw new TypeError('"list" argument must be an Array of Buffers')
6439    }
6440    buf.copy(buffer, pos)
6441    pos += buf.length
6442  }
6443  return buffer
6444}
6445
6446function byteLength (string, encoding) {
6447  if (Buffer.isBuffer(string)) {
6448    return string.length
6449  }
6450  if (isArrayBufferView(string) || string instanceof ArrayBuffer) {
6451    return string.byteLength
6452  }
6453  if (typeof string !== 'string') {
6454    string = '' + string
6455  }
6456
6457  var len = string.length
6458  if (len === 0) return 0
6459
6460  // Use a for loop to avoid recursion
6461  var loweredCase = false
6462  for (;;) {
6463    switch (encoding) {
6464      case 'ascii':
6465      case 'latin1':
6466      case 'binary':
6467        return len
6468      case 'utf8':
6469      case 'utf-8':
6470      case undefined:
6471        return utf8ToBytes(string).length
6472      case 'ucs2':
6473      case 'ucs-2':
6474      case 'utf16le':
6475      case 'utf-16le':
6476        return len * 2
6477      case 'hex':
6478        return len >>> 1
6479      case 'base64':
6480        return base64ToBytes(string).length
6481      default:
6482        if (loweredCase) return utf8ToBytes(string).length // assume utf8
6483        encoding = ('' + encoding).toLowerCase()
6484        loweredCase = true
6485    }
6486  }
6487}
6488Buffer.byteLength = byteLength
6489
6490function slowToString (encoding, start, end) {
6491  var loweredCase = false
6492
6493  // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
6494  // property of a typed array.
vendor: 6,395 bytes, lines 6495-6738
6495
6496  // This behaves neither like String nor Uint8Array in that we set start/end
6497  // to their upper/lower bounds if the value passed is out of range.
6498  // undefined is handled specially as per ECMA-262 6th Edition,
6499  // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
6500  if (start === undefined || start < 0) {
6501    start = 0
6502  }
6503  // Return early if start > this.length. Done here to prevent potential uint32
6504  // coercion fail below.
6505  if (start > this.length) {
6506    return ''
6507  }
6508
6509  if (end === undefined || end > this.length) {
6510    end = this.length
6511  }
6512
6513  if (end <= 0) {
6514    return ''
6515  }
6516
6517  // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
6518  end >>>= 0
6519  start >>>= 0
6520
6521  if (end <= start) {
6522    return ''
6523  }
6524
6525  if (!encoding) encoding = 'utf8'
6526
6527  while (true) {
6528    switch (encoding) {
6529      case 'hex':
6530        return hexSlice(this, start, end)
6531
6532      case 'utf8':
6533      case 'utf-8':
6534        return utf8Slice(this, start, end)
6535
6536      case 'ascii':
6537        return asciiSlice(this, start, end)
6538
6539      case 'latin1':
6540      case 'binary':
6541        return latin1Slice(this, start, end)
6542
6543      case 'base64':
6544        return base64Slice(this, start, end)
6545
6546      case 'ucs2':
6547      case 'ucs-2':
6548      case 'utf16le':
6549      case 'utf-16le':
6550        return utf16leSlice(this, start, end)
6551
6552      default:
6553        if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
6554        encoding = (encoding + '').toLowerCase()
6555        loweredCase = true
6556    }
6557  }
6558}
6559
6560// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
6561// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
6562// reliably in a browserify context because there could be multiple different
6563// copies of the 'buffer' package in use. This method works even for Buffer
6564// instances that were created from another copy of the `buffer` package.
6565// See: https://github.com/feross/buffer/issues/154
6566Buffer.prototype._isBuffer = true
6567
6568function swap (b, n, m) {
6569  var i = b[n]
6570  b[n] = b[m]
6571  b[m] = i
6572}
6573
6574Buffer.prototype.swap16 = function swap16 () {
6575  var len = this.length
6576  if (len % 2 !== 0) {
6577    throw new RangeError('Buffer size must be a multiple of 16-bits')
6578  }
6579  for (var i = 0; i < len; i += 2) {
6580    swap(this, i, i + 1)
6581  }
6582  return this
6583}
6584
6585Buffer.prototype.swap32 = function swap32 () {
6586  var len = this.length
6587  if (len % 4 !== 0) {
6588    throw new RangeError('Buffer size must be a multiple of 32-bits')
6589  }
6590  for (var i = 0; i < len; i += 4) {
6591    swap(this, i, i + 3)
6592    swap(this, i + 1, i + 2)
6593  }
6594  return this
6595}
6596
6597Buffer.prototype.swap64 = function swap64 () {
6598  var len = this.length
6599  if (len % 8 !== 0) {
6600    throw new RangeError('Buffer size must be a multiple of 64-bits')
6601  }
6602  for (var i = 0; i < len; i += 8) {
6603    swap(this, i, i + 7)
6604    swap(this, i + 1, i + 6)
6605    swap(this, i + 2, i + 5)
6606    swap(this, i + 3, i + 4)
6607  }
6608  return this
6609}
6610
6611Buffer.prototype.toString = function toString () {
6612  var length = this.length
6613  if (length === 0) return ''
6614  if (arguments.length === 0) return utf8Slice(this, 0, length)
6615  return slowToString.apply(this, arguments)
6616}
6617
6618Buffer.prototype.equals = function equals (b) {
6619  if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
6620  if (this === b) return true
6621  return Buffer.compare(this, b) === 0
6622}
6623
6624Buffer.prototype.inspect = function inspect () {
6625  var str = ''
6626  var max = exports.INSPECT_MAX_BYTES
6627  if (this.length > 0) {
6628    str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
6629    if (this.length > max) str += ' ... '
6630  }
6631  return '<Buffer ' + str + '>'
6632}
6633
6634Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
6635  if (!Buffer.isBuffer(target)) {
6636    throw new TypeError('Argument must be a Buffer')
6637  }
6638
6639  if (start === undefined) {
6640    start = 0
6641  }
6642  if (end === undefined) {
6643    end = target ? target.length : 0
6644  }
6645  if (thisStart === undefined) {
6646    thisStart = 0
6647  }
6648  if (thisEnd === undefined) {
6649    thisEnd = this.length
6650  }
6651
6652  if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
6653    throw new RangeError('out of range index')
6654  }
6655
6656  if (thisStart >= thisEnd && start >= end) {
6657    return 0
6658  }
6659  if (thisStart >= thisEnd) {
6660    return -1
6661  }
6662  if (start >= end) {
6663    return 1
6664  }
6665
6666  start >>>= 0
6667  end >>>= 0
6668  thisStart >>>= 0
6669  thisEnd >>>= 0
6670
6671  if (this === target) return 0
6672
6673  var x = thisEnd - thisStart
6674  var y = end - start
6675  var len = Math.min(x, y)
6676
6677  var thisCopy = this.slice(thisStart, thisEnd)
6678  var targetCopy = target.slice(start, end)
6679
6680  for (var i = 0; i < len; ++i) {
6681    if (thisCopy[i] !== targetCopy[i]) {
6682      x = thisCopy[i]
6683      y = targetCopy[i]
6684      break
6685    }
6686  }
6687
6688  if (x < y) return -1
6689  if (y < x) return 1
6690  return 0
6691}
6692
6693// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
6694// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
6695//
6696// Arguments:
6697// - buffer - a Buffer to search
6698// - val - a string, Buffer, or number
6699// - byteOffset - an index into `buffer`; will be clamped to an int32
6700// - encoding - an optional encoding, relevant is val is a string
6701// - dir - true for indexOf, false for lastIndexOf
6702function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
6703  // Empty buffer means no match
6704  if (buffer.length === 0) return -1
6705
6706  // Normalize byteOffset
6707  if (typeof byteOffset === 'string') {
6708    encoding = byteOffset
6709    byteOffset = 0
6710  } else if (byteOffset > 0x7fffffff) {
6711    byteOffset = 0x7fffffff
6712  } else if (byteOffset < -0x80000000) {
6713    byteOffset = -0x80000000
6714  }
6715  byteOffset = +byteOffset  // Coerce to Number.
6716  if (numberIsNaN(byteOffset)) {
6717    // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
6718    byteOffset = dir ? 0 : (buffer.length - 1)
6719  }
6720
6721  // Normalize byteOffset: negative offsets start from the end of the buffer
6722  if (byteOffset < 0) byteOffset = buffer.length + byteOffset
6723  if (byteOffset >= buffer.length) {
6724    if (dir) return -1
6725    else byteOffset = buffer.length - 1
6726  } else if (byteOffset < 0) {
6727    if (dir) byteOffset = 0
6728    else return -1
6729  }
6730
6731  // Normalize val
6732  if (typeof val === 'string') {
6733    val = Buffer.from(val, encoding)
6734  }
6735
6736  // Finally, search either indexOf (if dir is true) or lastIndexOf
6737  if (Buffer.isBuffer(val)) {
6738    // Special case: looking for empty string/buffer always fail
vendor: 6,275 bytes, lines 6738-6969
6738s
6739    if (val.length === 0) {
6740      return -1
6741    }
6742    return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
6743  } else if (typeof val === 'number') {
6744    val = val & 0xFF // Search for a byte value [0-255]
6745    if (typeof Uint8Array.prototype.indexOf === 'function') {
6746      if (dir) {
6747        return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
6748      } else {
6749        return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
6750      }
6751    }
6752    return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
6753  }
6754
6755  throw new TypeError('val must be string, number or Buffer')
6756}
6757
6758function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
6759  var indexSize = 1
6760  var arrLength = arr.length
6761  var valLength = val.length
6762
6763  if (encoding !== undefined) {
6764    encoding = String(encoding).toLowerCase()
6765    if (encoding === 'ucs2' || encoding === 'ucs-2' ||
6766        encoding === 'utf16le' || encoding === 'utf-16le') {
6767      if (arr.length < 2 || val.length < 2) {
6768        return -1
6769      }
6770      indexSize = 2
6771      arrLength /= 2
6772      valLength /= 2
6773      byteOffset /= 2
6774    }
6775  }
6776
6777  function read (buf, i) {
6778    if (indexSize === 1) {
6779      return buf[i]
6780    } else {
6781      return buf.readUInt16BE(i * indexSize)
6782    }
6783  }
6784
6785  var i
6786  if (dir) {
6787    var foundIndex = -1
6788    for (i = byteOffset; i < arrLength; i++) {
6789      if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
6790        if (foundIndex === -1) foundIndex = i
6791        if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
6792      } else {
6793        if (foundIndex !== -1) i -= i - foundIndex
6794        foundIndex = -1
6795      }
6796    }
6797  } else {
6798    if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
6799    for (i = byteOffset; i >= 0; i--) {
6800      var found = true
6801      for (var j = 0; j < valLength; j++) {
6802        if (read(arr, i + j) !== read(val, j)) {
6803          found = false
6804          break
6805        }
6806      }
6807      if (found) return i
6808    }
6809  }
6810
6811  return -1
6812}
6813
6814Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
6815  return this.indexOf(val, byteOffset, encoding) !== -1
6816}
6817
6818Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
6819  return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
6820}
6821
6822Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
6823  return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
6824}
6825
6826function hexWrite (buf, string, offset, length) {
6827  offset = Number(offset) || 0
6828  var remaining = buf.length - offset
6829  if (!length) {
6830    length = remaining
6831  } else {
6832    length = Number(length)
6833    if (length > remaining) {
6834      length = remaining
6835    }
6836  }
6837
6838  // must be an even number of digits
6839  var strLen = string.length
6840  if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
6841
6842  if (length > strLen / 2) {
6843    length = strLen / 2
6844  }
6845  for (var i = 0; i < length; ++i) {
6846    var parsed = parseInt(string.substr(i * 2, 2), 16)
6847    if (numberIsNaN(parsed)) return i
6848    buf[offset + i] = parsed
6849  }
6850  return i
6851}
6852
6853function utf8Write (buf, string, offset, length) {
6854  return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
6855}
6856
6857function asciiWrite (buf, string, offset, length) {
6858  return blitBuffer(asciiToBytes(string), buf, offset, length)
6859}
6860
6861function latin1Write (buf, string, offset, length) {
6862  return asciiWrite(buf, string, offset, length)
6863}
6864
6865function base64Write (buf, string, offset, length) {
6866  return blitBuffer(base64ToBytes(string), buf, offset, length)
6867}
6868
6869function ucs2Write (buf, string, offset, length) {
6870  return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
6871}
6872
6873Buffer.prototype.write = function write (string, offset, length, encoding) {
6874  // Buffer#write(string)
6875  if (offset === undefined) {
6876    encoding = 'utf8'
6877    length = this.length
6878    offset = 0
6879  // Buffer#write(string, encoding)
6880  } else if (length === undefined && typeof offset === 'string') {
6881    encoding = offset
6882    length = this.length
6883    offset = 0
6884  // Buffer#write(string, offset[, length][, encoding])
6885  } else if (isFinite(offset)) {
6886    offset = offset >>> 0
6887    if (isFinite(length)) {
6888      length = length >>> 0
6889      if (encoding === undefined) encoding = 'utf8'
6890    } else {
6891      encoding = length
6892      length = undefined
6893    }
6894  } else {
6895    throw new Error(
6896      'Buffer.write(string, encoding, offset[, length]) is no longer supported'
6897    )
6898  }
6899
6900  var remaining = this.length - offset
6901  if (length === undefined || length > remaining) length = remaining
6902
6903  if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
6904    throw new RangeError('Attempt to write outside buffer bounds')
6905  }
6906
6907  if (!encoding) encoding = 'utf8'
6908
6909  var loweredCase = false
6910  for (;;) {
6911    switch (encoding) {
6912      case 'hex':
6913        return hexWrite(this, string, offset, length)
6914
6915      case 'utf8':
6916      case 'utf-8':
6917        return utf8Write(this, string, offset, length)
6918
6919      case 'ascii':
6920        return asciiWrite(this, string, offset, length)
6921
6922      case 'latin1':
6923      case 'binary':
6924        return latin1Write(this, string, offset, length)
6925
6926      case 'base64':
6927        // Warning: maxLength not taken into account in base64Write
6928        return base64Write(this, string, offset, length)
6929
6930      case 'ucs2':
6931      case 'ucs-2':
6932      case 'utf16le':
6933      case 'utf-16le':
6934        return ucs2Write(this, string, offset, length)
6935
6936      default:
6937        if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
6938        encoding = ('' + encoding).toLowerCase()
6939        loweredCase = true
6940    }
6941  }
6942}
6943
6944Buffer.prototype.toJSON = function toJSON () {
6945  return {
6946    type: 'Buffer',
6947    data: Array.prototype.slice.call(this._arr || this, 0)
6948  }
6949}
6950
6951function base64Slice (buf, start, end) {
6952  if (start === 0 && end === buf.length) {
6953    return base64.fromByteArray(buf)
6954  } else {
6955    return base64.fromByteArray(buf.slice(start, end))
6956  }
6957}
6958
6959function utf8Slice (buf, start, end) {
6960  end = Math.min(buf.length, end)
6961  var res = []
6962
6963  var i = start
6964  while (i < end) {
6965    var firstByte = buf[i]
6966    var codePoint = null
6967    var bytesPerSequence = (firstByte > 0xEF) ? 4
6968      : (firstByte > 0xDF) ? 3
6969      : (firstByte > 0xBF) ? 2
vendor: 16,210 bytes, lines 6970-7533
6970      : 1
6971
6972    if (i + bytesPerSequence <= end) {
6973      var secondByte, thirdByte, fourthByte, tempCodePoint
6974
6975      switch (bytesPerSequence) {
6976        case 1:
6977          if (firstByte < 0x80) {
6978            codePoint = firstByte
6979          }
6980          break
6981        case 2:
6982          secondByte = buf[i + 1]
6983          if ((secondByte & 0xC0) === 0x80) {
6984            tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
6985            if (tempCodePoint > 0x7F) {
6986              codePoint = tempCodePoint
6987            }
6988          }
6989          break
6990        case 3:
6991          secondByte = buf[i + 1]
6992          thirdByte = buf[i + 2]
6993          if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
6994            tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
6995            if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
6996              codePoint = tempCodePoint
6997            }
6998          }
6999          break
7000        case 4:
7001          secondByte = buf[i + 1]
7002          thirdByte = buf[i + 2]
7003          fourthByte = buf[i + 3]
7004          if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
7005            tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
7006            if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
7007              codePoint = tempCodePoint
7008            }
7009          }
7010      }
7011    }
7012
7013    if (codePoint === null) {
7014      // we did not generate a valid codePoint so insert a
7015      // replacement char (U+FFFD) and advance only 1 byte
7016      codePoint = 0xFFFD
7017      bytesPerSequence = 1
7018    } else if (codePoint > 0xFFFF) {
7019      // encode to utf16 (surrogate pair dance)
7020      codePoint -= 0x10000
7021      res.push(codePoint >>> 10 & 0x3FF | 0xD800)
7022      codePoint = 0xDC00 | codePoint & 0x3FF
7023    }
7024
7025    res.push(codePoint)
7026    i += bytesPerSequence
7027  }
7028
7029  return decodeCodePointsArray(res)
7030}
7031
7032// Based on http://stackoverflow.com/a/22747272/680742, the browser with
7033// the lowest limit is Chrome, with 0x10000 args.
7034// We go 1 magnitude less, for safety
7035var MAX_ARGUMENTS_LENGTH = 0x1000
7036
7037function decodeCodePointsArray (codePoints) {
7038  var len = codePoints.length
7039  if (len <= MAX_ARGUMENTS_LENGTH) {
7040    return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
7041  }
7042
7043  // Decode in chunks to avoid "call stack size exceeded".
7044  var res = ''
7045  var i = 0
7046  while (i < len) {
7047    res += String.fromCharCode.apply(
7048      String,
7049      codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
7050    )
7051  }
7052  return res
7053}
7054
7055function asciiSlice (buf, start, end) {
7056  var ret = ''
7057  end = Math.min(buf.length, end)
7058
7059  for (var i = start; i < end; ++i) {
7060    ret += String.fromCharCode(buf[i] & 0x7F)
7061  }
7062  return ret
7063}
7064
7065function latin1Slice (buf, start, end) {
7066  var ret = ''
7067  end = Math.min(buf.length, end)
7068
7069  for (var i = start; i < end; ++i) {
7070    ret += String.fromCharCode(buf[i])
7071  }
7072  return ret
7073}
7074
7075function hexSlice (buf, start, end) {
7076  var len = buf.length
7077
7078  if (!start || start < 0) start = 0
7079  if (!end || end < 0 || end > len) end = len
7080
7081  var out = ''
7082  for (var i = start; i < end; ++i) {
7083    out += toHex(buf[i])
7084  }
7085  return out
7086}
7087
7088function utf16leSlice (buf, start, end) {
7089  var bytes = buf.slice(start, end)
7090  var res = ''
7091  for (var i = 0; i < bytes.length; i += 2) {
7092    res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
7093  }
7094  return res
7095}
7096
7097Buffer.prototype.slice = function slice (start, end) {
7098  var len = this.length
7099  start = ~~start
7100  end = end === undefined ? len : ~~end
7101
7102  if (start < 0) {
7103    start += len
7104    if (start < 0) start = 0
7105  } else if (start > len) {
7106    start = len
7107  }
7108
7109  if (end < 0) {
7110    end += len
7111    if (end < 0) end = 0
7112  } else if (end > len) {
7113    end = len
7114  }
7115
7116  if (end < start) end = start
7117
7118  var newBuf = this.subarray(start, end)
7119  // Return an augmented `Uint8Array` instance
7120  newBuf.__proto__ = Buffer.prototype
7121  return newBuf
7122}
7123
7124/*
7125 * Need to make sure that buffer isn't trying to write out of bounds.
7126 */
7127function checkOffset (offset, ext, length) {
7128  if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
7129  if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
7130}
7131
7132Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
7133  offset = offset >>> 0
7134  byteLength = byteLength >>> 0
7135  if (!noAssert) checkOffset(offset, byteLength, this.length)
7136
7137  var val = this[offset]
7138  var mul = 1
7139  var i = 0
7140  while (++i < byteLength && (mul *= 0x100)) {
7141    val += this[offset + i] * mul
7142  }
7143
7144  return val
7145}
7146
7147Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
7148  offset = offset >>> 0
7149  byteLength = byteLength >>> 0
7150  if (!noAssert) {
7151    checkOffset(offset, byteLength, this.length)
7152  }
7153
7154  var val = this[offset + --byteLength]
7155  var mul = 1
7156  while (byteLength > 0 && (mul *= 0x100)) {
7157    val += this[offset + --byteLength] * mul
7158  }
7159
7160  return val
7161}
7162
7163Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
7164  offset = offset >>> 0
7165  if (!noAssert) checkOffset(offset, 1, this.length)
7166  return this[offset]
7167}
7168
7169Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
7170  offset = offset >>> 0
7171  if (!noAssert) checkOffset(offset, 2, this.length)
7172  return this[offset] | (this[offset + 1] << 8)
7173}
7174
7175Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
7176  offset = offset >>> 0
7177  if (!noAssert) checkOffset(offset, 2, this.length)
7178  return (this[offset] << 8) | this[offset + 1]
7179}
7180
7181Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
7182  offset = offset >>> 0
7183  if (!noAssert) checkOffset(offset, 4, this.length)
7184
7185  return ((this[offset]) |
7186      (this[offset + 1] << 8) |
7187      (this[offset + 2] << 16)) +
7188      (this[offset + 3] * 0x1000000)
7189}
7190
7191Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
7192  offset = offset >>> 0
7193  if (!noAssert) checkOffset(offset, 4, this.length)
7194
7195  return (this[offset] * 0x1000000) +
7196    ((this[offset + 1] << 16) |
7197    (this[offset + 2] << 8) |
7198    this[offset + 3])
7199}
7200
7201Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
7202  offset = offset >>> 0
7203  byteLength = byteLength >>> 0
7204  if (!noAssert) checkOffset(offset, byteLength, this.length)
7205
7206  var val = this[offset]
7207  var mul = 1
7208  var i = 0
7209  while (++i < byteLength && (mul *= 0x100)) {
7210    val += this[offset + i] * mul
7211  }
7212  mul *= 0x80
7213
7214  if (val >= mul) val -= Math.pow(2, 8 * byteLength)
7215
7216  return val
7217}
7218
7219Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
7220  offset = offset >>> 0
7221  byteLength = byteLength >>> 0
7222  if (!noAssert) checkOffset(offset, byteLength, this.length)
7223
7224  var i = byteLength
7225  var mul = 1
7226  var val = this[offset + --i]
7227  while (i > 0 && (mul *= 0x100)) {
7228    val += this[offset + --i] * mul
7229  }
7230  mul *= 0x80
7231
7232  if (val >= mul) val -= Math.pow(2, 8 * byteLength)
7233
7234  return val
7235}
7236
7237Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
7238  offset = offset >>> 0
7239  if (!noAssert) checkOffset(offset, 1, this.length)
7240  if (!(this[offset] & 0x80)) return (this[offset])
7241  return ((0xff - this[offset] + 1) * -1)
7242}
7243
7244Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
7245  offset = offset >>> 0
7246  if (!noAssert) checkOffset(offset, 2, this.length)
7247  var val = this[offset] | (this[offset + 1] << 8)
7248  return (val & 0x8000) ? val | 0xFFFF0000 : val
7249}
7250
7251Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
7252  offset = offset >>> 0
7253  if (!noAssert) checkOffset(offset, 2, this.length)
7254  var val = this[offset + 1] | (this[offset] << 8)
7255  return (val & 0x8000) ? val | 0xFFFF0000 : val
7256}
7257
7258Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
7259  offset = offset >>> 0
7260  if (!noAssert) checkOffset(offset, 4, this.length)
7261
7262  return (this[offset]) |
7263    (this[offset + 1] << 8) |
7264    (this[offset + 2] << 16) |
7265    (this[offset + 3] << 24)
7266}
7267
7268Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
7269  offset = offset >>> 0
7270  if (!noAssert) checkOffset(offset, 4, this.length)
7271
7272  return (this[offset] << 24) |
7273    (this[offset + 1] << 16) |
7274    (this[offset + 2] << 8) |
7275    (this[offset + 3])
7276}
7277
7278Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
7279  offset = offset >>> 0
7280  if (!noAssert) checkOffset(offset, 4, this.length)
7281  return ieee754.read(this, offset, true, 23, 4)
7282}
7283
7284Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
7285  offset = offset >>> 0
7286  if (!noAssert) checkOffset(offset, 4, this.length)
7287  return ieee754.read(this, offset, false, 23, 4)
7288}
7289
7290Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
7291  offset = offset >>> 0
7292  if (!noAssert) checkOffset(offset, 8, this.length)
7293  return ieee754.read(this, offset, true, 52, 8)
7294}
7295
7296Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
7297  offset = offset >>> 0
7298  if (!noAssert) checkOffset(offset, 8, this.length)
7299  return ieee754.read(this, offset, false, 52, 8)
7300}
7301
7302function checkInt (buf, value, offset, ext, max, min) {
7303  if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
7304  if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
7305  if (offset + ext > buf.length) throw new RangeError('Index out of range')
7306}
7307
7308Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
7309  value = +value
7310  offset = offset >>> 0
7311  byteLength = byteLength >>> 0
7312  if (!noAssert) {
7313    var maxBytes = Math.pow(2, 8 * byteLength) - 1
7314    checkInt(this, value, offset, byteLength, maxBytes, 0)
7315  }
7316
7317  var mul = 1
7318  var i = 0
7319  this[offset] = value & 0xFF
7320  while (++i < byteLength && (mul *= 0x100)) {
7321    this[offset + i] = (value / mul) & 0xFF
7322  }
7323
7324  return offset + byteLength
7325}
7326
7327Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
7328  value = +value
7329  offset = offset >>> 0
7330  byteLength = byteLength >>> 0
7331  if (!noAssert) {
7332    var maxBytes = Math.pow(2, 8 * byteLength) - 1
7333    checkInt(this, value, offset, byteLength, maxBytes, 0)
7334  }
7335
7336  var i = byteLength - 1
7337  var mul = 1
7338  this[offset + i] = value & 0xFF
7339  while (--i >= 0 && (mul *= 0x100)) {
7340    this[offset + i] = (value / mul) & 0xFF
7341  }
7342
7343  return offset + byteLength
7344}
7345
7346Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
7347  value = +value
7348  offset = offset >>> 0
7349  if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
7350  this[offset] = (value & 0xff)
7351  return offset + 1
7352}
7353
7354Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
7355  value = +value
7356  offset = offset >>> 0
7357  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
7358  this[offset] = (value & 0xff)
7359  this[offset + 1] = (value >>> 8)
7360  return offset + 2
7361}
7362
7363Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
7364  value = +value
7365  offset = offset >>> 0
7366  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
7367  this[offset] = (value >>> 8)
7368  this[offset + 1] = (value & 0xff)
7369  return offset + 2
7370}
7371
7372Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
7373  value = +value
7374  offset = offset >>> 0
7375  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
7376  this[offset + 3] = (value >>> 24)
7377  this[offset + 2] = (value >>> 16)
7378  this[offset + 1] = (value >>> 8)
7379  this[offset] = (value & 0xff)
7380  return offset + 4
7381}
7382
7383Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
7384  value = +value
7385  offset = offset >>> 0
7386  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
7387  this[offset] = (value >>> 24)
7388  this[offset + 1] = (value >>> 16)
7389  this[offset + 2] = (value >>> 8)
7390  this[offset + 3] = (value & 0xff)
7391  return offset + 4
7392}
7393
7394Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
7395  value = +value
7396  offset = offset >>> 0
7397  if (!noAssert) {
7398    var limit = Math.pow(2, (8 * byteLength) - 1)
7399
7400    checkInt(this, value, offset, byteLength, limit - 1, -limit)
7401  }
7402
7403  var i = 0
7404  var mul = 1
7405  var sub = 0
7406  this[offset] = value & 0xFF
7407  while (++i < byteLength && (mul *= 0x100)) {
7408    if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
7409      sub = 1
7410    }
7411    this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
7412  }
7413
7414  return offset + byteLength
7415}
7416
7417Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
7418  value = +value
7419  offset = offset >>> 0
7420  if (!noAssert) {
7421    var limit = Math.pow(2, (8 * byteLength) - 1)
7422
7423    checkInt(this, value, offset, byteLength, limit - 1, -limit)
7424  }
7425
7426  var i = byteLength - 1
7427  var mul = 1
7428  var sub = 0
7429  this[offset + i] = value & 0xFF
7430  while (--i >= 0 && (mul *= 0x100)) {
7431    if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
7432      sub = 1
7433    }
7434    this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
7435  }
7436
7437  return offset + byteLength
7438}
7439
7440Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
7441  value = +value
7442  offset = offset >>> 0
7443  if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
7444  if (value < 0) value = 0xff + value + 1
7445  this[offset] = (value & 0xff)
7446  return offset + 1
7447}
7448
7449Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
7450  value = +value
7451  offset = offset >>> 0
7452  if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
7453  this[offset] = (value & 0xff)
7454  this[offset + 1] = (value >>> 8)
7455  return offset + 2
7456}
7457
7458Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
7459  value = +value
7460  offset = offset >>> 0
7461  if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
7462  this[offset] = (value >>> 8)
7463  this[offset + 1] = (value & 0xff)
7464  return offset + 2
7465}
7466
7467Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
7468  value = +value
7469  offset = offset >>> 0
7470  if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
7471  this[offset] = (value & 0xff)
7472  this[offset + 1] = (value >>> 8)
7473  this[offset + 2] = (value >>> 16)
7474  this[offset + 3] = (value >>> 24)
7475  return offset + 4
7476}
7477
7478Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
7479  value = +value
7480  offset = offset >>> 0
7481  if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
7482  if (value < 0) value = 0xffffffff + value + 1
7483  this[offset] = (value >>> 24)
7484  this[offset + 1] = (value >>> 16)
7485  this[offset + 2] = (value >>> 8)
7486  this[offset + 3] = (value & 0xff)
7487  return offset + 4
7488}
7489
7490function checkIEEE754 (buf, value, offset, ext, max, min) {
7491  if (offset + ext > buf.length) throw new RangeError('Index out of range')
7492  if (offset < 0) throw new RangeError('Index out of range')
7493}
7494
7495function writeFloat (buf, value, offset, littleEndian, noAssert) {
7496  value = +value
7497  offset = offset >>> 0
7498  if (!noAssert) {
7499    checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
7500  }
7501  ieee754.write(buf, value, offset, littleEndian, 23, 4)
7502  return offset + 4
7503}
7504
7505Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
7506  return writeFloat(this, value, offset, true, noAssert)
7507}
7508
7509Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
7510  return writeFloat(this, value, offset, false, noAssert)
7511}
7512
7513function writeDouble (buf, value, offset, littleEndian, noAssert) {
7514  value = +value
7515  offset = offset >>> 0
7516  if (!noAssert) {
7517    checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
7518  }
7519  ieee754.write(buf, value, offset, littleEndian, 52, 8)
7520  return offset + 8
7521}
7522
7523Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
7524  return writeDouble(this, value, offset, true, noAssert)
7525}
7526
7527Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
7528  return writeDouble(this, value, offset, false, noAssert)
7529}
7530
7531// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
7532Buffer.prototype.copy = function copy (target, targetStart, start, end) {
7533  if (!
vendor: 4,905 bytes, lines 7533-7719
7533start) start = 0
7534  if (!end && end !== 0) end = this.length
7535  if (targetStart >= target.length) targetStart = target.length
7536  if (!targetStart) targetStart = 0
7537  if (end > 0 && end < start) end = start
7538
7539  // Copy 0 bytes; we're done
7540  if (end === start) return 0
7541  if (target.length === 0 || this.length === 0) return 0
7542
7543  // Fatal error conditions
7544  if (targetStart < 0) {
7545    throw new RangeError('targetStart out of bounds')
7546  }
7547  if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
7548  if (end < 0) throw new RangeError('sourceEnd out of bounds')
7549
7550  // Are we oob?
7551  if (end > this.length) end = this.length
7552  if (target.length - targetStart < end - start) {
7553    end = target.length - targetStart + start
7554  }
7555
7556  var len = end - start
7557  var i
7558
7559  if (this === target && start < targetStart && targetStart < end) {
7560    // descending copy from end
7561    for (i = len - 1; i >= 0; --i) {
7562      target[i + targetStart] = this[i + start]
7563    }
7564  } else if (len < 1000) {
7565    // ascending copy from start
7566    for (i = 0; i < len; ++i) {
7567      target[i + targetStart] = this[i + start]
7568    }
7569  } else {
7570    Uint8Array.prototype.set.call(
7571      target,
7572      this.subarray(start, start + len),
7573      targetStart
7574    )
7575  }
7576
7577  return len
7578}
7579
7580// Usage:
7581//    buffer.fill(number[, offset[, end]])
7582//    buffer.fill(buffer[, offset[, end]])
7583//    buffer.fill(string[, offset[, end]][, encoding])
7584Buffer.prototype.fill = function fill (val, start, end, encoding) {
7585  // Handle string cases:
7586  if (typeof val === 'string') {
7587    if (typeof start === 'string') {
7588      encoding = start
7589      start = 0
7590      end = this.length
7591    } else if (typeof end === 'string') {
7592      encoding = end
7593      end = this.length
7594    }
7595    if (val.length === 1) {
7596      var code = val.charCodeAt(0)
7597      if (code < 256) {
7598        val = code
7599      }
7600    }
7601    if (encoding !== undefined && typeof encoding !== 'string') {
7602      throw new TypeError('encoding must be a string')
7603    }
7604    if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
7605      throw new TypeError('Unknown encoding: ' + encoding)
7606    }
7607  } else if (typeof val === 'number') {
7608    val = val & 255
7609  }
7610
7611  // Invalid ranges are not set to a default, so can range check early.
7612  if (start < 0 || this.length < start || this.length < end) {
7613    throw new RangeError('Out of range index')
7614  }
7615
7616  if (end <= start) {
7617    return this
7618  }
7619
7620  start = start >>> 0
7621  end = end === undefined ? this.length : end >>> 0
7622
7623  if (!val) val = 0
7624
7625  var i
7626  if (typeof val === 'number') {
7627    for (i = start; i < end; ++i) {
7628      this[i] = val
7629    }
7630  } else {
7631    var bytes = Buffer.isBuffer(val)
7632      ? val
7633      : new Buffer(val, encoding)
7634    var len = bytes.length
7635    for (i = 0; i < end - start; ++i) {
7636      this[i + start] = bytes[i % len]
7637    }
7638  }
7639
7640  return this
7641}
7642
7643// HELPER FUNCTIONS
7644// ================
7645
7646var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
7647
7648function base64clean (str) {
7649  // Node strips out invalid characters like \n and \t from the string, base64-js does not
7650  str = str.trim().replace(INVALID_BASE64_RE, '')
7651  // Node converts strings with length < 2 to ''
7652  if (str.length < 2) return ''
7653  // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
7654  while (str.length % 4 !== 0) {
7655    str = str + '='
7656  }
7657  return str
7658}
7659
7660function toHex (n) {
7661  if (n < 16) return '0' + n.toString(16)
7662  return n.toString(16)
7663}
7664
7665function utf8ToBytes (string, units) {
7666  units = units || Infinity
7667  var codePoint
7668  var length = string.length
7669  var leadSurrogate = null
7670  var bytes = []
7671
7672  for (var i = 0; i < length; ++i) {
7673    codePoint = string.charCodeAt(i)
7674
7675    // is surrogate component
7676    if (codePoint > 0xD7FF && codePoint < 0xE000) {
7677      // last char was a lead
7678      if (!leadSurrogate) {
7679        // no lead yet
7680        if (codePoint > 0xDBFF) {
7681          // unexpected trail
7682          if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
7683          continue
7684        } else if (i + 1 === length) {
7685          // unpaired lead
7686          if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
7687          continue
7688        }
7689
7690        // valid lead
7691        leadSurrogate = codePoint
7692
7693        continue
7694      }
7695
7696      // 2 leads in a row
7697      if (codePoint < 0xDC00) {
7698        if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
7699        leadSurrogate = codePoint
7700        continue
7701      }
7702
7703      // valid surrogate pair
7704      codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
7705    } else if (leadSurrogate) {
7706      // valid bmp char, but last char was a lead
7707      if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
7708    }
7709
7710    leadSurrogate = null
7711
7712    // encode utf8
7713    if (codePoint < 0x80) {
7714      if ((units -= 1) < 0) break
7715      bytes.push(codePoint)
7716    } else if (codePoint < 0x800) {
7717      if ((units -= 2) < 0) break
7718      bytes.push(
7719        codePoint >> 0x6 | 0xC0,
7720        codePoint & 0x3F | 0x80
7721      )
7722    } else if (codePoint < 0x10000) {
7723      if ((units -= 3) < 0) break
7724      bytes.push(
7725        codePoint >> 0xC | 0xE0,
7726        codePoint >> 0x6 & 0x3F | 0x80,
7727        codePoint & 0x3F | 0x80
7728      )
7729    } else if (codePoint < 0x110000) {
7730      if ((units -= 4) < 0) break
7731      bytes.push(
7732        codePoint >> 0x12 | 0xF0,
7733        codePoint >> 0xC & 0x3F | 0x80,
7734        codePoint >> 0x6 & 0x3F | 0x80,
7735        codePoint & 0x3F | 0x80
7736      )
7737    } else {
7738      throw new Error('Invalid code point')
7739    }
7740  }
7741
7742  return bytes
7743}
7744
7745function asciiToBytes (str) {
7746  var byteArray = []
7747  for (var i = 0; i < str.length; ++i) {
7748    // Node's code seems to be doing this and not & 0x7F..
7749    byteArray.push(str.charCodeAt(i) & 0xFF)
7750  }
7751  return byteArray
7752}
7753
7754function utf16leToBytes (str, units) {
7755  var c, hi, lo
7756  var byteArray = []
7757  for (var i = 0; i < str.length; ++i) {
7758    if ((units -= 2) < 0) break
7759
7760    c = str.charCodeAt(i)
7761    hi = c >> 8
7762    lo = c % 256
7763    byteArray.push(lo)
7764    byteArray.push(hi)
7765  }
7766
7767  return byteArray
7768}
7769
7770function base64ToBytes (str) {
7771  return base64.toByteArray(base64clean(str))
7772}
7773
7774function blitBuffer (src, dst, offset, length) {
7775  for (var i = 0; i < length; ++i) {
7776    if ((i + offset >= dst.length) || (i >= src.length)) break
7777    dst[i + offset] = src[i]
7778  }
7779  return i
7780}
7781
7782// Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
7783function isArrayBufferView (obj) {
7784  return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj)
7785}
7786
7787function numberIsNaN (obj) {
7788  return obj !== obj // eslint-disable-line no-self-compare
7789}
7790
7791},{"base64-js":9,"ieee754":15}],13:[function(require,module,exports){
7792(function (Buffer){
7793'use strict';
7794
7795/* eslint-disable */
7796
7797var utils = require('./utils/index.js');
7798var uint256Coder = utils.uint256Coder;
7799var coderBoolean = utils.coderBoolean;
7800var coderFixedBytes = utils.coderFixedBytes;
7801var coderAddress = utils.coderAddress;
7802var coderDynamicBytes = utils.coderDynamicBytes;
7803var coderString = utils.coderString;
7804var coderArray = utils.coderArray;
7805var paramTypePart = utils.paramTypePart;
7806var getParamCoder = utils.getParamCoder;
7807
7808function Result() {}
7809
7810function encodeParams(types, values) {
7811  if (types.length !== values.length) {
7812    throw new Error('[ethjs-abi] while encoding params, types/values mismatch, types length ' + types.length + ' should be ' + values.length);
7813  }
7814
7815  var parts = [];
7816
7817  types.forEach(function (type, index) {
7818    var coder = getParamCoder(type);
7819    parts.push({ dynamic: coder.dynamic, value: coder.encode(values[index]) });
7820  });
7821
7822  function alignSize(size) {
7823    return parseInt(32 * Math.ceil(size / 32));
7824  }
7825
7826  var staticSize = 0,
7827      dynamicSize = 0;
7828  parts.forEach(function (part) {
7829    if (part.dynamic) {
7830      staticSize += 32;
7831      dynamicSize += alignSize(part.value.length);
7832    } else {
7833      staticSize += alignSize(part.value.length);
7834    }
7835  });
7836
7837  var offset = 0,
7838      dynamicOffset = staticSize;
7839  var data = new Buffer(staticSize + dynamicSize);
7840
7841  parts.forEach(function (part, index) {
7842    if (part.dynamic) {
7843      uint256Coder.encode(dynamicOffset).copy(data, offset);
7844      offset += 32;
7845
7846      part.value.copy(data, dynamicOffset);
7847      dynamicOffset += alignSize(part.value.length);
7848    } else {
7849      part.value.copy(data, offset);
7850      offset += alignSize(part.value.length);
7851    }
7852  });
7853
7854  return '0x' + data.toString('hex');
7855}
7856
7857// decode bytecode data from output names and types
7858function decodeParams(names, types, data) {
7859  // Names is optional, so shift over all the parameters if not provided
7860  if (arguments.length < 3) {
7861    data = types;
7862    types = names;
7863    names = [];
7864  }
7865
7866  data = utils.hexOrBuffer(data);
7867  var values = new Result();
7868
7869  var offset = 0;
7870  types.forEach(function (type, index) {
7871    var coder = getParamCoder(type);
7872    if (coder.dynamic) {
7873      var dynamicOffset = uint256Coder.decode(data, offset);
7874      var result = coder.decode(data, dynamicOffset.value.toNumber());
7875      offset += dynamicOffset.consumed;
7876    } else {
7877      var result = coder.decode(data, offset);
7878      offset += result.consumed;
7879    }
7880    values[index] = result.value;
7881    if (names[index]) {
7882      values[names[index]] = result.value;
7883    }
7884  });
7885  return values;
7886}
7887
7888// encode method ABI object with values in an array, output bytecode
7889function encodeMethod(method, values) {
7890  var signature = method.name + '(' + utils.getKeys(method.inputs, 'type').join(',') + ')';
7891  var signatureEncoded = '0x' + new Buffer(utils.keccak256(signature), 'hex').slice(0, 4).toString('hex');
7892  var paramsEncoded = encodeParams(utils.getKeys(method.inputs, 'type'), values).substring(2);
7893
7894  return '' + signatureEncoded + paramsEncoded;
7895}
7896
7897// decode method data bytecode, from method ABI object
7898function decodeMethod(method, data) {
7899  var outputNames = utils.getKeys(method.outputs, 'name', true);
7900  var outputTypes = utils.getKeys(method.outputs, 'type');
7901
7902  return decodeParams(outputNames, outputTypes, utils.hexOrBuffer(data));
7903}
7904
7905// decode method data bytecode, from method ABI object
7906function encodeEvent(eventObject, values) {
7907  return encodeMethod(eventObject, values);
7908}
7909
7910// decode method data bytecode, from method ABI object
7911function decodeEvent(eventObject, data) {
7912  var inputNames = utils.getKeys(eventObject.inputs, 'name', true);
7913  var inputTypes = utils.getKeys(eventObject.inputs, 'type');
7914
7915  return decodeParams(inputNames, inputTypes, utils.hexOrBuffer(data));
7916}
7917
7918module.exports = {
7919  encodeParams: encodeParams,
7920  decodeParams: decodeParams,
7921  encodeMethod: encodeMethod,
7922  decodeMethod: decodeMethod,
7923  encodeEvent: encodeEvent,
7924  decodeEvent: decodeEvent
7925};
7926}).call(this,require("buffer").Buffer)
7927},{"./utils/index.js":14,"buffer":12}],14:[function(require,module,exports){
7928(function (Buffer){
7929'use strict';
7930
7931var BN = require('bn.js');
7932var numberToBN = require('number-to-bn');
7933var keccak256 = require('js-sha3').keccak_256;
7934
7935// from ethereumjs-util
7936function stripZeros(aInput) {
7937  var a = aInput; // eslint-disable-line
7938  var first = a[0]; // eslint-disable-line
7939  while (a.length > 0 && first.toString() === '0') {
7940    a = a.slice(1);
7941    first = a[0];
7942  }
7943  return a;
7944}
7945
7946function bnToBuffer(bnInput) {
7947  var bn = bnInput; // eslint-disable-line
7948  var hex = bn.toString(16); // eslint-disable-line
7949  if (hex.length % 2) {
7950    hex = '0' + hex;
7951  }
7952  return stripZeros(new Buffer(hex, 'hex'));
7953}
7954
7955function isHexString(value, length) {
7956  if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
7957    return false;
7958  }
7959  if (length && value.length !== 2 + 2 * length) {
7960    return false;
7961  }
7962  return true;
7963}
7964
7965function hexOrBuffer(valueInput, name) {
7966  var value = valueInput; // eslint-disable-line
7967  if (!Buffer.isBuffer(value)) {
7968    if (!isHexString(value)) {
7969      var error = new Error(name ? '[ethjs-abi] invalid ' + name : '[ethjs-abi] invalid hex or buffer, must be a prefixed alphanumeric even length hex string');
7970      error.reason = '[ethjs-abi] invalid hex string, hex must be prefixed and alphanumeric (e.g. 0x023..)';
7971      error.value = value;
7972      throw error;
7973    }
7974
7975    value = value.substring(2);
7976    if (value.length % 2) {
7977      value = '0' + value;
7978    }
7979    value = new Buffer(value, 'hex');
7980  }
7981
7982  return value;
7983}
7984
7985function hexlify(value) {
7986  if (typeof value === 'number') {
7987    return '0x' + bnToBuffer(new BN(value)).toString('hex');
7988  } else if (value.mod || value.modulo) {
7989    return '0x' + bnToBuffer(value).toString('hex');
7990  } else {
7991    // eslint-disable-line
7992    return '0x' + hexOrBuffer(value).toString('hex');
7993  }
7994}
7995
7996// getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3]
7997function getKeys(params, key, allowEmpty) {
7998  var result = []; // eslint-disable-line
7999
8000  if (!Array.isArray(params)) {
8001    throw new Error('[ethjs-abi] while getting keys, invalid params value ' + JSON.stringify(params));
8002  }
8003
8004  for (var i = 0; i < params.length; i++) {
8005    // eslint-disable-line
8006    var value = params[i][key]; // eslint-disable-line
8007    if (allowEmpty && !value) {
8008      value = '';
8009    } else if (typeof value !== 'string') {
8010      throw new Error('[ethjs-abi] while getKeys found invalid ABI data structure, type value not string');
8011    }
8012    result.push(value);
8013  }
8014
8015  return result;
8016}
8017
8018function coderNumber(size, signed) {
8019  return {
8020    encode: function encodeNumber(valueInput) {
8021      var value = valueInput; // eslint-disable-line
8022
8023      if (typeof value === 'object' && value.toString && (value.toTwos || value.dividedToIntegerBy)) {
8024        value = value.toString(10).split('.')[0];
8025      }
8026
8027      if (typeof value === 'string' || typeof value === 'number') {
8028        value = String(value).split('.')[0];
8029      }
8030
8031      value = numberToBN(value);
8032      value = value.toTwos(size * 8).maskn(size * 8);
8033      if (signed) {
8034        value = value.fromTwos(size * 8).toTwos(256);
8035      }
8036      return value.toArrayLike(Buffer, 'be', 32);
8037    },
8038    decode: function decodeNumber(data, offset) {
8039      var junkLength = 32 - size; // eslint-disable-line
8040      var value = new BN(data.slice(offset + junkLength, offset + 32)); // eslint-disable-line
8041      if (signed) {
8042        value = value.fromTwos(size * 8);
8043      } else {
8044        value = value.maskn(size * 8);
8045      }
8046      return {
8047        consumed: 32,
8048        value: new BN(value.toString(10))
8049      };
8050    }
8051  };
8052}
8053var uint256Coder = coderNumber(32, false);
8054
8055var coderBoolean = {
8056  encode: function encodeBoolean(value) {
8057    return uint256Coder.encode(value ? 1 : 0);
8058  },
8059  decode: function decodeBoolean(data, offset) {
8060    var result = uint256Coder.decode(data, offset); // eslint-disable-line
8061    return {
8062      consumed: result.consumed,
8063      value: !result.value.isZero()
8064    };
8065  }
8066};
8067
8068function coderFixedBytes(length) {
8069  return {
8070    encode: function encodeFixedBytes(valueInput) {
8071      var value = valueInput; // eslint-disable-line
8072      value = hexOrBuffer(value);
8073
8074      if (value.length === 32) {
8075        return value;
8076      }
8077
8078      var result = new Buffer(32); // eslint-disable-line
8079      result.fill(0);
8080      value.copy(result);
8081      return result;
8082    },
8083    decode: function decodeFixedBytes(data, offset) {
8084      if (data.length < offset + 32) {
8085        throw new Error('[ethjs-abi] while decoding fixed bytes, invalid bytes data length: ' + length);
8086      }
8087
8088      return {
8089        consumed: 32,
8090        value: '0x' + data.slice(offset, offset + length).toString('hex')
8091      };
8092    }
8093  };
8094}
8095
8096var coderAddress = {
8097  encode: function encodeAddress(valueInput) {
8098    var value = valueInput; // eslint-disable-line
8099    var result = new Buffer(32); // eslint-disable-line
8100    if (!isHexString(value, 20)) {
8101      throw new Error('[ethjs-abi] while encoding address, invalid address value, not alphanumeric 20 byte hex string');
8102    }
8103    value = hexOrBuffer(value);
8104    result.fill(0);
8105    value.copy(result, 12);
8106    return result;
8107  },
8108  decode: function decodeAddress(data, offset) {
8109    if (data.length === 0) {
8110      return {
8111        consumed: 32,
8112        value: '0x'
8113      };
8114    }
8115    if (data.length < offset + 32) {
8116      throw new Error('[ethjs-abi] while decoding address data, invalid address data, invalid byte length ' + data.length);
8117    }
8118    return {
8119      consumed: 32,
8120      value: '0x' + data.slice(offset + 12, offset + 32).toString('hex')
8121    };
8122  }
8123};
8124
8125function encodeDynamicBytesHelper(value) {
8126  var dataLength = parseInt(32 * Math.ceil(value.length / 32)); // eslint-disable-line
8127  var padding = new Buffer(dataLength - value.length); // eslint-disable-line
8128  padding.fill(0);
8129
8130  return Buffer.concat([uint256Coder.encode(value.length), value, padding]);
8131}
8132
8133function decodeDynamicBytesHelper(data, offset) {
8134  if (data.length < offset + 32) {
8135    throw new Error('[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: ' + data.length + ' should be less than ' + (offset + 32));
8136  }
8137
8138  var length = uint256Coder.decode(data, offset).value; // eslint-disable-line
8139  length = length.toNumber();
8140  if (data.length < offset + 32 + length) {
8141    throw new Error('[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: ' + data.length + ' should be less than ' + (offset + 32 + length));
8142  }
8143
8144  return {
8145    consumed: parseInt(32 + 32 * Math.ceil(length / 32), 10),
8146    value: data.slice(offset + 32, offset + 32 + length)
8147  };
8148}
8149
8150var coderDynamicBytes = {
8151  encode: function encodeDynamicBytes(value) {
8152    return encodeDynamicBytesHelper(hexOrBuffer(value));
8153  },
8154  decode: function decodeDynamicBytes(data, offset) {
8155    var result = decodeDynamicBytesHelper(data, offset); // eslint-disable-line
8156    result.value = '0x' + result.value.toString('hex');
8157    return result;
8158  },
8159  dynamic: true
8160};
8161
8162var coderString = {
8163  encode: function encodeString(value) {
8164    return encodeDynamicBytesHelper(new Buffer(value, 'utf8'));
8165  },
8166  decode: function decodeString(data, offset) {
8167    var result = decodeDynamicBytesHelper(data, offset); // eslint-disable-line
8168    result.value = result.value.toString('utf8');
8169    return result;
8170  },
8171  dynamic: true
8172};
8173
8174function coderArray(coder, lengthInput) {
8175  return {
8176    encode: function encodeArray(value) {
8177      var result = new Buffer(0); // eslint-disable-line
8178      var length = lengthInput; // eslint-disable-line
8179
8180      if (!Array.isArray(value)) {
8181        throw new Error('[ethjs-abi] while encoding array, invalid array data, not type Object (Array)');
8182      }
8183
8184      if (length === -1) {
8185        length = value.length;
8186        result = uint256Coder.encode(length);
8187      }
8188
8189      if (length !== value.length) {
8190        throw new Error('[ethjs-abi] while encoding array, size mismatch array length ' + length + ' does not equal ' + value.length);
8191      }
8192
8193      value.forEach(function (resultValue) {
8194        result = Buffer.concat([result, coder.encode(resultValue)]);
8195      });
8196
8197      return result;
8198    },
8199    decode: function decodeArray(data, offsetInput) {
8200      var length = lengthInput; // eslint-disable-line
8201      var offset = offsetInput; // eslint-disable-line
8202      // @TODO:
8203      // if (data.length < offset + length * 32) { throw new Error('invalid array'); }
8204
8205      var consumed = 0; // eslint-disable-line
8206      var decodeResult; // eslint-disable-line
8207
8208      if (length === -1) {
8209        decodeResult = uint256Coder.decode(data, offset);
8210        length = decodeResult.value.toNumber();
8211        consumed += decodeResult.consumed;
8212        offset += decodeResult.consumed;
8213      }
8214
8215      var value = []; // eslint-disable-line
8216
8217      for (var i = 0; i < length; i++) {
8218        // eslint-disable-line
8219        var loopResult = coder.decode(data, offset);
8220        consumed += loopResult.consumed;
8221        offset += loopResult.consumed;
8222        value.push(loopResult.value);
8223      }
8224
8225      return {
8226        consumed: consumed,
8227        value: value
8228      };
8229    },
8230    dynamic: lengthInput === -1
8231  };
8232}
8233
8234// Break the type up into [staticType][staticArray]*[dynamicArray]? | [dynamicType] and
8235// build the coder up from its parts
8236var paramTypePart = new RegExp(/^((u?int|bytes)([0-9]*)|(address|bool|string)|(\[([0-9]*)\]))/);
8237
8238function getParamCoder(typeInput) {
8239  var type = typeInput; // eslint-disable-line
8240  var coder = null; // eslint-disable-line
8241  var invalidTypeErrorMessage = '[ethjs-abi] while getting param coder (getParamCoder) type value ' + JSON.stringify(type) + ' is either invalid or unsupported by ethjs-abi.';
8242
8243  while (type) {
8244    var part = type.match(paramTypePart); // eslint-disable-line
8245    if (!part) {
8246      throw new Error(invalidTypeErrorMessage);
8247    }
8248    type = type.substring(part[0].length);
8249
8250    var prefix = part[2] || part[4] || part[5]; // eslint-disable-line
8251    switch (prefix) {
8252      case 'int':case 'uint':
8253        if (coder) {
8254          throw new Error(invalidTypeErrorMessage);
8255        }
8256        var intSize = parseInt(part[3] || 256); // eslint-disable-line
8257        if (intSize === 0 || intSize > 256 || intSize % 8 !== 0) {
8258          throw new Error('[ethjs-abi] while getting param coder for type ' + type + ', invalid ' + prefix + '<N> width: ' + type);
8259        }
8260
8261        coder = coderNumber(intSize / 8, prefix === 'int');
8262        break;
8263
8264      case 'bool':
8265        if (coder) {
8266          throw new Error(invalidTypeErrorMessage);
8267        }
8268        coder = coderBoolean;
8269        break;
8270
8271      case 'string':
8272        if (coder) {
8273          throw new Error(invalidTypeErrorMessage);
8274        }
8275        coder = coderString;
8276        break;
8277
8278      case 'bytes':
8279        if (coder) {
8280          throw new Error(invalidTypeErrorMessage);
8281        }
8282        if (part[3]) {
8283          var size = parseInt(part[3]); // eslint-disable-line
8284          if (size === 0 || size > 32) {
8285            throw new Error('[ethjs-abi] while getting param coder for prefix bytes, invalid type ' + type + ', size ' + size + ' should be 0 or greater than 32');
8286          }
8287          coder = coderFixedBytes(size);
8288        } else {
8289          coder = coderDynamicBytes;
8290        }
8291        break;
8292
8293      case 'address':
8294        if (coder) {
8295          throw new Error(invalidTypeErrorMessage);
8296        }
8297        coder = coderAddress;
8298        break;
8299
8300      case '[]':
8301        if (!coder || coder.dynamic) {
8302          throw new Error(invalidTypeErrorMessage);
8303        }
8304        coder = coderArray(coder, -1);
8305        break;
8306
8307      // "[0-9+]"
8308      default:
8309        if (!coder || coder.dynamic) {
8310          throw new Error(invalidTypeErrorMessage);
8311        }
8312        var defaultSize = parseInt(part[6]); // eslint-disable-line
8313        coder = coderArray(coder, defaultSize);
8314    }
8315  }
8316
8317  if (!coder) {
8318    throw new Error(invalidTypeErrorMessage);
8319  }
8320  return coder;
8321}
8322
8323module.exports = {
8324  BN: BN,
8325  bnToBuffer: bnToBuffer,
8326  isHexString: isHexString,
8327  hexOrBuffer: hexOrBuffer,
8328  hexlify: hexlify,
8329  stripZeros: stripZeros,
8330
8331  keccak256: keccak256,
8332
8333  getKeys: getKeys,
8334  numberToBN: numberToBN,
8335  coderNumber: coderNumber,
8336  uint256Coder: uint256Coder,
8337  coderBoolean: coderBoolean,
8338  coderFixedBytes: coderFixedBytes,
8339  coderAddress: coderAddress,
8340  coderDynamicBytes: coderDynamicBytes,
8341  coderString: coderString,
8342  coderArray: coderArray,
8343  paramTypePart: paramTypePart,
8344  getParamCoder: getParamCoder
8345};
8346}).call(this,require("buffer").Buffer)
8347},{"bn.js":10,"buffer":12,"js-sha3":17,"number-to-bn":18}],15:[function(require,module,exports){
8348exports.read = function (buffer, offset, isLE, mLen, nBytes) {
8349  var e, m
8350  var eLen = nBytes * 8 - mLen - 1
8351  var eMax = (1 << eLen) - 1
8352  var eBias = eMax >> 1
8353  var nBits = -7
8354  var i = isLE ? (nBytes - 1) : 0
8355  var d = isLE ? -1 : 1
8356  var s = buffer[offset + i]
8357
8358  i += d
8359
8360  e = s & ((1 << (-nBits)) - 1)
8361  s >>= (-nBits)
8362  nBits += eLen
8363  for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
8364
8365  m = e & ((1 << (-nBits)) - 1)
8366  e >>= (-nBits)
8367  nBits += mLen
8368  for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
8369
8370  if (e === 0) {
8371    e = 1 - eBias
8372  } else if (e === eMax) {
8373    return m ? NaN : ((s ? -1 : 1) * Infinity)
8374  } else {
8375    m = m + Math.pow(2, mLen)
8376    e = e - eBias
8377  }
8378  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
8379}
8380
8381exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
8382  var e, m, c
8383  var eLen = nBytes * 8 - mLen - 1
8384  var eMax = (1 << eLen) - 1
8385  var eBias = eMax >> 1
8386  var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
8387  var i = isLE ? 0 : (nBytes - 1)
8388  var d = isLE ? 1 : -1
8389  var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
8390
8391  value = Math.abs(value)
8392
8393  if (isNaN(value) || value === Infinity) {
8394    m = isNaN(value) ? 1 : 0
8395    e = eMax
8396  } else {
8397    e = Math.floor(Math.log(value) / Math.LN2)
8398    if (value * (c = Math.pow(2, -e)) < 1) {
8399      e--
8400      c *= 2
8401    }
8402    if (e + eBias >= 1) {
8403      value += rt / c
8404    } else {
8405      value += rt * Math.pow(2, 1 - eBias)
8406    }
8407    if (value * c >= 2) {
8408      e++
8409      c /= 2
8410    }
8411
8412    if (e + eBias >= eMax) {
8413      m = 0
8414      e = eMax
8415    } else if (e + eBias >= 1) {
8416      m = (value * c - 1) * Math.pow(2, mLen)
8417      e = e + eBias
8418    } else {
8419      m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
8420      e = 0
8421    }
8422  }
8423
8424  for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
8425
8426  e = (e << mLen) | m
8427  eLen += mLen
8428  for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
8429
8430  buffer[offset + i - d] |= s * 128
8431}
8432
8433},{}],16:[function(require,module,exports){
8434/**
8435 * Returns a `Boolean` on whether or not the a `String` starts with '0x'
8436 * @param {String} str the string input value
8437 * @return {Boolean} a boolean if it is or is not hex prefixed
8438 * @throws if the str input is not a string
8439 */
8440module.exports = function isHexPrefixed(str) {
8441  if (typeof str !== 'string') {
8442    throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed.");
8443  }
8444
8445  return str.slice(0, 2) === '0x';
8446}
8447
8448},{}],17:[function(require,module,exports){
8449(function (process,global){
8450/**
8451 * [js-sha3]{@link https://github.com/emn178/js-sha3}
8452 *
8453 * @version 0.5.5
8454 * @author Chen, Yi-Cyuan [[email protected]]
8455 * @copyright Chen, Yi-Cyuan 2015-2016
8456 * @license MIT
8457 */
8458(function (root) {
8459  'use strict';
8460
8461  var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
8462  if (NODE_JS) {
8463    root = global;
8464  }
8465  var COMMON_JS = !root.JS_SHA3_TEST && typeof module == 'object' && module.exports;
8466  var HEX_CHARS = '0123456789abcdef'.split('');
8467  var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
8468  var KECCAK_PADDING = [1, 256, 65536, 16777216];
8469  var PADDING = [6, 1536, 393216, 100663296];
8470  var SHIFT = [0, 8, 16, 24];
8471  var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
8472            0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 
8473            2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 
8474            2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
8475            2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
8476  var BITS = [224, 256, 384, 512];
8477  var SHAKE_BITS = [128, 256];
8478  var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
8479
8480  var createOutputMethod = function (bits, padding, outputType) {
8481    return function (message) {
8482      return new Keccak(bits, padding, bits).update(message)[outputType]();
8483    }
8484  };
8485
8486  var createShakeOutputMethod = function (bits, padding, outputType) {
8487    return function (message, outputBits) {
8488      return new Keccak(bits, padding, outputBits).update(message)[outputType]();
8489    }
8490  };
8491
8492  var createMethod = function (bits, padding) {
8493    var method = createOutputMethod(bits, padding, 'hex');
8494    method.create = function () {
8495      return new Keccak(bits, padding, bits);
8496    };
8497    method.update = function (message) {
8498      return method.create().update(message);
8499    };
8500    for (var i = 0;i < OUTPUT_TYPES.length;++i) {
8501      var type = OUTPUT_TYPES[i];
8502      method[type] = createOutputMethod(bits, padding, type);
8503    }
8504    return method;
8505  };
8506
8507  var createShakeMethod = function (bits, padding) {
8508    var method = createShakeOutputMethod(bits, padding, 'hex');
8509    method.create = function (outputBits) {
8510      return new Keccak(bits, padding, outputBits);
8511    };
8512    method.update = function (message, outputBits) {
8513      return method.create(outputBits).update(message);
8514    };
8515    for (var i = 0;i < OUTPUT_TYPES.length;++i) {
8516      var type = OUTPUT_TYPES[i];
8517      method[type] = createShakeOutputMethod(bits, padding, type);
8518    }
8519    return method;
8520  };
8521
8522  var algorithms = [
8523    {name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod},
8524    {name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
vendor: 11,675 bytes, lines 8525-8873
8525    {name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
8526  ];
8527
8528  var methods = {};
8529
8530  for (var i = 0;i < algorithms.length;++i) {
8531    var algorithm = algorithms[i];
8532    var bits  = algorithm.bits;
8533    for (var j = 0;j < bits.length;++j) {
8534      methods[algorithm.name +'_' + bits[j]] = algorithm.createMethod(bits[j], algorithm.padding);
8535    }
8536  }
8537
8538  function Keccak(bits, padding, outputBits) {
8539    this.blocks = [];
8540    this.s = [];
8541    this.padding = padding;
8542    this.outputBits = outputBits;
8543    this.reset = true;
8544    this.block = 0;
8545    this.start = 0;
8546    this.blockCount = (1600 - (bits << 1)) >> 5;
8547    this.byteCount = this.blockCount << 2;
8548    this.outputBlocks = outputBits >> 5;
8549    this.extraBytes = (outputBits & 31) >> 3;
8550
8551    for (var i = 0;i < 50;++i) {
8552      this.s[i] = 0;
8553    }
8554  };
8555
8556  Keccak.prototype.update = function (message) {
8557    var notString = typeof message != 'string';
8558    if (notString && message.constructor == root.ArrayBuffer) {
8559      message = new Uint8Array(message);
8560    }
8561    var length = message.length, blocks = this.blocks, byteCount = this.byteCount, 
8562        blockCount = this.blockCount, index = 0, s = this.s, i, code;
8563    
8564    while (index < length) {
8565      if (this.reset) {
8566        this.reset = false;
8567        blocks[0] = this.block;
8568        for (i = 1;i < blockCount + 1;++i) {
8569          blocks[i] = 0;
8570        }
8571      }
8572      if (notString) {
8573        for (i = this.start;index < length && i < byteCount;++index) {
8574          blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
8575        }
8576      } else {
8577        for (i = this.start;index < length && i < byteCount;++index) {
8578          code = message.charCodeAt(index);
8579          if (code < 0x80) {
8580            blocks[i >> 2] |= code << SHIFT[i++ & 3];
8581          } else if (code < 0x800) {
8582            blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
8583            blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
8584          } else if (code < 0xd800 || code >= 0xe000) {
8585            blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
8586            blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
8587            blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
8588          } else {
8589            code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
8590            blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
8591            blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
8592            blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
8593            blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
8594          }
8595        }
8596      }
8597      this.lastByteIndex = i;
8598      if (i >= byteCount) {
8599        this.start = i - byteCount;
8600        this.block = blocks[blockCount];
8601        for (i = 0;i < blockCount;++i) {
8602          s[i] ^= blocks[i];
8603        }
8604        f(s);
8605        this.reset = true;
8606      } else {
8607        this.start = i;
8608      }
8609    }
8610    return this;
8611  };
8612
8613  Keccak.prototype.finalize = function () {
8614    var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
8615    blocks[i >> 2] |= this.padding[i & 3];
8616    if (this.lastByteIndex == this.byteCount) {
8617      blocks[0] = blocks[blockCount];
8618      for (i = 1;i < blockCount + 1;++i) {
8619        blocks[i] = 0;
8620      }
8621    }
8622    blocks[blockCount - 1] |= 0x80000000;
8623    for (i = 0;i < blockCount;++i) {
8624      s[i] ^= blocks[i];
8625    }
8626    f(s);
8627  };
8628
8629  Keccak.prototype.toString = Keccak.prototype.hex = function () {
8630    this.finalize();
8631
8632    var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 
8633        extraBytes = this.extraBytes, i = 0, j = 0;
8634    var hex = '', block;
8635    while (j < outputBlocks) {
8636      for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
8637        block = s[i];
8638        hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
8639               HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
8640               HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
8641               HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
8642      }
8643      if (j % blockCount == 0) {
8644        f(s);
8645        i = 0;
8646      }
8647    }
8648    if (extraBytes) {
8649      block = s[i];
8650      if (extraBytes > 0) {
8651        hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
8652      }
8653      if (extraBytes > 1) {
8654        hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
8655      }
8656      if (extraBytes > 2) {
8657        hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
8658      }
8659    }
8660    return hex;
8661  };
8662
8663  Keccak.prototype.arrayBuffer = function () {
8664    this.finalize();
8665
8666    var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 
8667        extraBytes = this.extraBytes, i = 0, j = 0;
8668    var bytes = this.outputBits >> 3;
8669    var buffer;
8670    if (extraBytes) {
8671      buffer = new ArrayBuffer((outputBlocks + 1) << 2);
8672    } else {
8673      buffer = new ArrayBuffer(bytes);
8674    }
8675    var array = new Uint32Array(buffer);
8676    while (j < outputBlocks) {
8677      for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
8678        array[j] = s[i];
8679      }
8680      if (j % blockCount == 0) {
8681        f(s);
8682      }
8683    }
8684    if (extraBytes) {
8685      array[i] = s[i];
8686      buffer = buffer.slice(0, bytes);
8687    }
8688    return buffer;
8689  };
8690
8691  Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
8692
8693  Keccak.prototype.digest = Keccak.prototype.array = function () {
8694    this.finalize();
8695
8696    var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 
8697        extraBytes = this.extraBytes, i = 0, j = 0;
8698    var array = [], offset, block;
8699    while (j < outputBlocks) {
8700      for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) {
8701        offset = j << 2;
8702        block = s[i];
8703        array[offset] = block & 0xFF;
8704        array[offset + 1] = (block >> 8) & 0xFF;
8705        array[offset + 2] = (block >> 16) & 0xFF;
8706        array[offset + 3] = (block >> 24) & 0xFF;
8707      }
8708      if (j % blockCount == 0) {
8709        f(s);
8710      }
8711    }
8712    if (extraBytes) {
8713      offset = j << 2;
8714      block = s[i];
8715      if (extraBytes > 0) {
8716        array[offset] = block & 0xFF;
8717      }
8718      if (extraBytes > 1) {
8719        array[offset + 1] = (block >> 8) & 0xFF;
8720      }
8721      if (extraBytes > 2) {
8722        array[offset + 2] = (block >> 16) & 0xFF;
8723      }
8724    }
8725    return array;
8726  };
8727
8728  var f = function (s) {
8729    var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, 
8730        b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, 
8731        b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, 
8732        b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
8733    for (n = 0;n < 48;n += 2) {
8734      c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
8735      c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
8736      c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
8737      c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
8738      c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
8739      c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
8740      c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
8741      c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
8742      c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
8743      c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
8744
8745      h = c8 ^ ((c2 << 1) | (c3 >>> 31));
8746      l = c9 ^ ((c3 << 1) | (c2 >>> 31));
8747      s[0] ^= h;
8748      s[1] ^= l;
8749      s[10] ^= h;
8750      s[11] ^= l;
8751      s[20] ^= h;
8752      s[21] ^= l;
8753      s[30] ^= h;
8754      s[31] ^= l;
8755      s[40] ^= h;
8756      s[41] ^= l;
8757      h = c0 ^ ((c4 << 1) | (c5 >>> 31));
8758      l = c1 ^ ((c5 << 1) | (c4 >>> 31));
8759      s[2] ^= h;
8760      s[3] ^= l;
8761      s[12] ^= h;
8762      s[13] ^= l;
8763      s[22] ^= h;
8764      s[23] ^= l;
8765      s[32] ^= h;
8766      s[33] ^= l;
8767      s[42] ^= h;
8768      s[43] ^= l;
8769      h = c2 ^ ((c6 << 1) | (c7 >>> 31));
8770      l = c3 ^ ((c7 << 1) | (c6 >>> 31));
8771      s[4] ^= h;
8772      s[5] ^= l;
8773      s[14] ^= h;
8774      s[15] ^= l;
8775      s[24] ^= h;
8776      s[25] ^= l;
8777      s[34] ^= h;
8778      s[35] ^= l;
8779      s[44] ^= h;
8780      s[45] ^= l;
8781      h = c4 ^ ((c8 << 1) | (c9 >>> 31));
8782      l = c5 ^ ((c9 << 1) | (c8 >>> 31));
8783      s[6] ^= h;
8784      s[7] ^= l;
8785      s[16] ^= h;
8786      s[17] ^= l;
8787      s[26] ^= h;
8788      s[27] ^= l;
8789      s[36] ^= h;
8790      s[37] ^= l;
8791      s[46] ^= h;
8792      s[47] ^= l;
8793      h = c6 ^ ((c0 << 1) | (c1 >>> 31));
8794      l = c7 ^ ((c1 << 1) | (c0 >>> 31));
8795      s[8] ^= h;
8796      s[9] ^= l;
8797      s[18] ^= h;
8798      s[19] ^= l;
8799      s[28] ^= h;
8800      s[29] ^= l;
8801      s[38] ^= h;
8802      s[39] ^= l;
8803      s[48] ^= h;
8804      s[49] ^= l;
8805
8806      b0 = s[0];
8807      b1 = s[1];
8808      b32 = (s[11] << 4) | (s[10] >>> 28);
8809      b33 = (s[10] << 4) | (s[11] >>> 28);
8810      b14 = (s[20] << 3) | (s[21] >>> 29);
8811      b15 = (s[21] << 3) | (s[20] >>> 29);
8812      b46 = (s[31] << 9) | (s[30] >>> 23);
8813      b47 = (s[30] << 9) | (s[31] >>> 23);
8814      b28 = (s[40] << 18) | (s[41] >>> 14);
8815      b29 = (s[41] << 18) | (s[40] >>> 14);
8816      b20 = (s[2] << 1) | (s[3] >>> 31);
8817      b21 = (s[3] << 1) | (s[2] >>> 31);
8818      b2 = (s[13] << 12) | (s[12] >>> 20);
8819      b3 = (s[12] << 12) | (s[13] >>> 20);
8820      b34 = (s[22] << 10) | (s[23] >>> 22);
8821      b35 = (s[23] << 10) | (s[22] >>> 22);
8822      b16 = (s[33] << 13) | (s[32] >>> 19);
8823      b17 = (s[32] << 13) | (s[33] >>> 19);
8824      b48 = (s[42] << 2) | (s[43] >>> 30);
8825      b49 = (s[43] << 2) | (s[42] >>> 30);
8826      b40 = (s[5] << 30) | (s[4] >>> 2);
8827      b41 = (s[4] << 30) | (s[5] >>> 2);
8828      b22 = (s[14] << 6) | (s[15] >>> 26);
8829      b23 = (s[15] << 6) | (s[14] >>> 26);
8830      b4 = (s[25] << 11) | (s[24] >>> 21);
8831      b5 = (s[24] << 11) | (s[25] >>> 21);
8832      b36 = (s[34] << 15) | (s[35] >>> 17);
8833      b37 = (s[35] << 15) | (s[34] >>> 17);
8834      b18 = (s[45] << 29) | (s[44] >>> 3);
8835      b19 = (s[44] << 29) | (s[45] >>> 3);
8836      b10 = (s[6] << 28) | (s[7] >>> 4);
8837      b11 = (s[7] << 28) | (s[6] >>> 4);
8838      b42 = (s[17] << 23) | (s[16] >>> 9);
8839      b43 = (s[16] << 23) | (s[17] >>> 9);
8840      b24 = (s[26] << 25) | (s[27] >>> 7);
8841      b25 = (s[27] << 25) | (s[26] >>> 7);
8842      b6 = (s[36] << 21) | (s[37] >>> 11);
8843      b7 = (s[37] << 21) | (s[36] >>> 11);
8844      b38 = (s[47] << 24) | (s[46] >>> 8);
8845      b39 = (s[46] << 24) | (s[47] >>> 8);
8846      b30 = (s[8] << 27) | (s[9] >>> 5);
8847      b31 = (s[9] << 27) | (s[8] >>> 5);
8848      b12 = (s[18] << 20) | (s[19] >>> 12);
8849      b13 = (s[19] << 20) | (s[18] >>> 12);
8850      b44 = (s[29] << 7) | (s[28] >>> 25);
8851      b45 = (s[28] << 7) | (s[29] >>> 25);
8852      b26 = (s[38] << 8) | (s[39] >>> 24);
8853      b27 = (s[39] << 8) | (s[38] >>> 24);
8854      b8 = (s[48] << 14) | (s[49] >>> 18);
8855      b9 = (s[49] << 14) | (s[48] >>> 18);
8856
8857      s[0] = b0 ^ (~b2 & b4);
8858      s[1] = b1 ^ (~b3 & b5);
8859      s[10] = b10 ^ (~b12 & b14);
8860      s[11] = b11 ^ (~b13 & b15);
8861      s[20] = b20 ^ (~b22 & b24);
8862      s[21] = b21 ^ (~b23 & b25);
8863      s[30] = b30 ^ (~b32 & b34);
8864      s[31] = b31 ^ (~b33 & b35);
8865      s[40] = b40 ^ (~b42 & b44);
8866      s[41] = b41 ^ (~b43 & b45);
8867      s[2] = b2 ^ (~b4 & b6);
8868      s[3] = b3 ^ (~b5 & b7);
8869      s[12] = b12 ^ (~b14 & b16);
8870      s[13] = b13 ^ (~b15 & b17);
8871      s[22] = b22 ^ (~b24 & b26);
8872      s[23] = b23 ^ (~b25 & b27);
8873      s[32] = b32 ^ (~b34 & b36);
8874      s[33] = b33 ^ (~b35 & b37);
8875      s[42] = b42 ^ (~b44 & b46);
8876      s[43] = b43 ^ (~b45 & b47);
8877      s[4] = b4 ^ (~b6 & b8);
8878      s[5] = b5 ^ (~b7 & b9);
8879      s[14] = b14 ^ (~b16 & b18);
8880      s[15] = b15 ^ (~b17 & b19);
8881      s[24] = b24 ^ (~b26 & b28);
8882      s[25] = b25 ^ (~b27 & b29);
8883      s[34] = b34 ^ (~b36 & b38);
8884      s[35] = b35 ^ (~b37 & b39);
8885      s[44] = b44 ^ (~b46 & b48);
8886      s[45] = b45 ^ (~b47 & b49);
8887      s[6] = b6 ^ (~b8 & b0);
8888      s[7] = b7 ^ (~b9 & b1);
8889      s[16] = b16 ^ (~b18 & b10);
8890      s[17] = b17 ^ (~b19 & b11);
8891      s[26] = b26 ^ (~b28 & b20);
8892      s[27] = b27 ^ (~b29 & b21);
8893      s[36] = b36 ^ (~b38 & b30);
8894      s[37] = b37 ^ (~b39 & b31);
8895      s[46] = b46 ^ (~b48 & b40);
8896      s[47] = b47 ^ (~b49 & b41);
8897      s[8] = b8 ^ (~b0 & b2);
8898      s[9] = b9 ^ (~b1 & b3);
8899      s[18] = b18 ^ (~b10 & b12);
8900      s[19] = b19 ^ (~b11 & b13);
8901      s[28] = b28 ^ (~b20 & b22);
8902      s[29] = b29 ^ (~b21 & b23);
8903      s[38] = b38 ^ (~b30 & b32);
8904      s[39] = b39 ^ (~b31 & b33);
8905      s[48] = b48 ^ (~b40 & b42);
8906      s[49] = b49 ^ (~b41 & b43);
8907
8908      s[0] ^= RC[n];
8909      s[1] ^= RC[n + 1];
8910    }
8911  }
8912
8913  if (COMMON_JS) {
8914    module.exports = methods;
8915  } else if (root) {
8916    for (var key in methods) {
8917      root[key] = methods[key];
8918    }
8919  }
8920}(this));
8921
8922}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
8923},{"_process":19}],18:[function(require,module,exports){
8924var BN = require('bn.js');
8925var stripHexPrefix = require('strip-hex-prefix');
8926
8927/**
8928 * Returns a BN object, converts a number value to a BN
8929 * @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object
8930 * @return {Object} `output` BN object of the number
8931 * @throws if the argument is not an array, object that isn't a bignumber, not a string number or number
8932 */
8933module.exports = function numberToBN(arg) {
8934  if (typeof arg === 'string' || typeof arg === 'number') {
8935    var multiplier = new BN(1); // eslint-disable-line
8936    var formattedString = String(arg).toLowerCase().trim();
8937    var isHexPrefixed = formattedString.substr(0, 2) === '0x' || formattedString.substr(0, 3) === '-0x';
8938    var stringArg = stripHexPrefix(formattedString); // eslint-disable-line
8939    if (stringArg.substr(0, 1) === '-') {
8940      stringArg = stripHexPrefix(stringArg.slice(1));
8941      multiplier = new BN(-1, 10);
8942    }
8943    stringArg = stringArg === '' ? '0' : stringArg;
8944
8945    if ((!stringArg.match(/^-?[0-9]+$/) && stringArg.match(/^[0-9A-Fa-f]+$/))
8946      || stringArg.match(/^[a-fA-F]+$/)
8947      || (isHexPrefixed === true && stringArg.match(/^[0-9A-Fa-f]+$/))) {
8948      return new BN(stringArg, 16).mul(multiplier);
8949    }
8950
8951    if ((stringArg.match(/^-?[0-9]+$/) || stringArg === '') && isHexPrefixed === false) {
8952      return new BN(stringArg, 10).mul(multiplier);
8953    }
8954  } else if (typeof arg === 'object' && arg.toString && (!arg.pop && !arg.push)) {
8955    if (arg.toString(10).match(/^-?[0-9]+$/) && (arg.mul || arg.dividedToIntegerBy)) {
8956      return new BN(arg.toString(10), 10);
8957    }
8958  }
8959
8960  throw new Error('[number-to-bn] while converting number ' + JSON.stringify(arg) + ' to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.');
8961}
8962
8963},{"bn.js":10,"strip-hex-prefix":20}],19:[function(require,module,exports){
8964// shim for using process in browser
8965var process = module.exports = {};
8966
8967// cached from whatever global is present so that test runners that stub it
8968// don't break things.  But we need to wrap it in a try catch in case it is
8969// wrapped in strict mode code which doesn't define any globals.  It's inside a
8970// function because try/catches deoptimize in certain engines.
8971
8972var cachedSetTimeout;
8973var cachedClearTimeout;
8974
8975function defaultSetTimout() {
8976    throw new Error('setTimeout has not been defined');
8977}
8978function defaultClearTimeout () {
8979    throw new Error('clearTimeout has not been defined');
8980}
8981(function () {
8982    try {
8983        if (typeof setTimeout === 'function') {
8984            cachedSetTimeout = setTimeout;
8985        } else {
8986            cachedSetTimeout = defaultSetTimout;
8987        }
8988    } catch (e) {
8989        cachedSetTimeout = defaultSetTimout;
8990    }
8991    try {
8992        if (typeof clearTimeout === 'function') {
8993            cachedClearTimeout = clearTimeout;
8994        } else {
8995            cachedClearTimeout = defaultClearTimeout;
8996        }
8997    } catch (e) {
8998        cachedClearTimeout = defaultClearTimeout;
8999    }
9000} ())
9001function runTimeout(fun) {
9002    if (cachedSetTimeout === setTimeout) {
9003        //normal enviroments in sane situations
9004        return setTimeout(fun, 0);
9005    }
9006    // if setTimeout wasn't available but was latter defined
9007    if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
9008        cachedSetTimeout = setTimeout;
9009        return setTimeout(fun, 0);
9010    }
9011    try {
9012        // when when somebody has screwed with setTimeout but no I.E. maddness
9013        return cachedSetTimeout(fun, 0);
9014    } catch(e){
9015        try {
9016            // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
9017            return cachedSetTimeout.call(null, fun, 0);
9018        } catch(e){
9019            // 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
9020            return cachedSetTimeout.call(this, fun, 0);
9021        }
9022    }
9023
9024
9025}
9026function runClearTimeout(marker) {
9027    if (cachedClearTimeout === clearTimeout) {
9028        //normal enviroments in sane situations
9029        return clearTimeout(marker);
9030    }
9031    // if clearTimeout wasn't available but was latter defined
9032    if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
9033        cachedClearTimeout = clearTimeout;
9034        return clearTimeout(marker);
9035    }
9036    try {
9037        // when when somebody has screwed with setTimeout but no I.E. maddness
9038        return cachedClearTimeout(marker);
9039    } catch (e){
9040        try {
9041            // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally
9042            return cachedClearTimeout.call(null, marker);
9043        } catch (e){
9044            // 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.
9045            // Some versions of I.E. have different rules for clearTimeout vs setTimeout
9046            return cachedClearTimeout.call(this, marker);
9047        }
9048    }
9049
9050
9051
9052}
9053var queue = [];
9054var draining = false;
vendor: 2,565 bytes, lines 9055-9165
9055var currentQueue;
9056var queueIndex = -1;
9057
9058function cleanUpNextTick() {
9059    if (!draining || !currentQueue) {
9060        return;
9061    }
9062    draining = false;
9063    if (currentQueue.length) {
9064        queue = currentQueue.concat(queue);
9065    } else {
9066        queueIndex = -1;
9067    }
9068    if (queue.length) {
9069        drainQueue();
9070    }
9071}
9072
9073function drainQueue() {
9074    if (draining) {
9075        return;
9076    }
9077    var timeout = runTimeout(cleanUpNextTick);
9078    draining = true;
9079
9080    var len = queue.length;
9081    while(len) {
9082        currentQueue = queue;
9083        queue = [];
9084        while (++queueIndex < len) {
9085            if (currentQueue) {
9086                currentQueue[queueIndex].run();
9087            }
9088        }
9089        queueIndex = -1;
9090        len = queue.length;
9091    }
9092    currentQueue = null;
9093    draining = false;
9094    runClearTimeout(timeout);
9095}
9096
9097process.nextTick = function (fun) {
9098    var args = new Array(arguments.length - 1);
9099    if (arguments.length > 1) {
9100        for (var i = 1; i < arguments.length; i++) {
9101            args[i - 1] = arguments[i];
9102        }
9103    }
9104    queue.push(new Item(fun, args));
9105    if (queue.length === 1 && !draining) {
9106        runTimeout(drainQueue);
9107    }
9108};
9109
9110// v8 likes predictible objects
9111function Item(fun, array) {
9112    this.fun = fun;
9113    this.array = array;
9114}
9115Item.prototype.run = function () {
9116    this.fun.apply(null, this.array);
9117};
9118process.title = 'browser';
9119process.browser = true;
9120process.env = {};
9121process.argv = [];
9122process.version = ''; // empty string to avoid regexp issues
9123process.versions = {};
9124
9125function noop() {}
9126
9127process.on = noop;
9128process.addListener = noop;
9129process.once = noop;
9130process.off = noop;
9131process.removeListener = noop;
9132process.removeAllListeners = noop;
9133process.emit = noop;
9134process.prependListener = noop;
9135process.prependOnceListener = noop;
9136
9137process.listeners = function (name) { return [] }
9138
9139process.binding = function (name) {
9140    throw new Error('process.binding is not supported');
9141};
9142
9143process.cwd = function () { return '/' };
9144process.chdir = function (dir) {
9145    throw new Error('process.chdir is not supported');
9146};
9147process.umask = function() { return 0; };
9148
9149},{}],20:[function(require,module,exports){
9150var isHexPrefixed = require('is-hex-prefixed');
9151
9152/**
9153 * Removes '0x' from a given `String` is present
9154 * @param {String} str the string value
9155 * @return {String|Optional} a string by pass if necessary
9156 */
9157module.exports = function stripHexPrefix(str) {
9158  if (typeof str !== 'string') {
9159    return str;
9160  }
9161
9162  return isHexPrefixed(str) ? str.slice(2) : str;
9163}
9164
9165},{"is-hex-prefixed":16}]},{},[8]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.