aboutsummaryrefslogtreecommitdiff
path: root/bip39-standalone.html
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2017-02-11 20:55:49 +1100
committerIan Coleman <coleman.ian@gmail.com>2017-02-11 20:55:49 +1100
commit8b095871e8ab14ec236ddb181ffdfe36e6636058 (patch)
tree9597e5ca6f039c0fe1da2f0db2f2fc1be339316e /bip39-standalone.html
parentddeb86131e0d6e363a428709851365082c991a38 (diff)
downloadBIP39-8b095871e8ab14ec236ddb181ffdfe36e6636058.tar.gz
BIP39-8b095871e8ab14ec236ddb181ffdfe36e6636058.tar.zst
BIP39-8b095871e8ab14ec236ddb181ffdfe36e6636058.zip
Ethereum compiled into standalone
Diffstat (limited to 'bip39-standalone.html')
-rw-r--r--bip39-standalone.html22570
1 files changed, 22570 insertions, 0 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html
index a2a90d3..0d1d244 100644
--- a/bip39-standalone.html
+++ b/bip39-standalone.html
@@ -655,6 +655,3800 @@
655 <td class="privkey"><span data-show-qr></span></td> 655 <td class="privkey"><span data-show-qr></span></td>
656 </tr> 656 </tr>
657 </script> 657 </script>
658 <script>// From
659// https://raw.githubusercontent.com/inexorabletash/polyfill/a6bc6ced78160c994f76a909b6ff6bbbab3d43de/es6.js
660// Required for ethereumjs-utils.js when run in phantomjs-2.1.1
661// but is not required in any modern browsers.
662// For more information, see
663// https://www.bountysource.com/issues/38485709-error-rendering-plot-with-phantomjs
664
665//----------------------------------------------------------------------
666//
667// ECMAScript 2015 Polyfills
668//
669//----------------------------------------------------------------------
670
671(function (global) {
672 "use strict";
673
674 // Set this to always override native implementations, for testing
675 // the polyfill in browsers with partial/full ES2015 support.
676 var OVERRIDE_NATIVE_FOR_TESTING = false;
677
678 var undefined = (void 0); // Paranoia
679
680 // Helpers
681
682 function strict(o) {
683 return o === global ? undefined : o;
684 }
685
686 function hook(o, p, f) {
687 var op = o[p];
688 console.assert(typeof op === 'function', 'Hooking a non-function');
689 o[p] = function() {
690 var o = strict(this);
691 var r = f.apply(o, arguments);
692 return r !== undefined ? r : op.apply(o, arguments);
693 };
694 }
695
696 function isSymbol(s) {
697 return (typeof s === 'symbol') || ('Symbol' in global && s instanceof global.Symbol);
698 }
699
700 function getPropertyDescriptor(target, name) {
701 var desc = Object.getOwnPropertyDescriptor(target, name);
702 var proto = Object.getPrototypeOf(target);
703 while (!desc && proto) {
704 desc = Object.getOwnPropertyDescriptor(proto, name);
705 proto = Object.getPrototypeOf(proto);
706 }
707 return desc;
708 }
709
710 var enqueue = (function(nativePromise, nativeSetImmediate) {
711 if (nativePromise)
712 return function(job) { nativePromise.resolve().then(function() { job(); }); };
713 if (nativeSetImmediate)
714 return function(job) { nativeSetImmediate(job); };
715 return function(job) { setTimeout(job, 0); };
716 }(global['Promise'], global['setImmediate']));
717
718 function define(o, p, v, override) {
719 if (p in o && !override && !OVERRIDE_NATIVE_FOR_TESTING)
720 return;
721
722 if (typeof v === 'function') {
723 // Sanity check that functions are appropriately named (where possible)
724 console.assert(isSymbol(p) || !('name' in v) || v.name === p || v.name === p + '_', 'Expected function name "' + p.toString() + '", was "' + v.name + '"');
725 Object.defineProperty(o, p, {
726 value: v,
727 configurable: true,
728 enumerable: false,
729 writable: true
730 });
731 } else {
732 Object.defineProperty(o, p, {
733 value: v,
734 configurable: false,
735 enumerable: false,
736 writable: false
737 });
738 }
739 }
740
741 function set_internal(o, p, v) {
742 Object.defineProperty(o, p, {
743 value: v,
744 configurable: false,
745 enumerable: false,
746 writable: true
747 });
748 }
749
750 // Snapshot intrinsic functions
751 var $isNaN = global.isNaN,
752 $parseInt = global.parseInt,
753 $parseFloat = global.parseFloat;
754
755 var E = Math.E,
756 LOG10E = Math.LOG10E,
757 LOG2E = Math.LOG2E,
758 abs = Math.abs,
759 ceil = Math.ceil,
760 exp = Math.exp,
761 floor = Math.floor,
762 log = Math.log,
763 max = Math.max,
764 min = Math.min,
765 pow = Math.pow,
766 random = Math.random,
767 sqrt = Math.sqrt;
768
769 var orig_match = String.prototype.match,
770 orig_replace = String.prototype.replace,
771 orig_search = String.prototype.search,
772 orig_split = String.prototype.split;
773
774 // These are used for implementing the polyfills, but not exported.
775
776 // Inspired by https://gist.github.com/1638059
777 /** @constructor */
778 function EphemeronTable() {
779 var secretKey = ObjectCreate(null);
780
781 function conceal(o) {
782 var oValueOf = o.valueOf, secrets = ObjectCreate(null);
783 Object.defineProperty(o, 'valueOf', {
784 value: (function(secretKey) {
785 return function (k) {
786 return (k === secretKey) ? secrets : oValueOf.apply(o, arguments);
787 };
788 }(secretKey)),
789 configurable: true,
790 writeable: true,
791 enumerable: false
792 });
793 return secrets;
794 }
795
796 function reveal(o) {
797 var v = typeof o.valueOf === 'function' && o.valueOf(secretKey);
798 return v === o ? null : v;
799 }
800
801 return {
802 clear: function() {
803 secretKey = ObjectCreate(null);
804 },
805 remove: function(key) {
806 var secrets = reveal(key);
807 if (secrets && HasOwnProperty(secrets, 'value')) {
808 delete secrets.value;
809 return true;
810 }
811 return false;
812 },
813 get: function(key, defaultValue) {
814 var secrets = reveal(key);
815 return (secrets && HasOwnProperty(secrets, 'value')) ? secrets.value : defaultValue;
816 },
817 has: function(key) {
818 var secrets = reveal(key);
819 return Boolean(secrets && HasOwnProperty(secrets, 'value'));
820 },
821 set: function(key, value) {
822 var secrets = reveal(key) || conceal(key);
823 secrets.value = value;
824 }
825 };
826 }
827
828 var empty = Object.create(null);
829
830 //----------------------------------------------------------------------
831 //
832 // ECMAScript 2015
833 // http://www.ecma-international.org/ecma-262/6.0/
834 //
835 //----------------------------------------------------------------------
836
837 // ---------------------------------------
838 // 19.4 Symbol Objects
839 // ---------------------------------------
840
841 // NOTE: Symbols are defined here - out of spec order - since we need the
842 // properties and prototype to be populated for other polyfills.
843
844 // NOTE: Not secure, nor is obj[$$symbol] hidden from Object.keys()
845
846 var symbolForKey;
847 (function() {
848 var secret = Object.create(null);
849 var symbolMap = {};
850 symbolForKey = function(k) {
851 return symbolMap[k];
852 };
853
854 var GlobalSymbolRegistry = [];
855
856 function unique(bits) {
857 return Array(bits + 1).join('x').replace(/x/g, function() {
858 return random() < 0.5 ? '\u200C' : '\u200D'; // JWNJ / ZWJ
859 });
860 }
861
862 // 19.4.1 The Symbol Constructor
863 // 19.4.1.1 Symbol ( description=undefined )
864 function Symbol(description) {
865 if (!(this instanceof Symbol)) return new Symbol(description, secret);
866 if (this instanceof Symbol && arguments[1] !== secret) throw TypeError();
867
868 var descString = description === undefined ? undefined : String(description);
869
870 set_internal(this, '[[SymbolData]]', unique(128));
871 set_internal(this, '[[Description]]', descString);
872
873 symbolMap[this] = this;
874 return this;
875 }
876
877 if (!('Symbol' in global) || OVERRIDE_NATIVE_FOR_TESTING)
878 global.Symbol = Symbol;
879
880 // 19.4.2 Properties of the Symbol Constructor
881
882 // 19.4.2.1 Symbol.for (key)
883 define(Symbol, 'for', function for_(key) {
884 var stringKey = String(key);
885 for (var i = 0; i < GlobalSymbolRegistry.length; ++i) {
886 var e = GlobalSymbolRegistry[i];
887 if (SameValue(e['[[key]]'], stringKey)) return e['[[symbol]]'];
888 }
889 var newSymbol = Symbol(key);
890 GlobalSymbolRegistry.push({'[[key]]': stringKey, '[[symbol]]': newSymbol});
891 return newSymbol;
892 });
893
894 // 19.4.2.2 Symbol.hasInstance
895 // 19.4.2.3 Symbol.isConcatSpreadable
896
897 // 19.4.2.4 Symbol.iterator
898 define(global.Symbol, 'iterator', global.Symbol('Symbol.iterator'));
899
900 // 19.4.2.5 Symbol.keyFor (sym)
901 define(Symbol, 'keyFor', function keyFor(sym) {
902 if (!(sym instanceof Symbol)) throw TypeError();
903 for (var i = 0; i < GlobalSymbolRegistry.length; ++i) {
904 var e = GlobalSymbolRegistry[i];
905 if (SameValue(e['[[symbol]]'], sym)) return e['[[key]]'];
906 }
907 return undefined;
908 });
909
910 // 19.4.2.6 Symbol.match
911 define(global.Symbol, 'match', global.Symbol('Symbol.match'));
912
913 // 19.4.2.7 Symbol.prototype
914
915 // 19.4.2.8 Symbol.replace
916 define(global.Symbol, 'replace', global.Symbol('Symbol.replace'));
917
918 // 19.4.2.9 Symbol.search
919 define(global.Symbol, 'search', global.Symbol('Symbol.search'));
920
921 // 19.4.2.10 Symbol.species
922
923 // 19.4.2.11 Symbol.search
924 define(global.Symbol, 'split', global.Symbol('Symbol.split'));
925
926 // 19.4.2.12 Symbol.toPrimitive
927
928 // 19.4.2.13 Symbol.toStringTag
929 define(global.Symbol, 'toStringTag', global.Symbol('Symbol.toStringTag'));
930
931 // 19.4.2.14 Symbol.unscopables
932
933 // 19.4.3 Properties of the Symbol Prototype Object
934 // 19.4.3.1 Symbol.prototype.constructor
935
936 // 19.4.3.2 Symbol.prototype.toString ( )
937 Object.defineProperty(Symbol.prototype, 'toString', {
938 value: function toString() {
939 var s = strict(this);
940 var desc = s['[[Description]]'];
941 return 'Symbol(' + (desc === undefined ? '' : desc) + s['[[SymbolData]]'] + ')';
942 },
943 configurable: true, writeable: true, enumerable: false });
944
945 // 19.4.3.3 Symbol.prototype.valueOf ( )
946 Object.defineProperty(Symbol.prototype, 'valueOf', {
947 value: function valueOf() {
948 // To prevent automatic string conversion:
949 throw TypeError();
950
951 // Spec has approximately the following:
952 //var s = strict(this);
953 //if (Type(s) === 'symbol') return s;
954 //if (Type(s) !== 'object') throw TypeError();
955 //if (!('[[SymbolData]]' in s)) throw TypeError();
956 //return s['[[SymbolData]]'];
957 },
958 configurable: true, writeable: true, enumerable: false });
959
960 // 19.4.3.4 Symbol.prototype [ @@toStringTag ]
961 // (Done later to polyfill partial implementations)
962
963 // 19.4.4 Properties of Symbol Instances
964 }());
965
966 console.assert(typeof global.Symbol() === 'symbol' || symbolForKey(String(global.Symbol('x'))));
967
968 // Defined here so that other prototypes can reference it
969 // 25.1.2 The %IteratorPrototype% Object
970 var $IteratorPrototype$ = {};
971
972 //----------------------------------------
973 // 6 ECMAScript Data Types and Values
974 //----------------------------------------
975
976 // 6.1 ECMAScript Language Types
977
978 // "Type(x)" is used as shorthand for "the type of x"...
979 function Type(v) {
980 switch (typeof v) {
981 case 'undefined': return 'undefined';
982 case 'boolean': return 'boolean';
983 case 'number': return 'number';
984 case 'string': return 'string';
985 case 'symbol': return 'symbol';
986 default:
987 if (v === null) return 'null';
988 if (v instanceof global.Symbol) return 'symbol';
989 return 'object';
990 }
991 }
992
993 // 6.1.5.1 Well-Known Symbols
994 var $$iterator = global.Symbol.iterator,
995 $$match = global.Symbol.match,
996 $$replace = global.Symbol.replace,
997 $$search = global.Symbol.search,
998 $$split = global.Symbol.split,
999 $$toStringTag = global.Symbol.toStringTag;
1000
1001 //----------------------------------------
1002 // 7 Abstract Operations
1003 //----------------------------------------
1004
1005 //----------------------------------------
1006 // 7.1 Type Conversion
1007 //----------------------------------------
1008
1009 // 7.1.1 ToPrimitive ( input [, PreferredType] )
1010 // just use valueOf()
1011
1012 // 7.1.2 ToBoolean ( argument )
1013 // just use Boolean()
1014
1015 // 7.1.3 ToNumber ( argument )
1016 // just use Number()
1017
1018 // 7.1.4 ToInteger ( argument )
1019 function ToInteger(n) {
1020 n = Number(n);
1021 if ($isNaN(n)) return 0;
1022 if (n === 0 || n === Infinity || n === -Infinity) return n;
1023 return ((n < 0) ? -1 : 1) * floor(abs(n));
1024 }
1025
1026 // 7.1.5 ToInt32 ( argument )
1027 function ToInt32(v) { return v >> 0; }
1028
1029 // 7.1.6 ToUint32 ( argument )
1030 function ToUint32(v) { return v >>> 0; }
1031
1032 // 7.1.7 ToInt16 ( argument )
1033 function ToInt16(v) { return (v << 16) >> 16; }
1034
1035 // 7.1.8 ToUint16 ( argument )
1036 function ToUint16(v) { return v & 0xFFFF; }
1037
1038 // 7.1.9 ToInt8 ( argument )
1039 function ToInt8(v) { return (v << 24) >> 24; }
1040
1041 // 7.1.10 ToUint8 ( argument )
1042 function ToUint8(v) { return v & 0xFF; }
1043
1044 // 7.1.11 ToUint8Clamp ( argument )
1045 function ToUint8Clamp(argument) {
1046 var number = Number(argument);
1047 if ($isNaN(number)) return 0;
1048 if (number <= 0) return 0;
1049 if (number >= 255) return 255;
1050 var f = floor(number);
1051 if ((f + 0.5) < number) return f + 1;
1052 if (number < (f + 0.5)) return f;
1053 if (f % 2) return f + 1;
1054 return f;
1055 }
1056
1057 // 7.1.12 ToString ( argument )
1058 // just use String()
1059
1060 // 7.1.13 ToObject ( argument )
1061 function ToObject(v) {
1062 if (v === null || v === undefined) throw TypeError();
1063 return Object(v);
1064 }
1065
1066 // 7.1.14 ToPropertyKey ( argument )
1067 function ToPropertyKey(v) {
1068 return String(v);
1069 }
1070
1071 // 7.1.15 ToLength ( argument )
1072 function ToLength(v) {
1073 var len = ToInteger(v);
1074 if (len <= 0) return 0;
1075 if (len === Infinity) return 0x20000000000000 - 1; // 2^53-1
1076 return min(len, 0x20000000000000 - 1); // 2^53-1
1077 }
1078
1079 // 7.1.16 CanonicalNumericIndexString ( argument )
1080
1081 //----------------------------------------
1082 // 7.2 Testing and Comparison Operations
1083 //----------------------------------------
1084
1085 // 7.2.1 RequireObjectCoercible ( argument )
1086 // 7.2.2 IsArray ( argument )
1087
1088 // 7.2.3 IsCallable ( argument )
1089 function IsCallable(o) { return typeof o === 'function'; }
1090
1091 // 7.2.4 IsConstructor ( argument )
1092 function IsConstructor(o) {
1093 // Hacks for Safari 7 TypedArray XXXConstructor objects
1094 if (/Constructor/.test(Object.prototype.toString.call(o))) return true;
1095 if (/Function/.test(Object.prototype.toString.call(o))) return true;
1096 // TODO: Can this be improved on?
1097 return typeof o === 'function';
1098 }
1099
1100 // 7.2.5 IsExtensible (O)
1101 // 7.2.6 IsInteger ( argument )
1102
1103 // 7.2.7 IsPropertyKey ( argument )
1104 function IsPropertyKey(argument) {
1105 if (Type(argument) === 'string') return true;
1106 if (Type(argument) === 'symbol') return true;
1107 return false;
1108 }
1109
1110 // 7.2.8 IsRegExp ( argument )
1111 // 7.2.5 IsConstructor ( argument )
1112
1113 // 7.2.9 SameValue(x, y)
1114 function SameValue(x, y) {
1115 if (typeof x !== typeof y) return false;
1116 switch (typeof x) {
1117 case 'undefined':
1118 return true;
1119 case 'number':
1120 if (x !== x && y !== y) return true;
1121 if (x === 0 && y === 0) return 1/x === 1/y;
1122 return x === y;
1123 case 'boolean':
1124 case 'string':
1125 case 'object':
1126 default:
1127 return x === y;
1128 }
1129 }
1130
1131 // 7.2.10 SameValueZero(x, y)
1132 function SameValueZero(x, y) {
1133 if (typeof x !== typeof y) return false;
1134 switch (typeof x) {
1135 case 'undefined':
1136 return true;
1137 case 'number':
1138 if (x !== x && y !== y) return true;
1139 return x === y;
1140 case 'boolean':
1141 case 'string':
1142 case 'object':
1143 default:
1144 return x === y;
1145 }
1146 }
1147
1148 //----------------------------------------
1149 // 7.3 Operations on Objects
1150 //----------------------------------------
1151
1152 // 7.3.1 Get (O, P)
1153 // - just use o.p or o[p]
1154
1155 // 7.3.2 GetV (V, P)
1156 function GetV(v, p) {
1157 var o = ToObject(v);
1158 return o[p];
1159 }
1160
1161 // 7.3.3 Set (O, P, V, Throw)
1162 // - just use o.p = v or o[p] = v
1163
1164
1165
1166
1167 // 7.3.9 GetMethod (O, P)
1168 function GetMethod(o, p) {
1169 var func = GetV(o, p);
1170 if (func === undefined || func === null) return undefined;
1171 if (!IsCallable(func)) throw TypeError();
1172 return func;
1173 }
1174
1175 // 7.3.10 HasProperty (O, P)
1176 function HasProperty(o, p) {
1177 while (o) {
1178 if (Object.prototype.hasOwnProperty.call(o, p)) return true;
1179 if (Type(o) !== 'object') return false;
1180 o = Object.getPrototypeOf(o);
1181 }
1182 return false;
1183 }
1184
1185 // 7.3.11 HasOwnProperty (O, P)
1186 function HasOwnProperty(o, p) {
1187 return Object.prototype.hasOwnProperty.call(o, p);
1188 }
1189
1190 //----------------------------------------
1191 // 7.4 Operations on Iterator Objects
1192 //----------------------------------------
1193
1194 // 7.4.1 GetIterator ( obj, method )
1195 function GetIterator(obj, method) {
1196 if (arguments.length < 2)
1197 method = GetMethod(obj, $$iterator);
1198 var iterator = method.call(obj);
1199 if (Type(iterator) !== 'object') throw TypeError();
1200 return iterator;
1201 }
1202
1203 // 7.4.2 IteratorNext ( iterator, value )
1204 function IteratorNext(iterator, value) {
1205 if (arguments.length < 2)
1206 var result = iterator.next();
1207 else
1208 result = iterator.next(value);
1209 if (Type(result) !== 'object') throw TypeError();
1210 return result;
1211 }
1212
1213 // 7.4.3 IteratorComplete ( iterResult )
1214 function IteratorComplete(iterResult) {
1215 console.assert(Type(iterResult) === 'object');
1216 return Boolean(iterResult.done);
1217 }
1218
1219 // 7.4.4 IteratorValue ( iterResult )
1220 function IteratorValue(iterResult) {
1221 console.assert(Type(iterResult) === 'object');
1222 return iterResult.value;
1223 }
1224
1225 // 7.4.5 IteratorStep ( iterator )
1226 function IteratorStep( iterator, value ) {
1227 var result = IteratorNext(iterator, value);
1228 var done = result['done'];
1229 if (Boolean(done) === true) return false;
1230 return result;
1231 }
1232
1233 // 7.4.6 IteratorClose( iterator, completion )
1234 function IteratorClose( iterator, completion ) {
1235 console.assert(Type(iterator) === 'object');
1236 var _return = GetMethod(iterator, 'return');
1237 if (_return === undefined) return completion;
1238 try {
1239 var innerResult = _return[iterator]();
1240 } catch (result) {
1241 // TODO: If completion.[[type]] is throw, return completion
1242 return result;
1243 }
1244 if (Type(innerResult) !== 'object') throw TypeError();
1245 return completion;
1246 }
1247
1248 // 7.4.7 CreateIterResultObject (value, done)
1249 function CreateIterResultObject(value, done) {
1250 console.assert(Type(done) === 'boolean');
1251 var obj = {};
1252 obj["value"] = value;
1253 obj["done"] = done;
1254 return obj;
1255 }
1256
1257 // 7.4.8 CreateListIterator (list)
1258 // 7.4.8.1 ListIterator next( )
1259 // 7.4.9 CreateCompoundIterator ( iterator1, iterator2 )
1260 // 7.4.9.1 CompoundIterator next( )
1261
1262 //----------------------------------------
1263 // 8 Executable Code and Execution Contexts
1264 //----------------------------------------
1265
1266 //----------------------------------------
1267 // 8.4 Jobs and Job Queues
1268 //----------------------------------------
1269
1270 // 8.4.1 EnqueueJob ( queueName, job, arguments)
1271 function EnqueueJob(queueName, job, args) {
1272 var fn = function() { job.apply(undefined, args); };
1273 enqueue(fn);
1274 }
1275
1276 // 8.4.2 NextJob result
1277 function NextJob(result) {
1278 // no-op
1279 }
1280
1281 //----------------------------------------
1282 // 9 Ordinary and Exotic Objects Behaviors
1283 //----------------------------------------
1284
1285 // 9.1.11 [[Enumerate]] ()
1286 function Enumerate(obj) {
1287 var e = [];
1288 if (Object(obj) !== obj) return e;
1289 var visited = new Set;
1290 while (obj !== null) {
1291 Object.getOwnPropertyNames(obj).forEach(function(name) {
1292 if (!visited.has(name)) {
1293 var desc = Object.getOwnPropertyDescriptor(obj, name);
1294 if (desc) {
1295 visited.add(name);
1296 if (desc.enumerable) e.push(name);
1297 }
1298 }
1299 });
1300 obj = Object.getPrototypeOf(obj);
1301 }
1302 return e[$$iterator]();
1303 }
1304
1305 // 9.1.12 [[OwnPropertyKeys]] ( )
1306 function OwnPropertyKeys(o) {
1307 return Object.getOwnPropertyNames(o);
1308 }
1309
1310 // 9.1.13 ObjectCreate(proto, internalSlotsList)
1311 function ObjectCreate(proto, internalSlotsList) {
1312 return Object.create(proto, internalSlotsList);
1313 }
1314
1315 // ---------------------------------------
1316 // 19 Fundamental Objects
1317 // ---------------------------------------
1318
1319 // ---------------------------------------
1320 // 19.1 Object Objects
1321 // ---------------------------------------
1322
1323 // 19.1.1 The Object Constructor
1324 // 19.1.1.1 Object ( [ value ] )
1325 // 19.1.2 Properties of the Object Constructor
1326 // 19.1.2.1 Object.assign ( target, ...sources )
1327 define(
1328 Object, 'assign',
1329 function assign(target, /*...*/sources) {
1330 var to = ToObject(target);
1331 if (arguments.length < 2) return to;
1332
1333 var sourcesIndex = 1;
1334 while (sourcesIndex < arguments.length) {
1335 var nextSource = arguments[sourcesIndex++];
1336 if (nextSource === undefined || nextSource === null) {
1337 var keys = [];
1338 } else {
1339 var from = ToObject(nextSource);
1340 keys = OwnPropertyKeys(from);
1341 }
1342 for (var keysIndex = 0; keysIndex < keys.length; ++keysIndex) {
1343 var nextKey = keys[keysIndex];
1344 var desc = Object.getOwnPropertyDescriptor(from, nextKey);
1345 if (desc !== undefined && desc.enumerable) {
1346 var propValue = from[nextKey];
1347 to[nextKey] = propValue;
1348 }
1349 }
1350 }
1351 return to;
1352 });
1353
1354 // 19.1.2.2 Object.create ( O [ , Properties ] )
1355 // 19.1.2.3 Object.defineProperties ( O, Properties )
1356 // 19.1.2.4 Object.defineProperty ( O, P, Attributes )
1357 // 19.1.2.5 Object.freeze ( O )
1358 // 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P )
1359
1360 (function() {
1361 var nativeSymbols = (typeof global.Symbol() === 'symbol'),
1362 $getOwnPropertyNames = Object.getOwnPropertyNames,
1363 $keys = Object.keys,
1364 $window_names = (typeof window === 'object' ? $getOwnPropertyNames(window) : []);
1365
1366 function isStringKey(k) { return !symbolForKey(k); }
1367
1368 // 19.1.2.7 Object.getOwnPropertyNames ( O )
1369 define(
1370 Object, 'getOwnPropertyNames',
1371 function getOwnPropertyNames(o) {
1372 if (Object.prototype.toString.call(o) === '[object Window]') {
1373 // Workaround for cross-realm calling by IE itself.
1374 // https://github.com/inexorabletash/polyfill/issues/96
1375 try {
1376 return $getOwnPropertyNames(o).filter(isStringKey);
1377 } catch (_) {
1378 return $window_names.slice();
1379 }
1380 }
1381 return $getOwnPropertyNames(o).filter(isStringKey);
1382 }, !nativeSymbols);
1383
1384 // 19.1.2.8 Object.getOwnPropertySymbols ( O )
1385 define(
1386 Object, 'getOwnPropertySymbols',
1387 function getOwnPropertySymbols(o) {
1388 return $getOwnPropertyNames(o).filter(symbolForKey).map(symbolForKey);
1389 }, !nativeSymbols);
1390
1391 // 19.1.2.14 Object.keys ( O )
1392 define(
1393 Object, 'keys',
1394 function keys(o) {
1395 return $keys(o).filter(isStringKey);
1396 }, !nativeSymbols);
1397 }());
1398
1399 // 19.1.2.9 Object.getPrototypeOf ( O )
1400 // 19.1.2.10 Object.is ( value1, value2 )
1401 define(
1402 Object, 'is',
1403 function is(value1, value2) {
1404 return SameValue(value1, value2);
1405 });
1406
1407 // 19.1.2.11 Object.isExtensible ( O )
1408 // 19.1.2.12 Object.isFrozen ( O )
1409 // 19.1.2.13 Object.isSealed ( O )
1410
1411 // 19.1.2.14 Object.keys ( O )
1412 // see above
1413
1414 // 19.1.2.15 Object.preventExtensions ( O )
1415 // 19.1.2.16 Object.prototype
1416 // 19.1.2.17 Object.seal ( O )
1417
1418 // 19.1.2.18 Object.setPrototypeOf ( O, proto )
1419 define(
1420 Object, 'setPrototypeOf',
1421 function setPrototypeOf(o, proto) {
1422 if (Type(o) !== 'object') throw TypeError();
1423 if (Type(proto) !== 'object' && Type(proto) !== 'null') throw TypeError();
1424 o.__proto__ = proto;
1425 return o;
1426 }
1427 );
1428
1429 // 19.1.3 Properties of the Object Prototype Object
1430 // 19.1.3.1 Object.prototype.constructor
1431 // 19.1.3.2 Object.prototype.hasOwnProperty ( V )
1432 // 19.1.3.3 Object.prototype.isPrototypeOf ( V )
1433 // 19.1.3.4 Object.prototype.propertyIsEnumerable ( V )
1434 // 19.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
1435 // 19.1.3.6 Object.prototype.toString ( )
1436 hook(Object.prototype, 'toString',
1437 function() {
1438 var o = strict(this);
1439 if (o === Object(o) && $$toStringTag in o) {
1440 return '[object ' + o[$$toStringTag] + ']';
1441 }
1442 return undefined;
1443 });
1444
1445 // 19.1.3.7 Object.prototype.valueOf ( )
1446 // 19.1.4 Properties of Object Instances
1447
1448 // ---------------------------------------
1449 // 19.2 Function Objects
1450 // ---------------------------------------
1451
1452 // 19.2.1 The Function Constructor
1453 // 19.2.1.1 Function ( p1, p2, … , pn, body )
1454 // 19.2.2 Properties of the Function Constructor
1455 // 19.2.2.1 Function.length
1456 // 19.2.2.2 Function.prototype
1457 // 19.2.3 Properties of the Function Prototype Object
1458 // 19.2.3.1 Function.prototype.apply ( thisArg, argArray )
1459 // 19.2.3.2 Function.prototype.bind ( thisArg , ...args)
1460 // 19.2.3.3 Function.prototype.call (thisArg , ...args)
1461 // 19.2.3.4 Function.prototype.constructor
1462 // 19.2.3.5 Function.prototype.toString ( )
1463 // 19.2.3.6 Function.prototype[@@hasInstance] ( V )
1464 // 19.2.4 Function Instances
1465 // 19.2.4.1 length
1466 // 19.2.4.2 name
1467 // 19.2.4.3 prototype
1468
1469 // (No polyfillable changes from ES5)
1470
1471 // ---------------------------------------
1472 // 19.3 Boolean Objects
1473 // ---------------------------------------
1474
1475 // 19.3.1 The Boolean Constructor
1476 // 19.3.1.1 Boolean ( value )
1477 // 19.3.2 Properties of the Boolean Constructor
1478 // 19.3.2.1 Boolean.prototype
1479 // 19.3.3 Properties of the Boolean Prototype Object
1480 // 19.3.3.1 Boolean.prototype.constructor
1481 // 19.3.3.2 Boolean.prototype.toString ( )
1482 // 19.3.3.3 Boolean.prototype.valueOf ( )
1483 // 19.3.4 Properties of Boolean Instances
1484
1485 // (No polyfillable changes from ES5)
1486
1487 // ---------------------------------------
1488 // 19.4 Symbol Objects
1489 // ---------------------------------------
1490
1491 // Moved earlier in this script, so that other polyfills can depend on them.
1492
1493 // 19.4.3.4 Symbol.prototype [ @@toStringTag ]
1494 define(global.Symbol.prototype, global.Symbol.toStringTag, 'Symbol');
1495
1496 // ---------------------------------------
1497 // 19.5 Error Objects
1498 // ---------------------------------------
1499
1500 // 19.5.1 The Error Constructor
1501 // 19.5.1.1 Error ( message )
1502 // 19.5.1.2 new Error( ...argumentsList )
1503 // 19.5.2 Properties of the Error Constructor
1504 // 19.5.2.1 Error.prototype
1505 // 19.5.3 Properties of the Error Prototype Object
1506 // 19.5.3.1 Error.prototype.constructor
1507 // 19.5.3.2 Error.prototype.message
1508 // 19.5.3.3 Error.prototype.name
1509 // 19.5.3.4 Error.prototype.toString ( )
1510 // 19.5.4 Properties of Error Instances
1511 // 19.5.5 Native Error Types Used in This Standard
1512 // 19.5.5.1 EvalError
1513 // 19.5.5.2 RangeError
1514 // 19.5.5.3 ReferenceError
1515 // 19.5.5.4 SyntaxError
1516 // 19.5.5.5 TypeError
1517 // 19.5.5.6 URIError
1518 // 19.5.6 NativeError Object Structure
1519 // 19.5.6.1 NativeError Constructors
1520 // 19.5.6.1.1 NativeError ( message )
1521 // 19.5.6.1.2 new NativeError ( ...argumentsList )
1522 // 19.5.6.2 Properties of the NativeError Constructors
1523 // 19.5.6.2.1 NativeError.prototype
1524 // 19.5.6.3 Properties of the NativeError Prototype Objects
1525 // 19.5.6.4 Properties of NativeError Instances
1526
1527 // (No polyfillable changes from ES5)
1528
1529 // ---------------------------------------
1530 // 20 Numbers and Dates
1531 // ---------------------------------------
1532
1533 // ---------------------------------------
1534 // 20.1 Number Objects
1535 // ---------------------------------------
1536
1537 // 20.1.1 The Number Constructor
1538 // 20.1.1.1 Number ( [ value ] )
1539 // 20.1.1.2 new Number ( ...argumentsList )
1540 // 20.1.2 Properties of the Number Constructor
1541
1542 // 20.1.2.1 Number.EPSILON
1543 define(
1544 Number, 'EPSILON',
1545 (function () {
1546 var next, result;
1547 for (next = 1; 1 + next !== 1; next = next / 2)
1548 result = next;
1549 return result;
1550 }()));
1551
1552 // 20.1.2.2 Number.isFinite ( number )
1553 define(
1554 Number, 'isFinite',
1555 function isFinite(number) {
1556 if (Type(number) !== 'number') return false;
1557 if (number !== number || number === +Infinity || number === -Infinity) return false;
1558 return true;
1559 });
1560
1561 // 20.1.2.3 Number.isInteger ( number )
1562 define(
1563 Number, 'isInteger',
1564 function isInteger(number) {
1565 if (Type(number) !== 'number') return false;
1566 if (number !== number || number === +Infinity || number === -Infinity) return false;
1567 var integer = ToInteger(number);
1568 if (integer !== number) return false;
1569 return true;
1570 });
1571
1572 // 20.1.2.4 Number.isNaN ( number )
1573 define(
1574 Number, 'isNaN',
1575 function isNaN(number) {
1576 if (Type(number) !== 'number') return false;
1577 if (number !== number) return true;
1578 return false;
1579 });
1580
1581 // 20.1.2.5 Number.isSafeInteger ( number )
1582 define(
1583 Number, 'isSafeInteger',
1584 function isSafeInteger(number) {
1585 if (Type(number) !== 'number') return false;
1586 if (number !== number || number === +Infinity || number === -Infinity) return false;
1587 var integer = ToInteger(number);
1588 if (integer !== number) return false;
1589 if (abs(integer) <= (0x20000000000000 - 1)) // 2^53-1
1590 return true;
1591 return false;
1592 });
1593
1594 // 20.1.2.6 Number.MAX_SAFE_INTEGER
1595 define(
1596 Number, 'MAX_SAFE_INTEGER',
1597 9007199254740991); // 2^53-1
1598
1599 // 20.1.2.7 Number.MAX_VALUE
1600
1601 // 20.1.2.8 Number.MIN_SAFE_INTEGER
1602 define(
1603 Number, 'MIN_SAFE_INTEGER',
1604 -9007199254740991); // -2^53+1
1605
1606 // 20.1.2.9 Number.MIN_VALUE
1607 // 20.1.2.10 Number.NaN
1608 // 20.1.2.11 Number.NEGATIVE_INFINITY
1609
1610 // 20.1.2.12 Number.parseFloat ( string )
1611 define(Number, 'parseFloat', $parseFloat);
1612
1613 // 20.1.2.13 Number.parseInt ( string, radix )
1614 define(Number, 'parseInt', $parseInt);
1615
1616 // 20.1.2.14 Number.POSITIVE_INFINITY
1617 // 20.1.2.15 Number.prototype
1618
1619 // 20.1.3 Properties of the Number Prototype Object
1620 // 20.1.3.1 Number.prototype.constructor
1621 // 20.1.3.2 Number.prototype.toExponential ( fractionDigits )
1622 // 20.1.3.3 Number.prototype.toFixed ( fractionDigits )
1623 // 20.1.3.4 Number.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ])
1624 // 20.1.3.5 Number.prototype.toPrecision ( precision )
1625 // 20.1.3.6 Number.prototype.toString ( [ radix ] )
1626 // 20.1.3.7 Number.prototype.valueOf ( )
1627 // 20.1.4 Properties of Number Instances
1628
1629 // ---------------------------------------
1630 // 20.2 The Math Object
1631 // ---------------------------------------
1632
1633 // 20.2.1 Value Properties of the Math Object
1634 // 20.2.1.1 Math.E
1635 // 20.2.1.2 Math.LN10
1636 // 20.2.1.3 Math.LN2
1637 // 20.2.1.4 Math.LOG10E
1638 // 20.2.1.5 Math.LOG2E
1639 // 20.2.1.6 Math.PI
1640 // 20.2.1.7 Math.SQRT1_2
1641 // 20.2.1.8 Math.SQRT2
1642
1643 // 20.2.1.9 Math [ @@toStringTag ]
1644 define(Math, $$toStringTag, 'Math');
1645
1646 // 20.2.2 Function Properties of the Math Object
1647 // 20.2.2.1 Math.abs ( x )
1648 // 20.2.2.2 Math.acos ( x )
1649
1650 // 20.2.2.3 Math.acosh(x)
1651 define(
1652 Math, 'acosh',
1653 function acosh(x) {
1654 x = Number(x);
1655 return log(x + sqrt(x * x - 1));
1656 });
1657
1658 // 20.2.2.4 Math.asin ( x )
1659
1660 // 20.2.2.5 Math.asinh( x )
1661 define(
1662 Math, 'asinh',
1663 function asinh(x) {
1664 x = Number(x);
1665 if (SameValue(x, -0)) {
1666 return x;
1667 }
1668 var s = sqrt(x * x + 1);
1669 return (s === -x) ? log(0) : log(x + s);
1670 });
1671
1672 // 20.2.2.6 Math.atan ( x )
1673
1674 // 20.2.2.7 Math.atanh( x )
1675 define(
1676 Math, 'atanh',
1677 function atanh(x) {
1678 x = Number(x);
1679 return (x === 0) ? x : log((1 + x) / (1 - x)) / 2;
1680 });
1681
1682 // 20.2.2.8 Math.atan2 ( y, x )
1683
1684 // 20.2.2.9 Math.cbrt ( x )
1685 define(
1686 Math, 'cbrt',
1687 function cbrt(x) {
1688 x = Number(x);
1689 if ($isNaN(x/x)) {
1690 return x;
1691 }
1692 var r = pow(abs(x), 1/3);
1693 var t = x/r/r;
1694 return r + (r * (t-r) / (2*r + t));
1695 });
1696
1697 // 20.2.2.10 Math.ceil ( x )
1698
1699 // 20.2.2.11 Math.clz32 ( x )
1700 define(
1701 Math, 'clz32',
1702 function clz32(x) {
1703 function clz8(x) {
1704 return (x & 0xf0) ? (x & 0x80 ? 0 : x & 0x40 ? 1 : x & 0x20 ? 2 : 3) :
1705 (x & 0x08 ? 4 : x & 0x04 ? 5 : x & 0x02 ? 6 : x & 0x01 ? 7 : 8);
1706 }
1707 x = ToUint32(x);
1708 return x & 0xff000000 ? clz8(x >> 24) :
1709 x & 0xff0000 ? clz8(x >> 16) + 8 :
1710 x & 0xff00 ? clz8(x >> 8) + 16 : clz8(x) + 24;
1711 });
1712
1713
1714
1715 // 20.2.2.12 Math.cos ( x )
1716
1717 // 20.2.2.13 Math.cosh ( x )
1718 define(
1719 Math, 'cosh',
1720 function cosh(x) {
1721 x = Number(x);
1722 return (pow(E, x) + pow(E, -x)) / 2;
1723 });
1724
1725 // 20.2.2.14 Math.exp ( x )
1726
1727 // 20.2.2.15 Math.expm1 ( x )
1728 define(
1729 Math, 'expm1',
1730 function expm1(x) {
1731 x = Number(x);
1732 // from: http://www.johndcook.com/cpp_log1p.html
1733 if (SameValue(x, -0)) {
1734 return -0;
1735 } else if (abs(x) < 1e-5) {
1736 return x + 0.5 * x * x; // two terms of Taylor expansion
1737 } else {
1738 return exp(x) - 1;
1739 }
1740 });
1741
1742 // 20.2.2.16 Math.floor ( x )
1743
1744 // 20.2.2.17 Math.fround ( x )
1745 define(
1746 Math, 'fround',
1747 function fround(x) {
1748 if ($isNaN(x)) {
1749 return NaN;
1750 }
1751 if (1/x === +Infinity || 1/x === -Infinity || x === +Infinity || x === -Infinity) {
1752 return x;
1753 }
1754 return (new Float32Array([x]))[0];
1755 });
1756
1757 // 20.2.2.18 Math.hypot ( value1 [, value2 [ ... ] ] )
1758 define(
1759 Math, 'hypot',
1760 function hypot() {
1761 var values = [];
1762 var m = 0, sawNaN = false;
1763 for (var i = 0; i < arguments.length; ++i) {
1764 var n = abs(Number(arguments[i]));
1765 if (n === Infinity) return n;
1766 if (n !== n) sawNaN = true;
1767 if (n > m) m = n;
1768 values[i] = n;
1769 }
1770 if (sawNaN) return NaN;
1771 if (m === 0) return +0;
1772 var sum = +0;
1773 for (i = 0; i < values.length; ++i) {
1774 var r = values[i] / m;
1775 sum = sum + r * r;
1776 }
1777 return m * sqrt(sum);
1778 });
1779
1780 // 20.2.2.19 Math.imul ( x, y )
1781 define(
1782 Math, 'imul',
1783 function imul(x, y) {
1784 var a = ToUint32(x);
1785 var b = ToUint32(y);
1786 // (slow but accurate)
1787 var ah = (a >>> 16) & 0xffff;
1788 var al = a & 0xffff;
1789 var bh = (b >>> 16) & 0xffff;
1790 var bl = b & 0xffff;
1791 return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
1792 }, ('imul' in Math && Math.imul(1, 0x80000000) === 0) // Safari 7 bug
1793 );
1794
1795 // 20.2.2.20 Math.log ( x )
1796
1797 // 20.2.2.21 Math.log1p ( x )
1798 define(
1799 Math, 'log1p',
1800 function log1p(x) {
1801 x = Number(x);
1802 // from: http://www.johndcook.com/cpp_expm1.html
1803 if (x < -1) {
1804 return NaN;
1805 } else if (SameValue(x, -0)) {
1806 return -0;
1807 } else if (abs(x) > 1e-4) {
1808 return log(1 + x);
1809 } else {
1810 return (-0.5 * x + 1) * x;
1811 }
1812 });
1813
1814 // 20.2.2.22 Math.log10 ( x )
1815 define(
1816 Math, 'log10',
1817 function log10(x) {
1818 x = Number(x);
1819 return log(x) * LOG10E;
1820 });
1821
1822 // 20.2.2.23 Math.log2 ( x )
1823 define(
1824 Math, 'log2',
1825 function log2(x) {
1826 x = Number(x);
1827 return log(x) * LOG2E;
1828 });
1829
1830 // 20.2.2.24 Math.max ( value1, value2 , ...values )
1831 // 20.2.2.25 Math.min ( value1, value2 , ...values )
1832 // 20.2.2.26 Math.pow ( x, y )
1833 // 20.2.2.27 Math.random ( )
1834 // 20.2.2.28 Math.round ( x )
1835
1836 // 20.2.2.29 Math.sign(x)
1837 define(
1838 Math, 'sign',
1839 function sign(x) {
1840 x = Number(x);
1841 return x < 0 ? -1 : x > 0 ? 1 : x;
1842 });
1843
1844 // 20.2.2.30 Math.sin ( x )
1845
1846 // 20.2.2.31 Math.sinh( x )
1847 define(
1848 Math, 'sinh',
1849 function sinh(x) {
1850 x = Number(x);
1851 return SameValue(x, -0) ? x : (pow(E, x) - pow(E, -x)) / 2;
1852 });
1853
1854 // 20.2.2.32 Math.sqrt ( x )
1855 // 20.2.2.33 Math.tan ( x )
1856
1857 // 20.2.2.34 Math.tanh ( x )
1858 define(
1859 Math, 'tanh',
1860 function tanh(x) {
1861 x = Number(x);
1862 var n = pow(E, 2 * x) - 1,
1863 d = pow(E, 2 * x) + 1;
1864 if (SameValue(x, -0))
1865 return x;
1866 return (n === d) ? 1 : n / d; // Handle Infinity/Infinity
1867 });
1868
1869 // 20.2.2.35 Math.trunc ( x )
1870 define(
1871 Math, 'trunc',
1872 function trunc(x) {
1873 x = Number(x);
1874 return $isNaN(x) ? NaN :
1875 x < 0 ? ceil(x) : floor(x);
1876 });
1877
1878 // ---------------------------------------
1879 // 20.3 Date Objects
1880 // ---------------------------------------
1881
1882 // 20.3.1 Overview of Date Objects and Definitions of Abstract Operations
1883 // 20.3.1.1 Time Values and Time Range
1884 // 20.3.1.2 Day Number and Time within Day
1885 // 20.3.1.3 Year Number
1886 // 20.3.1.4 Month Number
1887 // 20.3.1.5 Date Number
1888 // 20.3.1.6 Week Day
1889 // 20.3.1.7 Local Time Zone Adjustment
1890 // 20.3.1.8 Daylight Saving Time Adjustment
1891 // 20.3.1.9 Local Time
1892 // 20.3.1.10 Hours, Minutes, Second, and Milliseconds
1893 // 20.3.1.11 MakeTime (hour, min, sec, ms)
1894 // 20.3.1.12 MakeDay (year, month, date)
1895 // 20.3.1.13 MakeDate (day, time)
1896 // 20.3.1.14 TimeClip (time)
1897 // 20.3.1.15 Date Time String Format
1898 // 20.3.1.15.1 Extended years
1899 // 20.3.2 The Date Constructor
1900 // 20.3.2.1 Date ( year, month [, date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] )
1901 // 20.3.2.2 Date ( value )
1902 // 20.3.2.3 Date ( )
1903 // 20.3.3 Properties of the Date Constructor
1904 // 20.3.3.1 Date.now ( )
1905 // 20.3.3.2 Date.parse (string)
1906 // 20.3.3.3 Date.prototype
1907 // 20.3.3.4 Date.UTC ( year, month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] )
1908 // 20.3.4 Properties of the Date Prototype Object
1909 // 20.3.4.1 Date.prototype.constructor
1910 // 20.3.4.2 Date.prototype.getDate ( )
1911 // 20.3.4.3 Date.prototype.getDay ( )
1912 // 20.3.4.4 Date.prototype.getFullYear ( )
1913 // 20.3.4.5 Date.prototype.getHours ( )
1914 // 20.3.4.6 Date.prototype.getMilliseconds ( )
1915 // 20.3.4.7 Date.prototype.getMinutes ( )
1916 // 20.3.4.8 Date.prototype.getMonth ( )
1917 // 20.3.4.9 Date.prototype.getSeconds ( )
1918 // 20.3.4.10 Date.prototype.getTime ( )
1919 // 20.3.4.11 Date.prototype.getTimezoneOffset ( )
1920 // 20.3.4.12 Date.prototype.getUTCDate ( )
1921 // 20.3.4.13 Date.prototype.getUTCDay ( )
1922 // 20.3.4.14 Date.prototype.getUTCFullYear ( )
1923 // 20.3.4.15 Date.prototype.getUTCHours ( )
1924 // 20.3.4.16 Date.prototype.getUTCMilliseconds ( )
1925 // 20.3.4.17 Date.prototype.getUTCMinutes ( )
1926 // 20.3.4.18 Date.prototype.getUTCMonth ( )
1927 // 20.3.4.19 Date.prototype.getUTCSeconds ( )
1928 // 20.3.4.20 Date.prototype.setDate ( date )
1929 // 20.3.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] )
1930 // 20.3.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
1931 // 20.3.4.23 Date.prototype.setMilliseconds ( ms )
1932 // 20.3.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
1933 // 20.3.4.25 Date.prototype.setMonth ( month [ , date ] )
1934 // 20.3.4.26 Date.prototype.setSeconds ( sec [ , ms ] )
1935 // 20.3.4.27 Date.prototype.setTime ( time )
1936 // 20.3.4.28 Date.prototype.setUTCDate ( date )
1937 // 20.3.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
1938 // 20.3.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
1939 // 20.3.4.31 Date.prototype.setUTCMilliseconds ( ms )
1940 // 20.3.4.32 Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] )
1941 // 20.3.4.33 Date.prototype.setUTCMonth ( month [ , date ] )
1942 // 20.3.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] )
1943 // 20.3.4.35 Date.prototype.toDateString ( )
1944 // 20.3.4.36 Date.prototype.toISOString ( )
1945 // 20.3.4.37 Date.prototype.toJSON ( key )
1946 // 20.3.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] )
1947 // 20.3.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
1948 // 20.3.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] )
1949 // 20.3.4.41 Date.prototype.toString ( )
1950 // 20.3.4.42 Date.prototype.toTimeString ( )
1951 // 20.3.4.43 Date.prototype.toUTCString ( )
1952 // 20.3.4.44 Date.prototype.valueOf ( )
1953 // 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
1954 // 20.3.5 Properties of Date Instances
1955
1956 // (No polyfillable changes from ES5)
1957
1958 // ---------------------------------------
1959 // 21 Text Processing
1960 // ---------------------------------------
1961
1962 var string_regexp_dispatch = (function() {
1963 var faux = {}, secret = Symbol();
1964 faux[Symbol.match] = function() { return secret; };
1965 return ("").match(faux) === secret;
1966 }());
1967
1968 // 21.1 String Objects
1969 // 21.1.1 The String Constructor
1970 // 21.1.1.1 String ( value )
1971 // 21.1.2 Properties of the String Constructor
1972 // 21.1.2.1 String.fromCharCode ( ...codeUnits )
1973
1974 // 21.1.2.2 String.fromCodePoint ( ...codePoints )
1975 define(
1976 String, 'fromCodePoint',
1977 function fromCodePoint(/*...codePoints*/) {
1978 var codePoints = arguments,
1979 length = codePoints.length,
1980 elements = [],
1981 nextIndex = 0;
1982 while (nextIndex < length) {
1983 var next = codePoints[nextIndex];
1984 var nextCP = Number(next);
1985 if (!SameValue(nextCP, ToInteger(nextCP)) ||
1986 nextCP < 0 || nextCP > 0x10FFFF) {
1987 throw RangeError('Invalid code point ' + nextCP);
1988 }
1989 if (nextCP < 0x10000) {
1990 elements.push(String.fromCharCode(nextCP));
1991 } else {
1992 nextCP -= 0x10000;
1993 elements.push(String.fromCharCode((nextCP >> 10) + 0xD800));
1994 elements.push(String.fromCharCode((nextCP % 0x400) + 0xDC00));
1995 }
1996 nextIndex += 1;
1997 }
1998 return elements.join('');
1999 });
2000
2001 // 21.1.2.3 String.prototype
2002
2003 // 21.1.2.4 String.raw ( template , ...substitutions )
2004 define(
2005 String, 'raw',
2006 function raw(template /*, ...substitutions*/) {
2007 var substitutions = [].slice.call(arguments, 1);
2008
2009 var cooked = Object(template);
2010 var rawValue = cooked['raw'];
2011 var raw = Object(rawValue);
2012 var len = raw['length'];
2013 var literalSegments = ToLength(len);
2014 if (literalSegments <= 0) return '';
2015 var stringElements = [];
2016 var nextIndex = 0;
2017 while (true) {
2018 var next = raw[nextIndex];
2019 var nextSeg = String(next);
2020 stringElements.push(nextSeg);
2021 if (nextIndex + 1 === literalSegments)
2022 return stringElements.join('');
2023 next = substitutions[nextIndex];
2024 var nextSub = String(next);
2025 stringElements.push(nextSub);
2026 nextIndex = nextIndex + 1;
2027 }
2028 });
2029
2030 // See https://githib.com/inexorabletash/uate for a more useful version.
2031
2032 // 21.1.3 Properties of the String Prototype Object
2033 // 21.1.3.1 String.prototype.charAt ( pos )
2034 // 21.1.3.2 String.prototype.charCodeAt ( pos )
2035
2036 // 21.1.3.3 String.prototype.codePointAt ( pos )
2037 define(
2038 String.prototype, 'codePointAt',
2039 function codePointAt(pos) {
2040 var o = strict(this);
2041 var s = String(o);
2042 var position = ToInteger(pos);
2043 var size = s.length;
2044 if (position < 0 || position >= size) return undefined;
2045 var first = s.charCodeAt(position);
2046 if (first < 0xD800 || first > 0xDBFF || position + 1 === size) return first;
2047 var second = s.charCodeAt(position + 1);
2048 if (second < 0xDC00 || second > 0xDFFF) return first;
2049 return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000;
2050 });
2051
2052 // 21.1.3.4 String.prototype.concat ( ...args )
2053 // 21.1.3.5 String.prototype.constructor
2054
2055 // 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] )
2056 define(
2057 String.prototype, 'endsWith',
2058 function endsWith(searchString) {
2059 var endPosition = arguments[1];
2060
2061 var o = strict(this);
2062 var s = String(o);
2063 var searchStr = String(searchString);
2064 var len = s.length;
2065 var pos = (endPosition === undefined) ? len : ToInteger(endPosition);
2066 var end = min(max(pos, 0), len);
2067 var searchLength = searchStr.length;
2068 var start = end - searchLength;
2069 if (start < 0) return false;
2070 if (s.substring(start, start + searchLength) === searchStr) return true;
2071 return false;
2072 });
2073
2074 // 21.1.3.7 String.prototype.includes ( searchString [ , position ] )
2075 define(
2076 String.prototype, 'includes',
2077 function includes(searchString) {
2078 var position = arguments[1];
2079
2080 var o = strict(this);
2081 var s = String(o);
2082 var searchStr = String(searchString);
2083 var pos = ToInteger(position);
2084 var len = s.length;
2085 var start = min(max(pos, 0), len);
2086 return s.indexOf(searchStr, start) !== -1;
2087 });
2088
2089 // 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] )
2090 // 21.1.3.9 String.prototype.lastIndexOf ( searchString [ , position ] )
2091 // 21.1.3.10 String.prototype.localeCompare ( that [, reserved1 [ , reserved2 ] ] )
2092 // 21.1.3.11 String.prototype.match ( regexp )
2093 define(
2094 String.prototype, 'match',
2095 function match(regexp) {
2096 var o = strict(this);
2097 var s = String(o);
2098 if (HasProperty(regexp, $$match)) var rx = regexp;
2099 else rx = new RegExp(regexp);
2100 return rx[$$match](s);
2101 }, !string_regexp_dispatch);
2102
2103 // 21.1.3.12 String.prototype.normalize ( [ form ] )
2104
2105 // Not practical due to table sizes; if needed, pull in:
2106 // https://github.com/walling/unorm/
2107
2108 // 21.1.3.13 String.prototype.repeat ( count )
2109 define(
2110 String.prototype, 'repeat',
2111 function repeat(count) {
2112 var o = strict(this);
2113 var s = String(o);
2114 var n = ToInteger(count);
2115 if (n < 0) throw RangeError();
2116 if (n === Infinity) throw RangeError();
2117 var t = new Array(n + 1).join(s);
2118 return t;
2119 });
2120
2121 // 21.1.3.14 String.prototype.replace (searchValue, replaceValue )
2122 define(
2123 String.prototype, 'replace',
2124 function replace(searchValue, replaceValue) {
2125 var o = strict(this);
2126 if (HasProperty(searchValue, $$replace))
2127 return searchValue[$$replace](o, replaceValue);
2128 return orig_replace.call(o, searchValue, replaceValue);
2129 }, !string_regexp_dispatch);
2130
2131 // 21.1.3.15 String.prototype.search ( regexp )
2132 define(
2133 String.prototype, 'search',
2134 function search(regexp) {
2135 var o = strict(this);
2136 var string = String(o);
2137 if (HasProperty(regexp, $$search)) var rx = regexp;
2138 else rx = new RegExp(regexp);
2139 return rx[$$search](string);
2140 }, !string_regexp_dispatch);
2141
2142 // 21.1.3.16 String.prototype.slice ( start, end )
2143 // 21.1.3.17 String.prototype.split ( separator, limit )
2144 define(
2145 String.prototype, 'split',
2146 function split(separator, limit) {
2147 var o = strict(this);
2148 if (HasProperty(separator, $$split))
2149 return separator[$$split](o, limit);
2150 return orig_split.call(o, separator, limit);
2151 }, !string_regexp_dispatch);
2152
2153 // 21.1.3.18 String.prototype.startsWith ( searchString [, position ] )
2154 define(
2155 String.prototype, 'startsWith',
2156 function startsWith(searchString) {
2157 var position = arguments[1];
2158
2159 var o = strict(this);
2160 var s = String(o);
2161 var searchStr = String(searchString);
2162 var pos = ToInteger(position);
2163 var len = s.length;
2164 var start = min(max(pos, 0), len);
2165 var searchLength = searchStr.length;
2166 if (searchLength + start > len) return false;
2167 if (s.substring(start, start + searchLength) === searchStr) return true;
2168 return false;
2169 });
2170
2171 // 21.1.3.19 String.prototype.substring ( start, end )
2172 // 21.1.3.20 String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] )
2173 // 21.1.3.21 String.prototype.toLocaleUpperCase ([ reserved1 [ , reserved2 ] ] )
2174 // 21.1.3.22 String.prototype.toLowerCase ( )
2175 // 21.1.3.23 String.prototype.toString ( )
2176 // 21.1.3.24 String.prototype.toUpperCase ( )
2177 // 21.1.3.25 String.prototype.trim ( )
2178 // 21.1.3.26 String.prototype.valueOf ( )
2179
2180 // 21.1.3.27 String.prototype [ @@iterator ]( )
2181 define(
2182 String.prototype, $$iterator,
2183 function entries() {
2184 return CreateStringIterator(this, 'value');
2185 });
2186
2187 // 21.1.4 Properties of String Instances
2188 // 21.1.4.1 length
2189
2190 // 21.1.5 String Iterator Objects
2191 /** @constructor */
2192 function StringIterator() {}
2193
2194 // 21.1.5.1 CreateStringIterator Abstract Operation
2195 function CreateStringIterator(string, kind) {
2196 var s = String(string);
2197 var iterator = new StringIterator;
2198 set_internal(iterator, '[[IteratedString]]', s);
2199 set_internal(iterator, '[[StringIteratorNextIndex]]', 0);
2200 set_internal(iterator, '[[StringIterationKind]]', kind);
2201 return iterator;
2202 }
2203
2204 // 21.1.5.2 The %StringIteratorPrototype% Object
2205 var $StringIteratorPrototype$ = Object.create($IteratorPrototype$);
2206 StringIterator.prototype = $StringIteratorPrototype$;
2207
2208 // 21.1.5.2.1 %StringIteratorPrototype%.next ( )
2209 define(
2210 $StringIteratorPrototype$, 'next',
2211 function next() {
2212 var o = ToObject(this);
2213 var s = String(o['[[IteratedString]]']),
2214 index = o['[[StringIteratorNextIndex]]'],
2215 len = s.length;
2216 if (index >= len) {
2217 set_internal(o, '[[StringIteratorNextIndex]]', Infinity);
2218 return CreateIterResultObject(undefined, true);
2219 }
2220 var cp = s.codePointAt(index);
2221 set_internal(o, '[[StringIteratorNextIndex]]', index + (cp > 0xFFFF ? 2 : 1));
2222 return CreateIterResultObject(String.fromCodePoint(cp), false);
2223 });
2224
2225 // 21.1.5.2.2 %StringIteratorPrototype% [ @@toStringTag ]
2226 define($StringIteratorPrototype$, $$toStringTag, 'String Iterator');
2227
2228 // 21.1.5.3 Properties of String Iterator Instances
2229
2230 // ---------------------------------------
2231 // 21.2 RegExp (Regular Expression) Objects
2232 // ---------------------------------------
2233
2234 // 21.2.1 Patterns
2235 // 21.2.2 Pattern Semantics
2236 // 21.2.2.1 Notation
2237 // 21.2.2.2 Pattern
2238 // 21.2.2.3 Disjunction
2239 // 21.2.2.4 Alternative
2240 // 21.2.2.5 Term
2241 // 21.2.2.6 Assertion
2242 // 21.2.2.7 Quantifier
2243 // 21.2.2.8 Atom
2244 // 21.2.2.9 AtomEscape
2245 // 21.2.2.10 CharacterEscape
2246 // 21.2.2.11 DecimalEscape
2247 // 21.2.2.12 CharacterClassEscape
2248 // 21.2.2.13 CharacterClass
2249 // 21.2.2.14 ClassRanges
2250 // 21.2.2.15 NonemptyClassRanges
2251 // 21.2.2.16 NonemptyClassRangesNoDash
2252 // 21.2.2.17 ClassAtom
2253 // 21.2.2.18 ClassAtomNoDash
2254 // 21.2.2.19 ClassEscape
2255 // 21.2.3 The RegExp Constructor
2256 // 21.2.3.1 RegExp ( pattern, flags )
2257 // 21.2.3.2 new RegExp( ...argumentsList )
2258 // 21.2.3.3 Abstract Operations for the RegExp Constructor
2259 // 21.2.4 Properties of the RegExp Constructor
2260 // 21.2.4.1 RegExp.prototype
2261 // 21.2.5 Properties of the RegExp Prototype Object
2262 // 21.2.5.1 RegExp.prototype.constructor
2263 // 21.2.5.2 RegExp.prototype.exec ( string )
2264
2265 // 21.2.5.3 get RegExp.prototype.flags
2266 if (!('flags' in RegExp.prototype)) {
2267 Object.defineProperty(
2268 RegExp.prototype, 'flags', {
2269 get: function() {
2270 var s = String(this);
2271 return s.substring(s.lastIndexOf('/') + 1);
2272 }
2273 });
2274 }
2275
2276 // 21.2.5.4 get RegExp.prototype.global
2277 // 21.2.5.5 get RegExp.prototype.ignoreCase
2278
2279 // 21.2.5.6 RegExp.prototype [ @@match ] ( string )
2280 define(RegExp.prototype, $$match, function(string) {
2281 var o = strict(this);
2282 return orig_match.call(string, o);
2283 });
2284
2285 // 21.2.5.7 get RegExp.prototype.multiline
2286
2287 // 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue )
2288 define(RegExp.prototype, $$replace, function(string, replaceValue) {
2289 var o = strict(this);
2290 return orig_replace.call(string, o, replaceValue);
2291 });
2292
2293 // 21.2.5.9 RegExp.prototype [ @@search ] ( string )
2294 define(RegExp.prototype, $$search, function(string) {
2295 var o = strict(this);
2296 return orig_search.call(string, o);
2297 });
2298
2299 // 21.2.5.10 get RegExp.prototype.source
2300
2301 // 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit )
2302 define(RegExp.prototype, $$split, function(string, limit) {
2303 var o = strict(this);
2304 return orig_split.call(string, o, limit);
2305 });
2306
2307 // 21.2.5.12 get RegExp.prototype.sticky
2308 // 21.2.5.13 RegExp.prototype.test( S )
2309 // 21.2.5.14 RegExp.prototype.toString ( )
2310 // 21.2.5.15 get RegExp.prototype.unicode
2311
2312 // 21.2.6 Properties of RegExp Instances
2313 // 21.2.6.1 lastIndex
2314
2315 // (No polyfillable changes from ES5)
2316
2317 // ---------------------------------------
2318 // 22 Indexed Collections
2319 // ---------------------------------------
2320
2321 // ---------------------------------------
2322 // 22.1 Array Objects
2323 // ---------------------------------------
2324
2325 // 22.1.1 The Array Constructor
2326 // 22.1.1.1 Array ( )
2327 // 22.1.1.2 Array (len)
2328 // 22.1.1.3 Array (...items )
2329
2330 // 22.1.2 Properties of the Array Constructor
2331
2332 // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
2333 define(
2334 Array, 'from',
2335 function from(items) {
2336 var mapfn = arguments[1];
2337 var thisArg = arguments[2];
2338
2339 var c = strict(this);
2340 if (mapfn === undefined) {
2341 var mapping = false;
2342 } else {
2343 if (!IsCallable(mapfn)) throw TypeError();
2344 var t = thisArg;
2345 mapping = true;
2346 }
2347 var usingIterator = GetMethod(items, $$iterator);
2348 if (usingIterator !== undefined) {
2349 if (IsConstructor(c)) {
2350 var a = new c();
2351 } else {
2352 a = new Array(0);
2353 }
2354 var iterator = GetIterator(items, usingIterator);
2355 var k = 0;
2356 while (true) {
2357 var next = IteratorStep(iterator);
2358 if (next === false) {
2359 a.length = k;
2360 return a;
2361 }
2362 var nextValue = IteratorValue(next);
2363 if (mapping)
2364 var mappedValue = mapfn.call(t, nextValue);
2365 else
2366 mappedValue = nextValue;
2367 a[k] = mappedValue;
2368 k += 1;
2369 }
2370 }
2371 var arrayLike = ToObject(items);
2372 var lenValue = arrayLike.length;
2373 var len = ToLength(lenValue);
2374 if (IsConstructor(c)) {
2375 a = new c(len);
2376 } else {
2377 a = new Array(len);
2378 }
2379 k = 0;
2380 while (k < len) {
2381 var kValue = arrayLike[k];
2382 if (mapping)
2383 mappedValue = mapfn.call(t, kValue, k);
2384 else
2385 mappedValue = kValue;
2386 a[k] = mappedValue;
2387 k += 1;
2388 }
2389 a.length = len;
2390 return a;
2391 });
2392
2393 // 22.1.2.2 Array.isArray ( arg )
2394
2395 // 22.1.2.3 Array.of ( ...items )
2396 define(
2397 Array, 'of',
2398 function of() {
2399 var items = arguments;
2400
2401 var lenValue = items.length;
2402 var len = ToUint32(lenValue);
2403 var c = strict(this), a;
2404 if (IsConstructor(c)) {
2405 a = new c(len);
2406 a = ToObject(a);
2407 } else {
2408 a = new Array(len);
2409 }
2410 var k = 0;
2411 while (k < len) {
2412 a[k] = items[k];
2413 k += 1;
2414 }
2415 a.length = len;
2416 return a;
2417 });
2418
2419 // 22.1.2.4 Array.prototype
2420 // 22.1.2.5 get Array [ @@species ]
2421 // 22.1.3 Properties of the Array Prototype Object
2422 // 22.1.3.1 Array.prototype.concat ( ...arguments )
2423 // 22.1.3.1.1 Runtime Semantics: IsConcatSpreadable ( O )
2424 // 22.1.3.2 Array.prototype.constructor
2425 // 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
2426 define(
2427 Array.prototype, 'copyWithin',
2428 function copyWithin(target, start/*, end*/) {
2429 var end = arguments[2];
2430
2431 var o = ToObject(this);
2432 var lenVal = o.length;
2433 var len = ToLength(lenVal);
2434 len = max(len, 0);
2435 var relativeTarget = ToInteger(target);
2436 var to;
2437 if (relativeTarget < 0)
2438 to = max(len + relativeTarget, 0);
2439 else
2440 to = min(relativeTarget, len);
2441 var relativeStart = ToInteger(start);
2442 var from;
2443 if (relativeStart < 0)
2444 from = max(len + relativeStart, 0);
2445 else
2446 from = min(relativeStart, len);
2447 var relativeEnd;
2448 if (end === undefined)
2449 relativeEnd = len;
2450 else
2451 relativeEnd = ToInteger(end);
2452 var final;
2453 if (relativeEnd < 0)
2454 final = max(len + relativeEnd, 0);
2455 else
2456 final = min(relativeEnd, len);
2457 var count = min(final - from, len - to);
2458 var direction;
2459 if (from < to && to < from + count) {
2460 direction = -1;
2461 from = from + count - 1;
2462 to = to + count - 1;
2463 } else {
2464 direction = 1;
2465 }
2466 while (count > 0) {
2467 var fromKey = String(from);
2468 var toKey = String(to);
2469 var fromPresent = HasProperty(o, fromKey);
2470 if (fromPresent) {
2471 var fromVal = o[fromKey];
2472 o[toKey] = fromVal;
2473 } else {
2474 delete o[toKey];
2475 }
2476 from = from + direction;
2477 to = to + direction;
2478 count = count - 1;
2479 }
2480 return o;
2481 });
2482
2483 // 22.1.3.4 Array.prototype.entries ( )
2484 var nativeArrayIteratorMethods =
2485 ('entries' in Array.prototype && 'next' in [].entries());
2486
2487 define(
2488 Array.prototype, 'entries',
2489 function entries() {
2490 return CreateArrayIterator(this, 'key+value');
2491 }, !nativeArrayIteratorMethods);
2492
2493 // 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg] )
2494
2495 // 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] )
2496 define(
2497 Array.prototype, 'fill',
2498 function fill(value/*, start, end*/) {
2499 var start = arguments[1],
2500 end = arguments[2];
2501
2502 var o = ToObject(this);
2503 var lenVal = o.length;
2504 var len = ToLength(lenVal);
2505 len = max(len, 0);
2506 var relativeStart = ToInteger(start);
2507 var k;
2508 if (relativeStart < 0)
2509 k = max((len + relativeStart), 0);
2510 else
2511 k = min(relativeStart, len);
2512 var relativeEnd;
2513 if (end === undefined)
2514 relativeEnd = len;
2515 else
2516 relativeEnd = ToInteger(end);
2517 var final;
2518 if (relativeEnd < 0)
2519 final = max((len + relativeEnd), 0);
2520 else
2521 final = min(relativeEnd, len);
2522 while (k < final) {
2523 var pk = String(k);
2524 o[pk] = value;
2525 k += 1;
2526 }
2527 return o;
2528 });
2529
2530 // 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] )
2531
2532 // 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] )
2533 define(
2534 Array.prototype, 'find',
2535 function find(predicate) {
2536 var o = ToObject(this);
2537 var lenValue = o.length;
2538 var len = ToInteger(lenValue);
2539 if (!IsCallable(predicate)) throw TypeError();
2540 var t = arguments.length > 1 ? arguments[1] : undefined;
2541 var k = 0;
2542 while (k < len) {
2543 var pk = String(k);
2544 var kPresent = HasProperty(o, pk);
2545 if (kPresent) {
2546 var kValue = o[pk];
2547 var testResult = predicate.call(t, kValue, k, o);
2548 if (Boolean(testResult)) {
2549 return kValue;
2550 }
2551 }
2552 ++k;
2553 }
2554 return undefined;
2555 });
2556
2557 // 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] )
2558 define(
2559 Array.prototype, 'findIndex',
2560 function findIndex(predicate) {
2561 var o = ToObject(this);
2562 var lenValue = o.length;
2563 var len = ToLength(lenValue);
2564 if (!IsCallable(predicate)) throw TypeError();
2565 var t = arguments.length > 1 ? arguments[1] : undefined;
2566 var k = 0;
2567 while (k < len) {
2568 var pk = String(k);
2569 var kPresent = HasProperty(o, pk);
2570 if (kPresent) {
2571 var kValue = o[pk];
2572 var testResult = predicate.call(t, kValue, k, o);
2573 if (Boolean(testResult)) {
2574 return k;
2575 }
2576 }
2577 ++k;
2578 }
2579 return -1;
2580 });
2581
2582 // 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] )
2583 // 22.1.3.11 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
2584 // 22.1.3.12 Array.prototype.join (separator)
2585
2586 // 22.1.3.13 Array.prototype.keys ( )
2587 define(
2588 Array.prototype, 'keys',
2589 function keys() {
2590 return CreateArrayIterator(this, 'key');
2591 }, !nativeArrayIteratorMethods);
2592
2593 // 22.1.3.14 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
2594 // 22.1.3.15 Array.prototype.map ( callbackfn [ , thisArg ] )
2595 // 22.1.3.16 Array.prototype.pop ( )
2596 // 22.1.3.17 Array.prototype.push ( ...items )
2597 // 22.1.3.18 Array.prototype.reduce ( callbackfn [ , initialValue ] )
2598 // 22.1.3.19 Array.prototype.reduceRight ( callbackfn [ , initialValue ] )
2599 // 22.1.3.20 Array.prototype.reverse ( )
2600 // 22.1.3.21 Array.prototype.shift ( )
2601 // 22.1.3.22 Array.prototype.slice (start, end)
2602 // 22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] )
2603 // 22.1.3.24 Array.prototype.sort (comparefn)
2604 // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items )
2605 // 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
2606 // 22.1.3.27 Array.prototype.toString ( )
2607 // 22.1.3.28 Array.prototype.unshift ( ...items )
2608
2609 // 22.1.3.29 Array.prototype.values ( )
2610 define(
2611 Array.prototype, 'values',
2612 function values() {
2613 return CreateArrayIterator(this, 'value');
2614 }, !nativeArrayIteratorMethods);
2615
2616 // 22.1.3.30 Array.prototype [ @@iterator ] ( )
2617 define(
2618 Array.prototype, $$iterator,
2619 Array.prototype.values
2620 );
2621
2622 // 22.1.3.31 Array.prototype [ @@unscopables ]
2623 // 22.1.4 Properties of Array Instances
2624 // 22.1.4.1 length
2625
2626 // 22.1.5 Array Iterator Objects
2627 function ArrayIterator() {}
2628
2629 // 22.1.5.1 CreateArrayIterator Abstract Operation
2630 function CreateArrayIterator(array, kind) {
2631 var o = ToObject(array);
2632 var iterator = new ArrayIterator;
2633 set_internal(iterator, '[[IteratedObject]]', o);
2634 set_internal(iterator, '[[ArrayIteratorNextIndex]]', 0);
2635 set_internal(iterator, '[[ArrayIterationKind]]', kind);
2636 return iterator;
2637 }
2638
2639 // 22.1.5.2 The %ArrayIteratorPrototype% Object
2640 var $ArrayIteratorPrototype$ = Object.create($IteratorPrototype$);
2641 ArrayIterator.prototype = $ArrayIteratorPrototype$;
2642
2643 // 22.1.5.2.1 %ArrayIteratorPrototype%. next( )
2644 define(
2645 $ArrayIteratorPrototype$, 'next',
2646 function next() {
2647 var o = strict(this);
2648 if (Type(o) !== 'object') throw TypeError();
2649 var a = o['[[IteratedObject]]'],
2650 index = o['[[ArrayIteratorNextIndex]]'],
2651 itemKind = o['[[ArrayIterationKind]]'],
2652 lenValue = a.length,
2653 len = ToUint32(lenValue),
2654 elementKey,
2655 elementValue;
2656 if (itemKind.indexOf('sparse') !== -1) {
2657 var found = false;
2658 while (!found && index < len) {
2659 elementKey = String(index);
2660 found = HasProperty(a, elementKey);
2661 if (!found) {
2662 index += 1;
2663 }
2664 }
2665 }
2666 if (index >= len) {
2667 set_internal(o, '[[ArrayIteratorNextIndex]]', Infinity);
2668 return CreateIterResultObject(undefined, true);
2669 }
2670 elementKey = index;
2671 set_internal(o, '[[ArrayIteratorNextIndex]]', index + 1);
2672 if (itemKind.indexOf('value') !== -1)
2673 elementValue = a[elementKey];
2674 if (itemKind.indexOf('key+value') !== -1)
2675 return CreateIterResultObject([elementKey, elementValue], false);
2676 if (itemKind.indexOf('key') !== -1)
2677 return CreateIterResultObject(elementKey, false);
2678 if (itemKind === 'value')
2679 return CreateIterResultObject(elementValue, false);
2680 throw Error('Internal error');
2681 });
2682
2683 // 22.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ]
2684 define($ArrayIteratorPrototype$, $$toStringTag, 'Array Iterator');
2685
2686 // 22.1.5.3 Properties of Array Iterator Instances
2687
2688
2689 // ---------------------------------------
2690 // 22.2 TypedArray Objects
2691 // ---------------------------------------
2692
2693 // See typedarray.js for TypedArray polyfill
2694
2695 ['Int8Array', 'Uint8Array', 'Uint8ClampedArray',
2696 'Int16Array', 'Uint16Array',
2697 'Int32Array', 'Uint32Array',
2698 'Float32Array', 'Float64Array'].forEach(function ($TypedArrayName$) {
2699 if (!($TypedArrayName$ in global))
2700 return;
2701 var $TypedArray$ = global[$TypedArrayName$];
2702
2703 // 22.2.1 The %TypedArray% Intrinsic Object
2704 // 22.2.1.1 %TypedArray% ( length )
2705 // 22.2.1.2 %TypedArray% ( typedArray )
2706 // 22.2.1.3 %TypedArray% ( object )
2707 // 22.2.1.4 %TypedArray% ( buffer [ , byteOffset [ , length ] ] )
2708 // 22.2.1.5 %TypedArray% ( all other argument combinations )
2709 // 22.2.2 Properties of the %TypedArray% Intrinsic Object
2710
2711 // 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
2712 define(
2713 $TypedArray$, 'from',
2714 function from(source) {
2715 var mapfn = arguments[1];
2716 var thisArg = arguments[2];
2717
2718 var c = strict(this);
2719 if (!IsConstructor(c)) throw TypeError();
2720 if (mapfn === undefined) {
2721 var mapping = false;
2722 } else {
2723 if (IsCallable(mapfn)) throw TypeError();
2724 var t = thisArg;
2725 mapping = true;
2726 }
2727 var usingIterator = GetMethod(source, $$iterator);
2728 if (usingIterator !== undefined) {
2729 var iterator = GetIterator(source, usingIterator);
2730 var values = [];
2731 var next = true;
2732 while (next !== false) {
2733 next = IteratorStep(iterator);
2734 if (next !== false) {
2735 var nextValue = IteratorValue(next);
2736 values.push(nextValue);
2737 }
2738 }
2739 var len = values.length;
2740 var newObj = new c(len);
2741 var k = 0;
2742 while (k < len) {
2743 var kValue = values.shift();
2744 if (mapping) {
2745 var mappedValue = mapfn.call(t, kValue);
2746 } else {
2747 mappedValue = kValue;
2748 }
2749 newObj[k] = mappedValue;
2750 ++k;
2751 }
2752 console.assert(values.length === 0);
2753 return newObj;
2754 }
2755 var arrayLike = ToObject(source);
2756 var lenValue = arrayLike.length;
2757 len = ToLength(lenValue);
2758 newObj = new c(len);
2759 k = 0;
2760 while (k < len) {
2761 kValue = arrayLike[k];
2762 if (mapping) {
2763 mappedValue = mapfn.call(t, kValue, k);
2764 } else {
2765 mappedValue = kValue;
2766 }
2767 newObj[k] = mappedValue;
2768 ++k;
2769 }
2770 return newObj;
2771 });
2772
2773 // 22.2.2.2 %TypedArray%.of ( ...items )
2774 define(
2775 $TypedArray$, 'of',
2776 function of() {
2777 var items = arguments;
2778
2779 var len = items.length;
2780 var c = strict(this);
2781 var newObj = new c(len);
2782 var k = 0;
2783 while (k < len) {
2784 newObj[k] = items[k];
2785 ++k;
2786 }
2787 return newObj;
2788 });
2789
2790 // 22.2.2.3 %TypedArray%.prototype
2791 // 22.2.2.4 get %TypedArray% [ @@species ]
2792 // 22.2.3 Properties of the %TypedArrayPrototype% Object
2793 // 22.2.3.1 get %TypedArray%.prototype.buffer
2794 // 22.2.3.2 get %TypedArray%.prototype.byteLength
2795 // 22.2.3.3 get %TypedArray%.prototype.byteOffset
2796 // 22.2.3.4 %TypedArray%.prototype.constructor
2797
2798 // 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] )
2799 define($TypedArray$.prototype, 'copyWithin', Array.prototype.copyWithin);
2800
2801 // 22.2.3.6 %TypedArray%.prototype.entries ( )
2802 define($TypedArray$.prototype, 'entries', Array.prototype.entries);
2803
2804 // 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] )
2805 define($TypedArray$.prototype, 'every', Array.prototype.every);
2806
2807 // 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] )
2808 define(
2809 $TypedArray$.prototype, 'fill',
2810 //Array.prototype.fill // Doesn't work in Safari 7
2811 function fill(value/*, start, end*/) {
2812 var start = arguments[1],
2813 end = arguments[2];
2814
2815 var o = ToObject(this);
2816 var lenVal = o.length;
2817 var len = ToLength(lenVal);
2818 len = max(len, 0);
2819 var relativeStart = ToInteger(start);
2820 var k;
2821 if (relativeStart < 0) k = max((len + relativeStart), 0);
2822 else k = min(relativeStart, len);
2823 var relativeEnd;
2824 if (end === undefined) relativeEnd = len;
2825 else relativeEnd = ToInteger(end);
2826 var final;
2827 if (relativeEnd < 0) final = max((len + relativeEnd), 0);
2828 else final = min(relativeEnd, len);
2829 while (k < final) {
2830 var pk = String(k);
2831 o[pk] = value;
2832 k += 1;
2833 }
2834 return o;
2835 });
2836
2837 // 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] )
2838 define(
2839 $TypedArray$.prototype, 'filter',
2840 function filter(callbackfn) {
2841 var thisArg = arguments[1];
2842
2843 var o = ToObject(this);
2844 var lenVal = o.length;
2845 var len = ToLength(lenVal);
2846 if (!IsCallable(callbackfn)) throw TypeError();
2847 var t = thisArg;
2848 var c = o.constructor;
2849 var kept = [];
2850 var k = 0;
2851 var captured = 0;
2852 while (k < len) {
2853 var kValue = o[k];
2854 var selected = callbackfn.call(t, kValue, k, o);
2855 if (selected) {
2856 kept.push(kValue);
2857 ++captured;
2858 }
2859 ++k;
2860 }
2861 var a = new c(captured);
2862 var n = 0;
2863 for (var i = 0; i < kept.length; ++i) {
2864 var e = kept[i];
2865 a[n] = e;
2866 ++n;
2867 }
2868 return a;
2869 });
2870
2871 // 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
2872 define($TypedArray$.prototype, 'find', Array.prototype.find);
2873
2874 // 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )
2875 define($TypedArray$.prototype, 'findIndex', Array.prototype.findIndex);
2876
2877 // 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] )
2878 define($TypedArray$.prototype, 'forEach', Array.prototype.forEach);
2879
2880 // 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
2881 define($TypedArray$.prototype, 'indexOf', Array.prototype.indexOf);
2882
2883 // 22.2.3.14 %TypedArray%.prototype.join ( separator )
2884 define($TypedArray$.prototype, 'join', Array.prototype.join);
2885
2886 // 22.2.3.15 %TypedArray%.prototype.keys ( )
2887 define($TypedArray$.prototype, 'keys', Array.prototype.keys);
2888
2889 // 22.2.3.16 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
2890 define($TypedArray$.prototype, 'lastIndexOf', Array.prototype.lastIndexOf);
2891
2892 // 22.2.3.17 get %TypedArray%.prototype.length
2893
2894 // 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
2895 define(
2896 $TypedArray$.prototype, 'map',
2897 function map(callbackfn) {
2898 var thisArg = arguments[1];
2899
2900 var o = ToObject(this);
2901 var lenValue = o.length;
2902 var len = ToLength(lenValue);
2903 if (!IsCallable(callbackfn)) throw TypeError();
2904 var t = thisArg;
2905 var a = undefined;
2906 var c = o.constructor;
2907 if (IsConstructor(c))
2908 a = new c(len);
2909 if (a === undefined)
2910 a = new Array(len);
2911 var k = 0;
2912 while (k < len) {
2913 var kPresent = HasProperty(o, k);
2914 if (kPresent) {
2915 var kValue = o[k];
2916 var mappedValue = callbackfn.call(t, kValue, k, o);
2917 a[k] = mappedValue;
2918 }
2919 ++k;
2920 }
2921 return a;
2922 });
2923
2924 // 22.2.3.19 %TypedArray%.prototype.reduce ( callbackfn [, initialValue] )
2925 define($TypedArray$.prototype, 'reduce', Array.prototype.reduce);
2926
2927 // 22.2.3.20 %TypedArray%.prototype.reduceRight ( callbackfn [, initialValue] )
2928 define($TypedArray$.prototype, 'reduceRight', Array.prototype.reduceRight);
2929
2930 // 22.2.3.21 %TypedArray%.prototype.reverse ( )
2931 define($TypedArray$.prototype, 'reverse', Array.prototype.reverse);
2932
2933 // 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ])
2934 // 22.2.3.22.1 %TypedArray%.prototype.set (array [ , offset ] )
2935 // 22.2.3.22.2 %TypedArray%.prototype.set(typedArray [, offset ] )
2936
2937 // 22.2.3.23 %TypedArray%.prototype.slice ( start, end )
2938 define(
2939 $TypedArray$.prototype, 'slice',
2940 function slice(start, end) {
2941 var o = ToObject(this);
2942 var lenVal = o.length;
2943 var len = ToLength(lenVal);
2944 var relativeStart = ToInteger(start);
2945 var k = (relativeStart < 0) ? max(len + relativeStart, 0) : min(relativeStart, len);
2946 var relativeEnd = (end === undefined) ? len : ToInteger(end);
2947 var final = (relativeEnd < 0) ? max(len + relativeEnd, 0) : min(relativeEnd, len);
2948 var count = final - k;
2949 var c = o.constructor;
2950 if (IsConstructor(c)) {
2951 var a = new c(count);
2952 } else {
2953 throw TypeError();
2954 }
2955 var n = 0;
2956 while (k < final) {
2957 var kValue = o[k];
2958 a[n] = kValue;
2959 ++k;
2960 ++n;
2961 }
2962 return a;
2963 });
2964
2965 // 22.2.3.24 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
2966 define($TypedArray$.prototype, 'some', Array.prototype.some);
2967
2968 // 22.2.3.25 %TypedArray%.prototype.sort ( comparefn )
2969 define(
2970 $TypedArray$.prototype, 'sort',
2971 function sort() {
2972 var comparefn = arguments[0];
2973
2974 function sortCompare(x, y) {
2975 console.assert(Type(x) === 'number' && Type(y) === 'number');
2976 if (x !== x && y !== y) return +0;
2977 if (x !== x) return 1;
2978 if (y !== y) return -1;
2979 if (comparefn !== undefined) {
2980 return comparefn(x, y);
2981 }
2982 if (x < y) return -1;
2983 if (x > y) return 1;
2984 return +0;
2985 }
2986 return Array.prototype.sort.call(this, sortCompare);
2987 });
2988
2989 // 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] )
2990 // 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
2991 // 22.2.3.28 %TypedArray%.prototype.toString ( )
2992
2993 // 22.2.3.29 %TypedArray%.prototype.values ( )
2994 define($TypedArray$.prototype, 'values', Array.prototype.values);
2995
2996 // 22.2.3.30 %TypedArray%.prototype [ @@iterator ] ( )
2997 define(
2998 $TypedArray$.prototype, $$iterator,
2999 $TypedArray$.prototype.values
3000 );
3001
3002 // 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ]
3003 define($TypedArray$.prototype, $$toStringTag, $TypedArrayName$);
3004
3005 // 22.2.4 The TypedArray Constructors
3006 // 22.2.4.1TypedArray( ... argumentsList)
3007 // 22.2.5 Properties of the TypedArray Constructors
3008 // 22.2.5.1 TypedArray.BYTES_PER_ELEMENT
3009 // 22.2.5.2 TypedArray.prototype
3010 // 22.2.6 Properties of TypedArray Prototype Objects
3011 // 22.2.6.1 TypedArray.prototype.BYTES_PER_ELEMENT
3012 // 22.2.6.2 TypedArray.prototype.constructor
3013 // 22.2.7 Properties of TypedArray Instances
3014 });
3015
3016 // ---------------------------------------
3017 // 23 Keyed Collection
3018 // ---------------------------------------
3019
3020 // ---------------------------------------
3021 // 23.1 Map Objects
3022 // ---------------------------------------
3023
3024 (function() {
3025 // 23.1.1 The Map Constructor
3026
3027 // 23.1.1.1 Map ( [ iterable ] )
3028 /** @constructor */
3029 function Map(/*iterable*/) {
3030 var map = strict(this);
3031 var iterable = arguments[0];
3032
3033 if (Type(map) !== 'object') throw TypeError();
3034 if ('[[MapData]]' in map) throw TypeError();
3035
3036 if (iterable !== undefined) {
3037 var adder = map['set'];
3038 if (!IsCallable(adder)) throw TypeError();
3039 var iter = GetIterator(ToObject(iterable));
3040 }
3041 set_internal(map, '[[MapData]]', { keys: [], values: [] });
3042 if (iter === undefined) return map;
3043 while (true) {
3044 var next = IteratorStep(iter);
3045 if (next === false)
3046 return map;
3047 var nextItem = IteratorValue(next);
3048 if (Type(nextItem) !== 'object') throw TypeError();
3049 var k = nextItem[0];
3050 var v = nextItem[1];
3051 adder.call(map, k, v);
3052 }
3053
3054 return map;
3055 }
3056
3057 if (!('Map' in global) || OVERRIDE_NATIVE_FOR_TESTING ||
3058 (function() { try { new global.Map([]); return false; } catch (_) { return true; } }()) ||
3059 (function() { try { return !new global.Map().entries().next; } catch (_) { return true; } }()) ||
3060 (new global.Map([['a', 1]]).size !== 1))
3061 global.Map = Map;
3062
3063
3064 function MapDataIndexOf(mapData, key) {
3065 var i;
3066 if (key === key) return mapData.keys.indexOf(key);
3067 // Slow case for NaN
3068 for (i = 0; i < mapData.keys.length; i += 1)
3069 if (SameValueZero(mapData.keys[i], key)) return i;
3070 return -1;
3071 }
3072
3073 // 23.1.1.2 new Map ( ... argumentsList )
3074 // 23.1.2 Properties of the Map Constructor
3075 // 23.1.2.1 Map.prototype
3076 var $MapPrototype$ = {};
3077 Map.prototype = $MapPrototype$;
3078
3079 // 23.1.2.2 get Map [ @@species ]
3080
3081 // 23.1.3 Properties of the Map Prototype Object
3082 // 23.1.3.1 Map.prototype.clear ()
3083 define(
3084 Map.prototype, 'clear',
3085 function clear() {
3086 var m = strict(this);
3087 if (Type(m) !== 'object') throw TypeError();
3088 if (!('[[MapData]]' in m)) throw TypeError();
3089 if (m['[[MapData]]'] === undefined) throw TypeError();
3090 var entries = m['[[MapData]]'];
3091 entries.keys.length = 0;
3092 entries.values.length = 0;
3093 return undefined;
3094 });
3095
3096 // 23.1.3.2 Map.prototype.constructor
3097
3098 // 23.1.3.3 Map.prototype.delete ( key )
3099 define(
3100 Map.prototype, 'delete',
3101 function delete_(key) {
3102 var m = strict(this);
3103 if (Type(m) !== 'object') throw TypeError();
3104 if (!('[[MapData]]' in m)) throw TypeError();
3105 if (m['[[MapData]]'] === undefined) throw TypeError();
3106 var entries = m['[[MapData]]'];
3107 var i = MapDataIndexOf(entries, key);
3108 if (i < 0) return false;
3109 entries.keys[i] = empty;
3110 entries.values[i] = empty;
3111 return true;
3112 });
3113
3114 // 23.1.3.4 Map.prototype.entries ( )
3115 define(
3116 Map.prototype, 'entries',
3117 function entries() {
3118 var m = strict(this);
3119 if (Type(m) !== 'object') throw TypeError();
3120 return CreateMapIterator(m, 'key+value');
3121 });
3122
3123 // 23.1.3.5 Map.prototype.forEach ( callbackfn [ , thisArg ] )
3124 define(
3125 Map.prototype, 'forEach',
3126 function forEach(callbackfn /*, thisArg*/) {
3127 var thisArg = arguments[1];
3128
3129 var m = strict(this);
3130 if (Type(m) !== 'object') throw TypeError();
3131 if (!('[[MapData]]' in m)) throw TypeError();
3132 if (m['[[MapData]]'] === undefined) throw TypeError();
3133 var entries = m['[[MapData]]'];
3134
3135 if (!IsCallable(callbackfn)) {
3136 throw TypeError('First argument to forEach is not callable.');
3137 }
3138 for (var i = 0; i < entries.keys.length; ++i) {
3139 if (entries.keys[i] !== empty) {
3140 callbackfn.call(thisArg, entries.values[i], entries.keys[i], m);
3141 }
3142 }
3143 return undefined;
3144 });
3145
3146 // 23.1.3.6 Map.prototype.get ( key )
3147 define(
3148 Map.prototype, 'get',
3149 function get(key) {
3150 var m = strict(this);
3151 if (Type(m) !== 'object') throw TypeError();
3152 if (!('[[MapData]]' in m)) throw TypeError();
3153 if (m['[[MapData]]'] === undefined) throw TypeError();
3154 var entries = m['[[MapData]]'];
3155 var i = MapDataIndexOf(entries, key);
3156 if (i >= 0) return entries.values[i];
3157 return undefined;
3158 });
3159
3160 // 23.1.3.7 Map.prototype.has ( key )
3161 define(
3162 Map.prototype, 'has',
3163 function has(key) {
3164 var m = strict(this);
3165 if (Type(m) !== 'object') throw TypeError();
3166 if (!('[[MapData]]' in m)) throw TypeError();
3167 if (m['[[MapData]]'] === undefined) throw TypeError();
3168 var entries = m['[[MapData]]'];
3169 if (MapDataIndexOf(entries, key) >= 0) return true;
3170 return false;
3171 });
3172
3173 // 23.1.3.8 Map.prototype.keys ( )
3174 define(
3175 Map.prototype, 'keys',
3176 function keys() {
3177 var m = strict(this);
3178 if (Type(m) !== 'object') throw TypeError();
3179 return CreateMapIterator(m, 'key');
3180 });
3181
3182 // 23.1.3.9 Map.prototype.set ( key , value )
3183 define(
3184 Map.prototype, 'set',
3185 function set(key, value) {
3186 var m = strict(this);
3187 if (Type(m) !== 'object') throw TypeError();
3188 if (!('[[MapData]]' in m)) throw TypeError();
3189 if (m['[[MapData]]'] === undefined) throw TypeError();
3190 var entries = m['[[MapData]]'];
3191 var i = MapDataIndexOf(entries, key);
3192 if (i < 0) i = entries.keys.length;
3193 if (SameValue(key, -0)) key = 0;
3194 entries.keys[i] = key;
3195 entries.values[i] = value;
3196 return m;
3197 });
3198
3199 // 23.1.3.10 get Map.prototype.size
3200 Object.defineProperty(
3201 Map.prototype, 'size', {
3202 get: function() {
3203 var m = strict(this);
3204 if (Type(m) !== 'object') throw TypeError();
3205 if (!('[[MapData]]' in m)) throw TypeError();
3206 if (m['[[MapData]]'] === undefined) throw TypeError();
3207 var entries = m['[[MapData]]'];
3208 var count = 0;
3209 for (var i = 0; i < entries.keys.length; ++i) {
3210 if (entries.keys[i] !== empty)
3211 count = count + 1;
3212 }
3213 return count;
3214 }
3215 });
3216
3217 // 23.1.3.11 Map.prototype.values ( )
3218 define(
3219 Map.prototype, 'values',
3220 function values() {
3221 var m = strict(this);
3222 if (Type(m) !== 'object') throw TypeError();
3223 return CreateMapIterator(m, 'value');
3224 });
3225
3226 // 23.1.3.12 Map.prototype [ @@iterator ]( )
3227 define(
3228 Map.prototype, $$iterator,
3229 function() {
3230 var m = strict(this);
3231 if (Type(m) !== 'object') throw TypeError();
3232 return CreateMapIterator(m, 'key+value');
3233 });
3234
3235 // 23.1.3.13 Map.prototype [ @@toStringTag ]
3236 define(global.Map.prototype, $$toStringTag, 'Map');
3237
3238 // 23.1.4 Properties of Map Instances
3239 // 23.1.5 Map Iterator Objects
3240
3241 /** @constructor */
3242 function MapIterator() {}
3243
3244 // 23.1.5.1 CreateMapIterator Abstract Operation
3245 function CreateMapIterator(map, kind) {
3246 if (Type(map) !== 'object') throw TypeError();
3247 if (!('[[MapData]]' in map)) throw TypeError();
3248 if (map['[[MapData]]'] === undefined) throw TypeError();
3249 var iterator = new MapIterator;
3250 set_internal(iterator, '[[Map]]', map);
3251 set_internal(iterator, '[[MapNextIndex]]', 0);
3252 set_internal(iterator, '[[MapIterationKind]]', kind);
3253 return iterator;
3254 }
3255
3256 // 23.1.5.2 The %MapIteratorPrototype% Object
3257 var $MapIteratorPrototype$ = Object.create($IteratorPrototype$);
3258 MapIterator.prototype = $MapIteratorPrototype$;
3259
3260 // 23.1.5.2.1 %MapIteratorPrototype%.next ( )
3261 define(
3262 $MapIteratorPrototype$, 'next',
3263 function next() {
3264 var o = strict(this);
3265 if (Type(o) !== 'object') throw TypeError();
3266 var m = o['[[Map]]'],
3267 index = o['[[MapNextIndex]]'],
3268 itemKind = o['[[MapIterationKind]]'],
3269 entries = m['[[MapData]]'];
3270 while (index < entries.keys.length) {
3271 var e = {key: entries.keys[index], value: entries.values[index]};
3272 index = index += 1;
3273 set_internal(o, '[[MapNextIndex]]', index);
3274 if (e.key !== empty) {
3275 if (itemKind === 'key') {
3276 return CreateIterResultObject(e.key, false);
3277 } else if (itemKind === 'value') {
3278 return CreateIterResultObject(e.value, false);
3279 } else {
3280 return CreateIterResultObject([e.key, e.value], false);
3281 }
3282 }
3283 }
3284 return CreateIterResultObject(undefined, true);
3285 });
3286
3287 // 23.1.5.2.2 %MapIteratorPrototype% [ @@toStringTag ]
3288 define($MapIteratorPrototype$, $$toStringTag, 'Map Iterator');
3289
3290 // 23.1.5.3 Properties of Map Iterator Instances
3291 }());
3292
3293 // ---------------------------------------
3294 // 23.2 Set Objects
3295 // ---------------------------------------
3296
3297 (function() {
3298 // 23.2.1 The Set Constructor
3299 // 23.2.1.1 Set ( [ iterable ] )
3300
3301 /** @constructor */
3302 function Set(/*iterable*/) {
3303 var set = strict(this);
3304 var iterable = arguments[0];
3305
3306 if (Type(set) !== 'object') throw TypeError();
3307 if ('[[SetData]]' in set) throw TypeError();
3308
3309 if (iterable !== undefined) {
3310 var adder = set['add'];
3311 if (!IsCallable(adder)) throw TypeError();
3312 var iter = GetIterator(ToObject(iterable));
3313 }
3314 set_internal(set, '[[SetData]]', []);
3315 if (iter === undefined) return set;
3316 while (true) {
3317 var next = IteratorStep(iter);
3318 if (next === false)
3319 return set;
3320 var nextValue = IteratorValue(next);
3321 adder.call(set, nextValue);
3322 }
3323
3324 return set;
3325 }
3326
3327 if (!('Set' in global) || OVERRIDE_NATIVE_FOR_TESTING ||
3328 (function() { try { return !new global.Set().entries().next; } catch (_) { return true; } }()) ||
3329 (new global.Set([1]).size !== 1))
3330 global.Set = Set;
3331
3332 function SetDataIndexOf(setData, key) {
3333 var i;
3334 if (key === key)
3335 return setData.indexOf(key);
3336 // Slow case for NaN
3337 for (i = 0; i < setData.length; i += 1)
3338 if (SameValueZero(setData[i], key)) return i;
3339 return -1;
3340 }
3341
3342 // 23.2.1.2 new Set ( ...argumentsList )
3343 // 23.2.2 Properties of the Set Constructor
3344
3345 // 23.2.2.1 Set.prototype
3346 var $SetPrototype$ = {};
3347 Set.prototype = $SetPrototype$;
3348
3349 // 23.2.2.2 get Set [ @@species ]
3350 // 23.2.3 Properties of the Set Prototype Object
3351
3352 // 23.2.3.1 Set.prototype.add (value )
3353 define(
3354 Set.prototype, 'add',
3355 function add(value) {
3356 var s = strict(this);
3357 if (Type(s) !== 'object') throw TypeError();
3358 if (!('[[SetData]]' in s)) throw TypeError();
3359 if (s['[[SetData]]'] === undefined) throw TypeError();
3360 if (SameValue(value, -0)) value = 0;
3361 var entries = s['[[SetData]]'];
3362 var i = SetDataIndexOf(entries, value);
3363 if (i < 0) i = s['[[SetData]]'].length;
3364 s['[[SetData]]'][i] = value;
3365
3366 return s;
3367 });
3368
3369 // 23.2.3.2 Set.prototype.clear ()
3370 define(
3371 Set.prototype, 'clear',
3372 function clear() {
3373 var s = strict(this);
3374 if (Type(s) !== 'object') throw TypeError();
3375 if (!('[[SetData]]' in s)) throw TypeError();
3376 if (s['[[SetData]]'] === undefined) throw TypeError();
3377 var entries = s['[[SetData]]'];
3378 entries.length = 0;
3379 return undefined;
3380 });
3381
3382 // 23.2.3.3 Set.prototype.constructor
3383 // 23.2.3.4 Set.prototype.delete ( value )
3384 define(
3385 Set.prototype, 'delete',
3386 function delete_(value) {
3387 var s = strict(this);
3388 if (Type(s) !== 'object') throw TypeError();
3389 if (!('[[SetData]]' in s)) throw TypeError();
3390 if (s['[[SetData]]'] === undefined) throw TypeError();
3391 var entries = s['[[SetData]]'];
3392 var i = SetDataIndexOf(entries, value);
3393 if (i < 0) return false;
3394 entries[i] = empty;
3395 return true;
3396 });
3397
3398 // 23.2.3.5 Set.prototype.entries ( )
3399 define(
3400 Set.prototype, 'entries',
3401 function entries() {
3402 var s = strict(this);
3403 if (Type(s) !== 'object') throw TypeError();
3404 return CreateSetIterator(s, 'key+value');
3405 });
3406
3407 // 23.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] )
3408 define(
3409 Set.prototype, 'forEach',
3410 function forEach(callbackfn/*, thisArg*/) {
3411 var thisArg = arguments[1];
3412
3413 var s = strict(this);
3414 if (Type(s) !== 'object') throw TypeError();
3415 if (!('[[SetData]]' in s)) throw TypeError();
3416 if (s['[[SetData]]'] === undefined) throw TypeError();
3417 var entries = s['[[SetData]]'];
3418
3419 if (!IsCallable(callbackfn)) {
3420 throw TypeError('First argument to forEach is not callable.');
3421 }
3422 for (var i = 0; i < entries.length; ++i) {
3423 if (entries[i] !== empty) {
3424 callbackfn.call(thisArg, entries[i], entries[i], s);
3425 }
3426 }
3427 });
3428
3429 // 23.2.3.7 Set.prototype.has ( value )
3430 define(
3431 Set.prototype, 'has',
3432 function has(key) {
3433 var s = strict(this);
3434 if (Type(s) !== 'object') throw TypeError();
3435 if (!('[[SetData]]' in s)) throw TypeError();
3436 if (s['[[SetData]]'] === undefined) throw TypeError();
3437 var entries = s['[[SetData]]'];
3438 return SetDataIndexOf(entries, key) !== -1;
3439 });
3440
3441 // 23.2.3.8 Set.prototype.keys ( )
3442 // See Set.prototype.values
3443
3444 // 23.2.3.9 get Set.prototype.size
3445 Object.defineProperty(
3446 Set.prototype, 'size', {
3447 get: function() {
3448 var s = strict(this);
3449 if (Type(s) !== 'object') throw TypeError();
3450 if (!('[[SetData]]' in s)) throw TypeError();
3451 if (s['[[SetData]]'] === undefined) throw TypeError();
3452 var entries = s['[[SetData]]'];
3453 var count = 0;
3454 for (var i = 0; i < entries.length; ++i) {
3455 if (entries[i] !== empty)
3456 count = count + 1;
3457 }
3458 return count;
3459 }
3460 });
3461
3462 // 23.2.3.10 Set.prototype.values ( )
3463 define(
3464 Set.prototype, 'values',
3465 function values() {
3466 var s = strict(this);
3467 if (Type(s) !== 'object') throw TypeError();
3468 return CreateSetIterator(s, 'value');
3469 });
3470 // NOTE: function name is still 'values':
3471 Set.prototype.keys = Set.prototype.values;
3472
3473 // 23.2.3.11 Set.prototype [@@iterator ] ( )
3474 define(
3475 Set.prototype, $$iterator,
3476 function() {
3477 var s = strict(this);
3478 if (Type(s) !== 'object') throw TypeError();
3479 return CreateSetIterator(s);
3480 });
3481
3482 // 23.2.3.12 Set.prototype [ @@toStringTag ]
3483 define(global.Set.prototype, $$toStringTag, 'Set');
3484
3485 // 23.2.4 Properties of Set Instances
3486 // 23.2.5 Set Iterator Objects
3487 /** @constructor */
3488 function SetIterator() {}
3489
3490 // 23.2.5.1 CreateSetIterator Abstract Operation
3491 function CreateSetIterator(set, kind) {
3492 if (Type(set) !== 'object') throw TypeError();
3493 if (!('[[SetData]]' in set)) throw TypeError();
3494 if (set['[[SetData]]'] === undefined) throw TypeError();
3495 var iterator = new SetIterator;
3496 set_internal(iterator, '[[IteratedSet]]', set);
3497 set_internal(iterator, '[[SetNextIndex]]', 0);
3498 set_internal(iterator, '[[SetIterationKind]]', kind);
3499 return iterator;
3500 }
3501
3502 // 23.2.5.2 The %SetIteratorPrototype% Object
3503 var $SetIteratorPrototype$ = Object.create($IteratorPrototype$);
3504 SetIterator.prototype = $SetIteratorPrototype$;
3505
3506 // 23.2.5.2.1 %SetIteratorPrototype%.next( )
3507 define(
3508 $SetIteratorPrototype$, 'next',
3509 function next() {
3510 var o = strict(this);
3511 if (Type(o) !== 'object') throw TypeError();
3512 var s = o['[[IteratedSet]]'],
3513 index = o['[[SetNextIndex]]'],
3514 itemKind = o['[[SetIterationKind]]'],
3515 entries = s['[[SetData]]'];
3516 while (index < entries.length) {
3517 var e = entries[index];
3518 index = index += 1;
3519 set_internal(o, '[[SetNextIndex]]', index);
3520 if (e !== empty) {
3521 if (itemKind === 'key+value')
3522 return CreateIterResultObject([e, e], false);
3523 return CreateIterResultObject(e, false);
3524 }
3525 }
3526 return CreateIterResultObject(undefined, true);
3527 });
3528
3529 // 23.2.5.2.2 %SetIteratorPrototype% [ @@toStringTag ]
3530 define($SetIteratorPrototype$, $$toStringTag, 'Set Iterator');
3531
3532 // 23.2.5.3 Properties of Set Iterator Instances
3533
3534 }());
3535
3536 // ---------------------------------------
3537 // 23.3 WeakMap Objects
3538 // ---------------------------------------
3539
3540 (function() {
3541 // 23.3.1 The WeakMap Constructor
3542 // 23.3.1.1 WeakMap ( [ iterable ] )
3543 /** @constructor */
3544 function WeakMap(/*iterable*/) {
3545 var map = strict(this);
3546 var iterable = arguments[0];
3547
3548 if (Type(map) !== 'object') throw TypeError();
3549 if ('[[WeakMapData]]' in map) throw TypeError();
3550
3551 if (iterable !== undefined) {
3552 var adder = map['set'];
3553 if (!IsCallable(adder)) throw TypeError();
3554 var iter = GetIterator(ToObject(iterable));
3555 }
3556 set_internal(map, '[[WeakMapData]]', new EphemeronTable);
3557 if (iter === undefined) return map;
3558 while (true) {
3559 var next = IteratorStep(iter);
3560 if (next === false)
3561 return map;
3562 var nextValue = IteratorValue(next);
3563 if (Type(nextValue) !== 'object') throw TypeError();
3564 var k = nextValue[0];
3565 var v = nextValue[1];
3566 adder.call(map, k, v);
3567 }
3568
3569 return map;
3570 }
3571
3572 if (!('WeakMap' in global) || OVERRIDE_NATIVE_FOR_TESTING)
3573 global.WeakMap = WeakMap;
3574
3575 // 23.3.2 Properties of the WeakMap Constructor
3576 // 23.3.2.1 WeakMap.prototype
3577 var $WeakMapPrototype$ = {};
3578 WeakMap.prototype = $WeakMapPrototype$;
3579
3580
3581
3582 // 23.3.2.2 WeakMap[ @@create ] ( )
3583 // 23.3.3 Properties of the WeakMap Prototype Object
3584
3585 // 23.3.3.1 WeakMap.prototype.constructor
3586
3587 // 23.3.3.2 WeakMap.prototype.delete ( key )
3588 define(
3589 WeakMap.prototype, 'delete',
3590 function delete_(key) {
3591 var M = strict(this);
3592 if (Type(M) !== 'object') throw TypeError();
3593 if (M['[[WeakMapData]]'] === undefined) throw TypeError();
3594 if (Type(key) !== 'object') throw TypeError('Expected object');
3595 return M['[[WeakMapData]]'].remove(key);
3596 });
3597
3598 // 23.3.3.3 WeakMap.prototype.get ( key )
3599 define(
3600 WeakMap.prototype, 'get',
3601 function get(key, defaultValue) {
3602 var M = strict(this);
3603 if (Type(M) !== 'object') throw TypeError();
3604 if (M['[[WeakMapData]]'] === undefined) throw TypeError();
3605 if (Type(key) !== 'object') throw TypeError('Expected object');
3606 return M['[[WeakMapData]]'].get(key, defaultValue);
3607 });
3608
3609 // 23.3.3.4 WeakMap.prototype.has ( key )
3610 define(
3611 WeakMap.prototype, 'has',
3612 function has(key) {
3613 var M = strict(this);
3614 if (Type(M) !== 'object') throw TypeError();
3615 if (M['[[WeakMapData]]'] === undefined) throw TypeError();
3616 if (Type(key) !== 'object') throw TypeError('Expected object');
3617 return M['[[WeakMapData]]'].has(key);
3618 });
3619
3620 // 23.3.3.5 WeakMap.prototype.set ( key , value )
3621 define(
3622 WeakMap.prototype, 'set',
3623 function set(key, value) {
3624 var M = strict(this);
3625 if (Type(M) !== 'object') throw TypeError();
3626 if (M['[[WeakMapData]]'] === undefined) throw TypeError();
3627 if (Type(key) !== 'object') throw TypeError('Expected object');
3628 M['[[WeakMapData]]'].set(key, value);
3629 return M;
3630 });
3631
3632 // 23.3.3.6 WeakMap.prototype [ @@toStringTag ]
3633 define(global.WeakMap.prototype, $$toStringTag, 'WeakMap');
3634
3635 // 23.3.4 Properties of WeakMap Instances
3636
3637 // Polyfills for incomplete native implementations:
3638 (function() {
3639 var wm = new global.WeakMap();
3640 var orig = global.WeakMap.prototype.set;
3641 define(global.WeakMap.prototype, 'set', function set() {
3642 orig.apply(this, arguments);
3643 return this;
3644 }, wm.set({}, 0) !== wm);
3645 }());
3646 }());
3647
3648 // ---------------------------------------
3649 // 23.4 WeakSet Objects
3650 // ---------------------------------------
3651
3652 (function() {
3653 // 23.4.1 The WeakSet Constructor
3654 // 23.4.1.1 WeakSet ( [ iterable ] )
3655 /** @constructor */
3656 function WeakSet(/*iterable*/) {
3657 var set = strict(this);
3658 var iterable = arguments[0];
3659
3660 if (Type(set) !== 'object') throw TypeError();
3661 if ('[[WeakSetData]]' in set) throw TypeError();
3662
3663 if (iterable !== undefined) {
3664 var adder = set['add'];
3665 if (!IsCallable(adder)) throw TypeError();
3666 var iter = GetIterator(ToObject(iterable));
3667 }
3668 set_internal(set, '[[WeakSetData]]', new EphemeronTable);
3669 if (iter === undefined) return set;
3670 while (true) {
3671 var next = IteratorStep(iter);
3672 if (next === false)
3673 return set;
3674 var nextValue = IteratorValue(next);
3675 adder.call(set, nextValue);
3676 }
3677
3678 return set;
3679 }
3680
3681 if (!('WeakSet' in global) || OVERRIDE_NATIVE_FOR_TESTING)
3682 global.WeakSet = WeakSet;
3683
3684 // 23.4.2 Properties of the WeakSet Constructor
3685 // 23.4.2.1 WeakSet.prototype
3686 var $WeakSetPrototype$ = {};
3687 WeakSet.prototype = $WeakSetPrototype$;
3688
3689 // 23.4.3 Properties of the WeakSet Prototype Object
3690 // 23.4.3.1 WeakSet.prototype.add (value )
3691 define(
3692 WeakSet.prototype, 'add',
3693 function add(value) {
3694 var S = strict(this);
3695 if (Type(S) !== 'object') throw TypeError();
3696 if (S['[[WeakSetData]]'] === undefined) throw TypeError();
3697 if (Type(value) !== 'object') throw TypeError('Expected object');
3698 S['[[WeakSetData]]'].set(value, true);
3699 return S;
3700 });
3701
3702 // 23.4.3.2 WeakSet.prototype.constructor
3703 // 23.4.3.3 WeakSet.prototype.delete ( value )
3704 define(
3705 WeakSet.prototype, 'delete',
3706 function delete_(value) {
3707 var S = strict(this);
3708 if (Type(S) !== 'object') throw TypeError();
3709 if (S['[[WeakSetData]]'] === undefined) throw TypeError();
3710 if (Type(value) !== 'object') throw TypeError('Expected object');
3711 return S['[[WeakSetData]]'].remove(value);
3712 });
3713
3714 // 23.4.3.4 WeakSet.prototype.has ( value )
3715 define(
3716 WeakSet.prototype, 'has',
3717 function has(key) {
3718 var S = strict(this);
3719 if (Type(S) !== 'object') throw TypeError();
3720 if (S['[[WeakSetData]]'] === undefined) throw TypeError();
3721 if (Type(key) !== 'object') throw TypeError('Expected object');
3722 return S['[[WeakSetData]]'].has(key);
3723 });
3724
3725 // 23.4.3.5 WeakSet.prototype [ @@toStringTag ]
3726 define(global.WeakSet.prototype, $$toStringTag, 'WeakSet');
3727
3728 // 23.4.4 Properties of WeakSet Instances
3729
3730 // Polyfills for incomplete native implementations:
3731 (function() {
3732 var ws = new global.WeakSet();
3733 var orig = global.WeakSet.prototype.add;
3734 define(global.WeakSet.prototype, 'add', function add() {
3735 orig.apply(this, arguments);
3736 return this;
3737 }, ws.add({}) !== ws);
3738 }());
3739 }());
3740
3741 // ---------------------------------------
3742 // 24 Structured Data
3743 // ---------------------------------------
3744
3745 // ---------------------------------------
3746 // 24.1 ArrayBuffer Objects
3747 // ---------------------------------------
3748
3749 // See typedarray.js for TypedArray polyfill
3750
3751 (function() {
3752 if (!('ArrayBuffer' in global))
3753 return;
3754
3755 // 24.1.1 Abstract Operations For ArrayBuffer Objects
3756 // 24.1.1.1 AllocateArrayBuffer( constructor, byteLength )
3757 // 24.1.1.2 IsDetachedBuffer( arrayBuffer )
3758 // 24.1.1.3 DetachArrayBuffer( arrayBuffer )
3759 // 24.1.1.4 CloneArrayBuffer( srcBuffer, srcByteOffset [, cloneConstructor] )
3760 // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian )
3761 // 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isLittleEndian )
3762 // 24.1.2 The ArrayBuffer Constructor
3763 // 24.1.2.1 ArrayBuffer( length )
3764 // 24.1.3 Properties of the ArrayBuffer Constructor
3765
3766 // 24.1.3.1 ArrayBuffer.isView ( arg )
3767 define(
3768 ArrayBuffer, 'isView',
3769 function isView(arg) {
3770 if (Type(arg) !== 'object') return false;
3771 if ('buffer' in arg && arg.buffer instanceof ArrayBuffer) return true;
3772 return false;
3773 });
3774
3775 // 24.1.3.2 ArrayBuffer.prototype
3776 // 24.1.3.3 get ArrayBuffer [ @@species ]
3777 // 24.1.4 Properties of the ArrayBuffer Prototype Object
3778 // 24.1.4.1 get ArrayBuffer.prototype.byteLength
3779 // 24.1.4.2 ArrayBuffer.prototype.constructor
3780 // 24.1.4.3 ArrayBuffer.prototype.slice ( start , end)
3781
3782 // 24.1.4.4 ArrayBuffer.prototype [ @@toStringTag ]
3783 define(ArrayBuffer.prototype, $$toStringTag, 'ArrayBuffer');
3784
3785 // 24.1.5 Properties of the ArrayBuffer Instances
3786 }());
3787
3788 // ---------------------------------------
3789 // 24.2 DataView Objects
3790 // ---------------------------------------
3791
3792 // See typedarray.js for TypedArray polyfill
3793
3794 (function() {
3795 if (!('DataView' in global))
3796 return;
3797
3798 // 24.2.1 Abstract Operations For DataView Objects
3799 // 24.2.1.1 GetViewValue(view, requestIndex, isLittleEndian, type)
3800 // 24.2.1.2 SetViewValue(view, requestIndex, isLittleEndian, type, value)
3801 // 24.2.2 The DataView Constructor
3802 // 24.2.2.1 DataView (buffer [ , byteOffset [ , byteLength ] ] )
3803 // 24.2.3 Properties of the DataView Constructor
3804 // 24.2.3.1 DataView.prototype
3805 // 24.2.4 Properties of the DataView Prototype Object
3806 // 24.2.4.1 get DataView.prototype.buffer
3807 // 24.2.4.2 get DataView.prototype.byteLength
3808 // 24.2.4.3 get DataView.prototype.byteOffset
3809 // 24.2.4.4 DataView.prototype.constructor
3810 // 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] )
3811 // 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] )
3812 // 24.2.4.7 DataView.prototype.getInt8 ( byteOffset )
3813 // 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] )
3814 // 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] )
3815 // 24.2.4.10 DataView.prototype.getUint8 ( byteOffset )
3816 // 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )
3817 // 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
3818 // 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] )
3819 // 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] )
3820 // 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value )
3821 // 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )
3822 // 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] )
3823 // 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value )
3824 // 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] )
3825 // 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] )
3826
3827 // 24.2.4.21 DataView.prototype[ @@toStringTag ]
3828 define(DataView.prototype, $$toStringTag, 'DataView');
3829
3830 // 24.2.5 Properties of DataView Instances
3831 }());
3832
3833 // ---------------------------------------
3834 // 24.3 The JSON Object
3835 // ---------------------------------------
3836
3837 // 24.3.1 JSON.parse ( text [ , reviver ] )
3838 // 24.3.2 JSON.stringify ( value [ , replacer [ , space ] ] )
3839 // 24.3.3 JSON [ @@toStringTag ]
3840 define(JSON, $$toStringTag, 'JSON');
3841
3842 // ---------------------------------------
3843 // 25.1 Iteration
3844 // ---------------------------------------
3845
3846 // 25.1.1 Common Iteration Interfaces
3847 // 25.1.1.1 The Iterable Interface
3848 // 25.1.1.2 The Iterator Interface
3849 // 25.1.1.3 The IteratorResult Interface
3850
3851 // 25.1.2 The %IteratorPrototype% Object
3852 // Defined earlier, so other prototypes can reference it.
3853 // 25.1.2.1 %IteratorPrototype% [ @@iterator ] ( )
3854 define($IteratorPrototype$, $$iterator, function() {
3855 return this;
3856 });
3857
3858
3859 // ---------------------------------------
3860 // 25.4 Promise Objects
3861 // ---------------------------------------
3862
3863 (function() {
3864 // 25.4 Promise Objects
3865
3866 // 25.4.1 Promise Abstract Operations
3867
3868 // 25.4.1.1 PromiseCapability Records
3869 // 25.4.1.1.1 IfAbruptRejectPromise ( value, capability )
3870
3871 function IfAbruptRejectPromise(value, capability) {
3872 var rejectResult = capability['[[Reject]]'].call(undefined, value);
3873 return capability['[[Promise]]'];
3874 }
3875
3876 // 25.4.1.2 PromiseReaction Records
3877
3878 // 25.4.1.3 CreateResolvingFunctions ( promise )
3879
3880 function CreateResolvingFunctions(promise) {
3881 var alreadyResolved = {'[[value]]': false};
3882 var resolve = PromiseResolveFunction();
3883 set_internal(resolve, '[[Promise]]', promise);
3884 set_internal(resolve, '[[AlreadyResolved]]', alreadyResolved);
3885 var reject = PromiseRejectFunction();
3886 set_internal(reject, '[[Promise]]', promise);
3887 set_internal(reject, '[[AlreadyResolved]]', alreadyResolved);
3888 return { '[[Resolve]]': resolve, '[[Reject]]': reject};
3889 }
3890
3891 // 25.4.1.3.1 Promise Reject Functions
3892
3893 function PromiseRejectFunction() {
3894 var F = function(reason) {
3895 console.assert(Type(F['[[Promise]]']) === 'object');
3896 var promise = F['[[Promise]]'];
3897 var alreadyResolved = F['[[AlreadyResolved]]'];
3898 if (alreadyResolved['[[value]]']) return undefined;
3899 set_internal(alreadyResolved, '[[value]]', true);
3900 return RejectPromise(promise, reason);
3901 };
3902 return F;
3903 }
3904
3905 // 25.4.1.3.2 Promise Resolve Functions
3906
3907 function PromiseResolveFunction() {
3908 var F = function(resolution) {
3909 console.assert(Type(F['[[Promise]]']) === 'object');
3910 var promise = F['[[Promise]]'];
3911 var alreadyResolved = F['[[AlreadyResolved]]'];
3912 if (alreadyResolved['[[value]]']) return undefined;
3913 set_internal(alreadyResolved, '[[value]]', true);
3914
3915 if (SameValue(resolution, promise)) {
3916 var selfResolutionError = TypeError();
3917 return RejectPromise(promise, selfResolutionError);
3918 }
3919 if (Type(resolution) !== 'object')
3920 return FulfillPromise(promise, resolution);
3921 try {
3922 var then = resolution['then'];
3923 } catch(then) {
3924 return RejectPromise(promise, then);
3925 }
3926 if (!IsCallable(then))
3927 return FulfillPromise(promise, resolution);
3928 EnqueueJob('PromiseJobs', PromiseResolveThenableJob, [promise, resolution, then]);
3929 return undefined;
3930 };
3931 return F;
3932 }
3933
3934 // 25.4.1.4 FulfillPromise ( promise, value )
3935
3936 function FulfillPromise(promise, value) {
3937 console.assert(promise['[[PromiseState]]'] === 'pending');
3938 var reactions = promise['[[PromiseFulfillReactions]]'];
3939 set_internal(promise, '[[PromiseResult]]', value);
3940 set_internal(promise, '[[PromiseFulfillReactions]]', undefined);
3941 set_internal(promise, '[[PromiseRejectReactions]]', undefined);
3942 set_internal(promise, '[[PromiseState]]', 'fulfilled');
3943 return TriggerPromiseReactions(reactions, value);
3944 }
3945
3946 // 25.4.1.5 NewPromiseCapability ( C )
3947
3948 function NewPromiseCapability(c) {
3949 // To keep Promise hermetic, this doesn't look much like the spec.
3950 return CreatePromiseCapabilityRecord(undefined, c);
3951 }
3952
3953 // 25.4.1.5.1 CreatePromiseCapabilityRecord ( promise, constructor )
3954
3955 function CreatePromiseCapabilityRecord(promise, constructor) {
3956 // To keep Promise hermetic, this doesn't look much like the spec.
3957 console.assert(IsConstructor(constructor));
3958 var promiseCapability = {};
3959 set_internal(promiseCapability, '[[Promise]]', promise);
3960 set_internal(promiseCapability, '[[Resolve]]', undefined);
3961 set_internal(promiseCapability, '[[Reject]]', undefined);
3962 var executor = GetCapabilitiesExecutor();
3963 set_internal(executor, '[[Capability]]', promiseCapability);
3964
3965 // NOTE: Differs from spec; object is constructed here
3966 var constructorResult = promise = new constructor(executor);
3967 set_internal(promiseCapability, '[[Promise]]', promise);
3968
3969 if (!IsCallable(promiseCapability['[[Resolve]]'])) throw TypeError();
3970 if (!IsCallable(promiseCapability['[[Reject]]'])) throw TypeError();
3971 if (Type(constructorResult) === 'object' && !SameValue(promise, constructorResult)) throw TypeError();
3972 return promiseCapability;
3973 }
3974
3975 // 25.4.1.5.2 GetCapabilitiesExecutor Functions
3976
3977 function GetCapabilitiesExecutor() {
3978 var F = function(resolve, reject) {
3979 console.assert(F['[[Capability]]']);
3980 var promiseCapability = F['[[Capability]]'];
3981 if (promiseCapability['[[Resolve]]'] !== undefined) throw TypeError();
3982 if (promiseCapability['[[Reject]]'] !== undefined) throw TypeError();
3983 set_internal(promiseCapability, '[[Resolve]]', resolve);
3984 set_internal(promiseCapability, '[[Reject]]', reject);
3985 return undefined;
3986 };
3987 return F;
3988 }
3989
3990 // 25.4.1.6 IsPromise ( x )
3991
3992 function IsPromise(x) {
3993 if (Type(x) !== 'object') return false;
3994 if (!('[[PromiseState]]' in x)) return false;
3995 if (x['[[PromiseState]]'] === undefined) return false;
3996 return true;
3997 }
3998
3999 // 25.4.1.7 RejectPromise ( promise, reason )
4000
4001 function RejectPromise(promise, reason) {
4002 console.assert(promise['[[PromiseState]]'] === 'pending');
4003 var reactions = promise['[[PromiseRejectReactions]]'];
4004 set_internal(promise, '[[PromiseResult]]', reason);
4005 set_internal(promise, '[[PromiseFulfillReactions]]', undefined);
4006 set_internal(promise, '[[PromiseRejectReactions]]', undefined);
4007 set_internal(promise, '[[PromiseState]]', 'rejected');
4008 return TriggerPromiseReactions(reactions, reason);
4009 }
4010
4011 // 25.4.1.8 TriggerPromiseReactions ( reactions, argument )
4012
4013 function TriggerPromiseReactions(reactions, argument) {
4014 for (var i = 0, len = reactions.length; i < len; ++i)
4015 EnqueueJob('PromiseJobs', PromiseReactionJob, [reactions[i], argument]);
4016 return undefined;
4017 }
4018
4019 // 25.4.2 Promise Jobs
4020
4021 // 25.4.2.1 PromiseReactionJob ( reaction, argument )
4022
4023 function PromiseReactionJob(reaction, argument) {
4024 var promiseCapability = reaction['[[Capabilities]]'];
4025 var handler = reaction['[[Handler]]'];
4026 var handlerResult, status;
4027 try {
4028 if (handler === 'Identity') handlerResult = argument;
4029 else if (handler === 'Thrower') throw argument;
4030 else handlerResult = handler.call(undefined, argument);
4031 } catch (handlerResult) {
4032 status = promiseCapability['[[Reject]]'].call(undefined, handlerResult);
4033 NextJob(status); return;
4034 }
4035 status = promiseCapability['[[Resolve]]'].call(undefined, handlerResult);
4036 NextJob(status);
4037 }
4038
4039 // 25.4.2.2 PromiseResolveThenableJob ( promiseToResolve, thenable, then)
4040
4041 function PromiseResolveThenableJob(promiseToResolve, thenable, then) {
4042 // SPEC BUG: promise vs. promiseToResolve
4043 var resolvingFunctions = CreateResolvingFunctions(promiseToResolve);
4044 try {
4045 var thenCallResult = then.call(thenable, resolvingFunctions['[[Resolve]]'],
4046 resolvingFunctions['[[Reject]]']);
4047 } catch (thenCallResult) {
4048 var status = resolvingFunctions['[[Reject]]'].call(undefined, thenCallResult);
4049 NextJob(status); return;
4050 }
4051 NextJob(thenCallResult);
4052 }
4053
4054 // 25.4.3 The Promise Constructor
4055
4056 // 25.4.3.1 Promise ( executor )
4057
4058 function Promise(executor) {
4059 var config = { configurable: false, enumerable: false, writable: true, value: undefined };
4060 Object.defineProperty(this, '[[PromiseState]]', config);
4061 Object.defineProperty(this, '[[PromiseConstructor]]', config);
4062 Object.defineProperty(this, '[[PromiseResult]]', config);
4063 Object.defineProperty(this, '[[PromiseFulfillReactions]]', config);
4064 Object.defineProperty(this, '[[PromiseRejectReactions]]', config);
4065
4066 var promise = this;
4067 if (Type(promise) !== 'object') throw new TypeError();
4068 if (!('[[PromiseState]]' in promise)) throw TypeError();
4069 if (promise['[[PromiseState]]'] !== undefined) throw TypeError();
4070 if (!IsCallable(executor)) throw TypeError();
4071
4072 set_internal(promise, '[[PromiseConstructor]]', Promise);
4073
4074 return InitializePromise(promise, executor);
4075 }
4076
4077 // 25.4.3.1.1 InitializePromise ( promise, executor )
4078
4079 function InitializePromise(promise, executor) {
4080 console.assert('[[PromiseState]]' in promise);
4081 console.assert(IsCallable(executor));
4082 set_internal(promise, '[[PromiseState]]', 'pending');
4083 set_internal(promise, '[[PromiseFulfillReactions]]', []);
4084 set_internal(promise, '[[PromiseRejectReactions]]', []);
4085 var resolvingFunctions = CreateResolvingFunctions(promise);
4086 try {
4087 var completion = executor.call(undefined, resolvingFunctions['[[Resolve]]'],
4088 resolvingFunctions['[[Reject]]']);
4089 } catch (completion) {
4090 var status = resolvingFunctions['[[Reject]]'].call(undefined, completion);
4091 }
4092 return promise;
4093 }
4094
4095 // 25.4.4 Properties of the Promise Constructor
4096 // 25.4.4.1 Promise.all ( iterable )
4097
4098 define(Promise, 'all', function all(iterable) {
4099 var c = strict(this);
4100 var promiseCapability = NewPromiseCapability(c);
4101 try {
4102 var iterator = GetIterator(iterable);
4103 } catch (value) {
4104 promiseCapability['[[Reject]]'].call(undefined, value);
4105 return promiseCapability['[[Promise]]'];
4106 }
4107 var values = [];
4108 var remainingElementsCount = { value: 1 };
4109 var index = 0;
4110 while (true) {
4111 try {
4112 var next = IteratorStep(iterator);
4113 } catch (value) {
4114 promiseCapability['[[Reject]]'].call(undefined, value);
4115 return promiseCapability['[[Promise]]'];
4116 }
4117 if (!next) {
4118 remainingElementsCount.value -= 1;
4119 if (remainingElementsCount.value === 0) {
4120 var resolveResult = promiseCapability['[[Resolve]]'].apply(undefined, values);
4121
4122
4123 }
4124 return promiseCapability['[[Promise]]'];
4125 }
4126 try {
4127 var nextValue = IteratorValue(next);
4128 } catch (value) {
4129 promiseCapability['[[Reject]]'].call(undefined, value);
4130 return promiseCapability['[[Promise]]'];
4131 }
4132 try {
4133 var nextPromise = c.resolve(nextValue);
4134 } catch (value) {
4135 promiseCapability['[[Reject]]'].call(undefined, value);
4136 return promiseCapability['[[Promise]]'];
4137 }
4138 var resolveElement = PromiseAllResolveElementFunction();
4139 set_internal(resolveElement, '[[AlreadyCalled]]', { value: false });
4140 set_internal(resolveElement, '[[Index]]', index);
4141 set_internal(resolveElement, '[[Values]]', values);
4142 set_internal(resolveElement, '[[Capabilities]]', promiseCapability);
4143 set_internal(resolveElement, '[[RemainingElements]]', remainingElementsCount);
4144 remainingElementsCount.value += 1;
4145 try {
4146 var result = nextPromise.then(resolveElement, promiseCapability['[[Reject]]']);
4147 } catch (value) {
4148 promiseCapability['[[Reject]]'].call(undefined, value);
4149 return promiseCapability['[[Promise]]'];
4150 }
4151 index += 1;
4152 }
4153 });
4154
4155 // 25.4.4.1.1 Promise.all Resolve Element Functions
4156
4157 function PromiseAllResolveElementFunction() {
4158 var F = function(x) {
4159 var alreadyCalled = F['[[AlreadyCalled]]'];
4160 if (alreadyCalled.value) return undefined;
4161 alreadyCalled.value = true;
4162 var index = F['[[Index]]'];
4163 var values = F['[[Values]]'];
4164 var promiseCapability = F['[[Capabilities]]'];
4165 var remainingElementsCount = F['[[RemainingElements]]'];
4166 try {
4167 values[index] = x;
4168 } catch (result) {
4169 promiseCapability['[[Reject]]'].call(undefined, result);
4170 return promiseCapability['[[Promise]]'];
4171 }
4172 remainingElementsCount.value -= 1;
4173 if (remainingElementsCount.value === 0)
4174 return promiseCapability['[[Resolve]]'].call(undefined, values);
4175 return undefined;
4176 };
4177 return F;
4178 }
4179
4180 // 25.4.4.2 Promise.prototype
4181
4182 Promise.prototype = {};
4183
4184 // 25.4.4.3 Promise.race ( iterable )
4185
4186 define(Promise, 'race', function race(iterable) {
4187 var c = strict(this);
4188 var promiseCapability = NewPromiseCapability(c);
4189 try {
4190 var iterator = GetIterator(iterable);
4191 } catch (value) {
4192 promiseCapability['[[Reject]]'].call(undefined, value);
4193 return promiseCapability['[[Promise]]'];
4194 }
4195 while (true) {
4196 try {
4197 var next = IteratorStep(iterator);
4198 } catch (value) {
4199 promiseCapability['[[Reject]]'].call(undefined, value);
4200 return promiseCapability['[[Promise]]'];
4201 }
4202 if (!next) return promiseCapability['[[Promise]]'];
4203 try {
4204 var nextValue = IteratorValue(next);
4205 } catch (value) {
4206 promiseCapability['[[Reject]]'].call(undefined, value);
4207 return promiseCapability['[[Promise]]'];
4208 }
4209 try {
4210 var nextPromise = c.resolve(nextValue);
4211 } catch (value) {
4212 promiseCapability['[[Reject]]'].call(undefined, value);
4213 return promiseCapability['[[Promise]]'];
4214 }
4215 try {
4216 nextPromise.then(promiseCapability['[[Resolve]]'], promiseCapability['[[Reject]]']);
4217 } catch (value) {
4218 promiseCapability['[[Reject]]'].call(undefined, value);
4219 return promiseCapability['[[Promise]]'];
4220 }
4221 }
4222 });
4223
4224 // 25.4.4.4 Promise.reject ( r )
4225
4226 define(Promise, 'reject', function reject(r) {
4227 var c = strict(this);
4228 var promiseCapability = NewPromiseCapability(c);
4229 var rejectResult = promiseCapability['[[Reject]]'].call(undefined, r);
4230 return promiseCapability['[[Promise]]'];
4231 });
4232
4233 // 25.4.4.5 Promise.resolve ( x )
4234
4235 define(Promise, 'resolve', function resolve(x) {
4236 var c = strict(this);
4237 if (IsPromise(x)) {
4238 var constructor = x['[[PromiseConstructor]]'];
4239 if (SameValue(constructor, c)) return x;
4240 }
4241 var promiseCapability = NewPromiseCapability(c);
4242 var resolveResult = promiseCapability['[[Resolve]]'].call(undefined, x);
4243 return promiseCapability['[[Promise]]'];
4244 });
4245
4246 // 25.4.4.6 Promise [ @@create ] ( )
4247 // 25.4.4.6.1 AllocatePromise ( constructor )
4248 // 25.4.5 Properties of the Promise Prototype Object
4249 // 25.4.5.1 Promise.prototype.catch ( onRejected )
4250
4251 define(Promise.prototype, 'catch', function catch_(onRejected) {
4252 var promise = this;
4253 return promise.then(undefined, onRejected);
4254 });
4255
4256 // 25.4.5.2 Promise.prototype.constructor
4257
4258 Promise.prototype.constructor = Promise;
4259
4260 // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected )
4261
4262 define(Promise.prototype, 'then', function then(onFulfilled, onRejected) {
4263 var promise = this;
4264 if (!IsPromise(promise)) throw TypeError();
4265 if (!IsCallable(onFulfilled)) onFulfilled = 'Identity';
4266 if (!IsCallable(onRejected)) onRejected = 'Thrower';
4267 var c = promise.constructor;
4268 var promiseCapability = NewPromiseCapability(c);
4269 var fulfillReaction = { '[[Capabilities]]': promiseCapability,
4270 '[[Handler]]': onFulfilled };
4271 var rejectReaction = { '[[Capabilities]]': promiseCapability,
4272 '[[Handler]]': onRejected };
4273 if (promise['[[PromiseState]]'] === 'pending') {
4274 promise['[[PromiseFulfillReactions]]'].push(fulfillReaction);
4275 promise['[[PromiseRejectReactions]]'].push(rejectReaction);
4276 } else if (promise['[[PromiseState]]'] === 'fulfilled') {
4277 var value = promise['[[PromiseResult]]'];
4278 EnqueueJob('PromiseJobs', PromiseReactionJob, [fulfillReaction, value]);
4279 } else if (promise['[[PromiseState]]'] === 'rejected') {
4280 var reason = promise['[[PromiseResult]]'];
4281 EnqueueJob('PromiseJobs', PromiseReactionJob, [rejectReaction, reason]);
4282 }
4283 return promiseCapability['[[Promise]]'];
4284 });
4285
4286 // 25.4.6 Properties of Promise Instances
4287
4288 if (!('Promise' in global) || OVERRIDE_NATIVE_FOR_TESTING)
4289 global.Promise = Promise;
4290
4291 // Patch early Promise.cast vs. Promise.resolve implementations
4292 if ('cast' in global.Promise) global.Promise.resolve = global.Promise.cast;
4293 }());
4294
4295 // 25.4.5.1 Promise.prototype [ @@toStringTag ]
4296 define(Promise.prototype, $$toStringTag, 'Promise');
4297
4298 // ---------------------------------------
4299 // 26 Reflection
4300 // ---------------------------------------
4301
4302 (function() {
4303 // 26.1 The Reflect Object
4304 if (!('Reflect' in global) || OVERRIDE_NATIVE_FOR_TESTING)
4305 global.Reflect = {};
4306
4307 // 26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
4308 define(
4309 Reflect, 'apply',
4310 function apply(target, thisArgument, argumentsList) {
4311 if (!IsCallable(target)) throw TypeError();
4312 return Function.prototype.apply.call(target, thisArgument, argumentsList);
4313 });
4314
4315 // 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
4316 define(
4317 Reflect, 'construct',
4318 function construct(target, argumentsList) {
4319 return __cons(target, argumentsList);
4320 });
4321
4322 // 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
4323 define(
4324 Reflect, 'defineProperty',
4325 function defineProperty(target, propertyKey, attributes) {
4326 try {
4327 Object.defineProperty(target, propertyKey, attributes);
4328 return true;
4329 } catch (_) {
4330 return false;
4331 }
4332 });
4333
4334 // 26.1.4 Reflect.deleteProperty ( target, propertyKey )
4335 define(
4336 Reflect, 'deleteProperty',
4337 function deleteProperty(target,name) {
4338 try {
4339 delete target[name];
4340 return !HasOwnProperty(target, name);
4341 } catch (_) {
4342 return false;
4343 }
4344 });
4345
4346 // 26.1.5 Reflect.enumerate ( target )
4347 define(
4348 Reflect, 'enumerate',
4349 function enumerate(target) {
4350 target = ToObject(target);
4351 var iterator = Enumerate(target);
4352 return iterator;
4353 });
4354
4355 // 26.1.6 Reflect.get ( target, propertyKey [ , receiver ])
4356 define(
4357 Reflect, 'get',
4358 function get(target, name, receiver) {
4359 target = ToObject(target);
4360 name = String(name);
4361 receiver = (receiver === undefined) ? target : ToObject(receiver);
4362 var desc = getPropertyDescriptor(target, name);
4363 if (desc && 'get' in desc)
4364 return Function.prototype.call.call(desc['get'], receiver);
4365 return target[name];
4366 });
4367
4368 // 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
4369 define(
4370 Reflect, 'getOwnPropertyDescriptor',
4371 Object.getOwnPropertyDescriptor);
4372
4373 // 26.1.8 Reflect.getPrototypeOf ( target )
4374 define(
4375 Reflect, 'getPrototypeOf',
4376 Object.getPrototypeOf);
4377
4378 // 26.1.9 Reflect.has ( target, propertyKey )
4379 define(
4380 Reflect, 'has',
4381 function has(target,name) {
4382 return String(name) in ToObject(target);
4383 });
4384
4385 // 26.1.10 Reflect.isExtensible (target)
4386 define(
4387 Reflect, 'isExtensible',
4388 Object.isExtensible);
4389
4390 // 26.1.11 Reflect.ownKeys ( target )
4391 define(
4392 Reflect, 'ownKeys',
4393 function ownKeys(target) {
4394 var obj = ToObject(target);
4395 return Object.getOwnPropertyNames(obj);
4396 });
4397
4398 // 26.1.12 Reflect.preventExtensions ( target )
4399 define(
4400 Reflect, 'preventExtensions',
4401 function preventExtensions(target) {
4402 try { Object.preventExtensions(target); return true; } catch (_) { return false; }
4403 });
4404
4405 // 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] )
4406 define(
4407 Reflect, 'set',
4408 function set(target, name, value, receiver) {
4409 target = ToObject(target);
4410 name = String(name);
4411 receiver = (receiver === undefined) ? target : ToObject(receiver);
4412 var desc = getPropertyDescriptor(target, name);
4413 try {
4414 if (desc && 'set' in desc)
4415 Function.prototype.call.call(desc['set'], receiver, value);
4416 else
4417 target[name] = value;
4418 return true;
4419 } catch (_) {
4420 return false;
4421 }
4422 });
4423
4424 // 26.1.14 Reflect.setPrototypeOf ( target, proto )
4425 define(
4426 Reflect, 'setPrototypeOf',
4427 function setPrototypeOf(target, proto) {
4428 try {
4429 target.__proto__ = proto;
4430 return Reflect.getPrototypeOf(target) === proto;
4431 } catch(_) {
4432 return false;
4433 }
4434 });
4435
4436 }());
4437
4438 // ---------------------------------------
4439 // 26.2 Proxy Objects
4440 // ---------------------------------------
4441
4442 // Not polyfillable.
4443
4444}(self));
4445
4446// This helper is defined outside the main scope so that the use of
4447// 'eval' does not taint the scope for minifiers.
4448function __cons(t, a) {
4449 return eval('new t(' + a.map(function(_, i) { return 'a[' + i + ']'; }).join(',') + ')');
4450}
4451</script>
658 <script>/*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ 4452 <script>/*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
659!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="<div class='a'></div><div class='a i'></div>",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="<select msallowclip=''><option selected=''></option></select>",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=lb(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=mb(b);function pb(){}pb.prototype=d.filters=d.pseudos,d.setFilters=new pb,g=fb.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){(!c||(e=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?fb.error(a):z(a,i).slice(0)};function qb(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+Math.random()}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b) 4453!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="<div class='a'></div><div class='a i'></div>",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="<select msallowclip=''><option selected=''></option></select>",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=lb(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=mb(b);function pb(){}pb.prototype=d.filters=d.pseudos,d.setFilters=new pb,g=fb.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){(!c||(e=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?fb.error(a):z(a,i).slice(0)};function qb(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+Math.random()}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b)
660},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?n.queue(this[0],a):void 0===b?this:this.each(function(){var c=n.queue(this,a,b);n._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&n.dequeue(this,a)})},dequeue:function(a){return this.each(function(){n.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=n.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=L.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var Q=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,R=["Top","Right","Bottom","Left"],S=function(a,b){return a=b||a,"none"===n.css(a,"display")||!n.contains(a.ownerDocument,a)},T=/^(?:checkbox|radio)$/i;!function(){var a=l.createDocumentFragment(),b=a.appendChild(l.createElement("div")),c=l.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button;return null==a.pageX&&null!=b.clientX&&(c=a.target.ownerDocument||l,d=c.documentElement,e=c.body,a.pageX=b.clientX+(d&&d.scrollLeft||e&&e.scrollLeft||0)-(d&&d.clientLeft||e&&e.clientLeft||0),a.pageY=b.clientY+(d&&d.scrollTop||e&&e.scrollTop||0)-(d&&d.clientTop||e&&e.clientTop||0)),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},fix:function(a){if(a[n.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=W.test(e)?this.mouseHooks:V.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new n.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=l),3===a.target.nodeType&&(a.target=a.target.parentNode),g.filter?g.filter(a,f):a},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==_()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===_()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&n.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(a){return n.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=n.extend(new n.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?n.event.trigger(e,null,b):n.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},n.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)},n.Event=function(a,b){return this instanceof n.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?Z:$):this.type=a,b&&n.extend(this,b),this.timeStamp=a&&a.timeStamp||n.now(),void(this[n.expando]=!0)):new n.Event(a,b)},n.Event.prototype={isDefaultPrevented:$,isPropagationStopped:$,isImmediatePropagationStopped:$,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=Z,a&&a.preventDefault&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=Z,a&&a.stopPropagation&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=Z,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},n.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){n.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!n.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.focusinBubbles||n.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){n.event.simulate(b,a.target,n.event.fix(a),!0)};n.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=L.access(d,b);e||d.addEventListener(a,c,!0),L.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=L.access(d,b)-1;e?L.access(d,b,e):(d.removeEventListener(a,c,!0),L.remove(d,b))}}}),n.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(g in a)this.on(g,b,c,a[g],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=$;else if(!d)return this;return 1===e&&(f=d,d=function(a){return n().off(a),f.apply(this,arguments)},d.guid=f.guid||(f.guid=n.guid++)),this.each(function(){n.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,n(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return(b===!1||"function"==typeof b)&&(c=b,b=void 0),c===!1&&(c=$),this.each(function(){n.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){n.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?n.event.trigger(a,b,c,!0):void 0}});var ab=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,ib={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1></$2>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=qb[0].contentDocument,b.write(),b.close(),c=sb(a,b),qb.detach()),rb[a]=c),c}var ub=/^margin/,vb=new RegExp("^("+Q+")(?!px)[a-z%]+$","i"),wb=function(a){return a.ownerDocument.defaultView.getComputedStyle(a,null)};function xb(a,b,c){var d,e,f,g,h=a.style;return c=c||wb(a),c&&(g=c.getPropertyValue(b)||c[b]),c&&(""!==g||n.contains(a.ownerDocument,a)||(g=n.style(a,b)),vb.test(g)&&ub.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+"":g}function yb(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d=l.documentElement,e=l.createElement("div"),f=l.createElement("div");if(f.style){f.style.backgroundClip="content-box",f.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===f.style.backgroundClip,e.style.cssText="border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;position:absolute",e.appendChild(f);function g(){f.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",f.innerHTML="",d.appendChild(e);var g=a.getComputedStyle(f,null);b="1%"!==g.top,c="4px"===g.width,d.removeChild(e)}a.getComputedStyle&&n.extend(k,{pixelPosition:function(){return g(),b},boxSizingReliable:function(){return null==c&&g(),c},reliableMarginRight:function(){var b,c=f.appendChild(l.createElement("div"));return c.style.cssText=f.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",c.style.marginRight=c.style.width="0",f.style.width="1px",d.appendChild(e),b=!parseFloat(a.getComputedStyle(c,null).marginRight),d.removeChild(e),b}})}}(),n.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var zb=/^(none|table(?!-c[ea]).+)/,Ab=new RegExp("^("+Q+")(.*)$","i"),Bb=new RegExp("^([+-])=("+Q+")","i"),Cb={position:"absolute",visibility:"hidden",display:"block"},Db={letterSpacing:"0",fontWeight:"400"},Eb=["Webkit","O","Moz","ms"];function Fb(a,b){if(b in a)return b;var c=b[0].toUpperCase()+b.slice(1),d=b,e=Eb.length;while(e--)if(b=Eb[e]+c,b in a)return b;return d}function Gb(a,b,c){var d=Ab.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Hb(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=n.css(a,c+R[f],!0,e)),d?("content"===c&&(g-=n.css(a,"padding"+R[f],!0,e)),"margin"!==c&&(g-=n.css(a,"border"+R[f]+"Width",!0,e))):(g+=n.css(a,"padding"+R[f],!0,e),"padding"!==c&&(g+=n.css(a,"border"+R[f]+"Width",!0,e)));return g}function Ib(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=wb(a),g="border-box"===n.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=xb(a,b,f),(0>e||null==e)&&(e=a.style[b]),vb.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Hb(a,b,c||(g?"border":"content"),d,f)+"px"}function Jb(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=L.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&S(d)&&(f[g]=L.access(d,"olddisplay",tb(d.nodeName)))):(e=S(d),"none"===c&&e||L.set(d,"olddisplay",e?c:n.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}n.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=xb(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=n.camelCase(b),i=a.style;return b=n.cssProps[h]||(n.cssProps[h]=Fb(i,h)),g=n.cssHooks[b]||n.cssHooks[h],void 0===c?g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b]:(f=typeof c,"string"===f&&(e=Bb.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(n.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||n.cssNumber[h]||(c+="px"),k.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),g&&"set"in g&&void 0===(c=g.set(a,c,d))||(i[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=n.camelCase(b);return b=n.cssProps[h]||(n.cssProps[h]=Fb(a.style,h)),g=n.cssHooks[b]||n.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=xb(a,b,d)),"normal"===e&&b in Db&&(e=Db[b]),""===c||c?(f=parseFloat(e),c===!0||n.isNumeric(f)?f||0:e):e}}),n.each(["height","width"],function(a,b){n.cssHooks[b]={get:function(a,c,d){return c?zb.test(n.css(a,"display"))&&0===a.offsetWidth?n.swap(a,Cb,function(){return Ib(a,b,d)}):Ib(a,b,d):void 0},set:function(a,c,d){var e=d&&wb(a);return Gb(a,c,d?Hb(a,b,d,"border-box"===n.css(a,"boxSizing",!1,e),e):0)}}}),n.cssHooks.marginRight=yb(k.reliableMarginRight,function(a,b){return b?n.swap(a,{display:"inline-block"},xb,[a,"marginRight"]):void 0}),n.each({margin:"",padding:"",border:"Width"},function(a,b){n.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+R[d]+b]=f[d]||f[d-2]||f[0];return e}},ub.test(a)||(n.cssHooks[a+b].set=Gb)}),n.fn.extend({css:function(a,b){return J(this,function(a,b,c){var d,e,f={},g=0;if(n.isArray(b)){for(d=wb(a),e=b.length;e>g;g++)f[b[g]]=n.css(a,b[g],!1,d);return f}return void 0!==c?n.style(a,b,c):n.css(a,b)},a,b,arguments.length>1)},show:function(){return Jb(this,!0)},hide:function(){return Jb(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){S(this)?n(this).show():n(this).hide()})}});function Kb(a,b,c,d,e){return new Kb.prototype.init(a,b,c,d,e)}n.Tween=Kb,Kb.prototype={constructor:Kb,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(n.cssNumber[c]?"":"px")},cur:function(){var a=Kb.propHooks[this.prop];return a&&a.get?a.get(this):Kb.propHooks._default.get(this)},run:function(a){var b,c=Kb.propHooks[this.prop];return this.pos=b=this.options.duration?n.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Kb.propHooks._default.set(this),this}},Kb.prototype.init.prototype=Kb.prototype,Kb.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=n.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){n.fx.step[a.prop]?n.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[n.cssProps[a.prop]]||n.cssHooks[a.prop])?n.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Kb.propHooks.scrollTop=Kb.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},n.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},n.fx=Kb.prototype.init,n.fx.step={};var Lb,Mb,Nb=/^(?:toggle|show|hide)$/,Ob=new RegExp("^(?:([+-])=|)("+Q+")([a-z%]*)$","i"),Pb=/queueHooks$/,Qb=[Vb],Rb={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=Ob.exec(b),f=e&&e[3]||(n.cssNumber[a]?"":"px"),g=(n.cssNumber[a]||"px"!==f&&+d)&&Ob.exec(n.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,n.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function Sb(){return setTimeout(function(){Lb=void 0}),Lb=n.now()}function Tb(a,b){var c,d=0,e={height:a};for(b=b?1:0;4>d;d+=2-b)c=R[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function Ub(a,b,c){for(var d,e=(Rb[b]||[]).concat(Rb["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function Vb(a,b,c){var d,e,f,g,h,i,j,k,l=this,m={},o=a.style,p=a.nodeType&&S(a),q=L.get(a,"fxshow");c.queue||(h=n._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,l.always(function(){l.always(function(){h.unqueued--,n.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=n.css(a,"display"),k="none"===j?L.get(a,"olddisplay")||tb(a.nodeName):j,"inline"===k&&"none"===n.css(a,"float")&&(o.display="inline-block")),c.overflow&&(o.overflow="hidden",l.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],Nb.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(p?"hide":"show")){if("show"!==e||!q||void 0===q[d])continue;p=!0}m[d]=q&&q[d]||n.style(a,d)}else j=void 0;if(n.isEmptyObject(m))"inline"===("none"===j?tb(a.nodeName):j)&&(o.display=j);else{q?"hidden"in q&&(p=q.hidden):q=L.access(a,"fxshow",{}),f&&(q.hidden=!p),p?n(a).show():l.done(function(){n(a).hide()}),l.done(function(){var b;L.remove(a,"fxshow");for(b in m)n.style(a,b,m[b])});for(d in m)g=Ub(p?q[d]:0,d,l),d in q||(q[d]=g.start,p&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function Wb(a,b){var c,d,e,f,g;for(c in a)if(d=n.camelCase(c),e=b[d],f=a[c],n.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=n.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function Xb(a,b,c){var d,e,f=0,g=Qb.length,h=n.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=Lb||Sb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:n.extend({},b),opts:n.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:Lb||Sb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=n.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(Wb(k,j.opts.specialEasing);g>f;f++)if(d=Qb[f].call(j,a,k,j.opts))return d;return n.map(k,Ub,j),n.isFunction(j.opts.start)&&j.opts.start.call(a,j),n.fx.timer(n.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}n.Animation=n.extend(Xb,{tweener:function(a,b){n.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],Rb[c]=Rb[c]||[],Rb[c].unshift(b)},prefilter:function(a,b){b?Qb.unshift(a):Qb.push(a)}}),n.speed=function(a,b,c){var d=a&&"object"==typeof a?n.extend({},a):{complete:c||!c&&b||n.isFunction(a)&&a,duration:a,easing:c&&b||b&&!n.isFunction(b)&&b};return d.duration=n.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in n.fx.speeds?n.fx.speeds[d.duration]:n.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){n.isFunction(d.old)&&d.old.call(this),d.queue&&n.dequeue(this,d.queue)},d},n.fn.extend({fadeTo:function(a,b,c,d){return this.filter(S).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=n.isEmptyObject(a),f=n.speed(b,c,d),g=function(){var b=Xb(this,n.extend({},a),f);(e||L.get(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=n.timers,g=L.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&Pb.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&n.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=L.get(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=n.timers,g=d?d.length:0;for(c.finish=!0,n.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),n.each(["toggle","show","hide"],function(a,b){var c=n.fn[b];n.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(Tb(b,!0),a,d,e)}}),n.each({slideDown:Tb("show"),slideUp:Tb("hide"),slideToggle:Tb("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){n.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),n.timers=[],n.fx.tick=function(){var a,b=0,c=n.timers;for(Lb=n.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||n.fx.stop(),Lb=void 0},n.fx.timer=function(a){n.timers.push(a),a()?n.fx.start():n.timers.pop()},n.fx.interval=13,n.fx.start=function(){Mb||(Mb=setInterval(n.fx.tick,n.fx.interval))},n.fx.stop=function(){clearInterval(Mb),Mb=null},n.fx.speeds={slow:600,fast:200,_default:400},n.fn.delay=function(a,b){return a=n.fx?n.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a=l.createElement("input"),b=l.createElement("select"),c=b.appendChild(l.createElement("option"));a.type="checkbox",k.checkOn=""!==a.value,k.optSelected=c.selected,b.disabled=!0,k.optDisabled=!c.disabled,a=l.createElement("input"),a.value="t",a.type="radio",k.radioValue="t"===a.value}();var Yb,Zb,$b=n.expr.attrHandle;n.fn.extend({attr:function(a,b){return J(this,n.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){n.removeAttr(this,a)})}}),n.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===U?n.prop(a,b,c):(1===f&&n.isXMLDoc(a)||(b=b.toLowerCase(),d=n.attrHooks[b]||(n.expr.match.bool.test(b)?Zb:Yb)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void n.removeAttr(a,b)) 4454},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?n.queue(this[0],a):void 0===b?this:this.each(function(){var c=n.queue(this,a,b);n._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&n.dequeue(this,a)})},dequeue:function(a){return this.each(function(){n.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=n.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=L.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var Q=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,R=["Top","Right","Bottom","Left"],S=function(a,b){return a=b||a,"none"===n.css(a,"display")||!n.contains(a.ownerDocument,a)},T=/^(?:checkbox|radio)$/i;!function(){var a=l.createDocumentFragment(),b=a.appendChild(l.createElement("div")),c=l.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button;return null==a.pageX&&null!=b.clientX&&(c=a.target.ownerDocument||l,d=c.documentElement,e=c.body,a.pageX=b.clientX+(d&&d.scrollLeft||e&&e.scrollLeft||0)-(d&&d.clientLeft||e&&e.clientLeft||0),a.pageY=b.clientY+(d&&d.scrollTop||e&&e.scrollTop||0)-(d&&d.clientTop||e&&e.clientTop||0)),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},fix:function(a){if(a[n.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=W.test(e)?this.mouseHooks:V.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new n.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=l),3===a.target.nodeType&&(a.target=a.target.parentNode),g.filter?g.filter(a,f):a},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==_()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===_()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&n.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(a){return n.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=n.extend(new n.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?n.event.trigger(e,null,b):n.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},n.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)},n.Event=function(a,b){return this instanceof n.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?Z:$):this.type=a,b&&n.extend(this,b),this.timeStamp=a&&a.timeStamp||n.now(),void(this[n.expando]=!0)):new n.Event(a,b)},n.Event.prototype={isDefaultPrevented:$,isPropagationStopped:$,isImmediatePropagationStopped:$,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=Z,a&&a.preventDefault&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=Z,a&&a.stopPropagation&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=Z,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},n.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){n.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!n.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.focusinBubbles||n.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){n.event.simulate(b,a.target,n.event.fix(a),!0)};n.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=L.access(d,b);e||d.addEventListener(a,c,!0),L.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=L.access(d,b)-1;e?L.access(d,b,e):(d.removeEventListener(a,c,!0),L.remove(d,b))}}}),n.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(g in a)this.on(g,b,c,a[g],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=$;else if(!d)return this;return 1===e&&(f=d,d=function(a){return n().off(a),f.apply(this,arguments)},d.guid=f.guid||(f.guid=n.guid++)),this.each(function(){n.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,n(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return(b===!1||"function"==typeof b)&&(c=b,b=void 0),c===!1&&(c=$),this.each(function(){n.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){n.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?n.event.trigger(a,b,c,!0):void 0}});var ab=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,ib={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1></$2>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=qb[0].contentDocument,b.write(),b.close(),c=sb(a,b),qb.detach()),rb[a]=c),c}var ub=/^margin/,vb=new RegExp("^("+Q+")(?!px)[a-z%]+$","i"),wb=function(a){return a.ownerDocument.defaultView.getComputedStyle(a,null)};function xb(a,b,c){var d,e,f,g,h=a.style;return c=c||wb(a),c&&(g=c.getPropertyValue(b)||c[b]),c&&(""!==g||n.contains(a.ownerDocument,a)||(g=n.style(a,b)),vb.test(g)&&ub.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+"":g}function yb(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d=l.documentElement,e=l.createElement("div"),f=l.createElement("div");if(f.style){f.style.backgroundClip="content-box",f.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===f.style.backgroundClip,e.style.cssText="border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;position:absolute",e.appendChild(f);function g(){f.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",f.innerHTML="",d.appendChild(e);var g=a.getComputedStyle(f,null);b="1%"!==g.top,c="4px"===g.width,d.removeChild(e)}a.getComputedStyle&&n.extend(k,{pixelPosition:function(){return g(),b},boxSizingReliable:function(){return null==c&&g(),c},reliableMarginRight:function(){var b,c=f.appendChild(l.createElement("div"));return c.style.cssText=f.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",c.style.marginRight=c.style.width="0",f.style.width="1px",d.appendChild(e),b=!parseFloat(a.getComputedStyle(c,null).marginRight),d.removeChild(e),b}})}}(),n.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var zb=/^(none|table(?!-c[ea]).+)/,Ab=new RegExp("^("+Q+")(.*)$","i"),Bb=new RegExp("^([+-])=("+Q+")","i"),Cb={position:"absolute",visibility:"hidden",display:"block"},Db={letterSpacing:"0",fontWeight:"400"},Eb=["Webkit","O","Moz","ms"];function Fb(a,b){if(b in a)return b;var c=b[0].toUpperCase()+b.slice(1),d=b,e=Eb.length;while(e--)if(b=Eb[e]+c,b in a)return b;return d}function Gb(a,b,c){var d=Ab.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Hb(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=n.css(a,c+R[f],!0,e)),d?("content"===c&&(g-=n.css(a,"padding"+R[f],!0,e)),"margin"!==c&&(g-=n.css(a,"border"+R[f]+"Width",!0,e))):(g+=n.css(a,"padding"+R[f],!0,e),"padding"!==c&&(g+=n.css(a,"border"+R[f]+"Width",!0,e)));return g}function Ib(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=wb(a),g="border-box"===n.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=xb(a,b,f),(0>e||null==e)&&(e=a.style[b]),vb.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Hb(a,b,c||(g?"border":"content"),d,f)+"px"}function Jb(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=L.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&S(d)&&(f[g]=L.access(d,"olddisplay",tb(d.nodeName)))):(e=S(d),"none"===c&&e||L.set(d,"olddisplay",e?c:n.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}n.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=xb(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=n.camelCase(b),i=a.style;return b=n.cssProps[h]||(n.cssProps[h]=Fb(i,h)),g=n.cssHooks[b]||n.cssHooks[h],void 0===c?g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b]:(f=typeof c,"string"===f&&(e=Bb.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(n.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||n.cssNumber[h]||(c+="px"),k.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),g&&"set"in g&&void 0===(c=g.set(a,c,d))||(i[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=n.camelCase(b);return b=n.cssProps[h]||(n.cssProps[h]=Fb(a.style,h)),g=n.cssHooks[b]||n.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=xb(a,b,d)),"normal"===e&&b in Db&&(e=Db[b]),""===c||c?(f=parseFloat(e),c===!0||n.isNumeric(f)?f||0:e):e}}),n.each(["height","width"],function(a,b){n.cssHooks[b]={get:function(a,c,d){return c?zb.test(n.css(a,"display"))&&0===a.offsetWidth?n.swap(a,Cb,function(){return Ib(a,b,d)}):Ib(a,b,d):void 0},set:function(a,c,d){var e=d&&wb(a);return Gb(a,c,d?Hb(a,b,d,"border-box"===n.css(a,"boxSizing",!1,e),e):0)}}}),n.cssHooks.marginRight=yb(k.reliableMarginRight,function(a,b){return b?n.swap(a,{display:"inline-block"},xb,[a,"marginRight"]):void 0}),n.each({margin:"",padding:"",border:"Width"},function(a,b){n.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+R[d]+b]=f[d]||f[d-2]||f[0];return e}},ub.test(a)||(n.cssHooks[a+b].set=Gb)}),n.fn.extend({css:function(a,b){return J(this,function(a,b,c){var d,e,f={},g=0;if(n.isArray(b)){for(d=wb(a),e=b.length;e>g;g++)f[b[g]]=n.css(a,b[g],!1,d);return f}return void 0!==c?n.style(a,b,c):n.css(a,b)},a,b,arguments.length>1)},show:function(){return Jb(this,!0)},hide:function(){return Jb(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){S(this)?n(this).show():n(this).hide()})}});function Kb(a,b,c,d,e){return new Kb.prototype.init(a,b,c,d,e)}n.Tween=Kb,Kb.prototype={constructor:Kb,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(n.cssNumber[c]?"":"px")},cur:function(){var a=Kb.propHooks[this.prop];return a&&a.get?a.get(this):Kb.propHooks._default.get(this)},run:function(a){var b,c=Kb.propHooks[this.prop];return this.pos=b=this.options.duration?n.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Kb.propHooks._default.set(this),this}},Kb.prototype.init.prototype=Kb.prototype,Kb.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=n.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){n.fx.step[a.prop]?n.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[n.cssProps[a.prop]]||n.cssHooks[a.prop])?n.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Kb.propHooks.scrollTop=Kb.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},n.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},n.fx=Kb.prototype.init,n.fx.step={};var Lb,Mb,Nb=/^(?:toggle|show|hide)$/,Ob=new RegExp("^(?:([+-])=|)("+Q+")([a-z%]*)$","i"),Pb=/queueHooks$/,Qb=[Vb],Rb={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=Ob.exec(b),f=e&&e[3]||(n.cssNumber[a]?"":"px"),g=(n.cssNumber[a]||"px"!==f&&+d)&&Ob.exec(n.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,n.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function Sb(){return setTimeout(function(){Lb=void 0}),Lb=n.now()}function Tb(a,b){var c,d=0,e={height:a};for(b=b?1:0;4>d;d+=2-b)c=R[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function Ub(a,b,c){for(var d,e=(Rb[b]||[]).concat(Rb["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function Vb(a,b,c){var d,e,f,g,h,i,j,k,l=this,m={},o=a.style,p=a.nodeType&&S(a),q=L.get(a,"fxshow");c.queue||(h=n._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,l.always(function(){l.always(function(){h.unqueued--,n.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=n.css(a,"display"),k="none"===j?L.get(a,"olddisplay")||tb(a.nodeName):j,"inline"===k&&"none"===n.css(a,"float")&&(o.display="inline-block")),c.overflow&&(o.overflow="hidden",l.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],Nb.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(p?"hide":"show")){if("show"!==e||!q||void 0===q[d])continue;p=!0}m[d]=q&&q[d]||n.style(a,d)}else j=void 0;if(n.isEmptyObject(m))"inline"===("none"===j?tb(a.nodeName):j)&&(o.display=j);else{q?"hidden"in q&&(p=q.hidden):q=L.access(a,"fxshow",{}),f&&(q.hidden=!p),p?n(a).show():l.done(function(){n(a).hide()}),l.done(function(){var b;L.remove(a,"fxshow");for(b in m)n.style(a,b,m[b])});for(d in m)g=Ub(p?q[d]:0,d,l),d in q||(q[d]=g.start,p&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function Wb(a,b){var c,d,e,f,g;for(c in a)if(d=n.camelCase(c),e=b[d],f=a[c],n.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=n.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function Xb(a,b,c){var d,e,f=0,g=Qb.length,h=n.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=Lb||Sb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:n.extend({},b),opts:n.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:Lb||Sb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=n.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(Wb(k,j.opts.specialEasing);g>f;f++)if(d=Qb[f].call(j,a,k,j.opts))return d;return n.map(k,Ub,j),n.isFunction(j.opts.start)&&j.opts.start.call(a,j),n.fx.timer(n.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}n.Animation=n.extend(Xb,{tweener:function(a,b){n.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],Rb[c]=Rb[c]||[],Rb[c].unshift(b)},prefilter:function(a,b){b?Qb.unshift(a):Qb.push(a)}}),n.speed=function(a,b,c){var d=a&&"object"==typeof a?n.extend({},a):{complete:c||!c&&b||n.isFunction(a)&&a,duration:a,easing:c&&b||b&&!n.isFunction(b)&&b};return d.duration=n.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in n.fx.speeds?n.fx.speeds[d.duration]:n.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){n.isFunction(d.old)&&d.old.call(this),d.queue&&n.dequeue(this,d.queue)},d},n.fn.extend({fadeTo:function(a,b,c,d){return this.filter(S).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=n.isEmptyObject(a),f=n.speed(b,c,d),g=function(){var b=Xb(this,n.extend({},a),f);(e||L.get(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=n.timers,g=L.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&Pb.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&n.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=L.get(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=n.timers,g=d?d.length:0;for(c.finish=!0,n.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),n.each(["toggle","show","hide"],function(a,b){var c=n.fn[b];n.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(Tb(b,!0),a,d,e)}}),n.each({slideDown:Tb("show"),slideUp:Tb("hide"),slideToggle:Tb("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){n.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),n.timers=[],n.fx.tick=function(){var a,b=0,c=n.timers;for(Lb=n.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||n.fx.stop(),Lb=void 0},n.fx.timer=function(a){n.timers.push(a),a()?n.fx.start():n.timers.pop()},n.fx.interval=13,n.fx.start=function(){Mb||(Mb=setInterval(n.fx.tick,n.fx.interval))},n.fx.stop=function(){clearInterval(Mb),Mb=null},n.fx.speeds={slow:600,fast:200,_default:400},n.fn.delay=function(a,b){return a=n.fx?n.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a=l.createElement("input"),b=l.createElement("select"),c=b.appendChild(l.createElement("option"));a.type="checkbox",k.checkOn=""!==a.value,k.optSelected=c.selected,b.disabled=!0,k.optDisabled=!c.disabled,a=l.createElement("input"),a.value="t",a.type="radio",k.radioValue="t"===a.value}();var Yb,Zb,$b=n.expr.attrHandle;n.fn.extend({attr:function(a,b){return J(this,n.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){n.removeAttr(this,a)})}}),n.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===U?n.prop(a,b,c):(1===f&&n.isXMLDoc(a)||(b=b.toLowerCase(),d=n.attrHooks[b]||(n.expr.match.bool.test(b)?Zb:Yb)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void n.removeAttr(a,b))
@@ -13658,6 +17452,18768 @@ bitcoin.networks.peercoin = {
13658}; 17452};
13659 17453
13660</script> 17454</script>
17455 <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethUtil = f()}})(function(){var define,module,exports;return (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){
17456(function (global){
17457'use strict';
17458
17459// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
17460// original notice:
17461
17462/*!
17463 * The buffer module from node.js, for the browser.
17464 *
17465 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
17466 * @license MIT
17467 */
17468function compare(a, b) {
17469 if (a === b) {
17470 return 0;
17471 }
17472
17473 var x = a.length;
17474 var y = b.length;
17475
17476 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
17477 if (a[i] !== b[i]) {
17478 x = a[i];
17479 y = b[i];
17480 break;
17481 }
17482 }
17483
17484 if (x < y) {
17485 return -1;
17486 }
17487 if (y < x) {
17488 return 1;
17489 }
17490 return 0;
17491}
17492function isBuffer(b) {
17493 if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
17494 return global.Buffer.isBuffer(b);
17495 }
17496 return !!(b != null && b._isBuffer);
17497}
17498
17499// based on node assert, original notice:
17500
17501// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
17502//
17503// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
17504//
17505// Originally from narwhal.js (http://narwhaljs.org)
17506// Copyright (c) 2009 Thomas Robinson <280north.com>
17507//
17508// Permission is hereby granted, free of charge, to any person obtaining a copy
17509// of this software and associated documentation files (the 'Software'), to
17510// deal in the Software without restriction, including without limitation the
17511// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
17512// sell copies of the Software, and to permit persons to whom the Software is
17513// furnished to do so, subject to the following conditions:
17514//
17515// The above copyright notice and this permission notice shall be included in
17516// all copies or substantial portions of the Software.
17517//
17518// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17519// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17520// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17521// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
17522// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17523// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17524
17525var util = require('util/');
17526var hasOwn = Object.prototype.hasOwnProperty;
17527var pSlice = Array.prototype.slice;
17528var functionsHaveNames = (function () {
17529 return function foo() {}.name === 'foo';
17530}());
17531function pToString (obj) {
17532 return Object.prototype.toString.call(obj);
17533}
17534function isView(arrbuf) {
17535 if (isBuffer(arrbuf)) {
17536 return false;
17537 }
17538 if (typeof global.ArrayBuffer !== 'function') {
17539 return false;
17540 }
17541 if (typeof ArrayBuffer.isView === 'function') {
17542 return ArrayBuffer.isView(arrbuf);
17543 }
17544 if (!arrbuf) {
17545 return false;
17546 }
17547 if (arrbuf instanceof DataView) {
17548 return true;
17549 }
17550 if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
17551 return true;
17552 }
17553 return false;
17554}
17555// 1. The assert module provides functions that throw
17556// AssertionError's when particular conditions are not met. The
17557// assert module must conform to the following interface.
17558
17559var assert = module.exports = ok;
17560
17561// 2. The AssertionError is defined in assert.
17562// new assert.AssertionError({ message: message,
17563// actual: actual,
17564// expected: expected })
17565
17566var regex = /\s*function\s+([^\(\s]*)\s*/;
17567// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
17568function getName(func) {
17569 if (!util.isFunction(func)) {
17570 return;
17571 }
17572 if (functionsHaveNames) {
17573 return func.name;
17574 }
17575 var str = func.toString();
17576 var match = str.match(regex);
17577 return match && match[1];
17578}
17579assert.AssertionError = function AssertionError(options) {
17580 this.name = 'AssertionError';
17581 this.actual = options.actual;
17582 this.expected = options.expected;
17583 this.operator = options.operator;
17584 if (options.message) {
17585 this.message = options.message;
17586 this.generatedMessage = false;
17587 } else {
17588 this.message = getMessage(this);
17589 this.generatedMessage = true;
17590 }
17591 var stackStartFunction = options.stackStartFunction || fail;
17592 if (Error.captureStackTrace) {
17593 Error.captureStackTrace(this, stackStartFunction);
17594 } else {
17595 // non v8 browsers so we can have a stacktrace
17596 var err = new Error();
17597 if (err.stack) {
17598 var out = err.stack;
17599
17600 // try to strip useless frames
17601 var fn_name = getName(stackStartFunction);
17602 var idx = out.indexOf('\n' + fn_name);
17603 if (idx >= 0) {
17604 // once we have located the function frame
17605 // we need to strip out everything before it (and its line)
17606 var next_line = out.indexOf('\n', idx + 1);
17607 out = out.substring(next_line + 1);
17608 }
17609
17610 this.stack = out;
17611 }
17612 }
17613};
17614
17615// assert.AssertionError instanceof Error
17616util.inherits(assert.AssertionError, Error);
17617
17618function truncate(s, n) {
17619 if (typeof s === 'string') {
17620 return s.length < n ? s : s.slice(0, n);
17621 } else {
17622 return s;
17623 }
17624}
17625function inspect(something) {
17626 if (functionsHaveNames || !util.isFunction(something)) {
17627 return util.inspect(something);
17628 }
17629 var rawname = getName(something);
17630 var name = rawname ? ': ' + rawname : '';
17631 return '[Function' + name + ']';
17632}
17633function getMessage(self) {
17634 return truncate(inspect(self.actual), 128) + ' ' +
17635 self.operator + ' ' +
17636 truncate(inspect(self.expected), 128);
17637}
17638
17639// At present only the three keys mentioned above are used and
17640// understood by the spec. Implementations or sub modules can pass
17641// other keys to the AssertionError's constructor - they will be
17642// ignored.
17643
17644// 3. All of the following functions must throw an AssertionError
17645// when a corresponding condition is not met, with a message that
17646// may be undefined if not provided. All assertion methods provide
17647// both the actual and expected values to the assertion error for
17648// display purposes.
17649
17650function fail(actual, expected, message, operator, stackStartFunction) {
17651 throw new assert.AssertionError({
17652 message: message,
17653 actual: actual,
17654 expected: expected,
17655 operator: operator,
17656 stackStartFunction: stackStartFunction
17657 });
17658}
17659
17660// EXTENSION! allows for well behaved errors defined elsewhere.
17661assert.fail = fail;
17662
17663// 4. Pure assertion tests whether a value is truthy, as determined
17664// by !!guard.
17665// assert.ok(guard, message_opt);
17666// This statement is equivalent to assert.equal(true, !!guard,
17667// message_opt);. To test strictly for the value true, use
17668// assert.strictEqual(true, guard, message_opt);.
17669
17670function ok(value, message) {
17671 if (!value) fail(value, true, message, '==', assert.ok);
17672}
17673assert.ok = ok;
17674
17675// 5. The equality assertion tests shallow, coercive equality with
17676// ==.
17677// assert.equal(actual, expected, message_opt);
17678
17679assert.equal = function equal(actual, expected, message) {
17680 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
17681};
17682
17683// 6. The non-equality assertion tests for whether two objects are not equal
17684// with != assert.notEqual(actual, expected, message_opt);
17685
17686assert.notEqual = function notEqual(actual, expected, message) {
17687 if (actual == expected) {
17688 fail(actual, expected, message, '!=', assert.notEqual);
17689 }
17690};
17691
17692// 7. The equivalence assertion tests a deep equality relation.
17693// assert.deepEqual(actual, expected, message_opt);
17694
17695assert.deepEqual = function deepEqual(actual, expected, message) {
17696 if (!_deepEqual(actual, expected, false)) {
17697 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
17698 }
17699};
17700
17701assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
17702 if (!_deepEqual(actual, expected, true)) {
17703 fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
17704 }
17705};
17706
17707function _deepEqual(actual, expected, strict, memos) {
17708 // 7.1. All identical values are equivalent, as determined by ===.
17709 if (actual === expected) {
17710 return true;
17711 } else if (isBuffer(actual) && isBuffer(expected)) {
17712 return compare(actual, expected) === 0;
17713
17714 // 7.2. If the expected value is a Date object, the actual value is
17715 // equivalent if it is also a Date object that refers to the same time.
17716 } else if (util.isDate(actual) && util.isDate(expected)) {
17717 return actual.getTime() === expected.getTime();
17718
17719 // 7.3 If the expected value is a RegExp object, the actual value is
17720 // equivalent if it is also a RegExp object with the same source and
17721 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
17722 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
17723 return actual.source === expected.source &&
17724 actual.global === expected.global &&
17725 actual.multiline === expected.multiline &&
17726 actual.lastIndex === expected.lastIndex &&
17727 actual.ignoreCase === expected.ignoreCase;
17728
17729 // 7.4. Other pairs that do not both pass typeof value == 'object',
17730 // equivalence is determined by ==.
17731 } else if ((actual === null || typeof actual !== 'object') &&
17732 (expected === null || typeof expected !== 'object')) {
17733 return strict ? actual === expected : actual == expected;
17734
17735 // If both values are instances of typed arrays, wrap their underlying
17736 // ArrayBuffers in a Buffer each to increase performance
17737 // This optimization requires the arrays to have the same type as checked by
17738 // Object.prototype.toString (aka pToString). Never perform binary
17739 // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
17740 // bit patterns are not identical.
17741 } else if (isView(actual) && isView(expected) &&
17742 pToString(actual) === pToString(expected) &&
17743 !(actual instanceof Float32Array ||
17744 actual instanceof Float64Array)) {
17745 return compare(new Uint8Array(actual.buffer),
17746 new Uint8Array(expected.buffer)) === 0;
17747
17748 // 7.5 For all other Object pairs, including Array objects, equivalence is
17749 // determined by having the same number of owned properties (as verified
17750 // with Object.prototype.hasOwnProperty.call), the same set of keys
17751 // (although not necessarily the same order), equivalent values for every
17752 // corresponding key, and an identical 'prototype' property. Note: this
17753 // accounts for both named and indexed properties on Arrays.
17754 } else if (isBuffer(actual) !== isBuffer(expected)) {
17755 return false;
17756 } else {
17757 memos = memos || {actual: [], expected: []};
17758
17759 var actualIndex = memos.actual.indexOf(actual);
17760 if (actualIndex !== -1) {
17761 if (actualIndex === memos.expected.indexOf(expected)) {
17762 return true;
17763 }
17764 }
17765
17766 memos.actual.push(actual);
17767 memos.expected.push(expected);
17768
17769 return objEquiv(actual, expected, strict, memos);
17770 }
17771}
17772
17773function isArguments(object) {
17774 return Object.prototype.toString.call(object) == '[object Arguments]';
17775}
17776
17777function objEquiv(a, b, strict, actualVisitedObjects) {
17778 if (a === null || a === undefined || b === null || b === undefined)
17779 return false;
17780 // if one is a primitive, the other must be same
17781 if (util.isPrimitive(a) || util.isPrimitive(b))
17782 return a === b;
17783 if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
17784 return false;
17785 var aIsArgs = isArguments(a);
17786 var bIsArgs = isArguments(b);
17787 if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
17788 return false;
17789 if (aIsArgs) {
17790 a = pSlice.call(a);
17791 b = pSlice.call(b);
17792 return _deepEqual(a, b, strict);
17793 }
17794 var ka = objectKeys(a);
17795 var kb = objectKeys(b);
17796 var key, i;
17797 // having the same number of owned properties (keys incorporates
17798 // hasOwnProperty)
17799 if (ka.length !== kb.length)
17800 return false;
17801 //the same set of keys (although not necessarily the same order),
17802 ka.sort();
17803 kb.sort();
17804 //~~~cheap key test
17805 for (i = ka.length - 1; i >= 0; i--) {
17806 if (ka[i] !== kb[i])
17807 return false;
17808 }
17809 //equivalent values for every corresponding key, and
17810 //~~~possibly expensive deep test
17811 for (i = ka.length - 1; i >= 0; i--) {
17812 key = ka[i];
17813 if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
17814 return false;
17815 }
17816 return true;
17817}
17818
17819// 8. The non-equivalence assertion tests for any deep inequality.
17820// assert.notDeepEqual(actual, expected, message_opt);
17821
17822assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
17823 if (_deepEqual(actual, expected, false)) {
17824 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
17825 }
17826};
17827
17828assert.notDeepStrictEqual = notDeepStrictEqual;
17829function notDeepStrictEqual(actual, expected, message) {
17830 if (_deepEqual(actual, expected, true)) {
17831 fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
17832 }
17833}
17834
17835
17836// 9. The strict equality assertion tests strict equality, as determined by ===.
17837// assert.strictEqual(actual, expected, message_opt);
17838
17839assert.strictEqual = function strictEqual(actual, expected, message) {
17840 if (actual !== expected) {
17841 fail(actual, expected, message, '===', assert.strictEqual);
17842 }
17843};
17844
17845// 10. The strict non-equality assertion tests for strict inequality, as
17846// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
17847
17848assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
17849 if (actual === expected) {
17850 fail(actual, expected, message, '!==', assert.notStrictEqual);
17851 }
17852};
17853
17854function expectedException(actual, expected) {
17855 if (!actual || !expected) {
17856 return false;
17857 }
17858
17859 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
17860 return expected.test(actual);
17861 }
17862
17863 try {
17864 if (actual instanceof expected) {
17865 return true;
17866 }
17867 } catch (e) {
17868 // Ignore. The instanceof check doesn't work for arrow functions.
17869 }
17870
17871 if (Error.isPrototypeOf(expected)) {
17872 return false;
17873 }
17874
17875 return expected.call({}, actual) === true;
17876}
17877
17878function _tryBlock(block) {
17879 var error;
17880 try {
17881 block();
17882 } catch (e) {
17883 error = e;
17884 }
17885 return error;
17886}
17887
17888function _throws(shouldThrow, block, expected, message) {
17889 var actual;
17890
17891 if (typeof block !== 'function') {
17892 throw new TypeError('"block" argument must be a function');
17893 }
17894
17895 if (typeof expected === 'string') {
17896 message = expected;
17897 expected = null;
17898 }
17899
17900 actual = _tryBlock(block);
17901
17902 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
17903 (message ? ' ' + message : '.');
17904
17905 if (shouldThrow && !actual) {
17906 fail(actual, expected, 'Missing expected exception' + message);
17907 }
17908
17909 var userProvidedMessage = typeof message === 'string';
17910 var isUnwantedException = !shouldThrow && util.isError(actual);
17911 var isUnexpectedException = !shouldThrow && actual && !expected;
17912
17913 if ((isUnwantedException &&
17914 userProvidedMessage &&
17915 expectedException(actual, expected)) ||
17916 isUnexpectedException) {
17917 fail(actual, expected, 'Got unwanted exception' + message);
17918 }
17919
17920 if ((shouldThrow && actual && expected &&
17921 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
17922 throw actual;
17923 }
17924}
17925
17926// 11. Expected to throw an error:
17927// assert.throws(block, Error_opt, message_opt);
17928
17929assert.throws = function(block, /*optional*/error, /*optional*/message) {
17930 _throws(true, block, error, message);
17931};
17932
17933// EXTENSION! This is annoying to write outside this module.
17934assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
17935 _throws(false, block, error, message);
17936};
17937
17938assert.ifError = function(err) { if (err) throw err; };
17939
17940var objectKeys = Object.keys || function (obj) {
17941 var keys = [];
17942 for (var key in obj) {
17943 if (hasOwn.call(obj, key)) keys.push(key);
17944 }
17945 return keys;
17946};
17947
17948}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
17949},{"util/":30}],2:[function(require,module,exports){
17950'use strict'
17951
17952exports.byteLength = byteLength
17953exports.toByteArray = toByteArray
17954exports.fromByteArray = fromByteArray
17955
17956var lookup = []
17957var revLookup = []
17958var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
17959
17960var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
17961for (var i = 0, len = code.length; i < len; ++i) {
17962 lookup[i] = code[i]
17963 revLookup[code.charCodeAt(i)] = i
17964}
17965
17966revLookup['-'.charCodeAt(0)] = 62
17967revLookup['_'.charCodeAt(0)] = 63
17968
17969function placeHoldersCount (b64) {
17970 var len = b64.length
17971 if (len % 4 > 0) {
17972 throw new Error('Invalid string. Length must be a multiple of 4')
17973 }
17974
17975 // the number of equal signs (place holders)
17976 // if there are two placeholders, than the two characters before it
17977 // represent one byte
17978 // if there is only one, then the three characters before it represent 2 bytes
17979 // this is just a cheap hack to not do indexOf twice
17980 return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
17981}
17982
17983function byteLength (b64) {
17984 // base64 is 4/3 + up to two characters of the original data
17985 return b64.length * 3 / 4 - placeHoldersCount(b64)
17986}
17987
17988function toByteArray (b64) {
17989 var i, j, l, tmp, placeHolders, arr
17990 var len = b64.length
17991 placeHolders = placeHoldersCount(b64)
17992
17993 arr = new Arr(len * 3 / 4 - placeHolders)
17994
17995 // if there are placeholders, only get up to the last complete 4 chars
17996 l = placeHolders > 0 ? len - 4 : len
17997
17998 var L = 0
17999
18000 for (i = 0, j = 0; i < l; i += 4, j += 3) {
18001 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
18002 arr[L++] = (tmp >> 16) & 0xFF
18003 arr[L++] = (tmp >> 8) & 0xFF
18004 arr[L++] = tmp & 0xFF
18005 }
18006
18007 if (placeHolders === 2) {
18008 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
18009 arr[L++] = tmp & 0xFF
18010 } else if (placeHolders === 1) {
18011 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
18012 arr[L++] = (tmp >> 8) & 0xFF
18013 arr[L++] = tmp & 0xFF
18014 }
18015
18016 return arr
18017}
18018
18019function tripletToBase64 (num) {
18020 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
18021}
18022
18023function encodeChunk (uint8, start, end) {
18024 var tmp
18025 var output = []
18026 for (var i = start; i < end; i += 3) {
18027 tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
18028 output.push(tripletToBase64(tmp))
18029 }
18030 return output.join('')
18031}
18032
18033function fromByteArray (uint8) {
18034 var tmp
18035 var len = uint8.length
18036 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
18037 var output = ''
18038 var parts = []
18039 var maxChunkLength = 16383 // must be multiple of 3
18040
18041 // go through the array every three bytes, we'll deal with trailing stuff later
18042 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
18043 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
18044 }
18045
18046 // pad the end with zeros, but make sure to not forget the extra bytes
18047 if (extraBytes === 1) {
18048 tmp = uint8[len - 1]
18049 output += lookup[tmp >> 2]
18050 output += lookup[(tmp << 4) & 0x3F]
18051 output += '=='
18052 } else if (extraBytes === 2) {
18053 tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
18054 output += lookup[tmp >> 10]
18055 output += lookup[(tmp >> 4) & 0x3F]
18056 output += lookup[(tmp << 2) & 0x3F]
18057 output += '='
18058 }
18059
18060 parts.push(output)
18061
18062 return parts.join('')
18063}
18064
18065},{}],3:[function(require,module,exports){
18066
18067},{}],4:[function(require,module,exports){
18068(function (global){
18069'use strict';
18070
18071var buffer = require('buffer');
18072var Buffer = buffer.Buffer;
18073var SlowBuffer = buffer.SlowBuffer;
18074var MAX_LEN = buffer.kMaxLength || 2147483647;
18075exports.alloc = function alloc(size, fill, encoding) {
18076 if (typeof Buffer.alloc === 'function') {
18077 return Buffer.alloc(size, fill, encoding);
18078 }
18079 if (typeof encoding === 'number') {
18080 throw new TypeError('encoding must not be number');
18081 }
18082 if (typeof size !== 'number') {
18083 throw new TypeError('size must be a number');
18084 }
18085 if (size > MAX_LEN) {
18086 throw new RangeError('size is too large');
18087 }
18088 var enc = encoding;
18089 var _fill = fill;
18090 if (_fill === undefined) {
18091 enc = undefined;
18092 _fill = 0;
18093 }
18094 var buf = new Buffer(size);
18095 if (typeof _fill === 'string') {
18096 var fillBuf = new Buffer(_fill, enc);
18097 var flen = fillBuf.length;
18098 var i = -1;
18099 while (++i < size) {
18100 buf[i] = fillBuf[i % flen];
18101 }
18102 } else {
18103 buf.fill(_fill);
18104 }
18105 return buf;
18106}
18107exports.allocUnsafe = function allocUnsafe(size) {
18108 if (typeof Buffer.allocUnsafe === 'function') {
18109 return Buffer.allocUnsafe(size);
18110 }
18111 if (typeof size !== 'number') {
18112 throw new TypeError('size must be a number');
18113 }
18114 if (size > MAX_LEN) {
18115 throw new RangeError('size is too large');
18116 }
18117 return new Buffer(size);
18118}
18119exports.from = function from(value, encodingOrOffset, length) {
18120 if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
18121 return Buffer.from(value, encodingOrOffset, length);
18122 }
18123 if (typeof value === 'number') {
18124 throw new TypeError('"value" argument must not be a number');
18125 }
18126 if (typeof value === 'string') {
18127 return new Buffer(value, encodingOrOffset);
18128 }
18129 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
18130 var offset = encodingOrOffset;
18131 if (arguments.length === 1) {
18132 return new Buffer(value);
18133 }
18134 if (typeof offset === 'undefined') {
18135 offset = 0;
18136 }
18137 var len = length;
18138 if (typeof len === 'undefined') {
18139 len = value.byteLength - offset;
18140 }
18141 if (offset >= value.byteLength) {
18142 throw new RangeError('\'offset\' is out of bounds');
18143 }
18144 if (len > value.byteLength - offset) {
18145 throw new RangeError('\'length\' is out of bounds');
18146 }
18147 return new Buffer(value.slice(offset, offset + len));
18148 }
18149 if (Buffer.isBuffer(value)) {
18150 var out = new Buffer(value.length);
18151 value.copy(out, 0, 0, value.length);
18152 return out;
18153 }
18154 if (value) {
18155 if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
18156 return new Buffer(value);
18157 }
18158 if (value.type === 'Buffer' && Array.isArray(value.data)) {
18159 return new Buffer(value.data);
18160 }
18161 }
18162
18163 throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
18164}
18165exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
18166 if (typeof Buffer.allocUnsafeSlow === 'function') {
18167 return Buffer.allocUnsafeSlow(size);
18168 }
18169 if (typeof size !== 'number') {
18170 throw new TypeError('size must be a number');
18171 }
18172 if (size >= MAX_LEN) {
18173 throw new RangeError('size is too large');
18174 }
18175 return new SlowBuffer(size);
18176}
18177
18178}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
18179},{"buffer":5}],5:[function(require,module,exports){
18180/*!
18181 * The buffer module from node.js, for the browser.
18182 *
18183 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
18184 * @license MIT
18185 */
18186/* eslint-disable no-proto */
18187
18188'use strict'
18189
18190var base64 = require('base64-js')
18191var ieee754 = require('ieee754')
18192
18193exports.Buffer = Buffer
18194exports.SlowBuffer = SlowBuffer
18195exports.INSPECT_MAX_BYTES = 50
18196
18197var K_MAX_LENGTH = 0x7fffffff
18198exports.kMaxLength = K_MAX_LENGTH
18199
18200/**
18201 * If `Buffer.TYPED_ARRAY_SUPPORT`:
18202 * === true Use Uint8Array implementation (fastest)
18203 * === false Print warning and recommend using `buffer` v4.x which has an Object
18204 * implementation (most compatible, even IE6)
18205 *
18206 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
18207 * Opera 11.6+, iOS 4.2+.
18208 *
18209 * We report that the browser does not support typed arrays if the are not subclassable
18210 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
18211 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
18212 * for __proto__ and has a buggy typed array implementation.
18213 */
18214Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
18215
18216if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
18217 typeof console.error === 'function') {
18218 console.error(
18219 'This browser lacks typed array (Uint8Array) support which is required by ' +
18220 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
18221 )
18222}
18223
18224function typedArraySupport () {
18225 // Can typed array instances can be augmented?
18226 try {
18227 var arr = new Uint8Array(1)
18228 arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
18229 return arr.foo() === 42
18230 } catch (e) {
18231 return false
18232 }
18233}
18234
18235function createBuffer (length) {
18236 if (length > K_MAX_LENGTH) {
18237 throw new RangeError('Invalid typed array length')
18238 }
18239 // Return an augmented `Uint8Array` instance
18240 var buf = new Uint8Array(length)
18241 buf.__proto__ = Buffer.prototype
18242 return buf
18243}
18244
18245/**
18246 * The Buffer constructor returns instances of `Uint8Array` that have their
18247 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
18248 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
18249 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
18250 * returns a single octet.
18251 *
18252 * The `Uint8Array` prototype remains unmodified.
18253 */
18254
18255function Buffer (arg, encodingOrOffset, length) {
18256 // Common case.
18257 if (typeof arg === 'number') {
18258 if (typeof encodingOrOffset === 'string') {
18259 throw new Error(
18260 'If encoding is specified then the first argument must be a string'
18261 )
18262 }
18263 return allocUnsafe(arg)
18264 }
18265 return from(arg, encodingOrOffset, length)
18266}
18267
18268// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
18269if (typeof Symbol !== 'undefined' && Symbol.species &&
18270 Buffer[Symbol.species] === Buffer) {
18271 Object.defineProperty(Buffer, Symbol.species, {
18272 value: null,
18273 configurable: true,
18274 enumerable: false,
18275 writable: false
18276 })
18277}
18278
18279Buffer.poolSize = 8192 // not used by this implementation
18280
18281function from (value, encodingOrOffset, length) {
18282 if (typeof value === 'number') {
18283 throw new TypeError('"value" argument must not be a number')
18284 }
18285
18286 if (value instanceof ArrayBuffer) {
18287 return fromArrayBuffer(value, encodingOrOffset, length)
18288 }
18289
18290 if (typeof value === 'string') {
18291 return fromString(value, encodingOrOffset)
18292 }
18293
18294 return fromObject(value)
18295}
18296
18297/**
18298 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
18299 * if value is a number.
18300 * Buffer.from(str[, encoding])
18301 * Buffer.from(array)
18302 * Buffer.from(buffer)
18303 * Buffer.from(arrayBuffer[, byteOffset[, length]])
18304 **/
18305Buffer.from = function (value, encodingOrOffset, length) {
18306 return from(value, encodingOrOffset, length)
18307}
18308
18309// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
18310// https://github.com/feross/buffer/pull/148
18311Buffer.prototype.__proto__ = Uint8Array.prototype
18312Buffer.__proto__ = Uint8Array
18313
18314function assertSize (size) {
18315 if (typeof size !== 'number') {
18316 throw new TypeError('"size" argument must be a number')
18317 } else if (size < 0) {
18318 throw new RangeError('"size" argument must not be negative')
18319 }
18320}
18321
18322function alloc (size, fill, encoding) {
18323 assertSize(size)
18324 if (size <= 0) {
18325 return createBuffer(size)
18326 }
18327 if (fill !== undefined) {
18328 // Only pay attention to encoding if it's a string. This
18329 // prevents accidentally sending in a number that would
18330 // be interpretted as a start offset.
18331 return typeof encoding === 'string'
18332 ? createBuffer(size).fill(fill, encoding)
18333 : createBuffer(size).fill(fill)
18334 }
18335 return createBuffer(size)
18336}
18337
18338/**
18339 * Creates a new filled Buffer instance.
18340 * alloc(size[, fill[, encoding]])
18341 **/
18342Buffer.alloc = function (size, fill, encoding) {
18343 return alloc(size, fill, encoding)
18344}
18345
18346function allocUnsafe (size) {
18347 assertSize(size)
18348 return createBuffer(size < 0 ? 0 : checked(size) | 0)
18349}
18350
18351/**
18352 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
18353 * */
18354Buffer.allocUnsafe = function (size) {
18355 return allocUnsafe(size)
18356}
18357/**
18358 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
18359 */
18360Buffer.allocUnsafeSlow = function (size) {
18361 return allocUnsafe(size)
18362}
18363
18364function fromString (string, encoding) {
18365 if (typeof encoding !== 'string' || encoding === '') {
18366 encoding = 'utf8'
18367 }
18368
18369 if (!Buffer.isEncoding(encoding)) {
18370 throw new TypeError('"encoding" must be a valid string encoding')
18371 }
18372
18373 var length = byteLength(string, encoding) | 0
18374 var buf = createBuffer(length)
18375
18376 var actual = buf.write(string, encoding)
18377
18378 if (actual !== length) {
18379 // Writing a hex string, for example, that contains invalid characters will
18380 // cause everything after the first invalid character to be ignored. (e.g.
18381 // 'abxxcd' will be treated as 'ab')
18382 buf = buf.slice(0, actual)
18383 }
18384
18385 return buf
18386}
18387
18388function fromArrayLike (array) {
18389 var length = array.length < 0 ? 0 : checked(array.length) | 0
18390 var buf = createBuffer(length)
18391 for (var i = 0; i < length; i += 1) {
18392 buf[i] = array[i] & 255
18393 }
18394 return buf
18395}
18396
18397function fromArrayBuffer (array, byteOffset, length) {
18398 if (byteOffset < 0 || array.byteLength < byteOffset) {
18399 throw new RangeError('\'offset\' is out of bounds')
18400 }
18401
18402 if (array.byteLength < byteOffset + (length || 0)) {
18403 throw new RangeError('\'length\' is out of bounds')
18404 }
18405
18406 var buf
18407 if (byteOffset === undefined && length === undefined) {
18408 buf = new Uint8Array(array)
18409 } else if (length === undefined) {
18410 buf = new Uint8Array(array, byteOffset)
18411 } else {
18412 buf = new Uint8Array(array, byteOffset, length)
18413 }
18414
18415 // Return an augmented `Uint8Array` instance
18416 buf.__proto__ = Buffer.prototype
18417 return buf
18418}
18419
18420function fromObject (obj) {
18421 if (Buffer.isBuffer(obj)) {
18422 var len = checked(obj.length) | 0
18423 var buf = createBuffer(len)
18424
18425 if (buf.length === 0) {
18426 return buf
18427 }
18428
18429 obj.copy(buf, 0, 0, len)
18430 return buf
18431 }
18432
18433 if (obj) {
18434 if (ArrayBuffer.isView(obj) || 'length' in obj) {
18435 if (typeof obj.length !== 'number' || isnan(obj.length)) {
18436 return createBuffer(0)
18437 }
18438 return fromArrayLike(obj)
18439 }
18440
18441 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
18442 return fromArrayLike(obj.data)
18443 }
18444 }
18445
18446 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
18447}
18448
18449function checked (length) {
18450 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
18451 // length is NaN (which is otherwise coerced to zero.)
18452 if (length >= K_MAX_LENGTH) {
18453 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
18454 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
18455 }
18456 return length | 0
18457}
18458
18459function SlowBuffer (length) {
18460 if (+length != length) { // eslint-disable-line eqeqeq
18461 length = 0
18462 }
18463 return Buffer.alloc(+length)
18464}
18465
18466Buffer.isBuffer = function isBuffer (b) {
18467 return b != null && b._isBuffer === true
18468}
18469
18470Buffer.compare = function compare (a, b) {
18471 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
18472 throw new TypeError('Arguments must be Buffers')
18473 }
18474
18475 if (a === b) return 0
18476
18477 var x = a.length
18478 var y = b.length
18479
18480 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
18481 if (a[i] !== b[i]) {
18482 x = a[i]
18483 y = b[i]
18484 break
18485 }
18486 }
18487
18488 if (x < y) return -1
18489 if (y < x) return 1
18490 return 0
18491}
18492
18493Buffer.isEncoding = function isEncoding (encoding) {
18494 switch (String(encoding).toLowerCase()) {
18495 case 'hex':
18496 case 'utf8':
18497 case 'utf-8':
18498 case 'ascii':
18499 case 'latin1':
18500 case 'binary':
18501 case 'base64':
18502 case 'ucs2':
18503 case 'ucs-2':
18504 case 'utf16le':
18505 case 'utf-16le':
18506 return true
18507 default:
18508 return false
18509 }
18510}
18511
18512Buffer.concat = function concat (list, length) {
18513 if (!Array.isArray(list)) {
18514 throw new TypeError('"list" argument must be an Array of Buffers')
18515 }
18516
18517 if (list.length === 0) {
18518 return Buffer.alloc(0)
18519 }
18520
18521 var i
18522 if (length === undefined) {
18523 length = 0
18524 for (i = 0; i < list.length; ++i) {
18525 length += list[i].length
18526 }
18527 }
18528
18529 var buffer = Buffer.allocUnsafe(length)
18530 var pos = 0
18531 for (i = 0; i < list.length; ++i) {
18532 var buf = list[i]
18533 if (!Buffer.isBuffer(buf)) {
18534 throw new TypeError('"list" argument must be an Array of Buffers')
18535 }
18536 buf.copy(buffer, pos)
18537 pos += buf.length
18538 }
18539 return buffer
18540}
18541
18542function byteLength (string, encoding) {
18543 if (Buffer.isBuffer(string)) {
18544 return string.length
18545 }
18546 if (ArrayBuffer.isView(string) || string instanceof ArrayBuffer) {
18547 return string.byteLength
18548 }
18549 if (typeof string !== 'string') {
18550 string = '' + string
18551 }
18552
18553 var len = string.length
18554 if (len === 0) return 0
18555
18556 // Use a for loop to avoid recursion
18557 var loweredCase = false
18558 for (;;) {
18559 switch (encoding) {
18560 case 'ascii':
18561 case 'latin1':
18562 case 'binary':
18563 return len
18564 case 'utf8':
18565 case 'utf-8':
18566 case undefined:
18567 return utf8ToBytes(string).length
18568 case 'ucs2':
18569 case 'ucs-2':
18570 case 'utf16le':
18571 case 'utf-16le':
18572 return len * 2
18573 case 'hex':
18574 return len >>> 1
18575 case 'base64':
18576 return base64ToBytes(string).length
18577 default:
18578 if (loweredCase) return utf8ToBytes(string).length // assume utf8
18579 encoding = ('' + encoding).toLowerCase()
18580 loweredCase = true
18581 }
18582 }
18583}
18584Buffer.byteLength = byteLength
18585
18586function slowToString (encoding, start, end) {
18587 var loweredCase = false
18588
18589 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
18590 // property of a typed array.
18591
18592 // This behaves neither like String nor Uint8Array in that we set start/end
18593 // to their upper/lower bounds if the value passed is out of range.
18594 // undefined is handled specially as per ECMA-262 6th Edition,
18595 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
18596 if (start === undefined || start < 0) {
18597 start = 0
18598 }
18599 // Return early if start > this.length. Done here to prevent potential uint32
18600 // coercion fail below.
18601 if (start > this.length) {
18602 return ''
18603 }
18604
18605 if (end === undefined || end > this.length) {
18606 end = this.length
18607 }
18608
18609 if (end <= 0) {
18610 return ''
18611 }
18612
18613 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
18614 end >>>= 0
18615 start >>>= 0
18616
18617 if (end <= start) {
18618 return ''
18619 }
18620
18621 if (!encoding) encoding = 'utf8'
18622
18623 while (true) {
18624 switch (encoding) {
18625 case 'hex':
18626 return hexSlice(this, start, end)
18627
18628 case 'utf8':
18629 case 'utf-8':
18630 return utf8Slice(this, start, end)
18631
18632 case 'ascii':
18633 return asciiSlice(this, start, end)
18634
18635 case 'latin1':
18636 case 'binary':
18637 return latin1Slice(this, start, end)
18638
18639 case 'base64':
18640 return base64Slice(this, start, end)
18641
18642 case 'ucs2':
18643 case 'ucs-2':
18644 case 'utf16le':
18645 case 'utf-16le':
18646 return utf16leSlice(this, start, end)
18647
18648 default:
18649 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
18650 encoding = (encoding + '').toLowerCase()
18651 loweredCase = true
18652 }
18653 }
18654}
18655
18656// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
18657// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
18658// reliably in a browserify context because there could be multiple different
18659// copies of the 'buffer' package in use. This method works even for Buffer
18660// instances that were created from another copy of the `buffer` package.
18661// See: https://github.com/feross/buffer/issues/154
18662Buffer.prototype._isBuffer = true
18663
18664function swap (b, n, m) {
18665 var i = b[n]
18666 b[n] = b[m]
18667 b[m] = i
18668}
18669
18670Buffer.prototype.swap16 = function swap16 () {
18671 var len = this.length
18672 if (len % 2 !== 0) {
18673 throw new RangeError('Buffer size must be a multiple of 16-bits')
18674 }
18675 for (var i = 0; i < len; i += 2) {
18676 swap(this, i, i + 1)
18677 }
18678 return this
18679}
18680
18681Buffer.prototype.swap32 = function swap32 () {
18682 var len = this.length
18683 if (len % 4 !== 0) {
18684 throw new RangeError('Buffer size must be a multiple of 32-bits')
18685 }
18686 for (var i = 0; i < len; i += 4) {
18687 swap(this, i, i + 3)
18688 swap(this, i + 1, i + 2)
18689 }
18690 return this
18691}
18692
18693Buffer.prototype.swap64 = function swap64 () {
18694 var len = this.length
18695 if (len % 8 !== 0) {
18696 throw new RangeError('Buffer size must be a multiple of 64-bits')
18697 }
18698 for (var i = 0; i < len; i += 8) {
18699 swap(this, i, i + 7)
18700 swap(this, i + 1, i + 6)
18701 swap(this, i + 2, i + 5)
18702 swap(this, i + 3, i + 4)
18703 }
18704 return this
18705}
18706
18707Buffer.prototype.toString = function toString () {
18708 var length = this.length
18709 if (length === 0) return ''
18710 if (arguments.length === 0) return utf8Slice(this, 0, length)
18711 return slowToString.apply(this, arguments)
18712}
18713
18714Buffer.prototype.equals = function equals (b) {
18715 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
18716 if (this === b) return true
18717 return Buffer.compare(this, b) === 0
18718}
18719
18720Buffer.prototype.inspect = function inspect () {
18721 var str = ''
18722 var max = exports.INSPECT_MAX_BYTES
18723 if (this.length > 0) {
18724 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
18725 if (this.length > max) str += ' ... '
18726 }
18727 return '<Buffer ' + str + '>'
18728}
18729
18730Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
18731 if (!Buffer.isBuffer(target)) {
18732 throw new TypeError('Argument must be a Buffer')
18733 }
18734
18735 if (start === undefined) {
18736 start = 0
18737 }
18738 if (end === undefined) {
18739 end = target ? target.length : 0
18740 }
18741 if (thisStart === undefined) {
18742 thisStart = 0
18743 }
18744 if (thisEnd === undefined) {
18745 thisEnd = this.length
18746 }
18747
18748 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
18749 throw new RangeError('out of range index')
18750 }
18751
18752 if (thisStart >= thisEnd && start >= end) {
18753 return 0
18754 }
18755 if (thisStart >= thisEnd) {
18756 return -1
18757 }
18758 if (start >= end) {
18759 return 1
18760 }
18761
18762 start >>>= 0
18763 end >>>= 0
18764 thisStart >>>= 0
18765 thisEnd >>>= 0
18766
18767 if (this === target) return 0
18768
18769 var x = thisEnd - thisStart
18770 var y = end - start
18771 var len = Math.min(x, y)
18772
18773 var thisCopy = this.slice(thisStart, thisEnd)
18774 var targetCopy = target.slice(start, end)
18775
18776 for (var i = 0; i < len; ++i) {
18777 if (thisCopy[i] !== targetCopy[i]) {
18778 x = thisCopy[i]
18779 y = targetCopy[i]
18780 break
18781 }
18782 }
18783
18784 if (x < y) return -1
18785 if (y < x) return 1
18786 return 0
18787}
18788
18789// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
18790// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
18791//
18792// Arguments:
18793// - buffer - a Buffer to search
18794// - val - a string, Buffer, or number
18795// - byteOffset - an index into `buffer`; will be clamped to an int32
18796// - encoding - an optional encoding, relevant is val is a string
18797// - dir - true for indexOf, false for lastIndexOf
18798function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
18799 // Empty buffer means no match
18800 if (buffer.length === 0) return -1
18801
18802 // Normalize byteOffset
18803 if (typeof byteOffset === 'string') {
18804 encoding = byteOffset
18805 byteOffset = 0
18806 } else if (byteOffset > 0x7fffffff) {
18807 byteOffset = 0x7fffffff
18808 } else if (byteOffset < -0x80000000) {
18809 byteOffset = -0x80000000
18810 }
18811 byteOffset = +byteOffset // Coerce to Number.
18812 if (isNaN(byteOffset)) {
18813 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
18814 byteOffset = dir ? 0 : (buffer.length - 1)
18815 }
18816
18817 // Normalize byteOffset: negative offsets start from the end of the buffer
18818 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
18819 if (byteOffset >= buffer.length) {
18820 if (dir) return -1
18821 else byteOffset = buffer.length - 1
18822 } else if (byteOffset < 0) {
18823 if (dir) byteOffset = 0
18824 else return -1
18825 }
18826
18827 // Normalize val
18828 if (typeof val === 'string') {
18829 val = Buffer.from(val, encoding)
18830 }
18831
18832 // Finally, search either indexOf (if dir is true) or lastIndexOf
18833 if (Buffer.isBuffer(val)) {
18834 // Special case: looking for empty string/buffer always fails
18835 if (val.length === 0) {
18836 return -1
18837 }
18838 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
18839 } else if (typeof val === 'number') {
18840 val = val & 0xFF // Search for a byte value [0-255]
18841 if (typeof Uint8Array.prototype.indexOf === 'function') {
18842 if (dir) {
18843 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
18844 } else {
18845 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
18846 }
18847 }
18848 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
18849 }
18850
18851 throw new TypeError('val must be string, number or Buffer')
18852}
18853
18854function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
18855 var indexSize = 1
18856 var arrLength = arr.length
18857 var valLength = val.length
18858
18859 if (encoding !== undefined) {
18860 encoding = String(encoding).toLowerCase()
18861 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
18862 encoding === 'utf16le' || encoding === 'utf-16le') {
18863 if (arr.length < 2 || val.length < 2) {
18864 return -1
18865 }
18866 indexSize = 2
18867 arrLength /= 2
18868 valLength /= 2
18869 byteOffset /= 2
18870 }
18871 }
18872
18873 function read (buf, i) {
18874 if (indexSize === 1) {
18875 return buf[i]
18876 } else {
18877 return buf.readUInt16BE(i * indexSize)
18878 }
18879 }
18880
18881 var i
18882 if (dir) {
18883 var foundIndex = -1
18884 for (i = byteOffset; i < arrLength; i++) {
18885 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
18886 if (foundIndex === -1) foundIndex = i
18887 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
18888 } else {
18889 if (foundIndex !== -1) i -= i - foundIndex
18890 foundIndex = -1
18891 }
18892 }
18893 } else {
18894 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
18895 for (i = byteOffset; i >= 0; i--) {
18896 var found = true
18897 for (var j = 0; j < valLength; j++) {
18898 if (read(arr, i + j) !== read(val, j)) {
18899 found = false
18900 break
18901 }
18902 }
18903 if (found) return i
18904 }
18905 }
18906
18907 return -1
18908}
18909
18910Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
18911 return this.indexOf(val, byteOffset, encoding) !== -1
18912}
18913
18914Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
18915 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
18916}
18917
18918Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
18919 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
18920}
18921
18922function hexWrite (buf, string, offset, length) {
18923 offset = Number(offset) || 0
18924 var remaining = buf.length - offset
18925 if (!length) {
18926 length = remaining
18927 } else {
18928 length = Number(length)
18929 if (length > remaining) {
18930 length = remaining
18931 }
18932 }
18933
18934 // must be an even number of digits
18935 var strLen = string.length
18936 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
18937
18938 if (length > strLen / 2) {
18939 length = strLen / 2
18940 }
18941 for (var i = 0; i < length; ++i) {
18942 var parsed = parseInt(string.substr(i * 2, 2), 16)
18943 if (isNaN(parsed)) return i
18944 buf[offset + i] = parsed
18945 }
18946 return i
18947}
18948
18949function utf8Write (buf, string, offset, length) {
18950 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
18951}
18952
18953function asciiWrite (buf, string, offset, length) {
18954 return blitBuffer(asciiToBytes(string), buf, offset, length)
18955}
18956
18957function latin1Write (buf, string, offset, length) {
18958 return asciiWrite(buf, string, offset, length)
18959}
18960
18961function base64Write (buf, string, offset, length) {
18962 return blitBuffer(base64ToBytes(string), buf, offset, length)
18963}
18964
18965function ucs2Write (buf, string, offset, length) {
18966 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
18967}
18968
18969Buffer.prototype.write = function write (string, offset, length, encoding) {
18970 // Buffer#write(string)
18971 if (offset === undefined) {
18972 encoding = 'utf8'
18973 length = this.length
18974 offset = 0
18975 // Buffer#write(string, encoding)
18976 } else if (length === undefined && typeof offset === 'string') {
18977 encoding = offset
18978 length = this.length
18979 offset = 0
18980 // Buffer#write(string, offset[, length][, encoding])
18981 } else if (isFinite(offset)) {
18982 offset = offset >>> 0
18983 if (isFinite(length)) {
18984 length = length >>> 0
18985 if (encoding === undefined) encoding = 'utf8'
18986 } else {
18987 encoding = length
18988 length = undefined
18989 }
18990 } else {
18991 throw new Error(
18992 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
18993 )
18994 }
18995
18996 var remaining = this.length - offset
18997 if (length === undefined || length > remaining) length = remaining
18998
18999 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
19000 throw new RangeError('Attempt to write outside buffer bounds')
19001 }
19002
19003 if (!encoding) encoding = 'utf8'
19004
19005 var loweredCase = false
19006 for (;;) {
19007 switch (encoding) {
19008 case 'hex':
19009 return hexWrite(this, string, offset, length)
19010
19011 case 'utf8':
19012 case 'utf-8':
19013 return utf8Write(this, string, offset, length)
19014
19015 case 'ascii':
19016 return asciiWrite(this, string, offset, length)
19017
19018 case 'latin1':
19019 case 'binary':
19020 return latin1Write(this, string, offset, length)
19021
19022 case 'base64':
19023 // Warning: maxLength not taken into account in base64Write
19024 return base64Write(this, string, offset, length)
19025
19026 case 'ucs2':
19027 case 'ucs-2':
19028 case 'utf16le':
19029 case 'utf-16le':
19030 return ucs2Write(this, string, offset, length)
19031
19032 default:
19033 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
19034 encoding = ('' + encoding).toLowerCase()
19035 loweredCase = true
19036 }
19037 }
19038}
19039
19040Buffer.prototype.toJSON = function toJSON () {
19041 return {
19042 type: 'Buffer',
19043 data: Array.prototype.slice.call(this._arr || this, 0)
19044 }
19045}
19046
19047function base64Slice (buf, start, end) {
19048 if (start === 0 && end === buf.length) {
19049 return base64.fromByteArray(buf)
19050 } else {
19051 return base64.fromByteArray(buf.slice(start, end))
19052 }
19053}
19054
19055function utf8Slice (buf, start, end) {
19056 end = Math.min(buf.length, end)
19057 var res = []
19058
19059 var i = start
19060 while (i < end) {
19061 var firstByte = buf[i]
19062 var codePoint = null
19063 var bytesPerSequence = (firstByte > 0xEF) ? 4
19064 : (firstByte > 0xDF) ? 3
19065 : (firstByte > 0xBF) ? 2
19066 : 1
19067
19068 if (i + bytesPerSequence <= end) {
19069 var secondByte, thirdByte, fourthByte, tempCodePoint
19070
19071 switch (bytesPerSequence) {
19072 case 1:
19073 if (firstByte < 0x80) {
19074 codePoint = firstByte
19075 }
19076 break
19077 case 2:
19078 secondByte = buf[i + 1]
19079 if ((secondByte & 0xC0) === 0x80) {
19080 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
19081 if (tempCodePoint > 0x7F) {
19082 codePoint = tempCodePoint
19083 }
19084 }
19085 break
19086 case 3:
19087 secondByte = buf[i + 1]
19088 thirdByte = buf[i + 2]
19089 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
19090 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
19091 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
19092 codePoint = tempCodePoint
19093 }
19094 }
19095 break
19096 case 4:
19097 secondByte = buf[i + 1]
19098 thirdByte = buf[i + 2]
19099 fourthByte = buf[i + 3]
19100 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
19101 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
19102 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
19103 codePoint = tempCodePoint
19104 }
19105 }
19106 }
19107 }
19108
19109 if (codePoint === null) {
19110 // we did not generate a valid codePoint so insert a
19111 // replacement char (U+FFFD) and advance only 1 byte
19112 codePoint = 0xFFFD
19113 bytesPerSequence = 1
19114 } else if (codePoint > 0xFFFF) {
19115 // encode to utf16 (surrogate pair dance)
19116 codePoint -= 0x10000
19117 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
19118 codePoint = 0xDC00 | codePoint & 0x3FF
19119 }
19120
19121 res.push(codePoint)
19122 i += bytesPerSequence
19123 }
19124
19125 return decodeCodePointsArray(res)
19126}
19127
19128// Based on http://stackoverflow.com/a/22747272/680742, the browser with
19129// the lowest limit is Chrome, with 0x10000 args.
19130// We go 1 magnitude less, for safety
19131var MAX_ARGUMENTS_LENGTH = 0x1000
19132
19133function decodeCodePointsArray (codePoints) {
19134 var len = codePoints.length
19135 if (len <= MAX_ARGUMENTS_LENGTH) {
19136 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
19137 }
19138
19139 // Decode in chunks to avoid "call stack size exceeded".
19140 var res = ''
19141 var i = 0
19142 while (i < len) {
19143 res += String.fromCharCode.apply(
19144 String,
19145 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
19146 )
19147 }
19148 return res
19149}
19150
19151function asciiSlice (buf, start, end) {
19152 var ret = ''
19153 end = Math.min(buf.length, end)
19154
19155 for (var i = start; i < end; ++i) {
19156 ret += String.fromCharCode(buf[i] & 0x7F)
19157 }
19158 return ret
19159}
19160
19161function latin1Slice (buf, start, end) {
19162 var ret = ''
19163 end = Math.min(buf.length, end)
19164
19165 for (var i = start; i < end; ++i) {
19166 ret += String.fromCharCode(buf[i])
19167 }
19168 return ret
19169}
19170
19171function hexSlice (buf, start, end) {
19172 var len = buf.length
19173
19174 if (!start || start < 0) start = 0
19175 if (!end || end < 0 || end > len) end = len
19176
19177 var out = ''
19178 for (var i = start; i < end; ++i) {
19179 out += toHex(buf[i])
19180 }
19181 return out
19182}
19183
19184function utf16leSlice (buf, start, end) {
19185 var bytes = buf.slice(start, end)
19186 var res = ''
19187 for (var i = 0; i < bytes.length; i += 2) {
19188 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
19189 }
19190 return res
19191}
19192
19193Buffer.prototype.slice = function slice (start, end) {
19194 var len = this.length
19195 start = ~~start
19196 end = end === undefined ? len : ~~end
19197
19198 if (start < 0) {
19199 start += len
19200 if (start < 0) start = 0
19201 } else if (start > len) {
19202 start = len
19203 }
19204
19205 if (end < 0) {
19206 end += len
19207 if (end < 0) end = 0
19208 } else if (end > len) {
19209 end = len
19210 }
19211
19212 if (end < start) end = start
19213
19214 var newBuf = this.subarray(start, end)
19215 // Return an augmented `Uint8Array` instance
19216 newBuf.__proto__ = Buffer.prototype
19217 return newBuf
19218}
19219
19220/*
19221 * Need to make sure that buffer isn't trying to write out of bounds.
19222 */
19223function checkOffset (offset, ext, length) {
19224 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
19225 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
19226}
19227
19228Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
19229 offset = offset >>> 0
19230 byteLength = byteLength >>> 0
19231 if (!noAssert) checkOffset(offset, byteLength, this.length)
19232
19233 var val = this[offset]
19234 var mul = 1
19235 var i = 0
19236 while (++i < byteLength && (mul *= 0x100)) {
19237 val += this[offset + i] * mul
19238 }
19239
19240 return val
19241}
19242
19243Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
19244 offset = offset >>> 0
19245 byteLength = byteLength >>> 0
19246 if (!noAssert) {
19247 checkOffset(offset, byteLength, this.length)
19248 }
19249
19250 var val = this[offset + --byteLength]
19251 var mul = 1
19252 while (byteLength > 0 && (mul *= 0x100)) {
19253 val += this[offset + --byteLength] * mul
19254 }
19255
19256 return val
19257}
19258
19259Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
19260 offset = offset >>> 0
19261 if (!noAssert) checkOffset(offset, 1, this.length)
19262 return this[offset]
19263}
19264
19265Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
19266 offset = offset >>> 0
19267 if (!noAssert) checkOffset(offset, 2, this.length)
19268 return this[offset] | (this[offset + 1] << 8)
19269}
19270
19271Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
19272 offset = offset >>> 0
19273 if (!noAssert) checkOffset(offset, 2, this.length)
19274 return (this[offset] << 8) | this[offset + 1]
19275}
19276
19277Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
19278 offset = offset >>> 0
19279 if (!noAssert) checkOffset(offset, 4, this.length)
19280
19281 return ((this[offset]) |
19282 (this[offset + 1] << 8) |
19283 (this[offset + 2] << 16)) +
19284 (this[offset + 3] * 0x1000000)
19285}
19286
19287Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
19288 offset = offset >>> 0
19289 if (!noAssert) checkOffset(offset, 4, this.length)
19290
19291 return (this[offset] * 0x1000000) +
19292 ((this[offset + 1] << 16) |
19293 (this[offset + 2] << 8) |
19294 this[offset + 3])
19295}
19296
19297Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
19298 offset = offset >>> 0
19299 byteLength = byteLength >>> 0
19300 if (!noAssert) checkOffset(offset, byteLength, this.length)
19301
19302 var val = this[offset]
19303 var mul = 1
19304 var i = 0
19305 while (++i < byteLength && (mul *= 0x100)) {
19306 val += this[offset + i] * mul
19307 }
19308 mul *= 0x80
19309
19310 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
19311
19312 return val
19313}
19314
19315Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
19316 offset = offset >>> 0
19317 byteLength = byteLength >>> 0
19318 if (!noAssert) checkOffset(offset, byteLength, this.length)
19319
19320 var i = byteLength
19321 var mul = 1
19322 var val = this[offset + --i]
19323 while (i > 0 && (mul *= 0x100)) {
19324 val += this[offset + --i] * mul
19325 }
19326 mul *= 0x80
19327
19328 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
19329
19330 return val
19331}
19332
19333Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
19334 offset = offset >>> 0
19335 if (!noAssert) checkOffset(offset, 1, this.length)
19336 if (!(this[offset] & 0x80)) return (this[offset])
19337 return ((0xff - this[offset] + 1) * -1)
19338}
19339
19340Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
19341 offset = offset >>> 0
19342 if (!noAssert) checkOffset(offset, 2, this.length)
19343 var val = this[offset] | (this[offset + 1] << 8)
19344 return (val & 0x8000) ? val | 0xFFFF0000 : val
19345}
19346
19347Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
19348 offset = offset >>> 0
19349 if (!noAssert) checkOffset(offset, 2, this.length)
19350 var val = this[offset + 1] | (this[offset] << 8)
19351 return (val & 0x8000) ? val | 0xFFFF0000 : val
19352}
19353
19354Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
19355 offset = offset >>> 0
19356 if (!noAssert) checkOffset(offset, 4, this.length)
19357
19358 return (this[offset]) |
19359 (this[offset + 1] << 8) |
19360 (this[offset + 2] << 16) |
19361 (this[offset + 3] << 24)
19362}
19363
19364Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
19365 offset = offset >>> 0
19366 if (!noAssert) checkOffset(offset, 4, this.length)
19367
19368 return (this[offset] << 24) |
19369 (this[offset + 1] << 16) |
19370 (this[offset + 2] << 8) |
19371 (this[offset + 3])
19372}
19373
19374Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
19375 offset = offset >>> 0
19376 if (!noAssert) checkOffset(offset, 4, this.length)
19377 return ieee754.read(this, offset, true, 23, 4)
19378}
19379
19380Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
19381 offset = offset >>> 0
19382 if (!noAssert) checkOffset(offset, 4, this.length)
19383 return ieee754.read(this, offset, false, 23, 4)
19384}
19385
19386Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
19387 offset = offset >>> 0
19388 if (!noAssert) checkOffset(offset, 8, this.length)
19389 return ieee754.read(this, offset, true, 52, 8)
19390}
19391
19392Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
19393 offset = offset >>> 0
19394 if (!noAssert) checkOffset(offset, 8, this.length)
19395 return ieee754.read(this, offset, false, 52, 8)
19396}
19397
19398function checkInt (buf, value, offset, ext, max, min) {
19399 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
19400 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
19401 if (offset + ext > buf.length) throw new RangeError('Index out of range')
19402}
19403
19404Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
19405 value = +value
19406 offset = offset >>> 0
19407 byteLength = byteLength >>> 0
19408 if (!noAssert) {
19409 var maxBytes = Math.pow(2, 8 * byteLength) - 1
19410 checkInt(this, value, offset, byteLength, maxBytes, 0)
19411 }
19412
19413 var mul = 1
19414 var i = 0
19415 this[offset] = value & 0xFF
19416 while (++i < byteLength && (mul *= 0x100)) {
19417 this[offset + i] = (value / mul) & 0xFF
19418 }
19419
19420 return offset + byteLength
19421}
19422
19423Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
19424 value = +value
19425 offset = offset >>> 0
19426 byteLength = byteLength >>> 0
19427 if (!noAssert) {
19428 var maxBytes = Math.pow(2, 8 * byteLength) - 1
19429 checkInt(this, value, offset, byteLength, maxBytes, 0)
19430 }
19431
19432 var i = byteLength - 1
19433 var mul = 1
19434 this[offset + i] = value & 0xFF
19435 while (--i >= 0 && (mul *= 0x100)) {
19436 this[offset + i] = (value / mul) & 0xFF
19437 }
19438
19439 return offset + byteLength
19440}
19441
19442Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
19443 value = +value
19444 offset = offset >>> 0
19445 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
19446 this[offset] = (value & 0xff)
19447 return offset + 1
19448}
19449
19450Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
19451 value = +value
19452 offset = offset >>> 0
19453 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
19454 this[offset] = (value & 0xff)
19455 this[offset + 1] = (value >>> 8)
19456 return offset + 2
19457}
19458
19459Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
19460 value = +value
19461 offset = offset >>> 0
19462 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
19463 this[offset] = (value >>> 8)
19464 this[offset + 1] = (value & 0xff)
19465 return offset + 2
19466}
19467
19468Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
19469 value = +value
19470 offset = offset >>> 0
19471 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
19472 this[offset + 3] = (value >>> 24)
19473 this[offset + 2] = (value >>> 16)
19474 this[offset + 1] = (value >>> 8)
19475 this[offset] = (value & 0xff)
19476 return offset + 4
19477}
19478
19479Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
19480 value = +value
19481 offset = offset >>> 0
19482 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
19483 this[offset] = (value >>> 24)
19484 this[offset + 1] = (value >>> 16)
19485 this[offset + 2] = (value >>> 8)
19486 this[offset + 3] = (value & 0xff)
19487 return offset + 4
19488}
19489
19490Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
19491 value = +value
19492 offset = offset >>> 0
19493 if (!noAssert) {
19494 var limit = Math.pow(2, (8 * byteLength) - 1)
19495
19496 checkInt(this, value, offset, byteLength, limit - 1, -limit)
19497 }
19498
19499 var i = 0
19500 var mul = 1
19501 var sub = 0
19502 this[offset] = value & 0xFF
19503 while (++i < byteLength && (mul *= 0x100)) {
19504 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
19505 sub = 1
19506 }
19507 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
19508 }
19509
19510 return offset + byteLength
19511}
19512
19513Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
19514 value = +value
19515 offset = offset >>> 0
19516 if (!noAssert) {
19517 var limit = Math.pow(2, (8 * byteLength) - 1)
19518
19519 checkInt(this, value, offset, byteLength, limit - 1, -limit)
19520 }
19521
19522 var i = byteLength - 1
19523 var mul = 1
19524 var sub = 0
19525 this[offset + i] = value & 0xFF
19526 while (--i >= 0 && (mul *= 0x100)) {
19527 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
19528 sub = 1
19529 }
19530 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
19531 }
19532
19533 return offset + byteLength
19534}
19535
19536Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
19537 value = +value
19538 offset = offset >>> 0
19539 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
19540 if (value < 0) value = 0xff + value + 1
19541 this[offset] = (value & 0xff)
19542 return offset + 1
19543}
19544
19545Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
19546 value = +value
19547 offset = offset >>> 0
19548 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
19549 this[offset] = (value & 0xff)
19550 this[offset + 1] = (value >>> 8)
19551 return offset + 2
19552}
19553
19554Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
19555 value = +value
19556 offset = offset >>> 0
19557 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
19558 this[offset] = (value >>> 8)
19559 this[offset + 1] = (value & 0xff)
19560 return offset + 2
19561}
19562
19563Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
19564 value = +value
19565 offset = offset >>> 0
19566 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
19567 this[offset] = (value & 0xff)
19568 this[offset + 1] = (value >>> 8)
19569 this[offset + 2] = (value >>> 16)
19570 this[offset + 3] = (value >>> 24)
19571 return offset + 4
19572}
19573
19574Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
19575 value = +value
19576 offset = offset >>> 0
19577 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
19578 if (value < 0) value = 0xffffffff + value + 1
19579 this[offset] = (value >>> 24)
19580 this[offset + 1] = (value >>> 16)
19581 this[offset + 2] = (value >>> 8)
19582 this[offset + 3] = (value & 0xff)
19583 return offset + 4
19584}
19585
19586function checkIEEE754 (buf, value, offset, ext, max, min) {
19587 if (offset + ext > buf.length) throw new RangeError('Index out of range')
19588 if (offset < 0) throw new RangeError('Index out of range')
19589}
19590
19591function writeFloat (buf, value, offset, littleEndian, noAssert) {
19592 value = +value
19593 offset = offset >>> 0
19594 if (!noAssert) {
19595 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
19596 }
19597 ieee754.write(buf, value, offset, littleEndian, 23, 4)
19598 return offset + 4
19599}
19600
19601Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
19602 return writeFloat(this, value, offset, true, noAssert)
19603}
19604
19605Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
19606 return writeFloat(this, value, offset, false, noAssert)
19607}
19608
19609function writeDouble (buf, value, offset, littleEndian, noAssert) {
19610 value = +value
19611 offset = offset >>> 0
19612 if (!noAssert) {
19613 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
19614 }
19615 ieee754.write(buf, value, offset, littleEndian, 52, 8)
19616 return offset + 8
19617}
19618
19619Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
19620 return writeDouble(this, value, offset, true, noAssert)
19621}
19622
19623Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
19624 return writeDouble(this, value, offset, false, noAssert)
19625}
19626
19627// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
19628Buffer.prototype.copy = function copy (target, targetStart, start, end) {
19629 if (!start) start = 0
19630 if (!end && end !== 0) end = this.length
19631 if (targetStart >= target.length) targetStart = target.length
19632 if (!targetStart) targetStart = 0
19633 if (end > 0 && end < start) end = start
19634
19635 // Copy 0 bytes; we're done
19636 if (end === start) return 0
19637 if (target.length === 0 || this.length === 0) return 0
19638
19639 // Fatal error conditions
19640 if (targetStart < 0) {
19641 throw new RangeError('targetStart out of bounds')
19642 }
19643 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
19644 if (end < 0) throw new RangeError('sourceEnd out of bounds')
19645
19646 // Are we oob?
19647 if (end > this.length) end = this.length
19648 if (target.length - targetStart < end - start) {
19649 end = target.length - targetStart + start
19650 }
19651
19652 var len = end - start
19653 var i
19654
19655 if (this === target && start < targetStart && targetStart < end) {
19656 // descending copy from end
19657 for (i = len - 1; i >= 0; --i) {
19658 target[i + targetStart] = this[i + start]
19659 }
19660 } else if (len < 1000) {
19661 // ascending copy from start
19662 for (i = 0; i < len; ++i) {
19663 target[i + targetStart] = this[i + start]
19664 }
19665 } else {
19666 Uint8Array.prototype.set.call(
19667 target,
19668 this.subarray(start, start + len),
19669 targetStart
19670 )
19671 }
19672
19673 return len
19674}
19675
19676// Usage:
19677// buffer.fill(number[, offset[, end]])
19678// buffer.fill(buffer[, offset[, end]])
19679// buffer.fill(string[, offset[, end]][, encoding])
19680Buffer.prototype.fill = function fill (val, start, end, encoding) {
19681 // Handle string cases:
19682 if (typeof val === 'string') {
19683 if (typeof start === 'string') {
19684 encoding = start
19685 start = 0
19686 end = this.length
19687 } else if (typeof end === 'string') {
19688 encoding = end
19689 end = this.length
19690 }
19691 if (val.length === 1) {
19692 var code = val.charCodeAt(0)
19693 if (code < 256) {
19694 val = code
19695 }
19696 }
19697 if (encoding !== undefined && typeof encoding !== 'string') {
19698 throw new TypeError('encoding must be a string')
19699 }
19700 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
19701 throw new TypeError('Unknown encoding: ' + encoding)
19702 }
19703 } else if (typeof val === 'number') {
19704 val = val & 255
19705 }
19706
19707 // Invalid ranges are not set to a default, so can range check early.
19708 if (start < 0 || this.length < start || this.length < end) {
19709 throw new RangeError('Out of range index')
19710 }
19711
19712 if (end <= start) {
19713 return this
19714 }
19715
19716 start = start >>> 0
19717 end = end === undefined ? this.length : end >>> 0
19718
19719 if (!val) val = 0
19720
19721 var i
19722 if (typeof val === 'number') {
19723 for (i = start; i < end; ++i) {
19724 this[i] = val
19725 }
19726 } else {
19727 var bytes = Buffer.isBuffer(val)
19728 ? val
19729 : new Buffer(val, encoding)
19730 var len = bytes.length
19731 for (i = 0; i < end - start; ++i) {
19732 this[i + start] = bytes[i % len]
19733 }
19734 }
19735
19736 return this
19737}
19738
19739// HELPER FUNCTIONS
19740// ================
19741
19742var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
19743
19744function base64clean (str) {
19745 // Node strips out invalid characters like \n and \t from the string, base64-js does not
19746 str = stringtrim(str).replace(INVALID_BASE64_RE, '')
19747 // Node converts strings with length < 2 to ''
19748 if (str.length < 2) return ''
19749 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
19750 while (str.length % 4 !== 0) {
19751 str = str + '='
19752 }
19753 return str
19754}
19755
19756function stringtrim (str) {
19757 if (str.trim) return str.trim()
19758 return str.replace(/^\s+|\s+$/g, '')
19759}
19760
19761function toHex (n) {
19762 if (n < 16) return '0' + n.toString(16)
19763 return n.toString(16)
19764}
19765
19766function utf8ToBytes (string, units) {
19767 units = units || Infinity
19768 var codePoint
19769 var length = string.length
19770 var leadSurrogate = null
19771 var bytes = []
19772
19773 for (var i = 0; i < length; ++i) {
19774 codePoint = string.charCodeAt(i)
19775
19776 // is surrogate component
19777 if (codePoint > 0xD7FF && codePoint < 0xE000) {
19778 // last char was a lead
19779 if (!leadSurrogate) {
19780 // no lead yet
19781 if (codePoint > 0xDBFF) {
19782 // unexpected trail
19783 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
19784 continue
19785 } else if (i + 1 === length) {
19786 // unpaired lead
19787 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
19788 continue
19789 }
19790
19791 // valid lead
19792 leadSurrogate = codePoint
19793
19794 continue
19795 }
19796
19797 // 2 leads in a row
19798 if (codePoint < 0xDC00) {
19799 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
19800 leadSurrogate = codePoint
19801 continue
19802 }
19803
19804 // valid surrogate pair
19805 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
19806 } else if (leadSurrogate) {
19807 // valid bmp char, but last char was a lead
19808 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
19809 }
19810
19811 leadSurrogate = null
19812
19813 // encode utf8
19814 if (codePoint < 0x80) {
19815 if ((units -= 1) < 0) break
19816 bytes.push(codePoint)
19817 } else if (codePoint < 0x800) {
19818 if ((units -= 2) < 0) break
19819 bytes.push(
19820 codePoint >> 0x6 | 0xC0,
19821 codePoint & 0x3F | 0x80
19822 )
19823 } else if (codePoint < 0x10000) {
19824 if ((units -= 3) < 0) break
19825 bytes.push(
19826 codePoint >> 0xC | 0xE0,
19827 codePoint >> 0x6 & 0x3F | 0x80,
19828 codePoint & 0x3F | 0x80
19829 )
19830 } else if (codePoint < 0x110000) {
19831 if ((units -= 4) < 0) break
19832 bytes.push(
19833 codePoint >> 0x12 | 0xF0,
19834 codePoint >> 0xC & 0x3F | 0x80,
19835 codePoint >> 0x6 & 0x3F | 0x80,
19836 codePoint & 0x3F | 0x80
19837 )
19838 } else {
19839 throw new Error('Invalid code point')
19840 }
19841 }
19842
19843 return bytes
19844}
19845
19846function asciiToBytes (str) {
19847 var byteArray = []
19848 for (var i = 0; i < str.length; ++i) {
19849 // Node's code seems to be doing this and not & 0x7F..
19850 byteArray.push(str.charCodeAt(i) & 0xFF)
19851 }
19852 return byteArray
19853}
19854
19855function utf16leToBytes (str, units) {
19856 var c, hi, lo
19857 var byteArray = []
19858 for (var i = 0; i < str.length; ++i) {
19859 if ((units -= 2) < 0) break
19860
19861 c = str.charCodeAt(i)
19862 hi = c >> 8
19863 lo = c % 256
19864 byteArray.push(lo)
19865 byteArray.push(hi)
19866 }
19867
19868 return byteArray
19869}
19870
19871function base64ToBytes (str) {
19872 return base64.toByteArray(base64clean(str))
19873}
19874
19875function blitBuffer (src, dst, offset, length) {
19876 for (var i = 0; i < length; ++i) {
19877 if ((i + offset >= dst.length) || (i >= src.length)) break
19878 dst[i + offset] = src[i]
19879 }
19880 return i
19881}
19882
19883function isnan (val) {
19884 return val !== val // eslint-disable-line no-self-compare
19885}
19886
19887},{"base64-js":2,"ieee754":8}],6:[function(require,module,exports){
19888(function (Buffer){
19889// Copyright Joyent, Inc. and other Node contributors.
19890//
19891// Permission is hereby granted, free of charge, to any person obtaining a
19892// copy of this software and associated documentation files (the
19893// "Software"), to deal in the Software without restriction, including
19894// without limitation the rights to use, copy, modify, merge, publish,
19895// distribute, sublicense, and/or sell copies of the Software, and to permit
19896// persons to whom the Software is furnished to do so, subject to the
19897// following conditions:
19898//
19899// The above copyright notice and this permission notice shall be included
19900// in all copies or substantial portions of the Software.
19901//
19902// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19903// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19904// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19905// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19906// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19907// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19908// USE OR OTHER DEALINGS IN THE SOFTWARE.
19909
19910// NOTE: These type checking functions intentionally don't use `instanceof`
19911// because it is fragile and can be easily faked with `Object.create()`.
19912
19913function isArray(arg) {
19914 if (Array.isArray) {
19915 return Array.isArray(arg);
19916 }
19917 return objectToString(arg) === '[object Array]';
19918}
19919exports.isArray = isArray;
19920
19921function isBoolean(arg) {
19922 return typeof arg === 'boolean';
19923}
19924exports.isBoolean = isBoolean;
19925
19926function isNull(arg) {
19927 return arg === null;
19928}
19929exports.isNull = isNull;
19930
19931function isNullOrUndefined(arg) {
19932 return arg == null;
19933}
19934exports.isNullOrUndefined = isNullOrUndefined;
19935
19936function isNumber(arg) {
19937 return typeof arg === 'number';
19938}
19939exports.isNumber = isNumber;
19940
19941function isString(arg) {
19942 return typeof arg === 'string';
19943}
19944exports.isString = isString;
19945
19946function isSymbol(arg) {
19947 return typeof arg === 'symbol';
19948}
19949exports.isSymbol = isSymbol;
19950
19951function isUndefined(arg) {
19952 return arg === void 0;
19953}
19954exports.isUndefined = isUndefined;
19955
19956function isRegExp(re) {
19957 return objectToString(re) === '[object RegExp]';
19958}
19959exports.isRegExp = isRegExp;
19960
19961function isObject(arg) {
19962 return typeof arg === 'object' && arg !== null;
19963}
19964exports.isObject = isObject;
19965
19966function isDate(d) {
19967 return objectToString(d) === '[object Date]';
19968}
19969exports.isDate = isDate;
19970
19971function isError(e) {
19972 return (objectToString(e) === '[object Error]' || e instanceof Error);
19973}
19974exports.isError = isError;
19975
19976function isFunction(arg) {
19977 return typeof arg === 'function';
19978}
19979exports.isFunction = isFunction;
19980
19981function isPrimitive(arg) {
19982 return arg === null ||
19983 typeof arg === 'boolean' ||
19984 typeof arg === 'number' ||
19985 typeof arg === 'string' ||
19986 typeof arg === 'symbol' || // ES6 symbol
19987 typeof arg === 'undefined';
19988}
19989exports.isPrimitive = isPrimitive;
19990
19991exports.isBuffer = Buffer.isBuffer;
19992
19993function objectToString(o) {
19994 return Object.prototype.toString.call(o);
19995}
19996
19997}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
19998},{"../../is-buffer/index.js":10}],7:[function(require,module,exports){
19999// Copyright Joyent, Inc. and other Node contributors.
20000//
20001// Permission is hereby granted, free of charge, to any person obtaining a
20002// copy of this software and associated documentation files (the
20003// "Software"), to deal in the Software without restriction, including
20004// without limitation the rights to use, copy, modify, merge, publish,
20005// distribute, sublicense, and/or sell copies of the Software, and to permit
20006// persons to whom the Software is furnished to do so, subject to the
20007// following conditions:
20008//
20009// The above copyright notice and this permission notice shall be included
20010// in all copies or substantial portions of the Software.
20011//
20012// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20013// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20014// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
20015// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20016// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20017// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20018// USE OR OTHER DEALINGS IN THE SOFTWARE.
20019
20020function EventEmitter() {
20021 this._events = this._events || {};
20022 this._maxListeners = this._maxListeners || undefined;
20023}
20024module.exports = EventEmitter;
20025
20026// Backwards-compat with node 0.10.x
20027EventEmitter.EventEmitter = EventEmitter;
20028
20029EventEmitter.prototype._events = undefined;
20030EventEmitter.prototype._maxListeners = undefined;
20031
20032// By default EventEmitters will print a warning if more than 10 listeners are
20033// added to it. This is a useful default which helps finding memory leaks.
20034EventEmitter.defaultMaxListeners = 10;
20035
20036// Obviously not all Emitters should be limited to 10. This function allows
20037// that to be increased. Set to zero for unlimited.
20038EventEmitter.prototype.setMaxListeners = function(n) {
20039 if (!isNumber(n) || n < 0 || isNaN(n))
20040 throw TypeError('n must be a positive number');
20041 this._maxListeners = n;
20042 return this;
20043};
20044
20045EventEmitter.prototype.emit = function(type) {
20046 var er, handler, len, args, i, listeners;
20047
20048 if (!this._events)
20049 this._events = {};
20050
20051 // If there is no 'error' event listener then throw.
20052 if (type === 'error') {
20053 if (!this._events.error ||
20054 (isObject(this._events.error) && !this._events.error.length)) {
20055 er = arguments[1];
20056 if (er instanceof Error) {
20057 throw er; // Unhandled 'error' event
20058 } else {
20059 // At least give some kind of context to the user
20060 var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
20061 err.context = er;
20062 throw err;
20063 }
20064 }
20065 }
20066
20067 handler = this._events[type];
20068
20069 if (isUndefined(handler))
20070 return false;
20071
20072 if (isFunction(handler)) {
20073 switch (arguments.length) {
20074 // fast cases
20075 case 1:
20076 handler.call(this);
20077 break;
20078 case 2:
20079 handler.call(this, arguments[1]);
20080 break;
20081 case 3:
20082 handler.call(this, arguments[1], arguments[2]);
20083 break;
20084 // slower
20085 default:
20086 args = Array.prototype.slice.call(arguments, 1);
20087 handler.apply(this, args);
20088 }
20089 } else if (isObject(handler)) {
20090 args = Array.prototype.slice.call(arguments, 1);
20091 listeners = handler.slice();
20092 len = listeners.length;
20093 for (i = 0; i < len; i++)
20094 listeners[i].apply(this, args);
20095 }
20096
20097 return true;
20098};
20099
20100EventEmitter.prototype.addListener = function(type, listener) {
20101 var m;
20102
20103 if (!isFunction(listener))
20104 throw TypeError('listener must be a function');
20105
20106 if (!this._events)
20107 this._events = {};
20108
20109 // To avoid recursion in the case that type === "newListener"! Before
20110 // adding it to the listeners, first emit "newListener".
20111 if (this._events.newListener)
20112 this.emit('newListener', type,
20113 isFunction(listener.listener) ?
20114 listener.listener : listener);
20115
20116 if (!this._events[type])
20117 // Optimize the case of one listener. Don't need the extra array object.
20118 this._events[type] = listener;
20119 else if (isObject(this._events[type]))
20120 // If we've already got an array, just append.
20121 this._events[type].push(listener);
20122 else
20123 // Adding the second element, need to change to array.
20124 this._events[type] = [this._events[type], listener];
20125
20126 // Check for listener leak
20127 if (isObject(this._events[type]) && !this._events[type].warned) {
20128 if (!isUndefined(this._maxListeners)) {
20129 m = this._maxListeners;
20130 } else {
20131 m = EventEmitter.defaultMaxListeners;
20132 }
20133
20134 if (m && m > 0 && this._events[type].length > m) {
20135 this._events[type].warned = true;
20136 console.error('(node) warning: possible EventEmitter memory ' +
20137 'leak detected. %d listeners added. ' +
20138 'Use emitter.setMaxListeners() to increase limit.',
20139 this._events[type].length);
20140 if (typeof console.trace === 'function') {
20141 // not supported in IE 10
20142 console.trace();
20143 }
20144 }
20145 }
20146
20147 return this;
20148};
20149
20150EventEmitter.prototype.on = EventEmitter.prototype.addListener;
20151
20152EventEmitter.prototype.once = function(type, listener) {
20153 if (!isFunction(listener))
20154 throw TypeError('listener must be a function');
20155
20156 var fired = false;
20157
20158 function g() {
20159 this.removeListener(type, g);
20160
20161 if (!fired) {
20162 fired = true;
20163 listener.apply(this, arguments);
20164 }
20165 }
20166
20167 g.listener = listener;
20168 this.on(type, g);
20169
20170 return this;
20171};
20172
20173// emits a 'removeListener' event iff the listener was removed
20174EventEmitter.prototype.removeListener = function(type, listener) {
20175 var list, position, length, i;
20176
20177 if (!isFunction(listener))
20178 throw TypeError('listener must be a function');
20179
20180 if (!this._events || !this._events[type])
20181 return this;
20182
20183 list = this._events[type];
20184 length = list.length;
20185 position = -1;
20186
20187 if (list === listener ||
20188 (isFunction(list.listener) && list.listener === listener)) {
20189 delete this._events[type];
20190 if (this._events.removeListener)
20191 this.emit('removeListener', type, listener);
20192
20193 } else if (isObject(list)) {
20194 for (i = length; i-- > 0;) {
20195 if (list[i] === listener ||
20196 (list[i].listener && list[i].listener === listener)) {
20197 position = i;
20198 break;
20199 }
20200 }
20201
20202 if (position < 0)
20203 return this;
20204
20205 if (list.length === 1) {
20206 list.length = 0;
20207 delete this._events[type];
20208 } else {
20209 list.splice(position, 1);
20210 }
20211
20212 if (this._events.removeListener)
20213 this.emit('removeListener', type, listener);
20214 }
20215
20216 return this;
20217};
20218
20219EventEmitter.prototype.removeAllListeners = function(type) {
20220 var key, listeners;
20221
20222 if (!this._events)
20223 return this;
20224
20225 // not listening for removeListener, no need to emit
20226 if (!this._events.removeListener) {
20227 if (arguments.length === 0)
20228 this._events = {};
20229 else if (this._events[type])
20230 delete this._events[type];
20231 return this;
20232 }
20233
20234 // emit removeListener for all listeners on all events
20235 if (arguments.length === 0) {
20236 for (key in this._events) {
20237 if (key === 'removeListener') continue;
20238 this.removeAllListeners(key);
20239 }
20240 this.removeAllListeners('removeListener');
20241 this._events = {};
20242 return this;
20243 }
20244
20245 listeners = this._events[type];
20246
20247 if (isFunction(listeners)) {
20248 this.removeListener(type, listeners);
20249 } else if (listeners) {
20250 // LIFO order
20251 while (listeners.length)
20252 this.removeListener(type, listeners[listeners.length - 1]);
20253 }
20254 delete this._events[type];
20255
20256 return this;
20257};
20258
20259EventEmitter.prototype.listeners = function(type) {
20260 var ret;
20261 if (!this._events || !this._events[type])
20262 ret = [];
20263 else if (isFunction(this._events[type]))
20264 ret = [this._events[type]];
20265 else
20266 ret = this._events[type].slice();
20267 return ret;
20268};
20269
20270EventEmitter.prototype.listenerCount = function(type) {
20271 if (this._events) {
20272 var evlistener = this._events[type];
20273
20274 if (isFunction(evlistener))
20275 return 1;
20276 else if (evlistener)
20277 return evlistener.length;
20278 }
20279 return 0;
20280};
20281
20282EventEmitter.listenerCount = function(emitter, type) {
20283 return emitter.listenerCount(type);
20284};
20285
20286function isFunction(arg) {
20287 return typeof arg === 'function';
20288}
20289
20290function isNumber(arg) {
20291 return typeof arg === 'number';
20292}
20293
20294function isObject(arg) {
20295 return typeof arg === 'object' && arg !== null;
20296}
20297
20298function isUndefined(arg) {
20299 return arg === void 0;
20300}
20301
20302},{}],8:[function(require,module,exports){
20303exports.read = function (buffer, offset, isLE, mLen, nBytes) {
20304 var e, m
20305 var eLen = nBytes * 8 - mLen - 1
20306 var eMax = (1 << eLen) - 1
20307 var eBias = eMax >> 1
20308 var nBits = -7
20309 var i = isLE ? (nBytes - 1) : 0
20310 var d = isLE ? -1 : 1
20311 var s = buffer[offset + i]
20312
20313 i += d
20314
20315 e = s & ((1 << (-nBits)) - 1)
20316 s >>= (-nBits)
20317 nBits += eLen
20318 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
20319
20320 m = e & ((1 << (-nBits)) - 1)
20321 e >>= (-nBits)
20322 nBits += mLen
20323 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
20324
20325 if (e === 0) {
20326 e = 1 - eBias
20327 } else if (e === eMax) {
20328 return m ? NaN : ((s ? -1 : 1) * Infinity)
20329 } else {
20330 m = m + Math.pow(2, mLen)
20331 e = e - eBias
20332 }
20333 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
20334}
20335
20336exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
20337 var e, m, c
20338 var eLen = nBytes * 8 - mLen - 1
20339 var eMax = (1 << eLen) - 1
20340 var eBias = eMax >> 1
20341 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
20342 var i = isLE ? 0 : (nBytes - 1)
20343 var d = isLE ? 1 : -1
20344 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
20345
20346 value = Math.abs(value)
20347
20348 if (isNaN(value) || value === Infinity) {
20349 m = isNaN(value) ? 1 : 0
20350 e = eMax
20351 } else {
20352 e = Math.floor(Math.log(value) / Math.LN2)
20353 if (value * (c = Math.pow(2, -e)) < 1) {
20354 e--
20355 c *= 2
20356 }
20357 if (e + eBias >= 1) {
20358 value += rt / c
20359 } else {
20360 value += rt * Math.pow(2, 1 - eBias)
20361 }
20362 if (value * c >= 2) {
20363 e++
20364 c /= 2
20365 }
20366
20367 if (e + eBias >= eMax) {
20368 m = 0
20369 e = eMax
20370 } else if (e + eBias >= 1) {
20371 m = (value * c - 1) * Math.pow(2, mLen)
20372 e = e + eBias
20373 } else {
20374 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
20375 e = 0
20376 }
20377 }
20378
20379 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
20380
20381 e = (e << mLen) | m
20382 eLen += mLen
20383 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
20384
20385 buffer[offset + i - d] |= s * 128
20386}
20387
20388},{}],9:[function(require,module,exports){
20389if (typeof Object.create === 'function') {
20390 // implementation from standard node.js 'util' module
20391 module.exports = function inherits(ctor, superCtor) {
20392 ctor.super_ = superCtor
20393 ctor.prototype = Object.create(superCtor.prototype, {
20394 constructor: {
20395 value: ctor,
20396 enumerable: false,
20397 writable: true,
20398 configurable: true
20399 }
20400 });
20401 };
20402} else {
20403 // old school shim for old browsers
20404 module.exports = function inherits(ctor, superCtor) {
20405 ctor.super_ = superCtor
20406 var TempCtor = function () {}
20407 TempCtor.prototype = superCtor.prototype
20408 ctor.prototype = new TempCtor()
20409 ctor.prototype.constructor = ctor
20410 }
20411}
20412
20413},{}],10:[function(require,module,exports){
20414/*!
20415 * Determine if an object is a Buffer
20416 *
20417 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
20418 * @license MIT
20419 */
20420
20421// The _isBuffer check is for Safari 5-7 support, because it's missing
20422// Object.prototype.constructor. Remove this eventually
20423module.exports = function (obj) {
20424 return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
20425}
20426
20427function isBuffer (obj) {
20428 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
20429}
20430
20431// For Node v0.10 support. Remove this eventually.
20432function isSlowBuffer (obj) {
20433 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
20434}
20435
20436},{}],11:[function(require,module,exports){
20437var toString = {}.toString;
20438
20439module.exports = Array.isArray || function (arr) {
20440 return toString.call(arr) == '[object Array]';
20441};
20442
20443},{}],12:[function(require,module,exports){
20444(function (process){
20445'use strict';
20446
20447if (!process.version ||
20448 process.version.indexOf('v0.') === 0 ||
20449 process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
20450 module.exports = nextTick;
20451} else {
20452 module.exports = process.nextTick;
20453}
20454
20455function nextTick(fn, arg1, arg2, arg3) {
20456 if (typeof fn !== 'function') {
20457 throw new TypeError('"callback" argument must be a function');
20458 }
20459 var len = arguments.length;
20460 var args, i;
20461 switch (len) {
20462 case 0:
20463 case 1:
20464 return process.nextTick(fn);
20465 case 2:
20466 return process.nextTick(function afterTickOne() {
20467 fn.call(null, arg1);
20468 });
20469 case 3:
20470 return process.nextTick(function afterTickTwo() {
20471 fn.call(null, arg1, arg2);
20472 });
20473 case 4:
20474 return process.nextTick(function afterTickThree() {
20475 fn.call(null, arg1, arg2, arg3);
20476 });
20477 default:
20478 args = new Array(len - 1);
20479 i = 0;
20480 while (i < args.length) {
20481 args[i++] = arguments[i];
20482 }
20483 return process.nextTick(function afterTick() {
20484 fn.apply(null, args);
20485 });
20486 }
20487}
20488
20489}).call(this,require('_process'))
20490},{"_process":13}],13:[function(require,module,exports){
20491// shim for using process in browser
20492var process = module.exports = {};
20493
20494// cached from whatever global is present so that test runners that stub it
20495// don't break things. But we need to wrap it in a try catch in case it is
20496// wrapped in strict mode code which doesn't define any globals. It's inside a
20497// function because try/catches deoptimize in certain engines.
20498
20499var cachedSetTimeout;
20500var cachedClearTimeout;
20501
20502function defaultSetTimout() {
20503 throw new Error('setTimeout has not been defined');
20504}
20505function defaultClearTimeout () {
20506 throw new Error('clearTimeout has not been defined');
20507}
20508(function () {
20509 try {
20510 if (typeof setTimeout === 'function') {
20511 cachedSetTimeout = setTimeout;
20512 } else {
20513 cachedSetTimeout = defaultSetTimout;
20514 }
20515 } catch (e) {
20516 cachedSetTimeout = defaultSetTimout;
20517 }
20518 try {
20519 if (typeof clearTimeout === 'function') {
20520 cachedClearTimeout = clearTimeout;
20521 } else {
20522 cachedClearTimeout = defaultClearTimeout;
20523 }
20524 } catch (e) {
20525 cachedClearTimeout = defaultClearTimeout;
20526 }
20527} ())
20528function runTimeout(fun) {
20529 if (cachedSetTimeout === setTimeout) {
20530 //normal enviroments in sane situations
20531 return setTimeout(fun, 0);
20532 }
20533 // if setTimeout wasn't available but was latter defined
20534 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
20535 cachedSetTimeout = setTimeout;
20536 return setTimeout(fun, 0);
20537 }
20538 try {
20539 // when when somebody has screwed with setTimeout but no I.E. maddness
20540 return cachedSetTimeout(fun, 0);
20541 } catch(e){
20542 try {
20543 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
20544 return cachedSetTimeout.call(null, fun, 0);
20545 } catch(e){
20546 // 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
20547 return cachedSetTimeout.call(this, fun, 0);
20548 }
20549 }
20550
20551
20552}
20553function runClearTimeout(marker) {
20554 if (cachedClearTimeout === clearTimeout) {
20555 //normal enviroments in sane situations
20556 return clearTimeout(marker);
20557 }
20558 // if clearTimeout wasn't available but was latter defined
20559 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
20560 cachedClearTimeout = clearTimeout;
20561 return clearTimeout(marker);
20562 }
20563 try {
20564 // when when somebody has screwed with setTimeout but no I.E. maddness
20565 return cachedClearTimeout(marker);
20566 } catch (e){
20567 try {
20568 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
20569 return cachedClearTimeout.call(null, marker);
20570 } catch (e){
20571 // 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.
20572 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
20573 return cachedClearTimeout.call(this, marker);
20574 }
20575 }
20576
20577
20578
20579}
20580var queue = [];
20581var draining = false;
20582var currentQueue;
20583var queueIndex = -1;
20584
20585function cleanUpNextTick() {
20586 if (!draining || !currentQueue) {
20587 return;
20588 }
20589 draining = false;
20590 if (currentQueue.length) {
20591 queue = currentQueue.concat(queue);
20592 } else {
20593 queueIndex = -1;
20594 }
20595 if (queue.length) {
20596 drainQueue();
20597 }
20598}
20599
20600function drainQueue() {
20601 if (draining) {
20602 return;
20603 }
20604 var timeout = runTimeout(cleanUpNextTick);
20605 draining = true;
20606
20607 var len = queue.length;
20608 while(len) {
20609 currentQueue = queue;
20610 queue = [];
20611 while (++queueIndex < len) {
20612 if (currentQueue) {
20613 currentQueue[queueIndex].run();
20614 }
20615 }
20616 queueIndex = -1;
20617 len = queue.length;
20618 }
20619 currentQueue = null;
20620 draining = false;
20621 runClearTimeout(timeout);
20622}
20623
20624process.nextTick = function (fun) {
20625 var args = new Array(arguments.length - 1);
20626 if (arguments.length > 1) {
20627 for (var i = 1; i < arguments.length; i++) {
20628 args[i - 1] = arguments[i];
20629 }
20630 }
20631 queue.push(new Item(fun, args));
20632 if (queue.length === 1 && !draining) {
20633 runTimeout(drainQueue);
20634 }
20635};
20636
20637// v8 likes predictible objects
20638function Item(fun, array) {
20639 this.fun = fun;
20640 this.array = array;
20641}
20642Item.prototype.run = function () {
20643 this.fun.apply(null, this.array);
20644};
20645process.title = 'browser';
20646process.browser = true;
20647process.env = {};
20648process.argv = [];
20649process.version = ''; // empty string to avoid regexp issues
20650process.versions = {};
20651
20652function noop() {}
20653
20654process.on = noop;
20655process.addListener = noop;
20656process.once = noop;
20657process.off = noop;
20658process.removeListener = noop;
20659process.removeAllListeners = noop;
20660process.emit = noop;
20661
20662process.binding = function (name) {
20663 throw new Error('process.binding is not supported');
20664};
20665
20666process.cwd = function () { return '/' };
20667process.chdir = function (dir) {
20668 throw new Error('process.chdir is not supported');
20669};
20670process.umask = function() { return 0; };
20671
20672},{}],14:[function(require,module,exports){
20673module.exports = require("./lib/_stream_duplex.js")
20674
20675},{"./lib/_stream_duplex.js":15}],15:[function(require,module,exports){
20676// a duplex stream is just a stream that is both readable and writable.
20677// Since JS doesn't have multiple prototypal inheritance, this class
20678// prototypally inherits from Readable, and then parasitically from
20679// Writable.
20680
20681'use strict';
20682
20683/*<replacement>*/
20684
20685var objectKeys = Object.keys || function (obj) {
20686 var keys = [];
20687 for (var key in obj) {
20688 keys.push(key);
20689 }return keys;
20690};
20691/*</replacement>*/
20692
20693module.exports = Duplex;
20694
20695/*<replacement>*/
20696var processNextTick = require('process-nextick-args');
20697/*</replacement>*/
20698
20699/*<replacement>*/
20700var util = require('core-util-is');
20701util.inherits = require('inherits');
20702/*</replacement>*/
20703
20704var Readable = require('./_stream_readable');
20705var Writable = require('./_stream_writable');
20706
20707util.inherits(Duplex, Readable);
20708
20709var keys = objectKeys(Writable.prototype);
20710for (var v = 0; v < keys.length; v++) {
20711 var method = keys[v];
20712 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
20713}
20714
20715function Duplex(options) {
20716 if (!(this instanceof Duplex)) return new Duplex(options);
20717
20718 Readable.call(this, options);
20719 Writable.call(this, options);
20720
20721 if (options && options.readable === false) this.readable = false;
20722
20723 if (options && options.writable === false) this.writable = false;
20724
20725 this.allowHalfOpen = true;
20726 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
20727
20728 this.once('end', onend);
20729}
20730
20731// the no-half-open enforcer
20732function onend() {
20733 // if we allow half-open state, or if the writable side ended,
20734 // then we're ok.
20735 if (this.allowHalfOpen || this._writableState.ended) return;
20736
20737 // no more data can be written.
20738 // But allow more writes to happen in this tick.
20739 processNextTick(onEndNT, this);
20740}
20741
20742function onEndNT(self) {
20743 self.end();
20744}
20745
20746function forEach(xs, f) {
20747 for (var i = 0, l = xs.length; i < l; i++) {
20748 f(xs[i], i);
20749 }
20750}
20751},{"./_stream_readable":17,"./_stream_writable":19,"core-util-is":6,"inherits":9,"process-nextick-args":12}],16:[function(require,module,exports){
20752// a passthrough stream.
20753// basically just the most minimal sort of Transform stream.
20754// Every written chunk gets output as-is.
20755
20756'use strict';
20757
20758module.exports = PassThrough;
20759
20760var Transform = require('./_stream_transform');
20761
20762/*<replacement>*/
20763var util = require('core-util-is');
20764util.inherits = require('inherits');
20765/*</replacement>*/
20766
20767util.inherits(PassThrough, Transform);
20768
20769function PassThrough(options) {
20770 if (!(this instanceof PassThrough)) return new PassThrough(options);
20771
20772 Transform.call(this, options);
20773}
20774
20775PassThrough.prototype._transform = function (chunk, encoding, cb) {
20776 cb(null, chunk);
20777};
20778},{"./_stream_transform":18,"core-util-is":6,"inherits":9}],17:[function(require,module,exports){
20779(function (process){
20780'use strict';
20781
20782module.exports = Readable;
20783
20784/*<replacement>*/
20785var processNextTick = require('process-nextick-args');
20786/*</replacement>*/
20787
20788/*<replacement>*/
20789var isArray = require('isarray');
20790/*</replacement>*/
20791
20792/*<replacement>*/
20793var Duplex;
20794/*</replacement>*/
20795
20796Readable.ReadableState = ReadableState;
20797
20798/*<replacement>*/
20799var EE = require('events').EventEmitter;
20800
20801var EElistenerCount = function (emitter, type) {
20802 return emitter.listeners(type).length;
20803};
20804/*</replacement>*/
20805
20806/*<replacement>*/
20807var Stream;
20808(function () {
20809 try {
20810 Stream = require('st' + 'ream');
20811 } catch (_) {} finally {
20812 if (!Stream) Stream = require('events').EventEmitter;
20813 }
20814})();
20815/*</replacement>*/
20816
20817var Buffer = require('buffer').Buffer;
20818/*<replacement>*/
20819var bufferShim = require('buffer-shims');
20820/*</replacement>*/
20821
20822/*<replacement>*/
20823var util = require('core-util-is');
20824util.inherits = require('inherits');
20825/*</replacement>*/
20826
20827/*<replacement>*/
20828var debugUtil = require('util');
20829var debug = void 0;
20830if (debugUtil && debugUtil.debuglog) {
20831 debug = debugUtil.debuglog('stream');
20832} else {
20833 debug = function () {};
20834}
20835/*</replacement>*/
20836
20837var BufferList = require('./internal/streams/BufferList');
20838var StringDecoder;
20839
20840util.inherits(Readable, Stream);
20841
20842function prependListener(emitter, event, fn) {
20843 // Sadly this is not cacheable as some libraries bundle their own
20844 // event emitter implementation with them.
20845 if (typeof emitter.prependListener === 'function') {
20846 return emitter.prependListener(event, fn);
20847 } else {
20848 // This is a hack to make sure that our error handler is attached before any
20849 // userland ones. NEVER DO THIS. This is here only because this code needs
20850 // to continue to work with older versions of Node.js that do not include
20851 // the prependListener() method. The goal is to eventually remove this hack.
20852 if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
20853 }
20854}
20855
20856function ReadableState(options, stream) {
20857 Duplex = Duplex || require('./_stream_duplex');
20858
20859 options = options || {};
20860
20861 // object stream flag. Used to make read(n) ignore n and to
20862 // make all the buffer merging and length checks go away
20863 this.objectMode = !!options.objectMode;
20864
20865 if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
20866
20867 // the point at which it stops calling _read() to fill the buffer
20868 // Note: 0 is a valid value, means "don't call _read preemptively ever"
20869 var hwm = options.highWaterMark;
20870 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
20871 this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
20872
20873 // cast to ints.
20874 this.highWaterMark = ~ ~this.highWaterMark;
20875
20876 // A linked list is used to store data chunks instead of an array because the
20877 // linked list can remove elements from the beginning faster than
20878 // array.shift()
20879 this.buffer = new BufferList();
20880 this.length = 0;
20881 this.pipes = null;
20882 this.pipesCount = 0;
20883 this.flowing = null;
20884 this.ended = false;
20885 this.endEmitted = false;
20886 this.reading = false;
20887
20888 // a flag to be able to tell if the onwrite cb is called immediately,
20889 // or on a later tick. We set this to true at first, because any
20890 // actions that shouldn't happen until "later" should generally also
20891 // not happen before the first write call.
20892 this.sync = true;
20893
20894 // whenever we return null, then we set a flag to say
20895 // that we're awaiting a 'readable' event emission.
20896 this.needReadable = false;
20897 this.emittedReadable = false;
20898 this.readableListening = false;
20899 this.resumeScheduled = false;
20900
20901 // Crypto is kind of old and crusty. Historically, its default string
20902 // encoding is 'binary' so we have to make this configurable.
20903 // Everything else in the universe uses 'utf8', though.
20904 this.defaultEncoding = options.defaultEncoding || 'utf8';
20905
20906 // when piping, we only care about 'readable' events that happen
20907 // after read()ing all the bytes and not getting any pushback.
20908 this.ranOut = false;
20909
20910 // the number of writers that are awaiting a drain event in .pipe()s
20911 this.awaitDrain = 0;
20912
20913 // if true, a maybeReadMore has been scheduled
20914 this.readingMore = false;
20915
20916 this.decoder = null;
20917 this.encoding = null;
20918 if (options.encoding) {
20919 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
20920 this.decoder = new StringDecoder(options.encoding);
20921 this.encoding = options.encoding;
20922 }
20923}
20924
20925function Readable(options) {
20926 Duplex = Duplex || require('./_stream_duplex');
20927
20928 if (!(this instanceof Readable)) return new Readable(options);
20929
20930 this._readableState = new ReadableState(options, this);
20931
20932 // legacy
20933 this.readable = true;
20934
20935 if (options && typeof options.read === 'function') this._read = options.read;
20936
20937 Stream.call(this);
20938}
20939
20940// Manually shove something into the read() buffer.
20941// This returns true if the highWaterMark has not been hit yet,
20942// similar to how Writable.write() returns true if you should
20943// write() some more.
20944Readable.prototype.push = function (chunk, encoding) {
20945 var state = this._readableState;
20946
20947 if (!state.objectMode && typeof chunk === 'string') {
20948 encoding = encoding || state.defaultEncoding;
20949 if (encoding !== state.encoding) {
20950 chunk = bufferShim.from(chunk, encoding);
20951 encoding = '';
20952 }
20953 }
20954
20955 return readableAddChunk(this, state, chunk, encoding, false);
20956};
20957
20958// Unshift should *always* be something directly out of read()
20959Readable.prototype.unshift = function (chunk) {
20960 var state = this._readableState;
20961 return readableAddChunk(this, state, chunk, '', true);
20962};
20963
20964Readable.prototype.isPaused = function () {
20965 return this._readableState.flowing === false;
20966};
20967
20968function readableAddChunk(stream, state, chunk, encoding, addToFront) {
20969 var er = chunkInvalid(state, chunk);
20970 if (er) {
20971 stream.emit('error', er);
20972 } else if (chunk === null) {
20973 state.reading = false;
20974 onEofChunk(stream, state);
20975 } else if (state.objectMode || chunk && chunk.length > 0) {
20976 if (state.ended && !addToFront) {
20977 var e = new Error('stream.push() after EOF');
20978 stream.emit('error', e);
20979 } else if (state.endEmitted && addToFront) {
20980 var _e = new Error('stream.unshift() after end event');
20981 stream.emit('error', _e);
20982 } else {
20983 var skipAdd;
20984 if (state.decoder && !addToFront && !encoding) {
20985 chunk = state.decoder.write(chunk);
20986 skipAdd = !state.objectMode && chunk.length === 0;
20987 }
20988
20989 if (!addToFront) state.reading = false;
20990
20991 // Don't add to the buffer if we've decoded to an empty string chunk and
20992 // we're not in object mode
20993 if (!skipAdd) {
20994 // if we want the data now, just emit it.
20995 if (state.flowing && state.length === 0 && !state.sync) {
20996 stream.emit('data', chunk);
20997 stream.read(0);
20998 } else {
20999 // update the buffer info.
21000 state.length += state.objectMode ? 1 : chunk.length;
21001 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
21002
21003 if (state.needReadable) emitReadable(stream);
21004 }
21005 }
21006
21007 maybeReadMore(stream, state);
21008 }
21009 } else if (!addToFront) {
21010 state.reading = false;
21011 }
21012
21013 return needMoreData(state);
21014}
21015
21016// if it's past the high water mark, we can push in some more.
21017// Also, if we have no data yet, we can stand some
21018// more bytes. This is to work around cases where hwm=0,
21019// such as the repl. Also, if the push() triggered a
21020// readable event, and the user called read(largeNumber) such that
21021// needReadable was set, then we ought to push more, so that another
21022// 'readable' event will be triggered.
21023function needMoreData(state) {
21024 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
21025}
21026
21027// backwards compatibility.
21028Readable.prototype.setEncoding = function (enc) {
21029 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
21030 this._readableState.decoder = new StringDecoder(enc);
21031 this._readableState.encoding = enc;
21032 return this;
21033};
21034
21035// Don't raise the hwm > 8MB
21036var MAX_HWM = 0x800000;
21037function computeNewHighWaterMark(n) {
21038 if (n >= MAX_HWM) {
21039 n = MAX_HWM;
21040 } else {
21041 // Get the next highest power of 2 to prevent increasing hwm excessively in
21042 // tiny amounts
21043 n--;
21044 n |= n >>> 1;
21045 n |= n >>> 2;
21046 n |= n >>> 4;
21047 n |= n >>> 8;
21048 n |= n >>> 16;
21049 n++;
21050 }
21051 return n;
21052}
21053
21054// This function is designed to be inlinable, so please take care when making
21055// changes to the function body.
21056function howMuchToRead(n, state) {
21057 if (n <= 0 || state.length === 0 && state.ended) return 0;
21058 if (state.objectMode) return 1;
21059 if (n !== n) {
21060 // Only flow one buffer at a time
21061 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
21062 }
21063 // If we're asking for more than the current hwm, then raise the hwm.
21064 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
21065 if (n <= state.length) return n;
21066 // Don't have enough
21067 if (!state.ended) {
21068 state.needReadable = true;
21069 return 0;
21070 }
21071 return state.length;
21072}
21073
21074// you can override either this method, or the async _read(n) below.
21075Readable.prototype.read = function (n) {
21076 debug('read', n);
21077 n = parseInt(n, 10);
21078 var state = this._readableState;
21079 var nOrig = n;
21080
21081 if (n !== 0) state.emittedReadable = false;
21082
21083 // if we're doing read(0) to trigger a readable event, but we
21084 // already have a bunch of data in the buffer, then just trigger
21085 // the 'readable' event and move on.
21086 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
21087 debug('read: emitReadable', state.length, state.ended);
21088 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
21089 return null;
21090 }
21091
21092 n = howMuchToRead(n, state);
21093
21094 // if we've ended, and we're now clear, then finish it up.
21095 if (n === 0 && state.ended) {
21096 if (state.length === 0) endReadable(this);
21097 return null;
21098 }
21099
21100 // All the actual chunk generation logic needs to be
21101 // *below* the call to _read. The reason is that in certain
21102 // synthetic stream cases, such as passthrough streams, _read
21103 // may be a completely synchronous operation which may change
21104 // the state of the read buffer, providing enough data when
21105 // before there was *not* enough.
21106 //
21107 // So, the steps are:
21108 // 1. Figure out what the state of things will be after we do
21109 // a read from the buffer.
21110 //
21111 // 2. If that resulting state will trigger a _read, then call _read.
21112 // Note that this may be asynchronous, or synchronous. Yes, it is
21113 // deeply ugly to write APIs this way, but that still doesn't mean
21114 // that the Readable class should behave improperly, as streams are
21115 // designed to be sync/async agnostic.
21116 // Take note if the _read call is sync or async (ie, if the read call
21117 // has returned yet), so that we know whether or not it's safe to emit
21118 // 'readable' etc.
21119 //
21120 // 3. Actually pull the requested chunks out of the buffer and return.
21121
21122 // if we need a readable event, then we need to do some reading.
21123 var doRead = state.needReadable;
21124 debug('need readable', doRead);
21125
21126 // if we currently have less than the highWaterMark, then also read some
21127 if (state.length === 0 || state.length - n < state.highWaterMark) {
21128 doRead = true;
21129 debug('length less than watermark', doRead);
21130 }
21131
21132 // however, if we've ended, then there's no point, and if we're already
21133 // reading, then it's unnecessary.
21134 if (state.ended || state.reading) {
21135 doRead = false;
21136 debug('reading or ended', doRead);
21137 } else if (doRead) {
21138 debug('do read');
21139 state.reading = true;
21140 state.sync = true;
21141 // if the length is currently zero, then we *need* a readable event.
21142 if (state.length === 0) state.needReadable = true;
21143 // call internal read method
21144 this._read(state.highWaterMark);
21145 state.sync = false;
21146 // If _read pushed data synchronously, then `reading` will be false,
21147 // and we need to re-evaluate how much data we can return to the user.
21148 if (!state.reading) n = howMuchToRead(nOrig, state);
21149 }
21150
21151 var ret;
21152 if (n > 0) ret = fromList(n, state);else ret = null;
21153
21154 if (ret === null) {
21155 state.needReadable = true;
21156 n = 0;
21157 } else {
21158 state.length -= n;
21159 }
21160
21161 if (state.length === 0) {
21162 // If we have nothing in the buffer, then we want to know
21163 // as soon as we *do* get something into the buffer.
21164 if (!state.ended) state.needReadable = true;
21165
21166 // If we tried to read() past the EOF, then emit end on the next tick.
21167 if (nOrig !== n && state.ended) endReadable(this);
21168 }
21169
21170 if (ret !== null) this.emit('data', ret);
21171
21172 return ret;
21173};
21174
21175function chunkInvalid(state, chunk) {
21176 var er = null;
21177 if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
21178 er = new TypeError('Invalid non-string/buffer chunk');
21179 }
21180 return er;
21181}
21182
21183function onEofChunk(stream, state) {
21184 if (state.ended) return;
21185 if (state.decoder) {
21186 var chunk = state.decoder.end();
21187 if (chunk && chunk.length) {
21188 state.buffer.push(chunk);
21189 state.length += state.objectMode ? 1 : chunk.length;
21190 }
21191 }
21192 state.ended = true;
21193
21194 // emit 'readable' now to make sure it gets picked up.
21195 emitReadable(stream);
21196}
21197
21198// Don't emit readable right away in sync mode, because this can trigger
21199// another read() call => stack overflow. This way, it might trigger
21200// a nextTick recursion warning, but that's not so bad.
21201function emitReadable(stream) {
21202 var state = stream._readableState;
21203 state.needReadable = false;
21204 if (!state.emittedReadable) {
21205 debug('emitReadable', state.flowing);
21206 state.emittedReadable = true;
21207 if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
21208 }
21209}
21210
21211function emitReadable_(stream) {
21212 debug('emit readable');
21213 stream.emit('readable');
21214 flow(stream);
21215}
21216
21217// at this point, the user has presumably seen the 'readable' event,
21218// and called read() to consume some data. that may have triggered
21219// in turn another _read(n) call, in which case reading = true if
21220// it's in progress.
21221// However, if we're not ended, or reading, and the length < hwm,
21222// then go ahead and try to read some more preemptively.
21223function maybeReadMore(stream, state) {
21224 if (!state.readingMore) {
21225 state.readingMore = true;
21226 processNextTick(maybeReadMore_, stream, state);
21227 }
21228}
21229
21230function maybeReadMore_(stream, state) {
21231 var len = state.length;
21232 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
21233 debug('maybeReadMore read 0');
21234 stream.read(0);
21235 if (len === state.length)
21236 // didn't get any data, stop spinning.
21237 break;else len = state.length;
21238 }
21239 state.readingMore = false;
21240}
21241
21242// abstract method. to be overridden in specific implementation classes.
21243// call cb(er, data) where data is <= n in length.
21244// for virtual (non-string, non-buffer) streams, "length" is somewhat
21245// arbitrary, and perhaps not very meaningful.
21246Readable.prototype._read = function (n) {
21247 this.emit('error', new Error('_read() is not implemented'));
21248};
21249
21250Readable.prototype.pipe = function (dest, pipeOpts) {
21251 var src = this;
21252 var state = this._readableState;
21253
21254 switch (state.pipesCount) {
21255 case 0:
21256 state.pipes = dest;
21257 break;
21258 case 1:
21259 state.pipes = [state.pipes, dest];
21260 break;
21261 default:
21262 state.pipes.push(dest);
21263 break;
21264 }
21265 state.pipesCount += 1;
21266 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
21267
21268 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
21269
21270 var endFn = doEnd ? onend : cleanup;
21271 if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
21272
21273 dest.on('unpipe', onunpipe);
21274 function onunpipe(readable) {
21275 debug('onunpipe');
21276 if (readable === src) {
21277 cleanup();
21278 }
21279 }
21280
21281 function onend() {
21282 debug('onend');
21283 dest.end();
21284 }
21285
21286 // when the dest drains, it reduces the awaitDrain counter
21287 // on the source. This would be more elegant with a .once()
21288 // handler in flow(), but adding and removing repeatedly is
21289 // too slow.
21290 var ondrain = pipeOnDrain(src);
21291 dest.on('drain', ondrain);
21292
21293 var cleanedUp = false;
21294 function cleanup() {
21295 debug('cleanup');
21296 // cleanup event handlers once the pipe is broken
21297 dest.removeListener('close', onclose);
21298 dest.removeListener('finish', onfinish);
21299 dest.removeListener('drain', ondrain);
21300 dest.removeListener('error', onerror);
21301 dest.removeListener('unpipe', onunpipe);
21302 src.removeListener('end', onend);
21303 src.removeListener('end', cleanup);
21304 src.removeListener('data', ondata);
21305
21306 cleanedUp = true;
21307
21308 // if the reader is waiting for a drain event from this
21309 // specific writer, then it would cause it to never start
21310 // flowing again.
21311 // So, if this is awaiting a drain, then we just call it now.
21312 // If we don't know, then assume that we are waiting for one.
21313 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
21314 }
21315
21316 // If the user pushes more data while we're writing to dest then we'll end up
21317 // in ondata again. However, we only want to increase awaitDrain once because
21318 // dest will only emit one 'drain' event for the multiple writes.
21319 // => Introduce a guard on increasing awaitDrain.
21320 var increasedAwaitDrain = false;
21321 src.on('data', ondata);
21322 function ondata(chunk) {
21323 debug('ondata');
21324 increasedAwaitDrain = false;
21325 var ret = dest.write(chunk);
21326 if (false === ret && !increasedAwaitDrain) {
21327 // If the user unpiped during `dest.write()`, it is possible
21328 // to get stuck in a permanently paused state if that write
21329 // also returned false.
21330 // => Check whether `dest` is still a piping destination.
21331 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
21332 debug('false write response, pause', src._readableState.awaitDrain);
21333 src._readableState.awaitDrain++;
21334 increasedAwaitDrain = true;
21335 }
21336 src.pause();
21337 }
21338 }
21339
21340 // if the dest has an error, then stop piping into it.
21341 // however, don't suppress the throwing behavior for this.
21342 function onerror(er) {
21343 debug('onerror', er);
21344 unpipe();
21345 dest.removeListener('error', onerror);
21346 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
21347 }
21348
21349 // Make sure our error handler is attached before userland ones.
21350 prependListener(dest, 'error', onerror);
21351
21352 // Both close and finish should trigger unpipe, but only once.
21353 function onclose() {
21354 dest.removeListener('finish', onfinish);
21355 unpipe();
21356 }
21357 dest.once('close', onclose);
21358 function onfinish() {
21359 debug('onfinish');
21360 dest.removeListener('close', onclose);
21361 unpipe();
21362 }
21363 dest.once('finish', onfinish);
21364
21365 function unpipe() {
21366 debug('unpipe');
21367 src.unpipe(dest);
21368 }
21369
21370 // tell the dest that it's being piped to
21371 dest.emit('pipe', src);
21372
21373 // start the flow if it hasn't been started already.
21374 if (!state.flowing) {
21375 debug('pipe resume');
21376 src.resume();
21377 }
21378
21379 return dest;
21380};
21381
21382function pipeOnDrain(src) {
21383 return function () {
21384 var state = src._readableState;
21385 debug('pipeOnDrain', state.awaitDrain);
21386 if (state.awaitDrain) state.awaitDrain--;
21387 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
21388 state.flowing = true;
21389 flow(src);
21390 }
21391 };
21392}
21393
21394Readable.prototype.unpipe = function (dest) {
21395 var state = this._readableState;
21396
21397 // if we're not piping anywhere, then do nothing.
21398 if (state.pipesCount === 0) return this;
21399
21400 // just one destination. most common case.
21401 if (state.pipesCount === 1) {
21402 // passed in one, but it's not the right one.
21403 if (dest && dest !== state.pipes) return this;
21404
21405 if (!dest) dest = state.pipes;
21406
21407 // got a match.
21408 state.pipes = null;
21409 state.pipesCount = 0;
21410 state.flowing = false;
21411 if (dest) dest.emit('unpipe', this);
21412 return this;
21413 }
21414
21415 // slow case. multiple pipe destinations.
21416
21417 if (!dest) {
21418 // remove all.
21419 var dests = state.pipes;
21420 var len = state.pipesCount;
21421 state.pipes = null;
21422 state.pipesCount = 0;
21423 state.flowing = false;
21424
21425 for (var i = 0; i < len; i++) {
21426 dests[i].emit('unpipe', this);
21427 }return this;
21428 }
21429
21430 // try to find the right one.
21431 var index = indexOf(state.pipes, dest);
21432 if (index === -1) return this;
21433
21434 state.pipes.splice(index, 1);
21435 state.pipesCount -= 1;
21436 if (state.pipesCount === 1) state.pipes = state.pipes[0];
21437
21438 dest.emit('unpipe', this);
21439
21440 return this;
21441};
21442
21443// set up data events if they are asked for
21444// Ensure readable listeners eventually get something
21445Readable.prototype.on = function (ev, fn) {
21446 var res = Stream.prototype.on.call(this, ev, fn);
21447
21448 if (ev === 'data') {
21449 // Start flowing on next tick if stream isn't explicitly paused
21450 if (this._readableState.flowing !== false) this.resume();
21451 } else if (ev === 'readable') {
21452 var state = this._readableState;
21453 if (!state.endEmitted && !state.readableListening) {
21454 state.readableListening = state.needReadable = true;
21455 state.emittedReadable = false;
21456 if (!state.reading) {
21457 processNextTick(nReadingNextTick, this);
21458 } else if (state.length) {
21459 emitReadable(this, state);
21460 }
21461 }
21462 }
21463
21464 return res;
21465};
21466Readable.prototype.addListener = Readable.prototype.on;
21467
21468function nReadingNextTick(self) {
21469 debug('readable nexttick read 0');
21470 self.read(0);
21471}
21472
21473// pause() and resume() are remnants of the legacy readable stream API
21474// If the user uses them, then switch into old mode.
21475Readable.prototype.resume = function () {
21476 var state = this._readableState;
21477 if (!state.flowing) {
21478 debug('resume');
21479 state.flowing = true;
21480 resume(this, state);
21481 }
21482 return this;
21483};
21484
21485function resume(stream, state) {
21486 if (!state.resumeScheduled) {
21487 state.resumeScheduled = true;
21488 processNextTick(resume_, stream, state);
21489 }
21490}
21491
21492function resume_(stream, state) {
21493 if (!state.reading) {
21494 debug('resume read 0');
21495 stream.read(0);
21496 }
21497
21498 state.resumeScheduled = false;
21499 state.awaitDrain = 0;
21500 stream.emit('resume');
21501 flow(stream);
21502 if (state.flowing && !state.reading) stream.read(0);
21503}
21504
21505Readable.prototype.pause = function () {
21506 debug('call pause flowing=%j', this._readableState.flowing);
21507 if (false !== this._readableState.flowing) {
21508 debug('pause');
21509 this._readableState.flowing = false;
21510 this.emit('pause');
21511 }
21512 return this;
21513};
21514
21515function flow(stream) {
21516 var state = stream._readableState;
21517 debug('flow', state.flowing);
21518 while (state.flowing && stream.read() !== null) {}
21519}
21520
21521// wrap an old-style stream as the async data source.
21522// This is *not* part of the readable stream interface.
21523// It is an ugly unfortunate mess of history.
21524Readable.prototype.wrap = function (stream) {
21525 var state = this._readableState;
21526 var paused = false;
21527
21528 var self = this;
21529 stream.on('end', function () {
21530 debug('wrapped end');
21531 if (state.decoder && !state.ended) {
21532 var chunk = state.decoder.end();
21533 if (chunk && chunk.length) self.push(chunk);
21534 }
21535
21536 self.push(null);
21537 });
21538
21539 stream.on('data', function (chunk) {
21540 debug('wrapped data');
21541 if (state.decoder) chunk = state.decoder.write(chunk);
21542
21543 // don't skip over falsy values in objectMode
21544 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
21545
21546 var ret = self.push(chunk);
21547 if (!ret) {
21548 paused = true;
21549 stream.pause();
21550 }
21551 });
21552
21553 // proxy all the other methods.
21554 // important when wrapping filters and duplexes.
21555 for (var i in stream) {
21556 if (this[i] === undefined && typeof stream[i] === 'function') {
21557 this[i] = function (method) {
21558 return function () {
21559 return stream[method].apply(stream, arguments);
21560 };
21561 }(i);
21562 }
21563 }
21564
21565 // proxy certain important events.
21566 var events = ['error', 'close', 'destroy', 'pause', 'resume'];
21567 forEach(events, function (ev) {
21568 stream.on(ev, self.emit.bind(self, ev));
21569 });
21570
21571 // when we try to consume some more bytes, simply unpause the
21572 // underlying stream.
21573 self._read = function (n) {
21574 debug('wrapped _read', n);
21575 if (paused) {
21576 paused = false;
21577 stream.resume();
21578 }
21579 };
21580
21581 return self;
21582};
21583
21584// exposed for testing purposes only.
21585Readable._fromList = fromList;
21586
21587// Pluck off n bytes from an array of buffers.
21588// Length is the combined lengths of all the buffers in the list.
21589// This function is designed to be inlinable, so please take care when making
21590// changes to the function body.
21591function fromList(n, state) {
21592 // nothing buffered
21593 if (state.length === 0) return null;
21594
21595 var ret;
21596 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
21597 // read it all, truncate the list
21598 if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
21599 state.buffer.clear();
21600 } else {
21601 // read part of list
21602 ret = fromListPartial(n, state.buffer, state.decoder);
21603 }
21604
21605 return ret;
21606}
21607
21608// Extracts only enough buffered data to satisfy the amount requested.
21609// This function is designed to be inlinable, so please take care when making
21610// changes to the function body.
21611function fromListPartial(n, list, hasStrings) {
21612 var ret;
21613 if (n < list.head.data.length) {
21614 // slice is the same for buffers and strings
21615 ret = list.head.data.slice(0, n);
21616 list.head.data = list.head.data.slice(n);
21617 } else if (n === list.head.data.length) {
21618 // first chunk is a perfect match
21619 ret = list.shift();
21620 } else {
21621 // result spans more than one buffer
21622 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
21623 }
21624 return ret;
21625}
21626
21627// Copies a specified amount of characters from the list of buffered data
21628// chunks.
21629// This function is designed to be inlinable, so please take care when making
21630// changes to the function body.
21631function copyFromBufferString(n, list) {
21632 var p = list.head;
21633 var c = 1;
21634 var ret = p.data;
21635 n -= ret.length;
21636 while (p = p.next) {
21637 var str = p.data;
21638 var nb = n > str.length ? str.length : n;
21639 if (nb === str.length) ret += str;else ret += str.slice(0, n);
21640 n -= nb;
21641 if (n === 0) {
21642 if (nb === str.length) {
21643 ++c;
21644 if (p.next) list.head = p.next;else list.head = list.tail = null;
21645 } else {
21646 list.head = p;
21647 p.data = str.slice(nb);
21648 }
21649 break;
21650 }
21651 ++c;
21652 }
21653 list.length -= c;
21654 return ret;
21655}
21656
21657// Copies a specified amount of bytes from the list of buffered data chunks.
21658// This function is designed to be inlinable, so please take care when making
21659// changes to the function body.
21660function copyFromBuffer(n, list) {
21661 var ret = bufferShim.allocUnsafe(n);
21662 var p = list.head;
21663 var c = 1;
21664 p.data.copy(ret);
21665 n -= p.data.length;
21666 while (p = p.next) {
21667 var buf = p.data;
21668 var nb = n > buf.length ? buf.length : n;
21669 buf.copy(ret, ret.length - n, 0, nb);
21670 n -= nb;
21671 if (n === 0) {
21672 if (nb === buf.length) {
21673 ++c;
21674 if (p.next) list.head = p.next;else list.head = list.tail = null;
21675 } else {
21676 list.head = p;
21677 p.data = buf.slice(nb);
21678 }
21679 break;
21680 }
21681 ++c;
21682 }
21683 list.length -= c;
21684 return ret;
21685}
21686
21687function endReadable(stream) {
21688 var state = stream._readableState;
21689
21690 // If we get here before consuming all the bytes, then that is a
21691 // bug in node. Should never happen.
21692 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
21693
21694 if (!state.endEmitted) {
21695 state.ended = true;
21696 processNextTick(endReadableNT, state, stream);
21697 }
21698}
21699
21700function endReadableNT(state, stream) {
21701 // Check that we didn't get one last unshift.
21702 if (!state.endEmitted && state.length === 0) {
21703 state.endEmitted = true;
21704 stream.readable = false;
21705 stream.emit('end');
21706 }
21707}
21708
21709function forEach(xs, f) {
21710 for (var i = 0, l = xs.length; i < l; i++) {
21711 f(xs[i], i);
21712 }
21713}
21714
21715function indexOf(xs, x) {
21716 for (var i = 0, l = xs.length; i < l; i++) {
21717 if (xs[i] === x) return i;
21718 }
21719 return -1;
21720}
21721}).call(this,require('_process'))
21722},{"./_stream_duplex":15,"./internal/streams/BufferList":20,"_process":13,"buffer":5,"buffer-shims":4,"core-util-is":6,"events":7,"inherits":9,"isarray":11,"process-nextick-args":12,"string_decoder/":26,"util":3}],18:[function(require,module,exports){
21723// a transform stream is a readable/writable stream where you do
21724// something with the data. Sometimes it's called a "filter",
21725// but that's not a great name for it, since that implies a thing where
21726// some bits pass through, and others are simply ignored. (That would
21727// be a valid example of a transform, of course.)
21728//
21729// While the output is causally related to the input, it's not a
21730// necessarily symmetric or synchronous transformation. For example,
21731// a zlib stream might take multiple plain-text writes(), and then
21732// emit a single compressed chunk some time in the future.
21733//
21734// Here's how this works:
21735//
21736// The Transform stream has all the aspects of the readable and writable
21737// stream classes. When you write(chunk), that calls _write(chunk,cb)
21738// internally, and returns false if there's a lot of pending writes
21739// buffered up. When you call read(), that calls _read(n) until
21740// there's enough pending readable data buffered up.
21741//
21742// In a transform stream, the written data is placed in a buffer. When
21743// _read(n) is called, it transforms the queued up data, calling the
21744// buffered _write cb's as it consumes chunks. If consuming a single
21745// written chunk would result in multiple output chunks, then the first
21746// outputted bit calls the readcb, and subsequent chunks just go into
21747// the read buffer, and will cause it to emit 'readable' if necessary.
21748//
21749// This way, back-pressure is actually determined by the reading side,
21750// since _read has to be called to start processing a new chunk. However,
21751// a pathological inflate type of transform can cause excessive buffering
21752// here. For example, imagine a stream where every byte of input is
21753// interpreted as an integer from 0-255, and then results in that many
21754// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
21755// 1kb of data being output. In this case, you could write a very small
21756// amount of input, and end up with a very large amount of output. In
21757// such a pathological inflating mechanism, there'd be no way to tell
21758// the system to stop doing the transform. A single 4MB write could
21759// cause the system to run out of memory.
21760//
21761// However, even in such a pathological case, only a single written chunk
21762// would be consumed, and then the rest would wait (un-transformed) until
21763// the results of the previous transformed chunk were consumed.
21764
21765'use strict';
21766
21767module.exports = Transform;
21768
21769var Duplex = require('./_stream_duplex');
21770
21771/*<replacement>*/
21772var util = require('core-util-is');
21773util.inherits = require('inherits');
21774/*</replacement>*/
21775
21776util.inherits(Transform, Duplex);
21777
21778function TransformState(stream) {
21779 this.afterTransform = function (er, data) {
21780 return afterTransform(stream, er, data);
21781 };
21782
21783 this.needTransform = false;
21784 this.transforming = false;
21785 this.writecb = null;
21786 this.writechunk = null;
21787 this.writeencoding = null;
21788}
21789
21790function afterTransform(stream, er, data) {
21791 var ts = stream._transformState;
21792 ts.transforming = false;
21793
21794 var cb = ts.writecb;
21795
21796 if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
21797
21798 ts.writechunk = null;
21799 ts.writecb = null;
21800
21801 if (data !== null && data !== undefined) stream.push(data);
21802
21803 cb(er);
21804
21805 var rs = stream._readableState;
21806 rs.reading = false;
21807 if (rs.needReadable || rs.length < rs.highWaterMark) {
21808 stream._read(rs.highWaterMark);
21809 }
21810}
21811
21812function Transform(options) {
21813 if (!(this instanceof Transform)) return new Transform(options);
21814
21815 Duplex.call(this, options);
21816
21817 this._transformState = new TransformState(this);
21818
21819 var stream = this;
21820
21821 // start out asking for a readable event once data is transformed.
21822 this._readableState.needReadable = true;
21823
21824 // we have implemented the _read method, and done the other things
21825 // that Readable wants before the first _read call, so unset the
21826 // sync guard flag.
21827 this._readableState.sync = false;
21828
21829 if (options) {
21830 if (typeof options.transform === 'function') this._transform = options.transform;
21831
21832 if (typeof options.flush === 'function') this._flush = options.flush;
21833 }
21834
21835 // When the writable side finishes, then flush out anything remaining.
21836 this.once('prefinish', function () {
21837 if (typeof this._flush === 'function') this._flush(function (er, data) {
21838 done(stream, er, data);
21839 });else done(stream);
21840 });
21841}
21842
21843Transform.prototype.push = function (chunk, encoding) {
21844 this._transformState.needTransform = false;
21845 return Duplex.prototype.push.call(this, chunk, encoding);
21846};
21847
21848// This is the part where you do stuff!
21849// override this function in implementation classes.
21850// 'chunk' is an input chunk.
21851//
21852// Call `push(newChunk)` to pass along transformed output
21853// to the readable side. You may call 'push' zero or more times.
21854//
21855// Call `cb(err)` when you are done with this chunk. If you pass
21856// an error, then that'll put the hurt on the whole operation. If you
21857// never call cb(), then you'll never get another chunk.
21858Transform.prototype._transform = function (chunk, encoding, cb) {
21859 throw new Error('_transform() is not implemented');
21860};
21861
21862Transform.prototype._write = function (chunk, encoding, cb) {
21863 var ts = this._transformState;
21864 ts.writecb = cb;
21865 ts.writechunk = chunk;
21866 ts.writeencoding = encoding;
21867 if (!ts.transforming) {
21868 var rs = this._readableState;
21869 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
21870 }
21871};
21872
21873// Doesn't matter what the args are here.
21874// _transform does all the work.
21875// That we got here means that the readable side wants more data.
21876Transform.prototype._read = function (n) {
21877 var ts = this._transformState;
21878
21879 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
21880 ts.transforming = true;
21881 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
21882 } else {
21883 // mark that we need a transform, so that any data that comes in
21884 // will get processed, now that we've asked for it.
21885 ts.needTransform = true;
21886 }
21887};
21888
21889function done(stream, er, data) {
21890 if (er) return stream.emit('error', er);
21891
21892 if (data !== null && data !== undefined) stream.push(data);
21893
21894 // if there's nothing in the write buffer, then that means
21895 // that nothing more will ever be provided
21896 var ws = stream._writableState;
21897 var ts = stream._transformState;
21898
21899 if (ws.length) throw new Error('Calling transform done when ws.length != 0');
21900
21901 if (ts.transforming) throw new Error('Calling transform done when still transforming');
21902
21903 return stream.push(null);
21904}
21905},{"./_stream_duplex":15,"core-util-is":6,"inherits":9}],19:[function(require,module,exports){
21906(function (process){
21907// A bit simpler than readable streams.
21908// Implement an async ._write(chunk, encoding, cb), and it'll handle all
21909// the drain event emission and buffering.
21910
21911'use strict';
21912
21913module.exports = Writable;
21914
21915/*<replacement>*/
21916var processNextTick = require('process-nextick-args');
21917/*</replacement>*/
21918
21919/*<replacement>*/
21920var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
21921/*</replacement>*/
21922
21923/*<replacement>*/
21924var Duplex;
21925/*</replacement>*/
21926
21927Writable.WritableState = WritableState;
21928
21929/*<replacement>*/
21930var util = require('core-util-is');
21931util.inherits = require('inherits');
21932/*</replacement>*/
21933
21934/*<replacement>*/
21935var internalUtil = {
21936 deprecate: require('util-deprecate')
21937};
21938/*</replacement>*/
21939
21940/*<replacement>*/
21941var Stream;
21942(function () {
21943 try {
21944 Stream = require('st' + 'ream');
21945 } catch (_) {} finally {
21946 if (!Stream) Stream = require('events').EventEmitter;
21947 }
21948})();
21949/*</replacement>*/
21950
21951var Buffer = require('buffer').Buffer;
21952/*<replacement>*/
21953var bufferShim = require('buffer-shims');
21954/*</replacement>*/
21955
21956util.inherits(Writable, Stream);
21957
21958function nop() {}
21959
21960function WriteReq(chunk, encoding, cb) {
21961 this.chunk = chunk;
21962 this.encoding = encoding;
21963 this.callback = cb;
21964 this.next = null;
21965}
21966
21967function WritableState(options, stream) {
21968 Duplex = Duplex || require('./_stream_duplex');
21969
21970 options = options || {};
21971
21972 // object stream flag to indicate whether or not this stream
21973 // contains buffers or objects.
21974 this.objectMode = !!options.objectMode;
21975
21976 if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
21977
21978 // the point at which write() starts returning false
21979 // Note: 0 is a valid value, means that we always return false if
21980 // the entire buffer is not flushed immediately on write()
21981 var hwm = options.highWaterMark;
21982 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
21983 this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
21984
21985 // cast to ints.
21986 this.highWaterMark = ~ ~this.highWaterMark;
21987
21988 // drain event flag.
21989 this.needDrain = false;
21990 // at the start of calling end()
21991 this.ending = false;
21992 // when end() has been called, and returned
21993 this.ended = false;
21994 // when 'finish' is emitted
21995 this.finished = false;
21996
21997 // should we decode strings into buffers before passing to _write?
21998 // this is here so that some node-core streams can optimize string
21999 // handling at a lower level.
22000 var noDecode = options.decodeStrings === false;
22001 this.decodeStrings = !noDecode;
22002
22003 // Crypto is kind of old and crusty. Historically, its default string
22004 // encoding is 'binary' so we have to make this configurable.
22005 // Everything else in the universe uses 'utf8', though.
22006 this.defaultEncoding = options.defaultEncoding || 'utf8';
22007
22008 // not an actual buffer we keep track of, but a measurement
22009 // of how much we're waiting to get pushed to some underlying
22010 // socket or file.
22011 this.length = 0;
22012
22013 // a flag to see when we're in the middle of a write.
22014 this.writing = false;
22015
22016 // when true all writes will be buffered until .uncork() call
22017 this.corked = 0;
22018
22019 // a flag to be able to tell if the onwrite cb is called immediately,
22020 // or on a later tick. We set this to true at first, because any
22021 // actions that shouldn't happen until "later" should generally also
22022 // not happen before the first write call.
22023 this.sync = true;
22024
22025 // a flag to know if we're processing previously buffered items, which
22026 // may call the _write() callback in the same tick, so that we don't
22027 // end up in an overlapped onwrite situation.
22028 this.bufferProcessing = false;
22029
22030 // the callback that's passed to _write(chunk,cb)
22031 this.onwrite = function (er) {
22032 onwrite(stream, er);
22033 };
22034
22035 // the callback that the user supplies to write(chunk,encoding,cb)
22036 this.writecb = null;
22037
22038 // the amount that is being written when _write is called.
22039 this.writelen = 0;
22040
22041 this.bufferedRequest = null;
22042 this.lastBufferedRequest = null;
22043
22044 // number of pending user-supplied write callbacks
22045 // this must be 0 before 'finish' can be emitted
22046 this.pendingcb = 0;
22047
22048 // emit prefinish if the only thing we're waiting for is _write cbs
22049 // This is relevant for synchronous Transform streams
22050 this.prefinished = false;
22051
22052 // True if the error was already emitted and should not be thrown again
22053 this.errorEmitted = false;
22054
22055 // count buffered requests
22056 this.bufferedRequestCount = 0;
22057
22058 // allocate the first CorkedRequest, there is always
22059 // one allocated and free to use, and we maintain at most two
22060 this.corkedRequestsFree = new CorkedRequest(this);
22061}
22062
22063WritableState.prototype.getBuffer = function getBuffer() {
22064 var current = this.bufferedRequest;
22065 var out = [];
22066 while (current) {
22067 out.push(current);
22068 current = current.next;
22069 }
22070 return out;
22071};
22072
22073(function () {
22074 try {
22075 Object.defineProperty(WritableState.prototype, 'buffer', {
22076 get: internalUtil.deprecate(function () {
22077 return this.getBuffer();
22078 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
22079 });
22080 } catch (_) {}
22081})();
22082
22083// Test _writableState for inheritance to account for Duplex streams,
22084// whose prototype chain only points to Readable.
22085var realHasInstance;
22086if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
22087 realHasInstance = Function.prototype[Symbol.hasInstance];
22088 Object.defineProperty(Writable, Symbol.hasInstance, {
22089 value: function (object) {
22090 if (realHasInstance.call(this, object)) return true;
22091
22092 return object && object._writableState instanceof WritableState;
22093 }
22094 });
22095} else {
22096 realHasInstance = function (object) {
22097 return object instanceof this;
22098 };
22099}
22100
22101function Writable(options) {
22102 Duplex = Duplex || require('./_stream_duplex');
22103
22104 // Writable ctor is applied to Duplexes, too.
22105 // `realHasInstance` is necessary because using plain `instanceof`
22106 // would return false, as no `_writableState` property is attached.
22107
22108 // Trying to use the custom `instanceof` for Writable here will also break the
22109 // Node.js LazyTransform implementation, which has a non-trivial getter for
22110 // `_writableState` that would lead to infinite recursion.
22111 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
22112 return new Writable(options);
22113 }
22114
22115 this._writableState = new WritableState(options, this);
22116
22117 // legacy.
22118 this.writable = true;
22119
22120 if (options) {
22121 if (typeof options.write === 'function') this._write = options.write;
22122
22123 if (typeof options.writev === 'function') this._writev = options.writev;
22124 }
22125
22126 Stream.call(this);
22127}
22128
22129// Otherwise people can pipe Writable streams, which is just wrong.
22130Writable.prototype.pipe = function () {
22131 this.emit('error', new Error('Cannot pipe, not readable'));
22132};
22133
22134function writeAfterEnd(stream, cb) {
22135 var er = new Error('write after end');
22136 // TODO: defer error events consistently everywhere, not just the cb
22137 stream.emit('error', er);
22138 processNextTick(cb, er);
22139}
22140
22141// If we get something that is not a buffer, string, null, or undefined,
22142// and we're not in objectMode, then that's an error.
22143// Otherwise stream chunks are all considered to be of length=1, and the
22144// watermarks determine how many objects to keep in the buffer, rather than
22145// how many bytes or characters.
22146function validChunk(stream, state, chunk, cb) {
22147 var valid = true;
22148 var er = false;
22149 // Always throw error if a null is written
22150 // if we are not in object mode then throw
22151 // if it is not a buffer, string, or undefined.
22152 if (chunk === null) {
22153 er = new TypeError('May not write null values to stream');
22154 } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
22155 er = new TypeError('Invalid non-string/buffer chunk');
22156 }
22157 if (er) {
22158 stream.emit('error', er);
22159 processNextTick(cb, er);
22160 valid = false;
22161 }
22162 return valid;
22163}
22164
22165Writable.prototype.write = function (chunk, encoding, cb) {
22166 var state = this._writableState;
22167 var ret = false;
22168
22169 if (typeof encoding === 'function') {
22170 cb = encoding;
22171 encoding = null;
22172 }
22173
22174 if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
22175
22176 if (typeof cb !== 'function') cb = nop;
22177
22178 if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
22179 state.pendingcb++;
22180 ret = writeOrBuffer(this, state, chunk, encoding, cb);
22181 }
22182
22183 return ret;
22184};
22185
22186Writable.prototype.cork = function () {
22187 var state = this._writableState;
22188
22189 state.corked++;
22190};
22191
22192Writable.prototype.uncork = function () {
22193 var state = this._writableState;
22194
22195 if (state.corked) {
22196 state.corked--;
22197
22198 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
22199 }
22200};
22201
22202Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
22203 // node::ParseEncoding() requires lower case.
22204 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
22205 if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
22206 this._writableState.defaultEncoding = encoding;
22207 return this;
22208};
22209
22210function decodeChunk(state, chunk, encoding) {
22211 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
22212 chunk = bufferShim.from(chunk, encoding);
22213 }
22214 return chunk;
22215}
22216
22217// if we're already writing something, then just put this
22218// in the queue, and wait our turn. Otherwise, call _write
22219// If we return false, then we need a drain event, so set that flag.
22220function writeOrBuffer(stream, state, chunk, encoding, cb) {
22221 chunk = decodeChunk(state, chunk, encoding);
22222
22223 if (Buffer.isBuffer(chunk)) encoding = 'buffer';
22224 var len = state.objectMode ? 1 : chunk.length;
22225
22226 state.length += len;
22227
22228 var ret = state.length < state.highWaterMark;
22229 // we must ensure that previous needDrain will not be reset to false.
22230 if (!ret) state.needDrain = true;
22231
22232 if (state.writing || state.corked) {
22233 var last = state.lastBufferedRequest;
22234 state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
22235 if (last) {
22236 last.next = state.lastBufferedRequest;
22237 } else {
22238 state.bufferedRequest = state.lastBufferedRequest;
22239 }
22240 state.bufferedRequestCount += 1;
22241 } else {
22242 doWrite(stream, state, false, len, chunk, encoding, cb);
22243 }
22244
22245 return ret;
22246}
22247
22248function doWrite(stream, state, writev, len, chunk, encoding, cb) {
22249 state.writelen = len;
22250 state.writecb = cb;
22251 state.writing = true;
22252 state.sync = true;
22253 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
22254 state.sync = false;
22255}
22256
22257function onwriteError(stream, state, sync, er, cb) {
22258 --state.pendingcb;
22259 if (sync) processNextTick(cb, er);else cb(er);
22260
22261 stream._writableState.errorEmitted = true;
22262 stream.emit('error', er);
22263}
22264
22265function onwriteStateUpdate(state) {
22266 state.writing = false;
22267 state.writecb = null;
22268 state.length -= state.writelen;
22269 state.writelen = 0;
22270}
22271
22272function onwrite(stream, er) {
22273 var state = stream._writableState;
22274 var sync = state.sync;
22275 var cb = state.writecb;
22276
22277 onwriteStateUpdate(state);
22278
22279 if (er) onwriteError(stream, state, sync, er, cb);else {
22280 // Check if we're actually ready to finish, but don't emit yet
22281 var finished = needFinish(state);
22282
22283 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
22284 clearBuffer(stream, state);
22285 }
22286
22287 if (sync) {
22288 /*<replacement>*/
22289 asyncWrite(afterWrite, stream, state, finished, cb);
22290 /*</replacement>*/
22291 } else {
22292 afterWrite(stream, state, finished, cb);
22293 }
22294 }
22295}
22296
22297function afterWrite(stream, state, finished, cb) {
22298 if (!finished) onwriteDrain(stream, state);
22299 state.pendingcb--;
22300 cb();
22301 finishMaybe(stream, state);
22302}
22303
22304// Must force callback to be called on nextTick, so that we don't
22305// emit 'drain' before the write() consumer gets the 'false' return
22306// value, and has a chance to attach a 'drain' listener.
22307function onwriteDrain(stream, state) {
22308 if (state.length === 0 && state.needDrain) {
22309 state.needDrain = false;
22310 stream.emit('drain');
22311 }
22312}
22313
22314// if there's something in the buffer waiting, then process it
22315function clearBuffer(stream, state) {
22316 state.bufferProcessing = true;
22317 var entry = state.bufferedRequest;
22318
22319 if (stream._writev && entry && entry.next) {
22320 // Fast case, write everything using _writev()
22321 var l = state.bufferedRequestCount;
22322 var buffer = new Array(l);
22323 var holder = state.corkedRequestsFree;
22324 holder.entry = entry;
22325
22326 var count = 0;
22327 while (entry) {
22328 buffer[count] = entry;
22329 entry = entry.next;
22330 count += 1;
22331 }
22332
22333 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
22334
22335 // doWrite is almost always async, defer these to save a bit of time
22336 // as the hot path ends with doWrite
22337 state.pendingcb++;
22338 state.lastBufferedRequest = null;
22339 if (holder.next) {
22340 state.corkedRequestsFree = holder.next;
22341 holder.next = null;
22342 } else {
22343 state.corkedRequestsFree = new CorkedRequest(state);
22344 }
22345 } else {
22346 // Slow case, write chunks one-by-one
22347 while (entry) {
22348 var chunk = entry.chunk;
22349 var encoding = entry.encoding;
22350 var cb = entry.callback;
22351 var len = state.objectMode ? 1 : chunk.length;
22352
22353 doWrite(stream, state, false, len, chunk, encoding, cb);
22354 entry = entry.next;
22355 // if we didn't call the onwrite immediately, then
22356 // it means that we need to wait until it does.
22357 // also, that means that the chunk and cb are currently
22358 // being processed, so move the buffer counter past them.
22359 if (state.writing) {
22360 break;
22361 }
22362 }
22363
22364 if (entry === null) state.lastBufferedRequest = null;
22365 }
22366
22367 state.bufferedRequestCount = 0;
22368 state.bufferedRequest = entry;
22369 state.bufferProcessing = false;
22370}
22371
22372Writable.prototype._write = function (chunk, encoding, cb) {
22373 cb(new Error('_write() is not implemented'));
22374};
22375
22376Writable.prototype._writev = null;
22377
22378Writable.prototype.end = function (chunk, encoding, cb) {
22379 var state = this._writableState;
22380
22381 if (typeof chunk === 'function') {
22382 cb = chunk;
22383 chunk = null;
22384 encoding = null;
22385 } else if (typeof encoding === 'function') {
22386 cb = encoding;
22387 encoding = null;
22388 }
22389
22390 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
22391
22392 // .end() fully uncorks
22393 if (state.corked) {
22394 state.corked = 1;
22395 this.uncork();
22396 }
22397
22398 // ignore unnecessary end() calls.
22399 if (!state.ending && !state.finished) endWritable(this, state, cb);
22400};
22401
22402function needFinish(state) {
22403 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
22404}
22405
22406function prefinish(stream, state) {
22407 if (!state.prefinished) {
22408 state.prefinished = true;
22409 stream.emit('prefinish');
22410 }
22411}
22412
22413function finishMaybe(stream, state) {
22414 var need = needFinish(state);
22415 if (need) {
22416 if (state.pendingcb === 0) {
22417 prefinish(stream, state);
22418 state.finished = true;
22419 stream.emit('finish');
22420 } else {
22421 prefinish(stream, state);
22422 }
22423 }
22424 return need;
22425}
22426
22427function endWritable(stream, state, cb) {
22428 state.ending = true;
22429 finishMaybe(stream, state);
22430 if (cb) {
22431 if (state.finished) processNextTick(cb);else stream.once('finish', cb);
22432 }
22433 state.ended = true;
22434 stream.writable = false;
22435}
22436
22437// It seems a linked list but it is not
22438// there will be only 2 of these for each stream
22439function CorkedRequest(state) {
22440 var _this = this;
22441
22442 this.next = null;
22443 this.entry = null;
22444
22445 this.finish = function (err) {
22446 var entry = _this.entry;
22447 _this.entry = null;
22448 while (entry) {
22449 var cb = entry.callback;
22450 state.pendingcb--;
22451 cb(err);
22452 entry = entry.next;
22453 }
22454 if (state.corkedRequestsFree) {
22455 state.corkedRequestsFree.next = _this;
22456 } else {
22457 state.corkedRequestsFree = _this;
22458 }
22459 };
22460}
22461}).call(this,require('_process'))
22462},{"./_stream_duplex":15,"_process":13,"buffer":5,"buffer-shims":4,"core-util-is":6,"events":7,"inherits":9,"process-nextick-args":12,"util-deprecate":27}],20:[function(require,module,exports){
22463'use strict';
22464
22465var Buffer = require('buffer').Buffer;
22466/*<replacement>*/
22467var bufferShim = require('buffer-shims');
22468/*</replacement>*/
22469
22470module.exports = BufferList;
22471
22472function BufferList() {
22473 this.head = null;
22474 this.tail = null;
22475 this.length = 0;
22476}
22477
22478BufferList.prototype.push = function (v) {
22479 var entry = { data: v, next: null };
22480 if (this.length > 0) this.tail.next = entry;else this.head = entry;
22481 this.tail = entry;
22482 ++this.length;
22483};
22484
22485BufferList.prototype.unshift = function (v) {
22486 var entry = { data: v, next: this.head };
22487 if (this.length === 0) this.tail = entry;
22488 this.head = entry;
22489 ++this.length;
22490};
22491
22492BufferList.prototype.shift = function () {
22493 if (this.length === 0) return;
22494 var ret = this.head.data;
22495 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
22496 --this.length;
22497 return ret;
22498};
22499
22500BufferList.prototype.clear = function () {
22501 this.head = this.tail = null;
22502 this.length = 0;
22503};
22504
22505BufferList.prototype.join = function (s) {
22506 if (this.length === 0) return '';
22507 var p = this.head;
22508 var ret = '' + p.data;
22509 while (p = p.next) {
22510 ret += s + p.data;
22511 }return ret;
22512};
22513
22514BufferList.prototype.concat = function (n) {
22515 if (this.length === 0) return bufferShim.alloc(0);
22516 if (this.length === 1) return this.head.data;
22517 var ret = bufferShim.allocUnsafe(n >>> 0);
22518 var p = this.head;
22519 var i = 0;
22520 while (p) {
22521 p.data.copy(ret, i);
22522 i += p.data.length;
22523 p = p.next;
22524 }
22525 return ret;
22526};
22527},{"buffer":5,"buffer-shims":4}],21:[function(require,module,exports){
22528module.exports = require("./lib/_stream_passthrough.js")
22529
22530},{"./lib/_stream_passthrough.js":16}],22:[function(require,module,exports){
22531(function (process){
22532var Stream = (function (){
22533 try {
22534 return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify
22535 } catch(_){}
22536}());
22537exports = module.exports = require('./lib/_stream_readable.js');
22538exports.Stream = Stream || exports;
22539exports.Readable = exports;
22540exports.Writable = require('./lib/_stream_writable.js');
22541exports.Duplex = require('./lib/_stream_duplex.js');
22542exports.Transform = require('./lib/_stream_transform.js');
22543exports.PassThrough = require('./lib/_stream_passthrough.js');
22544
22545if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) {
22546 module.exports = Stream;
22547}
22548
22549}).call(this,require('_process'))
22550},{"./lib/_stream_duplex.js":15,"./lib/_stream_passthrough.js":16,"./lib/_stream_readable.js":17,"./lib/_stream_transform.js":18,"./lib/_stream_writable.js":19,"_process":13}],23:[function(require,module,exports){
22551module.exports = require("./lib/_stream_transform.js")
22552
22553},{"./lib/_stream_transform.js":18}],24:[function(require,module,exports){
22554module.exports = require("./lib/_stream_writable.js")
22555
22556},{"./lib/_stream_writable.js":19}],25:[function(require,module,exports){
22557// Copyright Joyent, Inc. and other Node contributors.
22558//
22559// Permission is hereby granted, free of charge, to any person obtaining a
22560// copy of this software and associated documentation files (the
22561// "Software"), to deal in the Software without restriction, including
22562// without limitation the rights to use, copy, modify, merge, publish,
22563// distribute, sublicense, and/or sell copies of the Software, and to permit
22564// persons to whom the Software is furnished to do so, subject to the
22565// following conditions:
22566//
22567// The above copyright notice and this permission notice shall be included
22568// in all copies or substantial portions of the Software.
22569//
22570// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22571// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22572// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
22573// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22574// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22575// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22576// USE OR OTHER DEALINGS IN THE SOFTWARE.
22577
22578module.exports = Stream;
22579
22580var EE = require('events').EventEmitter;
22581var inherits = require('inherits');
22582
22583inherits(Stream, EE);
22584Stream.Readable = require('readable-stream/readable.js');
22585Stream.Writable = require('readable-stream/writable.js');
22586Stream.Duplex = require('readable-stream/duplex.js');
22587Stream.Transform = require('readable-stream/transform.js');
22588Stream.PassThrough = require('readable-stream/passthrough.js');
22589
22590// Backwards-compat with node 0.4.x
22591Stream.Stream = Stream;
22592
22593
22594
22595// old-style streams. Note that the pipe method (the only relevant
22596// part of this class) is overridden in the Readable class.
22597
22598function Stream() {
22599 EE.call(this);
22600}
22601
22602Stream.prototype.pipe = function(dest, options) {
22603 var source = this;
22604
22605 function ondata(chunk) {
22606 if (dest.writable) {
22607 if (false === dest.write(chunk) && source.pause) {
22608 source.pause();
22609 }
22610 }
22611 }
22612
22613 source.on('data', ondata);
22614
22615 function ondrain() {
22616 if (source.readable && source.resume) {
22617 source.resume();
22618 }
22619 }
22620
22621 dest.on('drain', ondrain);
22622
22623 // If the 'end' option is not supplied, dest.end() will be called when
22624 // source gets the 'end' or 'close' events. Only dest.end() once.
22625 if (!dest._isStdio && (!options || options.end !== false)) {
22626 source.on('end', onend);
22627 source.on('close', onclose);
22628 }
22629
22630 var didOnEnd = false;
22631 function onend() {
22632 if (didOnEnd) return;
22633 didOnEnd = true;
22634
22635 dest.end();
22636 }
22637
22638
22639 function onclose() {
22640 if (didOnEnd) return;
22641 didOnEnd = true;
22642
22643 if (typeof dest.destroy === 'function') dest.destroy();
22644 }
22645
22646 // don't leave dangling pipes when there are errors.
22647 function onerror(er) {
22648 cleanup();
22649 if (EE.listenerCount(this, 'error') === 0) {
22650 throw er; // Unhandled stream error in pipe.
22651 }
22652 }
22653
22654 source.on('error', onerror);
22655 dest.on('error', onerror);
22656
22657 // remove all the event listeners that were added.
22658 function cleanup() {
22659 source.removeListener('data', ondata);
22660 dest.removeListener('drain', ondrain);
22661
22662 source.removeListener('end', onend);
22663 source.removeListener('close', onclose);
22664
22665 source.removeListener('error', onerror);
22666 dest.removeListener('error', onerror);
22667
22668 source.removeListener('end', cleanup);
22669 source.removeListener('close', cleanup);
22670
22671 dest.removeListener('close', cleanup);
22672 }
22673
22674 source.on('end', cleanup);
22675 source.on('close', cleanup);
22676
22677 dest.on('close', cleanup);
22678
22679 dest.emit('pipe', source);
22680
22681 // Allow for unix-like usage: A.pipe(B).pipe(C)
22682 return dest;
22683};
22684
22685},{"events":7,"inherits":9,"readable-stream/duplex.js":14,"readable-stream/passthrough.js":21,"readable-stream/readable.js":22,"readable-stream/transform.js":23,"readable-stream/writable.js":24}],26:[function(require,module,exports){
22686// Copyright Joyent, Inc. and other Node contributors.
22687//
22688// Permission is hereby granted, free of charge, to any person obtaining a
22689// copy of this software and associated documentation files (the
22690// "Software"), to deal in the Software without restriction, including
22691// without limitation the rights to use, copy, modify, merge, publish,
22692// distribute, sublicense, and/or sell copies of the Software, and to permit
22693// persons to whom the Software is furnished to do so, subject to the
22694// following conditions:
22695//
22696// The above copyright notice and this permission notice shall be included
22697// in all copies or substantial portions of the Software.
22698//
22699// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22700// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22701// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
22702// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22703// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22704// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22705// USE OR OTHER DEALINGS IN THE SOFTWARE.
22706
22707var Buffer = require('buffer').Buffer;
22708
22709var isBufferEncoding = Buffer.isEncoding
22710 || function(encoding) {
22711 switch (encoding && encoding.toLowerCase()) {
22712 case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
22713 default: return false;
22714 }
22715 }
22716
22717
22718function assertEncoding(encoding) {
22719 if (encoding && !isBufferEncoding(encoding)) {
22720 throw new Error('Unknown encoding: ' + encoding);
22721 }
22722}
22723
22724// StringDecoder provides an interface for efficiently splitting a series of
22725// buffers into a series of JS strings without breaking apart multi-byte
22726// characters. CESU-8 is handled as part of the UTF-8 encoding.
22727//
22728// @TODO Handling all encodings inside a single object makes it very difficult
22729// to reason about this code, so it should be split up in the future.
22730// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
22731// points as used by CESU-8.
22732var StringDecoder = exports.StringDecoder = function(encoding) {
22733 this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
22734 assertEncoding(encoding);
22735 switch (this.encoding) {
22736 case 'utf8':
22737 // CESU-8 represents each of Surrogate Pair by 3-bytes
22738 this.surrogateSize = 3;
22739 break;
22740 case 'ucs2':
22741 case 'utf16le':
22742 // UTF-16 represents each of Surrogate Pair by 2-bytes
22743 this.surrogateSize = 2;
22744 this.detectIncompleteChar = utf16DetectIncompleteChar;
22745 break;
22746 case 'base64':
22747 // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
22748 this.surrogateSize = 3;
22749 this.detectIncompleteChar = base64DetectIncompleteChar;
22750 break;
22751 default:
22752 this.write = passThroughWrite;
22753 return;
22754 }
22755
22756 // Enough space to store all bytes of a single character. UTF-8 needs 4
22757 // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
22758 this.charBuffer = new Buffer(6);
22759 // Number of bytes received for the current incomplete multi-byte character.
22760 this.charReceived = 0;
22761 // Number of bytes expected for the current incomplete multi-byte character.
22762 this.charLength = 0;
22763};
22764
22765
22766// write decodes the given buffer and returns it as JS string that is
22767// guaranteed to not contain any partial multi-byte characters. Any partial
22768// character found at the end of the buffer is buffered up, and will be
22769// returned when calling write again with the remaining bytes.
22770//
22771// Note: Converting a Buffer containing an orphan surrogate to a String
22772// currently works, but converting a String to a Buffer (via `new Buffer`, or
22773// Buffer#write) will replace incomplete surrogates with the unicode
22774// replacement character. See https://codereview.chromium.org/121173009/ .
22775StringDecoder.prototype.write = function(buffer) {
22776 var charStr = '';
22777 // if our last write ended with an incomplete multibyte character
22778 while (this.charLength) {
22779 // determine how many remaining bytes this buffer has to offer for this char
22780 var available = (buffer.length >= this.charLength - this.charReceived) ?
22781 this.charLength - this.charReceived :
22782 buffer.length;
22783
22784 // add the new bytes to the char buffer
22785 buffer.copy(this.charBuffer, this.charReceived, 0, available);
22786 this.charReceived += available;
22787
22788 if (this.charReceived < this.charLength) {
22789 // still not enough chars in this buffer? wait for more ...
22790 return '';
22791 }
22792
22793 // remove bytes belonging to the current character from the buffer
22794 buffer = buffer.slice(available, buffer.length);
22795
22796 // get the character that was split
22797 charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
22798
22799 // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
22800 var charCode = charStr.charCodeAt(charStr.length - 1);
22801 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
22802 this.charLength += this.surrogateSize;
22803 charStr = '';
22804 continue;
22805 }
22806 this.charReceived = this.charLength = 0;
22807
22808 // if there are no more bytes in this buffer, just emit our char
22809 if (buffer.length === 0) {
22810 return charStr;
22811 }
22812 break;
22813 }
22814
22815 // determine and set charLength / charReceived
22816 this.detectIncompleteChar(buffer);
22817
22818 var end = buffer.length;
22819 if (this.charLength) {
22820 // buffer the incomplete character bytes we got
22821 buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
22822 end -= this.charReceived;
22823 }
22824
22825 charStr += buffer.toString(this.encoding, 0, end);
22826
22827 var end = charStr.length - 1;
22828 var charCode = charStr.charCodeAt(end);
22829 // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
22830 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
22831 var size = this.surrogateSize;
22832 this.charLength += size;
22833 this.charReceived += size;
22834 this.charBuffer.copy(this.charBuffer, size, 0, size);
22835 buffer.copy(this.charBuffer, 0, 0, size);
22836 return charStr.substring(0, end);
22837 }
22838
22839 // or just emit the charStr
22840 return charStr;
22841};
22842
22843// detectIncompleteChar determines if there is an incomplete UTF-8 character at
22844// the end of the given buffer. If so, it sets this.charLength to the byte
22845// length that character, and sets this.charReceived to the number of bytes
22846// that are available for this character.
22847StringDecoder.prototype.detectIncompleteChar = function(buffer) {
22848 // determine how many bytes we have to check at the end of this buffer
22849 var i = (buffer.length >= 3) ? 3 : buffer.length;
22850
22851 // Figure out if one of the last i bytes of our buffer announces an
22852 // incomplete char.
22853 for (; i > 0; i--) {
22854 var c = buffer[buffer.length - i];
22855
22856 // See http://en.wikipedia.org/wiki/UTF-8#Description
22857
22858 // 110XXXXX
22859 if (i == 1 && c >> 5 == 0x06) {
22860 this.charLength = 2;
22861 break;
22862 }
22863
22864 // 1110XXXX
22865 if (i <= 2 && c >> 4 == 0x0E) {
22866 this.charLength = 3;
22867 break;
22868 }
22869
22870 // 11110XXX
22871 if (i <= 3 && c >> 3 == 0x1E) {
22872 this.charLength = 4;
22873 break;
22874 }
22875 }
22876 this.charReceived = i;
22877};
22878
22879StringDecoder.prototype.end = function(buffer) {
22880 var res = '';
22881 if (buffer && buffer.length)
22882 res = this.write(buffer);
22883
22884 if (this.charReceived) {
22885 var cr = this.charReceived;
22886 var buf = this.charBuffer;
22887 var enc = this.encoding;
22888 res += buf.slice(0, cr).toString(enc);
22889 }
22890
22891 return res;
22892};
22893
22894function passThroughWrite(buffer) {
22895 return buffer.toString(this.encoding);
22896}
22897
22898function utf16DetectIncompleteChar(buffer) {
22899 this.charReceived = buffer.length % 2;
22900 this.charLength = this.charReceived ? 2 : 0;
22901}
22902
22903function base64DetectIncompleteChar(buffer) {
22904 this.charReceived = buffer.length % 3;
22905 this.charLength = this.charReceived ? 3 : 0;
22906}
22907
22908},{"buffer":5}],27:[function(require,module,exports){
22909(function (global){
22910
22911/**
22912 * Module exports.
22913 */
22914
22915module.exports = deprecate;
22916
22917/**
22918 * Mark that a method should not be used.
22919 * Returns a modified function which warns once by default.
22920 *
22921 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
22922 *
22923 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
22924 * will throw an Error when invoked.
22925 *
22926 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
22927 * will invoke `console.trace()` instead of `console.error()`.
22928 *
22929 * @param {Function} fn - the function to deprecate
22930 * @param {String} msg - the string to print to the console when `fn` is invoked
22931 * @returns {Function} a new "deprecated" version of `fn`
22932 * @api public
22933 */
22934
22935function deprecate (fn, msg) {
22936 if (config('noDeprecation')) {
22937 return fn;
22938 }
22939
22940 var warned = false;
22941 function deprecated() {
22942 if (!warned) {
22943 if (config('throwDeprecation')) {
22944 throw new Error(msg);
22945 } else if (config('traceDeprecation')) {
22946 console.trace(msg);
22947 } else {
22948 console.warn(msg);
22949 }
22950 warned = true;
22951 }
22952 return fn.apply(this, arguments);
22953 }
22954
22955 return deprecated;
22956}
22957
22958/**
22959 * Checks `localStorage` for boolean values for the given `name`.
22960 *
22961 * @param {String} name
22962 * @returns {Boolean}
22963 * @api private
22964 */
22965
22966function config (name) {
22967 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
22968 try {
22969 if (!global.localStorage) return false;
22970 } catch (_) {
22971 return false;
22972 }
22973 var val = global.localStorage[name];
22974 if (null == val) return false;
22975 return String(val).toLowerCase() === 'true';
22976}
22977
22978}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
22979},{}],28:[function(require,module,exports){
22980arguments[4][9][0].apply(exports,arguments)
22981},{"dup":9}],29:[function(require,module,exports){
22982module.exports = function isBuffer(arg) {
22983 return arg && typeof arg === 'object'
22984 && typeof arg.copy === 'function'
22985 && typeof arg.fill === 'function'
22986 && typeof arg.readUInt8 === 'function';
22987}
22988},{}],30:[function(require,module,exports){
22989(function (process,global){
22990// Copyright Joyent, Inc. and other Node contributors.
22991//
22992// Permission is hereby granted, free of charge, to any person obtaining a
22993// copy of this software and associated documentation files (the
22994// "Software"), to deal in the Software without restriction, including
22995// without limitation the rights to use, copy, modify, merge, publish,
22996// distribute, sublicense, and/or sell copies of the Software, and to permit
22997// persons to whom the Software is furnished to do so, subject to the
22998// following conditions:
22999//
23000// The above copyright notice and this permission notice shall be included
23001// in all copies or substantial portions of the Software.
23002//
23003// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23004// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23005// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
23006// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23007// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23008// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23009// USE OR OTHER DEALINGS IN THE SOFTWARE.
23010
23011var formatRegExp = /%[sdj%]/g;
23012exports.format = function(f) {
23013 if (!isString(f)) {
23014 var objects = [];
23015 for (var i = 0; i < arguments.length; i++) {
23016 objects.push(inspect(arguments[i]));
23017 }
23018 return objects.join(' ');
23019 }
23020
23021 var i = 1;
23022 var args = arguments;
23023 var len = args.length;
23024 var str = String(f).replace(formatRegExp, function(x) {
23025 if (x === '%%') return '%';
23026 if (i >= len) return x;
23027 switch (x) {
23028 case '%s': return String(args[i++]);
23029 case '%d': return Number(args[i++]);
23030 case '%j':
23031 try {
23032 return JSON.stringify(args[i++]);
23033 } catch (_) {
23034 return '[Circular]';
23035 }
23036 default:
23037 return x;
23038 }
23039 });
23040 for (var x = args[i]; i < len; x = args[++i]) {
23041 if (isNull(x) || !isObject(x)) {
23042 str += ' ' + x;
23043 } else {
23044 str += ' ' + inspect(x);
23045 }
23046 }
23047 return str;
23048};
23049
23050
23051// Mark that a method should not be used.
23052// Returns a modified function which warns once by default.
23053// If --no-deprecation is set, then it is a no-op.
23054exports.deprecate = function(fn, msg) {
23055 // Allow for deprecating things in the process of starting up.
23056 if (isUndefined(global.process)) {
23057 return function() {
23058 return exports.deprecate(fn, msg).apply(this, arguments);
23059 };
23060 }
23061
23062 if (process.noDeprecation === true) {
23063 return fn;
23064 }
23065
23066 var warned = false;
23067 function deprecated() {
23068 if (!warned) {
23069 if (process.throwDeprecation) {
23070 throw new Error(msg);
23071 } else if (process.traceDeprecation) {
23072 console.trace(msg);
23073 } else {
23074 console.error(msg);
23075 }
23076 warned = true;
23077 }
23078 return fn.apply(this, arguments);
23079 }
23080
23081 return deprecated;
23082};
23083
23084
23085var debugs = {};
23086var debugEnviron;
23087exports.debuglog = function(set) {
23088 if (isUndefined(debugEnviron))
23089 debugEnviron = process.env.NODE_DEBUG || '';
23090 set = set.toUpperCase();
23091 if (!debugs[set]) {
23092 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
23093 var pid = process.pid;
23094 debugs[set] = function() {
23095 var msg = exports.format.apply(exports, arguments);
23096 console.error('%s %d: %s', set, pid, msg);
23097 };
23098 } else {
23099 debugs[set] = function() {};
23100 }
23101 }
23102 return debugs[set];
23103};
23104
23105
23106/**
23107 * Echos the value of a value. Trys to print the value out
23108 * in the best way possible given the different types.
23109 *
23110 * @param {Object} obj The object to print out.
23111 * @param {Object} opts Optional options object that alters the output.
23112 */
23113/* legacy: obj, showHidden, depth, colors*/
23114function inspect(obj, opts) {
23115 // default options
23116 var ctx = {
23117 seen: [],
23118 stylize: stylizeNoColor
23119 };
23120 // legacy...
23121 if (arguments.length >= 3) ctx.depth = arguments[2];
23122 if (arguments.length >= 4) ctx.colors = arguments[3];
23123 if (isBoolean(opts)) {
23124 // legacy...
23125 ctx.showHidden = opts;
23126 } else if (opts) {
23127 // got an "options" object
23128 exports._extend(ctx, opts);
23129 }
23130 // set default options
23131 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
23132 if (isUndefined(ctx.depth)) ctx.depth = 2;
23133 if (isUndefined(ctx.colors)) ctx.colors = false;
23134 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
23135 if (ctx.colors) ctx.stylize = stylizeWithColor;
23136 return formatValue(ctx, obj, ctx.depth);
23137}
23138exports.inspect = inspect;
23139
23140
23141// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
23142inspect.colors = {
23143 'bold' : [1, 22],
23144 'italic' : [3, 23],
23145 'underline' : [4, 24],
23146 'inverse' : [7, 27],
23147 'white' : [37, 39],
23148 'grey' : [90, 39],
23149 'black' : [30, 39],
23150 'blue' : [34, 39],
23151 'cyan' : [36, 39],
23152 'green' : [32, 39],
23153 'magenta' : [35, 39],
23154 'red' : [31, 39],
23155 'yellow' : [33, 39]
23156};
23157
23158// Don't use 'blue' not visible on cmd.exe
23159inspect.styles = {
23160 'special': 'cyan',
23161 'number': 'yellow',
23162 'boolean': 'yellow',
23163 'undefined': 'grey',
23164 'null': 'bold',
23165 'string': 'green',
23166 'date': 'magenta',
23167 // "name": intentionally not styling
23168 'regexp': 'red'
23169};
23170
23171
23172function stylizeWithColor(str, styleType) {
23173 var style = inspect.styles[styleType];
23174
23175 if (style) {
23176 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
23177 '\u001b[' + inspect.colors[style][1] + 'm';
23178 } else {
23179 return str;
23180 }
23181}
23182
23183
23184function stylizeNoColor(str, styleType) {
23185 return str;
23186}
23187
23188
23189function arrayToHash(array) {
23190 var hash = {};
23191
23192 array.forEach(function(val, idx) {
23193 hash[val] = true;
23194 });
23195
23196 return hash;
23197}
23198
23199
23200function formatValue(ctx, value, recurseTimes) {
23201 // Provide a hook for user-specified inspect functions.
23202 // Check that value is an object with an inspect function on it
23203 if (ctx.customInspect &&
23204 value &&
23205 isFunction(value.inspect) &&
23206 // Filter out the util module, it's inspect function is special
23207 value.inspect !== exports.inspect &&
23208 // Also filter out any prototype objects using the circular check.
23209 !(value.constructor && value.constructor.prototype === value)) {
23210 var ret = value.inspect(recurseTimes, ctx);
23211 if (!isString(ret)) {
23212 ret = formatValue(ctx, ret, recurseTimes);
23213 }
23214 return ret;
23215 }
23216
23217 // Primitive types cannot have properties
23218 var primitive = formatPrimitive(ctx, value);
23219 if (primitive) {
23220 return primitive;
23221 }
23222
23223 // Look up the keys of the object.
23224 var keys = Object.keys(value);
23225 var visibleKeys = arrayToHash(keys);
23226
23227 if (ctx.showHidden) {
23228 keys = Object.getOwnPropertyNames(value);
23229 }
23230
23231 // IE doesn't make error fields non-enumerable
23232 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
23233 if (isError(value)
23234 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
23235 return formatError(value);
23236 }
23237
23238 // Some type of object without properties can be shortcutted.
23239 if (keys.length === 0) {
23240 if (isFunction(value)) {
23241 var name = value.name ? ': ' + value.name : '';
23242 return ctx.stylize('[Function' + name + ']', 'special');
23243 }
23244 if (isRegExp(value)) {
23245 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
23246 }
23247 if (isDate(value)) {
23248 return ctx.stylize(Date.prototype.toString.call(value), 'date');
23249 }
23250 if (isError(value)) {
23251 return formatError(value);
23252 }
23253 }
23254
23255 var base = '', array = false, braces = ['{', '}'];
23256
23257 // Make Array say that they are Array
23258 if (isArray(value)) {
23259 array = true;
23260 braces = ['[', ']'];
23261 }
23262
23263 // Make functions say that they are functions
23264 if (isFunction(value)) {
23265 var n = value.name ? ': ' + value.name : '';
23266 base = ' [Function' + n + ']';
23267 }
23268
23269 // Make RegExps say that they are RegExps
23270 if (isRegExp(value)) {
23271 base = ' ' + RegExp.prototype.toString.call(value);
23272 }
23273
23274 // Make dates with properties first say the date
23275 if (isDate(value)) {
23276 base = ' ' + Date.prototype.toUTCString.call(value);
23277 }
23278
23279 // Make error with message first say the error
23280 if (isError(value)) {
23281 base = ' ' + formatError(value);
23282 }
23283
23284 if (keys.length === 0 && (!array || value.length == 0)) {
23285 return braces[0] + base + braces[1];
23286 }
23287
23288 if (recurseTimes < 0) {
23289 if (isRegExp(value)) {
23290 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
23291 } else {
23292 return ctx.stylize('[Object]', 'special');
23293 }
23294 }
23295
23296 ctx.seen.push(value);
23297
23298 var output;
23299 if (array) {
23300 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
23301 } else {
23302 output = keys.map(function(key) {
23303 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
23304 });
23305 }
23306
23307 ctx.seen.pop();
23308
23309 return reduceToSingleString(output, base, braces);
23310}
23311
23312
23313function formatPrimitive(ctx, value) {
23314 if (isUndefined(value))
23315 return ctx.stylize('undefined', 'undefined');
23316 if (isString(value)) {
23317 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
23318 .replace(/'/g, "\\'")
23319 .replace(/\\"/g, '"') + '\'';
23320 return ctx.stylize(simple, 'string');
23321 }
23322 if (isNumber(value))
23323 return ctx.stylize('' + value, 'number');
23324 if (isBoolean(value))
23325 return ctx.stylize('' + value, 'boolean');
23326 // For some reason typeof null is "object", so special case here.
23327 if (isNull(value))
23328 return ctx.stylize('null', 'null');
23329}
23330
23331
23332function formatError(value) {
23333 return '[' + Error.prototype.toString.call(value) + ']';
23334}
23335
23336
23337function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
23338 var output = [];
23339 for (var i = 0, l = value.length; i < l; ++i) {
23340 if (hasOwnProperty(value, String(i))) {
23341 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
23342 String(i), true));
23343 } else {
23344 output.push('');
23345 }
23346 }
23347 keys.forEach(function(key) {
23348 if (!key.match(/^\d+$/)) {
23349 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
23350 key, true));
23351 }
23352 });
23353 return output;
23354}
23355
23356
23357function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
23358 var name, str, desc;
23359 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
23360 if (desc.get) {
23361 if (desc.set) {
23362 str = ctx.stylize('[Getter/Setter]', 'special');
23363 } else {
23364 str = ctx.stylize('[Getter]', 'special');
23365 }
23366 } else {
23367 if (desc.set) {
23368 str = ctx.stylize('[Setter]', 'special');
23369 }
23370 }
23371 if (!hasOwnProperty(visibleKeys, key)) {
23372 name = '[' + key + ']';
23373 }
23374 if (!str) {
23375 if (ctx.seen.indexOf(desc.value) < 0) {
23376 if (isNull(recurseTimes)) {
23377 str = formatValue(ctx, desc.value, null);
23378 } else {
23379 str = formatValue(ctx, desc.value, recurseTimes - 1);
23380 }
23381 if (str.indexOf('\n') > -1) {
23382 if (array) {
23383 str = str.split('\n').map(function(line) {
23384 return ' ' + line;
23385 }).join('\n').substr(2);
23386 } else {
23387 str = '\n' + str.split('\n').map(function(line) {
23388 return ' ' + line;
23389 }).join('\n');
23390 }
23391 }
23392 } else {
23393 str = ctx.stylize('[Circular]', 'special');
23394 }
23395 }
23396 if (isUndefined(name)) {
23397 if (array && key.match(/^\d+$/)) {
23398 return str;
23399 }
23400 name = JSON.stringify('' + key);
23401 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
23402 name = name.substr(1, name.length - 2);
23403 name = ctx.stylize(name, 'name');
23404 } else {
23405 name = name.replace(/'/g, "\\'")
23406 .replace(/\\"/g, '"')
23407 .replace(/(^"|"$)/g, "'");
23408 name = ctx.stylize(name, 'string');
23409 }
23410 }
23411
23412 return name + ': ' + str;
23413}
23414
23415
23416function reduceToSingleString(output, base, braces) {
23417 var numLinesEst = 0;
23418 var length = output.reduce(function(prev, cur) {
23419 numLinesEst++;
23420 if (cur.indexOf('\n') >= 0) numLinesEst++;
23421 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
23422 }, 0);
23423
23424 if (length > 60) {
23425 return braces[0] +
23426 (base === '' ? '' : base + '\n ') +
23427 ' ' +
23428 output.join(',\n ') +
23429 ' ' +
23430 braces[1];
23431 }
23432
23433 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
23434}
23435
23436
23437// NOTE: These type checking functions intentionally don't use `instanceof`
23438// because it is fragile and can be easily faked with `Object.create()`.
23439function isArray(ar) {
23440 return Array.isArray(ar);
23441}
23442exports.isArray = isArray;
23443
23444function isBoolean(arg) {
23445 return typeof arg === 'boolean';
23446}
23447exports.isBoolean = isBoolean;
23448
23449function isNull(arg) {
23450 return arg === null;
23451}
23452exports.isNull = isNull;
23453
23454function isNullOrUndefined(arg) {
23455 return arg == null;
23456}
23457exports.isNullOrUndefined = isNullOrUndefined;
23458
23459function isNumber(arg) {
23460 return typeof arg === 'number';
23461}
23462exports.isNumber = isNumber;
23463
23464function isString(arg) {
23465 return typeof arg === 'string';
23466}
23467exports.isString = isString;
23468
23469function isSymbol(arg) {
23470 return typeof arg === 'symbol';
23471}
23472exports.isSymbol = isSymbol;
23473
23474function isUndefined(arg) {
23475 return arg === void 0;
23476}
23477exports.isUndefined = isUndefined;
23478
23479function isRegExp(re) {
23480 return isObject(re) && objectToString(re) === '[object RegExp]';
23481}
23482exports.isRegExp = isRegExp;
23483
23484function isObject(arg) {
23485 return typeof arg === 'object' && arg !== null;
23486}
23487exports.isObject = isObject;
23488
23489function isDate(d) {
23490 return isObject(d) && objectToString(d) === '[object Date]';
23491}
23492exports.isDate = isDate;
23493
23494function isError(e) {
23495 return isObject(e) &&
23496 (objectToString(e) === '[object Error]' || e instanceof Error);
23497}
23498exports.isError = isError;
23499
23500function isFunction(arg) {
23501 return typeof arg === 'function';
23502}
23503exports.isFunction = isFunction;
23504
23505function isPrimitive(arg) {
23506 return arg === null ||
23507 typeof arg === 'boolean' ||
23508 typeof arg === 'number' ||
23509 typeof arg === 'string' ||
23510 typeof arg === 'symbol' || // ES6 symbol
23511 typeof arg === 'undefined';
23512}
23513exports.isPrimitive = isPrimitive;
23514
23515exports.isBuffer = require('./support/isBuffer');
23516
23517function objectToString(o) {
23518 return Object.prototype.toString.call(o);
23519}
23520
23521
23522function pad(n) {
23523 return n < 10 ? '0' + n.toString(10) : n.toString(10);
23524}
23525
23526
23527var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
23528 'Oct', 'Nov', 'Dec'];
23529
23530// 26 Feb 16:19:34
23531function timestamp() {
23532 var d = new Date();
23533 var time = [pad(d.getHours()),
23534 pad(d.getMinutes()),
23535 pad(d.getSeconds())].join(':');
23536 return [d.getDate(), months[d.getMonth()], time].join(' ');
23537}
23538
23539
23540// log is just a thin wrapper to console.log that prepends a timestamp
23541exports.log = function() {
23542 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
23543};
23544
23545
23546/**
23547 * Inherit the prototype methods from one constructor into another.
23548 *
23549 * The Function.prototype.inherits from lang.js rewritten as a standalone
23550 * function (not on Function.prototype). NOTE: If this file is to be loaded
23551 * during bootstrapping this function needs to be rewritten using some native
23552 * functions as prototype setup using normal JavaScript does not work as
23553 * expected during bootstrapping (see mirror.js in r114903).
23554 *
23555 * @param {function} ctor Constructor function which needs to inherit the
23556 * prototype.
23557 * @param {function} superCtor Constructor function to inherit prototype from.
23558 */
23559exports.inherits = require('inherits');
23560
23561exports._extend = function(origin, add) {
23562 // Don't do anything if add isn't an object
23563 if (!add || !isObject(add)) return origin;
23564
23565 var keys = Object.keys(add);
23566 var i = keys.length;
23567 while (i--) {
23568 origin[keys[i]] = add[keys[i]];
23569 }
23570 return origin;
23571};
23572
23573function hasOwnProperty(obj, prop) {
23574 return Object.prototype.hasOwnProperty.call(obj, prop);
23575}
23576
23577}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
23578},{"./support/isBuffer":29,"_process":13,"inherits":28}],31:[function(require,module,exports){
23579(function (Buffer){
23580const createKeccakHash = require('keccak')
23581const secp256k1 = require('secp256k1')
23582const assert = require('assert')
23583const rlp = require('rlp')
23584const BN = require('bn.js')
23585const createHash = require('create-hash')
23586Object.assign(exports, require('ethjs-util'))
23587
23588/**
23589 * the max integer that this VM can handle (a ```BN```)
23590 * @var {BN} MAX_INTEGER
23591 */
23592exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)
23593
23594/**
23595 * 2^256 (a ```BN```)
23596 * @var {BN} TWO_POW256
23597 */
23598exports.TWO_POW256 = new BN('10000000000000000000000000000000000000000000000000000000000000000', 16)
23599
23600/**
23601 * SHA3-256 hash of null (a ```String```)
23602 * @var {String} SHA3_NULL_S
23603 */
23604exports.SHA3_NULL_S = 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
23605
23606/**
23607 * SHA3-256 hash of null (a ```Buffer```)
23608 * @var {Buffer} SHA3_NULL
23609 */
23610exports.SHA3_NULL = Buffer.from(exports.SHA3_NULL_S, 'hex')
23611
23612/**
23613 * SHA3-256 of an RLP of an empty array (a ```String```)
23614 * @var {String} SHA3_RLP_ARRAY_S
23615 */
23616exports.SHA3_RLP_ARRAY_S = '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
23617
23618/**
23619 * SHA3-256 of an RLP of an empty array (a ```Buffer```)
23620 * @var {Buffer} SHA3_RLP_ARRAY
23621 */
23622exports.SHA3_RLP_ARRAY = Buffer.from(exports.SHA3_RLP_ARRAY_S, 'hex')
23623
23624/**
23625 * SHA3-256 hash of the RLP of null (a ```String```)
23626 * @var {String} SHA3_RLP_S
23627 */
23628exports.SHA3_RLP_S = '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
23629
23630/**
23631 * SHA3-256 hash of the RLP of null (a ```Buffer```)
23632 * @var {Buffer} SHA3_RLP
23633 */
23634exports.SHA3_RLP = Buffer.from(exports.SHA3_RLP_S, 'hex')
23635
23636/**
23637 * [`BN`](https://github.com/indutny/bn.js)
23638 * @var {Function}
23639 */
23640exports.BN = BN
23641
23642/**
23643 * [`rlp`](https://github.com/ethereumjs/rlp)
23644 * @var {Function}
23645 */
23646exports.rlp = rlp
23647
23648/**
23649 * [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)
23650 * @var {Object}
23651 */
23652exports.secp256k1 = secp256k1
23653
23654/**
23655 * Returns a buffer filled with 0s
23656 * @method zeros
23657 * @param {Number} bytes the number of bytes the buffer should be
23658 * @return {Buffer}
23659 */
23660exports.zeros = function (bytes) {
23661 return Buffer.allocUnsafe(bytes).fill(0)
23662}
23663
23664/**
23665 * Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
23666 * Or it truncates the beginning if it exceeds.
23667 * @method lsetLength
23668 * @param {Buffer|Array} msg the value to pad
23669 * @param {Number} length the number of bytes the output should be
23670 * @param {Boolean} [right=false] whether to start padding form the left or right
23671 * @return {Buffer|Array}
23672 */
23673exports.setLengthLeft = exports.setLength = function (msg, length, right) {
23674 var buf = exports.zeros(length)
23675 msg = exports.toBuffer(msg)
23676 if (right) {
23677 if (msg.length < length) {
23678 msg.copy(buf)
23679 return buf
23680 }
23681 return msg.slice(0, length)
23682 } else {
23683 if (msg.length < length) {
23684 msg.copy(buf, length - msg.length)
23685 return buf
23686 }
23687 return msg.slice(-length)
23688 }
23689}
23690
23691/**
23692 * Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
23693 * Or it truncates the beginning if it exceeds.
23694 * @param {Buffer|Array} msg the value to pad
23695 * @param {Number} length the number of bytes the output should be
23696 * @return {Buffer|Array}
23697 */
23698exports.setLengthRight = function (msg, length) {
23699 return exports.setLength(msg, length, true)
23700}
23701
23702/**
23703 * Trims leading zeros from a `Buffer` or an `Array`
23704 * @param {Buffer|Array|String} a
23705 * @return {Buffer|Array|String}
23706 */
23707exports.unpad = exports.stripZeros = function (a) {
23708 a = exports.stripHexPrefix(a)
23709 var first = a[0]
23710 while (a.length > 0 && first.toString() === '0') {
23711 a = a.slice(1)
23712 first = a[0]
23713 }
23714 return a
23715}
23716/**
23717 * Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` method.
23718 * @param {*} v the value
23719 */
23720exports.toBuffer = function (v) {
23721 if (!Buffer.isBuffer(v)) {
23722 if (Array.isArray(v)) {
23723 v = Buffer.from(v)
23724 } else if (typeof v === 'string') {
23725 if (exports.isHexPrefixed(v)) {
23726 v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), 'hex')
23727 } else {
23728 v = Buffer.from(v)
23729 }
23730 } else if (typeof v === 'number') {
23731 v = exports.intToBuffer(v)
23732 } else if (v === null || v === undefined) {
23733 v = Buffer.allocUnsafe(0)
23734 } else if (v.toArray) {
23735 // converts a BN to a Buffer
23736 v = Buffer.from(v.toArray())
23737 } else {
23738 throw new Error('invalid type')
23739 }
23740 }
23741 return v
23742}
23743
23744/**
23745 * Converts a `Buffer` to a `Number`
23746 * @param {Buffer} buf
23747 * @return {Number}
23748 * @throws If the input number exceeds 53 bits.
23749 */
23750exports.bufferToInt = function (buf) {
23751 return new BN(exports.toBuffer(buf)).toNumber()
23752}
23753
23754/**
23755 * Converts a `Buffer` into a hex `String`
23756 * @param {Buffer} buf
23757 * @return {String}
23758 */
23759exports.bufferToHex = function (buf) {
23760 buf = exports.toBuffer(buf)
23761 return '0x' + buf.toString('hex')
23762}
23763
23764/**
23765 * Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
23766 * @param {Buffer} num
23767 * @return {BN}
23768 */
23769exports.fromSigned = function (num) {
23770 return new BN(num).fromTwos(256)
23771}
23772
23773/**
23774 * Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
23775 * @param {BN} num
23776 * @return {Buffer}
23777 */
23778exports.toUnsigned = function (num) {
23779 return Buffer.from(num.toTwos(256).toArray())
23780}
23781
23782/**
23783 * Creates SHA-3 hash of the input
23784 * @param {Buffer|Array|String|Number} a the input data
23785 * @param {Number} [bits=256] the SHA width
23786 * @return {Buffer}
23787 */
23788exports.sha3 = function (a, bits) {
23789 a = exports.toBuffer(a)
23790 if (!bits) bits = 256
23791
23792 return createKeccakHash('keccak' + bits).update(a).digest()
23793}
23794
23795/**
23796 * Creates SHA256 hash of the input
23797 * @param {Buffer|Array|String|Number} a the input data
23798 * @return {Buffer}
23799 */
23800exports.sha256 = function (a) {
23801 a = exports.toBuffer(a)
23802 return createHash('sha256').update(a).digest()
23803}
23804
23805/**
23806 * Creates RIPEMD160 hash of the input
23807 * @param {Buffer|Array|String|Number} a the input data
23808 * @param {Boolean} padded whether it should be padded to 256 bits or not
23809 * @return {Buffer}
23810 */
23811exports.ripemd160 = function (a, padded) {
23812 a = exports.toBuffer(a)
23813 var hash = createHash('rmd160').update(a).digest()
23814 if (padded === true) {
23815 return exports.setLength(hash, 32)
23816 } else {
23817 return hash
23818 }
23819}
23820
23821/**
23822 * Creates SHA-3 hash of the RLP encoded version of the input
23823 * @param {Buffer|Array|String|Number} a the input data
23824 * @return {Buffer}
23825 */
23826exports.rlphash = function (a) {
23827 return exports.sha3(rlp.encode(a))
23828}
23829
23830/**
23831 * Checks if the private key satisfies the rules of the curve secp256k1.
23832 * @param {Buffer} privateKey
23833 * @return {Boolean}
23834 */
23835exports.isValidPrivate = function (privateKey) {
23836 return secp256k1.privateKeyVerify(privateKey)
23837}
23838
23839/**
23840 * Checks if the public key satisfies the rules of the curve secp256k1
23841 * and the requirements of Ethereum.
23842 * @param {Buffer} publicKey The two points of an uncompressed key, unless sanitize is enabled
23843 * @param {Boolean} [sanitize=false] Accept public keys in other formats
23844 * @return {Boolean}
23845 */
23846exports.isValidPublic = function (publicKey, sanitize) {
23847 if (publicKey.length === 64) {
23848 // Convert to SEC1 for secp256k1
23849 return secp256k1.publicKeyVerify(Buffer.concat([ Buffer.from([4]), publicKey ]))
23850 }
23851
23852 if (!sanitize) {
23853 return false
23854 }
23855
23856 return secp256k1.publicKeyVerify(publicKey)
23857}
23858
23859/**
23860 * Returns the ethereum address of a given public key.
23861 * Accepts "Ethereum public keys" and SEC1 encoded keys.
23862 * @param {Buffer} pubKey The two points of an uncompressed key, unless sanitize is enabled
23863 * @param {Boolean} [sanitize=false] Accept public keys in other formats
23864 * @return {Buffer}
23865 */
23866exports.pubToAddress = exports.publicToAddress = function (pubKey, sanitize) {
23867 pubKey = exports.toBuffer(pubKey)
23868 if (sanitize && (pubKey.length !== 64)) {
23869 pubKey = secp256k1.publicKeyConvert(pubKey, false).slice(1)
23870 }
23871 assert(pubKey.length === 64)
23872 // Only take the lower 160bits of the hash
23873 return exports.sha3(pubKey).slice(-20)
23874}
23875
23876/**
23877 * Returns the ethereum public key of a given private key
23878 * @param {Buffer} privateKey A private key must be 256 bits wide
23879 * @return {Buffer}
23880 */
23881var privateToPublic = exports.privateToPublic = function (privateKey) {
23882 privateKey = exports.toBuffer(privateKey)
23883 // skip the type flag and use the X, Y points
23884 return secp256k1.publicKeyCreate(privateKey, false).slice(1)
23885}
23886
23887/**
23888 * Converts a public key to the Ethereum format.
23889 * @param {Buffer} publicKey
23890 * @return {Buffer}
23891 */
23892exports.importPublic = function (publicKey) {
23893 publicKey = exports.toBuffer(publicKey)
23894 if (publicKey.length !== 64) {
23895 publicKey = secp256k1.publicKeyConvert(publicKey, false).slice(1)
23896 }
23897 return publicKey
23898}
23899
23900/**
23901 * ECDSA sign
23902 * @param {Buffer} msgHash
23903 * @param {Buffer} privateKey
23904 * @return {Object}
23905 */
23906exports.ecsign = function (msgHash, privateKey) {
23907 var sig = secp256k1.sign(msgHash, privateKey)
23908
23909 var ret = {}
23910 ret.r = sig.signature.slice(0, 32)
23911 ret.s = sig.signature.slice(32, 64)
23912 ret.v = sig.recovery + 27
23913 return ret
23914}
23915
23916/**
23917 * Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
23918 * The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
23919 * call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
23920 * used to produce the signature.
23921 * @param message
23922 * @returns {Buffer} hash
23923 */
23924exports.hashPersonalMessage = function (message) {
23925 var prefix = exports.toBuffer('\u0019Ethereum Signed Message:\n' + message.length.toString())
23926 return exports.sha3(Buffer.concat([prefix, message]))
23927}
23928
23929/**
23930 * ECDSA public key recovery from signature
23931 * @param {Buffer} msgHash
23932 * @param {Number} v
23933 * @param {Buffer} r
23934 * @param {Buffer} s
23935 * @return {Buffer} publicKey
23936 */
23937exports.ecrecover = function (msgHash, v, r, s) {
23938 var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64)
23939 var recovery = v - 27
23940 if (recovery !== 0 && recovery !== 1) {
23941 throw new Error('Invalid signature v value')
23942 }
23943 var senderPubKey = secp256k1.recover(msgHash, signature, recovery)
23944 return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)
23945}
23946
23947/**
23948 * Convert signature parameters into the format of `eth_sign` RPC method
23949 * @param {Number} v
23950 * @param {Buffer} r
23951 * @param {Buffer} s
23952 * @return {String} sig
23953 */
23954exports.toRpcSig = function (v, r, s) {
23955 // NOTE: with potential introduction of chainId this might need to be updated
23956 if (v !== 27 && v !== 28) {
23957 throw new Error('Invalid recovery id')
23958 }
23959
23960 // geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin
23961 // FIXME: this might change in the future - https://github.com/ethereum/go-ethereum/issues/2053
23962 return exports.bufferToHex(Buffer.concat([
23963 exports.setLengthLeft(r, 32),
23964 exports.setLengthLeft(s, 32),
23965 exports.toBuffer(v - 27)
23966 ]))
23967}
23968
23969/**
23970 * Convert signature format of the `eth_sign` RPC method to signature parameters
23971 * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
23972 * @param {String} sig
23973 * @return {Object}
23974 */
23975exports.fromRpcSig = function (sig) {
23976 sig = exports.toBuffer(sig)
23977
23978 // NOTE: with potential introduction of chainId this might need to be updated
23979 if (sig.length !== 65) {
23980 throw new Error('Invalid signature length')
23981 }
23982
23983 var v = sig[64]
23984 // support both versions of `eth_sign` responses
23985 if (v < 27) {
23986 v += 27
23987 }
23988
23989 return {
23990 v: v,
23991 r: sig.slice(0, 32),
23992 s: sig.slice(32, 64)
23993 }
23994}
23995
23996/**
23997 * Returns the ethereum address of a given private key
23998 * @param {Buffer} privateKey A private key must be 256 bits wide
23999 * @return {Buffer}
24000 */
24001exports.privateToAddress = function (privateKey) {
24002 return exports.publicToAddress(privateToPublic(privateKey))
24003}
24004
24005/**
24006 * Checks if the address is a valid. Accepts checksummed addresses too
24007 * @param {String} address
24008 * @return {Boolean}
24009 */
24010exports.isValidAddress = function (address) {
24011 return /^0x[0-9a-fA-F]{40}$/i.test(address)
24012}
24013
24014/**
24015 * Returns a checksummed address
24016 * @param {String} address
24017 * @return {String}
24018 */
24019exports.toChecksumAddress = function (address) {
24020 address = exports.stripHexPrefix(address).toLowerCase()
24021 var hash = exports.sha3(address).toString('hex')
24022 var ret = '0x'
24023
24024 for (var i = 0; i < address.length; i++) {
24025 if (parseInt(hash[i], 16) >= 8) {
24026 ret += address[i].toUpperCase()
24027 } else {
24028 ret += address[i]
24029 }
24030 }
24031
24032 return ret
24033}
24034
24035/**
24036 * Checks if the address is a valid checksummed address
24037 * @param {Buffer} address
24038 * @return {Boolean}
24039 */
24040exports.isValidChecksumAddress = function (address) {
24041 return exports.isValidAddress(address) && (exports.toChecksumAddress(address) === address)
24042}
24043
24044/**
24045 * Generates an address of a newly created contract
24046 * @param {Buffer} from the address which is creating this new address
24047 * @param {Buffer} nonce the nonce of the from account
24048 * @return {Buffer}
24049 */
24050exports.generateAddress = function (from, nonce) {
24051 from = exports.toBuffer(from)
24052 nonce = new BN(nonce)
24053
24054 if (nonce.isZero()) {
24055 // in RLP we want to encode null in the case of zero nonce
24056 // read the RLP documentation for an answer if you dare
24057 nonce = null
24058 } else {
24059 nonce = Buffer.from(nonce.toArray())
24060 }
24061
24062 // Only take the lower 160bits of the hash
24063 return exports.rlphash([from, nonce]).slice(-20)
24064}
24065
24066/**
24067 * Returns true if the supplied address belongs to a precompiled account
24068 * @param {Buffer|String} address
24069 * @return {Boolean}
24070 */
24071exports.isPrecompiled = function (address) {
24072 var a = exports.unpad(address)
24073 return a.length === 1 && a[0] > 0 && a[0] < 5
24074}
24075
24076/**
24077 * Adds "0x" to a given `String` if it does not already start with "0x"
24078 * @param {String} str
24079 * @return {String}
24080 */
24081exports.addHexPrefix = function (str) {
24082 if (typeof str !== 'string') {
24083 return str
24084 }
24085
24086 return exports.isHexPrefixed(str) ? str : '0x' + str
24087}
24088
24089/**
24090 * Validate ECDSA signature
24091 * @method isValidSignature
24092 * @param {Buffer} v
24093 * @param {Buffer} r
24094 * @param {Buffer} s
24095 * @param {Boolean} [homestead=true]
24096 * @return {Boolean}
24097 */
24098
24099exports.isValidSignature = function (v, r, s, homestead) {
24100 const SECP256K1_N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16)
24101 const SECP256K1_N = new BN('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16)
24102
24103 if (r.length !== 32 || s.length !== 32) {
24104 return false
24105 }
24106
24107 if (v !== 27 && v !== 28) {
24108 return false
24109 }
24110
24111 r = new BN(r)
24112 s = new BN(s)
24113
24114 if (r.isZero() || r.gt(SECP256K1_N) || s.isZero() || s.gt(SECP256K1_N)) {
24115 return false
24116 }
24117
24118 if ((homestead === false) && (new BN(s).cmp(SECP256K1_N_DIV_2) === 1)) {
24119 return false
24120 }
24121
24122 return true
24123}
24124
24125/**
24126 * Converts a `Buffer` or `Array` to JSON
24127 * @param {Buffer|Array} ba
24128 * @return {Array|String|null}
24129 */
24130exports.baToJSON = function (ba) {
24131 if (Buffer.isBuffer(ba)) {
24132 return '0x' + ba.toString('hex')
24133 } else if (ba instanceof Array) {
24134 var array = []
24135 for (var i = 0; i < ba.length; i++) {
24136 array.push(exports.baToJSON(ba[i]))
24137 }
24138 return array
24139 }
24140}
24141
24142/**
24143 * Defines properties on a `Object`. It make the assumption that underlying data is binary.
24144 * @param {Object} self the `Object` to define properties on
24145 * @param {Array} fields an array fields to define. Fields can contain:
24146 * * `name` - the name of the properties
24147 * * `length` - the number of bytes the field can have
24148 * * `allowLess` - if the field can be less than the length
24149 * * `allowEmpty`
24150 * @param {*} data data to be validated against the definitions
24151 */
24152exports.defineProperties = function (self, fields, data) {
24153 self.raw = []
24154 self._fields = []
24155
24156 // attach the `toJSON`
24157 self.toJSON = function (label) {
24158 if (label) {
24159 var obj = {}
24160 self._fields.forEach(function (field) {
24161 obj[field] = '0x' + self[field].toString('hex')
24162 })
24163 return obj
24164 }
24165 return exports.baToJSON(this.raw)
24166 }
24167
24168 self.serialize = function serialize () {
24169 return rlp.encode(self.raw)
24170 }
24171
24172 fields.forEach(function (field, i) {
24173 self._fields.push(field.name)
24174 function getter () {
24175 return self.raw[i]
24176 }
24177 function setter (v) {
24178 v = exports.toBuffer(v)
24179
24180 if (v.toString('hex') === '00' && !field.allowZero) {
24181 v = Buffer.allocUnsafe(0)
24182 }
24183
24184 if (field.allowLess && field.length) {
24185 v = exports.stripZeros(v)
24186 assert(field.length >= v.length, 'The field ' + field.name + ' must not have more ' + field.length + ' bytes')
24187 } else if (!(field.allowZero && v.length === 0) && field.length) {
24188 assert(field.length === v.length, 'The field ' + field.name + ' must have byte length of ' + field.length)
24189 }
24190
24191 self.raw[i] = v
24192 }
24193
24194 Object.defineProperty(self, field.name, {
24195 enumerable: true,
24196 configurable: true,
24197 get: getter,
24198 set: setter
24199 })
24200
24201 if (field.default) {
24202 self[field.name] = field.default
24203 }
24204
24205 // attach alias
24206 if (field.alias) {
24207 Object.defineProperty(self, field.alias, {
24208 enumerable: false,
24209 configurable: true,
24210 set: setter,
24211 get: getter
24212 })
24213 }
24214 })
24215
24216 // if the constuctor is passed data
24217 if (data) {
24218 if (typeof data === 'string') {
24219 data = Buffer.from(exports.stripHexPrefix(data), 'hex')
24220 }
24221
24222 if (Buffer.isBuffer(data)) {
24223 data = rlp.decode(data)
24224 }
24225
24226 if (Array.isArray(data)) {
24227 if (data.length > self._fields.length) {
24228 throw (new Error('wrong number of fields in data'))
24229 }
24230
24231 // make sure all the items are buffers
24232 data.forEach(function (d, i) {
24233 self[self._fields[i]] = exports.toBuffer(d)
24234 })
24235 } else if (typeof data === 'object') {
24236 const keys = Object.keys(data)
24237 fields.forEach(function (field) {
24238 if (keys.indexOf(field.name) !== -1) self[field.name] = data[field.name]
24239 if (keys.indexOf(field.alias) !== -1) self[field.alias] = data[field.alias]
24240 })
24241 } else {
24242 throw new Error('invalid data')
24243 }
24244 }
24245}
24246
24247}).call(this,require("buffer").Buffer)
24248},{"assert":1,"bn.js":33,"buffer":5,"create-hash":36,"ethjs-util":56,"keccak":65,"rlp":72,"secp256k1":73}],32:[function(require,module,exports){
24249(function (Buffer){
24250// Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
24251// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
24252// NOTE: SIGHASH byte ignored AND restricted, truncate before use
24253
24254function check (buffer) {
24255 if (buffer.length < 8) return false
24256 if (buffer.length > 72) return false
24257 if (buffer[0] !== 0x30) return false
24258 if (buffer[1] !== buffer.length - 2) return false
24259 if (buffer[2] !== 0x02) return false
24260
24261 var lenR = buffer[3]
24262 if (lenR === 0) return false
24263 if (5 + lenR >= buffer.length) return false
24264 if (buffer[4 + lenR] !== 0x02) return false
24265
24266 var lenS = buffer[5 + lenR]
24267 if (lenS === 0) return false
24268 if ((6 + lenR + lenS) !== buffer.length) return false
24269
24270 if (buffer[4] & 0x80) return false
24271 if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) return false
24272
24273 if (buffer[lenR + 6] & 0x80) return false
24274 if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) return false
24275 return true
24276}
24277
24278function decode (buffer) {
24279 if (buffer.length < 8) throw new Error('DER sequence length is too short')
24280 if (buffer.length > 72) throw new Error('DER sequence length is too long')
24281 if (buffer[0] !== 0x30) throw new Error('Expected DER sequence')
24282 if (buffer[1] !== buffer.length - 2) throw new Error('DER sequence length is invalid')
24283 if (buffer[2] !== 0x02) throw new Error('Expected DER integer')
24284
24285 var lenR = buffer[3]
24286 if (lenR === 0) throw new Error('R length is zero')
24287 if (5 + lenR >= buffer.length) throw new Error('R length is too long')
24288 if (buffer[4 + lenR] !== 0x02) throw new Error('Expected DER integer (2)')
24289
24290 var lenS = buffer[5 + lenR]
24291 if (lenS === 0) throw new Error('S length is zero')
24292 if ((6 + lenR + lenS) !== buffer.length) throw new Error('S length is invalid')
24293
24294 if (buffer[4] & 0x80) throw new Error('R value is negative')
24295 if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) throw new Error('R value excessively padded')
24296
24297 if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative')
24298 if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) throw new Error('S value excessively padded')
24299
24300 // non-BIP66 - extract R, S values
24301 return {
24302 r: buffer.slice(4, 4 + lenR),
24303 s: buffer.slice(6 + lenR)
24304 }
24305}
24306
24307/*
24308 * Expects r and s to be positive DER integers.
24309 *
24310 * The DER format uses the most significant bit as a sign bit (& 0x80).
24311 * If the significant bit is set AND the integer is positive, a 0x00 is prepended.
24312 *
24313 * Examples:
24314 *
24315 * 0 => 0x00
24316 * 1 => 0x01
24317 * -1 => 0xff
24318 * 127 => 0x7f
24319 * -127 => 0x81
24320 * 128 => 0x0080
24321 * -128 => 0x80
24322 * 255 => 0x00ff
24323 * -255 => 0xff01
24324 * 16300 => 0x3fac
24325 * -16300 => 0xc054
24326 * 62300 => 0x00f35c
24327 * -62300 => 0xff0ca4
24328*/
24329function encode (r, s) {
24330 var lenR = r.length
24331 var lenS = s.length
24332 if (lenR === 0) throw new Error('R length is zero')
24333 if (lenS === 0) throw new Error('S length is zero')
24334 if (lenR > 33) throw new Error('R length is too long')
24335 if (lenS > 33) throw new Error('S length is too long')
24336 if (r[0] & 0x80) throw new Error('R value is negative')
24337 if (s[0] & 0x80) throw new Error('S value is negative')
24338 if (lenR > 1 && (r[0] === 0x00) && !(r[1] & 0x80)) throw new Error('R value excessively padded')
24339 if (lenS > 1 && (s[0] === 0x00) && !(s[1] & 0x80)) throw new Error('S value excessively padded')
24340
24341 var signature = new Buffer(6 + lenR + lenS)
24342
24343 // 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
24344 signature[0] = 0x30
24345 signature[1] = signature.length - 2
24346 signature[2] = 0x02
24347 signature[3] = r.length
24348 r.copy(signature, 4)
24349 signature[4 + lenR] = 0x02
24350 signature[5 + lenR] = s.length
24351 s.copy(signature, 6 + lenR)
24352
24353 return signature
24354}
24355
24356module.exports = {
24357 check: check,
24358 decode: decode,
24359 encode: encode
24360}
24361
24362}).call(this,require("buffer").Buffer)
24363},{"buffer":5}],33:[function(require,module,exports){
24364(function (module, exports) {
24365 'use strict';
24366
24367 // Utils
24368 function assert (val, msg) {
24369 if (!val) throw new Error(msg || 'Assertion failed');
24370 }
24371
24372 // Could use `inherits` module, but don't want to move from single file
24373 // architecture yet.
24374 function inherits (ctor, superCtor) {
24375 ctor.super_ = superCtor;
24376 var TempCtor = function () {};
24377 TempCtor.prototype = superCtor.prototype;
24378 ctor.prototype = new TempCtor();
24379 ctor.prototype.constructor = ctor;
24380 }
24381
24382 // BN
24383
24384 function BN (number, base, endian) {
24385 if (BN.isBN(number)) {
24386 return number;
24387 }
24388
24389 this.negative = 0;
24390 this.words = null;
24391 this.length = 0;
24392
24393 // Reduction context
24394 this.red = null;
24395
24396 if (number !== null) {
24397 if (base === 'le' || base === 'be') {
24398 endian = base;
24399 base = 10;
24400 }
24401
24402 this._init(number || 0, base || 10, endian || 'be');
24403 }
24404 }
24405 if (typeof module === 'object') {
24406 module.exports = BN;
24407 } else {
24408 exports.BN = BN;
24409 }
24410
24411 BN.BN = BN;
24412 BN.wordSize = 26;
24413
24414 var Buffer;
24415 try {
24416 Buffer = require('buf' + 'fer').Buffer;
24417 } catch (e) {
24418 }
24419
24420 BN.isBN = function isBN (num) {
24421 if (num instanceof BN) {
24422 return true;
24423 }
24424
24425 return num !== null && typeof num === 'object' &&
24426 num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
24427 };
24428
24429 BN.max = function max (left, right) {
24430 if (left.cmp(right) > 0) return left;
24431 return right;
24432 };
24433
24434 BN.min = function min (left, right) {
24435 if (left.cmp(right) < 0) return left;
24436 return right;
24437 };
24438
24439 BN.prototype._init = function init (number, base, endian) {
24440 if (typeof number === 'number') {
24441 return this._initNumber(number, base, endian);
24442 }
24443
24444 if (typeof number === 'object') {
24445 return this._initArray(number, base, endian);
24446 }
24447
24448 if (base === 'hex') {
24449 base = 16;
24450 }
24451 assert(base === (base | 0) && base >= 2 && base <= 36);
24452
24453 number = number.toString().replace(/\s+/g, '');
24454 var start = 0;
24455 if (number[0] === '-') {
24456 start++;
24457 }
24458
24459 if (base === 16) {
24460 this._parseHex(number, start);
24461 } else {
24462 this._parseBase(number, base, start);
24463 }
24464
24465 if (number[0] === '-') {
24466 this.negative = 1;
24467 }
24468
24469 this.strip();
24470
24471 if (endian !== 'le') return;
24472
24473 this._initArray(this.toArray(), base, endian);
24474 };
24475
24476 BN.prototype._initNumber = function _initNumber (number, base, endian) {
24477 if (number < 0) {
24478 this.negative = 1;
24479 number = -number;
24480 }
24481 if (number < 0x4000000) {
24482 this.words = [ number & 0x3ffffff ];
24483 this.length = 1;
24484 } else if (number < 0x10000000000000) {
24485 this.words = [
24486 number & 0x3ffffff,
24487 (number / 0x4000000) & 0x3ffffff
24488 ];
24489 this.length = 2;
24490 } else {
24491 assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
24492 this.words = [
24493 number & 0x3ffffff,
24494 (number / 0x4000000) & 0x3ffffff,
24495 1
24496 ];
24497 this.length = 3;
24498 }
24499
24500 if (endian !== 'le') return;
24501
24502 // Reverse the bytes
24503 this._initArray(this.toArray(), base, endian);
24504 };
24505
24506 BN.prototype._initArray = function _initArray (number, base, endian) {
24507 // Perhaps a Uint8Array
24508 assert(typeof number.length === 'number');
24509 if (number.length <= 0) {
24510 this.words = [ 0 ];
24511 this.length = 1;
24512 return this;
24513 }
24514
24515 this.length = Math.ceil(number.length / 3);
24516 this.words = new Array(this.length);
24517 for (var i = 0; i < this.length; i++) {
24518 this.words[i] = 0;
24519 }
24520
24521 var j, w;
24522 var off = 0;
24523 if (endian === 'be') {
24524 for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
24525 w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
24526 this.words[j] |= (w << off) & 0x3ffffff;
24527 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
24528 off += 24;
24529 if (off >= 26) {
24530 off -= 26;
24531 j++;
24532 }
24533 }
24534 } else if (endian === 'le') {
24535 for (i = 0, j = 0; i < number.length; i += 3) {
24536 w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
24537 this.words[j] |= (w << off) & 0x3ffffff;
24538 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
24539 off += 24;
24540 if (off >= 26) {
24541 off -= 26;
24542 j++;
24543 }
24544 }
24545 }
24546 return this.strip();
24547 };
24548
24549 function parseHex (str, start, end) {
24550 var r = 0;
24551 var len = Math.min(str.length, end);
24552 for (var i = start; i < len; i++) {
24553 var c = str.charCodeAt(i) - 48;
24554
24555 r <<= 4;
24556
24557 // 'a' - 'f'
24558 if (c >= 49 && c <= 54) {
24559 r |= c - 49 + 0xa;
24560
24561 // 'A' - 'F'
24562 } else if (c >= 17 && c <= 22) {
24563 r |= c - 17 + 0xa;
24564
24565 // '0' - '9'
24566 } else {
24567 r |= c & 0xf;
24568 }
24569 }
24570 return r;
24571 }
24572
24573 BN.prototype._parseHex = function _parseHex (number, start) {
24574 // Create possibly bigger array to ensure that it fits the number
24575 this.length = Math.ceil((number.length - start) / 6);
24576 this.words = new Array(this.length);
24577 for (var i = 0; i < this.length; i++) {
24578 this.words[i] = 0;
24579 }
24580
24581 var j, w;
24582 // Scan 24-bit chunks and add them to the number
24583 var off = 0;
24584 for (i = number.length - 6, j = 0; i >= start; i -= 6) {
24585 w = parseHex(number, i, i + 6);
24586 this.words[j] |= (w << off) & 0x3ffffff;
24587 // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
24588 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
24589 off += 24;
24590 if (off >= 26) {
24591 off -= 26;
24592 j++;
24593 }
24594 }
24595 if (i + 6 !== start) {
24596 w = parseHex(number, start, i + 6);
24597 this.words[j] |= (w << off) & 0x3ffffff;
24598 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
24599 }
24600 this.strip();
24601 };
24602
24603 function parseBase (str, start, end, mul) {
24604 var r = 0;
24605 var len = Math.min(str.length, end);
24606 for (var i = start; i < len; i++) {
24607 var c = str.charCodeAt(i) - 48;
24608
24609 r *= mul;
24610
24611 // 'a'
24612 if (c >= 49) {
24613 r += c - 49 + 0xa;
24614
24615 // 'A'
24616 } else if (c >= 17) {
24617 r += c - 17 + 0xa;
24618
24619 // '0' - '9'
24620 } else {
24621 r += c;
24622 }
24623 }
24624 return r;
24625 }
24626
24627 BN.prototype._parseBase = function _parseBase (number, base, start) {
24628 // Initialize as zero
24629 this.words = [ 0 ];
24630 this.length = 1;
24631
24632 // Find length of limb in base
24633 for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
24634 limbLen++;
24635 }
24636 limbLen--;
24637 limbPow = (limbPow / base) | 0;
24638
24639 var total = number.length - start;
24640 var mod = total % limbLen;
24641 var end = Math.min(total, total - mod) + start;
24642
24643 var word = 0;
24644 for (var i = start; i < end; i += limbLen) {
24645 word = parseBase(number, i, i + limbLen, base);
24646
24647 this.imuln(limbPow);
24648 if (this.words[0] + word < 0x4000000) {
24649 this.words[0] += word;
24650 } else {
24651 this._iaddn(word);
24652 }
24653 }
24654
24655 if (mod !== 0) {
24656 var pow = 1;
24657 word = parseBase(number, i, number.length, base);
24658
24659 for (i = 0; i < mod; i++) {
24660 pow *= base;
24661 }
24662
24663 this.imuln(pow);
24664 if (this.words[0] + word < 0x4000000) {
24665 this.words[0] += word;
24666 } else {
24667 this._iaddn(word);
24668 }
24669 }
24670 };
24671
24672 BN.prototype.copy = function copy (dest) {
24673 dest.words = new Array(this.length);
24674 for (var i = 0; i < this.length; i++) {
24675 dest.words[i] = this.words[i];
24676 }
24677 dest.length = this.length;
24678 dest.negative = this.negative;
24679 dest.red = this.red;
24680 };
24681
24682 BN.prototype.clone = function clone () {
24683 var r = new BN(null);
24684 this.copy(r);
24685 return r;
24686 };
24687
24688 BN.prototype._expand = function _expand (size) {
24689 while (this.length < size) {
24690 this.words[this.length++] = 0;
24691 }
24692 return this;
24693 };
24694
24695 // Remove leading `0` from `this`
24696 BN.prototype.strip = function strip () {
24697 while (this.length > 1 && this.words[this.length - 1] === 0) {
24698 this.length--;
24699 }
24700 return this._normSign();
24701 };
24702
24703 BN.prototype._normSign = function _normSign () {
24704 // -0 = 0
24705 if (this.length === 1 && this.words[0] === 0) {
24706 this.negative = 0;
24707 }
24708 return this;
24709 };
24710
24711 BN.prototype.inspect = function inspect () {
24712 return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
24713 };
24714
24715 /*
24716
24717 var zeros = [];
24718 var groupSizes = [];
24719 var groupBases = [];
24720
24721 var s = '';
24722 var i = -1;
24723 while (++i < BN.wordSize) {
24724 zeros[i] = s;
24725 s += '0';
24726 }
24727 groupSizes[0] = 0;
24728 groupSizes[1] = 0;
24729 groupBases[0] = 0;
24730 groupBases[1] = 0;
24731 var base = 2 - 1;
24732 while (++base < 36 + 1) {
24733 var groupSize = 0;
24734 var groupBase = 1;
24735 while (groupBase < (1 << BN.wordSize) / base) {
24736 groupBase *= base;
24737 groupSize += 1;
24738 }
24739 groupSizes[base] = groupSize;
24740 groupBases[base] = groupBase;
24741 }
24742
24743 */
24744
24745 var zeros = [
24746 '',
24747 '0',
24748 '00',
24749 '000',
24750 '0000',
24751 '00000',
24752 '000000',
24753 '0000000',
24754 '00000000',
24755 '000000000',
24756 '0000000000',
24757 '00000000000',
24758 '000000000000',
24759 '0000000000000',
24760 '00000000000000',
24761 '000000000000000',
24762 '0000000000000000',
24763 '00000000000000000',
24764 '000000000000000000',
24765 '0000000000000000000',
24766 '00000000000000000000',
24767 '000000000000000000000',
24768 '0000000000000000000000',
24769 '00000000000000000000000',
24770 '000000000000000000000000',
24771 '0000000000000000000000000'
24772 ];
24773
24774 var groupSizes = [
24775 0, 0,
24776 25, 16, 12, 11, 10, 9, 8,
24777 8, 7, 7, 7, 7, 6, 6,
24778 6, 6, 6, 6, 6, 5, 5,
24779 5, 5, 5, 5, 5, 5, 5,
24780 5, 5, 5, 5, 5, 5, 5
24781 ];
24782
24783 var groupBases = [
24784 0, 0,
24785 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
24786 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
24787 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
24788 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
24789 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
24790 ];
24791
24792 BN.prototype.toString = function toString (base, padding) {
24793 base = base || 10;
24794 padding = padding | 0 || 1;
24795
24796 var out;
24797 if (base === 16 || base === 'hex') {
24798 out = '';
24799 var off = 0;
24800 var carry = 0;
24801 for (var i = 0; i < this.length; i++) {
24802 var w = this.words[i];
24803 var word = (((w << off) | carry) & 0xffffff).toString(16);
24804 carry = (w >>> (24 - off)) & 0xffffff;
24805 if (carry !== 0 || i !== this.length - 1) {
24806 out = zeros[6 - word.length] + word + out;
24807 } else {
24808 out = word + out;
24809 }
24810 off += 2;
24811 if (off >= 26) {
24812 off -= 26;
24813 i--;
24814 }
24815 }
24816 if (carry !== 0) {
24817 out = carry.toString(16) + out;
24818 }
24819 while (out.length % padding !== 0) {
24820 out = '0' + out;
24821 }
24822 if (this.negative !== 0) {
24823 out = '-' + out;
24824 }
24825 return out;
24826 }
24827
24828 if (base === (base | 0) && base >= 2 && base <= 36) {
24829 // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
24830 var groupSize = groupSizes[base];
24831 // var groupBase = Math.pow(base, groupSize);
24832 var groupBase = groupBases[base];
24833 out = '';
24834 var c = this.clone();
24835 c.negative = 0;
24836 while (!c.isZero()) {
24837 var r = c.modn(groupBase).toString(base);
24838 c = c.idivn(groupBase);
24839
24840 if (!c.isZero()) {
24841 out = zeros[groupSize - r.length] + r + out;
24842 } else {
24843 out = r + out;
24844 }
24845 }
24846 if (this.isZero()) {
24847 out = '0' + out;
24848 }
24849 while (out.length % padding !== 0) {
24850 out = '0' + out;
24851 }
24852 if (this.negative !== 0) {
24853 out = '-' + out;
24854 }
24855 return out;
24856 }
24857
24858 assert(false, 'Base should be between 2 and 36');
24859 };
24860
24861 BN.prototype.toNumber = function toNumber () {
24862 var ret = this.words[0];
24863 if (this.length === 2) {
24864 ret += this.words[1] * 0x4000000;
24865 } else if (this.length === 3 && this.words[2] === 0x01) {
24866 // NOTE: at this stage it is known that the top bit is set
24867 ret += 0x10000000000000 + (this.words[1] * 0x4000000);
24868 } else if (this.length > 2) {
24869 assert(false, 'Number can only safely store up to 53 bits');
24870 }
24871 return (this.negative !== 0) ? -ret : ret;
24872 };
24873
24874 BN.prototype.toJSON = function toJSON () {
24875 return this.toString(16);
24876 };
24877
24878 BN.prototype.toBuffer = function toBuffer (endian, length) {
24879 assert(typeof Buffer !== 'undefined');
24880 return this.toArrayLike(Buffer, endian, length);
24881 };
24882
24883 BN.prototype.toArray = function toArray (endian, length) {
24884 return this.toArrayLike(Array, endian, length);
24885 };
24886
24887 BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
24888 var byteLength = this.byteLength();
24889 var reqLength = length || Math.max(1, byteLength);
24890 assert(byteLength <= reqLength, 'byte array longer than desired length');
24891 assert(reqLength > 0, 'Requested array length <= 0');
24892
24893 this.strip();
24894 var littleEndian = endian === 'le';
24895 var res = new ArrayType(reqLength);
24896
24897 var b, i;
24898 var q = this.clone();
24899 if (!littleEndian) {
24900 // Assume big-endian
24901 for (i = 0; i < reqLength - byteLength; i++) {
24902 res[i] = 0;
24903 }
24904
24905 for (i = 0; !q.isZero(); i++) {
24906 b = q.andln(0xff);
24907 q.iushrn(8);
24908
24909 res[reqLength - i - 1] = b;
24910 }
24911 } else {
24912 for (i = 0; !q.isZero(); i++) {
24913 b = q.andln(0xff);
24914 q.iushrn(8);
24915
24916 res[i] = b;
24917 }
24918
24919 for (; i < reqLength; i++) {
24920 res[i] = 0;
24921 }
24922 }
24923
24924 return res;
24925 };
24926
24927 if (Math.clz32) {
24928 BN.prototype._countBits = function _countBits (w) {
24929 return 32 - Math.clz32(w);
24930 };
24931 } else {
24932 BN.prototype._countBits = function _countBits (w) {
24933 var t = w;
24934 var r = 0;
24935 if (t >= 0x1000) {
24936 r += 13;
24937 t >>>= 13;
24938 }
24939 if (t >= 0x40) {
24940 r += 7;
24941 t >>>= 7;
24942 }
24943 if (t >= 0x8) {
24944 r += 4;
24945 t >>>= 4;
24946 }
24947 if (t >= 0x02) {
24948 r += 2;
24949 t >>>= 2;
24950 }
24951 return r + t;
24952 };
24953 }
24954
24955 BN.prototype._zeroBits = function _zeroBits (w) {
24956 // Short-cut
24957 if (w === 0) return 26;
24958
24959 var t = w;
24960 var r = 0;
24961 if ((t & 0x1fff) === 0) {
24962 r += 13;
24963 t >>>= 13;
24964 }
24965 if ((t & 0x7f) === 0) {
24966 r += 7;
24967 t >>>= 7;
24968 }
24969 if ((t & 0xf) === 0) {
24970 r += 4;
24971 t >>>= 4;
24972 }
24973 if ((t & 0x3) === 0) {
24974 r += 2;
24975 t >>>= 2;
24976 }
24977 if ((t & 0x1) === 0) {
24978 r++;
24979 }
24980 return r;
24981 };
24982
24983 // Return number of used bits in a BN
24984 BN.prototype.bitLength = function bitLength () {
24985 var w = this.words[this.length - 1];
24986 var hi = this._countBits(w);
24987 return (this.length - 1) * 26 + hi;
24988 };
24989
24990 function toBitArray (num) {
24991 var w = new Array(num.bitLength());
24992
24993 for (var bit = 0; bit < w.length; bit++) {
24994 var off = (bit / 26) | 0;
24995 var wbit = bit % 26;
24996
24997 w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
24998 }
24999
25000 return w;
25001 }
25002
25003 // Number of trailing zero bits
25004 BN.prototype.zeroBits = function zeroBits () {
25005 if (this.isZero()) return 0;
25006
25007 var r = 0;
25008 for (var i = 0; i < this.length; i++) {
25009 var b = this._zeroBits(this.words[i]);
25010 r += b;
25011 if (b !== 26) break;
25012 }
25013 return r;
25014 };
25015
25016 BN.prototype.byteLength = function byteLength () {
25017 return Math.ceil(this.bitLength() / 8);
25018 };
25019
25020 BN.prototype.toTwos = function toTwos (width) {
25021 if (this.negative !== 0) {
25022 return this.abs().inotn(width).iaddn(1);
25023 }
25024 return this.clone();
25025 };
25026
25027 BN.prototype.fromTwos = function fromTwos (width) {
25028 if (this.testn(width - 1)) {
25029 return this.notn(width).iaddn(1).ineg();
25030 }
25031 return this.clone();
25032 };
25033
25034 BN.prototype.isNeg = function isNeg () {
25035 return this.negative !== 0;
25036 };
25037
25038 // Return negative clone of `this`
25039 BN.prototype.neg = function neg () {
25040 return this.clone().ineg();
25041 };
25042
25043 BN.prototype.ineg = function ineg () {
25044 if (!this.isZero()) {
25045 this.negative ^= 1;
25046 }
25047
25048 return this;
25049 };
25050
25051 // Or `num` with `this` in-place
25052 BN.prototype.iuor = function iuor (num) {
25053 while (this.length < num.length) {
25054 this.words[this.length++] = 0;
25055 }
25056
25057 for (var i = 0; i < num.length; i++) {
25058 this.words[i] = this.words[i] | num.words[i];
25059 }
25060
25061 return this.strip();
25062 };
25063
25064 BN.prototype.ior = function ior (num) {
25065 assert((this.negative | num.negative) === 0);
25066 return this.iuor(num);
25067 };
25068
25069 // Or `num` with `this`
25070 BN.prototype.or = function or (num) {
25071 if (this.length > num.length) return this.clone().ior(num);
25072 return num.clone().ior(this);
25073 };
25074
25075 BN.prototype.uor = function uor (num) {
25076 if (this.length > num.length) return this.clone().iuor(num);
25077 return num.clone().iuor(this);
25078 };
25079
25080 // And `num` with `this` in-place
25081 BN.prototype.iuand = function iuand (num) {
25082 // b = min-length(num, this)
25083 var b;
25084 if (this.length > num.length) {
25085 b = num;
25086 } else {
25087 b = this;
25088 }
25089
25090 for (var i = 0; i < b.length; i++) {
25091 this.words[i] = this.words[i] & num.words[i];
25092 }
25093
25094 this.length = b.length;
25095
25096 return this.strip();
25097 };
25098
25099 BN.prototype.iand = function iand (num) {
25100 assert((this.negative | num.negative) === 0);
25101 return this.iuand(num);
25102 };
25103
25104 // And `num` with `this`
25105 BN.prototype.and = function and (num) {
25106 if (this.length > num.length) return this.clone().iand(num);
25107 return num.clone().iand(this);
25108 };
25109
25110 BN.prototype.uand = function uand (num) {
25111 if (this.length > num.length) return this.clone().iuand(num);
25112 return num.clone().iuand(this);
25113 };
25114
25115 // Xor `num` with `this` in-place
25116 BN.prototype.iuxor = function iuxor (num) {
25117 // a.length > b.length
25118 var a;
25119 var b;
25120 if (this.length > num.length) {
25121 a = this;
25122 b = num;
25123 } else {
25124 a = num;
25125 b = this;
25126 }
25127
25128 for (var i = 0; i < b.length; i++) {
25129 this.words[i] = a.words[i] ^ b.words[i];
25130 }
25131
25132 if (this !== a) {
25133 for (; i < a.length; i++) {
25134 this.words[i] = a.words[i];
25135 }
25136 }
25137
25138 this.length = a.length;
25139
25140 return this.strip();
25141 };
25142
25143 BN.prototype.ixor = function ixor (num) {
25144 assert((this.negative | num.negative) === 0);
25145 return this.iuxor(num);
25146 };
25147
25148 // Xor `num` with `this`
25149 BN.prototype.xor = function xor (num) {
25150 if (this.length > num.length) return this.clone().ixor(num);
25151 return num.clone().ixor(this);
25152 };
25153
25154 BN.prototype.uxor = function uxor (num) {
25155 if (this.length > num.length) return this.clone().iuxor(num);
25156 return num.clone().iuxor(this);
25157 };
25158
25159 // Not ``this`` with ``width`` bitwidth
25160 BN.prototype.inotn = function inotn (width) {
25161 assert(typeof width === 'number' && width >= 0);
25162
25163 var bytesNeeded = Math.ceil(width / 26) | 0;
25164 var bitsLeft = width % 26;
25165
25166 // Extend the buffer with leading zeroes
25167 this._expand(bytesNeeded);
25168
25169 if (bitsLeft > 0) {
25170 bytesNeeded--;
25171 }
25172
25173 // Handle complete words
25174 for (var i = 0; i < bytesNeeded; i++) {
25175 this.words[i] = ~this.words[i] & 0x3ffffff;
25176 }
25177
25178 // Handle the residue
25179 if (bitsLeft > 0) {
25180 this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
25181 }
25182
25183 // And remove leading zeroes
25184 return this.strip();
25185 };
25186
25187 BN.prototype.notn = function notn (width) {
25188 return this.clone().inotn(width);
25189 };
25190
25191 // Set `bit` of `this`
25192 BN.prototype.setn = function setn (bit, val) {
25193 assert(typeof bit === 'number' && bit >= 0);
25194
25195 var off = (bit / 26) | 0;
25196 var wbit = bit % 26;
25197
25198 this._expand(off + 1);
25199
25200 if (val) {
25201 this.words[off] = this.words[off] | (1 << wbit);
25202 } else {
25203 this.words[off] = this.words[off] & ~(1 << wbit);
25204 }
25205
25206 return this.strip();
25207 };
25208
25209 // Add `num` to `this` in-place
25210 BN.prototype.iadd = function iadd (num) {
25211 var r;
25212
25213 // negative + positive
25214 if (this.negative !== 0 && num.negative === 0) {
25215 this.negative = 0;
25216 r = this.isub(num);
25217 this.negative ^= 1;
25218 return this._normSign();
25219
25220 // positive + negative
25221 } else if (this.negative === 0 && num.negative !== 0) {
25222 num.negative = 0;
25223 r = this.isub(num);
25224 num.negative = 1;
25225 return r._normSign();
25226 }
25227
25228 // a.length > b.length
25229 var a, b;
25230 if (this.length > num.length) {
25231 a = this;
25232 b = num;
25233 } else {
25234 a = num;
25235 b = this;
25236 }
25237
25238 var carry = 0;
25239 for (var i = 0; i < b.length; i++) {
25240 r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
25241 this.words[i] = r & 0x3ffffff;
25242 carry = r >>> 26;
25243 }
25244 for (; carry !== 0 && i < a.length; i++) {
25245 r = (a.words[i] | 0) + carry;
25246 this.words[i] = r & 0x3ffffff;
25247 carry = r >>> 26;
25248 }
25249
25250 this.length = a.length;
25251 if (carry !== 0) {
25252 this.words[this.length] = carry;
25253 this.length++;
25254 // Copy the rest of the words
25255 } else if (a !== this) {
25256 for (; i < a.length; i++) {
25257 this.words[i] = a.words[i];
25258 }
25259 }
25260
25261 return this;
25262 };
25263
25264 // Add `num` to `this`
25265 BN.prototype.add = function add (num) {
25266 var res;
25267 if (num.negative !== 0 && this.negative === 0) {
25268 num.negative = 0;
25269 res = this.sub(num);
25270 num.negative ^= 1;
25271 return res;
25272 } else if (num.negative === 0 && this.negative !== 0) {
25273 this.negative = 0;
25274 res = num.sub(this);
25275 this.negative = 1;
25276 return res;
25277 }
25278
25279 if (this.length > num.length) return this.clone().iadd(num);
25280
25281 return num.clone().iadd(this);
25282 };
25283
25284 // Subtract `num` from `this` in-place
25285 BN.prototype.isub = function isub (num) {
25286 // this - (-num) = this + num
25287 if (num.negative !== 0) {
25288 num.negative = 0;
25289 var r = this.iadd(num);
25290 num.negative = 1;
25291 return r._normSign();
25292
25293 // -this - num = -(this + num)
25294 } else if (this.negative !== 0) {
25295 this.negative = 0;
25296 this.iadd(num);
25297 this.negative = 1;
25298 return this._normSign();
25299 }
25300
25301 // At this point both numbers are positive
25302 var cmp = this.cmp(num);
25303
25304 // Optimization - zeroify
25305 if (cmp === 0) {
25306 this.negative = 0;
25307 this.length = 1;
25308 this.words[0] = 0;
25309 return this;
25310 }
25311
25312 // a > b
25313 var a, b;
25314 if (cmp > 0) {
25315 a = this;
25316 b = num;
25317 } else {
25318 a = num;
25319 b = this;
25320 }
25321
25322 var carry = 0;
25323 for (var i = 0; i < b.length; i++) {
25324 r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
25325 carry = r >> 26;
25326 this.words[i] = r & 0x3ffffff;
25327 }
25328 for (; carry !== 0 && i < a.length; i++) {
25329 r = (a.words[i] | 0) + carry;
25330 carry = r >> 26;
25331 this.words[i] = r & 0x3ffffff;
25332 }
25333
25334 // Copy rest of the words
25335 if (carry === 0 && i < a.length && a !== this) {
25336 for (; i < a.length; i++) {
25337 this.words[i] = a.words[i];
25338 }
25339 }
25340
25341 this.length = Math.max(this.length, i);
25342
25343 if (a !== this) {
25344 this.negative = 1;
25345 }
25346
25347 return this.strip();
25348 };
25349
25350 // Subtract `num` from `this`
25351 BN.prototype.sub = function sub (num) {
25352 return this.clone().isub(num);
25353 };
25354
25355 function smallMulTo (self, num, out) {
25356 out.negative = num.negative ^ self.negative;
25357 var len = (self.length + num.length) | 0;
25358 out.length = len;
25359 len = (len - 1) | 0;
25360
25361 // Peel one iteration (compiler can't do it, because of code complexity)
25362 var a = self.words[0] | 0;
25363 var b = num.words[0] | 0;
25364 var r = a * b;
25365
25366 var lo = r & 0x3ffffff;
25367 var carry = (r / 0x4000000) | 0;
25368 out.words[0] = lo;
25369
25370 for (var k = 1; k < len; k++) {
25371 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
25372 // note that ncarry could be >= 0x3ffffff
25373 var ncarry = carry >>> 26;
25374 var rword = carry & 0x3ffffff;
25375 var maxJ = Math.min(k, num.length - 1);
25376 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
25377 var i = (k - j) | 0;
25378 a = self.words[i] | 0;
25379 b = num.words[j] | 0;
25380 r = a * b + rword;
25381 ncarry += (r / 0x4000000) | 0;
25382 rword = r & 0x3ffffff;
25383 }
25384 out.words[k] = rword | 0;
25385 carry = ncarry | 0;
25386 }
25387 if (carry !== 0) {
25388 out.words[k] = carry | 0;
25389 } else {
25390 out.length--;
25391 }
25392
25393 return out.strip();
25394 }
25395
25396 // TODO(indutny): it may be reasonable to omit it for users who don't need
25397 // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
25398 // multiplication (like elliptic secp256k1).
25399 var comb10MulTo = function comb10MulTo (self, num, out) {
25400 var a = self.words;
25401 var b = num.words;
25402 var o = out.words;
25403 var c = 0;
25404 var lo;
25405 var mid;
25406 var hi;
25407 var a0 = a[0] | 0;
25408 var al0 = a0 & 0x1fff;
25409 var ah0 = a0 >>> 13;
25410 var a1 = a[1] | 0;
25411 var al1 = a1 & 0x1fff;
25412 var ah1 = a1 >>> 13;
25413 var a2 = a[2] | 0;
25414 var al2 = a2 & 0x1fff;
25415 var ah2 = a2 >>> 13;
25416 var a3 = a[3] | 0;
25417 var al3 = a3 & 0x1fff;
25418 var ah3 = a3 >>> 13;
25419 var a4 = a[4] | 0;
25420 var al4 = a4 & 0x1fff;
25421 var ah4 = a4 >>> 13;
25422 var a5 = a[5] | 0;
25423 var al5 = a5 & 0x1fff;
25424 var ah5 = a5 >>> 13;
25425 var a6 = a[6] | 0;
25426 var al6 = a6 & 0x1fff;
25427 var ah6 = a6 >>> 13;
25428 var a7 = a[7] | 0;
25429 var al7 = a7 & 0x1fff;
25430 var ah7 = a7 >>> 13;
25431 var a8 = a[8] | 0;
25432 var al8 = a8 & 0x1fff;
25433 var ah8 = a8 >>> 13;
25434 var a9 = a[9] | 0;
25435 var al9 = a9 & 0x1fff;
25436 var ah9 = a9 >>> 13;
25437 var b0 = b[0] | 0;
25438 var bl0 = b0 & 0x1fff;
25439 var bh0 = b0 >>> 13;
25440 var b1 = b[1] | 0;
25441 var bl1 = b1 & 0x1fff;
25442 var bh1 = b1 >>> 13;
25443 var b2 = b[2] | 0;
25444 var bl2 = b2 & 0x1fff;
25445 var bh2 = b2 >>> 13;
25446 var b3 = b[3] | 0;
25447 var bl3 = b3 & 0x1fff;
25448 var bh3 = b3 >>> 13;
25449 var b4 = b[4] | 0;
25450 var bl4 = b4 & 0x1fff;
25451 var bh4 = b4 >>> 13;
25452 var b5 = b[5] | 0;
25453 var bl5 = b5 & 0x1fff;
25454 var bh5 = b5 >>> 13;
25455 var b6 = b[6] | 0;
25456 var bl6 = b6 & 0x1fff;
25457 var bh6 = b6 >>> 13;
25458 var b7 = b[7] | 0;
25459 var bl7 = b7 & 0x1fff;
25460 var bh7 = b7 >>> 13;
25461 var b8 = b[8] | 0;
25462 var bl8 = b8 & 0x1fff;
25463 var bh8 = b8 >>> 13;
25464 var b9 = b[9] | 0;
25465 var bl9 = b9 & 0x1fff;
25466 var bh9 = b9 >>> 13;
25467
25468 out.negative = self.negative ^ num.negative;
25469 out.length = 19;
25470 /* k = 0 */
25471 lo = Math.imul(al0, bl0);
25472 mid = Math.imul(al0, bh0);
25473 mid = (mid + Math.imul(ah0, bl0)) | 0;
25474 hi = Math.imul(ah0, bh0);
25475 var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25476 c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
25477 w0 &= 0x3ffffff;
25478 /* k = 1 */
25479 lo = Math.imul(al1, bl0);
25480 mid = Math.imul(al1, bh0);
25481 mid = (mid + Math.imul(ah1, bl0)) | 0;
25482 hi = Math.imul(ah1, bh0);
25483 lo = (lo + Math.imul(al0, bl1)) | 0;
25484 mid = (mid + Math.imul(al0, bh1)) | 0;
25485 mid = (mid + Math.imul(ah0, bl1)) | 0;
25486 hi = (hi + Math.imul(ah0, bh1)) | 0;
25487 var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25488 c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
25489 w1 &= 0x3ffffff;
25490 /* k = 2 */
25491 lo = Math.imul(al2, bl0);
25492 mid = Math.imul(al2, bh0);
25493 mid = (mid + Math.imul(ah2, bl0)) | 0;
25494 hi = Math.imul(ah2, bh0);
25495 lo = (lo + Math.imul(al1, bl1)) | 0;
25496 mid = (mid + Math.imul(al1, bh1)) | 0;
25497 mid = (mid + Math.imul(ah1, bl1)) | 0;
25498 hi = (hi + Math.imul(ah1, bh1)) | 0;
25499 lo = (lo + Math.imul(al0, bl2)) | 0;
25500 mid = (mid + Math.imul(al0, bh2)) | 0;
25501 mid = (mid + Math.imul(ah0, bl2)) | 0;
25502 hi = (hi + Math.imul(ah0, bh2)) | 0;
25503 var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25504 c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
25505 w2 &= 0x3ffffff;
25506 /* k = 3 */
25507 lo = Math.imul(al3, bl0);
25508 mid = Math.imul(al3, bh0);
25509 mid = (mid + Math.imul(ah3, bl0)) | 0;
25510 hi = Math.imul(ah3, bh0);
25511 lo = (lo + Math.imul(al2, bl1)) | 0;
25512 mid = (mid + Math.imul(al2, bh1)) | 0;
25513 mid = (mid + Math.imul(ah2, bl1)) | 0;
25514 hi = (hi + Math.imul(ah2, bh1)) | 0;
25515 lo = (lo + Math.imul(al1, bl2)) | 0;
25516 mid = (mid + Math.imul(al1, bh2)) | 0;
25517 mid = (mid + Math.imul(ah1, bl2)) | 0;
25518 hi = (hi + Math.imul(ah1, bh2)) | 0;
25519 lo = (lo + Math.imul(al0, bl3)) | 0;
25520 mid = (mid + Math.imul(al0, bh3)) | 0;
25521 mid = (mid + Math.imul(ah0, bl3)) | 0;
25522 hi = (hi + Math.imul(ah0, bh3)) | 0;
25523 var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25524 c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
25525 w3 &= 0x3ffffff;
25526 /* k = 4 */
25527 lo = Math.imul(al4, bl0);
25528 mid = Math.imul(al4, bh0);
25529 mid = (mid + Math.imul(ah4, bl0)) | 0;
25530 hi = Math.imul(ah4, bh0);
25531 lo = (lo + Math.imul(al3, bl1)) | 0;
25532 mid = (mid + Math.imul(al3, bh1)) | 0;
25533 mid = (mid + Math.imul(ah3, bl1)) | 0;
25534 hi = (hi + Math.imul(ah3, bh1)) | 0;
25535 lo = (lo + Math.imul(al2, bl2)) | 0;
25536 mid = (mid + Math.imul(al2, bh2)) | 0;
25537 mid = (mid + Math.imul(ah2, bl2)) | 0;
25538 hi = (hi + Math.imul(ah2, bh2)) | 0;
25539 lo = (lo + Math.imul(al1, bl3)) | 0;
25540 mid = (mid + Math.imul(al1, bh3)) | 0;
25541 mid = (mid + Math.imul(ah1, bl3)) | 0;
25542 hi = (hi + Math.imul(ah1, bh3)) | 0;
25543 lo = (lo + Math.imul(al0, bl4)) | 0;
25544 mid = (mid + Math.imul(al0, bh4)) | 0;
25545 mid = (mid + Math.imul(ah0, bl4)) | 0;
25546 hi = (hi + Math.imul(ah0, bh4)) | 0;
25547 var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25548 c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
25549 w4 &= 0x3ffffff;
25550 /* k = 5 */
25551 lo = Math.imul(al5, bl0);
25552 mid = Math.imul(al5, bh0);
25553 mid = (mid + Math.imul(ah5, bl0)) | 0;
25554 hi = Math.imul(ah5, bh0);
25555 lo = (lo + Math.imul(al4, bl1)) | 0;
25556 mid = (mid + Math.imul(al4, bh1)) | 0;
25557 mid = (mid + Math.imul(ah4, bl1)) | 0;
25558 hi = (hi + Math.imul(ah4, bh1)) | 0;
25559 lo = (lo + Math.imul(al3, bl2)) | 0;
25560 mid = (mid + Math.imul(al3, bh2)) | 0;
25561 mid = (mid + Math.imul(ah3, bl2)) | 0;
25562 hi = (hi + Math.imul(ah3, bh2)) | 0;
25563 lo = (lo + Math.imul(al2, bl3)) | 0;
25564 mid = (mid + Math.imul(al2, bh3)) | 0;
25565 mid = (mid + Math.imul(ah2, bl3)) | 0;
25566 hi = (hi + Math.imul(ah2, bh3)) | 0;
25567 lo = (lo + Math.imul(al1, bl4)) | 0;
25568 mid = (mid + Math.imul(al1, bh4)) | 0;
25569 mid = (mid + Math.imul(ah1, bl4)) | 0;
25570 hi = (hi + Math.imul(ah1, bh4)) | 0;
25571 lo = (lo + Math.imul(al0, bl5)) | 0;
25572 mid = (mid + Math.imul(al0, bh5)) | 0;
25573 mid = (mid + Math.imul(ah0, bl5)) | 0;
25574 hi = (hi + Math.imul(ah0, bh5)) | 0;
25575 var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25576 c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
25577 w5 &= 0x3ffffff;
25578 /* k = 6 */
25579 lo = Math.imul(al6, bl0);
25580 mid = Math.imul(al6, bh0);
25581 mid = (mid + Math.imul(ah6, bl0)) | 0;
25582 hi = Math.imul(ah6, bh0);
25583 lo = (lo + Math.imul(al5, bl1)) | 0;
25584 mid = (mid + Math.imul(al5, bh1)) | 0;
25585 mid = (mid + Math.imul(ah5, bl1)) | 0;
25586 hi = (hi + Math.imul(ah5, bh1)) | 0;
25587 lo = (lo + Math.imul(al4, bl2)) | 0;
25588 mid = (mid + Math.imul(al4, bh2)) | 0;
25589 mid = (mid + Math.imul(ah4, bl2)) | 0;
25590 hi = (hi + Math.imul(ah4, bh2)) | 0;
25591 lo = (lo + Math.imul(al3, bl3)) | 0;
25592 mid = (mid + Math.imul(al3, bh3)) | 0;
25593 mid = (mid + Math.imul(ah3, bl3)) | 0;
25594 hi = (hi + Math.imul(ah3, bh3)) | 0;
25595 lo = (lo + Math.imul(al2, bl4)) | 0;
25596 mid = (mid + Math.imul(al2, bh4)) | 0;
25597 mid = (mid + Math.imul(ah2, bl4)) | 0;
25598 hi = (hi + Math.imul(ah2, bh4)) | 0;
25599 lo = (lo + Math.imul(al1, bl5)) | 0;
25600 mid = (mid + Math.imul(al1, bh5)) | 0;
25601 mid = (mid + Math.imul(ah1, bl5)) | 0;
25602 hi = (hi + Math.imul(ah1, bh5)) | 0;
25603 lo = (lo + Math.imul(al0, bl6)) | 0;
25604 mid = (mid + Math.imul(al0, bh6)) | 0;
25605 mid = (mid + Math.imul(ah0, bl6)) | 0;
25606 hi = (hi + Math.imul(ah0, bh6)) | 0;
25607 var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25608 c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
25609 w6 &= 0x3ffffff;
25610 /* k = 7 */
25611 lo = Math.imul(al7, bl0);
25612 mid = Math.imul(al7, bh0);
25613 mid = (mid + Math.imul(ah7, bl0)) | 0;
25614 hi = Math.imul(ah7, bh0);
25615 lo = (lo + Math.imul(al6, bl1)) | 0;
25616 mid = (mid + Math.imul(al6, bh1)) | 0;
25617 mid = (mid + Math.imul(ah6, bl1)) | 0;
25618 hi = (hi + Math.imul(ah6, bh1)) | 0;
25619 lo = (lo + Math.imul(al5, bl2)) | 0;
25620 mid = (mid + Math.imul(al5, bh2)) | 0;
25621 mid = (mid + Math.imul(ah5, bl2)) | 0;
25622 hi = (hi + Math.imul(ah5, bh2)) | 0;
25623 lo = (lo + Math.imul(al4, bl3)) | 0;
25624 mid = (mid + Math.imul(al4, bh3)) | 0;
25625 mid = (mid + Math.imul(ah4, bl3)) | 0;
25626 hi = (hi + Math.imul(ah4, bh3)) | 0;
25627 lo = (lo + Math.imul(al3, bl4)) | 0;
25628 mid = (mid + Math.imul(al3, bh4)) | 0;
25629 mid = (mid + Math.imul(ah3, bl4)) | 0;
25630 hi = (hi + Math.imul(ah3, bh4)) | 0;
25631 lo = (lo + Math.imul(al2, bl5)) | 0;
25632 mid = (mid + Math.imul(al2, bh5)) | 0;
25633 mid = (mid + Math.imul(ah2, bl5)) | 0;
25634 hi = (hi + Math.imul(ah2, bh5)) | 0;
25635 lo = (lo + Math.imul(al1, bl6)) | 0;
25636 mid = (mid + Math.imul(al1, bh6)) | 0;
25637 mid = (mid + Math.imul(ah1, bl6)) | 0;
25638 hi = (hi + Math.imul(ah1, bh6)) | 0;
25639 lo = (lo + Math.imul(al0, bl7)) | 0;
25640 mid = (mid + Math.imul(al0, bh7)) | 0;
25641 mid = (mid + Math.imul(ah0, bl7)) | 0;
25642 hi = (hi + Math.imul(ah0, bh7)) | 0;
25643 var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25644 c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
25645 w7 &= 0x3ffffff;
25646 /* k = 8 */
25647 lo = Math.imul(al8, bl0);
25648 mid = Math.imul(al8, bh0);
25649 mid = (mid + Math.imul(ah8, bl0)) | 0;
25650 hi = Math.imul(ah8, bh0);
25651 lo = (lo + Math.imul(al7, bl1)) | 0;
25652 mid = (mid + Math.imul(al7, bh1)) | 0;
25653 mid = (mid + Math.imul(ah7, bl1)) | 0;
25654 hi = (hi + Math.imul(ah7, bh1)) | 0;
25655 lo = (lo + Math.imul(al6, bl2)) | 0;
25656 mid = (mid + Math.imul(al6, bh2)) | 0;
25657 mid = (mid + Math.imul(ah6, bl2)) | 0;
25658 hi = (hi + Math.imul(ah6, bh2)) | 0;
25659 lo = (lo + Math.imul(al5, bl3)) | 0;
25660 mid = (mid + Math.imul(al5, bh3)) | 0;
25661 mid = (mid + Math.imul(ah5, bl3)) | 0;
25662 hi = (hi + Math.imul(ah5, bh3)) | 0;
25663 lo = (lo + Math.imul(al4, bl4)) | 0;
25664 mid = (mid + Math.imul(al4, bh4)) | 0;
25665 mid = (mid + Math.imul(ah4, bl4)) | 0;
25666 hi = (hi + Math.imul(ah4, bh4)) | 0;
25667 lo = (lo + Math.imul(al3, bl5)) | 0;
25668 mid = (mid + Math.imul(al3, bh5)) | 0;
25669 mid = (mid + Math.imul(ah3, bl5)) | 0;
25670 hi = (hi + Math.imul(ah3, bh5)) | 0;
25671 lo = (lo + Math.imul(al2, bl6)) | 0;
25672 mid = (mid + Math.imul(al2, bh6)) | 0;
25673 mid = (mid + Math.imul(ah2, bl6)) | 0;
25674 hi = (hi + Math.imul(ah2, bh6)) | 0;
25675 lo = (lo + Math.imul(al1, bl7)) | 0;
25676 mid = (mid + Math.imul(al1, bh7)) | 0;
25677 mid = (mid + Math.imul(ah1, bl7)) | 0;
25678 hi = (hi + Math.imul(ah1, bh7)) | 0;
25679 lo = (lo + Math.imul(al0, bl8)) | 0;
25680 mid = (mid + Math.imul(al0, bh8)) | 0;
25681 mid = (mid + Math.imul(ah0, bl8)) | 0;
25682 hi = (hi + Math.imul(ah0, bh8)) | 0;
25683 var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25684 c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
25685 w8 &= 0x3ffffff;
25686 /* k = 9 */
25687 lo = Math.imul(al9, bl0);
25688 mid = Math.imul(al9, bh0);
25689 mid = (mid + Math.imul(ah9, bl0)) | 0;
25690 hi = Math.imul(ah9, bh0);
25691 lo = (lo + Math.imul(al8, bl1)) | 0;
25692 mid = (mid + Math.imul(al8, bh1)) | 0;
25693 mid = (mid + Math.imul(ah8, bl1)) | 0;
25694 hi = (hi + Math.imul(ah8, bh1)) | 0;
25695 lo = (lo + Math.imul(al7, bl2)) | 0;
25696 mid = (mid + Math.imul(al7, bh2)) | 0;
25697 mid = (mid + Math.imul(ah7, bl2)) | 0;
25698 hi = (hi + Math.imul(ah7, bh2)) | 0;
25699 lo = (lo + Math.imul(al6, bl3)) | 0;
25700 mid = (mid + Math.imul(al6, bh3)) | 0;
25701 mid = (mid + Math.imul(ah6, bl3)) | 0;
25702 hi = (hi + Math.imul(ah6, bh3)) | 0;
25703 lo = (lo + Math.imul(al5, bl4)) | 0;
25704 mid = (mid + Math.imul(al5, bh4)) | 0;
25705 mid = (mid + Math.imul(ah5, bl4)) | 0;
25706 hi = (hi + Math.imul(ah5, bh4)) | 0;
25707 lo = (lo + Math.imul(al4, bl5)) | 0;
25708 mid = (mid + Math.imul(al4, bh5)) | 0;
25709 mid = (mid + Math.imul(ah4, bl5)) | 0;
25710 hi = (hi + Math.imul(ah4, bh5)) | 0;
25711 lo = (lo + Math.imul(al3, bl6)) | 0;
25712 mid = (mid + Math.imul(al3, bh6)) | 0;
25713 mid = (mid + Math.imul(ah3, bl6)) | 0;
25714 hi = (hi + Math.imul(ah3, bh6)) | 0;
25715 lo = (lo + Math.imul(al2, bl7)) | 0;
25716 mid = (mid + Math.imul(al2, bh7)) | 0;
25717 mid = (mid + Math.imul(ah2, bl7)) | 0;
25718 hi = (hi + Math.imul(ah2, bh7)) | 0;
25719 lo = (lo + Math.imul(al1, bl8)) | 0;
25720 mid = (mid + Math.imul(al1, bh8)) | 0;
25721 mid = (mid + Math.imul(ah1, bl8)) | 0;
25722 hi = (hi + Math.imul(ah1, bh8)) | 0;
25723 lo = (lo + Math.imul(al0, bl9)) | 0;
25724 mid = (mid + Math.imul(al0, bh9)) | 0;
25725 mid = (mid + Math.imul(ah0, bl9)) | 0;
25726 hi = (hi + Math.imul(ah0, bh9)) | 0;
25727 var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25728 c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
25729 w9 &= 0x3ffffff;
25730 /* k = 10 */
25731 lo = Math.imul(al9, bl1);
25732 mid = Math.imul(al9, bh1);
25733 mid = (mid + Math.imul(ah9, bl1)) | 0;
25734 hi = Math.imul(ah9, bh1);
25735 lo = (lo + Math.imul(al8, bl2)) | 0;
25736 mid = (mid + Math.imul(al8, bh2)) | 0;
25737 mid = (mid + Math.imul(ah8, bl2)) | 0;
25738 hi = (hi + Math.imul(ah8, bh2)) | 0;
25739 lo = (lo + Math.imul(al7, bl3)) | 0;
25740 mid = (mid + Math.imul(al7, bh3)) | 0;
25741 mid = (mid + Math.imul(ah7, bl3)) | 0;
25742 hi = (hi + Math.imul(ah7, bh3)) | 0;
25743 lo = (lo + Math.imul(al6, bl4)) | 0;
25744 mid = (mid + Math.imul(al6, bh4)) | 0;
25745 mid = (mid + Math.imul(ah6, bl4)) | 0;
25746 hi = (hi + Math.imul(ah6, bh4)) | 0;
25747 lo = (lo + Math.imul(al5, bl5)) | 0;
25748 mid = (mid + Math.imul(al5, bh5)) | 0;
25749 mid = (mid + Math.imul(ah5, bl5)) | 0;
25750 hi = (hi + Math.imul(ah5, bh5)) | 0;
25751 lo = (lo + Math.imul(al4, bl6)) | 0;
25752 mid = (mid + Math.imul(al4, bh6)) | 0;
25753 mid = (mid + Math.imul(ah4, bl6)) | 0;
25754 hi = (hi + Math.imul(ah4, bh6)) | 0;
25755 lo = (lo + Math.imul(al3, bl7)) | 0;
25756 mid = (mid + Math.imul(al3, bh7)) | 0;
25757 mid = (mid + Math.imul(ah3, bl7)) | 0;
25758 hi = (hi + Math.imul(ah3, bh7)) | 0;
25759 lo = (lo + Math.imul(al2, bl8)) | 0;
25760 mid = (mid + Math.imul(al2, bh8)) | 0;
25761 mid = (mid + Math.imul(ah2, bl8)) | 0;
25762 hi = (hi + Math.imul(ah2, bh8)) | 0;
25763 lo = (lo + Math.imul(al1, bl9)) | 0;
25764 mid = (mid + Math.imul(al1, bh9)) | 0;
25765 mid = (mid + Math.imul(ah1, bl9)) | 0;
25766 hi = (hi + Math.imul(ah1, bh9)) | 0;
25767 var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25768 c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
25769 w10 &= 0x3ffffff;
25770 /* k = 11 */
25771 lo = Math.imul(al9, bl2);
25772 mid = Math.imul(al9, bh2);
25773 mid = (mid + Math.imul(ah9, bl2)) | 0;
25774 hi = Math.imul(ah9, bh2);
25775 lo = (lo + Math.imul(al8, bl3)) | 0;
25776 mid = (mid + Math.imul(al8, bh3)) | 0;
25777 mid = (mid + Math.imul(ah8, bl3)) | 0;
25778 hi = (hi + Math.imul(ah8, bh3)) | 0;
25779 lo = (lo + Math.imul(al7, bl4)) | 0;
25780 mid = (mid + Math.imul(al7, bh4)) | 0;
25781 mid = (mid + Math.imul(ah7, bl4)) | 0;
25782 hi = (hi + Math.imul(ah7, bh4)) | 0;
25783 lo = (lo + Math.imul(al6, bl5)) | 0;
25784 mid = (mid + Math.imul(al6, bh5)) | 0;
25785 mid = (mid + Math.imul(ah6, bl5)) | 0;
25786 hi = (hi + Math.imul(ah6, bh5)) | 0;
25787 lo = (lo + Math.imul(al5, bl6)) | 0;
25788 mid = (mid + Math.imul(al5, bh6)) | 0;
25789 mid = (mid + Math.imul(ah5, bl6)) | 0;
25790 hi = (hi + Math.imul(ah5, bh6)) | 0;
25791 lo = (lo + Math.imul(al4, bl7)) | 0;
25792 mid = (mid + Math.imul(al4, bh7)) | 0;
25793 mid = (mid + Math.imul(ah4, bl7)) | 0;
25794 hi = (hi + Math.imul(ah4, bh7)) | 0;
25795 lo = (lo + Math.imul(al3, bl8)) | 0;
25796 mid = (mid + Math.imul(al3, bh8)) | 0;
25797 mid = (mid + Math.imul(ah3, bl8)) | 0;
25798 hi = (hi + Math.imul(ah3, bh8)) | 0;
25799 lo = (lo + Math.imul(al2, bl9)) | 0;
25800 mid = (mid + Math.imul(al2, bh9)) | 0;
25801 mid = (mid + Math.imul(ah2, bl9)) | 0;
25802 hi = (hi + Math.imul(ah2, bh9)) | 0;
25803 var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25804 c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
25805 w11 &= 0x3ffffff;
25806 /* k = 12 */
25807 lo = Math.imul(al9, bl3);
25808 mid = Math.imul(al9, bh3);
25809 mid = (mid + Math.imul(ah9, bl3)) | 0;
25810 hi = Math.imul(ah9, bh3);
25811 lo = (lo + Math.imul(al8, bl4)) | 0;
25812 mid = (mid + Math.imul(al8, bh4)) | 0;
25813 mid = (mid + Math.imul(ah8, bl4)) | 0;
25814 hi = (hi + Math.imul(ah8, bh4)) | 0;
25815 lo = (lo + Math.imul(al7, bl5)) | 0;
25816 mid = (mid + Math.imul(al7, bh5)) | 0;
25817 mid = (mid + Math.imul(ah7, bl5)) | 0;
25818 hi = (hi + Math.imul(ah7, bh5)) | 0;
25819 lo = (lo + Math.imul(al6, bl6)) | 0;
25820 mid = (mid + Math.imul(al6, bh6)) | 0;
25821 mid = (mid + Math.imul(ah6, bl6)) | 0;
25822 hi = (hi + Math.imul(ah6, bh6)) | 0;
25823 lo = (lo + Math.imul(al5, bl7)) | 0;
25824 mid = (mid + Math.imul(al5, bh7)) | 0;
25825 mid = (mid + Math.imul(ah5, bl7)) | 0;
25826 hi = (hi + Math.imul(ah5, bh7)) | 0;
25827 lo = (lo + Math.imul(al4, bl8)) | 0;
25828 mid = (mid + Math.imul(al4, bh8)) | 0;
25829 mid = (mid + Math.imul(ah4, bl8)) | 0;
25830 hi = (hi + Math.imul(ah4, bh8)) | 0;
25831 lo = (lo + Math.imul(al3, bl9)) | 0;
25832 mid = (mid + Math.imul(al3, bh9)) | 0;
25833 mid = (mid + Math.imul(ah3, bl9)) | 0;
25834 hi = (hi + Math.imul(ah3, bh9)) | 0;
25835 var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25836 c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
25837 w12 &= 0x3ffffff;
25838 /* k = 13 */
25839 lo = Math.imul(al9, bl4);
25840 mid = Math.imul(al9, bh4);
25841 mid = (mid + Math.imul(ah9, bl4)) | 0;
25842 hi = Math.imul(ah9, bh4);
25843 lo = (lo + Math.imul(al8, bl5)) | 0;
25844 mid = (mid + Math.imul(al8, bh5)) | 0;
25845 mid = (mid + Math.imul(ah8, bl5)) | 0;
25846 hi = (hi + Math.imul(ah8, bh5)) | 0;
25847 lo = (lo + Math.imul(al7, bl6)) | 0;
25848 mid = (mid + Math.imul(al7, bh6)) | 0;
25849 mid = (mid + Math.imul(ah7, bl6)) | 0;
25850 hi = (hi + Math.imul(ah7, bh6)) | 0;
25851 lo = (lo + Math.imul(al6, bl7)) | 0;
25852 mid = (mid + Math.imul(al6, bh7)) | 0;
25853 mid = (mid + Math.imul(ah6, bl7)) | 0;
25854 hi = (hi + Math.imul(ah6, bh7)) | 0;
25855 lo = (lo + Math.imul(al5, bl8)) | 0;
25856 mid = (mid + Math.imul(al5, bh8)) | 0;
25857 mid = (mid + Math.imul(ah5, bl8)) | 0;
25858 hi = (hi + Math.imul(ah5, bh8)) | 0;
25859 lo = (lo + Math.imul(al4, bl9)) | 0;
25860 mid = (mid + Math.imul(al4, bh9)) | 0;
25861 mid = (mid + Math.imul(ah4, bl9)) | 0;
25862 hi = (hi + Math.imul(ah4, bh9)) | 0;
25863 var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25864 c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
25865 w13 &= 0x3ffffff;
25866 /* k = 14 */
25867 lo = Math.imul(al9, bl5);
25868 mid = Math.imul(al9, bh5);
25869 mid = (mid + Math.imul(ah9, bl5)) | 0;
25870 hi = Math.imul(ah9, bh5);
25871 lo = (lo + Math.imul(al8, bl6)) | 0;
25872 mid = (mid + Math.imul(al8, bh6)) | 0;
25873 mid = (mid + Math.imul(ah8, bl6)) | 0;
25874 hi = (hi + Math.imul(ah8, bh6)) | 0;
25875 lo = (lo + Math.imul(al7, bl7)) | 0;
25876 mid = (mid + Math.imul(al7, bh7)) | 0;
25877 mid = (mid + Math.imul(ah7, bl7)) | 0;
25878 hi = (hi + Math.imul(ah7, bh7)) | 0;
25879 lo = (lo + Math.imul(al6, bl8)) | 0;
25880 mid = (mid + Math.imul(al6, bh8)) | 0;
25881 mid = (mid + Math.imul(ah6, bl8)) | 0;
25882 hi = (hi + Math.imul(ah6, bh8)) | 0;
25883 lo = (lo + Math.imul(al5, bl9)) | 0;
25884 mid = (mid + Math.imul(al5, bh9)) | 0;
25885 mid = (mid + Math.imul(ah5, bl9)) | 0;
25886 hi = (hi + Math.imul(ah5, bh9)) | 0;
25887 var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25888 c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
25889 w14 &= 0x3ffffff;
25890 /* k = 15 */
25891 lo = Math.imul(al9, bl6);
25892 mid = Math.imul(al9, bh6);
25893 mid = (mid + Math.imul(ah9, bl6)) | 0;
25894 hi = Math.imul(ah9, bh6);
25895 lo = (lo + Math.imul(al8, bl7)) | 0;
25896 mid = (mid + Math.imul(al8, bh7)) | 0;
25897 mid = (mid + Math.imul(ah8, bl7)) | 0;
25898 hi = (hi + Math.imul(ah8, bh7)) | 0;
25899 lo = (lo + Math.imul(al7, bl8)) | 0;
25900 mid = (mid + Math.imul(al7, bh8)) | 0;
25901 mid = (mid + Math.imul(ah7, bl8)) | 0;
25902 hi = (hi + Math.imul(ah7, bh8)) | 0;
25903 lo = (lo + Math.imul(al6, bl9)) | 0;
25904 mid = (mid + Math.imul(al6, bh9)) | 0;
25905 mid = (mid + Math.imul(ah6, bl9)) | 0;
25906 hi = (hi + Math.imul(ah6, bh9)) | 0;
25907 var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25908 c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
25909 w15 &= 0x3ffffff;
25910 /* k = 16 */
25911 lo = Math.imul(al9, bl7);
25912 mid = Math.imul(al9, bh7);
25913 mid = (mid + Math.imul(ah9, bl7)) | 0;
25914 hi = Math.imul(ah9, bh7);
25915 lo = (lo + Math.imul(al8, bl8)) | 0;
25916 mid = (mid + Math.imul(al8, bh8)) | 0;
25917 mid = (mid + Math.imul(ah8, bl8)) | 0;
25918 hi = (hi + Math.imul(ah8, bh8)) | 0;
25919 lo = (lo + Math.imul(al7, bl9)) | 0;
25920 mid = (mid + Math.imul(al7, bh9)) | 0;
25921 mid = (mid + Math.imul(ah7, bl9)) | 0;
25922 hi = (hi + Math.imul(ah7, bh9)) | 0;
25923 var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25924 c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
25925 w16 &= 0x3ffffff;
25926 /* k = 17 */
25927 lo = Math.imul(al9, bl8);
25928 mid = Math.imul(al9, bh8);
25929 mid = (mid + Math.imul(ah9, bl8)) | 0;
25930 hi = Math.imul(ah9, bh8);
25931 lo = (lo + Math.imul(al8, bl9)) | 0;
25932 mid = (mid + Math.imul(al8, bh9)) | 0;
25933 mid = (mid + Math.imul(ah8, bl9)) | 0;
25934 hi = (hi + Math.imul(ah8, bh9)) | 0;
25935 var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25936 c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
25937 w17 &= 0x3ffffff;
25938 /* k = 18 */
25939 lo = Math.imul(al9, bl9);
25940 mid = Math.imul(al9, bh9);
25941 mid = (mid + Math.imul(ah9, bl9)) | 0;
25942 hi = Math.imul(ah9, bh9);
25943 var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
25944 c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
25945 w18 &= 0x3ffffff;
25946 o[0] = w0;
25947 o[1] = w1;
25948 o[2] = w2;
25949 o[3] = w3;
25950 o[4] = w4;
25951 o[5] = w5;
25952 o[6] = w6;
25953 o[7] = w7;
25954 o[8] = w8;
25955 o[9] = w9;
25956 o[10] = w10;
25957 o[11] = w11;
25958 o[12] = w12;
25959 o[13] = w13;
25960 o[14] = w14;
25961 o[15] = w15;
25962 o[16] = w16;
25963 o[17] = w17;
25964 o[18] = w18;
25965 if (c !== 0) {
25966 o[19] = c;
25967 out.length++;
25968 }
25969 return out;
25970 };
25971
25972 // Polyfill comb
25973 if (!Math.imul) {
25974 comb10MulTo = smallMulTo;
25975 }
25976
25977 function bigMulTo (self, num, out) {
25978 out.negative = num.negative ^ self.negative;
25979 out.length = self.length + num.length;
25980
25981 var carry = 0;
25982 var hncarry = 0;
25983 for (var k = 0; k < out.length - 1; k++) {
25984 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
25985 // note that ncarry could be >= 0x3ffffff
25986 var ncarry = hncarry;
25987 hncarry = 0;
25988 var rword = carry & 0x3ffffff;
25989 var maxJ = Math.min(k, num.length - 1);
25990 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
25991 var i = k - j;
25992 var a = self.words[i] | 0;
25993 var b = num.words[j] | 0;
25994 var r = a * b;
25995
25996 var lo = r & 0x3ffffff;
25997 ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
25998 lo = (lo + rword) | 0;
25999 rword = lo & 0x3ffffff;
26000 ncarry = (ncarry + (lo >>> 26)) | 0;
26001
26002 hncarry += ncarry >>> 26;
26003 ncarry &= 0x3ffffff;
26004 }
26005 out.words[k] = rword;
26006 carry = ncarry;
26007 ncarry = hncarry;
26008 }
26009 if (carry !== 0) {
26010 out.words[k] = carry;
26011 } else {
26012 out.length--;
26013 }
26014
26015 return out.strip();
26016 }
26017
26018 function jumboMulTo (self, num, out) {
26019 var fftm = new FFTM();
26020 return fftm.mulp(self, num, out);
26021 }
26022
26023 BN.prototype.mulTo = function mulTo (num, out) {
26024 var res;
26025 var len = this.length + num.length;
26026 if (this.length === 10 && num.length === 10) {
26027 res = comb10MulTo(this, num, out);
26028 } else if (len < 63) {
26029 res = smallMulTo(this, num, out);
26030 } else if (len < 1024) {
26031 res = bigMulTo(this, num, out);
26032 } else {
26033 res = jumboMulTo(this, num, out);
26034 }
26035
26036 return res;
26037 };
26038
26039 // Cooley-Tukey algorithm for FFT
26040 // slightly revisited to rely on looping instead of recursion
26041
26042 function FFTM (x, y) {
26043 this.x = x;
26044 this.y = y;
26045 }
26046
26047 FFTM.prototype.makeRBT = function makeRBT (N) {
26048 var t = new Array(N);
26049 var l = BN.prototype._countBits(N) - 1;
26050 for (var i = 0; i < N; i++) {
26051 t[i] = this.revBin(i, l, N);
26052 }
26053
26054 return t;
26055 };
26056
26057 // Returns binary-reversed representation of `x`
26058 FFTM.prototype.revBin = function revBin (x, l, N) {
26059 if (x === 0 || x === N - 1) return x;
26060
26061 var rb = 0;
26062 for (var i = 0; i < l; i++) {
26063 rb |= (x & 1) << (l - i - 1);
26064 x >>= 1;
26065 }
26066
26067 return rb;
26068 };
26069
26070 // Performs "tweedling" phase, therefore 'emulating'
26071 // behaviour of the recursive algorithm
26072 FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
26073 for (var i = 0; i < N; i++) {
26074 rtws[i] = rws[rbt[i]];
26075 itws[i] = iws[rbt[i]];
26076 }
26077 };
26078
26079 FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
26080 this.permute(rbt, rws, iws, rtws, itws, N);
26081
26082 for (var s = 1; s < N; s <<= 1) {
26083 var l = s << 1;
26084
26085 var rtwdf = Math.cos(2 * Math.PI / l);
26086 var itwdf = Math.sin(2 * Math.PI / l);
26087
26088 for (var p = 0; p < N; p += l) {
26089 var rtwdf_ = rtwdf;
26090 var itwdf_ = itwdf;
26091
26092 for (var j = 0; j < s; j++) {
26093 var re = rtws[p + j];
26094 var ie = itws[p + j];
26095
26096 var ro = rtws[p + j + s];
26097 var io = itws[p + j + s];
26098
26099 var rx = rtwdf_ * ro - itwdf_ * io;
26100
26101 io = rtwdf_ * io + itwdf_ * ro;
26102 ro = rx;
26103
26104 rtws[p + j] = re + ro;
26105 itws[p + j] = ie + io;
26106
26107 rtws[p + j + s] = re - ro;
26108 itws[p + j + s] = ie - io;
26109
26110 /* jshint maxdepth : false */
26111 if (j !== l) {
26112 rx = rtwdf * rtwdf_ - itwdf * itwdf_;
26113
26114 itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
26115 rtwdf_ = rx;
26116 }
26117 }
26118 }
26119 }
26120 };
26121
26122 FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
26123 var N = Math.max(m, n) | 1;
26124 var odd = N & 1;
26125 var i = 0;
26126 for (N = N / 2 | 0; N; N = N >>> 1) {
26127 i++;
26128 }
26129
26130 return 1 << i + 1 + odd;
26131 };
26132
26133 FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
26134 if (N <= 1) return;
26135
26136 for (var i = 0; i < N / 2; i++) {
26137 var t = rws[i];
26138
26139 rws[i] = rws[N - i - 1];
26140 rws[N - i - 1] = t;
26141
26142 t = iws[i];
26143
26144 iws[i] = -iws[N - i - 1];
26145 iws[N - i - 1] = -t;
26146 }
26147 };
26148
26149 FFTM.prototype.normalize13b = function normalize13b (ws, N) {
26150 var carry = 0;
26151 for (var i = 0; i < N / 2; i++) {
26152 var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
26153 Math.round(ws[2 * i] / N) +
26154 carry;
26155
26156 ws[i] = w & 0x3ffffff;
26157
26158 if (w < 0x4000000) {
26159 carry = 0;
26160 } else {
26161 carry = w / 0x4000000 | 0;
26162 }
26163 }
26164
26165 return ws;
26166 };
26167
26168 FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
26169 var carry = 0;
26170 for (var i = 0; i < len; i++) {
26171 carry = carry + (ws[i] | 0);
26172
26173 rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
26174 rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
26175 }
26176
26177 // Pad with zeroes
26178 for (i = 2 * len; i < N; ++i) {
26179 rws[i] = 0;
26180 }
26181
26182 assert(carry === 0);
26183 assert((carry & ~0x1fff) === 0);
26184 };
26185
26186 FFTM.prototype.stub = function stub (N) {
26187 var ph = new Array(N);
26188 for (var i = 0; i < N; i++) {
26189 ph[i] = 0;
26190 }
26191
26192 return ph;
26193 };
26194
26195 FFTM.prototype.mulp = function mulp (x, y, out) {
26196 var N = 2 * this.guessLen13b(x.length, y.length);
26197
26198 var rbt = this.makeRBT(N);
26199
26200 var _ = this.stub(N);
26201
26202 var rws = new Array(N);
26203 var rwst = new Array(N);
26204 var iwst = new Array(N);
26205
26206 var nrws = new Array(N);
26207 var nrwst = new Array(N);
26208 var niwst = new Array(N);
26209
26210 var rmws = out.words;
26211 rmws.length = N;
26212
26213 this.convert13b(x.words, x.length, rws, N);
26214 this.convert13b(y.words, y.length, nrws, N);
26215
26216 this.transform(rws, _, rwst, iwst, N, rbt);
26217 this.transform(nrws, _, nrwst, niwst, N, rbt);
26218
26219 for (var i = 0; i < N; i++) {
26220 var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
26221 iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
26222 rwst[i] = rx;
26223 }
26224
26225 this.conjugate(rwst, iwst, N);
26226 this.transform(rwst, iwst, rmws, _, N, rbt);
26227 this.conjugate(rmws, _, N);
26228 this.normalize13b(rmws, N);
26229
26230 out.negative = x.negative ^ y.negative;
26231 out.length = x.length + y.length;
26232 return out.strip();
26233 };
26234
26235 // Multiply `this` by `num`
26236 BN.prototype.mul = function mul (num) {
26237 var out = new BN(null);
26238 out.words = new Array(this.length + num.length);
26239 return this.mulTo(num, out);
26240 };
26241
26242 // Multiply employing FFT
26243 BN.prototype.mulf = function mulf (num) {
26244 var out = new BN(null);
26245 out.words = new Array(this.length + num.length);
26246 return jumboMulTo(this, num, out);
26247 };
26248
26249 // In-place Multiplication
26250 BN.prototype.imul = function imul (num) {
26251 return this.clone().mulTo(num, this);
26252 };
26253
26254 BN.prototype.imuln = function imuln (num) {
26255 assert(typeof num === 'number');
26256 assert(num < 0x4000000);
26257
26258 // Carry
26259 var carry = 0;
26260 for (var i = 0; i < this.length; i++) {
26261 var w = (this.words[i] | 0) * num;
26262 var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
26263 carry >>= 26;
26264 carry += (w / 0x4000000) | 0;
26265 // NOTE: lo is 27bit maximum
26266 carry += lo >>> 26;
26267 this.words[i] = lo & 0x3ffffff;
26268 }
26269
26270 if (carry !== 0) {
26271 this.words[i] = carry;
26272 this.length++;
26273 }
26274
26275 return this;
26276 };
26277
26278 BN.prototype.muln = function muln (num) {
26279 return this.clone().imuln(num);
26280 };
26281
26282 // `this` * `this`
26283 BN.prototype.sqr = function sqr () {
26284 return this.mul(this);
26285 };
26286
26287 // `this` * `this` in-place
26288 BN.prototype.isqr = function isqr () {
26289 return this.imul(this.clone());
26290 };
26291
26292 // Math.pow(`this`, `num`)
26293 BN.prototype.pow = function pow (num) {
26294 var w = toBitArray(num);
26295 if (w.length === 0) return new BN(1);
26296
26297 // Skip leading zeroes
26298 var res = this;
26299 for (var i = 0; i < w.length; i++, res = res.sqr()) {
26300 if (w[i] !== 0) break;
26301 }
26302
26303 if (++i < w.length) {
26304 for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
26305 if (w[i] === 0) continue;
26306
26307 res = res.mul(q);
26308 }
26309 }
26310
26311 return res;
26312 };
26313
26314 // Shift-left in-place
26315 BN.prototype.iushln = function iushln (bits) {
26316 assert(typeof bits === 'number' && bits >= 0);
26317 var r = bits % 26;
26318 var s = (bits - r) / 26;
26319 var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
26320 var i;
26321
26322 if (r !== 0) {
26323 var carry = 0;
26324
26325 for (i = 0; i < this.length; i++) {
26326 var newCarry = this.words[i] & carryMask;
26327 var c = ((this.words[i] | 0) - newCarry) << r;
26328 this.words[i] = c | carry;
26329 carry = newCarry >>> (26 - r);
26330 }
26331
26332 if (carry) {
26333 this.words[i] = carry;
26334 this.length++;
26335 }
26336 }
26337
26338 if (s !== 0) {
26339 for (i = this.length - 1; i >= 0; i--) {
26340 this.words[i + s] = this.words[i];
26341 }
26342
26343 for (i = 0; i < s; i++) {
26344 this.words[i] = 0;
26345 }
26346
26347 this.length += s;
26348 }
26349
26350 return this.strip();
26351 };
26352
26353 BN.prototype.ishln = function ishln (bits) {
26354 // TODO(indutny): implement me
26355 assert(this.negative === 0);
26356 return this.iushln(bits);
26357 };
26358
26359 // Shift-right in-place
26360 // NOTE: `hint` is a lowest bit before trailing zeroes
26361 // NOTE: if `extended` is present - it will be filled with destroyed bits
26362 BN.prototype.iushrn = function iushrn (bits, hint, extended) {
26363 assert(typeof bits === 'number' && bits >= 0);
26364 var h;
26365 if (hint) {
26366 h = (hint - (hint % 26)) / 26;
26367 } else {
26368 h = 0;
26369 }
26370
26371 var r = bits % 26;
26372 var s = Math.min((bits - r) / 26, this.length);
26373 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
26374 var maskedWords = extended;
26375
26376 h -= s;
26377 h = Math.max(0, h);
26378
26379 // Extended mode, copy masked part
26380 if (maskedWords) {
26381 for (var i = 0; i < s; i++) {
26382 maskedWords.words[i] = this.words[i];
26383 }
26384 maskedWords.length = s;
26385 }
26386
26387 if (s === 0) {
26388 // No-op, we should not move anything at all
26389 } else if (this.length > s) {
26390 this.length -= s;
26391 for (i = 0; i < this.length; i++) {
26392 this.words[i] = this.words[i + s];
26393 }
26394 } else {
26395 this.words[0] = 0;
26396 this.length = 1;
26397 }
26398
26399 var carry = 0;
26400 for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
26401 var word = this.words[i] | 0;
26402 this.words[i] = (carry << (26 - r)) | (word >>> r);
26403 carry = word & mask;
26404 }
26405
26406 // Push carried bits as a mask
26407 if (maskedWords && carry !== 0) {
26408 maskedWords.words[maskedWords.length++] = carry;
26409 }
26410
26411 if (this.length === 0) {
26412 this.words[0] = 0;
26413 this.length = 1;
26414 }
26415
26416 return this.strip();
26417 };
26418
26419 BN.prototype.ishrn = function ishrn (bits, hint, extended) {
26420 // TODO(indutny): implement me
26421 assert(this.negative === 0);
26422 return this.iushrn(bits, hint, extended);
26423 };
26424
26425 // Shift-left
26426 BN.prototype.shln = function shln (bits) {
26427 return this.clone().ishln(bits);
26428 };
26429
26430 BN.prototype.ushln = function ushln (bits) {
26431 return this.clone().iushln(bits);
26432 };
26433
26434 // Shift-right
26435 BN.prototype.shrn = function shrn (bits) {
26436 return this.clone().ishrn(bits);
26437 };
26438
26439 BN.prototype.ushrn = function ushrn (bits) {
26440 return this.clone().iushrn(bits);
26441 };
26442
26443 // Test if n bit is set
26444 BN.prototype.testn = function testn (bit) {
26445 assert(typeof bit === 'number' && bit >= 0);
26446 var r = bit % 26;
26447 var s = (bit - r) / 26;
26448 var q = 1 << r;
26449
26450 // Fast case: bit is much higher than all existing words
26451 if (this.length <= s) return false;
26452
26453 // Check bit and return
26454 var w = this.words[s];
26455
26456 return !!(w & q);
26457 };
26458
26459 // Return only lowers bits of number (in-place)
26460 BN.prototype.imaskn = function imaskn (bits) {
26461 assert(typeof bits === 'number' && bits >= 0);
26462 var r = bits % 26;
26463 var s = (bits - r) / 26;
26464
26465 assert(this.negative === 0, 'imaskn works only with positive numbers');
26466
26467 if (this.length <= s) {
26468 return this;
26469 }
26470
26471 if (r !== 0) {
26472 s++;
26473 }
26474 this.length = Math.min(s, this.length);
26475
26476 if (r !== 0) {
26477 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
26478 this.words[this.length - 1] &= mask;
26479 }
26480
26481 return this.strip();
26482 };
26483
26484 // Return only lowers bits of number
26485 BN.prototype.maskn = function maskn (bits) {
26486 return this.clone().imaskn(bits);
26487 };
26488
26489 // Add plain number `num` to `this`
26490 BN.prototype.iaddn = function iaddn (num) {
26491 assert(typeof num === 'number');
26492 assert(num < 0x4000000);
26493 if (num < 0) return this.isubn(-num);
26494
26495 // Possible sign change
26496 if (this.negative !== 0) {
26497 if (this.length === 1 && (this.words[0] | 0) < num) {
26498 this.words[0] = num - (this.words[0] | 0);
26499 this.negative = 0;
26500 return this;
26501 }
26502
26503 this.negative = 0;
26504 this.isubn(num);
26505 this.negative = 1;
26506 return this;
26507 }
26508
26509 // Add without checks
26510 return this._iaddn(num);
26511 };
26512
26513 BN.prototype._iaddn = function _iaddn (num) {
26514 this.words[0] += num;
26515
26516 // Carry
26517 for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
26518 this.words[i] -= 0x4000000;
26519 if (i === this.length - 1) {
26520 this.words[i + 1] = 1;
26521 } else {
26522 this.words[i + 1]++;
26523 }
26524 }
26525 this.length = Math.max(this.length, i + 1);
26526
26527 return this;
26528 };
26529
26530 // Subtract plain number `num` from `this`
26531 BN.prototype.isubn = function isubn (num) {
26532 assert(typeof num === 'number');
26533 assert(num < 0x4000000);
26534 if (num < 0) return this.iaddn(-num);
26535
26536 if (this.negative !== 0) {
26537 this.negative = 0;
26538 this.iaddn(num);
26539 this.negative = 1;
26540 return this;
26541 }
26542
26543 this.words[0] -= num;
26544
26545 if (this.length === 1 && this.words[0] < 0) {
26546 this.words[0] = -this.words[0];
26547 this.negative = 1;
26548 } else {
26549 // Carry
26550 for (var i = 0; i < this.length && this.words[i] < 0; i++) {
26551 this.words[i] += 0x4000000;
26552 this.words[i + 1] -= 1;
26553 }
26554 }
26555
26556 return this.strip();
26557 };
26558
26559 BN.prototype.addn = function addn (num) {
26560 return this.clone().iaddn(num);
26561 };
26562
26563 BN.prototype.subn = function subn (num) {
26564 return this.clone().isubn(num);
26565 };
26566
26567 BN.prototype.iabs = function iabs () {
26568 this.negative = 0;
26569
26570 return this;
26571 };
26572
26573 BN.prototype.abs = function abs () {
26574 return this.clone().iabs();
26575 };
26576
26577 BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
26578 var len = num.length + shift;
26579 var i;
26580
26581 this._expand(len);
26582
26583 var w;
26584 var carry = 0;
26585 for (i = 0; i < num.length; i++) {
26586 w = (this.words[i + shift] | 0) + carry;
26587 var right = (num.words[i] | 0) * mul;
26588 w -= right & 0x3ffffff;
26589 carry = (w >> 26) - ((right / 0x4000000) | 0);
26590 this.words[i + shift] = w & 0x3ffffff;
26591 }
26592 for (; i < this.length - shift; i++) {
26593 w = (this.words[i + shift] | 0) + carry;
26594 carry = w >> 26;
26595 this.words[i + shift] = w & 0x3ffffff;
26596 }
26597
26598 if (carry === 0) return this.strip();
26599
26600 // Subtraction overflow
26601 assert(carry === -1);
26602 carry = 0;
26603 for (i = 0; i < this.length; i++) {
26604 w = -(this.words[i] | 0) + carry;
26605 carry = w >> 26;
26606 this.words[i] = w & 0x3ffffff;
26607 }
26608 this.negative = 1;
26609
26610 return this.strip();
26611 };
26612
26613 BN.prototype._wordDiv = function _wordDiv (num, mode) {
26614 var shift = this.length - num.length;
26615
26616 var a = this.clone();
26617 var b = num;
26618
26619 // Normalize
26620 var bhi = b.words[b.length - 1] | 0;
26621 var bhiBits = this._countBits(bhi);
26622 shift = 26 - bhiBits;
26623 if (shift !== 0) {
26624 b = b.ushln(shift);
26625 a.iushln(shift);
26626 bhi = b.words[b.length - 1] | 0;
26627 }
26628
26629 // Initialize quotient
26630 var m = a.length - b.length;
26631 var q;
26632
26633 if (mode !== 'mod') {
26634 q = new BN(null);
26635 q.length = m + 1;
26636 q.words = new Array(q.length);
26637 for (var i = 0; i < q.length; i++) {
26638 q.words[i] = 0;
26639 }
26640 }
26641
26642 var diff = a.clone()._ishlnsubmul(b, 1, m);
26643 if (diff.negative === 0) {
26644 a = diff;
26645 if (q) {
26646 q.words[m] = 1;
26647 }
26648 }
26649
26650 for (var j = m - 1; j >= 0; j--) {
26651 var qj = (a.words[b.length + j] | 0) * 0x4000000 +
26652 (a.words[b.length + j - 1] | 0);
26653
26654 // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
26655 // (0x7ffffff)
26656 qj = Math.min((qj / bhi) | 0, 0x3ffffff);
26657
26658 a._ishlnsubmul(b, qj, j);
26659 while (a.negative !== 0) {
26660 qj--;
26661 a.negative = 0;
26662 a._ishlnsubmul(b, 1, j);
26663 if (!a.isZero()) {
26664 a.negative ^= 1;
26665 }
26666 }
26667 if (q) {
26668 q.words[j] = qj;
26669 }
26670 }
26671 if (q) {
26672 q.strip();
26673 }
26674 a.strip();
26675
26676 // Denormalize
26677 if (mode !== 'div' && shift !== 0) {
26678 a.iushrn(shift);
26679 }
26680
26681 return {
26682 div: q || null,
26683 mod: a
26684 };
26685 };
26686
26687 // NOTE: 1) `mode` can be set to `mod` to request mod only,
26688 // to `div` to request div only, or be absent to
26689 // request both div & mod
26690 // 2) `positive` is true if unsigned mod is requested
26691 BN.prototype.divmod = function divmod (num, mode, positive) {
26692 assert(!num.isZero());
26693
26694 if (this.isZero()) {
26695 return {
26696 div: new BN(0),
26697 mod: new BN(0)
26698 };
26699 }
26700
26701 var div, mod, res;
26702 if (this.negative !== 0 && num.negative === 0) {
26703 res = this.neg().divmod(num, mode);
26704
26705 if (mode !== 'mod') {
26706 div = res.div.neg();
26707 }
26708
26709 if (mode !== 'div') {
26710 mod = res.mod.neg();
26711 if (positive && mod.negative !== 0) {
26712 mod.iadd(num);
26713 }
26714 }
26715
26716 return {
26717 div: div,
26718 mod: mod
26719 };
26720 }
26721
26722 if (this.negative === 0 && num.negative !== 0) {
26723 res = this.divmod(num.neg(), mode);
26724
26725 if (mode !== 'mod') {
26726 div = res.div.neg();
26727 }
26728
26729 return {
26730 div: div,
26731 mod: res.mod
26732 };
26733 }
26734
26735 if ((this.negative & num.negative) !== 0) {
26736 res = this.neg().divmod(num.neg(), mode);
26737
26738 if (mode !== 'div') {
26739 mod = res.mod.neg();
26740 if (positive && mod.negative !== 0) {
26741 mod.isub(num);
26742 }
26743 }
26744
26745 return {
26746 div: res.div,
26747 mod: mod
26748 };
26749 }
26750
26751 // Both numbers are positive at this point
26752
26753 // Strip both numbers to approximate shift value
26754 if (num.length > this.length || this.cmp(num) < 0) {
26755 return {
26756 div: new BN(0),
26757 mod: this
26758 };
26759 }
26760
26761 // Very short reduction
26762 if (num.length === 1) {
26763 if (mode === 'div') {
26764 return {
26765 div: this.divn(num.words[0]),
26766 mod: null
26767 };
26768 }
26769
26770 if (mode === 'mod') {
26771 return {
26772 div: null,
26773 mod: new BN(this.modn(num.words[0]))
26774 };
26775 }
26776
26777 return {
26778 div: this.divn(num.words[0]),
26779 mod: new BN(this.modn(num.words[0]))
26780 };
26781 }
26782
26783 return this._wordDiv(num, mode);
26784 };
26785
26786 // Find `this` / `num`
26787 BN.prototype.div = function div (num) {
26788 return this.divmod(num, 'div', false).div;
26789 };
26790
26791 // Find `this` % `num`
26792 BN.prototype.mod = function mod (num) {
26793 return this.divmod(num, 'mod', false).mod;
26794 };
26795
26796 BN.prototype.umod = function umod (num) {
26797 return this.divmod(num, 'mod', true).mod;
26798 };
26799
26800 // Find Round(`this` / `num`)
26801 BN.prototype.divRound = function divRound (num) {
26802 var dm = this.divmod(num);
26803
26804 // Fast case - exact division
26805 if (dm.mod.isZero()) return dm.div;
26806
26807 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
26808
26809 var half = num.ushrn(1);
26810 var r2 = num.andln(1);
26811 var cmp = mod.cmp(half);
26812
26813 // Round down
26814 if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
26815
26816 // Round up
26817 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
26818 };
26819
26820 BN.prototype.modn = function modn (num) {
26821 assert(num <= 0x3ffffff);
26822 var p = (1 << 26) % num;
26823
26824 var acc = 0;
26825 for (var i = this.length - 1; i >= 0; i--) {
26826 acc = (p * acc + (this.words[i] | 0)) % num;
26827 }
26828
26829 return acc;
26830 };
26831
26832 // In-place division by number
26833 BN.prototype.idivn = function idivn (num) {
26834 assert(num <= 0x3ffffff);
26835
26836 var carry = 0;
26837 for (var i = this.length - 1; i >= 0; i--) {
26838 var w = (this.words[i] | 0) + carry * 0x4000000;
26839 this.words[i] = (w / num) | 0;
26840 carry = w % num;
26841 }
26842
26843 return this.strip();
26844 };
26845
26846 BN.prototype.divn = function divn (num) {
26847 return this.clone().idivn(num);
26848 };
26849
26850 BN.prototype.egcd = function egcd (p) {
26851 assert(p.negative === 0);
26852 assert(!p.isZero());
26853
26854 var x = this;
26855 var y = p.clone();
26856
26857 if (x.negative !== 0) {
26858 x = x.umod(p);
26859 } else {
26860 x = x.clone();
26861 }
26862
26863 // A * x + B * y = x
26864 var A = new BN(1);
26865 var B = new BN(0);
26866
26867 // C * x + D * y = y
26868 var C = new BN(0);
26869 var D = new BN(1);
26870
26871 var g = 0;
26872
26873 while (x.isEven() && y.isEven()) {
26874 x.iushrn(1);
26875 y.iushrn(1);
26876 ++g;
26877 }
26878
26879 var yp = y.clone();
26880 var xp = x.clone();
26881
26882 while (!x.isZero()) {
26883 for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
26884 if (i > 0) {
26885 x.iushrn(i);
26886 while (i-- > 0) {
26887 if (A.isOdd() || B.isOdd()) {
26888 A.iadd(yp);
26889 B.isub(xp);
26890 }
26891
26892 A.iushrn(1);
26893 B.iushrn(1);
26894 }
26895 }
26896
26897 for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
26898 if (j > 0) {
26899 y.iushrn(j);
26900 while (j-- > 0) {
26901 if (C.isOdd() || D.isOdd()) {
26902 C.iadd(yp);
26903 D.isub(xp);
26904 }
26905
26906 C.iushrn(1);
26907 D.iushrn(1);
26908 }
26909 }
26910
26911 if (x.cmp(y) >= 0) {
26912 x.isub(y);
26913 A.isub(C);
26914 B.isub(D);
26915 } else {
26916 y.isub(x);
26917 C.isub(A);
26918 D.isub(B);
26919 }
26920 }
26921
26922 return {
26923 a: C,
26924 b: D,
26925 gcd: y.iushln(g)
26926 };
26927 };
26928
26929 // This is reduced incarnation of the binary EEA
26930 // above, designated to invert members of the
26931 // _prime_ fields F(p) at a maximal speed
26932 BN.prototype._invmp = function _invmp (p) {
26933 assert(p.negative === 0);
26934 assert(!p.isZero());
26935
26936 var a = this;
26937 var b = p.clone();
26938
26939 if (a.negative !== 0) {
26940 a = a.umod(p);
26941 } else {
26942 a = a.clone();
26943 }
26944
26945 var x1 = new BN(1);
26946 var x2 = new BN(0);
26947
26948 var delta = b.clone();
26949
26950 while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
26951 for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
26952 if (i > 0) {
26953 a.iushrn(i);
26954 while (i-- > 0) {
26955 if (x1.isOdd()) {
26956 x1.iadd(delta);
26957 }
26958
26959 x1.iushrn(1);
26960 }
26961 }
26962
26963 for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
26964 if (j > 0) {
26965 b.iushrn(j);
26966 while (j-- > 0) {
26967 if (x2.isOdd()) {
26968 x2.iadd(delta);
26969 }
26970
26971 x2.iushrn(1);
26972 }
26973 }
26974
26975 if (a.cmp(b) >= 0) {
26976 a.isub(b);
26977 x1.isub(x2);
26978 } else {
26979 b.isub(a);
26980 x2.isub(x1);
26981 }
26982 }
26983
26984 var res;
26985 if (a.cmpn(1) === 0) {
26986 res = x1;
26987 } else {
26988 res = x2;
26989 }
26990
26991 if (res.cmpn(0) < 0) {
26992 res.iadd(p);
26993 }
26994
26995 return res;
26996 };
26997
26998 BN.prototype.gcd = function gcd (num) {
26999 if (this.isZero()) return num.abs();
27000 if (num.isZero()) return this.abs();
27001
27002 var a = this.clone();
27003 var b = num.clone();
27004 a.negative = 0;
27005 b.negative = 0;
27006
27007 // Remove common factor of two
27008 for (var shift = 0; a.isEven() && b.isEven(); shift++) {
27009 a.iushrn(1);
27010 b.iushrn(1);
27011 }
27012
27013 do {
27014 while (a.isEven()) {
27015 a.iushrn(1);
27016 }
27017 while (b.isEven()) {
27018 b.iushrn(1);
27019 }
27020
27021 var r = a.cmp(b);
27022 if (r < 0) {
27023 // Swap `a` and `b` to make `a` always bigger than `b`
27024 var t = a;
27025 a = b;
27026 b = t;
27027 } else if (r === 0 || b.cmpn(1) === 0) {
27028 break;
27029 }
27030
27031 a.isub(b);
27032 } while (true);
27033
27034 return b.iushln(shift);
27035 };
27036
27037 // Invert number in the field F(num)
27038 BN.prototype.invm = function invm (num) {
27039 return this.egcd(num).a.umod(num);
27040 };
27041
27042 BN.prototype.isEven = function isEven () {
27043 return (this.words[0] & 1) === 0;
27044 };
27045
27046 BN.prototype.isOdd = function isOdd () {
27047 return (this.words[0] & 1) === 1;
27048 };
27049
27050 // And first word and num
27051 BN.prototype.andln = function andln (num) {
27052 return this.words[0] & num;
27053 };
27054
27055 // Increment at the bit position in-line
27056 BN.prototype.bincn = function bincn (bit) {
27057 assert(typeof bit === 'number');
27058 var r = bit % 26;
27059 var s = (bit - r) / 26;
27060 var q = 1 << r;
27061
27062 // Fast case: bit is much higher than all existing words
27063 if (this.length <= s) {
27064 this._expand(s + 1);
27065 this.words[s] |= q;
27066 return this;
27067 }
27068
27069 // Add bit and propagate, if needed
27070 var carry = q;
27071 for (var i = s; carry !== 0 && i < this.length; i++) {
27072 var w = this.words[i] | 0;
27073 w += carry;
27074 carry = w >>> 26;
27075 w &= 0x3ffffff;
27076 this.words[i] = w;
27077 }
27078 if (carry !== 0) {
27079 this.words[i] = carry;
27080 this.length++;
27081 }
27082 return this;
27083 };
27084
27085 BN.prototype.isZero = function isZero () {
27086 return this.length === 1 && this.words[0] === 0;
27087 };
27088
27089 BN.prototype.cmpn = function cmpn (num) {
27090 var negative = num < 0;
27091
27092 if (this.negative !== 0 && !negative) return -1;
27093 if (this.negative === 0 && negative) return 1;
27094
27095 this.strip();
27096
27097 var res;
27098 if (this.length > 1) {
27099 res = 1;
27100 } else {
27101 if (negative) {
27102 num = -num;
27103 }
27104
27105 assert(num <= 0x3ffffff, 'Number is too big');
27106
27107 var w = this.words[0] | 0;
27108 res = w === num ? 0 : w < num ? -1 : 1;
27109 }
27110 if (this.negative !== 0) return -res | 0;
27111 return res;
27112 };
27113
27114 // Compare two numbers and return:
27115 // 1 - if `this` > `num`
27116 // 0 - if `this` == `num`
27117 // -1 - if `this` < `num`
27118 BN.prototype.cmp = function cmp (num) {
27119 if (this.negative !== 0 && num.negative === 0) return -1;
27120 if (this.negative === 0 && num.negative !== 0) return 1;
27121
27122 var res = this.ucmp(num);
27123 if (this.negative !== 0) return -res | 0;
27124 return res;
27125 };
27126
27127 // Unsigned comparison
27128 BN.prototype.ucmp = function ucmp (num) {
27129 // At this point both numbers have the same sign
27130 if (this.length > num.length) return 1;
27131 if (this.length < num.length) return -1;
27132
27133 var res = 0;
27134 for (var i = this.length - 1; i >= 0; i--) {
27135 var a = this.words[i] | 0;
27136 var b = num.words[i] | 0;
27137
27138 if (a === b) continue;
27139 if (a < b) {
27140 res = -1;
27141 } else if (a > b) {
27142 res = 1;
27143 }
27144 break;
27145 }
27146 return res;
27147 };
27148
27149 BN.prototype.gtn = function gtn (num) {
27150 return this.cmpn(num) === 1;
27151 };
27152
27153 BN.prototype.gt = function gt (num) {
27154 return this.cmp(num) === 1;
27155 };
27156
27157 BN.prototype.gten = function gten (num) {
27158 return this.cmpn(num) >= 0;
27159 };
27160
27161 BN.prototype.gte = function gte (num) {
27162 return this.cmp(num) >= 0;
27163 };
27164
27165 BN.prototype.ltn = function ltn (num) {
27166 return this.cmpn(num) === -1;
27167 };
27168
27169 BN.prototype.lt = function lt (num) {
27170 return this.cmp(num) === -1;
27171 };
27172
27173 BN.prototype.lten = function lten (num) {
27174 return this.cmpn(num) <= 0;
27175 };
27176
27177 BN.prototype.lte = function lte (num) {
27178 return this.cmp(num) <= 0;
27179 };
27180
27181 BN.prototype.eqn = function eqn (num) {
27182 return this.cmpn(num) === 0;
27183 };
27184
27185 BN.prototype.eq = function eq (num) {
27186 return this.cmp(num) === 0;
27187 };
27188
27189 //
27190 // A reduce context, could be using montgomery or something better, depending
27191 // on the `m` itself.
27192 //
27193 BN.red = function red (num) {
27194 return new Red(num);
27195 };
27196
27197 BN.prototype.toRed = function toRed (ctx) {
27198 assert(!this.red, 'Already a number in reduction context');
27199 assert(this.negative === 0, 'red works only with positives');
27200 return ctx.convertTo(this)._forceRed(ctx);
27201 };
27202
27203 BN.prototype.fromRed = function fromRed () {
27204 assert(this.red, 'fromRed works only with numbers in reduction context');
27205 return this.red.convertFrom(this);
27206 };
27207
27208 BN.prototype._forceRed = function _forceRed (ctx) {
27209 this.red = ctx;
27210 return this;
27211 };
27212
27213 BN.prototype.forceRed = function forceRed (ctx) {
27214 assert(!this.red, 'Already a number in reduction context');
27215 return this._forceRed(ctx);
27216 };
27217
27218 BN.prototype.redAdd = function redAdd (num) {
27219 assert(this.red, 'redAdd works only with red numbers');
27220 return this.red.add(this, num);
27221 };
27222
27223 BN.prototype.redIAdd = function redIAdd (num) {
27224 assert(this.red, 'redIAdd works only with red numbers');
27225 return this.red.iadd(this, num);
27226 };
27227
27228 BN.prototype.redSub = function redSub (num) {
27229 assert(this.red, 'redSub works only with red numbers');
27230 return this.red.sub(this, num);
27231 };
27232
27233 BN.prototype.redISub = function redISub (num) {
27234 assert(this.red, 'redISub works only with red numbers');
27235 return this.red.isub(this, num);
27236 };
27237
27238 BN.prototype.redShl = function redShl (num) {
27239 assert(this.red, 'redShl works only with red numbers');
27240 return this.red.shl(this, num);
27241 };
27242
27243 BN.prototype.redMul = function redMul (num) {
27244 assert(this.red, 'redMul works only with red numbers');
27245 this.red._verify2(this, num);
27246 return this.red.mul(this, num);
27247 };
27248
27249 BN.prototype.redIMul = function redIMul (num) {
27250 assert(this.red, 'redMul works only with red numbers');
27251 this.red._verify2(this, num);
27252 return this.red.imul(this, num);
27253 };
27254
27255 BN.prototype.redSqr = function redSqr () {
27256 assert(this.red, 'redSqr works only with red numbers');
27257 this.red._verify1(this);
27258 return this.red.sqr(this);
27259 };
27260
27261 BN.prototype.redISqr = function redISqr () {
27262 assert(this.red, 'redISqr works only with red numbers');
27263 this.red._verify1(this);
27264 return this.red.isqr(this);
27265 };
27266
27267 // Square root over p
27268 BN.prototype.redSqrt = function redSqrt () {
27269 assert(this.red, 'redSqrt works only with red numbers');
27270 this.red._verify1(this);
27271 return this.red.sqrt(this);
27272 };
27273
27274 BN.prototype.redInvm = function redInvm () {
27275 assert(this.red, 'redInvm works only with red numbers');
27276 this.red._verify1(this);
27277 return this.red.invm(this);
27278 };
27279
27280 // Return negative clone of `this` % `red modulo`
27281 BN.prototype.redNeg = function redNeg () {
27282 assert(this.red, 'redNeg works only with red numbers');
27283 this.red._verify1(this);
27284 return this.red.neg(this);
27285 };
27286
27287 BN.prototype.redPow = function redPow (num) {
27288 assert(this.red && !num.red, 'redPow(normalNum)');
27289 this.red._verify1(this);
27290 return this.red.pow(this, num);
27291 };
27292
27293 // Prime numbers with efficient reduction
27294 var primes = {
27295 k256: null,
27296 p224: null,
27297 p192: null,
27298 p25519: null
27299 };
27300
27301 // Pseudo-Mersenne prime
27302 function MPrime (name, p) {
27303 // P = 2 ^ N - K
27304 this.name = name;
27305 this.p = new BN(p, 16);
27306 this.n = this.p.bitLength();
27307 this.k = new BN(1).iushln(this.n).isub(this.p);
27308
27309 this.tmp = this._tmp();
27310 }
27311
27312 MPrime.prototype._tmp = function _tmp () {
27313 var tmp = new BN(null);
27314 tmp.words = new Array(Math.ceil(this.n / 13));
27315 return tmp;
27316 };
27317
27318 MPrime.prototype.ireduce = function ireduce (num) {
27319 // Assumes that `num` is less than `P^2`
27320 // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
27321 var r = num;
27322 var rlen;
27323
27324 do {
27325 this.split(r, this.tmp);
27326 r = this.imulK(r);
27327 r = r.iadd(this.tmp);
27328 rlen = r.bitLength();
27329 } while (rlen > this.n);
27330
27331 var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
27332 if (cmp === 0) {
27333 r.words[0] = 0;
27334 r.length = 1;
27335 } else if (cmp > 0) {
27336 r.isub(this.p);
27337 } else {
27338 r.strip();
27339 }
27340
27341 return r;
27342 };
27343
27344 MPrime.prototype.split = function split (input, out) {
27345 input.iushrn(this.n, 0, out);
27346 };
27347
27348 MPrime.prototype.imulK = function imulK (num) {
27349 return num.imul(this.k);
27350 };
27351
27352 function K256 () {
27353 MPrime.call(
27354 this,
27355 'k256',
27356 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
27357 }
27358 inherits(K256, MPrime);
27359
27360 K256.prototype.split = function split (input, output) {
27361 // 256 = 9 * 26 + 22
27362 var mask = 0x3fffff;
27363
27364 var outLen = Math.min(input.length, 9);
27365 for (var i = 0; i < outLen; i++) {
27366 output.words[i] = input.words[i];
27367 }
27368 output.length = outLen;
27369
27370 if (input.length <= 9) {
27371 input.words[0] = 0;
27372 input.length = 1;
27373 return;
27374 }
27375
27376 // Shift by 9 limbs
27377 var prev = input.words[9];
27378 output.words[output.length++] = prev & mask;
27379
27380 for (i = 10; i < input.length; i++) {
27381 var next = input.words[i] | 0;
27382 input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
27383 prev = next;
27384 }
27385 prev >>>= 22;
27386 input.words[i - 10] = prev;
27387 if (prev === 0 && input.length > 10) {
27388 input.length -= 10;
27389 } else {
27390 input.length -= 9;
27391 }
27392 };
27393
27394 K256.prototype.imulK = function imulK (num) {
27395 // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
27396 num.words[num.length] = 0;
27397 num.words[num.length + 1] = 0;
27398 num.length += 2;
27399
27400 // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
27401 var lo = 0;
27402 for (var i = 0; i < num.length; i++) {
27403 var w = num.words[i] | 0;
27404 lo += w * 0x3d1;
27405 num.words[i] = lo & 0x3ffffff;
27406 lo = w * 0x40 + ((lo / 0x4000000) | 0);
27407 }
27408
27409 // Fast length reduction
27410 if (num.words[num.length - 1] === 0) {
27411 num.length--;
27412 if (num.words[num.length - 1] === 0) {
27413 num.length--;
27414 }
27415 }
27416 return num;
27417 };
27418
27419 function P224 () {
27420 MPrime.call(
27421 this,
27422 'p224',
27423 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
27424 }
27425 inherits(P224, MPrime);
27426
27427 function P192 () {
27428 MPrime.call(
27429 this,
27430 'p192',
27431 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
27432 }
27433 inherits(P192, MPrime);
27434
27435 function P25519 () {
27436 // 2 ^ 255 - 19
27437 MPrime.call(
27438 this,
27439 '25519',
27440 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
27441 }
27442 inherits(P25519, MPrime);
27443
27444 P25519.prototype.imulK = function imulK (num) {
27445 // K = 0x13
27446 var carry = 0;
27447 for (var i = 0; i < num.length; i++) {
27448 var hi = (num.words[i] | 0) * 0x13 + carry;
27449 var lo = hi & 0x3ffffff;
27450 hi >>>= 26;
27451
27452 num.words[i] = lo;
27453 carry = hi;
27454 }
27455 if (carry !== 0) {
27456 num.words[num.length++] = carry;
27457 }
27458 return num;
27459 };
27460
27461 // Exported mostly for testing purposes, use plain name instead
27462 BN._prime = function prime (name) {
27463 // Cached version of prime
27464 if (primes[name]) return primes[name];
27465
27466 var prime;
27467 if (name === 'k256') {
27468 prime = new K256();
27469 } else if (name === 'p224') {
27470 prime = new P224();
27471 } else if (name === 'p192') {
27472 prime = new P192();
27473 } else if (name === 'p25519') {
27474 prime = new P25519();
27475 } else {
27476 throw new Error('Unknown prime ' + name);
27477 }
27478 primes[name] = prime;
27479
27480 return prime;
27481 };
27482
27483 //
27484 // Base reduction engine
27485 //
27486 function Red (m) {
27487 if (typeof m === 'string') {
27488 var prime = BN._prime(m);
27489 this.m = prime.p;
27490 this.prime = prime;
27491 } else {
27492 assert(m.gtn(1), 'modulus must be greater than 1');
27493 this.m = m;
27494 this.prime = null;
27495 }
27496 }
27497
27498 Red.prototype._verify1 = function _verify1 (a) {
27499 assert(a.negative === 0, 'red works only with positives');
27500 assert(a.red, 'red works only with red numbers');
27501 };
27502
27503 Red.prototype._verify2 = function _verify2 (a, b) {
27504 assert((a.negative | b.negative) === 0, 'red works only with positives');
27505 assert(a.red && a.red === b.red,
27506 'red works only with red numbers');
27507 };
27508
27509 Red.prototype.imod = function imod (a) {
27510 if (this.prime) return this.prime.ireduce(a)._forceRed(this);
27511 return a.umod(this.m)._forceRed(this);
27512 };
27513
27514 Red.prototype.neg = function neg (a) {
27515 if (a.isZero()) {
27516 return a.clone();
27517 }
27518
27519 return this.m.sub(a)._forceRed(this);
27520 };
27521
27522 Red.prototype.add = function add (a, b) {
27523 this._verify2(a, b);
27524
27525 var res = a.add(b);
27526 if (res.cmp(this.m) >= 0) {
27527 res.isub(this.m);
27528 }
27529 return res._forceRed(this);
27530 };
27531
27532 Red.prototype.iadd = function iadd (a, b) {
27533 this._verify2(a, b);
27534
27535 var res = a.iadd(b);
27536 if (res.cmp(this.m) >= 0) {
27537 res.isub(this.m);
27538 }
27539 return res;
27540 };
27541
27542 Red.prototype.sub = function sub (a, b) {
27543 this._verify2(a, b);
27544
27545 var res = a.sub(b);
27546 if (res.cmpn(0) < 0) {
27547 res.iadd(this.m);
27548 }
27549 return res._forceRed(this);
27550 };
27551
27552 Red.prototype.isub = function isub (a, b) {
27553 this._verify2(a, b);
27554
27555 var res = a.isub(b);
27556 if (res.cmpn(0) < 0) {
27557 res.iadd(this.m);
27558 }
27559 return res;
27560 };
27561
27562 Red.prototype.shl = function shl (a, num) {
27563 this._verify1(a);
27564 return this.imod(a.ushln(num));
27565 };
27566
27567 Red.prototype.imul = function imul (a, b) {
27568 this._verify2(a, b);
27569 return this.imod(a.imul(b));
27570 };
27571
27572 Red.prototype.mul = function mul (a, b) {
27573 this._verify2(a, b);
27574 return this.imod(a.mul(b));
27575 };
27576
27577 Red.prototype.isqr = function isqr (a) {
27578 return this.imul(a, a.clone());
27579 };
27580
27581 Red.prototype.sqr = function sqr (a) {
27582 return this.mul(a, a);
27583 };
27584
27585 Red.prototype.sqrt = function sqrt (a) {
27586 if (a.isZero()) return a.clone();
27587
27588 var mod3 = this.m.andln(3);
27589 assert(mod3 % 2 === 1);
27590
27591 // Fast case
27592 if (mod3 === 3) {
27593 var pow = this.m.add(new BN(1)).iushrn(2);
27594 return this.pow(a, pow);
27595 }
27596
27597 // Tonelli-Shanks algorithm (Totally unoptimized and slow)
27598 //
27599 // Find Q and S, that Q * 2 ^ S = (P - 1)
27600 var q = this.m.subn(1);
27601 var s = 0;
27602 while (!q.isZero() && q.andln(1) === 0) {
27603 s++;
27604 q.iushrn(1);
27605 }
27606 assert(!q.isZero());
27607
27608 var one = new BN(1).toRed(this);
27609 var nOne = one.redNeg();
27610
27611 // Find quadratic non-residue
27612 // NOTE: Max is such because of generalized Riemann hypothesis.
27613 var lpow = this.m.subn(1).iushrn(1);
27614 var z = this.m.bitLength();
27615 z = new BN(2 * z * z).toRed(this);
27616
27617 while (this.pow(z, lpow).cmp(nOne) !== 0) {
27618 z.redIAdd(nOne);
27619 }
27620
27621 var c = this.pow(z, q);
27622 var r = this.pow(a, q.addn(1).iushrn(1));
27623 var t = this.pow(a, q);
27624 var m = s;
27625 while (t.cmp(one) !== 0) {
27626 var tmp = t;
27627 for (var i = 0; tmp.cmp(one) !== 0; i++) {
27628 tmp = tmp.redSqr();
27629 }
27630 assert(i < m);
27631 var b = this.pow(c, new BN(1).iushln(m - i - 1));
27632
27633 r = r.redMul(b);
27634 c = b.redSqr();
27635 t = t.redMul(c);
27636 m = i;
27637 }
27638
27639 return r;
27640 };
27641
27642 Red.prototype.invm = function invm (a) {
27643 var inv = a._invmp(this.m);
27644 if (inv.negative !== 0) {
27645 inv.negative = 0;
27646 return this.imod(inv).redNeg();
27647 } else {
27648 return this.imod(inv);
27649 }
27650 };
27651
27652 Red.prototype.pow = function pow (a, num) {
27653 if (num.isZero()) return new BN(1);
27654 if (num.cmpn(1) === 0) return a.clone();
27655
27656 var windowSize = 4;
27657 var wnd = new Array(1 << windowSize);
27658 wnd[0] = new BN(1).toRed(this);
27659 wnd[1] = a;
27660 for (var i = 2; i < wnd.length; i++) {
27661 wnd[i] = this.mul(wnd[i - 1], a);
27662 }
27663
27664 var res = wnd[0];
27665 var current = 0;
27666 var currentLen = 0;
27667 var start = num.bitLength() % 26;
27668 if (start === 0) {
27669 start = 26;
27670 }
27671
27672 for (i = num.length - 1; i >= 0; i--) {
27673 var word = num.words[i];
27674 for (var j = start - 1; j >= 0; j--) {
27675 var bit = (word >> j) & 1;
27676 if (res !== wnd[0]) {
27677 res = this.sqr(res);
27678 }
27679
27680 if (bit === 0 && current === 0) {
27681 currentLen = 0;
27682 continue;
27683 }
27684
27685 current <<= 1;
27686 current |= bit;
27687 currentLen++;
27688 if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
27689
27690 res = this.mul(res, wnd[current]);
27691 currentLen = 0;
27692 current = 0;
27693 }
27694 start = 26;
27695 }
27696
27697 return res;
27698 };
27699
27700 Red.prototype.convertTo = function convertTo (num) {
27701 var r = num.umod(this.m);
27702
27703 return r === num ? r.clone() : r;
27704 };
27705
27706 Red.prototype.convertFrom = function convertFrom (num) {
27707 var res = num.clone();
27708 res.red = null;
27709 return res;
27710 };
27711
27712 //
27713 // Montgomery method engine
27714 //
27715
27716 BN.mont = function mont (num) {
27717 return new Mont(num);
27718 };
27719
27720 function Mont (m) {
27721 Red.call(this, m);
27722
27723 this.shift = this.m.bitLength();
27724 if (this.shift % 26 !== 0) {
27725 this.shift += 26 - (this.shift % 26);
27726 }
27727
27728 this.r = new BN(1).iushln(this.shift);
27729 this.r2 = this.imod(this.r.sqr());
27730 this.rinv = this.r._invmp(this.m);
27731
27732 this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
27733 this.minv = this.minv.umod(this.r);
27734 this.minv = this.r.sub(this.minv);
27735 }
27736 inherits(Mont, Red);
27737
27738 Mont.prototype.convertTo = function convertTo (num) {
27739 return this.imod(num.ushln(this.shift));
27740 };
27741
27742 Mont.prototype.convertFrom = function convertFrom (num) {
27743 var r = this.imod(num.mul(this.rinv));
27744 r.red = null;
27745 return r;
27746 };
27747
27748 Mont.prototype.imul = function imul (a, b) {
27749 if (a.isZero() || b.isZero()) {
27750 a.words[0] = 0;
27751 a.length = 1;
27752 return a;
27753 }
27754
27755 var t = a.imul(b);
27756 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
27757 var u = t.isub(c).iushrn(this.shift);
27758 var res = u;
27759
27760 if (u.cmp(this.m) >= 0) {
27761 res = u.isub(this.m);
27762 } else if (u.cmpn(0) < 0) {
27763 res = u.iadd(this.m);
27764 }
27765
27766 return res._forceRed(this);
27767 };
27768
27769 Mont.prototype.mul = function mul (a, b) {
27770 if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
27771
27772 var t = a.mul(b);
27773 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
27774 var u = t.isub(c).iushrn(this.shift);
27775 var res = u;
27776 if (u.cmp(this.m) >= 0) {
27777 res = u.isub(this.m);
27778 } else if (u.cmpn(0) < 0) {
27779 res = u.iadd(this.m);
27780 }
27781
27782 return res._forceRed(this);
27783 };
27784
27785 Mont.prototype.invm = function invm (a) {
27786 // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
27787 var res = this.imod(a._invmp(this.m).mul(this.r2));
27788 return res._forceRed(this);
27789 };
27790})(typeof module === 'undefined' || module, this);
27791
27792},{}],34:[function(require,module,exports){
27793var r;
27794
27795module.exports = function rand(len) {
27796 if (!r)
27797 r = new Rand(null);
27798
27799 return r.generate(len);
27800};
27801
27802function Rand(rand) {
27803 this.rand = rand;
27804}
27805module.exports.Rand = Rand;
27806
27807Rand.prototype.generate = function generate(len) {
27808 return this._rand(len);
27809};
27810
27811if (typeof self === 'object') {
27812 if (self.crypto && self.crypto.getRandomValues) {
27813 // Modern browsers
27814 Rand.prototype._rand = function _rand(n) {
27815 var arr = new Uint8Array(n);
27816 self.crypto.getRandomValues(arr);
27817 return arr;
27818 };
27819 } else if (self.msCrypto && self.msCrypto.getRandomValues) {
27820 // IE
27821 Rand.prototype._rand = function _rand(n) {
27822 var arr = new Uint8Array(n);
27823 self.msCrypto.getRandomValues(arr);
27824 return arr;
27825 };
27826 } else {
27827 // Old junk
27828 Rand.prototype._rand = function() {
27829 throw new Error('Not implemented yet');
27830 };
27831 }
27832} else {
27833 // Node.js or Web worker with no crypto support
27834 try {
27835 var crypto = require('crypto');
27836
27837 Rand.prototype._rand = function _rand(n) {
27838 return crypto.randomBytes(n);
27839 };
27840 } catch (e) {
27841 // Emulate crypto API using randy
27842 Rand.prototype._rand = function _rand(n) {
27843 var res = new Uint8Array(n);
27844 for (var i = 0; i < res.length; i++)
27845 res[i] = this.rand.getByte();
27846 return res;
27847 };
27848 }
27849}
27850
27851},{"crypto":3}],35:[function(require,module,exports){
27852(function (Buffer){
27853var Transform = require('stream').Transform
27854var inherits = require('inherits')
27855var StringDecoder = require('string_decoder').StringDecoder
27856module.exports = CipherBase
27857inherits(CipherBase, Transform)
27858function CipherBase (hashMode) {
27859 Transform.call(this)
27860 this.hashMode = typeof hashMode === 'string'
27861 if (this.hashMode) {
27862 this[hashMode] = this._finalOrDigest
27863 } else {
27864 this.final = this._finalOrDigest
27865 }
27866 this._decoder = null
27867 this._encoding = null
27868}
27869CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
27870 if (typeof data === 'string') {
27871 data = new Buffer(data, inputEnc)
27872 }
27873 var outData = this._update(data)
27874 if (this.hashMode) {
27875 return this
27876 }
27877 if (outputEnc) {
27878 outData = this._toString(outData, outputEnc)
27879 }
27880 return outData
27881}
27882
27883CipherBase.prototype.setAutoPadding = function () {}
27884
27885CipherBase.prototype.getAuthTag = function () {
27886 throw new Error('trying to get auth tag in unsupported state')
27887}
27888
27889CipherBase.prototype.setAuthTag = function () {
27890 throw new Error('trying to set auth tag in unsupported state')
27891}
27892
27893CipherBase.prototype.setAAD = function () {
27894 throw new Error('trying to set aad in unsupported state')
27895}
27896
27897CipherBase.prototype._transform = function (data, _, next) {
27898 var err
27899 try {
27900 if (this.hashMode) {
27901 this._update(data)
27902 } else {
27903 this.push(this._update(data))
27904 }
27905 } catch (e) {
27906 err = e
27907 } finally {
27908 next(err)
27909 }
27910}
27911CipherBase.prototype._flush = function (done) {
27912 var err
27913 try {
27914 this.push(this._final())
27915 } catch (e) {
27916 err = e
27917 } finally {
27918 done(err)
27919 }
27920}
27921CipherBase.prototype._finalOrDigest = function (outputEnc) {
27922 var outData = this._final() || new Buffer('')
27923 if (outputEnc) {
27924 outData = this._toString(outData, outputEnc, true)
27925 }
27926 return outData
27927}
27928
27929CipherBase.prototype._toString = function (value, enc, fin) {
27930 if (!this._decoder) {
27931 this._decoder = new StringDecoder(enc)
27932 this._encoding = enc
27933 }
27934 if (this._encoding !== enc) {
27935 throw new Error('can\'t switch encodings')
27936 }
27937 var out = this._decoder.write(value)
27938 if (fin) {
27939 out += this._decoder.end()
27940 }
27941 return out
27942}
27943
27944}).call(this,require("buffer").Buffer)
27945},{"buffer":5,"inherits":63,"stream":25,"string_decoder":26}],36:[function(require,module,exports){
27946(function (Buffer){
27947'use strict';
27948var inherits = require('inherits')
27949var md5 = require('./md5')
27950var rmd160 = require('ripemd160')
27951var sha = require('sha.js')
27952
27953var Base = require('cipher-base')
27954
27955function HashNoConstructor(hash) {
27956 Base.call(this, 'digest')
27957
27958 this._hash = hash
27959 this.buffers = []
27960}
27961
27962inherits(HashNoConstructor, Base)
27963
27964HashNoConstructor.prototype._update = function (data) {
27965 this.buffers.push(data)
27966}
27967
27968HashNoConstructor.prototype._final = function () {
27969 var buf = Buffer.concat(this.buffers)
27970 var r = this._hash(buf)
27971 this.buffers = null
27972
27973 return r
27974}
27975
27976function Hash(hash) {
27977 Base.call(this, 'digest')
27978
27979 this._hash = hash
27980}
27981
27982inherits(Hash, Base)
27983
27984Hash.prototype._update = function (data) {
27985 this._hash.update(data)
27986}
27987
27988Hash.prototype._final = function () {
27989 return this._hash.digest()
27990}
27991
27992module.exports = function createHash (alg) {
27993 alg = alg.toLowerCase()
27994 if ('md5' === alg) return new HashNoConstructor(md5)
27995 if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160)
27996
27997 return new Hash(sha(alg))
27998}
27999
28000}).call(this,require("buffer").Buffer)
28001},{"./md5":38,"buffer":5,"cipher-base":35,"inherits":63,"ripemd160":71,"sha.js":80}],37:[function(require,module,exports){
28002(function (Buffer){
28003'use strict';
28004var intSize = 4;
28005var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
28006var chrsz = 8;
28007
28008function toArray(buf, bigEndian) {
28009 if ((buf.length % intSize) !== 0) {
28010 var len = buf.length + (intSize - (buf.length % intSize));
28011 buf = Buffer.concat([buf, zeroBuffer], len);
28012 }
28013
28014 var arr = [];
28015 var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
28016 for (var i = 0; i < buf.length; i += intSize) {
28017 arr.push(fn.call(buf, i));
28018 }
28019 return arr;
28020}
28021
28022function toBuffer(arr, size, bigEndian) {
28023 var buf = new Buffer(size);
28024 var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
28025 for (var i = 0; i < arr.length; i++) {
28026 fn.call(buf, arr[i], i * 4, true);
28027 }
28028 return buf;
28029}
28030
28031function hash(buf, fn, hashSize, bigEndian) {
28032 if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
28033 var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
28034 return toBuffer(arr, hashSize, bigEndian);
28035}
28036exports.hash = hash;
28037}).call(this,require("buffer").Buffer)
28038},{"buffer":5}],38:[function(require,module,exports){
28039'use strict';
28040/*
28041 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
28042 * Digest Algorithm, as defined in RFC 1321.
28043 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
28044 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
28045 * Distributed under the BSD License
28046 * See http://pajhome.org.uk/crypt/md5 for more info.
28047 */
28048
28049var helpers = require('./helpers');
28050
28051/*
28052 * Calculate the MD5 of an array of little-endian words, and a bit length
28053 */
28054function core_md5(x, len)
28055{
28056 /* append padding */
28057 x[len >> 5] |= 0x80 << ((len) % 32);
28058 x[(((len + 64) >>> 9) << 4) + 14] = len;
28059
28060 var a = 1732584193;
28061 var b = -271733879;
28062 var c = -1732584194;
28063 var d = 271733878;
28064
28065 for(var i = 0; i < x.length; i += 16)
28066 {
28067 var olda = a;
28068 var oldb = b;
28069 var oldc = c;
28070 var oldd = d;
28071
28072 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
28073 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
28074 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
28075 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
28076 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
28077 d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
28078 c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
28079 b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
28080 a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
28081 d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
28082 c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
28083 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
28084 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
28085 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
28086 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
28087 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
28088
28089 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
28090 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
28091 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
28092 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
28093 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
28094 d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
28095 c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
28096 b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
28097 a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
28098 d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
28099 c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
28100 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
28101 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
28102 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
28103 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
28104 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
28105
28106 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
28107 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
28108 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
28109 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
28110 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
28111 d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
28112 c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
28113 b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
28114 a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
28115 d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
28116 c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
28117 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
28118 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
28119 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
28120 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
28121 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
28122
28123 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
28124 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
28125 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
28126 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
28127 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
28128 d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
28129 c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
28130 b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
28131 a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
28132 d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
28133 c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
28134 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
28135 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
28136 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
28137 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
28138 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
28139
28140 a = safe_add(a, olda);
28141 b = safe_add(b, oldb);
28142 c = safe_add(c, oldc);
28143 d = safe_add(d, oldd);
28144 }
28145 return Array(a, b, c, d);
28146
28147}
28148
28149/*
28150 * These functions implement the four basic operations the algorithm uses.
28151 */
28152function md5_cmn(q, a, b, x, s, t)
28153{
28154 return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
28155}
28156function md5_ff(a, b, c, d, x, s, t)
28157{
28158 return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
28159}
28160function md5_gg(a, b, c, d, x, s, t)
28161{
28162 return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
28163}
28164function md5_hh(a, b, c, d, x, s, t)
28165{
28166 return md5_cmn(b ^ c ^ d, a, b, x, s, t);
28167}
28168function md5_ii(a, b, c, d, x, s, t)
28169{
28170 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
28171}
28172
28173/*
28174 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
28175 * to work around bugs in some JS interpreters.
28176 */
28177function safe_add(x, y)
28178{
28179 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
28180 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
28181 return (msw << 16) | (lsw & 0xFFFF);
28182}
28183
28184/*
28185 * Bitwise rotate a 32-bit number to the left.
28186 */
28187function bit_rol(num, cnt)
28188{
28189 return (num << cnt) | (num >>> (32 - cnt));
28190}
28191
28192module.exports = function md5(buf) {
28193 return helpers.hash(buf, core_md5, 16);
28194};
28195},{"./helpers":37}],39:[function(require,module,exports){
28196'use strict';
28197
28198var elliptic = exports;
28199
28200elliptic.version = require('../package.json').version;
28201elliptic.utils = require('./elliptic/utils');
28202elliptic.rand = require('brorand');
28203elliptic.hmacDRBG = require('./elliptic/hmac-drbg');
28204elliptic.curve = require('./elliptic/curve');
28205elliptic.curves = require('./elliptic/curves');
28206
28207// Protocols
28208elliptic.ec = require('./elliptic/ec');
28209elliptic.eddsa = require('./elliptic/eddsa');
28210
28211},{"../package.json":55,"./elliptic/curve":42,"./elliptic/curves":45,"./elliptic/ec":46,"./elliptic/eddsa":49,"./elliptic/hmac-drbg":52,"./elliptic/utils":54,"brorand":34}],40:[function(require,module,exports){
28212'use strict';
28213
28214var BN = require('bn.js');
28215var elliptic = require('../../elliptic');
28216var utils = elliptic.utils;
28217var getNAF = utils.getNAF;
28218var getJSF = utils.getJSF;
28219var assert = utils.assert;
28220
28221function BaseCurve(type, conf) {
28222 this.type = type;
28223 this.p = new BN(conf.p, 16);
28224
28225 // Use Montgomery, when there is no fast reduction for the prime
28226 this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
28227
28228 // Useful for many curves
28229 this.zero = new BN(0).toRed(this.red);
28230 this.one = new BN(1).toRed(this.red);
28231 this.two = new BN(2).toRed(this.red);
28232
28233 // Curve configuration, optional
28234 this.n = conf.n && new BN(conf.n, 16);
28235 this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
28236
28237 // Temporary arrays
28238 this._wnafT1 = new Array(4);
28239 this._wnafT2 = new Array(4);
28240 this._wnafT3 = new Array(4);
28241 this._wnafT4 = new Array(4);
28242
28243 // Generalized Greg Maxwell's trick
28244 var adjustCount = this.n && this.p.div(this.n);
28245 if (!adjustCount || adjustCount.cmpn(100) > 0) {
28246 this.redN = null;
28247 } else {
28248 this._maxwellTrick = true;
28249 this.redN = this.n.toRed(this.red);
28250 }
28251}
28252module.exports = BaseCurve;
28253
28254BaseCurve.prototype.point = function point() {
28255 throw new Error('Not implemented');
28256};
28257
28258BaseCurve.prototype.validate = function validate() {
28259 throw new Error('Not implemented');
28260};
28261
28262BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
28263 assert(p.precomputed);
28264 var doubles = p._getDoubles();
28265
28266 var naf = getNAF(k, 1);
28267 var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
28268 I /= 3;
28269
28270 // Translate into more windowed form
28271 var repr = [];
28272 for (var j = 0; j < naf.length; j += doubles.step) {
28273 var nafW = 0;
28274 for (var k = j + doubles.step - 1; k >= j; k--)
28275 nafW = (nafW << 1) + naf[k];
28276 repr.push(nafW);
28277 }
28278
28279 var a = this.jpoint(null, null, null);
28280 var b = this.jpoint(null, null, null);
28281 for (var i = I; i > 0; i--) {
28282 for (var j = 0; j < repr.length; j++) {
28283 var nafW = repr[j];
28284 if (nafW === i)
28285 b = b.mixedAdd(doubles.points[j]);
28286 else if (nafW === -i)
28287 b = b.mixedAdd(doubles.points[j].neg());
28288 }
28289 a = a.add(b);
28290 }
28291 return a.toP();
28292};
28293
28294BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
28295 var w = 4;
28296
28297 // Precompute window
28298 var nafPoints = p._getNAFPoints(w);
28299 w = nafPoints.wnd;
28300 var wnd = nafPoints.points;
28301
28302 // Get NAF form
28303 var naf = getNAF(k, w);
28304
28305 // Add `this`*(N+1) for every w-NAF index
28306 var acc = this.jpoint(null, null, null);
28307 for (var i = naf.length - 1; i >= 0; i--) {
28308 // Count zeroes
28309 for (var k = 0; i >= 0 && naf[i] === 0; i--)
28310 k++;
28311 if (i >= 0)
28312 k++;
28313 acc = acc.dblp(k);
28314
28315 if (i < 0)
28316 break;
28317 var z = naf[i];
28318 assert(z !== 0);
28319 if (p.type === 'affine') {
28320 // J +- P
28321 if (z > 0)
28322 acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
28323 else
28324 acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
28325 } else {
28326 // J +- J
28327 if (z > 0)
28328 acc = acc.add(wnd[(z - 1) >> 1]);
28329 else
28330 acc = acc.add(wnd[(-z - 1) >> 1].neg());
28331 }
28332 }
28333 return p.type === 'affine' ? acc.toP() : acc;
28334};
28335
28336BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
28337 points,
28338 coeffs,
28339 len,
28340 jacobianResult) {
28341 var wndWidth = this._wnafT1;
28342 var wnd = this._wnafT2;
28343 var naf = this._wnafT3;
28344
28345 // Fill all arrays
28346 var max = 0;
28347 for (var i = 0; i < len; i++) {
28348 var p = points[i];
28349 var nafPoints = p._getNAFPoints(defW);
28350 wndWidth[i] = nafPoints.wnd;
28351 wnd[i] = nafPoints.points;
28352 }
28353
28354 // Comb small window NAFs
28355 for (var i = len - 1; i >= 1; i -= 2) {
28356 var a = i - 1;
28357 var b = i;
28358 if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
28359 naf[a] = getNAF(coeffs[a], wndWidth[a]);
28360 naf[b] = getNAF(coeffs[b], wndWidth[b]);
28361 max = Math.max(naf[a].length, max);
28362 max = Math.max(naf[b].length, max);
28363 continue;
28364 }
28365
28366 var comb = [
28367 points[a], /* 1 */
28368 null, /* 3 */
28369 null, /* 5 */
28370 points[b] /* 7 */
28371 ];
28372
28373 // Try to avoid Projective points, if possible
28374 if (points[a].y.cmp(points[b].y) === 0) {
28375 comb[1] = points[a].add(points[b]);
28376 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
28377 } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
28378 comb[1] = points[a].toJ().mixedAdd(points[b]);
28379 comb[2] = points[a].add(points[b].neg());
28380 } else {
28381 comb[1] = points[a].toJ().mixedAdd(points[b]);
28382 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
28383 }
28384
28385 var index = [
28386 -3, /* -1 -1 */
28387 -1, /* -1 0 */
28388 -5, /* -1 1 */
28389 -7, /* 0 -1 */
28390 0, /* 0 0 */
28391 7, /* 0 1 */
28392 5, /* 1 -1 */
28393 1, /* 1 0 */
28394 3 /* 1 1 */
28395 ];
28396
28397 var jsf = getJSF(coeffs[a], coeffs[b]);
28398 max = Math.max(jsf[0].length, max);
28399 naf[a] = new Array(max);
28400 naf[b] = new Array(max);
28401 for (var j = 0; j < max; j++) {
28402 var ja = jsf[0][j] | 0;
28403 var jb = jsf[1][j] | 0;
28404
28405 naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
28406 naf[b][j] = 0;
28407 wnd[a] = comb;
28408 }
28409 }
28410
28411 var acc = this.jpoint(null, null, null);
28412 var tmp = this._wnafT4;
28413 for (var i = max; i >= 0; i--) {
28414 var k = 0;
28415
28416 while (i >= 0) {
28417 var zero = true;
28418 for (var j = 0; j < len; j++) {
28419 tmp[j] = naf[j][i] | 0;
28420 if (tmp[j] !== 0)
28421 zero = false;
28422 }
28423 if (!zero)
28424 break;
28425 k++;
28426 i--;
28427 }
28428 if (i >= 0)
28429 k++;
28430 acc = acc.dblp(k);
28431 if (i < 0)
28432 break;
28433
28434 for (var j = 0; j < len; j++) {
28435 var z = tmp[j];
28436 var p;
28437 if (z === 0)
28438 continue;
28439 else if (z > 0)
28440 p = wnd[j][(z - 1) >> 1];
28441 else if (z < 0)
28442 p = wnd[j][(-z - 1) >> 1].neg();
28443
28444 if (p.type === 'affine')
28445 acc = acc.mixedAdd(p);
28446 else
28447 acc = acc.add(p);
28448 }
28449 }
28450 // Zeroify references
28451 for (var i = 0; i < len; i++)
28452 wnd[i] = null;
28453
28454 if (jacobianResult)
28455 return acc;
28456 else
28457 return acc.toP();
28458};
28459
28460function BasePoint(curve, type) {
28461 this.curve = curve;
28462 this.type = type;
28463 this.precomputed = null;
28464}
28465BaseCurve.BasePoint = BasePoint;
28466
28467BasePoint.prototype.eq = function eq(/*other*/) {
28468 throw new Error('Not implemented');
28469};
28470
28471BasePoint.prototype.validate = function validate() {
28472 return this.curve.validate(this);
28473};
28474
28475BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
28476 bytes = utils.toArray(bytes, enc);
28477
28478 var len = this.p.byteLength();
28479
28480 // uncompressed, hybrid-odd, hybrid-even
28481 if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
28482 bytes.length - 1 === 2 * len) {
28483 if (bytes[0] === 0x06)
28484 assert(bytes[bytes.length - 1] % 2 === 0);
28485 else if (bytes[0] === 0x07)
28486 assert(bytes[bytes.length - 1] % 2 === 1);
28487
28488 var res = this.point(bytes.slice(1, 1 + len),
28489 bytes.slice(1 + len, 1 + 2 * len));
28490
28491 return res;
28492 } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
28493 bytes.length - 1 === len) {
28494 return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
28495 }
28496 throw new Error('Unknown point format');
28497};
28498
28499BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
28500 return this.encode(enc, true);
28501};
28502
28503BasePoint.prototype._encode = function _encode(compact) {
28504 var len = this.curve.p.byteLength();
28505 var x = this.getX().toArray('be', len);
28506
28507 if (compact)
28508 return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
28509
28510 return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
28511};
28512
28513BasePoint.prototype.encode = function encode(enc, compact) {
28514 return utils.encode(this._encode(compact), enc);
28515};
28516
28517BasePoint.prototype.precompute = function precompute(power) {
28518 if (this.precomputed)
28519 return this;
28520
28521 var precomputed = {
28522 doubles: null,
28523 naf: null,
28524 beta: null
28525 };
28526 precomputed.naf = this._getNAFPoints(8);
28527 precomputed.doubles = this._getDoubles(4, power);
28528 precomputed.beta = this._getBeta();
28529 this.precomputed = precomputed;
28530
28531 return this;
28532};
28533
28534BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
28535 if (!this.precomputed)
28536 return false;
28537
28538 var doubles = this.precomputed.doubles;
28539 if (!doubles)
28540 return false;
28541
28542 return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
28543};
28544
28545BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
28546 if (this.precomputed && this.precomputed.doubles)
28547 return this.precomputed.doubles;
28548
28549 var doubles = [ this ];
28550 var acc = this;
28551 for (var i = 0; i < power; i += step) {
28552 for (var j = 0; j < step; j++)
28553 acc = acc.dbl();
28554 doubles.push(acc);
28555 }
28556 return {
28557 step: step,
28558 points: doubles
28559 };
28560};
28561
28562BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
28563 if (this.precomputed && this.precomputed.naf)
28564 return this.precomputed.naf;
28565
28566 var res = [ this ];
28567 var max = (1 << wnd) - 1;
28568 var dbl = max === 1 ? null : this.dbl();
28569 for (var i = 1; i < max; i++)
28570 res[i] = res[i - 1].add(dbl);
28571 return {
28572 wnd: wnd,
28573 points: res
28574 };
28575};
28576
28577BasePoint.prototype._getBeta = function _getBeta() {
28578 return null;
28579};
28580
28581BasePoint.prototype.dblp = function dblp(k) {
28582 var r = this;
28583 for (var i = 0; i < k; i++)
28584 r = r.dbl();
28585 return r;
28586};
28587
28588},{"../../elliptic":39,"bn.js":33}],41:[function(require,module,exports){
28589'use strict';
28590
28591var curve = require('../curve');
28592var elliptic = require('../../elliptic');
28593var BN = require('bn.js');
28594var inherits = require('inherits');
28595var Base = curve.base;
28596
28597var assert = elliptic.utils.assert;
28598
28599function EdwardsCurve(conf) {
28600 // NOTE: Important as we are creating point in Base.call()
28601 this.twisted = (conf.a | 0) !== 1;
28602 this.mOneA = this.twisted && (conf.a | 0) === -1;
28603 this.extended = this.mOneA;
28604
28605 Base.call(this, 'edwards', conf);
28606
28607 this.a = new BN(conf.a, 16).umod(this.red.m);
28608 this.a = this.a.toRed(this.red);
28609 this.c = new BN(conf.c, 16).toRed(this.red);
28610 this.c2 = this.c.redSqr();
28611 this.d = new BN(conf.d, 16).toRed(this.red);
28612 this.dd = this.d.redAdd(this.d);
28613
28614 assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
28615 this.oneC = (conf.c | 0) === 1;
28616}
28617inherits(EdwardsCurve, Base);
28618module.exports = EdwardsCurve;
28619
28620EdwardsCurve.prototype._mulA = function _mulA(num) {
28621 if (this.mOneA)
28622 return num.redNeg();
28623 else
28624 return this.a.redMul(num);
28625};
28626
28627EdwardsCurve.prototype._mulC = function _mulC(num) {
28628 if (this.oneC)
28629 return num;
28630 else
28631 return this.c.redMul(num);
28632};
28633
28634// Just for compatibility with Short curve
28635EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
28636 return this.point(x, y, z, t);
28637};
28638
28639EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
28640 x = new BN(x, 16);
28641 if (!x.red)
28642 x = x.toRed(this.red);
28643
28644 var x2 = x.redSqr();
28645 var rhs = this.c2.redSub(this.a.redMul(x2));
28646 var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
28647
28648 var y2 = rhs.redMul(lhs.redInvm());
28649 var y = y2.redSqrt();
28650 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
28651 throw new Error('invalid point');
28652
28653 var isOdd = y.fromRed().isOdd();
28654 if (odd && !isOdd || !odd && isOdd)
28655 y = y.redNeg();
28656
28657 return this.point(x, y);
28658};
28659
28660EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
28661 y = new BN(y, 16);
28662 if (!y.red)
28663 y = y.toRed(this.red);
28664
28665 // x^2 = (y^2 - 1) / (d y^2 + 1)
28666 var y2 = y.redSqr();
28667 var lhs = y2.redSub(this.one);
28668 var rhs = y2.redMul(this.d).redAdd(this.one);
28669 var x2 = lhs.redMul(rhs.redInvm());
28670
28671 if (x2.cmp(this.zero) === 0) {
28672 if (odd)
28673 throw new Error('invalid point');
28674 else
28675 return this.point(this.zero, y);
28676 }
28677
28678 var x = x2.redSqrt();
28679 if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
28680 throw new Error('invalid point');
28681
28682 if (x.isOdd() !== odd)
28683 x = x.redNeg();
28684
28685 return this.point(x, y);
28686};
28687
28688EdwardsCurve.prototype.validate = function validate(point) {
28689 if (point.isInfinity())
28690 return true;
28691
28692 // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
28693 point.normalize();
28694
28695 var x2 = point.x.redSqr();
28696 var y2 = point.y.redSqr();
28697 var lhs = x2.redMul(this.a).redAdd(y2);
28698 var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
28699
28700 return lhs.cmp(rhs) === 0;
28701};
28702
28703function Point(curve, x, y, z, t) {
28704 Base.BasePoint.call(this, curve, 'projective');
28705 if (x === null && y === null && z === null) {
28706 this.x = this.curve.zero;
28707 this.y = this.curve.one;
28708 this.z = this.curve.one;
28709 this.t = this.curve.zero;
28710 this.zOne = true;
28711 } else {
28712 this.x = new BN(x, 16);
28713 this.y = new BN(y, 16);
28714 this.z = z ? new BN(z, 16) : this.curve.one;
28715 this.t = t && new BN(t, 16);
28716 if (!this.x.red)
28717 this.x = this.x.toRed(this.curve.red);
28718 if (!this.y.red)
28719 this.y = this.y.toRed(this.curve.red);
28720 if (!this.z.red)
28721 this.z = this.z.toRed(this.curve.red);
28722 if (this.t && !this.t.red)
28723 this.t = this.t.toRed(this.curve.red);
28724 this.zOne = this.z === this.curve.one;
28725
28726 // Use extended coordinates
28727 if (this.curve.extended && !this.t) {
28728 this.t = this.x.redMul(this.y);
28729 if (!this.zOne)
28730 this.t = this.t.redMul(this.z.redInvm());
28731 }
28732 }
28733}
28734inherits(Point, Base.BasePoint);
28735
28736EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
28737 return Point.fromJSON(this, obj);
28738};
28739
28740EdwardsCurve.prototype.point = function point(x, y, z, t) {
28741 return new Point(this, x, y, z, t);
28742};
28743
28744Point.fromJSON = function fromJSON(curve, obj) {
28745 return new Point(curve, obj[0], obj[1], obj[2]);
28746};
28747
28748Point.prototype.inspect = function inspect() {
28749 if (this.isInfinity())
28750 return '<EC Point Infinity>';
28751 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
28752 ' y: ' + this.y.fromRed().toString(16, 2) +
28753 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
28754};
28755
28756Point.prototype.isInfinity = function isInfinity() {
28757 // XXX This code assumes that zero is always zero in red
28758 return this.x.cmpn(0) === 0 &&
28759 this.y.cmp(this.z) === 0;
28760};
28761
28762Point.prototype._extDbl = function _extDbl() {
28763 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
28764 // #doubling-dbl-2008-hwcd
28765 // 4M + 4S
28766
28767 // A = X1^2
28768 var a = this.x.redSqr();
28769 // B = Y1^2
28770 var b = this.y.redSqr();
28771 // C = 2 * Z1^2
28772 var c = this.z.redSqr();
28773 c = c.redIAdd(c);
28774 // D = a * A
28775 var d = this.curve._mulA(a);
28776 // E = (X1 + Y1)^2 - A - B
28777 var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
28778 // G = D + B
28779 var g = d.redAdd(b);
28780 // F = G - C
28781 var f = g.redSub(c);
28782 // H = D - B
28783 var h = d.redSub(b);
28784 // X3 = E * F
28785 var nx = e.redMul(f);
28786 // Y3 = G * H
28787 var ny = g.redMul(h);
28788 // T3 = E * H
28789 var nt = e.redMul(h);
28790 // Z3 = F * G
28791 var nz = f.redMul(g);
28792 return this.curve.point(nx, ny, nz, nt);
28793};
28794
28795Point.prototype._projDbl = function _projDbl() {
28796 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
28797 // #doubling-dbl-2008-bbjlp
28798 // #doubling-dbl-2007-bl
28799 // and others
28800 // Generally 3M + 4S or 2M + 4S
28801
28802 // B = (X1 + Y1)^2
28803 var b = this.x.redAdd(this.y).redSqr();
28804 // C = X1^2
28805 var c = this.x.redSqr();
28806 // D = Y1^2
28807 var d = this.y.redSqr();
28808
28809 var nx;
28810 var ny;
28811 var nz;
28812 if (this.curve.twisted) {
28813 // E = a * C
28814 var e = this.curve._mulA(c);
28815 // F = E + D
28816 var f = e.redAdd(d);
28817 if (this.zOne) {
28818 // X3 = (B - C - D) * (F - 2)
28819 nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
28820 // Y3 = F * (E - D)
28821 ny = f.redMul(e.redSub(d));
28822 // Z3 = F^2 - 2 * F
28823 nz = f.redSqr().redSub(f).redSub(f);
28824 } else {
28825 // H = Z1^2
28826 var h = this.z.redSqr();
28827 // J = F - 2 * H
28828 var j = f.redSub(h).redISub(h);
28829 // X3 = (B-C-D)*J
28830 nx = b.redSub(c).redISub(d).redMul(j);
28831 // Y3 = F * (E - D)
28832 ny = f.redMul(e.redSub(d));
28833 // Z3 = F * J
28834 nz = f.redMul(j);
28835 }
28836 } else {
28837 // E = C + D
28838 var e = c.redAdd(d);
28839 // H = (c * Z1)^2
28840 var h = this.curve._mulC(this.c.redMul(this.z)).redSqr();
28841 // J = E - 2 * H
28842 var j = e.redSub(h).redSub(h);
28843 // X3 = c * (B - E) * J
28844 nx = this.curve._mulC(b.redISub(e)).redMul(j);
28845 // Y3 = c * E * (C - D)
28846 ny = this.curve._mulC(e).redMul(c.redISub(d));
28847 // Z3 = E * J
28848 nz = e.redMul(j);
28849 }
28850 return this.curve.point(nx, ny, nz);
28851};
28852
28853Point.prototype.dbl = function dbl() {
28854 if (this.isInfinity())
28855 return this;
28856
28857 // Double in extended coordinates
28858 if (this.curve.extended)
28859 return this._extDbl();
28860 else
28861 return this._projDbl();
28862};
28863
28864Point.prototype._extAdd = function _extAdd(p) {
28865 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
28866 // #addition-add-2008-hwcd-3
28867 // 8M
28868
28869 // A = (Y1 - X1) * (Y2 - X2)
28870 var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
28871 // B = (Y1 + X1) * (Y2 + X2)
28872 var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
28873 // C = T1 * k * T2
28874 var c = this.t.redMul(this.curve.dd).redMul(p.t);
28875 // D = Z1 * 2 * Z2
28876 var d = this.z.redMul(p.z.redAdd(p.z));
28877 // E = B - A
28878 var e = b.redSub(a);
28879 // F = D - C
28880 var f = d.redSub(c);
28881 // G = D + C
28882 var g = d.redAdd(c);
28883 // H = B + A
28884 var h = b.redAdd(a);
28885 // X3 = E * F
28886 var nx = e.redMul(f);
28887 // Y3 = G * H
28888 var ny = g.redMul(h);
28889 // T3 = E * H
28890 var nt = e.redMul(h);
28891 // Z3 = F * G
28892 var nz = f.redMul(g);
28893 return this.curve.point(nx, ny, nz, nt);
28894};
28895
28896Point.prototype._projAdd = function _projAdd(p) {
28897 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
28898 // #addition-add-2008-bbjlp
28899 // #addition-add-2007-bl
28900 // 10M + 1S
28901
28902 // A = Z1 * Z2
28903 var a = this.z.redMul(p.z);
28904 // B = A^2
28905 var b = a.redSqr();
28906 // C = X1 * X2
28907 var c = this.x.redMul(p.x);
28908 // D = Y1 * Y2
28909 var d = this.y.redMul(p.y);
28910 // E = d * C * D
28911 var e = this.curve.d.redMul(c).redMul(d);
28912 // F = B - E
28913 var f = b.redSub(e);
28914 // G = B + E
28915 var g = b.redAdd(e);
28916 // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
28917 var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
28918 var nx = a.redMul(f).redMul(tmp);
28919 var ny;
28920 var nz;
28921 if (this.curve.twisted) {
28922 // Y3 = A * G * (D - a * C)
28923 ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
28924 // Z3 = F * G
28925 nz = f.redMul(g);
28926 } else {
28927 // Y3 = A * G * (D - C)
28928 ny = a.redMul(g).redMul(d.redSub(c));
28929 // Z3 = c * F * G
28930 nz = this.curve._mulC(f).redMul(g);
28931 }
28932 return this.curve.point(nx, ny, nz);
28933};
28934
28935Point.prototype.add = function add(p) {
28936 if (this.isInfinity())
28937 return p;
28938 if (p.isInfinity())
28939 return this;
28940
28941 if (this.curve.extended)
28942 return this._extAdd(p);
28943 else
28944 return this._projAdd(p);
28945};
28946
28947Point.prototype.mul = function mul(k) {
28948 if (this._hasDoubles(k))
28949 return this.curve._fixedNafMul(this, k);
28950 else
28951 return this.curve._wnafMul(this, k);
28952};
28953
28954Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
28955 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false);
28956};
28957
28958Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
28959 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true);
28960};
28961
28962Point.prototype.normalize = function normalize() {
28963 if (this.zOne)
28964 return this;
28965
28966 // Normalize coordinates
28967 var zi = this.z.redInvm();
28968 this.x = this.x.redMul(zi);
28969 this.y = this.y.redMul(zi);
28970 if (this.t)
28971 this.t = this.t.redMul(zi);
28972 this.z = this.curve.one;
28973 this.zOne = true;
28974 return this;
28975};
28976
28977Point.prototype.neg = function neg() {
28978 return this.curve.point(this.x.redNeg(),
28979 this.y,
28980 this.z,
28981 this.t && this.t.redNeg());
28982};
28983
28984Point.prototype.getX = function getX() {
28985 this.normalize();
28986 return this.x.fromRed();
28987};
28988
28989Point.prototype.getY = function getY() {
28990 this.normalize();
28991 return this.y.fromRed();
28992};
28993
28994Point.prototype.eq = function eq(other) {
28995 return this === other ||
28996 this.getX().cmp(other.getX()) === 0 &&
28997 this.getY().cmp(other.getY()) === 0;
28998};
28999
29000Point.prototype.eqXToP = function eqXToP(x) {
29001 var rx = x.toRed(this.curve.red).redMul(this.z);
29002 if (this.x.cmp(rx) === 0)
29003 return true;
29004
29005 var xc = x.clone();
29006 var t = this.curve.redN.redMul(this.z);
29007 for (;;) {
29008 xc.iadd(this.curve.n);
29009 if (xc.cmp(this.curve.p) >= 0)
29010 return false;
29011
29012 rx.redIAdd(t);
29013 if (this.x.cmp(rx) === 0)
29014 return true;
29015 }
29016 return false;
29017};
29018
29019// Compatibility with BaseCurve
29020Point.prototype.toP = Point.prototype.normalize;
29021Point.prototype.mixedAdd = Point.prototype.add;
29022
29023},{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],42:[function(require,module,exports){
29024'use strict';
29025
29026var curve = exports;
29027
29028curve.base = require('./base');
29029curve.short = require('./short');
29030curve.mont = require('./mont');
29031curve.edwards = require('./edwards');
29032
29033},{"./base":40,"./edwards":41,"./mont":43,"./short":44}],43:[function(require,module,exports){
29034'use strict';
29035
29036var curve = require('../curve');
29037var BN = require('bn.js');
29038var inherits = require('inherits');
29039var Base = curve.base;
29040
29041var elliptic = require('../../elliptic');
29042var utils = elliptic.utils;
29043
29044function MontCurve(conf) {
29045 Base.call(this, 'mont', conf);
29046
29047 this.a = new BN(conf.a, 16).toRed(this.red);
29048 this.b = new BN(conf.b, 16).toRed(this.red);
29049 this.i4 = new BN(4).toRed(this.red).redInvm();
29050 this.two = new BN(2).toRed(this.red);
29051 this.a24 = this.i4.redMul(this.a.redAdd(this.two));
29052}
29053inherits(MontCurve, Base);
29054module.exports = MontCurve;
29055
29056MontCurve.prototype.validate = function validate(point) {
29057 var x = point.normalize().x;
29058 var x2 = x.redSqr();
29059 var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
29060 var y = rhs.redSqrt();
29061
29062 return y.redSqr().cmp(rhs) === 0;
29063};
29064
29065function Point(curve, x, z) {
29066 Base.BasePoint.call(this, curve, 'projective');
29067 if (x === null && z === null) {
29068 this.x = this.curve.one;
29069 this.z = this.curve.zero;
29070 } else {
29071 this.x = new BN(x, 16);
29072 this.z = new BN(z, 16);
29073 if (!this.x.red)
29074 this.x = this.x.toRed(this.curve.red);
29075 if (!this.z.red)
29076 this.z = this.z.toRed(this.curve.red);
29077 }
29078}
29079inherits(Point, Base.BasePoint);
29080
29081MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
29082 return this.point(utils.toArray(bytes, enc), 1);
29083};
29084
29085MontCurve.prototype.point = function point(x, z) {
29086 return new Point(this, x, z);
29087};
29088
29089MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
29090 return Point.fromJSON(this, obj);
29091};
29092
29093Point.prototype.precompute = function precompute() {
29094 // No-op
29095};
29096
29097Point.prototype._encode = function _encode() {
29098 return this.getX().toArray('be', this.curve.p.byteLength());
29099};
29100
29101Point.fromJSON = function fromJSON(curve, obj) {
29102 return new Point(curve, obj[0], obj[1] || curve.one);
29103};
29104
29105Point.prototype.inspect = function inspect() {
29106 if (this.isInfinity())
29107 return '<EC Point Infinity>';
29108 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
29109 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
29110};
29111
29112Point.prototype.isInfinity = function isInfinity() {
29113 // XXX This code assumes that zero is always zero in red
29114 return this.z.cmpn(0) === 0;
29115};
29116
29117Point.prototype.dbl = function dbl() {
29118 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
29119 // 2M + 2S + 4A
29120
29121 // A = X1 + Z1
29122 var a = this.x.redAdd(this.z);
29123 // AA = A^2
29124 var aa = a.redSqr();
29125 // B = X1 - Z1
29126 var b = this.x.redSub(this.z);
29127 // BB = B^2
29128 var bb = b.redSqr();
29129 // C = AA - BB
29130 var c = aa.redSub(bb);
29131 // X3 = AA * BB
29132 var nx = aa.redMul(bb);
29133 // Z3 = C * (BB + A24 * C)
29134 var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
29135 return this.curve.point(nx, nz);
29136};
29137
29138Point.prototype.add = function add() {
29139 throw new Error('Not supported on Montgomery curve');
29140};
29141
29142Point.prototype.diffAdd = function diffAdd(p, diff) {
29143 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
29144 // 4M + 2S + 6A
29145
29146 // A = X2 + Z2
29147 var a = this.x.redAdd(this.z);
29148 // B = X2 - Z2
29149 var b = this.x.redSub(this.z);
29150 // C = X3 + Z3
29151 var c = p.x.redAdd(p.z);
29152 // D = X3 - Z3
29153 var d = p.x.redSub(p.z);
29154 // DA = D * A
29155 var da = d.redMul(a);
29156 // CB = C * B
29157 var cb = c.redMul(b);
29158 // X5 = Z1 * (DA + CB)^2
29159 var nx = diff.z.redMul(da.redAdd(cb).redSqr());
29160 // Z5 = X1 * (DA - CB)^2
29161 var nz = diff.x.redMul(da.redISub(cb).redSqr());
29162 return this.curve.point(nx, nz);
29163};
29164
29165Point.prototype.mul = function mul(k) {
29166 var t = k.clone();
29167 var a = this; // (N / 2) * Q + Q
29168 var b = this.curve.point(null, null); // (N / 2) * Q
29169 var c = this; // Q
29170
29171 for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
29172 bits.push(t.andln(1));
29173
29174 for (var i = bits.length - 1; i >= 0; i--) {
29175 if (bits[i] === 0) {
29176 // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
29177 a = a.diffAdd(b, c);
29178 // N * Q = 2 * ((N / 2) * Q + Q))
29179 b = b.dbl();
29180 } else {
29181 // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
29182 b = a.diffAdd(b, c);
29183 // N * Q + Q = 2 * ((N / 2) * Q + Q)
29184 a = a.dbl();
29185 }
29186 }
29187 return b;
29188};
29189
29190Point.prototype.mulAdd = function mulAdd() {
29191 throw new Error('Not supported on Montgomery curve');
29192};
29193
29194Point.prototype.jumlAdd = function jumlAdd() {
29195 throw new Error('Not supported on Montgomery curve');
29196};
29197
29198Point.prototype.eq = function eq(other) {
29199 return this.getX().cmp(other.getX()) === 0;
29200};
29201
29202Point.prototype.normalize = function normalize() {
29203 this.x = this.x.redMul(this.z.redInvm());
29204 this.z = this.curve.one;
29205 return this;
29206};
29207
29208Point.prototype.getX = function getX() {
29209 // Normalize coordinates
29210 this.normalize();
29211
29212 return this.x.fromRed();
29213};
29214
29215},{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],44:[function(require,module,exports){
29216'use strict';
29217
29218var curve = require('../curve');
29219var elliptic = require('../../elliptic');
29220var BN = require('bn.js');
29221var inherits = require('inherits');
29222var Base = curve.base;
29223
29224var assert = elliptic.utils.assert;
29225
29226function ShortCurve(conf) {
29227 Base.call(this, 'short', conf);
29228
29229 this.a = new BN(conf.a, 16).toRed(this.red);
29230 this.b = new BN(conf.b, 16).toRed(this.red);
29231 this.tinv = this.two.redInvm();
29232
29233 this.zeroA = this.a.fromRed().cmpn(0) === 0;
29234 this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
29235
29236 // If the curve is endomorphic, precalculate beta and lambda
29237 this.endo = this._getEndomorphism(conf);
29238 this._endoWnafT1 = new Array(4);
29239 this._endoWnafT2 = new Array(4);
29240}
29241inherits(ShortCurve, Base);
29242module.exports = ShortCurve;
29243
29244ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
29245 // No efficient endomorphism
29246 if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
29247 return;
29248
29249 // Compute beta and lambda, that lambda * P = (beta * Px; Py)
29250 var beta;
29251 var lambda;
29252 if (conf.beta) {
29253 beta = new BN(conf.beta, 16).toRed(this.red);
29254 } else {
29255 var betas = this._getEndoRoots(this.p);
29256 // Choose the smallest beta
29257 beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
29258 beta = beta.toRed(this.red);
29259 }
29260 if (conf.lambda) {
29261 lambda = new BN(conf.lambda, 16);
29262 } else {
29263 // Choose the lambda that is matching selected beta
29264 var lambdas = this._getEndoRoots(this.n);
29265 if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
29266 lambda = lambdas[0];
29267 } else {
29268 lambda = lambdas[1];
29269 assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
29270 }
29271 }
29272
29273 // Get basis vectors, used for balanced length-two representation
29274 var basis;
29275 if (conf.basis) {
29276 basis = conf.basis.map(function(vec) {
29277 return {
29278 a: new BN(vec.a, 16),
29279 b: new BN(vec.b, 16)
29280 };
29281 });
29282 } else {
29283 basis = this._getEndoBasis(lambda);
29284 }
29285
29286 return {
29287 beta: beta,
29288 lambda: lambda,
29289 basis: basis
29290 };
29291};
29292
29293ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
29294 // Find roots of for x^2 + x + 1 in F
29295 // Root = (-1 +- Sqrt(-3)) / 2
29296 //
29297 var red = num === this.p ? this.red : BN.mont(num);
29298 var tinv = new BN(2).toRed(red).redInvm();
29299 var ntinv = tinv.redNeg();
29300
29301 var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
29302
29303 var l1 = ntinv.redAdd(s).fromRed();
29304 var l2 = ntinv.redSub(s).fromRed();
29305 return [ l1, l2 ];
29306};
29307
29308ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
29309 // aprxSqrt >= sqrt(this.n)
29310 var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
29311
29312 // 3.74
29313 // Run EGCD, until r(L + 1) < aprxSqrt
29314 var u = lambda;
29315 var v = this.n.clone();
29316 var x1 = new BN(1);
29317 var y1 = new BN(0);
29318 var x2 = new BN(0);
29319 var y2 = new BN(1);
29320
29321 // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
29322 var a0;
29323 var b0;
29324 // First vector
29325 var a1;
29326 var b1;
29327 // Second vector
29328 var a2;
29329 var b2;
29330
29331 var prevR;
29332 var i = 0;
29333 var r;
29334 var x;
29335 while (u.cmpn(0) !== 0) {
29336 var q = v.div(u);
29337 r = v.sub(q.mul(u));
29338 x = x2.sub(q.mul(x1));
29339 var y = y2.sub(q.mul(y1));
29340
29341 if (!a1 && r.cmp(aprxSqrt) < 0) {
29342 a0 = prevR.neg();
29343 b0 = x1;
29344 a1 = r.neg();
29345 b1 = x;
29346 } else if (a1 && ++i === 2) {
29347 break;
29348 }
29349 prevR = r;
29350
29351 v = u;
29352 u = r;
29353 x2 = x1;
29354 x1 = x;
29355 y2 = y1;
29356 y1 = y;
29357 }
29358 a2 = r.neg();
29359 b2 = x;
29360
29361 var len1 = a1.sqr().add(b1.sqr());
29362 var len2 = a2.sqr().add(b2.sqr());
29363 if (len2.cmp(len1) >= 0) {
29364 a2 = a0;
29365 b2 = b0;
29366 }
29367
29368 // Normalize signs
29369 if (a1.negative) {
29370 a1 = a1.neg();
29371 b1 = b1.neg();
29372 }
29373 if (a2.negative) {
29374 a2 = a2.neg();
29375 b2 = b2.neg();
29376 }
29377
29378 return [
29379 { a: a1, b: b1 },
29380 { a: a2, b: b2 }
29381 ];
29382};
29383
29384ShortCurve.prototype._endoSplit = function _endoSplit(k) {
29385 var basis = this.endo.basis;
29386 var v1 = basis[0];
29387 var v2 = basis[1];
29388
29389 var c1 = v2.b.mul(k).divRound(this.n);
29390 var c2 = v1.b.neg().mul(k).divRound(this.n);
29391
29392 var p1 = c1.mul(v1.a);
29393 var p2 = c2.mul(v2.a);
29394 var q1 = c1.mul(v1.b);
29395 var q2 = c2.mul(v2.b);
29396
29397 // Calculate answer
29398 var k1 = k.sub(p1).sub(p2);
29399 var k2 = q1.add(q2).neg();
29400 return { k1: k1, k2: k2 };
29401};
29402
29403ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
29404 x = new BN(x, 16);
29405 if (!x.red)
29406 x = x.toRed(this.red);
29407
29408 var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
29409 var y = y2.redSqrt();
29410 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
29411 throw new Error('invalid point');
29412
29413 // XXX Is there any way to tell if the number is odd without converting it
29414 // to non-red form?
29415 var isOdd = y.fromRed().isOdd();
29416 if (odd && !isOdd || !odd && isOdd)
29417 y = y.redNeg();
29418
29419 return this.point(x, y);
29420};
29421
29422ShortCurve.prototype.validate = function validate(point) {
29423 if (point.inf)
29424 return true;
29425
29426 var x = point.x;
29427 var y = point.y;
29428
29429 var ax = this.a.redMul(x);
29430 var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
29431 return y.redSqr().redISub(rhs).cmpn(0) === 0;
29432};
29433
29434ShortCurve.prototype._endoWnafMulAdd =
29435 function _endoWnafMulAdd(points, coeffs, jacobianResult) {
29436 var npoints = this._endoWnafT1;
29437 var ncoeffs = this._endoWnafT2;
29438 for (var i = 0; i < points.length; i++) {
29439 var split = this._endoSplit(coeffs[i]);
29440 var p = points[i];
29441 var beta = p._getBeta();
29442
29443 if (split.k1.negative) {
29444 split.k1.ineg();
29445 p = p.neg(true);
29446 }
29447 if (split.k2.negative) {
29448 split.k2.ineg();
29449 beta = beta.neg(true);
29450 }
29451
29452 npoints[i * 2] = p;
29453 npoints[i * 2 + 1] = beta;
29454 ncoeffs[i * 2] = split.k1;
29455 ncoeffs[i * 2 + 1] = split.k2;
29456 }
29457 var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
29458
29459 // Clean-up references to points and coefficients
29460 for (var j = 0; j < i * 2; j++) {
29461 npoints[j] = null;
29462 ncoeffs[j] = null;
29463 }
29464 return res;
29465};
29466
29467function Point(curve, x, y, isRed) {
29468 Base.BasePoint.call(this, curve, 'affine');
29469 if (x === null && y === null) {
29470 this.x = null;
29471 this.y = null;
29472 this.inf = true;
29473 } else {
29474 this.x = new BN(x, 16);
29475 this.y = new BN(y, 16);
29476 // Force redgomery representation when loading from JSON
29477 if (isRed) {
29478 this.x.forceRed(this.curve.red);
29479 this.y.forceRed(this.curve.red);
29480 }
29481 if (!this.x.red)
29482 this.x = this.x.toRed(this.curve.red);
29483 if (!this.y.red)
29484 this.y = this.y.toRed(this.curve.red);
29485 this.inf = false;
29486 }
29487}
29488inherits(Point, Base.BasePoint);
29489
29490ShortCurve.prototype.point = function point(x, y, isRed) {
29491 return new Point(this, x, y, isRed);
29492};
29493
29494ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
29495 return Point.fromJSON(this, obj, red);
29496};
29497
29498Point.prototype._getBeta = function _getBeta() {
29499 if (!this.curve.endo)
29500 return;
29501
29502 var pre = this.precomputed;
29503 if (pre && pre.beta)
29504 return pre.beta;
29505
29506 var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
29507 if (pre) {
29508 var curve = this.curve;
29509 var endoMul = function(p) {
29510 return curve.point(p.x.redMul(curve.endo.beta), p.y);
29511 };
29512 pre.beta = beta;
29513 beta.precomputed = {
29514 beta: null,
29515 naf: pre.naf && {
29516 wnd: pre.naf.wnd,
29517 points: pre.naf.points.map(endoMul)
29518 },
29519 doubles: pre.doubles && {
29520 step: pre.doubles.step,
29521 points: pre.doubles.points.map(endoMul)
29522 }
29523 };
29524 }
29525 return beta;
29526};
29527
29528Point.prototype.toJSON = function toJSON() {
29529 if (!this.precomputed)
29530 return [ this.x, this.y ];
29531
29532 return [ this.x, this.y, this.precomputed && {
29533 doubles: this.precomputed.doubles && {
29534 step: this.precomputed.doubles.step,
29535 points: this.precomputed.doubles.points.slice(1)
29536 },
29537 naf: this.precomputed.naf && {
29538 wnd: this.precomputed.naf.wnd,
29539 points: this.precomputed.naf.points.slice(1)
29540 }
29541 } ];
29542};
29543
29544Point.fromJSON = function fromJSON(curve, obj, red) {
29545 if (typeof obj === 'string')
29546 obj = JSON.parse(obj);
29547 var res = curve.point(obj[0], obj[1], red);
29548 if (!obj[2])
29549 return res;
29550
29551 function obj2point(obj) {
29552 return curve.point(obj[0], obj[1], red);
29553 }
29554
29555 var pre = obj[2];
29556 res.precomputed = {
29557 beta: null,
29558 doubles: pre.doubles && {
29559 step: pre.doubles.step,
29560 points: [ res ].concat(pre.doubles.points.map(obj2point))
29561 },
29562 naf: pre.naf && {
29563 wnd: pre.naf.wnd,
29564 points: [ res ].concat(pre.naf.points.map(obj2point))
29565 }
29566 };
29567 return res;
29568};
29569
29570Point.prototype.inspect = function inspect() {
29571 if (this.isInfinity())
29572 return '<EC Point Infinity>';
29573 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
29574 ' y: ' + this.y.fromRed().toString(16, 2) + '>';
29575};
29576
29577Point.prototype.isInfinity = function isInfinity() {
29578 return this.inf;
29579};
29580
29581Point.prototype.add = function add(p) {
29582 // O + P = P
29583 if (this.inf)
29584 return p;
29585
29586 // P + O = P
29587 if (p.inf)
29588 return this;
29589
29590 // P + P = 2P
29591 if (this.eq(p))
29592 return this.dbl();
29593
29594 // P + (-P) = O
29595 if (this.neg().eq(p))
29596 return this.curve.point(null, null);
29597
29598 // P + Q = O
29599 if (this.x.cmp(p.x) === 0)
29600 return this.curve.point(null, null);
29601
29602 var c = this.y.redSub(p.y);
29603 if (c.cmpn(0) !== 0)
29604 c = c.redMul(this.x.redSub(p.x).redInvm());
29605 var nx = c.redSqr().redISub(this.x).redISub(p.x);
29606 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
29607 return this.curve.point(nx, ny);
29608};
29609
29610Point.prototype.dbl = function dbl() {
29611 if (this.inf)
29612 return this;
29613
29614 // 2P = O
29615 var ys1 = this.y.redAdd(this.y);
29616 if (ys1.cmpn(0) === 0)
29617 return this.curve.point(null, null);
29618
29619 var a = this.curve.a;
29620
29621 var x2 = this.x.redSqr();
29622 var dyinv = ys1.redInvm();
29623 var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
29624
29625 var nx = c.redSqr().redISub(this.x.redAdd(this.x));
29626 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
29627 return this.curve.point(nx, ny);
29628};
29629
29630Point.prototype.getX = function getX() {
29631 return this.x.fromRed();
29632};
29633
29634Point.prototype.getY = function getY() {
29635 return this.y.fromRed();
29636};
29637
29638Point.prototype.mul = function mul(k) {
29639 k = new BN(k, 16);
29640
29641 if (this._hasDoubles(k))
29642 return this.curve._fixedNafMul(this, k);
29643 else if (this.curve.endo)
29644 return this.curve._endoWnafMulAdd([ this ], [ k ]);
29645 else
29646 return this.curve._wnafMul(this, k);
29647};
29648
29649Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
29650 var points = [ this, p2 ];
29651 var coeffs = [ k1, k2 ];
29652 if (this.curve.endo)
29653 return this.curve._endoWnafMulAdd(points, coeffs);
29654 else
29655 return this.curve._wnafMulAdd(1, points, coeffs, 2);
29656};
29657
29658Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
29659 var points = [ this, p2 ];
29660 var coeffs = [ k1, k2 ];
29661 if (this.curve.endo)
29662 return this.curve._endoWnafMulAdd(points, coeffs, true);
29663 else
29664 return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
29665};
29666
29667Point.prototype.eq = function eq(p) {
29668 return this === p ||
29669 this.inf === p.inf &&
29670 (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
29671};
29672
29673Point.prototype.neg = function neg(_precompute) {
29674 if (this.inf)
29675 return this;
29676
29677 var res = this.curve.point(this.x, this.y.redNeg());
29678 if (_precompute && this.precomputed) {
29679 var pre = this.precomputed;
29680 var negate = function(p) {
29681 return p.neg();
29682 };
29683 res.precomputed = {
29684 naf: pre.naf && {
29685 wnd: pre.naf.wnd,
29686 points: pre.naf.points.map(negate)
29687 },
29688 doubles: pre.doubles && {
29689 step: pre.doubles.step,
29690 points: pre.doubles.points.map(negate)
29691 }
29692 };
29693 }
29694 return res;
29695};
29696
29697Point.prototype.toJ = function toJ() {
29698 if (this.inf)
29699 return this.curve.jpoint(null, null, null);
29700
29701 var res = this.curve.jpoint(this.x, this.y, this.curve.one);
29702 return res;
29703};
29704
29705function JPoint(curve, x, y, z) {
29706 Base.BasePoint.call(this, curve, 'jacobian');
29707 if (x === null && y === null && z === null) {
29708 this.x = this.curve.one;
29709 this.y = this.curve.one;
29710 this.z = new BN(0);
29711 } else {
29712 this.x = new BN(x, 16);
29713 this.y = new BN(y, 16);
29714 this.z = new BN(z, 16);
29715 }
29716 if (!this.x.red)
29717 this.x = this.x.toRed(this.curve.red);
29718 if (!this.y.red)
29719 this.y = this.y.toRed(this.curve.red);
29720 if (!this.z.red)
29721 this.z = this.z.toRed(this.curve.red);
29722
29723 this.zOne = this.z === this.curve.one;
29724}
29725inherits(JPoint, Base.BasePoint);
29726
29727ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
29728 return new JPoint(this, x, y, z);
29729};
29730
29731JPoint.prototype.toP = function toP() {
29732 if (this.isInfinity())
29733 return this.curve.point(null, null);
29734
29735 var zinv = this.z.redInvm();
29736 var zinv2 = zinv.redSqr();
29737 var ax = this.x.redMul(zinv2);
29738 var ay = this.y.redMul(zinv2).redMul(zinv);
29739
29740 return this.curve.point(ax, ay);
29741};
29742
29743JPoint.prototype.neg = function neg() {
29744 return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
29745};
29746
29747JPoint.prototype.add = function add(p) {
29748 // O + P = P
29749 if (this.isInfinity())
29750 return p;
29751
29752 // P + O = P
29753 if (p.isInfinity())
29754 return this;
29755
29756 // 12M + 4S + 7A
29757 var pz2 = p.z.redSqr();
29758 var z2 = this.z.redSqr();
29759 var u1 = this.x.redMul(pz2);
29760 var u2 = p.x.redMul(z2);
29761 var s1 = this.y.redMul(pz2.redMul(p.z));
29762 var s2 = p.y.redMul(z2.redMul(this.z));
29763
29764 var h = u1.redSub(u2);
29765 var r = s1.redSub(s2);
29766 if (h.cmpn(0) === 0) {
29767 if (r.cmpn(0) !== 0)
29768 return this.curve.jpoint(null, null, null);
29769 else
29770 return this.dbl();
29771 }
29772
29773 var h2 = h.redSqr();
29774 var h3 = h2.redMul(h);
29775 var v = u1.redMul(h2);
29776
29777 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
29778 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
29779 var nz = this.z.redMul(p.z).redMul(h);
29780
29781 return this.curve.jpoint(nx, ny, nz);
29782};
29783
29784JPoint.prototype.mixedAdd = function mixedAdd(p) {
29785 // O + P = P
29786 if (this.isInfinity())
29787 return p.toJ();
29788
29789 // P + O = P
29790 if (p.isInfinity())
29791 return this;
29792
29793 // 8M + 3S + 7A
29794 var z2 = this.z.redSqr();
29795 var u1 = this.x;
29796 var u2 = p.x.redMul(z2);
29797 var s1 = this.y;
29798 var s2 = p.y.redMul(z2).redMul(this.z);
29799
29800 var h = u1.redSub(u2);
29801 var r = s1.redSub(s2);
29802 if (h.cmpn(0) === 0) {
29803 if (r.cmpn(0) !== 0)
29804 return this.curve.jpoint(null, null, null);
29805 else
29806 return this.dbl();
29807 }
29808
29809 var h2 = h.redSqr();
29810 var h3 = h2.redMul(h);
29811 var v = u1.redMul(h2);
29812
29813 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
29814 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
29815 var nz = this.z.redMul(h);
29816
29817 return this.curve.jpoint(nx, ny, nz);
29818};
29819
29820JPoint.prototype.dblp = function dblp(pow) {
29821 if (pow === 0)
29822 return this;
29823 if (this.isInfinity())
29824 return this;
29825 if (!pow)
29826 return this.dbl();
29827
29828 if (this.curve.zeroA || this.curve.threeA) {
29829 var r = this;
29830 for (var i = 0; i < pow; i++)
29831 r = r.dbl();
29832 return r;
29833 }
29834
29835 // 1M + 2S + 1A + N * (4S + 5M + 8A)
29836 // N = 1 => 6M + 6S + 9A
29837 var a = this.curve.a;
29838 var tinv = this.curve.tinv;
29839
29840 var jx = this.x;
29841 var jy = this.y;
29842 var jz = this.z;
29843 var jz4 = jz.redSqr().redSqr();
29844
29845 // Reuse results
29846 var jyd = jy.redAdd(jy);
29847 for (var i = 0; i < pow; i++) {
29848 var jx2 = jx.redSqr();
29849 var jyd2 = jyd.redSqr();
29850 var jyd4 = jyd2.redSqr();
29851 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
29852
29853 var t1 = jx.redMul(jyd2);
29854 var nx = c.redSqr().redISub(t1.redAdd(t1));
29855 var t2 = t1.redISub(nx);
29856 var dny = c.redMul(t2);
29857 dny = dny.redIAdd(dny).redISub(jyd4);
29858 var nz = jyd.redMul(jz);
29859 if (i + 1 < pow)
29860 jz4 = jz4.redMul(jyd4);
29861
29862 jx = nx;
29863 jz = nz;
29864 jyd = dny;
29865 }
29866
29867 return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
29868};
29869
29870JPoint.prototype.dbl = function dbl() {
29871 if (this.isInfinity())
29872 return this;
29873
29874 if (this.curve.zeroA)
29875 return this._zeroDbl();
29876 else if (this.curve.threeA)
29877 return this._threeDbl();
29878 else
29879 return this._dbl();
29880};
29881
29882JPoint.prototype._zeroDbl = function _zeroDbl() {
29883 var nx;
29884 var ny;
29885 var nz;
29886 // Z = 1
29887 if (this.zOne) {
29888 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
29889 // #doubling-mdbl-2007-bl
29890 // 1M + 5S + 14A
29891
29892 // XX = X1^2
29893 var xx = this.x.redSqr();
29894 // YY = Y1^2
29895 var yy = this.y.redSqr();
29896 // YYYY = YY^2
29897 var yyyy = yy.redSqr();
29898 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
29899 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
29900 s = s.redIAdd(s);
29901 // M = 3 * XX + a; a = 0
29902 var m = xx.redAdd(xx).redIAdd(xx);
29903 // T = M ^ 2 - 2*S
29904 var t = m.redSqr().redISub(s).redISub(s);
29905
29906 // 8 * YYYY
29907 var yyyy8 = yyyy.redIAdd(yyyy);
29908 yyyy8 = yyyy8.redIAdd(yyyy8);
29909 yyyy8 = yyyy8.redIAdd(yyyy8);
29910
29911 // X3 = T
29912 nx = t;
29913 // Y3 = M * (S - T) - 8 * YYYY
29914 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
29915 // Z3 = 2*Y1
29916 nz = this.y.redAdd(this.y);
29917 } else {
29918 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
29919 // #doubling-dbl-2009-l
29920 // 2M + 5S + 13A
29921
29922 // A = X1^2
29923 var a = this.x.redSqr();
29924 // B = Y1^2
29925 var b = this.y.redSqr();
29926 // C = B^2
29927 var c = b.redSqr();
29928 // D = 2 * ((X1 + B)^2 - A - C)
29929 var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
29930 d = d.redIAdd(d);
29931 // E = 3 * A
29932 var e = a.redAdd(a).redIAdd(a);
29933 // F = E^2
29934 var f = e.redSqr();
29935
29936 // 8 * C
29937 var c8 = c.redIAdd(c);
29938 c8 = c8.redIAdd(c8);
29939 c8 = c8.redIAdd(c8);
29940
29941 // X3 = F - 2 * D
29942 nx = f.redISub(d).redISub(d);
29943 // Y3 = E * (D - X3) - 8 * C
29944 ny = e.redMul(d.redISub(nx)).redISub(c8);
29945 // Z3 = 2 * Y1 * Z1
29946 nz = this.y.redMul(this.z);
29947 nz = nz.redIAdd(nz);
29948 }
29949
29950 return this.curve.jpoint(nx, ny, nz);
29951};
29952
29953JPoint.prototype._threeDbl = function _threeDbl() {
29954 var nx;
29955 var ny;
29956 var nz;
29957 // Z = 1
29958 if (this.zOne) {
29959 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
29960 // #doubling-mdbl-2007-bl
29961 // 1M + 5S + 15A
29962
29963 // XX = X1^2
29964 var xx = this.x.redSqr();
29965 // YY = Y1^2
29966 var yy = this.y.redSqr();
29967 // YYYY = YY^2
29968 var yyyy = yy.redSqr();
29969 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
29970 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
29971 s = s.redIAdd(s);
29972 // M = 3 * XX + a
29973 var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
29974 // T = M^2 - 2 * S
29975 var t = m.redSqr().redISub(s).redISub(s);
29976 // X3 = T
29977 nx = t;
29978 // Y3 = M * (S - T) - 8 * YYYY
29979 var yyyy8 = yyyy.redIAdd(yyyy);
29980 yyyy8 = yyyy8.redIAdd(yyyy8);
29981 yyyy8 = yyyy8.redIAdd(yyyy8);
29982 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
29983 // Z3 = 2 * Y1
29984 nz = this.y.redAdd(this.y);
29985 } else {
29986 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
29987 // 3M + 5S
29988
29989 // delta = Z1^2
29990 var delta = this.z.redSqr();
29991 // gamma = Y1^2
29992 var gamma = this.y.redSqr();
29993 // beta = X1 * gamma
29994 var beta = this.x.redMul(gamma);
29995 // alpha = 3 * (X1 - delta) * (X1 + delta)
29996 var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
29997 alpha = alpha.redAdd(alpha).redIAdd(alpha);
29998 // X3 = alpha^2 - 8 * beta
29999 var beta4 = beta.redIAdd(beta);
30000 beta4 = beta4.redIAdd(beta4);
30001 var beta8 = beta4.redAdd(beta4);
30002 nx = alpha.redSqr().redISub(beta8);
30003 // Z3 = (Y1 + Z1)^2 - gamma - delta
30004 nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
30005 // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
30006 var ggamma8 = gamma.redSqr();
30007 ggamma8 = ggamma8.redIAdd(ggamma8);
30008 ggamma8 = ggamma8.redIAdd(ggamma8);
30009 ggamma8 = ggamma8.redIAdd(ggamma8);
30010 ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
30011 }
30012
30013 return this.curve.jpoint(nx, ny, nz);
30014};
30015
30016JPoint.prototype._dbl = function _dbl() {
30017 var a = this.curve.a;
30018
30019 // 4M + 6S + 10A
30020 var jx = this.x;
30021 var jy = this.y;
30022 var jz = this.z;
30023 var jz4 = jz.redSqr().redSqr();
30024
30025 var jx2 = jx.redSqr();
30026 var jy2 = jy.redSqr();
30027
30028 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
30029
30030 var jxd4 = jx.redAdd(jx);
30031 jxd4 = jxd4.redIAdd(jxd4);
30032 var t1 = jxd4.redMul(jy2);
30033 var nx = c.redSqr().redISub(t1.redAdd(t1));
30034 var t2 = t1.redISub(nx);
30035
30036 var jyd8 = jy2.redSqr();
30037 jyd8 = jyd8.redIAdd(jyd8);
30038 jyd8 = jyd8.redIAdd(jyd8);
30039 jyd8 = jyd8.redIAdd(jyd8);
30040 var ny = c.redMul(t2).redISub(jyd8);
30041 var nz = jy.redAdd(jy).redMul(jz);
30042
30043 return this.curve.jpoint(nx, ny, nz);
30044};
30045
30046JPoint.prototype.trpl = function trpl() {
30047 if (!this.curve.zeroA)
30048 return this.dbl().add(this);
30049
30050 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
30051 // 5M + 10S + ...
30052
30053 // XX = X1^2
30054 var xx = this.x.redSqr();
30055 // YY = Y1^2
30056 var yy = this.y.redSqr();
30057 // ZZ = Z1^2
30058 var zz = this.z.redSqr();
30059 // YYYY = YY^2
30060 var yyyy = yy.redSqr();
30061 // M = 3 * XX + a * ZZ2; a = 0
30062 var m = xx.redAdd(xx).redIAdd(xx);
30063 // MM = M^2
30064 var mm = m.redSqr();
30065 // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
30066 var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
30067 e = e.redIAdd(e);
30068 e = e.redAdd(e).redIAdd(e);
30069 e = e.redISub(mm);
30070 // EE = E^2
30071 var ee = e.redSqr();
30072 // T = 16*YYYY
30073 var t = yyyy.redIAdd(yyyy);
30074 t = t.redIAdd(t);
30075 t = t.redIAdd(t);
30076 t = t.redIAdd(t);
30077 // U = (M + E)^2 - MM - EE - T
30078 var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
30079 // X3 = 4 * (X1 * EE - 4 * YY * U)
30080 var yyu4 = yy.redMul(u);
30081 yyu4 = yyu4.redIAdd(yyu4);
30082 yyu4 = yyu4.redIAdd(yyu4);
30083 var nx = this.x.redMul(ee).redISub(yyu4);
30084 nx = nx.redIAdd(nx);
30085 nx = nx.redIAdd(nx);
30086 // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
30087 var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
30088 ny = ny.redIAdd(ny);
30089 ny = ny.redIAdd(ny);
30090 ny = ny.redIAdd(ny);
30091 // Z3 = (Z1 + E)^2 - ZZ - EE
30092 var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
30093
30094 return this.curve.jpoint(nx, ny, nz);
30095};
30096
30097JPoint.prototype.mul = function mul(k, kbase) {
30098 k = new BN(k, kbase);
30099
30100 return this.curve._wnafMul(this, k);
30101};
30102
30103JPoint.prototype.eq = function eq(p) {
30104 if (p.type === 'affine')
30105 return this.eq(p.toJ());
30106
30107 if (this === p)
30108 return true;
30109
30110 // x1 * z2^2 == x2 * z1^2
30111 var z2 = this.z.redSqr();
30112 var pz2 = p.z.redSqr();
30113 if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
30114 return false;
30115
30116 // y1 * z2^3 == y2 * z1^3
30117 var z3 = z2.redMul(this.z);
30118 var pz3 = pz2.redMul(p.z);
30119 return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
30120};
30121
30122JPoint.prototype.eqXToP = function eqXToP(x) {
30123 var zs = this.z.redSqr();
30124 var rx = x.toRed(this.curve.red).redMul(zs);
30125 if (this.x.cmp(rx) === 0)
30126 return true;
30127
30128 var xc = x.clone();
30129 var t = this.curve.redN.redMul(zs);
30130 for (;;) {
30131 xc.iadd(this.curve.n);
30132 if (xc.cmp(this.curve.p) >= 0)
30133 return false;
30134
30135 rx.redIAdd(t);
30136 if (this.x.cmp(rx) === 0)
30137 return true;
30138 }
30139 return false;
30140};
30141
30142JPoint.prototype.inspect = function inspect() {
30143 if (this.isInfinity())
30144 return '<EC JPoint Infinity>';
30145 return '<EC JPoint x: ' + this.x.toString(16, 2) +
30146 ' y: ' + this.y.toString(16, 2) +
30147 ' z: ' + this.z.toString(16, 2) + '>';
30148};
30149
30150JPoint.prototype.isInfinity = function isInfinity() {
30151 // XXX This code assumes that zero is always zero in red
30152 return this.z.cmpn(0) === 0;
30153};
30154
30155},{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],45:[function(require,module,exports){
30156'use strict';
30157
30158var curves = exports;
30159
30160var hash = require('hash.js');
30161var elliptic = require('../elliptic');
30162
30163var assert = elliptic.utils.assert;
30164
30165function PresetCurve(options) {
30166 if (options.type === 'short')
30167 this.curve = new elliptic.curve.short(options);
30168 else if (options.type === 'edwards')
30169 this.curve = new elliptic.curve.edwards(options);
30170 else
30171 this.curve = new elliptic.curve.mont(options);
30172 this.g = this.curve.g;
30173 this.n = this.curve.n;
30174 this.hash = options.hash;
30175
30176 assert(this.g.validate(), 'Invalid curve');
30177 assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
30178}
30179curves.PresetCurve = PresetCurve;
30180
30181function defineCurve(name, options) {
30182 Object.defineProperty(curves, name, {
30183 configurable: true,
30184 enumerable: true,
30185 get: function() {
30186 var curve = new PresetCurve(options);
30187 Object.defineProperty(curves, name, {
30188 configurable: true,
30189 enumerable: true,
30190 value: curve
30191 });
30192 return curve;
30193 }
30194 });
30195}
30196
30197defineCurve('p192', {
30198 type: 'short',
30199 prime: 'p192',
30200 p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
30201 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
30202 b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
30203 n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
30204 hash: hash.sha256,
30205 gRed: false,
30206 g: [
30207 '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
30208 '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
30209 ]
30210});
30211
30212defineCurve('p224', {
30213 type: 'short',
30214 prime: 'p224',
30215 p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
30216 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
30217 b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
30218 n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
30219 hash: hash.sha256,
30220 gRed: false,
30221 g: [
30222 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
30223 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
30224 ]
30225});
30226
30227defineCurve('p256', {
30228 type: 'short',
30229 prime: null,
30230 p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
30231 a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
30232 b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
30233 n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
30234 hash: hash.sha256,
30235 gRed: false,
30236 g: [
30237 '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
30238 '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
30239 ]
30240});
30241
30242defineCurve('p384', {
30243 type: 'short',
30244 prime: null,
30245 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30246 'fffffffe ffffffff 00000000 00000000 ffffffff',
30247 a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30248 'fffffffe ffffffff 00000000 00000000 fffffffc',
30249 b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
30250 '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
30251 n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
30252 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
30253 hash: hash.sha384,
30254 gRed: false,
30255 g: [
30256 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
30257 '5502f25d bf55296c 3a545e38 72760ab7',
30258 '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
30259 '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
30260 ]
30261});
30262
30263defineCurve('p521', {
30264 type: 'short',
30265 prime: null,
30266 p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30267 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30268 'ffffffff ffffffff ffffffff ffffffff ffffffff',
30269 a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30270 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30271 'ffffffff ffffffff ffffffff ffffffff fffffffc',
30272 b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
30273 '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
30274 '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
30275 n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
30276 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
30277 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
30278 hash: hash.sha512,
30279 gRed: false,
30280 g: [
30281 '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
30282 '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
30283 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
30284 '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
30285 '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
30286 '3fad0761 353c7086 a272c240 88be9476 9fd16650'
30287 ]
30288});
30289
30290defineCurve('curve25519', {
30291 type: 'mont',
30292 prime: 'p25519',
30293 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
30294 a: '76d06',
30295 b: '1',
30296 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
30297 hash: hash.sha256,
30298 gRed: false,
30299 g: [
30300 '9'
30301 ]
30302});
30303
30304defineCurve('ed25519', {
30305 type: 'edwards',
30306 prime: 'p25519',
30307 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
30308 a: '-1',
30309 c: '1',
30310 // -121665 * (121666^(-1)) (mod P)
30311 d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
30312 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
30313 hash: hash.sha256,
30314 gRed: false,
30315 g: [
30316 '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
30317
30318 // 4/5
30319 '6666666666666666666666666666666666666666666666666666666666666658'
30320 ]
30321});
30322
30323var pre;
30324try {
30325 pre = require('./precomputed/secp256k1');
30326} catch (e) {
30327 pre = undefined;
30328}
30329
30330defineCurve('secp256k1', {
30331 type: 'short',
30332 prime: 'k256',
30333 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
30334 a: '0',
30335 b: '7',
30336 n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
30337 h: '1',
30338 hash: hash.sha256,
30339
30340 // Precomputed endomorphism
30341 beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
30342 lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
30343 basis: [
30344 {
30345 a: '3086d221a7d46bcde86c90e49284eb15',
30346 b: '-e4437ed6010e88286f547fa90abfe4c3'
30347 },
30348 {
30349 a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
30350 b: '3086d221a7d46bcde86c90e49284eb15'
30351 }
30352 ],
30353
30354 gRed: false,
30355 g: [
30356 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
30357 '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
30358 pre
30359 ]
30360});
30361
30362},{"../elliptic":39,"./precomputed/secp256k1":53,"hash.js":57}],46:[function(require,module,exports){
30363'use strict';
30364
30365var BN = require('bn.js');
30366var elliptic = require('../../elliptic');
30367var utils = elliptic.utils;
30368var assert = utils.assert;
30369
30370var KeyPair = require('./key');
30371var Signature = require('./signature');
30372
30373function EC(options) {
30374 if (!(this instanceof EC))
30375 return new EC(options);
30376
30377 // Shortcut `elliptic.ec(curve-name)`
30378 if (typeof options === 'string') {
30379 assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options);
30380
30381 options = elliptic.curves[options];
30382 }
30383
30384 // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
30385 if (options instanceof elliptic.curves.PresetCurve)
30386 options = { curve: options };
30387
30388 this.curve = options.curve.curve;
30389 this.n = this.curve.n;
30390 this.nh = this.n.ushrn(1);
30391 this.g = this.curve.g;
30392
30393 // Point on curve
30394 this.g = options.curve.g;
30395 this.g.precompute(options.curve.n.bitLength() + 1);
30396
30397 // Hash for function for DRBG
30398 this.hash = options.hash || options.curve.hash;
30399}
30400module.exports = EC;
30401
30402EC.prototype.keyPair = function keyPair(options) {
30403 return new KeyPair(this, options);
30404};
30405
30406EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
30407 return KeyPair.fromPrivate(this, priv, enc);
30408};
30409
30410EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
30411 return KeyPair.fromPublic(this, pub, enc);
30412};
30413
30414EC.prototype.genKeyPair = function genKeyPair(options) {
30415 if (!options)
30416 options = {};
30417
30418 // Instantiate Hmac_DRBG
30419 var drbg = new elliptic.hmacDRBG({
30420 hash: this.hash,
30421 pers: options.pers,
30422 entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
30423 nonce: this.n.toArray()
30424 });
30425
30426 var bytes = this.n.byteLength();
30427 var ns2 = this.n.sub(new BN(2));
30428 do {
30429 var priv = new BN(drbg.generate(bytes));
30430 if (priv.cmp(ns2) > 0)
30431 continue;
30432
30433 priv.iaddn(1);
30434 return this.keyFromPrivate(priv);
30435 } while (true);
30436};
30437
30438EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
30439 var delta = msg.byteLength() * 8 - this.n.bitLength();
30440 if (delta > 0)
30441 msg = msg.ushrn(delta);
30442 if (!truncOnly && msg.cmp(this.n) >= 0)
30443 return msg.sub(this.n);
30444 else
30445 return msg;
30446};
30447
30448EC.prototype.sign = function sign(msg, key, enc, options) {
30449 if (typeof enc === 'object') {
30450 options = enc;
30451 enc = null;
30452 }
30453 if (!options)
30454 options = {};
30455
30456 key = this.keyFromPrivate(key, enc);
30457 msg = this._truncateToN(new BN(msg, 16));
30458
30459 // Zero-extend key to provide enough entropy
30460 var bytes = this.n.byteLength();
30461 var bkey = key.getPrivate().toArray('be', bytes);
30462
30463 // Zero-extend nonce to have the same byte size as N
30464 var nonce = msg.toArray('be', bytes);
30465
30466 // Instantiate Hmac_DRBG
30467 var drbg = new elliptic.hmacDRBG({
30468 hash: this.hash,
30469 entropy: bkey,
30470 nonce: nonce,
30471 pers: options.pers,
30472 persEnc: options.persEnc
30473 });
30474
30475 // Number of bytes to generate
30476 var ns1 = this.n.sub(new BN(1));
30477
30478 for (var iter = 0; true; iter++) {
30479 var k = options.k ?
30480 options.k(iter) :
30481 new BN(drbg.generate(this.n.byteLength()));
30482 k = this._truncateToN(k, true);
30483 if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
30484 continue;
30485
30486 var kp = this.g.mul(k);
30487 if (kp.isInfinity())
30488 continue;
30489
30490 var kpX = kp.getX();
30491 var r = kpX.umod(this.n);
30492 if (r.cmpn(0) === 0)
30493 continue;
30494
30495 var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
30496 s = s.umod(this.n);
30497 if (s.cmpn(0) === 0)
30498 continue;
30499
30500 var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
30501 (kpX.cmp(r) !== 0 ? 2 : 0);
30502
30503 // Use complement of `s`, if it is > `n / 2`
30504 if (options.canonical && s.cmp(this.nh) > 0) {
30505 s = this.n.sub(s);
30506 recoveryParam ^= 1;
30507 }
30508
30509 return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
30510 }
30511};
30512
30513EC.prototype.verify = function verify(msg, signature, key, enc) {
30514 msg = this._truncateToN(new BN(msg, 16));
30515 key = this.keyFromPublic(key, enc);
30516 signature = new Signature(signature, 'hex');
30517
30518 // Perform primitive values validation
30519 var r = signature.r;
30520 var s = signature.s;
30521 if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
30522 return false;
30523 if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
30524 return false;
30525
30526 // Validate signature
30527 var sinv = s.invm(this.n);
30528 var u1 = sinv.mul(msg).umod(this.n);
30529 var u2 = sinv.mul(r).umod(this.n);
30530
30531 if (!this.curve._maxwellTrick) {
30532 var p = this.g.mulAdd(u1, key.getPublic(), u2);
30533 if (p.isInfinity())
30534 return false;
30535
30536 return p.getX().umod(this.n).cmp(r) === 0;
30537 }
30538
30539 // NOTE: Greg Maxwell's trick, inspired by:
30540 // https://git.io/vad3K
30541
30542 var p = this.g.jmulAdd(u1, key.getPublic(), u2);
30543 if (p.isInfinity())
30544 return false;
30545
30546 // Compare `p.x` of Jacobian point with `r`,
30547 // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
30548 // inverse of `p.z^2`
30549 return p.eqXToP(r);
30550};
30551
30552EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
30553 assert((3 & j) === j, 'The recovery param is more than two bits');
30554 signature = new Signature(signature, enc);
30555
30556 var n = this.n;
30557 var e = new BN(msg);
30558 var r = signature.r;
30559 var s = signature.s;
30560
30561 // A set LSB signifies that the y-coordinate is odd
30562 var isYOdd = j & 1;
30563 var isSecondKey = j >> 1;
30564 if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
30565 throw new Error('Unable to find sencond key candinate');
30566
30567 // 1.1. Let x = r + jn.
30568 if (isSecondKey)
30569 r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
30570 else
30571 r = this.curve.pointFromX(r, isYOdd);
30572
30573 var rInv = signature.r.invm(n);
30574 var s1 = n.sub(e).mul(rInv).umod(n);
30575 var s2 = s.mul(rInv).umod(n);
30576
30577 // 1.6.1 Compute Q = r^-1 (sR - eG)
30578 // Q = r^-1 (sR + -eG)
30579 return this.g.mulAdd(s1, r, s2);
30580};
30581
30582EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
30583 signature = new Signature(signature, enc);
30584 if (signature.recoveryParam !== null)
30585 return signature.recoveryParam;
30586
30587 for (var i = 0; i < 4; i++) {
30588 var Qprime;
30589 try {
30590 Qprime = this.recoverPubKey(e, signature, i);
30591 } catch (e) {
30592 continue;
30593 }
30594
30595 if (Qprime.eq(Q))
30596 return i;
30597 }
30598 throw new Error('Unable to find valid recovery factor');
30599};
30600
30601},{"../../elliptic":39,"./key":47,"./signature":48,"bn.js":33}],47:[function(require,module,exports){
30602'use strict';
30603
30604var BN = require('bn.js');
30605var elliptic = require('../../elliptic');
30606var utils = elliptic.utils;
30607var assert = utils.assert;
30608
30609function KeyPair(ec, options) {
30610 this.ec = ec;
30611 this.priv = null;
30612 this.pub = null;
30613
30614 // KeyPair(ec, { priv: ..., pub: ... })
30615 if (options.priv)
30616 this._importPrivate(options.priv, options.privEnc);
30617 if (options.pub)
30618 this._importPublic(options.pub, options.pubEnc);
30619}
30620module.exports = KeyPair;
30621
30622KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
30623 if (pub instanceof KeyPair)
30624 return pub;
30625
30626 return new KeyPair(ec, {
30627 pub: pub,
30628 pubEnc: enc
30629 });
30630};
30631
30632KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
30633 if (priv instanceof KeyPair)
30634 return priv;
30635
30636 return new KeyPair(ec, {
30637 priv: priv,
30638 privEnc: enc
30639 });
30640};
30641
30642KeyPair.prototype.validate = function validate() {
30643 var pub = this.getPublic();
30644
30645 if (pub.isInfinity())
30646 return { result: false, reason: 'Invalid public key' };
30647 if (!pub.validate())
30648 return { result: false, reason: 'Public key is not a point' };
30649 if (!pub.mul(this.ec.curve.n).isInfinity())
30650 return { result: false, reason: 'Public key * N != O' };
30651
30652 return { result: true, reason: null };
30653};
30654
30655KeyPair.prototype.getPublic = function getPublic(compact, enc) {
30656 // compact is optional argument
30657 if (typeof compact === 'string') {
30658 enc = compact;
30659 compact = null;
30660 }
30661
30662 if (!this.pub)
30663 this.pub = this.ec.g.mul(this.priv);
30664
30665 if (!enc)
30666 return this.pub;
30667
30668 return this.pub.encode(enc, compact);
30669};
30670
30671KeyPair.prototype.getPrivate = function getPrivate(enc) {
30672 if (enc === 'hex')
30673 return this.priv.toString(16, 2);
30674 else
30675 return this.priv;
30676};
30677
30678KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
30679 this.priv = new BN(key, enc || 16);
30680
30681 // Ensure that the priv won't be bigger than n, otherwise we may fail
30682 // in fixed multiplication method
30683 this.priv = this.priv.umod(this.ec.curve.n);
30684};
30685
30686KeyPair.prototype._importPublic = function _importPublic(key, enc) {
30687 if (key.x || key.y) {
30688 // Montgomery points only have an `x` coordinate.
30689 // Weierstrass/Edwards points on the other hand have both `x` and
30690 // `y` coordinates.
30691 if (this.ec.curve.type === 'mont') {
30692 assert(key.x, 'Need x coordinate');
30693 } else if (this.ec.curve.type === 'short' ||
30694 this.ec.curve.type === 'edwards') {
30695 assert(key.x && key.y, 'Need both x and y coordinate');
30696 }
30697 this.pub = this.ec.curve.point(key.x, key.y);
30698 return;
30699 }
30700 this.pub = this.ec.curve.decodePoint(key, enc);
30701};
30702
30703// ECDH
30704KeyPair.prototype.derive = function derive(pub) {
30705 return pub.mul(this.priv).getX();
30706};
30707
30708// ECDSA
30709KeyPair.prototype.sign = function sign(msg, enc, options) {
30710 return this.ec.sign(msg, this, enc, options);
30711};
30712
30713KeyPair.prototype.verify = function verify(msg, signature) {
30714 return this.ec.verify(msg, signature, this);
30715};
30716
30717KeyPair.prototype.inspect = function inspect() {
30718 return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
30719 ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
30720};
30721
30722},{"../../elliptic":39,"bn.js":33}],48:[function(require,module,exports){
30723'use strict';
30724
30725var BN = require('bn.js');
30726
30727var elliptic = require('../../elliptic');
30728var utils = elliptic.utils;
30729var assert = utils.assert;
30730
30731function Signature(options, enc) {
30732 if (options instanceof Signature)
30733 return options;
30734
30735 if (this._importDER(options, enc))
30736 return;
30737
30738 assert(options.r && options.s, 'Signature without r or s');
30739 this.r = new BN(options.r, 16);
30740 this.s = new BN(options.s, 16);
30741 if (options.recoveryParam === undefined)
30742 this.recoveryParam = null;
30743 else
30744 this.recoveryParam = options.recoveryParam;
30745}
30746module.exports = Signature;
30747
30748function Position() {
30749 this.place = 0;
30750}
30751
30752function getLength(buf, p) {
30753 var initial = buf[p.place++];
30754 if (!(initial & 0x80)) {
30755 return initial;
30756 }
30757 var octetLen = initial & 0xf;
30758 var val = 0;
30759 for (var i = 0, off = p.place; i < octetLen; i++, off++) {
30760 val <<= 8;
30761 val |= buf[off];
30762 }
30763 p.place = off;
30764 return val;
30765}
30766
30767function rmPadding(buf) {
30768 var i = 0;
30769 var len = buf.length - 1;
30770 while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
30771 i++;
30772 }
30773 if (i === 0) {
30774 return buf;
30775 }
30776 return buf.slice(i);
30777}
30778
30779Signature.prototype._importDER = function _importDER(data, enc) {
30780 data = utils.toArray(data, enc);
30781 var p = new Position();
30782 if (data[p.place++] !== 0x30) {
30783 return false;
30784 }
30785 var len = getLength(data, p);
30786 if ((len + p.place) !== data.length) {
30787 return false;
30788 }
30789 if (data[p.place++] !== 0x02) {
30790 return false;
30791 }
30792 var rlen = getLength(data, p);
30793 var r = data.slice(p.place, rlen + p.place);
30794 p.place += rlen;
30795 if (data[p.place++] !== 0x02) {
30796 return false;
30797 }
30798 var slen = getLength(data, p);
30799 if (data.length !== slen + p.place) {
30800 return false;
30801 }
30802 var s = data.slice(p.place, slen + p.place);
30803 if (r[0] === 0 && (r[1] & 0x80)) {
30804 r = r.slice(1);
30805 }
30806 if (s[0] === 0 && (s[1] & 0x80)) {
30807 s = s.slice(1);
30808 }
30809
30810 this.r = new BN(r);
30811 this.s = new BN(s);
30812 this.recoveryParam = null;
30813
30814 return true;
30815};
30816
30817function constructLength(arr, len) {
30818 if (len < 0x80) {
30819 arr.push(len);
30820 return;
30821 }
30822 var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
30823 arr.push(octets | 0x80);
30824 while (--octets) {
30825 arr.push((len >>> (octets << 3)) & 0xff);
30826 }
30827 arr.push(len);
30828}
30829
30830Signature.prototype.toDER = function toDER(enc) {
30831 var r = this.r.toArray();
30832 var s = this.s.toArray();
30833
30834 // Pad values
30835 if (r[0] & 0x80)
30836 r = [ 0 ].concat(r);
30837 // Pad values
30838 if (s[0] & 0x80)
30839 s = [ 0 ].concat(s);
30840
30841 r = rmPadding(r);
30842 s = rmPadding(s);
30843
30844 while (!s[0] && !(s[1] & 0x80)) {
30845 s = s.slice(1);
30846 }
30847 var arr = [ 0x02 ];
30848 constructLength(arr, r.length);
30849 arr = arr.concat(r);
30850 arr.push(0x02);
30851 constructLength(arr, s.length);
30852 var backHalf = arr.concat(s);
30853 var res = [ 0x30 ];
30854 constructLength(res, backHalf.length);
30855 res = res.concat(backHalf);
30856 return utils.encode(res, enc);
30857};
30858
30859},{"../../elliptic":39,"bn.js":33}],49:[function(require,module,exports){
30860'use strict';
30861
30862var hash = require('hash.js');
30863var elliptic = require('../../elliptic');
30864var utils = elliptic.utils;
30865var assert = utils.assert;
30866var parseBytes = utils.parseBytes;
30867var KeyPair = require('./key');
30868var Signature = require('./signature');
30869
30870function EDDSA(curve) {
30871 assert(curve === 'ed25519', 'only tested with ed25519 so far');
30872
30873 if (!(this instanceof EDDSA))
30874 return new EDDSA(curve);
30875
30876 var curve = elliptic.curves[curve].curve;
30877 this.curve = curve;
30878 this.g = curve.g;
30879 this.g.precompute(curve.n.bitLength() + 1);
30880
30881 this.pointClass = curve.point().constructor;
30882 this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
30883 this.hash = hash.sha512;
30884}
30885
30886module.exports = EDDSA;
30887
30888/**
30889* @param {Array|String} message - message bytes
30890* @param {Array|String|KeyPair} secret - secret bytes or a keypair
30891* @returns {Signature} - signature
30892*/
30893EDDSA.prototype.sign = function sign(message, secret) {
30894 message = parseBytes(message);
30895 var key = this.keyFromSecret(secret);
30896 var r = this.hashInt(key.messagePrefix(), message);
30897 var R = this.g.mul(r);
30898 var Rencoded = this.encodePoint(R);
30899 var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
30900 .mul(key.priv());
30901 var S = r.add(s_).umod(this.curve.n);
30902 return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
30903};
30904
30905/**
30906* @param {Array} message - message bytes
30907* @param {Array|String|Signature} sig - sig bytes
30908* @param {Array|String|Point|KeyPair} pub - public key
30909* @returns {Boolean} - true if public key matches sig of message
30910*/
30911EDDSA.prototype.verify = function verify(message, sig, pub) {
30912 message = parseBytes(message);
30913 sig = this.makeSignature(sig);
30914 var key = this.keyFromPublic(pub);
30915 var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
30916 var SG = this.g.mul(sig.S());
30917 var RplusAh = sig.R().add(key.pub().mul(h));
30918 return RplusAh.eq(SG);
30919};
30920
30921EDDSA.prototype.hashInt = function hashInt() {
30922 var hash = this.hash();
30923 for (var i = 0; i < arguments.length; i++)
30924 hash.update(arguments[i]);
30925 return utils.intFromLE(hash.digest()).umod(this.curve.n);
30926};
30927
30928EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
30929 return KeyPair.fromPublic(this, pub);
30930};
30931
30932EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
30933 return KeyPair.fromSecret(this, secret);
30934};
30935
30936EDDSA.prototype.makeSignature = function makeSignature(sig) {
30937 if (sig instanceof Signature)
30938 return sig;
30939 return new Signature(this, sig);
30940};
30941
30942/**
30943* * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
30944*
30945* EDDSA defines methods for encoding and decoding points and integers. These are
30946* helper convenience methods, that pass along to utility functions implied
30947* parameters.
30948*
30949*/
30950EDDSA.prototype.encodePoint = function encodePoint(point) {
30951 var enc = point.getY().toArray('le', this.encodingLength);
30952 enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
30953 return enc;
30954};
30955
30956EDDSA.prototype.decodePoint = function decodePoint(bytes) {
30957 bytes = utils.parseBytes(bytes);
30958
30959 var lastIx = bytes.length - 1;
30960 var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
30961 var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
30962
30963 var y = utils.intFromLE(normed);
30964 return this.curve.pointFromY(y, xIsOdd);
30965};
30966
30967EDDSA.prototype.encodeInt = function encodeInt(num) {
30968 return num.toArray('le', this.encodingLength);
30969};
30970
30971EDDSA.prototype.decodeInt = function decodeInt(bytes) {
30972 return utils.intFromLE(bytes);
30973};
30974
30975EDDSA.prototype.isPoint = function isPoint(val) {
30976 return val instanceof this.pointClass;
30977};
30978
30979},{"../../elliptic":39,"./key":50,"./signature":51,"hash.js":57}],50:[function(require,module,exports){
30980'use strict';
30981
30982var elliptic = require('../../elliptic');
30983var utils = elliptic.utils;
30984var assert = utils.assert;
30985var parseBytes = utils.parseBytes;
30986var cachedProperty = utils.cachedProperty;
30987
30988/**
30989* @param {EDDSA} eddsa - instance
30990* @param {Object} params - public/private key parameters
30991*
30992* @param {Array<Byte>} [params.secret] - secret seed bytes
30993* @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
30994* @param {Array<Byte>} [params.pub] - public key point encoded as bytes
30995*
30996*/
30997function KeyPair(eddsa, params) {
30998 this.eddsa = eddsa;
30999 this._secret = parseBytes(params.secret);
31000 if (eddsa.isPoint(params.pub))
31001 this._pub = params.pub;
31002 else
31003 this._pubBytes = parseBytes(params.pub);
31004}
31005
31006KeyPair.fromPublic = function fromPublic(eddsa, pub) {
31007 if (pub instanceof KeyPair)
31008 return pub;
31009 return new KeyPair(eddsa, { pub: pub });
31010};
31011
31012KeyPair.fromSecret = function fromSecret(eddsa, secret) {
31013 if (secret instanceof KeyPair)
31014 return secret;
31015 return new KeyPair(eddsa, { secret: secret });
31016};
31017
31018KeyPair.prototype.secret = function secret() {
31019 return this._secret;
31020};
31021
31022cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
31023 return this.eddsa.encodePoint(this.pub());
31024});
31025
31026cachedProperty(KeyPair, 'pub', function pub() {
31027 if (this._pubBytes)
31028 return this.eddsa.decodePoint(this._pubBytes);
31029 return this.eddsa.g.mul(this.priv());
31030});
31031
31032cachedProperty(KeyPair, 'privBytes', function privBytes() {
31033 var eddsa = this.eddsa;
31034 var hash = this.hash();
31035 var lastIx = eddsa.encodingLength - 1;
31036
31037 var a = hash.slice(0, eddsa.encodingLength);
31038 a[0] &= 248;
31039 a[lastIx] &= 127;
31040 a[lastIx] |= 64;
31041
31042 return a;
31043});
31044
31045cachedProperty(KeyPair, 'priv', function priv() {
31046 return this.eddsa.decodeInt(this.privBytes());
31047});
31048
31049cachedProperty(KeyPair, 'hash', function hash() {
31050 return this.eddsa.hash().update(this.secret()).digest();
31051});
31052
31053cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
31054 return this.hash().slice(this.eddsa.encodingLength);
31055});
31056
31057KeyPair.prototype.sign = function sign(message) {
31058 assert(this._secret, 'KeyPair can only verify');
31059 return this.eddsa.sign(message, this);
31060};
31061
31062KeyPair.prototype.verify = function verify(message, sig) {
31063 return this.eddsa.verify(message, sig, this);
31064};
31065
31066KeyPair.prototype.getSecret = function getSecret(enc) {
31067 assert(this._secret, 'KeyPair is public only');
31068 return utils.encode(this.secret(), enc);
31069};
31070
31071KeyPair.prototype.getPublic = function getPublic(enc) {
31072 return utils.encode(this.pubBytes(), enc);
31073};
31074
31075module.exports = KeyPair;
31076
31077},{"../../elliptic":39}],51:[function(require,module,exports){
31078'use strict';
31079
31080var BN = require('bn.js');
31081var elliptic = require('../../elliptic');
31082var utils = elliptic.utils;
31083var assert = utils.assert;
31084var cachedProperty = utils.cachedProperty;
31085var parseBytes = utils.parseBytes;
31086
31087/**
31088* @param {EDDSA} eddsa - eddsa instance
31089* @param {Array<Bytes>|Object} sig -
31090* @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
31091* @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
31092* @param {Array<Bytes>} [sig.Rencoded] - R point encoded
31093* @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
31094*/
31095function Signature(eddsa, sig) {
31096 this.eddsa = eddsa;
31097
31098 if (typeof sig !== 'object')
31099 sig = parseBytes(sig);
31100
31101 if (Array.isArray(sig)) {
31102 sig = {
31103 R: sig.slice(0, eddsa.encodingLength),
31104 S: sig.slice(eddsa.encodingLength)
31105 };
31106 }
31107
31108 assert(sig.R && sig.S, 'Signature without R or S');
31109
31110 if (eddsa.isPoint(sig.R))
31111 this._R = sig.R;
31112 if (sig.S instanceof BN)
31113 this._S = sig.S;
31114
31115 this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
31116 this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
31117}
31118
31119cachedProperty(Signature, 'S', function S() {
31120 return this.eddsa.decodeInt(this.Sencoded());
31121});
31122
31123cachedProperty(Signature, 'R', function R() {
31124 return this.eddsa.decodePoint(this.Rencoded());
31125});
31126
31127cachedProperty(Signature, 'Rencoded', function Rencoded() {
31128 return this.eddsa.encodePoint(this.R());
31129});
31130
31131cachedProperty(Signature, 'Sencoded', function Sencoded() {
31132 return this.eddsa.encodeInt(this.S());
31133});
31134
31135Signature.prototype.toBytes = function toBytes() {
31136 return this.Rencoded().concat(this.Sencoded());
31137};
31138
31139Signature.prototype.toHex = function toHex() {
31140 return utils.encode(this.toBytes(), 'hex').toUpperCase();
31141};
31142
31143module.exports = Signature;
31144
31145},{"../../elliptic":39,"bn.js":33}],52:[function(require,module,exports){
31146'use strict';
31147
31148var hash = require('hash.js');
31149var elliptic = require('../elliptic');
31150var utils = elliptic.utils;
31151var assert = utils.assert;
31152
31153function HmacDRBG(options) {
31154 if (!(this instanceof HmacDRBG))
31155 return new HmacDRBG(options);
31156 this.hash = options.hash;
31157 this.predResist = !!options.predResist;
31158
31159 this.outLen = this.hash.outSize;
31160 this.minEntropy = options.minEntropy || this.hash.hmacStrength;
31161
31162 this.reseed = null;
31163 this.reseedInterval = null;
31164 this.K = null;
31165 this.V = null;
31166
31167 var entropy = utils.toArray(options.entropy, options.entropyEnc);
31168 var nonce = utils.toArray(options.nonce, options.nonceEnc);
31169 var pers = utils.toArray(options.pers, options.persEnc);
31170 assert(entropy.length >= (this.minEntropy / 8),
31171 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
31172 this._init(entropy, nonce, pers);
31173}
31174module.exports = HmacDRBG;
31175
31176HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
31177 var seed = entropy.concat(nonce).concat(pers);
31178
31179 this.K = new Array(this.outLen / 8);
31180 this.V = new Array(this.outLen / 8);
31181 for (var i = 0; i < this.V.length; i++) {
31182 this.K[i] = 0x00;
31183 this.V[i] = 0x01;
31184 }
31185
31186 this._update(seed);
31187 this.reseed = 1;
31188 this.reseedInterval = 0x1000000000000; // 2^48
31189};
31190
31191HmacDRBG.prototype._hmac = function hmac() {
31192 return new hash.hmac(this.hash, this.K);
31193};
31194
31195HmacDRBG.prototype._update = function update(seed) {
31196 var kmac = this._hmac()
31197 .update(this.V)
31198 .update([ 0x00 ]);
31199 if (seed)
31200 kmac = kmac.update(seed);
31201 this.K = kmac.digest();
31202 this.V = this._hmac().update(this.V).digest();
31203 if (!seed)
31204 return;
31205
31206 this.K = this._hmac()
31207 .update(this.V)
31208 .update([ 0x01 ])
31209 .update(seed)
31210 .digest();
31211 this.V = this._hmac().update(this.V).digest();
31212};
31213
31214HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
31215 // Optional entropy enc
31216 if (typeof entropyEnc !== 'string') {
31217 addEnc = add;
31218 add = entropyEnc;
31219 entropyEnc = null;
31220 }
31221
31222 entropy = utils.toBuffer(entropy, entropyEnc);
31223 add = utils.toBuffer(add, addEnc);
31224
31225 assert(entropy.length >= (this.minEntropy / 8),
31226 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
31227
31228 this._update(entropy.concat(add || []));
31229 this.reseed = 1;
31230};
31231
31232HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
31233 if (this.reseed > this.reseedInterval)
31234 throw new Error('Reseed is required');
31235
31236 // Optional encoding
31237 if (typeof enc !== 'string') {
31238 addEnc = add;
31239 add = enc;
31240 enc = null;
31241 }
31242
31243 // Optional additional data
31244 if (add) {
31245 add = utils.toArray(add, addEnc);
31246 this._update(add);
31247 }
31248
31249 var temp = [];
31250 while (temp.length < len) {
31251 this.V = this._hmac().update(this.V).digest();
31252 temp = temp.concat(this.V);
31253 }
31254
31255 var res = temp.slice(0, len);
31256 this._update(add);
31257 this.reseed++;
31258 return utils.encode(res, enc);
31259};
31260
31261},{"../elliptic":39,"hash.js":57}],53:[function(require,module,exports){
31262module.exports = {
31263 doubles: {
31264 step: 4,
31265 points: [
31266 [
31267 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
31268 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
31269 ],
31270 [
31271 '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
31272 '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
31273 ],
31274 [
31275 '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
31276 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
31277 ],
31278 [
31279 '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
31280 '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
31281 ],
31282 [
31283 '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
31284 '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
31285 ],
31286 [
31287 '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
31288 '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
31289 ],
31290 [
31291 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
31292 '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
31293 ],
31294 [
31295 '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
31296 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
31297 ],
31298 [
31299 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
31300 '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
31301 ],
31302 [
31303 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
31304 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
31305 ],
31306 [
31307 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
31308 '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
31309 ],
31310 [
31311 '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
31312 '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
31313 ],
31314 [
31315 '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
31316 '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
31317 ],
31318 [
31319 '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
31320 '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
31321 ],
31322 [
31323 '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
31324 '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
31325 ],
31326 [
31327 '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
31328 '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
31329 ],
31330 [
31331 '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
31332 '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
31333 ],
31334 [
31335 '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
31336 '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
31337 ],
31338 [
31339 '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
31340 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
31341 ],
31342 [
31343 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
31344 '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
31345 ],
31346 [
31347 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
31348 '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
31349 ],
31350 [
31351 '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
31352 '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
31353 ],
31354 [
31355 '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
31356 '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
31357 ],
31358 [
31359 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
31360 '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
31361 ],
31362 [
31363 '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
31364 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
31365 ],
31366 [
31367 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
31368 '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
31369 ],
31370 [
31371 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
31372 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
31373 ],
31374 [
31375 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
31376 '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
31377 ],
31378 [
31379 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
31380 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
31381 ],
31382 [
31383 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
31384 '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
31385 ],
31386 [
31387 '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
31388 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
31389 ],
31390 [
31391 '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
31392 '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
31393 ],
31394 [
31395 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
31396 '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
31397 ],
31398 [
31399 '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
31400 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
31401 ],
31402 [
31403 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
31404 '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
31405 ],
31406 [
31407 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
31408 '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
31409 ],
31410 [
31411 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
31412 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
31413 ],
31414 [
31415 '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
31416 '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
31417 ],
31418 [
31419 '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
31420 '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
31421 ],
31422 [
31423 '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
31424 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
31425 ],
31426 [
31427 '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
31428 '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
31429 ],
31430 [
31431 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
31432 '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
31433 ],
31434 [
31435 '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
31436 '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
31437 ],
31438 [
31439 '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
31440 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
31441 ],
31442 [
31443 '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
31444 '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
31445 ],
31446 [
31447 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
31448 '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
31449 ],
31450 [
31451 '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
31452 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
31453 ],
31454 [
31455 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
31456 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
31457 ],
31458 [
31459 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
31460 '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
31461 ],
31462 [
31463 '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
31464 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
31465 ],
31466 [
31467 '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
31468 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
31469 ],
31470 [
31471 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
31472 '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
31473 ],
31474 [
31475 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
31476 '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
31477 ],
31478 [
31479 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
31480 '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
31481 ],
31482 [
31483 '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
31484 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
31485 ],
31486 [
31487 '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
31488 '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
31489 ],
31490 [
31491 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
31492 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
31493 ],
31494 [
31495 '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
31496 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
31497 ],
31498 [
31499 '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
31500 '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
31501 ],
31502 [
31503 '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
31504 '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
31505 ],
31506 [
31507 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
31508 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
31509 ],
31510 [
31511 '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
31512 '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
31513 ],
31514 [
31515 '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
31516 '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
31517 ],
31518 [
31519 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
31520 '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
31521 ],
31522 [
31523 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
31524 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
31525 ]
31526 ]
31527 },
31528 naf: {
31529 wnd: 7,
31530 points: [
31531 [
31532 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
31533 '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
31534 ],
31535 [
31536 '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
31537 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
31538 ],
31539 [
31540 '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
31541 '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
31542 ],
31543 [
31544 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
31545 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
31546 ],
31547 [
31548 '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
31549 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
31550 ],
31551 [
31552 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
31553 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
31554 ],
31555 [
31556 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
31557 '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
31558 ],
31559 [
31560 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
31561 '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
31562 ],
31563 [
31564 '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
31565 '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
31566 ],
31567 [
31568 '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
31569 '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
31570 ],
31571 [
31572 '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
31573 '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
31574 ],
31575 [
31576 '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
31577 '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
31578 ],
31579 [
31580 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
31581 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
31582 ],
31583 [
31584 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
31585 '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
31586 ],
31587 [
31588 '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
31589 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
31590 ],
31591 [
31592 '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
31593 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
31594 ],
31595 [
31596 '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
31597 '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
31598 ],
31599 [
31600 '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
31601 '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
31602 ],
31603 [
31604 '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
31605 '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
31606 ],
31607 [
31608 '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
31609 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
31610 ],
31611 [
31612 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
31613 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
31614 ],
31615 [
31616 '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
31617 '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
31618 ],
31619 [
31620 '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
31621 '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
31622 ],
31623 [
31624 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
31625 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
31626 ],
31627 [
31628 '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
31629 '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
31630 ],
31631 [
31632 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
31633 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
31634 ],
31635 [
31636 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
31637 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
31638 ],
31639 [
31640 '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
31641 '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
31642 ],
31643 [
31644 '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
31645 '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
31646 ],
31647 [
31648 '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
31649 '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
31650 ],
31651 [
31652 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
31653 '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
31654 ],
31655 [
31656 '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
31657 '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
31658 ],
31659 [
31660 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
31661 '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
31662 ],
31663 [
31664 '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
31665 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
31666 ],
31667 [
31668 '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
31669 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
31670 ],
31671 [
31672 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
31673 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
31674 ],
31675 [
31676 '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
31677 '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
31678 ],
31679 [
31680 '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
31681 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
31682 ],
31683 [
31684 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
31685 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
31686 ],
31687 [
31688 '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
31689 '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
31690 ],
31691 [
31692 '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
31693 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
31694 ],
31695 [
31696 '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
31697 '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
31698 ],
31699 [
31700 '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
31701 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
31702 ],
31703 [
31704 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
31705 '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
31706 ],
31707 [
31708 '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
31709 '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
31710 ],
31711 [
31712 '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
31713 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
31714 ],
31715 [
31716 '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
31717 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
31718 ],
31719 [
31720 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
31721 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
31722 ],
31723 [
31724 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
31725 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
31726 ],
31727 [
31728 '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
31729 '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
31730 ],
31731 [
31732 '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
31733 '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
31734 ],
31735 [
31736 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
31737 '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
31738 ],
31739 [
31740 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
31741 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
31742 ],
31743 [
31744 '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
31745 '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
31746 ],
31747 [
31748 '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
31749 '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
31750 ],
31751 [
31752 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
31753 '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
31754 ],
31755 [
31756 '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
31757 '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
31758 ],
31759 [
31760 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
31761 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
31762 ],
31763 [
31764 '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
31765 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
31766 ],
31767 [
31768 '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
31769 '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
31770 ],
31771 [
31772 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
31773 '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
31774 ],
31775 [
31776 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
31777 '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
31778 ],
31779 [
31780 '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
31781 '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
31782 ],
31783 [
31784 '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
31785 '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
31786 ],
31787 [
31788 '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
31789 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
31790 ],
31791 [
31792 '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
31793 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
31794 ],
31795 [
31796 '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
31797 '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
31798 ],
31799 [
31800 '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
31801 '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
31802 ],
31803 [
31804 '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
31805 '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
31806 ],
31807 [
31808 '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
31809 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
31810 ],
31811 [
31812 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
31813 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
31814 ],
31815 [
31816 '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
31817 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
31818 ],
31819 [
31820 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
31821 '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
31822 ],
31823 [
31824 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
31825 '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
31826 ],
31827 [
31828 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
31829 '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
31830 ],
31831 [
31832 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
31833 '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
31834 ],
31835 [
31836 '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
31837 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
31838 ],
31839 [
31840 '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
31841 '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
31842 ],
31843 [
31844 '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
31845 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
31846 ],
31847 [
31848 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
31849 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
31850 ],
31851 [
31852 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
31853 '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
31854 ],
31855 [
31856 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
31857 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
31858 ],
31859 [
31860 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
31861 '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
31862 ],
31863 [
31864 '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
31865 '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
31866 ],
31867 [
31868 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
31869 '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
31870 ],
31871 [
31872 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
31873 '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
31874 ],
31875 [
31876 '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
31877 '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
31878 ],
31879 [
31880 '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
31881 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
31882 ],
31883 [
31884 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
31885 '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
31886 ],
31887 [
31888 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
31889 '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
31890 ],
31891 [
31892 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
31893 '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
31894 ],
31895 [
31896 '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
31897 '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
31898 ],
31899 [
31900 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
31901 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
31902 ],
31903 [
31904 '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
31905 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
31906 ],
31907 [
31908 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
31909 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
31910 ],
31911 [
31912 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
31913 '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
31914 ],
31915 [
31916 '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
31917 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
31918 ],
31919 [
31920 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
31921 '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
31922 ],
31923 [
31924 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
31925 '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
31926 ],
31927 [
31928 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
31929 '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
31930 ],
31931 [
31932 '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
31933 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
31934 ],
31935 [
31936 '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
31937 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
31938 ],
31939 [
31940 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
31941 '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
31942 ],
31943 [
31944 '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
31945 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
31946 ],
31947 [
31948 '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
31949 '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
31950 ],
31951 [
31952 '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
31953 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
31954 ],
31955 [
31956 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
31957 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
31958 ],
31959 [
31960 '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
31961 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
31962 ],
31963 [
31964 '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
31965 '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
31966 ],
31967 [
31968 '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
31969 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
31970 ],
31971 [
31972 '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
31973 '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
31974 ],
31975 [
31976 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
31977 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
31978 ],
31979 [
31980 '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
31981 '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
31982 ],
31983 [
31984 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
31985 '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
31986 ],
31987 [
31988 '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
31989 '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
31990 ],
31991 [
31992 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
31993 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
31994 ],
31995 [
31996 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
31997 '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
31998 ],
31999 [
32000 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
32001 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
32002 ],
32003 [
32004 '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
32005 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
32006 ],
32007 [
32008 '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
32009 '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
32010 ],
32011 [
32012 '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
32013 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
32014 ],
32015 [
32016 '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
32017 '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
32018 ],
32019 [
32020 '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
32021 '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
32022 ],
32023 [
32024 '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
32025 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
32026 ],
32027 [
32028 '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
32029 '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
32030 ],
32031 [
32032 '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
32033 '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
32034 ],
32035 [
32036 '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
32037 '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
32038 ]
32039 ]
32040 }
32041};
32042
32043},{}],54:[function(require,module,exports){
32044'use strict';
32045
32046var utils = exports;
32047var BN = require('bn.js');
32048
32049utils.assert = function assert(val, msg) {
32050 if (!val)
32051 throw new Error(msg || 'Assertion failed');
32052};
32053
32054function toArray(msg, enc) {
32055 if (Array.isArray(msg))
32056 return msg.slice();
32057 if (!msg)
32058 return [];
32059 var res = [];
32060 if (typeof msg !== 'string') {
32061 for (var i = 0; i < msg.length; i++)
32062 res[i] = msg[i] | 0;
32063 return res;
32064 }
32065 if (!enc) {
32066 for (var i = 0; i < msg.length; i++) {
32067 var c = msg.charCodeAt(i);
32068 var hi = c >> 8;
32069 var lo = c & 0xff;
32070 if (hi)
32071 res.push(hi, lo);
32072 else
32073 res.push(lo);
32074 }
32075 } else if (enc === 'hex') {
32076 msg = msg.replace(/[^a-z0-9]+/ig, '');
32077 if (msg.length % 2 !== 0)
32078 msg = '0' + msg;
32079 for (var i = 0; i < msg.length; i += 2)
32080 res.push(parseInt(msg[i] + msg[i + 1], 16));
32081 }
32082 return res;
32083}
32084utils.toArray = toArray;
32085
32086function zero2(word) {
32087 if (word.length === 1)
32088 return '0' + word;
32089 else
32090 return word;
32091}
32092utils.zero2 = zero2;
32093
32094function toHex(msg) {
32095 var res = '';
32096 for (var i = 0; i < msg.length; i++)
32097 res += zero2(msg[i].toString(16));
32098 return res;
32099}
32100utils.toHex = toHex;
32101
32102utils.encode = function encode(arr, enc) {
32103 if (enc === 'hex')
32104 return toHex(arr);
32105 else
32106 return arr;
32107};
32108
32109// Represent num in a w-NAF form
32110function getNAF(num, w) {
32111 var naf = [];
32112 var ws = 1 << (w + 1);
32113 var k = num.clone();
32114 while (k.cmpn(1) >= 0) {
32115 var z;
32116 if (k.isOdd()) {
32117 var mod = k.andln(ws - 1);
32118 if (mod > (ws >> 1) - 1)
32119 z = (ws >> 1) - mod;
32120 else
32121 z = mod;
32122 k.isubn(z);
32123 } else {
32124 z = 0;
32125 }
32126 naf.push(z);
32127
32128 // Optimization, shift by word if possible
32129 var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
32130 for (var i = 1; i < shift; i++)
32131 naf.push(0);
32132 k.iushrn(shift);
32133 }
32134
32135 return naf;
32136}
32137utils.getNAF = getNAF;
32138
32139// Represent k1, k2 in a Joint Sparse Form
32140function getJSF(k1, k2) {
32141 var jsf = [
32142 [],
32143 []
32144 ];
32145
32146 k1 = k1.clone();
32147 k2 = k2.clone();
32148 var d1 = 0;
32149 var d2 = 0;
32150 while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
32151
32152 // First phase
32153 var m14 = (k1.andln(3) + d1) & 3;
32154 var m24 = (k2.andln(3) + d2) & 3;
32155 if (m14 === 3)
32156 m14 = -1;
32157 if (m24 === 3)
32158 m24 = -1;
32159 var u1;
32160 if ((m14 & 1) === 0) {
32161 u1 = 0;
32162 } else {
32163 var m8 = (k1.andln(7) + d1) & 7;
32164 if ((m8 === 3 || m8 === 5) && m24 === 2)
32165 u1 = -m14;
32166 else
32167 u1 = m14;
32168 }
32169 jsf[0].push(u1);
32170
32171 var u2;
32172 if ((m24 & 1) === 0) {
32173 u2 = 0;
32174 } else {
32175 var m8 = (k2.andln(7) + d2) & 7;
32176 if ((m8 === 3 || m8 === 5) && m14 === 2)
32177 u2 = -m24;
32178 else
32179 u2 = m24;
32180 }
32181 jsf[1].push(u2);
32182
32183 // Second phase
32184 if (2 * d1 === u1 + 1)
32185 d1 = 1 - d1;
32186 if (2 * d2 === u2 + 1)
32187 d2 = 1 - d2;
32188 k1.iushrn(1);
32189 k2.iushrn(1);
32190 }
32191
32192 return jsf;
32193}
32194utils.getJSF = getJSF;
32195
32196function cachedProperty(obj, name, computer) {
32197 var key = '_' + name;
32198 obj.prototype[name] = function cachedProperty() {
32199 return this[key] !== undefined ? this[key] :
32200 this[key] = computer.call(this);
32201 };
32202}
32203utils.cachedProperty = cachedProperty;
32204
32205function parseBytes(bytes) {
32206 return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
32207 bytes;
32208}
32209utils.parseBytes = parseBytes;
32210
32211function intFromLE(bytes) {
32212 return new BN(bytes, 'hex', 'le');
32213}
32214utils.intFromLE = intFromLE;
32215
32216
32217},{"bn.js":33}],55:[function(require,module,exports){
32218module.exports={
32219 "_args": [
32220 [
32221 {
32222 "raw": "elliptic@^6.2.3",
32223 "scope": null,
32224 "escapedName": "elliptic",
32225 "name": "elliptic",
32226 "rawSpec": "^6.2.3",
32227 "spec": ">=6.2.3 <7.0.0",
32228 "type": "range"
32229 },
32230 "/home/user/ethereum/ethereumjs-util/node_modules/secp256k1"
32231 ]
32232 ],
32233 "_from": "elliptic@>=6.2.3 <7.0.0",
32234 "_id": "elliptic@6.3.3",
32235 "_inCache": true,
32236 "_location": "/elliptic",
32237 "_nodeVersion": "7.0.0",
32238 "_npmOperationalInternal": {
32239 "host": "packages-18-east.internal.npmjs.com",
32240 "tmp": "tmp/elliptic-6.3.3.tgz_1486422837740_0.10658654430881143"
32241 },
32242 "_npmUser": {
32243 "name": "indutny",
32244 "email": "fedor@indutny.com"
32245 },
32246 "_npmVersion": "3.10.8",
32247 "_phantomChildren": {},
32248 "_requested": {
32249 "raw": "elliptic@^6.2.3",
32250 "scope": null,
32251 "escapedName": "elliptic",
32252 "name": "elliptic",
32253 "rawSpec": "^6.2.3",
32254 "spec": ">=6.2.3 <7.0.0",
32255 "type": "range"
32256 },
32257 "_requiredBy": [
32258 "/browserify-sign",
32259 "/create-ecdh",
32260 "/secp256k1"
32261 ],
32262 "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.3.3.tgz",
32263 "_shasum": "5482d9646d54bcb89fd7d994fc9e2e9568876e3f",
32264 "_shrinkwrap": null,
32265 "_spec": "elliptic@^6.2.3",
32266 "_where": "/home/user/ethereum/ethereumjs-util/node_modules/secp256k1",
32267 "author": {
32268 "name": "Fedor Indutny",
32269 "email": "fedor@indutny.com"
32270 },
32271 "bugs": {
32272 "url": "https://github.com/indutny/elliptic/issues"
32273 },
32274 "dependencies": {
32275 "bn.js": "^4.4.0",
32276 "brorand": "^1.0.1",
32277 "hash.js": "^1.0.0",
32278 "inherits": "^2.0.1"
32279 },
32280 "description": "EC cryptography",
32281 "devDependencies": {
32282 "brfs": "^1.4.3",
32283 "coveralls": "^2.11.3",
32284 "grunt": "^0.4.5",
32285 "grunt-browserify": "^5.0.0",
32286 "grunt-cli": "^1.2.0",
32287 "grunt-contrib-connect": "^1.0.0",
32288 "grunt-contrib-copy": "^1.0.0",
32289 "grunt-contrib-uglify": "^1.0.1",
32290 "grunt-mocha-istanbul": "^3.0.1",
32291 "grunt-saucelabs": "^8.6.2",
32292 "istanbul": "^0.4.2",
32293 "jscs": "^2.9.0",
32294 "jshint": "^2.6.0",
32295 "mocha": "^2.1.0"
32296 },
32297 "directories": {},
32298 "dist": {
32299 "shasum": "5482d9646d54bcb89fd7d994fc9e2e9568876e3f",
32300 "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.3.3.tgz"
32301 },
32302 "files": [
32303 "lib"
32304 ],
32305 "gitHead": "63aee8d697e9b7fac37ece24222029117a890a7e",
32306 "homepage": "https://github.com/indutny/elliptic",
32307 "keywords": [
32308 "EC",
32309 "Elliptic",
32310 "curve",
32311 "Cryptography"
32312 ],
32313 "license": "MIT",
32314 "main": "lib/elliptic.js",
32315 "maintainers": [
32316 {
32317 "name": "indutny",
32318 "email": "fedor@indutny.com"
32319 }
32320 ],
32321 "name": "elliptic",
32322 "optionalDependencies": {},
32323 "readme": "ERROR: No README data found!",
32324 "repository": {
32325 "type": "git",
32326 "url": "git+ssh://git@github.com/indutny/elliptic.git"
32327 },
32328 "scripts": {
32329 "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
32330 "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
32331 "lint": "npm run jscs && npm run jshint",
32332 "test": "npm run lint && npm run unit",
32333 "unit": "istanbul test _mocha --reporter=spec test/index.js",
32334 "version": "grunt dist && git add dist/"
32335 },
32336 "version": "6.3.3"
32337}
32338
32339},{}],56:[function(require,module,exports){
32340(function (Buffer){
32341'use strict';
32342
32343var isHexPrefixed = require('is-hex-prefixed');
32344var stripHexPrefix = require('strip-hex-prefix');
32345
32346/**
32347 * Pads a `String` to have an even length
32348 * @param {String} value
32349 * @return {String} output
32350 */
32351function padToEven(value) {
32352 var a = value; // eslint-disable-line
32353
32354 if (typeof a !== 'string') {
32355 throw new Error('[ethjs-util] while padding to even, value must be string, is currently ' + typeof a + ', while padToEven.');
32356 }
32357
32358 if (a.length % 2) {
32359 a = '0' + a;
32360 }
32361
32362 return a;
32363}
32364
32365/**
32366 * Converts a `Number` into a hex `String`
32367 * @param {Number} i
32368 * @return {String}
32369 */
32370function intToHex(i) {
32371 var hex = i.toString(16); // eslint-disable-line
32372
32373 return '0x' + padToEven(hex);
32374}
32375
32376/**
32377 * Converts an `Number` to a `Buffer`
32378 * @param {Number} i
32379 * @return {Buffer}
32380 */
32381function intToBuffer(i) {
32382 var hex = intToHex(i);
32383
32384 return new Buffer(hex.slice(2), 'hex');
32385}
32386
32387/**
32388 * Get the binary size of a string
32389 * @param {String} str
32390 * @return {Number}
32391 */
32392function getBinarySize(str) {
32393 if (typeof str !== 'string') {
32394 throw new Error('[ethjs-util] while getting binary size, method getBinarySize requires input \'str\' to be type String, got \'' + typeof str + '\'.');
32395 }
32396
32397 return Buffer.byteLength(str, 'utf8');
32398}
32399
32400/**
32401 * Returns TRUE if the first specified array contains all elements
32402 * from the second one. FALSE otherwise.
32403 *
32404 * @param {array} superset
32405 * @param {array} subset
32406 *
32407 * @returns {boolean}
32408 */
32409function arrayContainsArray(superset, subset, some) {
32410 if (Array.isArray(superset) !== true) {
32411 throw new Error('[ethjs-util] method arrayContainsArray requires input \'superset\' to be an array got type \'' + typeof superset + '\'');
32412 }
32413 if (Array.isArray(subset) !== true) {
32414 throw new Error('[ethjs-util] method arrayContainsArray requires input \'subset\' to be an array got type \'' + typeof subset + '\'');
32415 }
32416
32417 return subset[Boolean(some) && 'some' || 'every'](function (value) {
32418 return superset.indexOf(value) >= 0;
32419 });
32420}
32421
32422/**
32423 * Should be called to get utf8 from it's hex representation
32424 *
32425 * @method toUtf8
32426 * @param {String} string in hex
32427 * @returns {String} ascii string representation of hex value
32428 */
32429function toUtf8(hex) {
32430 var bufferValue = new Buffer(padToEven(stripHexPrefix(hex).replace(/^0+|0+$/g, '')), 'hex');
32431
32432 return bufferValue.toString('utf8');
32433}
32434
32435/**
32436 * Should be called to get ascii from it's hex representation
32437 *
32438 * @method toAscii
32439 * @param {String} string in hex
32440 * @returns {String} ascii string representation of hex value
32441 */
32442function toAscii(hex) {
32443 var str = ''; // eslint-disable-line
32444 var i = 0,
32445 l = hex.length; // eslint-disable-line
32446
32447 if (hex.substring(0, 2) === '0x') {
32448 i = 2;
32449 }
32450
32451 for (; i < l; i += 2) {
32452 var code = parseInt(hex.substr(i, 2), 16);
32453 str += String.fromCharCode(code);
32454 }
32455
32456 return str;
32457}
32458
32459/**
32460 * Should be called to get hex representation (prefixed by 0x) of utf8 string
32461 *
32462 * @method fromUtf8
32463 * @param {String} string
32464 * @param {Number} optional padding
32465 * @returns {String} hex representation of input string
32466 */
32467function fromUtf8(stringValue) {
32468 var str = new Buffer(stringValue, 'utf8');
32469
32470 return '0x' + padToEven(str.toString('hex')).replace(/^0+|0+$/g, '');
32471}
32472
32473/**
32474 * Should be called to get hex representation (prefixed by 0x) of ascii string
32475 *
32476 * @method fromAscii
32477 * @param {String} string
32478 * @param {Number} optional padding
32479 * @returns {String} hex representation of input string
32480 */
32481function fromAscii(stringValue) {
32482 var hex = ''; // eslint-disable-line
32483 for (var i = 0; i < stringValue.length; i++) {
32484 // eslint-disable-line
32485 var code = stringValue.charCodeAt(i);
32486 var n = code.toString(16);
32487 hex += n.length < 2 ? '0' + n : n;
32488 }
32489
32490 return '0x' + hex;
32491}
32492
32493/**
32494 * getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3]
32495 *
32496 * @method getKeys get specific key from inner object array of objects
32497 * @param {String} params
32498 * @param {String} key
32499 * @param {Boolean} allowEmpty
32500 * @returns {Array} output just a simple array of output keys
32501 */
32502function getKeys(params, key, allowEmpty) {
32503 if (!Array.isArray(params)) {
32504 throw new Error('[ethjs-util] method getKeys expecting type Array as \'params\' input, got \'' + typeof params + '\'');
32505 }
32506 if (typeof key !== 'string') {
32507 throw new Error('[ethjs-util] method getKeys expecting type String for input \'key\' got \'' + typeof key + '\'.');
32508 }
32509
32510 var result = []; // eslint-disable-line
32511
32512 for (var i = 0; i < params.length; i++) {
32513 // eslint-disable-line
32514 var value = params[i][key]; // eslint-disable-line
32515 if (allowEmpty && !value) {
32516 value = '';
32517 } else if (typeof value !== 'string') {
32518 throw new Error('invalid abi');
32519 }
32520 result.push(value);
32521 }
32522
32523 return result;
32524}
32525
32526/**
32527 * Is the string a hex string.
32528 *
32529 * @method check if string is hex string of specific length
32530 * @param {String} value
32531 * @param {Number} length
32532 * @returns {Boolean} output the string is a hex string
32533 */
32534function isHexString(value, length) {
32535 if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
32536 return false;
32537 }
32538
32539 if (length && value.length !== 2 + 2 * length) {
32540 return false;
32541 }
32542
32543 return true;
32544}
32545
32546module.exports = {
32547 arrayContainsArray: arrayContainsArray,
32548 intToBuffer: intToBuffer,
32549 getBinarySize: getBinarySize,
32550 isHexPrefixed: isHexPrefixed,
32551 stripHexPrefix: stripHexPrefix,
32552 padToEven: padToEven,
32553 intToHex: intToHex,
32554 fromAscii: fromAscii,
32555 fromUtf8: fromUtf8,
32556 toAscii: toAscii,
32557 toUtf8: toUtf8,
32558 getKeys: getKeys,
32559 isHexString: isHexString
32560};
32561}).call(this,require("buffer").Buffer)
32562},{"buffer":5,"is-hex-prefixed":64,"strip-hex-prefix":87}],57:[function(require,module,exports){
32563var hash = exports;
32564
32565hash.utils = require('./hash/utils');
32566hash.common = require('./hash/common');
32567hash.sha = require('./hash/sha');
32568hash.ripemd = require('./hash/ripemd');
32569hash.hmac = require('./hash/hmac');
32570
32571// Proxy hash functions to the main object
32572hash.sha1 = hash.sha.sha1;
32573hash.sha256 = hash.sha.sha256;
32574hash.sha224 = hash.sha.sha224;
32575hash.sha384 = hash.sha.sha384;
32576hash.sha512 = hash.sha.sha512;
32577hash.ripemd160 = hash.ripemd.ripemd160;
32578
32579},{"./hash/common":58,"./hash/hmac":59,"./hash/ripemd":60,"./hash/sha":61,"./hash/utils":62}],58:[function(require,module,exports){
32580var hash = require('../hash');
32581var utils = hash.utils;
32582var assert = utils.assert;
32583
32584function BlockHash() {
32585 this.pending = null;
32586 this.pendingTotal = 0;
32587 this.blockSize = this.constructor.blockSize;
32588 this.outSize = this.constructor.outSize;
32589 this.hmacStrength = this.constructor.hmacStrength;
32590 this.padLength = this.constructor.padLength / 8;
32591 this.endian = 'big';
32592
32593 this._delta8 = this.blockSize / 8;
32594 this._delta32 = this.blockSize / 32;
32595}
32596exports.BlockHash = BlockHash;
32597
32598BlockHash.prototype.update = function update(msg, enc) {
32599 // Convert message to array, pad it, and join into 32bit blocks
32600 msg = utils.toArray(msg, enc);
32601 if (!this.pending)
32602 this.pending = msg;
32603 else
32604 this.pending = this.pending.concat(msg);
32605 this.pendingTotal += msg.length;
32606
32607 // Enough data, try updating
32608 if (this.pending.length >= this._delta8) {
32609 msg = this.pending;
32610
32611 // Process pending data in blocks
32612 var r = msg.length % this._delta8;
32613 this.pending = msg.slice(msg.length - r, msg.length);
32614 if (this.pending.length === 0)
32615 this.pending = null;
32616
32617 msg = utils.join32(msg, 0, msg.length - r, this.endian);
32618 for (var i = 0; i < msg.length; i += this._delta32)
32619 this._update(msg, i, i + this._delta32);
32620 }
32621
32622 return this;
32623};
32624
32625BlockHash.prototype.digest = function digest(enc) {
32626 this.update(this._pad());
32627 assert(this.pending === null);
32628
32629 return this._digest(enc);
32630};
32631
32632BlockHash.prototype._pad = function pad() {
32633 var len = this.pendingTotal;
32634 var bytes = this._delta8;
32635 var k = bytes - ((len + this.padLength) % bytes);
32636 var res = new Array(k + this.padLength);
32637 res[0] = 0x80;
32638 for (var i = 1; i < k; i++)
32639 res[i] = 0;
32640
32641 // Append length
32642 len <<= 3;
32643 if (this.endian === 'big') {
32644 for (var t = 8; t < this.padLength; t++)
32645 res[i++] = 0;
32646
32647 res[i++] = 0;
32648 res[i++] = 0;
32649 res[i++] = 0;
32650 res[i++] = 0;
32651 res[i++] = (len >>> 24) & 0xff;
32652 res[i++] = (len >>> 16) & 0xff;
32653 res[i++] = (len >>> 8) & 0xff;
32654 res[i++] = len & 0xff;
32655 } else {
32656 res[i++] = len & 0xff;
32657 res[i++] = (len >>> 8) & 0xff;
32658 res[i++] = (len >>> 16) & 0xff;
32659 res[i++] = (len >>> 24) & 0xff;
32660 res[i++] = 0;
32661 res[i++] = 0;
32662 res[i++] = 0;
32663 res[i++] = 0;
32664
32665 for (var t = 8; t < this.padLength; t++)
32666 res[i++] = 0;
32667 }
32668
32669 return res;
32670};
32671
32672},{"../hash":57}],59:[function(require,module,exports){
32673var hmac = exports;
32674
32675var hash = require('../hash');
32676var utils = hash.utils;
32677var assert = utils.assert;
32678
32679function Hmac(hash, key, enc) {
32680 if (!(this instanceof Hmac))
32681 return new Hmac(hash, key, enc);
32682 this.Hash = hash;
32683 this.blockSize = hash.blockSize / 8;
32684 this.outSize = hash.outSize / 8;
32685 this.inner = null;
32686 this.outer = null;
32687
32688 this._init(utils.toArray(key, enc));
32689}
32690module.exports = Hmac;
32691
32692Hmac.prototype._init = function init(key) {
32693 // Shorten key, if needed
32694 if (key.length > this.blockSize)
32695 key = new this.Hash().update(key).digest();
32696 assert(key.length <= this.blockSize);
32697
32698 // Add padding to key
32699 for (var i = key.length; i < this.blockSize; i++)
32700 key.push(0);
32701
32702 for (var i = 0; i < key.length; i++)
32703 key[i] ^= 0x36;
32704 this.inner = new this.Hash().update(key);
32705
32706 // 0x36 ^ 0x5c = 0x6a
32707 for (var i = 0; i < key.length; i++)
32708 key[i] ^= 0x6a;
32709 this.outer = new this.Hash().update(key);
32710};
32711
32712Hmac.prototype.update = function update(msg, enc) {
32713 this.inner.update(msg, enc);
32714 return this;
32715};
32716
32717Hmac.prototype.digest = function digest(enc) {
32718 this.outer.update(this.inner.digest());
32719 return this.outer.digest(enc);
32720};
32721
32722},{"../hash":57}],60:[function(require,module,exports){
32723var hash = require('../hash');
32724var utils = hash.utils;
32725
32726var rotl32 = utils.rotl32;
32727var sum32 = utils.sum32;
32728var sum32_3 = utils.sum32_3;
32729var sum32_4 = utils.sum32_4;
32730var BlockHash = hash.common.BlockHash;
32731
32732function RIPEMD160() {
32733 if (!(this instanceof RIPEMD160))
32734 return new RIPEMD160();
32735
32736 BlockHash.call(this);
32737
32738 this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
32739 this.endian = 'little';
32740}
32741utils.inherits(RIPEMD160, BlockHash);
32742exports.ripemd160 = RIPEMD160;
32743
32744RIPEMD160.blockSize = 512;
32745RIPEMD160.outSize = 160;
32746RIPEMD160.hmacStrength = 192;
32747RIPEMD160.padLength = 64;
32748
32749RIPEMD160.prototype._update = function update(msg, start) {
32750 var A = this.h[0];
32751 var B = this.h[1];
32752 var C = this.h[2];
32753 var D = this.h[3];
32754 var E = this.h[4];
32755 var Ah = A;
32756 var Bh = B;
32757 var Ch = C;
32758 var Dh = D;
32759 var Eh = E;
32760 for (var j = 0; j < 80; j++) {
32761 var T = sum32(
32762 rotl32(
32763 sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
32764 s[j]),
32765 E);
32766 A = E;
32767 E = D;
32768 D = rotl32(C, 10);
32769 C = B;
32770 B = T;
32771 T = sum32(
32772 rotl32(
32773 sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
32774 sh[j]),
32775 Eh);
32776 Ah = Eh;
32777 Eh = Dh;
32778 Dh = rotl32(Ch, 10);
32779 Ch = Bh;
32780 Bh = T;
32781 }
32782 T = sum32_3(this.h[1], C, Dh);
32783 this.h[1] = sum32_3(this.h[2], D, Eh);
32784 this.h[2] = sum32_3(this.h[3], E, Ah);
32785 this.h[3] = sum32_3(this.h[4], A, Bh);
32786 this.h[4] = sum32_3(this.h[0], B, Ch);
32787 this.h[0] = T;
32788};
32789
32790RIPEMD160.prototype._digest = function digest(enc) {
32791 if (enc === 'hex')
32792 return utils.toHex32(this.h, 'little');
32793 else
32794 return utils.split32(this.h, 'little');
32795};
32796
32797function f(j, x, y, z) {
32798 if (j <= 15)
32799 return x ^ y ^ z;
32800 else if (j <= 31)
32801 return (x & y) | ((~x) & z);
32802 else if (j <= 47)
32803 return (x | (~y)) ^ z;
32804 else if (j <= 63)
32805 return (x & z) | (y & (~z));
32806 else
32807 return x ^ (y | (~z));
32808}
32809
32810function K(j) {
32811 if (j <= 15)
32812 return 0x00000000;
32813 else if (j <= 31)
32814 return 0x5a827999;
32815 else if (j <= 47)
32816 return 0x6ed9eba1;
32817 else if (j <= 63)
32818 return 0x8f1bbcdc;
32819 else
32820 return 0xa953fd4e;
32821}
32822
32823function Kh(j) {
32824 if (j <= 15)
32825 return 0x50a28be6;
32826 else if (j <= 31)
32827 return 0x5c4dd124;
32828 else if (j <= 47)
32829 return 0x6d703ef3;
32830 else if (j <= 63)
32831 return 0x7a6d76e9;
32832 else
32833 return 0x00000000;
32834}
32835
32836var r = [
32837 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
32838 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
32839 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
32840 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
32841 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
32842];
32843
32844var rh = [
32845 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
32846 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
32847 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
32848 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
32849 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
32850];
32851
32852var s = [
32853 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
32854 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
32855 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
32856 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
32857 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
32858];
32859
32860var sh = [
32861 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
32862 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
32863 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
32864 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
32865 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
32866];
32867
32868},{"../hash":57}],61:[function(require,module,exports){
32869var hash = require('../hash');
32870var utils = hash.utils;
32871var assert = utils.assert;
32872
32873var rotr32 = utils.rotr32;
32874var rotl32 = utils.rotl32;
32875var sum32 = utils.sum32;
32876var sum32_4 = utils.sum32_4;
32877var sum32_5 = utils.sum32_5;
32878var rotr64_hi = utils.rotr64_hi;
32879var rotr64_lo = utils.rotr64_lo;
32880var shr64_hi = utils.shr64_hi;
32881var shr64_lo = utils.shr64_lo;
32882var sum64 = utils.sum64;
32883var sum64_hi = utils.sum64_hi;
32884var sum64_lo = utils.sum64_lo;
32885var sum64_4_hi = utils.sum64_4_hi;
32886var sum64_4_lo = utils.sum64_4_lo;
32887var sum64_5_hi = utils.sum64_5_hi;
32888var sum64_5_lo = utils.sum64_5_lo;
32889var BlockHash = hash.common.BlockHash;
32890
32891var sha256_K = [
32892 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
32893 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
32894 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
32895 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
32896 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
32897 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
32898 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
32899 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
32900 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
32901 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
32902 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
32903 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
32904 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
32905 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
32906 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
32907 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
32908];
32909
32910var sha512_K = [
32911 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
32912 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
32913 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
32914 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
32915 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
32916 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
32917 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
32918 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
32919 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
32920 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
32921 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
32922 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
32923 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
32924 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
32925 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
32926 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
32927 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
32928 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
32929 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
32930 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
32931 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
32932 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
32933 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
32934 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
32935 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
32936 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
32937 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
32938 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
32939 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
32940 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
32941 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
32942 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
32943 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
32944 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
32945 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
32946 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
32947 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
32948 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
32949 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
32950 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
32951];
32952
32953var sha1_K = [
32954 0x5A827999, 0x6ED9EBA1,
32955 0x8F1BBCDC, 0xCA62C1D6
32956];
32957
32958function SHA256() {
32959 if (!(this instanceof SHA256))
32960 return new SHA256();
32961
32962 BlockHash.call(this);
32963 this.h = [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
32964 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ];
32965 this.k = sha256_K;
32966 this.W = new Array(64);
32967}
32968utils.inherits(SHA256, BlockHash);
32969exports.sha256 = SHA256;
32970
32971SHA256.blockSize = 512;
32972SHA256.outSize = 256;
32973SHA256.hmacStrength = 192;
32974SHA256.padLength = 64;
32975
32976SHA256.prototype._update = function _update(msg, start) {
32977 var W = this.W;
32978
32979 for (var i = 0; i < 16; i++)
32980 W[i] = msg[start + i];
32981 for (; i < W.length; i++)
32982 W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
32983
32984 var a = this.h[0];
32985 var b = this.h[1];
32986 var c = this.h[2];
32987 var d = this.h[3];
32988 var e = this.h[4];
32989 var f = this.h[5];
32990 var g = this.h[6];
32991 var h = this.h[7];
32992
32993 assert(this.k.length === W.length);
32994 for (var i = 0; i < W.length; i++) {
32995 var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
32996 var T2 = sum32(s0_256(a), maj32(a, b, c));
32997 h = g;
32998 g = f;
32999 f = e;
33000 e = sum32(d, T1);
33001 d = c;
33002 c = b;
33003 b = a;
33004 a = sum32(T1, T2);
33005 }
33006
33007 this.h[0] = sum32(this.h[0], a);
33008 this.h[1] = sum32(this.h[1], b);
33009 this.h[2] = sum32(this.h[2], c);
33010 this.h[3] = sum32(this.h[3], d);
33011 this.h[4] = sum32(this.h[4], e);
33012 this.h[5] = sum32(this.h[5], f);
33013 this.h[6] = sum32(this.h[6], g);
33014 this.h[7] = sum32(this.h[7], h);
33015};
33016
33017SHA256.prototype._digest = function digest(enc) {
33018 if (enc === 'hex')
33019 return utils.toHex32(this.h, 'big');
33020 else
33021 return utils.split32(this.h, 'big');
33022};
33023
33024function SHA224() {
33025 if (!(this instanceof SHA224))
33026 return new SHA224();
33027
33028 SHA256.call(this);
33029 this.h = [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
33030 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
33031}
33032utils.inherits(SHA224, SHA256);
33033exports.sha224 = SHA224;
33034
33035SHA224.blockSize = 512;
33036SHA224.outSize = 224;
33037SHA224.hmacStrength = 192;
33038SHA224.padLength = 64;
33039
33040SHA224.prototype._digest = function digest(enc) {
33041 // Just truncate output
33042 if (enc === 'hex')
33043 return utils.toHex32(this.h.slice(0, 7), 'big');
33044 else
33045 return utils.split32(this.h.slice(0, 7), 'big');
33046};
33047
33048function SHA512() {
33049 if (!(this instanceof SHA512))
33050 return new SHA512();
33051
33052 BlockHash.call(this);
33053 this.h = [ 0x6a09e667, 0xf3bcc908,
33054 0xbb67ae85, 0x84caa73b,
33055 0x3c6ef372, 0xfe94f82b,
33056 0xa54ff53a, 0x5f1d36f1,
33057 0x510e527f, 0xade682d1,
33058 0x9b05688c, 0x2b3e6c1f,
33059 0x1f83d9ab, 0xfb41bd6b,
33060 0x5be0cd19, 0x137e2179 ];
33061 this.k = sha512_K;
33062 this.W = new Array(160);
33063}
33064utils.inherits(SHA512, BlockHash);
33065exports.sha512 = SHA512;
33066
33067SHA512.blockSize = 1024;
33068SHA512.outSize = 512;
33069SHA512.hmacStrength = 192;
33070SHA512.padLength = 128;
33071
33072SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
33073 var W = this.W;
33074
33075 // 32 x 32bit words
33076 for (var i = 0; i < 32; i++)
33077 W[i] = msg[start + i];
33078 for (; i < W.length; i += 2) {
33079 var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
33080 var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
33081 var c1_hi = W[i - 14]; // i - 7
33082 var c1_lo = W[i - 13];
33083 var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
33084 var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
33085 var c3_hi = W[i - 32]; // i - 16
33086 var c3_lo = W[i - 31];
33087
33088 W[i] = sum64_4_hi(c0_hi, c0_lo,
33089 c1_hi, c1_lo,
33090 c2_hi, c2_lo,
33091 c3_hi, c3_lo);
33092 W[i + 1] = sum64_4_lo(c0_hi, c0_lo,
33093 c1_hi, c1_lo,
33094 c2_hi, c2_lo,
33095 c3_hi, c3_lo);
33096 }
33097};
33098
33099SHA512.prototype._update = function _update(msg, start) {
33100 this._prepareBlock(msg, start);
33101
33102 var W = this.W;
33103
33104 var ah = this.h[0];
33105 var al = this.h[1];
33106 var bh = this.h[2];
33107 var bl = this.h[3];
33108 var ch = this.h[4];
33109 var cl = this.h[5];
33110 var dh = this.h[6];
33111 var dl = this.h[7];
33112 var eh = this.h[8];
33113 var el = this.h[9];
33114 var fh = this.h[10];
33115 var fl = this.h[11];
33116 var gh = this.h[12];
33117 var gl = this.h[13];
33118 var hh = this.h[14];
33119 var hl = this.h[15];
33120
33121 assert(this.k.length === W.length);
33122 for (var i = 0; i < W.length; i += 2) {
33123 var c0_hi = hh;
33124 var c0_lo = hl;
33125 var c1_hi = s1_512_hi(eh, el);
33126 var c1_lo = s1_512_lo(eh, el);
33127 var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
33128 var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
33129 var c3_hi = this.k[i];
33130 var c3_lo = this.k[i + 1];
33131 var c4_hi = W[i];
33132 var c4_lo = W[i + 1];
33133
33134 var T1_hi = sum64_5_hi(c0_hi, c0_lo,
33135 c1_hi, c1_lo,
33136 c2_hi, c2_lo,
33137 c3_hi, c3_lo,
33138 c4_hi, c4_lo);
33139 var T1_lo = sum64_5_lo(c0_hi, c0_lo,
33140 c1_hi, c1_lo,
33141 c2_hi, c2_lo,
33142 c3_hi, c3_lo,
33143 c4_hi, c4_lo);
33144
33145 var c0_hi = s0_512_hi(ah, al);
33146 var c0_lo = s0_512_lo(ah, al);
33147 var c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
33148 var c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
33149
33150 var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
33151 var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
33152
33153 hh = gh;
33154 hl = gl;
33155
33156 gh = fh;
33157 gl = fl;
33158
33159 fh = eh;
33160 fl = el;
33161
33162 eh = sum64_hi(dh, dl, T1_hi, T1_lo);
33163 el = sum64_lo(dl, dl, T1_hi, T1_lo);
33164
33165 dh = ch;
33166 dl = cl;
33167
33168 ch = bh;
33169 cl = bl;
33170
33171 bh = ah;
33172 bl = al;
33173
33174 ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
33175 al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
33176 }
33177
33178 sum64(this.h, 0, ah, al);
33179 sum64(this.h, 2, bh, bl);
33180 sum64(this.h, 4, ch, cl);
33181 sum64(this.h, 6, dh, dl);
33182 sum64(this.h, 8, eh, el);
33183 sum64(this.h, 10, fh, fl);
33184 sum64(this.h, 12, gh, gl);
33185 sum64(this.h, 14, hh, hl);
33186};
33187
33188SHA512.prototype._digest = function digest(enc) {
33189 if (enc === 'hex')
33190 return utils.toHex32(this.h, 'big');
33191 else
33192 return utils.split32(this.h, 'big');
33193};
33194
33195function SHA384() {
33196 if (!(this instanceof SHA384))
33197 return new SHA384();
33198
33199 SHA512.call(this);
33200 this.h = [ 0xcbbb9d5d, 0xc1059ed8,
33201 0x629a292a, 0x367cd507,
33202 0x9159015a, 0x3070dd17,
33203 0x152fecd8, 0xf70e5939,
33204 0x67332667, 0xffc00b31,
33205 0x8eb44a87, 0x68581511,
33206 0xdb0c2e0d, 0x64f98fa7,
33207 0x47b5481d, 0xbefa4fa4 ];
33208}
33209utils.inherits(SHA384, SHA512);
33210exports.sha384 = SHA384;
33211
33212SHA384.blockSize = 1024;
33213SHA384.outSize = 384;
33214SHA384.hmacStrength = 192;
33215SHA384.padLength = 128;
33216
33217SHA384.prototype._digest = function digest(enc) {
33218 if (enc === 'hex')
33219 return utils.toHex32(this.h.slice(0, 12), 'big');
33220 else
33221 return utils.split32(this.h.slice(0, 12), 'big');
33222};
33223
33224function SHA1() {
33225 if (!(this instanceof SHA1))
33226 return new SHA1();
33227
33228 BlockHash.call(this);
33229 this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe,
33230 0x10325476, 0xc3d2e1f0 ];
33231 this.W = new Array(80);
33232}
33233
33234utils.inherits(SHA1, BlockHash);
33235exports.sha1 = SHA1;
33236
33237SHA1.blockSize = 512;
33238SHA1.outSize = 160;
33239SHA1.hmacStrength = 80;
33240SHA1.padLength = 64;
33241
33242SHA1.prototype._update = function _update(msg, start) {
33243 var W = this.W;
33244
33245 for (var i = 0; i < 16; i++)
33246 W[i] = msg[start + i];
33247
33248 for(; i < W.length; i++)
33249 W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
33250
33251 var a = this.h[0];
33252 var b = this.h[1];
33253 var c = this.h[2];
33254 var d = this.h[3];
33255 var e = this.h[4];
33256
33257 for (var i = 0; i < W.length; i++) {
33258 var s = ~~(i / 20);
33259 var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
33260 e = d;
33261 d = c;
33262 c = rotl32(b, 30);
33263 b = a;
33264 a = t;
33265 }
33266
33267 this.h[0] = sum32(this.h[0], a);
33268 this.h[1] = sum32(this.h[1], b);
33269 this.h[2] = sum32(this.h[2], c);
33270 this.h[3] = sum32(this.h[3], d);
33271 this.h[4] = sum32(this.h[4], e);
33272};
33273
33274SHA1.prototype._digest = function digest(enc) {
33275 if (enc === 'hex')
33276 return utils.toHex32(this.h, 'big');
33277 else
33278 return utils.split32(this.h, 'big');
33279};
33280
33281function ch32(x, y, z) {
33282 return (x & y) ^ ((~x) & z);
33283}
33284
33285function maj32(x, y, z) {
33286 return (x & y) ^ (x & z) ^ (y & z);
33287}
33288
33289function p32(x, y, z) {
33290 return x ^ y ^ z;
33291}
33292
33293function s0_256(x) {
33294 return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
33295}
33296
33297function s1_256(x) {
33298 return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
33299}
33300
33301function g0_256(x) {
33302 return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
33303}
33304
33305function g1_256(x) {
33306 return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
33307}
33308
33309function ft_1(s, x, y, z) {
33310 if (s === 0)
33311 return ch32(x, y, z);
33312 if (s === 1 || s === 3)
33313 return p32(x, y, z);
33314 if (s === 2)
33315 return maj32(x, y, z);
33316}
33317
33318function ch64_hi(xh, xl, yh, yl, zh, zl) {
33319 var r = (xh & yh) ^ ((~xh) & zh);
33320 if (r < 0)
33321 r += 0x100000000;
33322 return r;
33323}
33324
33325function ch64_lo(xh, xl, yh, yl, zh, zl) {
33326 var r = (xl & yl) ^ ((~xl) & zl);
33327 if (r < 0)
33328 r += 0x100000000;
33329 return r;
33330}
33331
33332function maj64_hi(xh, xl, yh, yl, zh, zl) {
33333 var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
33334 if (r < 0)
33335 r += 0x100000000;
33336 return r;
33337}
33338
33339function maj64_lo(xh, xl, yh, yl, zh, zl) {
33340 var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
33341 if (r < 0)
33342 r += 0x100000000;
33343 return r;
33344}
33345
33346function s0_512_hi(xh, xl) {
33347 var c0_hi = rotr64_hi(xh, xl, 28);
33348 var c1_hi = rotr64_hi(xl, xh, 2); // 34
33349 var c2_hi = rotr64_hi(xl, xh, 7); // 39
33350
33351 var r = c0_hi ^ c1_hi ^ c2_hi;
33352 if (r < 0)
33353 r += 0x100000000;
33354 return r;
33355}
33356
33357function s0_512_lo(xh, xl) {
33358 var c0_lo = rotr64_lo(xh, xl, 28);
33359 var c1_lo = rotr64_lo(xl, xh, 2); // 34
33360 var c2_lo = rotr64_lo(xl, xh, 7); // 39
33361
33362 var r = c0_lo ^ c1_lo ^ c2_lo;
33363 if (r < 0)
33364 r += 0x100000000;
33365 return r;
33366}
33367
33368function s1_512_hi(xh, xl) {
33369 var c0_hi = rotr64_hi(xh, xl, 14);
33370 var c1_hi = rotr64_hi(xh, xl, 18);
33371 var c2_hi = rotr64_hi(xl, xh, 9); // 41
33372
33373 var r = c0_hi ^ c1_hi ^ c2_hi;
33374 if (r < 0)
33375 r += 0x100000000;
33376 return r;
33377}
33378
33379function s1_512_lo(xh, xl) {
33380 var c0_lo = rotr64_lo(xh, xl, 14);
33381 var c1_lo = rotr64_lo(xh, xl, 18);
33382 var c2_lo = rotr64_lo(xl, xh, 9); // 41
33383
33384 var r = c0_lo ^ c1_lo ^ c2_lo;
33385 if (r < 0)
33386 r += 0x100000000;
33387 return r;
33388}
33389
33390function g0_512_hi(xh, xl) {
33391 var c0_hi = rotr64_hi(xh, xl, 1);
33392 var c1_hi = rotr64_hi(xh, xl, 8);
33393 var c2_hi = shr64_hi(xh, xl, 7);
33394
33395 var r = c0_hi ^ c1_hi ^ c2_hi;
33396 if (r < 0)
33397 r += 0x100000000;
33398 return r;
33399}
33400
33401function g0_512_lo(xh, xl) {
33402 var c0_lo = rotr64_lo(xh, xl, 1);
33403 var c1_lo = rotr64_lo(xh, xl, 8);
33404 var c2_lo = shr64_lo(xh, xl, 7);
33405
33406 var r = c0_lo ^ c1_lo ^ c2_lo;
33407 if (r < 0)
33408 r += 0x100000000;
33409 return r;
33410}
33411
33412function g1_512_hi(xh, xl) {
33413 var c0_hi = rotr64_hi(xh, xl, 19);
33414 var c1_hi = rotr64_hi(xl, xh, 29); // 61
33415 var c2_hi = shr64_hi(xh, xl, 6);
33416
33417 var r = c0_hi ^ c1_hi ^ c2_hi;
33418 if (r < 0)
33419 r += 0x100000000;
33420 return r;
33421}
33422
33423function g1_512_lo(xh, xl) {
33424 var c0_lo = rotr64_lo(xh, xl, 19);
33425 var c1_lo = rotr64_lo(xl, xh, 29); // 61
33426 var c2_lo = shr64_lo(xh, xl, 6);
33427
33428 var r = c0_lo ^ c1_lo ^ c2_lo;
33429 if (r < 0)
33430 r += 0x100000000;
33431 return r;
33432}
33433
33434},{"../hash":57}],62:[function(require,module,exports){
33435var utils = exports;
33436var inherits = require('inherits');
33437
33438function toArray(msg, enc) {
33439 if (Array.isArray(msg))
33440 return msg.slice();
33441 if (!msg)
33442 return [];
33443 var res = [];
33444 if (typeof msg === 'string') {
33445 if (!enc) {
33446 for (var i = 0; i < msg.length; i++) {
33447 var c = msg.charCodeAt(i);
33448 var hi = c >> 8;
33449 var lo = c & 0xff;
33450 if (hi)
33451 res.push(hi, lo);
33452 else
33453 res.push(lo);
33454 }
33455 } else if (enc === 'hex') {
33456 msg = msg.replace(/[^a-z0-9]+/ig, '');
33457 if (msg.length % 2 !== 0)
33458 msg = '0' + msg;
33459 for (var i = 0; i < msg.length; i += 2)
33460 res.push(parseInt(msg[i] + msg[i + 1], 16));
33461 }
33462 } else {
33463 for (var i = 0; i < msg.length; i++)
33464 res[i] = msg[i] | 0;
33465 }
33466 return res;
33467}
33468utils.toArray = toArray;
33469
33470function toHex(msg) {
33471 var res = '';
33472 for (var i = 0; i < msg.length; i++)
33473 res += zero2(msg[i].toString(16));
33474 return res;
33475}
33476utils.toHex = toHex;
33477
33478function htonl(w) {
33479 var res = (w >>> 24) |
33480 ((w >>> 8) & 0xff00) |
33481 ((w << 8) & 0xff0000) |
33482 ((w & 0xff) << 24);
33483 return res >>> 0;
33484}
33485utils.htonl = htonl;
33486
33487function toHex32(msg, endian) {
33488 var res = '';
33489 for (var i = 0; i < msg.length; i++) {
33490 var w = msg[i];
33491 if (endian === 'little')
33492 w = htonl(w);
33493 res += zero8(w.toString(16));
33494 }
33495 return res;
33496}
33497utils.toHex32 = toHex32;
33498
33499function zero2(word) {
33500 if (word.length === 1)
33501 return '0' + word;
33502 else
33503 return word;
33504}
33505utils.zero2 = zero2;
33506
33507function zero8(word) {
33508 if (word.length === 7)
33509 return '0' + word;
33510 else if (word.length === 6)
33511 return '00' + word;
33512 else if (word.length === 5)
33513 return '000' + word;
33514 else if (word.length === 4)
33515 return '0000' + word;
33516 else if (word.length === 3)
33517 return '00000' + word;
33518 else if (word.length === 2)
33519 return '000000' + word;
33520 else if (word.length === 1)
33521 return '0000000' + word;
33522 else
33523 return word;
33524}
33525utils.zero8 = zero8;
33526
33527function join32(msg, start, end, endian) {
33528 var len = end - start;
33529 assert(len % 4 === 0);
33530 var res = new Array(len / 4);
33531 for (var i = 0, k = start; i < res.length; i++, k += 4) {
33532 var w;
33533 if (endian === 'big')
33534 w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
33535 else
33536 w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
33537 res[i] = w >>> 0;
33538 }
33539 return res;
33540}
33541utils.join32 = join32;
33542
33543function split32(msg, endian) {
33544 var res = new Array(msg.length * 4);
33545 for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
33546 var m = msg[i];
33547 if (endian === 'big') {
33548 res[k] = m >>> 24;
33549 res[k + 1] = (m >>> 16) & 0xff;
33550 res[k + 2] = (m >>> 8) & 0xff;
33551 res[k + 3] = m & 0xff;
33552 } else {
33553 res[k + 3] = m >>> 24;
33554 res[k + 2] = (m >>> 16) & 0xff;
33555 res[k + 1] = (m >>> 8) & 0xff;
33556 res[k] = m & 0xff;
33557 }
33558 }
33559 return res;
33560}
33561utils.split32 = split32;
33562
33563function rotr32(w, b) {
33564 return (w >>> b) | (w << (32 - b));
33565}
33566utils.rotr32 = rotr32;
33567
33568function rotl32(w, b) {
33569 return (w << b) | (w >>> (32 - b));
33570}
33571utils.rotl32 = rotl32;
33572
33573function sum32(a, b) {
33574 return (a + b) >>> 0;
33575}
33576utils.sum32 = sum32;
33577
33578function sum32_3(a, b, c) {
33579 return (a + b + c) >>> 0;
33580}
33581utils.sum32_3 = sum32_3;
33582
33583function sum32_4(a, b, c, d) {
33584 return (a + b + c + d) >>> 0;
33585}
33586utils.sum32_4 = sum32_4;
33587
33588function sum32_5(a, b, c, d, e) {
33589 return (a + b + c + d + e) >>> 0;
33590}
33591utils.sum32_5 = sum32_5;
33592
33593function assert(cond, msg) {
33594 if (!cond)
33595 throw new Error(msg || 'Assertion failed');
33596}
33597utils.assert = assert;
33598
33599utils.inherits = inherits;
33600
33601function sum64(buf, pos, ah, al) {
33602 var bh = buf[pos];
33603 var bl = buf[pos + 1];
33604
33605 var lo = (al + bl) >>> 0;
33606 var hi = (lo < al ? 1 : 0) + ah + bh;
33607 buf[pos] = hi >>> 0;
33608 buf[pos + 1] = lo;
33609}
33610exports.sum64 = sum64;
33611
33612function sum64_hi(ah, al, bh, bl) {
33613 var lo = (al + bl) >>> 0;
33614 var hi = (lo < al ? 1 : 0) + ah + bh;
33615 return hi >>> 0;
33616};
33617exports.sum64_hi = sum64_hi;
33618
33619function sum64_lo(ah, al, bh, bl) {
33620 var lo = al + bl;
33621 return lo >>> 0;
33622};
33623exports.sum64_lo = sum64_lo;
33624
33625function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
33626 var carry = 0;
33627 var lo = al;
33628 lo = (lo + bl) >>> 0;
33629 carry += lo < al ? 1 : 0;
33630 lo = (lo + cl) >>> 0;
33631 carry += lo < cl ? 1 : 0;
33632 lo = (lo + dl) >>> 0;
33633 carry += lo < dl ? 1 : 0;
33634
33635 var hi = ah + bh + ch + dh + carry;
33636 return hi >>> 0;
33637};
33638exports.sum64_4_hi = sum64_4_hi;
33639
33640function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
33641 var lo = al + bl + cl + dl;
33642 return lo >>> 0;
33643};
33644exports.sum64_4_lo = sum64_4_lo;
33645
33646function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
33647 var carry = 0;
33648 var lo = al;
33649 lo = (lo + bl) >>> 0;
33650 carry += lo < al ? 1 : 0;
33651 lo = (lo + cl) >>> 0;
33652 carry += lo < cl ? 1 : 0;
33653 lo = (lo + dl) >>> 0;
33654 carry += lo < dl ? 1 : 0;
33655 lo = (lo + el) >>> 0;
33656 carry += lo < el ? 1 : 0;
33657
33658 var hi = ah + bh + ch + dh + eh + carry;
33659 return hi >>> 0;
33660};
33661exports.sum64_5_hi = sum64_5_hi;
33662
33663function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
33664 var lo = al + bl + cl + dl + el;
33665
33666 return lo >>> 0;
33667};
33668exports.sum64_5_lo = sum64_5_lo;
33669
33670function rotr64_hi(ah, al, num) {
33671 var r = (al << (32 - num)) | (ah >>> num);
33672 return r >>> 0;
33673};
33674exports.rotr64_hi = rotr64_hi;
33675
33676function rotr64_lo(ah, al, num) {
33677 var r = (ah << (32 - num)) | (al >>> num);
33678 return r >>> 0;
33679};
33680exports.rotr64_lo = rotr64_lo;
33681
33682function shr64_hi(ah, al, num) {
33683 return ah >>> num;
33684};
33685exports.shr64_hi = shr64_hi;
33686
33687function shr64_lo(ah, al, num) {
33688 var r = (ah << (32 - num)) | (al >>> num);
33689 return r >>> 0;
33690};
33691exports.shr64_lo = shr64_lo;
33692
33693},{"inherits":63}],63:[function(require,module,exports){
33694arguments[4][9][0].apply(exports,arguments)
33695},{"dup":9}],64:[function(require,module,exports){
33696/**
33697 * Returns a `Boolean` on whether or not the a `String` starts with '0x'
33698 * @param {String} str the string input value
33699 * @return {Boolean} a boolean if it is or is not hex prefixed
33700 * @throws if the str input is not a string
33701 */
33702module.exports = function isHexPrefixed(str) {
33703 if (typeof str !== 'string') {
33704 throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed.");
33705 }
33706
33707 return str.slice(0, 2) === '0x';
33708}
33709
33710},{}],65:[function(require,module,exports){
33711'use strict'
33712module.exports = require('./lib/api')(require('./lib/keccak'))
33713
33714},{"./lib/api":66,"./lib/keccak":70}],66:[function(require,module,exports){
33715'use strict'
33716var createKeccak = require('./keccak')
33717var createShake = require('./shake')
33718
33719module.exports = function (KeccakState) {
33720 var Keccak = createKeccak(KeccakState)
33721 var Shake = createShake(KeccakState)
33722
33723 return function (algorithm, options) {
33724 var hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm
33725 switch (hash) {
33726 case 'keccak224': return new Keccak(1152, 448, null, 224, options)
33727 case 'keccak256': return new Keccak(1088, 512, null, 256, options)
33728 case 'keccak384': return new Keccak(832, 768, null, 384, options)
33729 case 'keccak512': return new Keccak(576, 1024, null, 512, options)
33730
33731 case 'sha3-224': return new Keccak(1152, 448, 0x06, 224, options)
33732 case 'sha3-256': return new Keccak(1088, 512, 0x06, 256, options)
33733 case 'sha3-384': return new Keccak(832, 768, 0x06, 384, options)
33734 case 'sha3-512': return new Keccak(576, 1024, 0x06, 512, options)
33735
33736 case 'shake128': return new Shake(1344, 256, 0x1f, options)
33737 case 'shake256': return new Shake(1088, 512, 0x1f, options)
33738
33739 default: throw new Error('Invald algorithm: ' + algorithm)
33740 }
33741 }
33742}
33743
33744},{"./keccak":67,"./shake":68}],67:[function(require,module,exports){
33745(function (Buffer){
33746'use strict'
33747var Transform = require('stream').Transform
33748var inherits = require('inherits')
33749
33750module.exports = function (KeccakState) {
33751 function Keccak (rate, capacity, delimitedSuffix, hashBitLength, options) {
33752 Transform.call(this, options)
33753
33754 this._rate = rate
33755 this._capacity = capacity
33756 this._delimitedSuffix = delimitedSuffix
33757 this._hashBitLength = hashBitLength
33758 this._options = options
33759
33760 this._state = new KeccakState()
33761 this._state.initialize(rate, capacity)
33762 this._finalized = false
33763 }
33764
33765 inherits(Keccak, Transform)
33766
33767 Keccak.prototype._transform = function (chunk, encoding, callback) {
33768 var error = null
33769 try {
33770 this.update(chunk, encoding)
33771 } catch (err) {
33772 error = err
33773 }
33774
33775 callback(error)
33776 }
33777
33778 Keccak.prototype._flush = function (callback) {
33779 var error = null
33780 try {
33781 this.push(this.digest())
33782 } catch (err) {
33783 error = err
33784 }
33785
33786 callback(error)
33787 }
33788
33789 Keccak.prototype.update = function (data, encoding) {
33790 if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
33791 if (this._finalized) throw new Error('Digest already called')
33792 if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
33793
33794 this._state.absorb(data)
33795
33796 return this
33797 }
33798
33799 Keccak.prototype.digest = function (encoding) {
33800 if (this._finalized) throw new Error('Digest already called')
33801 this._finalized = true
33802
33803 if (this._delimitedSuffix) this._state.absorbLastFewBits(this._delimitedSuffix)
33804 var digest = this._state.squeeze(this._hashBitLength / 8)
33805 if (encoding !== undefined) digest = digest.toString(encoding)
33806
33807 this._resetState()
33808
33809 return digest
33810 }
33811
33812 // remove result from memory
33813 Keccak.prototype._resetState = function () {
33814 this._state.initialize(this._rate, this._capacity)
33815 return this
33816 }
33817
33818 // because sometimes we need hash right now and little later
33819 Keccak.prototype._clone = function () {
33820 var clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options)
33821 this._state.copy(clone._state)
33822 clone._finalized = this._finalized
33823
33824 return clone
33825 }
33826
33827 return Keccak
33828}
33829
33830}).call(this,require("buffer").Buffer)
33831},{"buffer":5,"inherits":63,"stream":25}],68:[function(require,module,exports){
33832(function (Buffer){
33833'use strict'
33834var Transform = require('stream').Transform
33835var inherits = require('inherits')
33836
33837module.exports = function (KeccakState) {
33838 function Shake (rate, capacity, delimitedSuffix, options) {
33839 Transform.call(this, options)
33840
33841 this._rate = rate
33842 this._capacity = capacity
33843 this._delimitedSuffix = delimitedSuffix
33844 this._options = options
33845
33846 this._state = new KeccakState()
33847 this._state.initialize(rate, capacity)
33848 this._finalized = false
33849 }
33850
33851 inherits(Shake, Transform)
33852
33853 Shake.prototype._transform = function (chunk, encoding, callback) {
33854 var error = null
33855 try {
33856 this.update(chunk, encoding)
33857 } catch (err) {
33858 error = err
33859 }
33860
33861 callback(error)
33862 }
33863
33864 Shake.prototype._flush = function () {}
33865
33866 Shake.prototype._read = function (size) {
33867 this.push(this.squeeze(size))
33868 }
33869
33870 Shake.prototype.update = function (data, encoding) {
33871 if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
33872 if (this._finalized) throw new Error('Squeeze already called')
33873 if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
33874
33875 this._state.absorb(data)
33876
33877 return this
33878 }
33879
33880 Shake.prototype.squeeze = function (dataByteLength, encoding) {
33881 if (!this._finalized) {
33882 this._finalized = true
33883 this._state.absorbLastFewBits(this._delimitedSuffix)
33884 }
33885
33886 var data = this._state.squeeze(dataByteLength)
33887 if (encoding !== undefined) data = data.toString(encoding)
33888
33889 return data
33890 }
33891
33892 Shake.prototype._resetState = function () {
33893 this._state.initialize(this._rate, this._capacity)
33894 return this
33895 }
33896
33897 Shake.prototype._clone = function () {
33898 var clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options)
33899 this._state.copy(clone._state)
33900 clone._finalized = this._finalized
33901
33902 return clone
33903 }
33904
33905 return Shake
33906}
33907
33908}).call(this,require("buffer").Buffer)
33909},{"buffer":5,"inherits":63,"stream":25}],69:[function(require,module,exports){
33910'use strict'
33911var P1600_ROUND_CONSTANTS = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648]
33912
33913exports.p1600 = function (s) {
33914 for (var round = 0; round < 24; ++round) {
33915 // theta
33916 var lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]
33917 var hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]
33918 var lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]
33919 var hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]
33920 var lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]
33921 var hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]
33922 var lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]
33923 var hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]
33924 var lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]
33925 var hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]
33926
33927 var lo = lo4 ^ (lo1 << 1 | hi1 >>> 31)
33928 var hi = hi4 ^ (hi1 << 1 | lo1 >>> 31)
33929 var t1slo0 = s[0] ^ lo
33930 var t1shi0 = s[1] ^ hi
33931 var t1slo5 = s[10] ^ lo
33932 var t1shi5 = s[11] ^ hi
33933 var t1slo10 = s[20] ^ lo
33934 var t1shi10 = s[21] ^ hi
33935 var t1slo15 = s[30] ^ lo
33936 var t1shi15 = s[31] ^ hi
33937 var t1slo20 = s[40] ^ lo
33938 var t1shi20 = s[41] ^ hi
33939 lo = lo0 ^ (lo2 << 1 | hi2 >>> 31)
33940 hi = hi0 ^ (hi2 << 1 | lo2 >>> 31)
33941 var t1slo1 = s[2] ^ lo
33942 var t1shi1 = s[3] ^ hi
33943 var t1slo6 = s[12] ^ lo
33944 var t1shi6 = s[13] ^ hi
33945 var t1slo11 = s[22] ^ lo
33946 var t1shi11 = s[23] ^ hi
33947 var t1slo16 = s[32] ^ lo
33948 var t1shi16 = s[33] ^ hi
33949 var t1slo21 = s[42] ^ lo
33950 var t1shi21 = s[43] ^ hi
33951 lo = lo1 ^ (lo3 << 1 | hi3 >>> 31)
33952 hi = hi1 ^ (hi3 << 1 | lo3 >>> 31)
33953 var t1slo2 = s[4] ^ lo
33954 var t1shi2 = s[5] ^ hi
33955 var t1slo7 = s[14] ^ lo
33956 var t1shi7 = s[15] ^ hi
33957 var t1slo12 = s[24] ^ lo
33958 var t1shi12 = s[25] ^ hi
33959 var t1slo17 = s[34] ^ lo
33960 var t1shi17 = s[35] ^ hi
33961 var t1slo22 = s[44] ^ lo
33962 var t1shi22 = s[45] ^ hi
33963 lo = lo2 ^ (lo4 << 1 | hi4 >>> 31)
33964 hi = hi2 ^ (hi4 << 1 | lo4 >>> 31)
33965 var t1slo3 = s[6] ^ lo
33966 var t1shi3 = s[7] ^ hi
33967 var t1slo8 = s[16] ^ lo
33968 var t1shi8 = s[17] ^ hi
33969 var t1slo13 = s[26] ^ lo
33970 var t1shi13 = s[27] ^ hi
33971 var t1slo18 = s[36] ^ lo
33972 var t1shi18 = s[37] ^ hi
33973 var t1slo23 = s[46] ^ lo
33974 var t1shi23 = s[47] ^ hi
33975 lo = lo3 ^ (lo0 << 1 | hi0 >>> 31)
33976 hi = hi3 ^ (hi0 << 1 | lo0 >>> 31)
33977 var t1slo4 = s[8] ^ lo
33978 var t1shi4 = s[9] ^ hi
33979 var t1slo9 = s[18] ^ lo
33980 var t1shi9 = s[19] ^ hi
33981 var t1slo14 = s[28] ^ lo
33982 var t1shi14 = s[29] ^ hi
33983 var t1slo19 = s[38] ^ lo
33984 var t1shi19 = s[39] ^ hi
33985 var t1slo24 = s[48] ^ lo
33986 var t1shi24 = s[49] ^ hi
33987
33988 // rho & pi
33989 var t2slo0 = t1slo0
33990 var t2shi0 = t1shi0
33991 var t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28)
33992 var t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28)
33993 var t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29)
33994 var t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29)
33995 var t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23)
33996 var t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23)
33997 var t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14)
33998 var t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14)
33999 var t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31)
34000 var t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31)
34001 var t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20)
34002 var t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20)
34003 var t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22)
34004 var t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22)
34005 var t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19)
34006 var t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19)
34007 var t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30)
34008 var t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30)
34009 var t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2)
34010 var t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2)
34011 var t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26)
34012 var t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26)
34013 var t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21)
34014 var t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21)
34015 var t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17)
34016 var t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17)
34017 var t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3)
34018 var t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3)
34019 var t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4)
34020 var t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4)
34021 var t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9)
34022 var t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9)
34023 var t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7)
34024 var t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7)
34025 var t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11)
34026 var t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11)
34027 var t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8)
34028 var t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8)
34029 var t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5)
34030 var t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5)
34031 var t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12)
34032 var t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12)
34033 var t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25)
34034 var t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25)
34035 var t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24)
34036 var t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24)
34037 var t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18)
34038 var t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18)
34039
34040 // chi
34041 s[0] = t2slo0 ^ (~t2slo1 & t2slo2)
34042 s[1] = t2shi0 ^ (~t2shi1 & t2shi2)
34043 s[10] = t2slo5 ^ (~t2slo6 & t2slo7)
34044 s[11] = t2shi5 ^ (~t2shi6 & t2shi7)
34045 s[20] = t2slo10 ^ (~t2slo11 & t2slo12)
34046 s[21] = t2shi10 ^ (~t2shi11 & t2shi12)
34047 s[30] = t2slo15 ^ (~t2slo16 & t2slo17)
34048 s[31] = t2shi15 ^ (~t2shi16 & t2shi17)
34049 s[40] = t2slo20 ^ (~t2slo21 & t2slo22)
34050 s[41] = t2shi20 ^ (~t2shi21 & t2shi22)
34051 s[2] = t2slo1 ^ (~t2slo2 & t2slo3)
34052 s[3] = t2shi1 ^ (~t2shi2 & t2shi3)
34053 s[12] = t2slo6 ^ (~t2slo7 & t2slo8)
34054 s[13] = t2shi6 ^ (~t2shi7 & t2shi8)
34055 s[22] = t2slo11 ^ (~t2slo12 & t2slo13)
34056 s[23] = t2shi11 ^ (~t2shi12 & t2shi13)
34057 s[32] = t2slo16 ^ (~t2slo17 & t2slo18)
34058 s[33] = t2shi16 ^ (~t2shi17 & t2shi18)
34059 s[42] = t2slo21 ^ (~t2slo22 & t2slo23)
34060 s[43] = t2shi21 ^ (~t2shi22 & t2shi23)
34061 s[4] = t2slo2 ^ (~t2slo3 & t2slo4)
34062 s[5] = t2shi2 ^ (~t2shi3 & t2shi4)
34063 s[14] = t2slo7 ^ (~t2slo8 & t2slo9)
34064 s[15] = t2shi7 ^ (~t2shi8 & t2shi9)
34065 s[24] = t2slo12 ^ (~t2slo13 & t2slo14)
34066 s[25] = t2shi12 ^ (~t2shi13 & t2shi14)
34067 s[34] = t2slo17 ^ (~t2slo18 & t2slo19)
34068 s[35] = t2shi17 ^ (~t2shi18 & t2shi19)
34069 s[44] = t2slo22 ^ (~t2slo23 & t2slo24)
34070 s[45] = t2shi22 ^ (~t2shi23 & t2shi24)
34071 s[6] = t2slo3 ^ (~t2slo4 & t2slo0)
34072 s[7] = t2shi3 ^ (~t2shi4 & t2shi0)
34073 s[16] = t2slo8 ^ (~t2slo9 & t2slo5)
34074 s[17] = t2shi8 ^ (~t2shi9 & t2shi5)
34075 s[26] = t2slo13 ^ (~t2slo14 & t2slo10)
34076 s[27] = t2shi13 ^ (~t2shi14 & t2shi10)
34077 s[36] = t2slo18 ^ (~t2slo19 & t2slo15)
34078 s[37] = t2shi18 ^ (~t2shi19 & t2shi15)
34079 s[46] = t2slo23 ^ (~t2slo24 & t2slo20)
34080 s[47] = t2shi23 ^ (~t2shi24 & t2shi20)
34081 s[8] = t2slo4 ^ (~t2slo0 & t2slo1)
34082 s[9] = t2shi4 ^ (~t2shi0 & t2shi1)
34083 s[18] = t2slo9 ^ (~t2slo5 & t2slo6)
34084 s[19] = t2shi9 ^ (~t2shi5 & t2shi6)
34085 s[28] = t2slo14 ^ (~t2slo10 & t2slo11)
34086 s[29] = t2shi14 ^ (~t2shi10 & t2shi11)
34087 s[38] = t2slo19 ^ (~t2slo15 & t2slo16)
34088 s[39] = t2shi19 ^ (~t2shi15 & t2shi16)
34089 s[48] = t2slo24 ^ (~t2slo20 & t2slo21)
34090 s[49] = t2shi24 ^ (~t2shi20 & t2shi21)
34091
34092 // iota
34093 s[0] ^= P1600_ROUND_CONSTANTS[round * 2]
34094 s[1] ^= P1600_ROUND_CONSTANTS[round * 2 + 1]
34095 }
34096}
34097
34098},{}],70:[function(require,module,exports){
34099(function (Buffer){
34100'use strict'
34101var keccakState = require('./keccak-state-unroll')
34102
34103function Keccak () {
34104 // much faster than `new Array(50)`
34105 this.state = [
34106 0, 0, 0, 0, 0,
34107 0, 0, 0, 0, 0,
34108 0, 0, 0, 0, 0,
34109 0, 0, 0, 0, 0,
34110 0, 0, 0, 0, 0
34111 ]
34112
34113 this.blockSize = null
34114 this.count = 0
34115 this.squeezing = false
34116}
34117
34118Keccak.prototype.initialize = function (rate, capacity) {
34119 for (var i = 0; i < 50; ++i) this.state[i] = 0
34120 this.blockSize = rate / 8
34121 this.count = 0
34122 this.squeezing = false
34123}
34124
34125Keccak.prototype.absorb = function (data) {
34126 for (var i = 0; i < data.length; ++i) {
34127 this.state[~~(this.count / 4)] ^= data[i] << (8 * (this.count % 4))
34128 this.count += 1
34129 if (this.count === this.blockSize) {
34130 keccakState.p1600(this.state)
34131 this.count = 0
34132 }
34133 }
34134}
34135
34136Keccak.prototype.absorbLastFewBits = function (bits) {
34137 this.state[~~(this.count / 4)] ^= bits << (8 * (this.count % 4))
34138 if ((bits & 0x80) !== 0 && this.count === (this.blockSize - 1)) keccakState.p1600(this.state)
34139 this.state[~~((this.blockSize - 1) / 4)] ^= 0x80 << (8 * ((this.blockSize - 1) % 4))
34140 keccakState.p1600(this.state)
34141 this.count = 0
34142 this.squeezing = true
34143}
34144
34145Keccak.prototype.squeeze = function (length) {
34146 if (!this.squeezing) this.absorbLastFewBits(0x01)
34147
34148 var output = Buffer.allocUnsafe(length)
34149 for (var i = 0; i < length; ++i) {
34150 output[i] = (this.state[~~(this.count / 4)] >>> (8 * (this.count % 4))) & 0xff
34151 this.count += 1
34152 if (this.count === this.blockSize) {
34153 keccakState.p1600(this.state)
34154 this.count = 0
34155 }
34156 }
34157
34158 return output
34159}
34160
34161Keccak.prototype.copy = function (dest) {
34162 for (var i = 0; i < 50; ++i) dest.state[i] = this.state[i]
34163 dest.blockSize = this.blockSize
34164 dest.count = this.count
34165 dest.squeezing = this.squeezing
34166}
34167
34168module.exports = Keccak
34169
34170}).call(this,require("buffer").Buffer)
34171},{"./keccak-state-unroll":69,"buffer":5}],71:[function(require,module,exports){
34172(function (Buffer){
34173/*
34174CryptoJS v3.1.2
34175code.google.com/p/crypto-js
34176(c) 2009-2013 by Jeff Mott. All rights reserved.
34177code.google.com/p/crypto-js/wiki/License
34178*/
34179/** @preserve
34180(c) 2012 by Cédric Mesnil. All rights reserved.
34181
34182Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
34183
34184 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
34185 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
34186
34187THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34188*/
34189
34190// constants table
34191var zl = [
34192 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
34193 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
34194 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
34195 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
34196 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
34197]
34198
34199var zr = [
34200 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
34201 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
34202 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
34203 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
34204 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
34205]
34206
34207var sl = [
34208 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
34209 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
34210 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
34211 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
34212 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
34213]
34214
34215var sr = [
34216 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
34217 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
34218 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
34219 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
34220 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
34221]
34222
34223var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]
34224var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]
34225
34226function bytesToWords (bytes) {
34227 var words = []
34228 for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
34229 words[b >>> 5] |= bytes[i] << (24 - b % 32)
34230 }
34231 return words
34232}
34233
34234function wordsToBytes (words) {
34235 var bytes = []
34236 for (var b = 0; b < words.length * 32; b += 8) {
34237 bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF)
34238 }
34239 return bytes
34240}
34241
34242function processBlock (H, M, offset) {
34243 // swap endian
34244 for (var i = 0; i < 16; i++) {
34245 var offset_i = offset + i
34246 var M_offset_i = M[offset_i]
34247
34248 // Swap
34249 M[offset_i] = (
34250 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
34251 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
34252 )
34253 }
34254
34255 // Working variables
34256 var al, bl, cl, dl, el
34257 var ar, br, cr, dr, er
34258
34259 ar = al = H[0]
34260 br = bl = H[1]
34261 cr = cl = H[2]
34262 dr = dl = H[3]
34263 er = el = H[4]
34264
34265 // computation
34266 var t
34267 for (i = 0; i < 80; i += 1) {
34268 t = (al + M[offset + zl[i]]) | 0
34269 if (i < 16) {
34270 t += f1(bl, cl, dl) + hl[0]
34271 } else if (i < 32) {
34272 t += f2(bl, cl, dl) + hl[1]
34273 } else if (i < 48) {
34274 t += f3(bl, cl, dl) + hl[2]
34275 } else if (i < 64) {
34276 t += f4(bl, cl, dl) + hl[3]
34277 } else {// if (i<80) {
34278 t += f5(bl, cl, dl) + hl[4]
34279 }
34280 t = t | 0
34281 t = rotl(t, sl[i])
34282 t = (t + el) | 0
34283 al = el
34284 el = dl
34285 dl = rotl(cl, 10)
34286 cl = bl
34287 bl = t
34288
34289 t = (ar + M[offset + zr[i]]) | 0
34290 if (i < 16) {
34291 t += f5(br, cr, dr) + hr[0]
34292 } else if (i < 32) {
34293 t += f4(br, cr, dr) + hr[1]
34294 } else if (i < 48) {
34295 t += f3(br, cr, dr) + hr[2]
34296 } else if (i < 64) {
34297 t += f2(br, cr, dr) + hr[3]
34298 } else {// if (i<80) {
34299 t += f1(br, cr, dr) + hr[4]
34300 }
34301
34302 t = t | 0
34303 t = rotl(t, sr[i])
34304 t = (t + er) | 0
34305 ar = er
34306 er = dr
34307 dr = rotl(cr, 10)
34308 cr = br
34309 br = t
34310 }
34311
34312 // intermediate hash value
34313 t = (H[1] + cl + dr) | 0
34314 H[1] = (H[2] + dl + er) | 0
34315 H[2] = (H[3] + el + ar) | 0
34316 H[3] = (H[4] + al + br) | 0
34317 H[4] = (H[0] + bl + cr) | 0
34318 H[0] = t
34319}
34320
34321function f1 (x, y, z) {
34322 return ((x) ^ (y) ^ (z))
34323}
34324
34325function f2 (x, y, z) {
34326 return (((x) & (y)) | ((~x) & (z)))
34327}
34328
34329function f3 (x, y, z) {
34330 return (((x) | (~(y))) ^ (z))
34331}
34332
34333function f4 (x, y, z) {
34334 return (((x) & (z)) | ((y) & (~(z))))
34335}
34336
34337function f5 (x, y, z) {
34338 return ((x) ^ ((y) | (~(z))))
34339}
34340
34341function rotl (x, n) {
34342 return (x << n) | (x >>> (32 - n))
34343}
34344
34345function ripemd160 (message) {
34346 var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
34347
34348 if (typeof message === 'string') {
34349 message = new Buffer(message, 'utf8')
34350 }
34351
34352 var m = bytesToWords(message)
34353
34354 var nBitsLeft = message.length * 8
34355 var nBitsTotal = message.length * 8
34356
34357 // Add padding
34358 m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32)
34359 m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
34360 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
34361 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
34362 )
34363
34364 for (var i = 0; i < m.length; i += 16) {
34365 processBlock(H, m, i)
34366 }
34367
34368 // swap endian
34369 for (i = 0; i < 5; i++) {
34370 // shortcut
34371 var H_i = H[i]
34372
34373 // Swap
34374 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
34375 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00)
34376 }
34377
34378 var digestbytes = wordsToBytes(H)
34379 return new Buffer(digestbytes)
34380}
34381
34382module.exports = ripemd160
34383
34384}).call(this,require("buffer").Buffer)
34385},{"buffer":5}],72:[function(require,module,exports){
34386(function (Buffer){
34387const assert = require('assert')
34388/**
34389 * RLP Encoding based on: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP
34390 * This function takes in a data, convert it to buffer if not, and a length for recursion
34391 *
34392 * @param {Buffer,String,Integer,Array} data - will be converted to buffer
34393 * @returns {Buffer} - returns buffer of encoded data
34394 **/
34395exports.encode = function (input) {
34396 if (input instanceof Array) {
34397 var output = []
34398 for (var i = 0; i < input.length; i++) {
34399 output.push(exports.encode(input[i]))
34400 }
34401 var buf = Buffer.concat(output)
34402 return Buffer.concat([encodeLength(buf.length, 192), buf])
34403 } else {
34404 input = toBuffer(input)
34405 if (input.length === 1 && input[0] < 128) {
34406 return input
34407 } else {
34408 return Buffer.concat([encodeLength(input.length, 128), input])
34409 }
34410 }
34411}
34412
34413function safeParseInt (v, base) {
34414 if (v.slice(0, 2) === '00') {
34415 throw (new Error('invalid RLP: extra zeros'))
34416 }
34417
34418 return parseInt(v, base)
34419}
34420
34421function encodeLength (len, offset) {
34422 if (len < 56) {
34423 return new Buffer([len + offset])
34424 } else {
34425 var hexLength = intToHex(len)
34426 var lLength = hexLength.length / 2
34427 var firstByte = intToHex(offset + 55 + lLength)
34428 return new Buffer(firstByte + hexLength, 'hex')
34429 }
34430}
34431
34432/**
34433 * RLP Decoding based on: {@link https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP|RLP}
34434 * @param {Buffer,String,Integer,Array} data - will be converted to buffer
34435 * @returns {Array} - returns decode Array of Buffers containg the original message
34436 **/
34437exports.decode = function (input, stream) {
34438 if (!input || input.length === 0) {
34439 return new Buffer([])
34440 }
34441
34442 input = toBuffer(input)
34443 var decoded = _decode(input)
34444
34445 if (stream) {
34446 return decoded
34447 }
34448
34449 assert.equal(decoded.remainder.length, 0, 'invalid remainder')
34450 return decoded.data
34451}
34452
34453exports.getLength = function (input) {
34454 if (!input || input.length === 0) {
34455 return new Buffer([])
34456 }
34457
34458 input = toBuffer(input)
34459 var firstByte = input[0]
34460 if (firstByte <= 0x7f) {
34461 return input.length
34462 } else if (firstByte <= 0xb7) {
34463 return firstByte - 0x7f
34464 } else if (firstByte <= 0xbf) {
34465 return firstByte - 0xb6
34466 } else if (firstByte <= 0xf7) {
34467 // a list between 0-55 bytes long
34468 return firstByte - 0xbf
34469 } else {
34470 // a list over 55 bytes long
34471 var llength = firstByte - 0xf6
34472 var length = safeParseInt(input.slice(1, llength).toString('hex'), 16)
34473 return llength + length
34474 }
34475}
34476
34477function _decode (input) {
34478 var length, llength, data, innerRemainder, d
34479 var decoded = []
34480 var firstByte = input[0]
34481
34482 if (firstByte <= 0x7f) {
34483 // a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.
34484 return {
34485 data: input.slice(0, 1),
34486 remainder: input.slice(1)
34487 }
34488 } else if (firstByte <= 0xb7) {
34489 // string is 0-55 bytes long. A single byte with value 0x80 plus the length of the string followed by the string
34490 // The range of the first byte is [0x80, 0xb7]
34491 length = firstByte - 0x7f
34492
34493 // set 0x80 null to 0
34494 if (firstByte === 0x80) {
34495 data = new Buffer([])
34496 } else {
34497 data = input.slice(1, length)
34498 }
34499
34500 if (length === 2 && data[0] < 0x80) {
34501 throw new Error('invalid rlp encoding: byte must be less 0x80')
34502 }
34503
34504 return {
34505 data: data,
34506 remainder: input.slice(length)
34507 }
34508 } else if (firstByte <= 0xbf) {
34509 llength = firstByte - 0xb6
34510 length = safeParseInt(input.slice(1, llength).toString('hex'), 16)
34511 data = input.slice(llength, length + llength)
34512 if (data.length < length) {
34513 throw (new Error('invalid RLP'))
34514 }
34515
34516 return {
34517 data: data,
34518 remainder: input.slice(length + llength)
34519 }
34520 } else if (firstByte <= 0xf7) {
34521 // a list between 0-55 bytes long
34522 length = firstByte - 0xbf
34523 innerRemainder = input.slice(1, length)
34524 while (innerRemainder.length) {
34525 d = _decode(innerRemainder)
34526 decoded.push(d.data)
34527 innerRemainder = d.remainder
34528 }
34529
34530 return {
34531 data: decoded,
34532 remainder: input.slice(length)
34533 }
34534 } else {
34535 // a list over 55 bytes long
34536 llength = firstByte - 0xf6
34537 length = safeParseInt(input.slice(1, llength).toString('hex'), 16)
34538 var totalLength = llength + length
34539 if (totalLength > input.length) {
34540 throw new Error('invalid rlp: total length is larger than the data')
34541 }
34542
34543 innerRemainder = input.slice(llength, totalLength)
34544 if (innerRemainder.length === 0) {
34545 throw new Error('invalid rlp, List has a invalid length')
34546 }
34547
34548 while (innerRemainder.length) {
34549 d = _decode(innerRemainder)
34550 decoded.push(d.data)
34551 innerRemainder = d.remainder
34552 }
34553 return {
34554 data: decoded,
34555 remainder: input.slice(totalLength)
34556 }
34557 }
34558}
34559
34560function isHexPrefixed (str) {
34561 return str.slice(0, 2) === '0x'
34562}
34563
34564// Removes 0x from a given String
34565function stripHexPrefix (str) {
34566 if (typeof str !== 'string') {
34567 return str
34568 }
34569 return isHexPrefixed(str) ? str.slice(2) : str
34570}
34571
34572function intToHex (i) {
34573 var hex = i.toString(16)
34574 if (hex.length % 2) {
34575 hex = '0' + hex
34576 }
34577
34578 return hex
34579}
34580
34581function padToEven (a) {
34582 if (a.length % 2) a = '0' + a
34583 return a
34584}
34585
34586function intToBuffer (i) {
34587 var hex = intToHex(i)
34588 return new Buffer(hex, 'hex')
34589}
34590
34591function toBuffer (v) {
34592 if (!Buffer.isBuffer(v)) {
34593 if (typeof v === 'string') {
34594 if (isHexPrefixed(v)) {
34595 v = new Buffer(padToEven(stripHexPrefix(v)), 'hex')
34596 } else {
34597 v = new Buffer(v)
34598 }
34599 } else if (typeof v === 'number') {
34600 if (!v) {
34601 v = new Buffer([])
34602 } else {
34603 v = intToBuffer(v)
34604 }
34605 } else if (v === null || v === undefined) {
34606 v = new Buffer([])
34607 } else if (v.toArray) {
34608 // converts a BN to a Buffer
34609 v = new Buffer(v.toArray())
34610 } else {
34611 throw new Error('invalid type')
34612 }
34613 }
34614 return v
34615}
34616
34617}).call(this,require("buffer").Buffer)
34618},{"assert":1,"buffer":5}],73:[function(require,module,exports){
34619'use strict'
34620module.exports = require('./lib')(require('./lib/elliptic'))
34621
34622},{"./lib":77,"./lib/elliptic":76}],74:[function(require,module,exports){
34623(function (Buffer){
34624'use strict'
34625var toString = Object.prototype.toString
34626
34627// TypeError
34628exports.isArray = function (value, message) {
34629 if (!Array.isArray(value)) throw TypeError(message)
34630}
34631
34632exports.isBoolean = function (value, message) {
34633 if (toString.call(value) !== '[object Boolean]') throw TypeError(message)
34634}
34635
34636exports.isBuffer = function (value, message) {
34637 if (!Buffer.isBuffer(value)) throw TypeError(message)
34638}
34639
34640exports.isFunction = function (value, message) {
34641 if (toString.call(value) !== '[object Function]') throw TypeError(message)
34642}
34643
34644exports.isNumber = function (value, message) {
34645 if (toString.call(value) !== '[object Number]') throw TypeError(message)
34646}
34647
34648exports.isObject = function (value, message) {
34649 if (toString.call(value) !== '[object Object]') throw TypeError(message)
34650}
34651
34652// RangeError
34653exports.isBufferLength = function (buffer, length, message) {
34654 if (buffer.length !== length) throw RangeError(message)
34655}
34656
34657exports.isBufferLength2 = function (buffer, length1, length2, message) {
34658 if (buffer.length !== length1 && buffer.length !== length2) throw RangeError(message)
34659}
34660
34661exports.isLengthGTZero = function (value, message) {
34662 if (value.length === 0) throw RangeError(message)
34663}
34664
34665exports.isNumberInInterval = function (number, x, y, message) {
34666 if (number <= x || number >= y) throw RangeError(message)
34667}
34668
34669}).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v7.5.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
34670},{"../../../../../.nvm/versions/node/v7.5.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10}],75:[function(require,module,exports){
34671(function (Buffer){
34672'use strict'
34673var bip66 = require('bip66')
34674
34675var EC_PRIVKEY_EXPORT_DER_COMPRESSED = new Buffer([
34676 // begin
34677 0x30, 0x81, 0xd3, 0x02, 0x01, 0x01, 0x04, 0x20,
34678 // private key
34679 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34680 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34681 // middle
34682 0xa0, 0x81, 0x85, 0x30, 0x81, 0x82, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48,
34683 0xcE, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34684 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34685 0xff, 0xff, 0xfE, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04,
34686 0x21, 0x02, 0x79, 0xbE, 0x66, 0x7E, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xcE, 0x87,
34687 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xcE, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8,
34688 0x17, 0x98, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34689 0xff, 0xff, 0xff, 0xff, 0xfE, 0xba, 0xaE, 0xdc, 0xE6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5E,
34690 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0xa1, 0x24, 0x03, 0x22, 0x00,
34691 // public key
34692 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34693 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34694 0x00
34695])
34696
34697var EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED = new Buffer([
34698 // begin
34699 0x30, 0x82, 0x01, 0x13, 0x02, 0x01, 0x01, 0x04, 0x20,
34700 // private key
34701 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34702 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34703 // middle
34704 0xa0, 0x81, 0xa5, 0x30, 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48,
34705 0xcE, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34706 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34707 0xff, 0xff, 0xfE, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04,
34708 0x41, 0x04, 0x79, 0xbE, 0x66, 0x7E, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xcE, 0x87,
34709 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xcE, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8,
34710 0x17, 0x98, 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0E, 0x11,
34711 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10,
34712 0xd4, 0xb8, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34713 0xff, 0xff, 0xff, 0xff, 0xfE, 0xba, 0xaE, 0xdc, 0xE6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5E,
34714 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0xa1, 0x44, 0x03, 0x42, 0x00,
34715 // public key
34716 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34717 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34718 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34719 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34720 0x00
34721])
34722
34723var ZERO_BUFFER_32 = new Buffer([
34724 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34725 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
34726])
34727
34728exports.privateKeyExport = function (privateKey, publicKey, compressed) {
34729 var result = new Buffer(compressed ? EC_PRIVKEY_EXPORT_DER_COMPRESSED : EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED)
34730 privateKey.copy(result, compressed ? 8 : 9)
34731 publicKey.copy(result, compressed ? 181 : 214)
34732 return result
34733}
34734
34735exports.privateKeyImport = function (privateKey) {
34736 var length = privateKey.length
34737
34738 // sequence header
34739 var index = 0
34740 if (length < index + 1 || privateKey[index] !== 0x30) return
34741 index += 1
34742
34743 // sequence length constructor
34744 if (length < index + 1 || !(privateKey[index] & 0x80)) return
34745
34746 var lenb = privateKey[index] & 0x7f
34747 index += 1
34748 if (lenb < 1 || lenb > 2) return
34749 if (length < index + lenb) return
34750
34751 // sequence length
34752 var len = privateKey[index + lenb - 1] | (lenb > 1 ? privateKey[index + lenb - 2] << 8 : 0)
34753 index += lenb
34754 if (length < index + len) return
34755
34756 // sequence element 0: version number (=1)
34757 if (length < index + 3 ||
34758 privateKey[index] !== 0x02 ||
34759 privateKey[index + 1] !== 0x01 ||
34760 privateKey[index + 2] !== 0x01) {
34761 return
34762 }
34763 index += 3
34764
34765 // sequence element 1: octet string, up to 32 bytes
34766 if (length < index + 2 ||
34767 privateKey[index] !== 0x04 ||
34768 privateKey[index + 1] > 0x20 ||
34769 length < index + 2 + privateKey[index + 1]) {
34770 return
34771 }
34772
34773 return privateKey.slice(index + 2, index + 2 + privateKey[index + 1])
34774}
34775
34776exports.signatureExport = function (sigObj) {
34777 var r = Buffer.concat([new Buffer([0]), sigObj.r])
34778 for (var lenR = 33, posR = 0; lenR > 1 && r[posR] === 0x00 && !(r[posR + 1] & 0x80); --lenR, ++posR);
34779
34780 var s = Buffer.concat([new Buffer([0]), sigObj.s])
34781 for (var lenS = 33, posS = 0; lenS > 1 && s[posS] === 0x00 && !(s[posS + 1] & 0x80); --lenS, ++posS);
34782
34783 return bip66.encode(r.slice(posR), s.slice(posS))
34784}
34785
34786exports.signatureImport = function (sig) {
34787 var r = new Buffer(ZERO_BUFFER_32)
34788 var s = new Buffer(ZERO_BUFFER_32)
34789
34790 try {
34791 var sigObj = bip66.decode(sig)
34792 if (sigObj.r.length === 33 && sigObj.r[0] === 0x00) sigObj.r = sigObj.r.slice(1)
34793 if (sigObj.r.length > 32) throw new Error('R length is too long')
34794 if (sigObj.s.length === 33 && sigObj.s[0] === 0x00) sigObj.s = sigObj.s.slice(1)
34795 if (sigObj.s.length > 32) throw new Error('S length is too long')
34796 } catch (err) {
34797 return
34798 }
34799
34800 sigObj.r.copy(r, 32 - sigObj.r.length)
34801 sigObj.s.copy(s, 32 - sigObj.s.length)
34802
34803 return { r: r, s: s }
34804}
34805
34806exports.signatureImportLax = function (sig) {
34807 var r = new Buffer(ZERO_BUFFER_32)
34808 var s = new Buffer(ZERO_BUFFER_32)
34809
34810 var length = sig.length
34811 var index = 0
34812
34813 // sequence tag byte
34814 if (sig[index++] !== 0x30) return
34815
34816 // sequence length byte
34817 var lenbyte = sig[index++]
34818 if (lenbyte & 0x80) {
34819 index += lenbyte - 0x80
34820 if (index > length) return
34821 }
34822
34823 // sequence tag byte for r
34824 if (sig[index++] !== 0x02) return
34825
34826 // length for r
34827 var rlen = sig[index++]
34828 if (rlen & 0x80) {
34829 lenbyte = rlen - 0x80
34830 if (index + lenbyte > length) return
34831 for (; lenbyte > 0 && sig[index] === 0x00; index += 1, lenbyte -= 1);
34832 for (rlen = 0; lenbyte > 0; index += 1, lenbyte -= 1) rlen = (rlen << 8) + sig[index]
34833 }
34834 if (rlen > length - index) return
34835 var rindex = index
34836 index += rlen
34837
34838 // sequence tag byte for s
34839 if (sig[index++] !== 0x02) return
34840
34841 // length for s
34842 var slen = sig[index++]
34843 if (slen & 0x80) {
34844 lenbyte = slen - 0x80
34845 if (index + lenbyte > length) return
34846 for (; lenbyte > 0 && sig[index] === 0x00; index += 1, lenbyte -= 1);
34847 for (slen = 0; lenbyte > 0; index += 1, lenbyte -= 1) slen = (slen << 8) + sig[index]
34848 }
34849 if (slen > length - index) return
34850 var sindex = index
34851 index += slen
34852
34853 // ignore leading zeros in r
34854 for (; rlen > 0 && sig[rindex] === 0x00; rlen -= 1, rindex += 1);
34855 // copy r value
34856 if (rlen > 32) return
34857 var rvalue = sig.slice(rindex, rindex + rlen)
34858 rvalue.copy(r, 32 - rvalue.length)
34859
34860 // ignore leading zeros in s
34861 for (; slen > 0 && sig[sindex] === 0x00; slen -= 1, sindex += 1);
34862 // copy s value
34863 if (slen > 32) return
34864 var svalue = sig.slice(sindex, sindex + slen)
34865 svalue.copy(s, 32 - svalue.length)
34866
34867 return { r: r, s: s }
34868}
34869
34870}).call(this,require("buffer").Buffer)
34871},{"bip66":32,"buffer":5}],76:[function(require,module,exports){
34872(function (Buffer){
34873'use strict'
34874var createHash = require('create-hash')
34875var BN = require('bn.js')
34876var EC = require('elliptic').ec
34877
34878var messages = require('../messages.json')
34879
34880var ec = new EC('secp256k1')
34881var ecparams = ec.curve
34882
34883function loadCompressedPublicKey (first, xBuffer) {
34884 var x = new BN(xBuffer)
34885
34886 // overflow
34887 if (x.cmp(ecparams.p) >= 0) return null
34888 x = x.toRed(ecparams.red)
34889
34890 // compute corresponding Y
34891 var y = x.redSqr().redIMul(x).redIAdd(ecparams.b).redSqrt()
34892 if ((first === 0x03) !== y.isOdd()) y = y.redNeg()
34893
34894 return ec.keyPair({ pub: { x: x, y: y } })
34895}
34896
34897function loadUncompressedPublicKey (first, xBuffer, yBuffer) {
34898 var x = new BN(xBuffer)
34899 var y = new BN(yBuffer)
34900
34901 // overflow
34902 if (x.cmp(ecparams.p) >= 0 || y.cmp(ecparams.p) >= 0) return null
34903
34904 x = x.toRed(ecparams.red)
34905 y = y.toRed(ecparams.red)
34906
34907 // is odd flag
34908 if ((first === 0x06 || first === 0x07) && y.isOdd() !== (first === 0x07)) return null
34909
34910 // x*x*x + b = y*y
34911 var x3 = x.redSqr().redIMul(x)
34912 if (!y.redSqr().redISub(x3.redIAdd(ecparams.b)).isZero()) return null
34913
34914 return ec.keyPair({ pub: { x: x, y: y } })
34915}
34916
34917function loadPublicKey (publicKey) {
34918 var first = publicKey[0]
34919 switch (first) {
34920 case 0x02:
34921 case 0x03:
34922 if (publicKey.length !== 33) return null
34923 return loadCompressedPublicKey(first, publicKey.slice(1, 33))
34924 case 0x04:
34925 case 0x06:
34926 case 0x07:
34927 if (publicKey.length !== 65) return null
34928 return loadUncompressedPublicKey(first, publicKey.slice(1, 33), publicKey.slice(33, 65))
34929 default:
34930 return null
34931 }
34932}
34933
34934exports.privateKeyVerify = function (privateKey) {
34935 var bn = new BN(privateKey)
34936 return bn.cmp(ecparams.n) < 0 && !bn.isZero()
34937}
34938
34939exports.privateKeyExport = function (privateKey, compressed) {
34940 var d = new BN(privateKey)
34941 if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.EC_PRIVATE_KEY_EXPORT_DER_FAIL)
34942
34943 return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
34944}
34945
34946exports.privateKeyTweakAdd = function (privateKey, tweak) {
34947 var bn = new BN(tweak)
34948 if (bn.cmp(ecparams.n) >= 0) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_ADD_FAIL)
34949
34950 bn.iadd(new BN(privateKey))
34951 if (bn.cmp(ecparams.n) >= 0) bn.isub(ecparams.n)
34952 if (bn.isZero()) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_ADD_FAIL)
34953
34954 return bn.toArrayLike(Buffer, 'be', 32)
34955}
34956
34957exports.privateKeyTweakMul = function (privateKey, tweak) {
34958 var bn = new BN(tweak)
34959 if (bn.cmp(ecparams.n) >= 0 || bn.isZero()) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_MUL_FAIL)
34960
34961 bn.imul(new BN(privateKey))
34962 if (bn.cmp(ecparams.n)) bn = bn.umod(ecparams.n)
34963
34964 return bn.toArrayLike(Buffer, 'be', 32)
34965}
34966
34967exports.publicKeyCreate = function (privateKey, compressed) {
34968 var d = new BN(privateKey)
34969 if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.EC_PUBLIC_KEY_CREATE_FAIL)
34970
34971 return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true))
34972}
34973
34974exports.publicKeyConvert = function (publicKey, compressed) {
34975 var pair = loadPublicKey(publicKey)
34976 if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
34977
34978 return new Buffer(pair.getPublic(compressed, true))
34979}
34980
34981exports.publicKeyVerify = function (publicKey) {
34982 return loadPublicKey(publicKey) !== null
34983}
34984
34985exports.publicKeyTweakAdd = function (publicKey, tweak, compressed) {
34986 var pair = loadPublicKey(publicKey)
34987 if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
34988
34989 tweak = new BN(tweak)
34990 if (tweak.cmp(ecparams.n) >= 0) throw new Error(messages.EC_PUBLIC_KEY_TWEAK_ADD_FAIL)
34991
34992 return new Buffer(ecparams.g.mul(tweak).add(pair.pub).encode(true, compressed))
34993}
34994
34995exports.publicKeyTweakMul = function (publicKey, tweak, compressed) {
34996 var pair = loadPublicKey(publicKey)
34997 if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
34998
34999 tweak = new BN(tweak)
35000 if (tweak.cmp(ecparams.n) >= 0 || tweak.isZero()) throw new Error(messages.EC_PUBLIC_KEY_TWEAK_MUL_FAIL)
35001
35002 return new Buffer(pair.pub.mul(tweak).encode(true, compressed))
35003}
35004
35005exports.publicKeyCombine = function (publicKeys, compressed) {
35006 var pairs = new Array(publicKeys.length)
35007 for (var i = 0; i < publicKeys.length; ++i) {
35008 pairs[i] = loadPublicKey(publicKeys[i])
35009 if (pairs[i] === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
35010 }
35011
35012 var point = pairs[0].pub
35013 for (var j = 1; j < pairs.length; ++j) point = point.add(pairs[j].pub)
35014 if (point.isInfinity()) throw new Error(messages.EC_PUBLIC_KEY_COMBINE_FAIL)
35015
35016 return new Buffer(point.encode(true, compressed))
35017}
35018
35019exports.signatureNormalize = function (signature) {
35020 var r = new BN(signature.slice(0, 32))
35021 var s = new BN(signature.slice(32, 64))
35022 if (r.cmp(ecparams.n) >= 0 || s.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL)
35023
35024 var result = new Buffer(signature)
35025 if (s.cmp(ec.nh) === 1) ecparams.n.sub(s).toArrayLike(Buffer, 'be', 32).copy(result, 32)
35026
35027 return result
35028}
35029
35030exports.signatureExport = function (signature) {
35031 var r = signature.slice(0, 32)
35032 var s = signature.slice(32, 64)
35033 if (new BN(r).cmp(ecparams.n) >= 0 || new BN(s).cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL)
35034
35035 return { r: r, s: s }
35036}
35037
35038exports.signatureImport = function (sigObj) {
35039 var r = new BN(sigObj.r)
35040 if (r.cmp(ecparams.n) >= 0) r = new BN(0)
35041
35042 var s = new BN(sigObj.s)
35043 if (s.cmp(ecparams.n) >= 0) s = new BN(0)
35044
35045 return Buffer.concat([
35046 r.toArrayLike(Buffer, 'be', 32),
35047 s.toArrayLike(Buffer, 'be', 32)
35048 ])
35049}
35050
35051exports.sign = function (message, privateKey, noncefn, data) {
35052 if (typeof noncefn === 'function') {
35053 var getNonce = noncefn
35054 noncefn = function (counter) {
35055 var nonce = getNonce(message, privateKey, null, data, counter)
35056 if (!Buffer.isBuffer(nonce) || nonce.length !== 32) throw new Error(messages.ECDSA_SIGN_FAIL)
35057
35058 return new BN(nonce)
35059 }
35060 }
35061
35062 var d = new BN(privateKey)
35063 if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.ECDSA_SIGN_FAIL)
35064
35065 var result = ec.sign(message, privateKey, { canonical: true, k: noncefn, pers: data })
35066 return {
35067 signature: Buffer.concat([
35068 result.r.toArrayLike(Buffer, 'be', 32),
35069 result.s.toArrayLike(Buffer, 'be', 32)
35070 ]),
35071 recovery: result.recoveryParam
35072 }
35073}
35074
35075exports.verify = function (message, signature, publicKey) {
35076 var sigObj = {r: signature.slice(0, 32), s: signature.slice(32, 64)}
35077
35078 var sigr = new BN(sigObj.r)
35079 var sigs = new BN(sigObj.s)
35080 if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL)
35081 if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return false
35082
35083 var pair = loadPublicKey(publicKey)
35084 if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
35085
35086 return ec.verify(message, sigObj, {x: pair.pub.x, y: pair.pub.y})
35087}
35088
35089exports.recover = function (message, signature, recovery, compressed) {
35090 var sigObj = {r: signature.slice(0, 32), s: signature.slice(32, 64)}
35091
35092 var sigr = new BN(sigObj.r)
35093 var sigs = new BN(sigObj.s)
35094 if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL)
35095
35096 try {
35097 if (sigr.isZero() || sigs.isZero()) throw new Error()
35098
35099 var point = ec.recoverPubKey(message, sigObj, recovery)
35100 return new Buffer(point.encode(true, compressed))
35101 } catch (err) {
35102 throw new Error(messages.ECDSA_RECOVER_FAIL)
35103 }
35104}
35105
35106exports.ecdh = function (publicKey, privateKey) {
35107 var shared = exports.ecdhUnsafe(publicKey, privateKey, true)
35108 return createHash('sha256').update(shared).digest()
35109}
35110
35111exports.ecdhUnsafe = function (publicKey, privateKey, compressed) {
35112 var pair = loadPublicKey(publicKey)
35113 if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL)
35114
35115 var scalar = new BN(privateKey)
35116 if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) throw new Error(messages.ECDH_FAIL)
35117
35118 return new Buffer(pair.pub.mul(scalar).encode(true, compressed))
35119}
35120
35121}).call(this,require("buffer").Buffer)
35122},{"../messages.json":78,"bn.js":33,"buffer":5,"create-hash":36,"elliptic":39}],77:[function(require,module,exports){
35123'use strict'
35124var assert = require('./assert')
35125var der = require('./der')
35126var messages = require('./messages.json')
35127
35128function initCompressedValue (value, defaultValue) {
35129 if (value === undefined) return defaultValue
35130
35131 assert.isBoolean(value, messages.COMPRESSED_TYPE_INVALID)
35132 return value
35133}
35134
35135module.exports = function (secp256k1) {
35136 return {
35137 privateKeyVerify: function (privateKey) {
35138 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35139 return privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)
35140 },
35141
35142 privateKeyExport: function (privateKey, compressed) {
35143 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35144 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35145
35146 compressed = initCompressedValue(compressed, true)
35147 var publicKey = secp256k1.privateKeyExport(privateKey, compressed)
35148
35149 return der.privateKeyExport(privateKey, publicKey, compressed)
35150 },
35151
35152 privateKeyImport: function (privateKey) {
35153 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35154
35155 privateKey = der.privateKeyImport(privateKey)
35156 if (privateKey && privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)) return privateKey
35157
35158 throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL)
35159 },
35160
35161 privateKeyTweakAdd: function (privateKey, tweak) {
35162 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35163 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35164
35165 assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
35166 assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
35167
35168 return secp256k1.privateKeyTweakAdd(privateKey, tweak)
35169 },
35170
35171 privateKeyTweakMul: function (privateKey, tweak) {
35172 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35173 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35174
35175 assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
35176 assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
35177
35178 return secp256k1.privateKeyTweakMul(privateKey, tweak)
35179 },
35180
35181 publicKeyCreate: function (privateKey, compressed) {
35182 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35183 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35184
35185 compressed = initCompressedValue(compressed, true)
35186
35187 return secp256k1.publicKeyCreate(privateKey, compressed)
35188 },
35189
35190 publicKeyConvert: function (publicKey, compressed) {
35191 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35192 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35193
35194 compressed = initCompressedValue(compressed, true)
35195
35196 return secp256k1.publicKeyConvert(publicKey, compressed)
35197 },
35198
35199 publicKeyVerify: function (publicKey) {
35200 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35201 return secp256k1.publicKeyVerify(publicKey)
35202 },
35203
35204 publicKeyTweakAdd: function (publicKey, tweak, compressed) {
35205 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35206 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35207
35208 assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
35209 assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
35210
35211 compressed = initCompressedValue(compressed, true)
35212
35213 return secp256k1.publicKeyTweakAdd(publicKey, tweak, compressed)
35214 },
35215
35216 publicKeyTweakMul: function (publicKey, tweak, compressed) {
35217 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35218 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35219
35220 assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
35221 assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
35222
35223 compressed = initCompressedValue(compressed, true)
35224
35225 return secp256k1.publicKeyTweakMul(publicKey, tweak, compressed)
35226 },
35227
35228 publicKeyCombine: function (publicKeys, compressed) {
35229 assert.isArray(publicKeys, messages.EC_PUBLIC_KEYS_TYPE_INVALID)
35230 assert.isLengthGTZero(publicKeys, messages.EC_PUBLIC_KEYS_LENGTH_INVALID)
35231 for (var i = 0; i < publicKeys.length; ++i) {
35232 assert.isBuffer(publicKeys[i], messages.EC_PUBLIC_KEY_TYPE_INVALID)
35233 assert.isBufferLength2(publicKeys[i], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35234 }
35235
35236 compressed = initCompressedValue(compressed, true)
35237
35238 return secp256k1.publicKeyCombine(publicKeys, compressed)
35239 },
35240
35241 signatureNormalize: function (signature) {
35242 assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35243 assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35244
35245 return secp256k1.signatureNormalize(signature)
35246 },
35247
35248 signatureExport: function (signature) {
35249 assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35250 assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35251
35252 var sigObj = secp256k1.signatureExport(signature)
35253 return der.signatureExport(sigObj)
35254 },
35255
35256 signatureImport: function (sig) {
35257 assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35258 assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35259
35260 var sigObj = der.signatureImport(sig)
35261 if (sigObj) return secp256k1.signatureImport(sigObj)
35262
35263 throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL)
35264 },
35265
35266 signatureImportLax: function (sig) {
35267 assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35268 assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35269
35270 var sigObj = der.signatureImportLax(sig)
35271 if (sigObj) return secp256k1.signatureImport(sigObj)
35272
35273 throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL)
35274 },
35275
35276 sign: function (message, privateKey, options) {
35277 assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
35278 assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
35279
35280 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35281 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35282
35283 var data = null
35284 var noncefn = null
35285 if (options !== undefined) {
35286 assert.isObject(options, messages.OPTIONS_TYPE_INVALID)
35287
35288 if (options.data !== undefined) {
35289 assert.isBuffer(options.data, messages.OPTIONS_DATA_TYPE_INVALID)
35290 assert.isBufferLength(options.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID)
35291 data = options.data
35292 }
35293
35294 if (options.noncefn !== undefined) {
35295 assert.isFunction(options.noncefn, messages.OPTIONS_NONCEFN_TYPE_INVALID)
35296 noncefn = options.noncefn
35297 }
35298 }
35299
35300 return secp256k1.sign(message, privateKey, noncefn, data)
35301 },
35302
35303 verify: function (message, signature, publicKey) {
35304 assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
35305 assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
35306
35307 assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35308 assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35309
35310 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35311 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35312
35313 return secp256k1.verify(message, signature, publicKey)
35314 },
35315
35316 recover: function (message, signature, recovery, compressed) {
35317 assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
35318 assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
35319
35320 assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
35321 assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
35322
35323 assert.isNumber(recovery, messages.RECOVERY_ID_TYPE_INVALID)
35324 assert.isNumberInInterval(recovery, -1, 4, messages.RECOVERY_ID_VALUE_INVALID)
35325
35326 compressed = initCompressedValue(compressed, true)
35327
35328 return secp256k1.recover(message, signature, recovery, compressed)
35329 },
35330
35331 ecdh: function (publicKey, privateKey) {
35332 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35333 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35334
35335 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35336 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35337
35338 return secp256k1.ecdh(publicKey, privateKey)
35339 },
35340
35341 ecdhUnsafe: function (publicKey, privateKey, compressed) {
35342 assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
35343 assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
35344
35345 assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
35346 assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
35347
35348 compressed = initCompressedValue(compressed, true)
35349
35350 return secp256k1.ecdhUnsafe(publicKey, privateKey, compressed)
35351 }
35352 }
35353}
35354
35355},{"./assert":74,"./der":75,"./messages.json":78}],78:[function(require,module,exports){
35356module.exports={
35357 "COMPRESSED_TYPE_INVALID": "compressed should be a boolean",
35358 "EC_PRIVATE_KEY_TYPE_INVALID": "private key should be a Buffer",
35359 "EC_PRIVATE_KEY_LENGTH_INVALID": "private key length is invalid",
35360 "EC_PRIVATE_KEY_TWEAK_ADD_FAIL": "tweak out of range or resulting private key is invalid",
35361 "EC_PRIVATE_KEY_TWEAK_MUL_FAIL": "tweak out of range",
35362 "EC_PRIVATE_KEY_EXPORT_DER_FAIL": "couldn't export to DER format",
35363 "EC_PRIVATE_KEY_IMPORT_DER_FAIL": "couldn't import from DER format",
35364 "EC_PUBLIC_KEYS_TYPE_INVALID": "public keys should be an Array",
35365 "EC_PUBLIC_KEYS_LENGTH_INVALID": "public keys Array should have at least 1 element",
35366 "EC_PUBLIC_KEY_TYPE_INVALID": "public key should be a Buffer",
35367 "EC_PUBLIC_KEY_LENGTH_INVALID": "public key length is invalid",
35368 "EC_PUBLIC_KEY_PARSE_FAIL": "the public key could not be parsed or is invalid",
35369 "EC_PUBLIC_KEY_CREATE_FAIL": "private was invalid, try again",
35370 "EC_PUBLIC_KEY_TWEAK_ADD_FAIL": "tweak out of range or resulting public key is invalid",
35371 "EC_PUBLIC_KEY_TWEAK_MUL_FAIL": "tweak out of range",
35372 "EC_PUBLIC_KEY_COMBINE_FAIL": "the sum of the public keys is not valid",
35373 "ECDH_FAIL": "scalar was invalid (zero or overflow)",
35374 "ECDSA_SIGNATURE_TYPE_INVALID": "signature should be a Buffer",
35375 "ECDSA_SIGNATURE_LENGTH_INVALID": "signature length is invalid",
35376 "ECDSA_SIGNATURE_PARSE_FAIL": "couldn't parse signature",
35377 "ECDSA_SIGNATURE_PARSE_DER_FAIL": "couldn't parse DER signature",
35378 "ECDSA_SIGNATURE_SERIALIZE_DER_FAIL": "couldn't serialize signature to DER format",
35379 "ECDSA_SIGN_FAIL": "nonce generation function failed or private key is invalid",
35380 "ECDSA_RECOVER_FAIL": "couldn't recover public key from signature",
35381 "MSG32_TYPE_INVALID": "message should be a Buffer",
35382 "MSG32_LENGTH_INVALID": "message length is invalid",
35383 "OPTIONS_TYPE_INVALID": "options should be an Object",
35384 "OPTIONS_DATA_TYPE_INVALID": "options.data should be a Buffer",
35385 "OPTIONS_DATA_LENGTH_INVALID": "options.data length is invalid",
35386 "OPTIONS_NONCEFN_TYPE_INVALID": "options.noncefn should be a Function",
35387 "RECOVERY_ID_TYPE_INVALID": "recovery should be a Number",
35388 "RECOVERY_ID_VALUE_INVALID": "recovery should have value between -1 and 4",
35389 "TWEAK_TYPE_INVALID": "tweak should be a Buffer",
35390 "TWEAK_LENGTH_INVALID": "tweak length is invalid"
35391}
35392
35393},{}],79:[function(require,module,exports){
35394(function (Buffer){
35395// prototype class for hash functions
35396function Hash (blockSize, finalSize) {
35397 this._block = new Buffer(blockSize)
35398 this._finalSize = finalSize
35399 this._blockSize = blockSize
35400 this._len = 0
35401 this._s = 0
35402}
35403
35404Hash.prototype.update = function (data, enc) {
35405 if (typeof data === 'string') {
35406 enc = enc || 'utf8'
35407 data = new Buffer(data, enc)
35408 }
35409
35410 var l = this._len += data.length
35411 var s = this._s || 0
35412 var f = 0
35413 var buffer = this._block
35414
35415 while (s < l) {
35416 var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
35417 var ch = (t - f)
35418
35419 for (var i = 0; i < ch; i++) {
35420 buffer[(s % this._blockSize) + i] = data[i + f]
35421 }
35422
35423 s += ch
35424 f += ch
35425
35426 if ((s % this._blockSize) === 0) {
35427 this._update(buffer)
35428 }
35429 }
35430 this._s = s
35431
35432 return this
35433}
35434
35435Hash.prototype.digest = function (enc) {
35436 // Suppose the length of the message M, in bits, is l
35437 var l = this._len * 8
35438
35439 // Append the bit 1 to the end of the message
35440 this._block[this._len % this._blockSize] = 0x80
35441
35442 // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize
35443 this._block.fill(0, this._len % this._blockSize + 1)
35444
35445 if (l % (this._blockSize * 8) >= this._finalSize * 8) {
35446 this._update(this._block)
35447 this._block.fill(0)
35448 }
35449
35450 // to this append the block which is equal to the number l written in binary
35451 // TODO: handle case where l is > Math.pow(2, 29)
35452 this._block.writeInt32BE(l, this._blockSize - 4)
35453
35454 var hash = this._update(this._block) || this._hash()
35455
35456 return enc ? hash.toString(enc) : hash
35457}
35458
35459Hash.prototype._update = function () {
35460 throw new Error('_update must be implemented by subclass')
35461}
35462
35463module.exports = Hash
35464
35465}).call(this,require("buffer").Buffer)
35466},{"buffer":5}],80:[function(require,module,exports){
35467var exports = module.exports = function SHA (algorithm) {
35468 algorithm = algorithm.toLowerCase()
35469
35470 var Algorithm = exports[algorithm]
35471 if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
35472
35473 return new Algorithm()
35474}
35475
35476exports.sha = require('./sha')
35477exports.sha1 = require('./sha1')
35478exports.sha224 = require('./sha224')
35479exports.sha256 = require('./sha256')
35480exports.sha384 = require('./sha384')
35481exports.sha512 = require('./sha512')
35482
35483},{"./sha":81,"./sha1":82,"./sha224":83,"./sha256":84,"./sha384":85,"./sha512":86}],81:[function(require,module,exports){
35484(function (Buffer){
35485/*
35486 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
35487 * in FIPS PUB 180-1
35488 * This source code is derived from sha1.js of the same repository.
35489 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
35490 * operation was added.
35491 */
35492
35493var inherits = require('inherits')
35494var Hash = require('./hash')
35495
35496var K = [
35497 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
35498]
35499
35500var W = new Array(80)
35501
35502function Sha () {
35503 this.init()
35504 this._w = W
35505
35506 Hash.call(this, 64, 56)
35507}
35508
35509inherits(Sha, Hash)
35510
35511Sha.prototype.init = function () {
35512 this._a = 0x67452301
35513 this._b = 0xefcdab89
35514 this._c = 0x98badcfe
35515 this._d = 0x10325476
35516 this._e = 0xc3d2e1f0
35517
35518 return this
35519}
35520
35521function rotl5 (num) {
35522 return (num << 5) | (num >>> 27)
35523}
35524
35525function rotl30 (num) {
35526 return (num << 30) | (num >>> 2)
35527}
35528
35529function ft (s, b, c, d) {
35530 if (s === 0) return (b & c) | ((~b) & d)
35531 if (s === 2) return (b & c) | (b & d) | (c & d)
35532 return b ^ c ^ d
35533}
35534
35535Sha.prototype._update = function (M) {
35536 var W = this._w
35537
35538 var a = this._a | 0
35539 var b = this._b | 0
35540 var c = this._c | 0
35541 var d = this._d | 0
35542 var e = this._e | 0
35543
35544 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
35545 for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
35546
35547 for (var j = 0; j < 80; ++j) {
35548 var s = ~~(j / 20)
35549 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
35550
35551 e = d
35552 d = c
35553 c = rotl30(b)
35554 b = a
35555 a = t
35556 }
35557
35558 this._a = (a + this._a) | 0
35559 this._b = (b + this._b) | 0
35560 this._c = (c + this._c) | 0
35561 this._d = (d + this._d) | 0
35562 this._e = (e + this._e) | 0
35563}
35564
35565Sha.prototype._hash = function () {
35566 var H = new Buffer(20)
35567
35568 H.writeInt32BE(this._a | 0, 0)
35569 H.writeInt32BE(this._b | 0, 4)
35570 H.writeInt32BE(this._c | 0, 8)
35571 H.writeInt32BE(this._d | 0, 12)
35572 H.writeInt32BE(this._e | 0, 16)
35573
35574 return H
35575}
35576
35577module.exports = Sha
35578
35579}).call(this,require("buffer").Buffer)
35580},{"./hash":79,"buffer":5,"inherits":63}],82:[function(require,module,exports){
35581(function (Buffer){
35582/*
35583 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
35584 * in FIPS PUB 180-1
35585 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
35586 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
35587 * Distributed under the BSD License
35588 * See http://pajhome.org.uk/crypt/md5 for details.
35589 */
35590
35591var inherits = require('inherits')
35592var Hash = require('./hash')
35593
35594var K = [
35595 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
35596]
35597
35598var W = new Array(80)
35599
35600function Sha1 () {
35601 this.init()
35602 this._w = W
35603
35604 Hash.call(this, 64, 56)
35605}
35606
35607inherits(Sha1, Hash)
35608
35609Sha1.prototype.init = function () {
35610 this._a = 0x67452301
35611 this._b = 0xefcdab89
35612 this._c = 0x98badcfe
35613 this._d = 0x10325476
35614 this._e = 0xc3d2e1f0
35615
35616 return this
35617}
35618
35619function rotl1 (num) {
35620 return (num << 1) | (num >>> 31)
35621}
35622
35623function rotl5 (num) {
35624 return (num << 5) | (num >>> 27)
35625}
35626
35627function rotl30 (num) {
35628 return (num << 30) | (num >>> 2)
35629}
35630
35631function ft (s, b, c, d) {
35632 if (s === 0) return (b & c) | ((~b) & d)
35633 if (s === 2) return (b & c) | (b & d) | (c & d)
35634 return b ^ c ^ d
35635}
35636
35637Sha1.prototype._update = function (M) {
35638 var W = this._w
35639
35640 var a = this._a | 0
35641 var b = this._b | 0
35642 var c = this._c | 0
35643 var d = this._d | 0
35644 var e = this._e | 0
35645
35646 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
35647 for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
35648
35649 for (var j = 0; j < 80; ++j) {
35650 var s = ~~(j / 20)
35651 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
35652
35653 e = d
35654 d = c
35655 c = rotl30(b)
35656 b = a
35657 a = t
35658 }
35659
35660 this._a = (a + this._a) | 0
35661 this._b = (b + this._b) | 0
35662 this._c = (c + this._c) | 0
35663 this._d = (d + this._d) | 0
35664 this._e = (e + this._e) | 0
35665}
35666
35667Sha1.prototype._hash = function () {
35668 var H = new Buffer(20)
35669
35670 H.writeInt32BE(this._a | 0, 0)
35671 H.writeInt32BE(this._b | 0, 4)
35672 H.writeInt32BE(this._c | 0, 8)
35673 H.writeInt32BE(this._d | 0, 12)
35674 H.writeInt32BE(this._e | 0, 16)
35675
35676 return H
35677}
35678
35679module.exports = Sha1
35680
35681}).call(this,require("buffer").Buffer)
35682},{"./hash":79,"buffer":5,"inherits":63}],83:[function(require,module,exports){
35683(function (Buffer){
35684/**
35685 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
35686 * in FIPS 180-2
35687 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
35688 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
35689 *
35690 */
35691
35692var inherits = require('inherits')
35693var Sha256 = require('./sha256')
35694var Hash = require('./hash')
35695
35696var W = new Array(64)
35697
35698function Sha224 () {
35699 this.init()
35700
35701 this._w = W // new Array(64)
35702
35703 Hash.call(this, 64, 56)
35704}
35705
35706inherits(Sha224, Sha256)
35707
35708Sha224.prototype.init = function () {
35709 this._a = 0xc1059ed8
35710 this._b = 0x367cd507
35711 this._c = 0x3070dd17
35712 this._d = 0xf70e5939
35713 this._e = 0xffc00b31
35714 this._f = 0x68581511
35715 this._g = 0x64f98fa7
35716 this._h = 0xbefa4fa4
35717
35718 return this
35719}
35720
35721Sha224.prototype._hash = function () {
35722 var H = new Buffer(28)
35723
35724 H.writeInt32BE(this._a, 0)
35725 H.writeInt32BE(this._b, 4)
35726 H.writeInt32BE(this._c, 8)
35727 H.writeInt32BE(this._d, 12)
35728 H.writeInt32BE(this._e, 16)
35729 H.writeInt32BE(this._f, 20)
35730 H.writeInt32BE(this._g, 24)
35731
35732 return H
35733}
35734
35735module.exports = Sha224
35736
35737}).call(this,require("buffer").Buffer)
35738},{"./hash":79,"./sha256":84,"buffer":5,"inherits":63}],84:[function(require,module,exports){
35739(function (Buffer){
35740/**
35741 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
35742 * in FIPS 180-2
35743 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
35744 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
35745 *
35746 */
35747
35748var inherits = require('inherits')
35749var Hash = require('./hash')
35750
35751var K = [
35752 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
35753 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
35754 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
35755 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
35756 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
35757 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
35758 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
35759 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
35760 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
35761 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
35762 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
35763 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
35764 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
35765 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
35766 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
35767 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
35768]
35769
35770var W = new Array(64)
35771
35772function Sha256 () {
35773 this.init()
35774
35775 this._w = W // new Array(64)
35776
35777 Hash.call(this, 64, 56)
35778}
35779
35780inherits(Sha256, Hash)
35781
35782Sha256.prototype.init = function () {
35783 this._a = 0x6a09e667
35784 this._b = 0xbb67ae85
35785 this._c = 0x3c6ef372
35786 this._d = 0xa54ff53a
35787 this._e = 0x510e527f
35788 this._f = 0x9b05688c
35789 this._g = 0x1f83d9ab
35790 this._h = 0x5be0cd19
35791
35792 return this
35793}
35794
35795function ch (x, y, z) {
35796 return z ^ (x & (y ^ z))
35797}
35798
35799function maj (x, y, z) {
35800 return (x & y) | (z & (x | y))
35801}
35802
35803function sigma0 (x) {
35804 return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
35805}
35806
35807function sigma1 (x) {
35808 return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
35809}
35810
35811function gamma0 (x) {
35812 return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
35813}
35814
35815function gamma1 (x) {
35816 return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
35817}
35818
35819Sha256.prototype._update = function (M) {
35820 var W = this._w
35821
35822 var a = this._a | 0
35823 var b = this._b | 0
35824 var c = this._c | 0
35825 var d = this._d | 0
35826 var e = this._e | 0
35827 var f = this._f | 0
35828 var g = this._g | 0
35829 var h = this._h | 0
35830
35831 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
35832 for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
35833
35834 for (var j = 0; j < 64; ++j) {
35835 var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
35836 var T2 = (sigma0(a) + maj(a, b, c)) | 0
35837
35838 h = g
35839 g = f
35840 f = e
35841 e = (d + T1) | 0
35842 d = c
35843 c = b
35844 b = a
35845 a = (T1 + T2) | 0
35846 }
35847
35848 this._a = (a + this._a) | 0
35849 this._b = (b + this._b) | 0
35850 this._c = (c + this._c) | 0
35851 this._d = (d + this._d) | 0
35852 this._e = (e + this._e) | 0
35853 this._f = (f + this._f) | 0
35854 this._g = (g + this._g) | 0
35855 this._h = (h + this._h) | 0
35856}
35857
35858Sha256.prototype._hash = function () {
35859 var H = new Buffer(32)
35860
35861 H.writeInt32BE(this._a, 0)
35862 H.writeInt32BE(this._b, 4)
35863 H.writeInt32BE(this._c, 8)
35864 H.writeInt32BE(this._d, 12)
35865 H.writeInt32BE(this._e, 16)
35866 H.writeInt32BE(this._f, 20)
35867 H.writeInt32BE(this._g, 24)
35868 H.writeInt32BE(this._h, 28)
35869
35870 return H
35871}
35872
35873module.exports = Sha256
35874
35875}).call(this,require("buffer").Buffer)
35876},{"./hash":79,"buffer":5,"inherits":63}],85:[function(require,module,exports){
35877(function (Buffer){
35878var inherits = require('inherits')
35879var SHA512 = require('./sha512')
35880var Hash = require('./hash')
35881
35882var W = new Array(160)
35883
35884function Sha384 () {
35885 this.init()
35886 this._w = W
35887
35888 Hash.call(this, 128, 112)
35889}
35890
35891inherits(Sha384, SHA512)
35892
35893Sha384.prototype.init = function () {
35894 this._ah = 0xcbbb9d5d
35895 this._bh = 0x629a292a
35896 this._ch = 0x9159015a
35897 this._dh = 0x152fecd8
35898 this._eh = 0x67332667
35899 this._fh = 0x8eb44a87
35900 this._gh = 0xdb0c2e0d
35901 this._hh = 0x47b5481d
35902
35903 this._al = 0xc1059ed8
35904 this._bl = 0x367cd507
35905 this._cl = 0x3070dd17
35906 this._dl = 0xf70e5939
35907 this._el = 0xffc00b31
35908 this._fl = 0x68581511
35909 this._gl = 0x64f98fa7
35910 this._hl = 0xbefa4fa4
35911
35912 return this
35913}
35914
35915Sha384.prototype._hash = function () {
35916 var H = new Buffer(48)
35917
35918 function writeInt64BE (h, l, offset) {
35919 H.writeInt32BE(h, offset)
35920 H.writeInt32BE(l, offset + 4)
35921 }
35922
35923 writeInt64BE(this._ah, this._al, 0)
35924 writeInt64BE(this._bh, this._bl, 8)
35925 writeInt64BE(this._ch, this._cl, 16)
35926 writeInt64BE(this._dh, this._dl, 24)
35927 writeInt64BE(this._eh, this._el, 32)
35928 writeInt64BE(this._fh, this._fl, 40)
35929
35930 return H
35931}
35932
35933module.exports = Sha384
35934
35935}).call(this,require("buffer").Buffer)
35936},{"./hash":79,"./sha512":86,"buffer":5,"inherits":63}],86:[function(require,module,exports){
35937(function (Buffer){
35938var inherits = require('inherits')
35939var Hash = require('./hash')
35940
35941var K = [
35942 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
35943 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
35944 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
35945 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
35946 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
35947 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
35948 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
35949 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
35950 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
35951 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
35952 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
35953 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
35954 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
35955 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
35956 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
35957 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
35958 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
35959 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
35960 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
35961 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
35962 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
35963 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
35964 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
35965 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
35966 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
35967 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
35968 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
35969 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
35970 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
35971 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
35972 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
35973 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
35974 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
35975 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
35976 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
35977 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
35978 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
35979 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
35980 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
35981 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
35982]
35983
35984var W = new Array(160)
35985
35986function Sha512 () {
35987 this.init()
35988 this._w = W
35989
35990 Hash.call(this, 128, 112)
35991}
35992
35993inherits(Sha512, Hash)
35994
35995Sha512.prototype.init = function () {
35996 this._ah = 0x6a09e667
35997 this._bh = 0xbb67ae85
35998 this._ch = 0x3c6ef372
35999 this._dh = 0xa54ff53a
36000 this._eh = 0x510e527f
36001 this._fh = 0x9b05688c
36002 this._gh = 0x1f83d9ab
36003 this._hh = 0x5be0cd19
36004
36005 this._al = 0xf3bcc908
36006 this._bl = 0x84caa73b
36007 this._cl = 0xfe94f82b
36008 this._dl = 0x5f1d36f1
36009 this._el = 0xade682d1
36010 this._fl = 0x2b3e6c1f
36011 this._gl = 0xfb41bd6b
36012 this._hl = 0x137e2179
36013
36014 return this
36015}
36016
36017function Ch (x, y, z) {
36018 return z ^ (x & (y ^ z))
36019}
36020
36021function maj (x, y, z) {
36022 return (x & y) | (z & (x | y))
36023}
36024
36025function sigma0 (x, xl) {
36026 return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
36027}
36028
36029function sigma1 (x, xl) {
36030 return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
36031}
36032
36033function Gamma0 (x, xl) {
36034 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
36035}
36036
36037function Gamma0l (x, xl) {
36038 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
36039}
36040
36041function Gamma1 (x, xl) {
36042 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
36043}
36044
36045function Gamma1l (x, xl) {
36046 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
36047}
36048
36049function getCarry (a, b) {
36050 return (a >>> 0) < (b >>> 0) ? 1 : 0
36051}
36052
36053Sha512.prototype._update = function (M) {
36054 var W = this._w
36055
36056 var ah = this._ah | 0
36057 var bh = this._bh | 0
36058 var ch = this._ch | 0
36059 var dh = this._dh | 0
36060 var eh = this._eh | 0
36061 var fh = this._fh | 0
36062 var gh = this._gh | 0
36063 var hh = this._hh | 0
36064
36065 var al = this._al | 0
36066 var bl = this._bl | 0
36067 var cl = this._cl | 0
36068 var dl = this._dl | 0
36069 var el = this._el | 0
36070 var fl = this._fl | 0
36071 var gl = this._gl | 0
36072 var hl = this._hl | 0
36073
36074 for (var i = 0; i < 32; i += 2) {
36075 W[i] = M.readInt32BE(i * 4)
36076 W[i + 1] = M.readInt32BE(i * 4 + 4)
36077 }
36078 for (; i < 160; i += 2) {
36079 var xh = W[i - 15 * 2]
36080 var xl = W[i - 15 * 2 + 1]
36081 var gamma0 = Gamma0(xh, xl)
36082 var gamma0l = Gamma0l(xl, xh)
36083
36084 xh = W[i - 2 * 2]
36085 xl = W[i - 2 * 2 + 1]
36086 var gamma1 = Gamma1(xh, xl)
36087 var gamma1l = Gamma1l(xl, xh)
36088
36089 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
36090 var Wi7h = W[i - 7 * 2]
36091 var Wi7l = W[i - 7 * 2 + 1]
36092
36093 var Wi16h = W[i - 16 * 2]
36094 var Wi16l = W[i - 16 * 2 + 1]
36095
36096 var Wil = (gamma0l + Wi7l) | 0
36097 var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
36098 Wil = (Wil + gamma1l) | 0
36099 Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
36100 Wil = (Wil + Wi16l) | 0
36101 Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
36102
36103 W[i] = Wih
36104 W[i + 1] = Wil
36105 }
36106
36107 for (var j = 0; j < 160; j += 2) {
36108 Wih = W[j]
36109 Wil = W[j + 1]
36110
36111 var majh = maj(ah, bh, ch)
36112 var majl = maj(al, bl, cl)
36113
36114 var sigma0h = sigma0(ah, al)
36115 var sigma0l = sigma0(al, ah)
36116 var sigma1h = sigma1(eh, el)
36117 var sigma1l = sigma1(el, eh)
36118
36119 // t1 = h + sigma1 + ch + K[j] + W[j]
36120 var Kih = K[j]
36121 var Kil = K[j + 1]
36122
36123 var chh = Ch(eh, fh, gh)
36124 var chl = Ch(el, fl, gl)
36125
36126 var t1l = (hl + sigma1l) | 0
36127 var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
36128 t1l = (t1l + chl) | 0
36129 t1h = (t1h + chh + getCarry(t1l, chl)) | 0
36130 t1l = (t1l + Kil) | 0
36131 t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
36132 t1l = (t1l + Wil) | 0
36133 t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
36134
36135 // t2 = sigma0 + maj
36136 var t2l = (sigma0l + majl) | 0
36137 var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
36138
36139 hh = gh
36140 hl = gl
36141 gh = fh
36142 gl = fl
36143 fh = eh
36144 fl = el
36145 el = (dl + t1l) | 0
36146 eh = (dh + t1h + getCarry(el, dl)) | 0
36147 dh = ch
36148 dl = cl
36149 ch = bh
36150 cl = bl
36151 bh = ah
36152 bl = al
36153 al = (t1l + t2l) | 0
36154 ah = (t1h + t2h + getCarry(al, t1l)) | 0
36155 }
36156
36157 this._al = (this._al + al) | 0
36158 this._bl = (this._bl + bl) | 0
36159 this._cl = (this._cl + cl) | 0
36160 this._dl = (this._dl + dl) | 0
36161 this._el = (this._el + el) | 0
36162 this._fl = (this._fl + fl) | 0
36163 this._gl = (this._gl + gl) | 0
36164 this._hl = (this._hl + hl) | 0
36165
36166 this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
36167 this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
36168 this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
36169 this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
36170 this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
36171 this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
36172 this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
36173 this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
36174}
36175
36176Sha512.prototype._hash = function () {
36177 var H = new Buffer(64)
36178
36179 function writeInt64BE (h, l, offset) {
36180 H.writeInt32BE(h, offset)
36181 H.writeInt32BE(l, offset + 4)
36182 }
36183
36184 writeInt64BE(this._ah, this._al, 0)
36185 writeInt64BE(this._bh, this._bl, 8)
36186 writeInt64BE(this._ch, this._cl, 16)
36187 writeInt64BE(this._dh, this._dl, 24)
36188 writeInt64BE(this._eh, this._el, 32)
36189 writeInt64BE(this._fh, this._fl, 40)
36190 writeInt64BE(this._gh, this._gl, 48)
36191 writeInt64BE(this._hh, this._hl, 56)
36192
36193 return H
36194}
36195
36196module.exports = Sha512
36197
36198}).call(this,require("buffer").Buffer)
36199},{"./hash":79,"buffer":5,"inherits":63}],87:[function(require,module,exports){
36200var isHexPrefixed = require('is-hex-prefixed');
36201
36202/**
36203 * Removes '0x' from a given `String` is present
36204 * @param {String} str the string value
36205 * @return {String|Optional} a string by pass if necessary
36206 */
36207module.exports = function stripHexPrefix(str) {
36208 if (typeof str !== 'string') {
36209 return str;
36210 }
36211
36212 return isHexPrefixed(str) ? str.slice(2) : str;
36213}
36214
36215},{"is-hex-prefixed":64}]},{},[31])(31)
36216});</script>
13661 <script>// Select components from sjcl to suit the crypto operations bip39 requires. 36217 <script>// Select components from sjcl to suit the crypto operations bip39 requires.
13662 36218
13663//// base.js 36219//// base.js
@@ -19209,6 +41765,13 @@ window.Entropy = new (function() {
19209 if (useHardenedAddresses) { 41765 if (useHardenedAddresses) {
19210 indexText = indexText + "'"; 41766 indexText = indexText + "'";
19211 } 41767 }
41768 // Ethereum values are different
41769 if (networks[DOM.network.val()].name == "Ethereum") {
41770 var privKeyBuffer = key.privKey.d.toBuffer();
41771 privkey = privKeyBuffer.toString('hex');
41772 var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
41773 address = "0x" + addressBuffer.toString('hex');
41774 }
19212 addAddressToList(indexText, address, pubkey, privkey); 41775 addAddressToList(indexText, address, pubkey, privkey);
19213 }, 50) 41776 }, 50)
19214 } 41777 }
@@ -19768,6 +42331,13 @@ window.Entropy = new (function() {
19768 DOM.bip44coin.val(6); 42331 DOM.bip44coin.val(6);
19769 }, 42332 },
19770 }, 42333 },
42334 {
42335 name: "Ethereum",
42336 onSelect: function() {
42337 network = bitcoin.networks.bitcoin;
42338 DOM.bip44coin.val(60);
42339 },
42340 },
19771 ] 42341 ]
19772 42342
19773 init(); 42343 init();