diff options
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/basex.js | 2010 | ||||
-rw-r--r-- | src/js/bitcoinjs-extensions.js | 10 | ||||
-rw-r--r-- | src/js/ethereumjs-util.js | 18762 | ||||
-rw-r--r-- | src/js/index.js | 143 | ||||
-rw-r--r-- | src/js/jsbip39.js | 5 | ||||
-rw-r--r-- | src/js/polyfill.es6.js | 3793 | ||||
-rw-r--r-- | src/js/ripple-util.js | 10 | ||||
-rw-r--r-- | src/js/unorm.js | 442 |
8 files changed, 25146 insertions, 29 deletions
diff --git a/src/js/basex.js b/src/js/basex.js new file mode 100644 index 0000000..1ec705d --- /dev/null +++ b/src/js/basex.js | |||
@@ -0,0 +1,2010 @@ | |||
1 | (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.foo = 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){ | ||
2 | 'use strict' | ||
3 | |||
4 | exports.byteLength = byteLength | ||
5 | exports.toByteArray = toByteArray | ||
6 | exports.fromByteArray = fromByteArray | ||
7 | |||
8 | var lookup = [] | ||
9 | var revLookup = [] | ||
10 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array | ||
11 | |||
12 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | ||
13 | for (var i = 0, len = code.length; i < len; ++i) { | ||
14 | lookup[i] = code[i] | ||
15 | revLookup[code.charCodeAt(i)] = i | ||
16 | } | ||
17 | |||
18 | revLookup['-'.charCodeAt(0)] = 62 | ||
19 | revLookup['_'.charCodeAt(0)] = 63 | ||
20 | |||
21 | function placeHoldersCount (b64) { | ||
22 | var len = b64.length | ||
23 | if (len % 4 > 0) { | ||
24 | throw new Error('Invalid string. Length must be a multiple of 4') | ||
25 | } | ||
26 | |||
27 | // the number of equal signs (place holders) | ||
28 | // if there are two placeholders, than the two characters before it | ||
29 | // represent one byte | ||
30 | // if there is only one, then the three characters before it represent 2 bytes | ||
31 | // this is just a cheap hack to not do indexOf twice | ||
32 | return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 | ||
33 | } | ||
34 | |||
35 | function byteLength (b64) { | ||
36 | // base64 is 4/3 + up to two characters of the original data | ||
37 | return b64.length * 3 / 4 - placeHoldersCount(b64) | ||
38 | } | ||
39 | |||
40 | function toByteArray (b64) { | ||
41 | var i, j, l, tmp, placeHolders, arr | ||
42 | var len = b64.length | ||
43 | placeHolders = placeHoldersCount(b64) | ||
44 | |||
45 | arr = new Arr(len * 3 / 4 - placeHolders) | ||
46 | |||
47 | // if there are placeholders, only get up to the last complete 4 chars | ||
48 | l = placeHolders > 0 ? len - 4 : len | ||
49 | |||
50 | var L = 0 | ||
51 | |||
52 | for (i = 0, j = 0; i < l; i += 4, j += 3) { | ||
53 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] | ||
54 | arr[L++] = (tmp >> 16) & 0xFF | ||
55 | arr[L++] = (tmp >> 8) & 0xFF | ||
56 | arr[L++] = tmp & 0xFF | ||
57 | } | ||
58 | |||
59 | if (placeHolders === 2) { | ||
60 | tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) | ||
61 | arr[L++] = tmp & 0xFF | ||
62 | } else if (placeHolders === 1) { | ||
63 | tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) | ||
64 | arr[L++] = (tmp >> 8) & 0xFF | ||
65 | arr[L++] = tmp & 0xFF | ||
66 | } | ||
67 | |||
68 | return arr | ||
69 | } | ||
70 | |||
71 | function tripletToBase64 (num) { | ||
72 | return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] | ||
73 | } | ||
74 | |||
75 | function encodeChunk (uint8, start, end) { | ||
76 | var tmp | ||
77 | var output = [] | ||
78 | for (var i = start; i < end; i += 3) { | ||
79 | tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) | ||
80 | output.push(tripletToBase64(tmp)) | ||
81 | } | ||
82 | return output.join('') | ||
83 | } | ||
84 | |||
85 | function fromByteArray (uint8) { | ||
86 | var tmp | ||
87 | var len = uint8.length | ||
88 | var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes | ||
89 | var output = '' | ||
90 | var parts = [] | ||
91 | var maxChunkLength = 16383 // must be multiple of 3 | ||
92 | |||
93 | // go through the array every three bytes, we'll deal with trailing stuff later | ||
94 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
95 | parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) | ||
96 | } | ||
97 | |||
98 | // pad the end with zeros, but make sure to not forget the extra bytes | ||
99 | if (extraBytes === 1) { | ||
100 | tmp = uint8[len - 1] | ||
101 | output += lookup[tmp >> 2] | ||
102 | output += lookup[(tmp << 4) & 0x3F] | ||
103 | output += '==' | ||
104 | } else if (extraBytes === 2) { | ||
105 | tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) | ||
106 | output += lookup[tmp >> 10] | ||
107 | output += lookup[(tmp >> 4) & 0x3F] | ||
108 | output += lookup[(tmp << 2) & 0x3F] | ||
109 | output += '=' | ||
110 | } | ||
111 | |||
112 | parts.push(output) | ||
113 | |||
114 | return parts.join('') | ||
115 | } | ||
116 | |||
117 | },{}],2:[function(require,module,exports){ | ||
118 | /*! | ||
119 | * The buffer module from node.js, for the browser. | ||
120 | * | ||
121 | * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
122 | * @license MIT | ||
123 | */ | ||
124 | /* eslint-disable no-proto */ | ||
125 | |||
126 | 'use strict' | ||
127 | |||
128 | var base64 = require('base64-js') | ||
129 | var ieee754 = require('ieee754') | ||
130 | |||
131 | exports.Buffer = Buffer | ||
132 | exports.SlowBuffer = SlowBuffer | ||
133 | exports.INSPECT_MAX_BYTES = 50 | ||
134 | |||
135 | var K_MAX_LENGTH = 0x7fffffff | ||
136 | exports.kMaxLength = K_MAX_LENGTH | ||
137 | |||
138 | /** | ||
139 | * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
140 | * === true Use Uint8Array implementation (fastest) | ||
141 | * === false Print warning and recommend using `buffer` v4.x which has an Object | ||
142 | * implementation (most compatible, even IE6) | ||
143 | * | ||
144 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
145 | * Opera 11.6+, iOS 4.2+. | ||
146 | * | ||
147 | * We report that the browser does not support typed arrays if the are not subclassable | ||
148 | * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` | ||
149 | * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support | ||
150 | * for __proto__ and has a buggy typed array implementation. | ||
151 | */ | ||
152 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() | ||
153 | |||
154 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && | ||
155 | typeof console.error === 'function') { | ||
156 | console.error( | ||
157 | 'This browser lacks typed array (Uint8Array) support which is required by ' + | ||
158 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' | ||
159 | ) | ||
160 | } | ||
161 | |||
162 | function typedArraySupport () { | ||
163 | // Can typed array instances can be augmented? | ||
164 | try { | ||
165 | var arr = new Uint8Array(1) | ||
166 | arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} | ||
167 | return arr.foo() === 42 | ||
168 | } catch (e) { | ||
169 | return false | ||
170 | } | ||
171 | } | ||
172 | |||
173 | function createBuffer (length) { | ||
174 | if (length > K_MAX_LENGTH) { | ||
175 | throw new RangeError('Invalid typed array length') | ||
176 | } | ||
177 | // Return an augmented `Uint8Array` instance | ||
178 | var buf = new Uint8Array(length) | ||
179 | buf.__proto__ = Buffer.prototype | ||
180 | return buf | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * The Buffer constructor returns instances of `Uint8Array` that have their | ||
185 | * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of | ||
186 | * `Uint8Array`, so the returned instances will have all the node `Buffer` methods | ||
187 | * and the `Uint8Array` methods. Square bracket notation works as expected -- it | ||
188 | * returns a single octet. | ||
189 | * | ||
190 | * The `Uint8Array` prototype remains unmodified. | ||
191 | */ | ||
192 | |||
193 | function Buffer (arg, encodingOrOffset, length) { | ||
194 | // Common case. | ||
195 | if (typeof arg === 'number') { | ||
196 | if (typeof encodingOrOffset === 'string') { | ||
197 | throw new Error( | ||
198 | 'If encoding is specified then the first argument must be a string' | ||
199 | ) | ||
200 | } | ||
201 | return allocUnsafe(arg) | ||
202 | } | ||
203 | return from(arg, encodingOrOffset, length) | ||
204 | } | ||
205 | |||
206 | // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
207 | if (typeof Symbol !== 'undefined' && Symbol.species && | ||
208 | Buffer[Symbol.species] === Buffer) { | ||
209 | Object.defineProperty(Buffer, Symbol.species, { | ||
210 | value: null, | ||
211 | configurable: true, | ||
212 | enumerable: false, | ||
213 | writable: false | ||
214 | }) | ||
215 | } | ||
216 | |||
217 | Buffer.poolSize = 8192 // not used by this implementation | ||
218 | |||
219 | function from (value, encodingOrOffset, length) { | ||
220 | if (typeof value === 'number') { | ||
221 | throw new TypeError('"value" argument must not be a number') | ||
222 | } | ||
223 | |||
224 | if (value instanceof ArrayBuffer) { | ||
225 | return fromArrayBuffer(value, encodingOrOffset, length) | ||
226 | } | ||
227 | |||
228 | if (typeof value === 'string') { | ||
229 | return fromString(value, encodingOrOffset) | ||
230 | } | ||
231 | |||
232 | return fromObject(value) | ||
233 | } | ||
234 | |||
235 | /** | ||
236 | * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError | ||
237 | * if value is a number. | ||
238 | * Buffer.from(str[, encoding]) | ||
239 | * Buffer.from(array) | ||
240 | * Buffer.from(buffer) | ||
241 | * Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||
242 | **/ | ||
243 | Buffer.from = function (value, encodingOrOffset, length) { | ||
244 | return from(value, encodingOrOffset, length) | ||
245 | } | ||
246 | |||
247 | // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: | ||
248 | // https://github.com/feross/buffer/pull/148 | ||
249 | Buffer.prototype.__proto__ = Uint8Array.prototype | ||
250 | Buffer.__proto__ = Uint8Array | ||
251 | |||
252 | function assertSize (size) { | ||
253 | if (typeof size !== 'number') { | ||
254 | throw new TypeError('"size" argument must be a number') | ||
255 | } else if (size < 0) { | ||
256 | throw new RangeError('"size" argument must not be negative') | ||
257 | } | ||
258 | } | ||
259 | |||
260 | function alloc (size, fill, encoding) { | ||
261 | assertSize(size) | ||
262 | if (size <= 0) { | ||
263 | return createBuffer(size) | ||
264 | } | ||
265 | if (fill !== undefined) { | ||
266 | // Only pay attention to encoding if it's a string. This | ||
267 | // prevents accidentally sending in a number that would | ||
268 | // be interpretted as a start offset. | ||
269 | return typeof encoding === 'string' | ||
270 | ? createBuffer(size).fill(fill, encoding) | ||
271 | : createBuffer(size).fill(fill) | ||
272 | } | ||
273 | return createBuffer(size) | ||
274 | } | ||
275 | |||
276 | /** | ||
277 | * Creates a new filled Buffer instance. | ||
278 | * alloc(size[, fill[, encoding]]) | ||
279 | **/ | ||
280 | Buffer.alloc = function (size, fill, encoding) { | ||
281 | return alloc(size, fill, encoding) | ||
282 | } | ||
283 | |||
284 | function allocUnsafe (size) { | ||
285 | assertSize(size) | ||
286 | return createBuffer(size < 0 ? 0 : checked(size) | 0) | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. | ||
291 | * */ | ||
292 | Buffer.allocUnsafe = function (size) { | ||
293 | return allocUnsafe(size) | ||
294 | } | ||
295 | /** | ||
296 | * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ||
297 | */ | ||
298 | Buffer.allocUnsafeSlow = function (size) { | ||
299 | return allocUnsafe(size) | ||
300 | } | ||
301 | |||
302 | function fromString (string, encoding) { | ||
303 | if (typeof encoding !== 'string' || encoding === '') { | ||
304 | encoding = 'utf8' | ||
305 | } | ||
306 | |||
307 | if (!Buffer.isEncoding(encoding)) { | ||
308 | throw new TypeError('"encoding" must be a valid string encoding') | ||
309 | } | ||
310 | |||
311 | var length = byteLength(string, encoding) | 0 | ||
312 | var buf = createBuffer(length) | ||
313 | |||
314 | var actual = buf.write(string, encoding) | ||
315 | |||
316 | if (actual !== length) { | ||
317 | // Writing a hex string, for example, that contains invalid characters will | ||
318 | // cause everything after the first invalid character to be ignored. (e.g. | ||
319 | // 'abxxcd' will be treated as 'ab') | ||
320 | buf = buf.slice(0, actual) | ||
321 | } | ||
322 | |||
323 | return buf | ||
324 | } | ||
325 | |||
326 | function fromArrayLike (array) { | ||
327 | var length = array.length < 0 ? 0 : checked(array.length) | 0 | ||
328 | var buf = createBuffer(length) | ||
329 | for (var i = 0; i < length; i += 1) { | ||
330 | buf[i] = array[i] & 255 | ||
331 | } | ||
332 | return buf | ||
333 | } | ||
334 | |||
335 | function fromArrayBuffer (array, byteOffset, length) { | ||
336 | if (byteOffset < 0 || array.byteLength < byteOffset) { | ||
337 | throw new RangeError('\'offset\' is out of bounds') | ||
338 | } | ||
339 | |||
340 | if (array.byteLength < byteOffset + (length || 0)) { | ||
341 | throw new RangeError('\'length\' is out of bounds') | ||
342 | } | ||
343 | |||
344 | var buf | ||
345 | if (byteOffset === undefined && length === undefined) { | ||
346 | buf = new Uint8Array(array) | ||
347 | } else if (length === undefined) { | ||
348 | buf = new Uint8Array(array, byteOffset) | ||
349 | } else { | ||
350 | buf = new Uint8Array(array, byteOffset, length) | ||
351 | } | ||
352 | |||
353 | // Return an augmented `Uint8Array` instance | ||
354 | buf.__proto__ = Buffer.prototype | ||
355 | return buf | ||
356 | } | ||
357 | |||
358 | function fromObject (obj) { | ||
359 | if (Buffer.isBuffer(obj)) { | ||
360 | var len = checked(obj.length) | 0 | ||
361 | var buf = createBuffer(len) | ||
362 | |||
363 | if (buf.length === 0) { | ||
364 | return buf | ||
365 | } | ||
366 | |||
367 | obj.copy(buf, 0, 0, len) | ||
368 | return buf | ||
369 | } | ||
370 | |||
371 | if (obj) { | ||
372 | if (isArrayBufferView(obj) || 'length' in obj) { | ||
373 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
374 | return createBuffer(0) | ||
375 | } | ||
376 | return fromArrayLike(obj) | ||
377 | } | ||
378 | |||
379 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
380 | return fromArrayLike(obj.data) | ||
381 | } | ||
382 | } | ||
383 | |||
384 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') | ||
385 | } | ||
386 | |||
387 | function checked (length) { | ||
388 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when | ||
389 | // length is NaN (which is otherwise coerced to zero.) | ||
390 | if (length >= K_MAX_LENGTH) { | ||
391 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
392 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') | ||
393 | } | ||
394 | return length | 0 | ||
395 | } | ||
396 | |||
397 | function SlowBuffer (length) { | ||
398 | if (+length != length) { // eslint-disable-line eqeqeq | ||
399 | length = 0 | ||
400 | } | ||
401 | return Buffer.alloc(+length) | ||
402 | } | ||
403 | |||
404 | Buffer.isBuffer = function isBuffer (b) { | ||
405 | return b != null && b._isBuffer === true | ||
406 | } | ||
407 | |||
408 | Buffer.compare = function compare (a, b) { | ||
409 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
410 | throw new TypeError('Arguments must be Buffers') | ||
411 | } | ||
412 | |||
413 | if (a === b) return 0 | ||
414 | |||
415 | var x = a.length | ||
416 | var y = b.length | ||
417 | |||
418 | for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
419 | if (a[i] !== b[i]) { | ||
420 | x = a[i] | ||
421 | y = b[i] | ||
422 | break | ||
423 | } | ||
424 | } | ||
425 | |||
426 | if (x < y) return -1 | ||
427 | if (y < x) return 1 | ||
428 | return 0 | ||
429 | } | ||
430 | |||
431 | Buffer.isEncoding = function isEncoding (encoding) { | ||
432 | switch (String(encoding).toLowerCase()) { | ||
433 | case 'hex': | ||
434 | case 'utf8': | ||
435 | case 'utf-8': | ||
436 | case 'ascii': | ||
437 | case 'latin1': | ||
438 | case 'binary': | ||
439 | case 'base64': | ||
440 | case 'ucs2': | ||
441 | case 'ucs-2': | ||
442 | case 'utf16le': | ||
443 | case 'utf-16le': | ||
444 | return true | ||
445 | default: | ||
446 | return false | ||
447 | } | ||
448 | } | ||
449 | |||
450 | Buffer.concat = function concat (list, length) { | ||
451 | if (!Array.isArray(list)) { | ||
452 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
453 | } | ||
454 | |||
455 | if (list.length === 0) { | ||
456 | return Buffer.alloc(0) | ||
457 | } | ||
458 | |||
459 | var i | ||
460 | if (length === undefined) { | ||
461 | length = 0 | ||
462 | for (i = 0; i < list.length; ++i) { | ||
463 | length += list[i].length | ||
464 | } | ||
465 | } | ||
466 | |||
467 | var buffer = Buffer.allocUnsafe(length) | ||
468 | var pos = 0 | ||
469 | for (i = 0; i < list.length; ++i) { | ||
470 | var buf = list[i] | ||
471 | if (!Buffer.isBuffer(buf)) { | ||
472 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
473 | } | ||
474 | buf.copy(buffer, pos) | ||
475 | pos += buf.length | ||
476 | } | ||
477 | return buffer | ||
478 | } | ||
479 | |||
480 | function byteLength (string, encoding) { | ||
481 | if (Buffer.isBuffer(string)) { | ||
482 | return string.length | ||
483 | } | ||
484 | if (isArrayBufferView(string) || string instanceof ArrayBuffer) { | ||
485 | return string.byteLength | ||
486 | } | ||
487 | if (typeof string !== 'string') { | ||
488 | string = '' + string | ||
489 | } | ||
490 | |||
491 | var len = string.length | ||
492 | if (len === 0) return 0 | ||
493 | |||
494 | // Use a for loop to avoid recursion | ||
495 | var loweredCase = false | ||
496 | for (;;) { | ||
497 | switch (encoding) { | ||
498 | case 'ascii': | ||
499 | case 'latin1': | ||
500 | case 'binary': | ||
501 | return len | ||
502 | case 'utf8': | ||
503 | case 'utf-8': | ||
504 | case undefined: | ||
505 | return utf8ToBytes(string).length | ||
506 | case 'ucs2': | ||
507 | case 'ucs-2': | ||
508 | case 'utf16le': | ||
509 | case 'utf-16le': | ||
510 | return len * 2 | ||
511 | case 'hex': | ||
512 | return len >>> 1 | ||
513 | case 'base64': | ||
514 | return base64ToBytes(string).length | ||
515 | default: | ||
516 | if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
517 | encoding = ('' + encoding).toLowerCase() | ||
518 | loweredCase = true | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | Buffer.byteLength = byteLength | ||
523 | |||
524 | function slowToString (encoding, start, end) { | ||
525 | var loweredCase = false | ||
526 | |||
527 | // No need to verify that "this.length <= MAX_UINT32" since it's a read-only | ||
528 | // property of a typed array. | ||
529 | |||
530 | // This behaves neither like String nor Uint8Array in that we set start/end | ||
531 | // to their upper/lower bounds if the value passed is out of range. | ||
532 | // undefined is handled specially as per ECMA-262 6th Edition, | ||
533 | // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. | ||
534 | if (start === undefined || start < 0) { | ||
535 | start = 0 | ||
536 | } | ||
537 | // Return early if start > this.length. Done here to prevent potential uint32 | ||
538 | // coercion fail below. | ||
539 | if (start > this.length) { | ||
540 | return '' | ||
541 | } | ||
542 | |||
543 | if (end === undefined || end > this.length) { | ||
544 | end = this.length | ||
545 | } | ||
546 | |||
547 | if (end <= 0) { | ||
548 | return '' | ||
549 | } | ||
550 | |||
551 | // Force coersion to uint32. This will also coerce falsey/NaN values to 0. | ||
552 | end >>>= 0 | ||
553 | start >>>= 0 | ||
554 | |||
555 | if (end <= start) { | ||
556 | return '' | ||
557 | } | ||
558 | |||
559 | if (!encoding) encoding = 'utf8' | ||
560 | |||
561 | while (true) { | ||
562 | switch (encoding) { | ||
563 | case 'hex': | ||
564 | return hexSlice(this, start, end) | ||
565 | |||
566 | case 'utf8': | ||
567 | case 'utf-8': | ||
568 | return utf8Slice(this, start, end) | ||
569 | |||
570 | case 'ascii': | ||
571 | return asciiSlice(this, start, end) | ||
572 | |||
573 | case 'latin1': | ||
574 | case 'binary': | ||
575 | return latin1Slice(this, start, end) | ||
576 | |||
577 | case 'base64': | ||
578 | return base64Slice(this, start, end) | ||
579 | |||
580 | case 'ucs2': | ||
581 | case 'ucs-2': | ||
582 | case 'utf16le': | ||
583 | case 'utf-16le': | ||
584 | return utf16leSlice(this, start, end) | ||
585 | |||
586 | default: | ||
587 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
588 | encoding = (encoding + '').toLowerCase() | ||
589 | loweredCase = true | ||
590 | } | ||
591 | } | ||
592 | } | ||
593 | |||
594 | // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) | ||
595 | // to detect a Buffer instance. It's not possible to use `instanceof Buffer` | ||
596 | // reliably in a browserify context because there could be multiple different | ||
597 | // copies of the 'buffer' package in use. This method works even for Buffer | ||
598 | // instances that were created from another copy of the `buffer` package. | ||
599 | // See: https://github.com/feross/buffer/issues/154 | ||
600 | Buffer.prototype._isBuffer = true | ||
601 | |||
602 | function swap (b, n, m) { | ||
603 | var i = b[n] | ||
604 | b[n] = b[m] | ||
605 | b[m] = i | ||
606 | } | ||
607 | |||
608 | Buffer.prototype.swap16 = function swap16 () { | ||
609 | var len = this.length | ||
610 | if (len % 2 !== 0) { | ||
611 | throw new RangeError('Buffer size must be a multiple of 16-bits') | ||
612 | } | ||
613 | for (var i = 0; i < len; i += 2) { | ||
614 | swap(this, i, i + 1) | ||
615 | } | ||
616 | return this | ||
617 | } | ||
618 | |||
619 | Buffer.prototype.swap32 = function swap32 () { | ||
620 | var len = this.length | ||
621 | if (len % 4 !== 0) { | ||
622 | throw new RangeError('Buffer size must be a multiple of 32-bits') | ||
623 | } | ||
624 | for (var i = 0; i < len; i += 4) { | ||
625 | swap(this, i, i + 3) | ||
626 | swap(this, i + 1, i + 2) | ||
627 | } | ||
628 | return this | ||
629 | } | ||
630 | |||
631 | Buffer.prototype.swap64 = function swap64 () { | ||
632 | var len = this.length | ||
633 | if (len % 8 !== 0) { | ||
634 | throw new RangeError('Buffer size must be a multiple of 64-bits') | ||
635 | } | ||
636 | for (var i = 0; i < len; i += 8) { | ||
637 | swap(this, i, i + 7) | ||
638 | swap(this, i + 1, i + 6) | ||
639 | swap(this, i + 2, i + 5) | ||
640 | swap(this, i + 3, i + 4) | ||
641 | } | ||
642 | return this | ||
643 | } | ||
644 | |||
645 | Buffer.prototype.toString = function toString () { | ||
646 | var length = this.length | ||
647 | if (length === 0) return '' | ||
648 | if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
649 | return slowToString.apply(this, arguments) | ||
650 | } | ||
651 | |||
652 | Buffer.prototype.equals = function equals (b) { | ||
653 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
654 | if (this === b) return true | ||
655 | return Buffer.compare(this, b) === 0 | ||
656 | } | ||
657 | |||
658 | Buffer.prototype.inspect = function inspect () { | ||
659 | var str = '' | ||
660 | var max = exports.INSPECT_MAX_BYTES | ||
661 | if (this.length > 0) { | ||
662 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
663 | if (this.length > max) str += ' ... ' | ||
664 | } | ||
665 | return '<Buffer ' + str + '>' | ||
666 | } | ||
667 | |||
668 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { | ||
669 | if (!Buffer.isBuffer(target)) { | ||
670 | throw new TypeError('Argument must be a Buffer') | ||
671 | } | ||
672 | |||
673 | if (start === undefined) { | ||
674 | start = 0 | ||
675 | } | ||
676 | if (end === undefined) { | ||
677 | end = target ? target.length : 0 | ||
678 | } | ||
679 | if (thisStart === undefined) { | ||
680 | thisStart = 0 | ||
681 | } | ||
682 | if (thisEnd === undefined) { | ||
683 | thisEnd = this.length | ||
684 | } | ||
685 | |||
686 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { | ||
687 | throw new RangeError('out of range index') | ||
688 | } | ||
689 | |||
690 | if (thisStart >= thisEnd && start >= end) { | ||
691 | return 0 | ||
692 | } | ||
693 | if (thisStart >= thisEnd) { | ||
694 | return -1 | ||
695 | } | ||
696 | if (start >= end) { | ||
697 | return 1 | ||
698 | } | ||
699 | |||
700 | start >>>= 0 | ||
701 | end >>>= 0 | ||
702 | thisStart >>>= 0 | ||
703 | thisEnd >>>= 0 | ||
704 | |||
705 | if (this === target) return 0 | ||
706 | |||
707 | var x = thisEnd - thisStart | ||
708 | var y = end - start | ||
709 | var len = Math.min(x, y) | ||
710 | |||
711 | var thisCopy = this.slice(thisStart, thisEnd) | ||
712 | var targetCopy = target.slice(start, end) | ||
713 | |||
714 | for (var i = 0; i < len; ++i) { | ||
715 | if (thisCopy[i] !== targetCopy[i]) { | ||
716 | x = thisCopy[i] | ||
717 | y = targetCopy[i] | ||
718 | break | ||
719 | } | ||
720 | } | ||
721 | |||
722 | if (x < y) return -1 | ||
723 | if (y < x) return 1 | ||
724 | return 0 | ||
725 | } | ||
726 | |||
727 | // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, | ||
728 | // OR the last index of `val` in `buffer` at offset <= `byteOffset`. | ||
729 | // | ||
730 | // Arguments: | ||
731 | // - buffer - a Buffer to search | ||
732 | // - val - a string, Buffer, or number | ||
733 | // - byteOffset - an index into `buffer`; will be clamped to an int32 | ||
734 | // - encoding - an optional encoding, relevant is val is a string | ||
735 | // - dir - true for indexOf, false for lastIndexOf | ||
736 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { | ||
737 | // Empty buffer means no match | ||
738 | if (buffer.length === 0) return -1 | ||
739 | |||
740 | // Normalize byteOffset | ||
741 | if (typeof byteOffset === 'string') { | ||
742 | encoding = byteOffset | ||
743 | byteOffset = 0 | ||
744 | } else if (byteOffset > 0x7fffffff) { | ||
745 | byteOffset = 0x7fffffff | ||
746 | } else if (byteOffset < -0x80000000) { | ||
747 | byteOffset = -0x80000000 | ||
748 | } | ||
749 | byteOffset = +byteOffset // Coerce to Number. | ||
750 | if (numberIsNaN(byteOffset)) { | ||
751 | // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
752 | byteOffset = dir ? 0 : (buffer.length - 1) | ||
753 | } | ||
754 | |||
755 | // Normalize byteOffset: negative offsets start from the end of the buffer | ||
756 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset | ||
757 | if (byteOffset >= buffer.length) { | ||
758 | if (dir) return -1 | ||
759 | else byteOffset = buffer.length - 1 | ||
760 | } else if (byteOffset < 0) { | ||
761 | if (dir) byteOffset = 0 | ||
762 | else return -1 | ||
763 | } | ||
764 | |||
765 | // Normalize val | ||
766 | if (typeof val === 'string') { | ||
767 | val = Buffer.from(val, encoding) | ||
768 | } | ||
769 | |||
770 | // Finally, search either indexOf (if dir is true) or lastIndexOf | ||
771 | if (Buffer.isBuffer(val)) { | ||
772 | // Special case: looking for empty string/buffer always fails | ||
773 | if (val.length === 0) { | ||
774 | return -1 | ||
775 | } | ||
776 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir) | ||
777 | } else if (typeof val === 'number') { | ||
778 | val = val & 0xFF // Search for a byte value [0-255] | ||
779 | if (typeof Uint8Array.prototype.indexOf === 'function') { | ||
780 | if (dir) { | ||
781 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) | ||
782 | } else { | ||
783 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) | ||
784 | } | ||
785 | } | ||
786 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) | ||
787 | } | ||
788 | |||
789 | throw new TypeError('val must be string, number or Buffer') | ||
790 | } | ||
791 | |||
792 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) { | ||
793 | var indexSize = 1 | ||
794 | var arrLength = arr.length | ||
795 | var valLength = val.length | ||
796 | |||
797 | if (encoding !== undefined) { | ||
798 | encoding = String(encoding).toLowerCase() | ||
799 | if (encoding === 'ucs2' || encoding === 'ucs-2' || | ||
800 | encoding === 'utf16le' || encoding === 'utf-16le') { | ||
801 | if (arr.length < 2 || val.length < 2) { | ||
802 | return -1 | ||
803 | } | ||
804 | indexSize = 2 | ||
805 | arrLength /= 2 | ||
806 | valLength /= 2 | ||
807 | byteOffset /= 2 | ||
808 | } | ||
809 | } | ||
810 | |||
811 | function read (buf, i) { | ||
812 | if (indexSize === 1) { | ||
813 | return buf[i] | ||
814 | } else { | ||
815 | return buf.readUInt16BE(i * indexSize) | ||
816 | } | ||
817 | } | ||
818 | |||
819 | var i | ||
820 | if (dir) { | ||
821 | var foundIndex = -1 | ||
822 | for (i = byteOffset; i < arrLength; i++) { | ||
823 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { | ||
824 | if (foundIndex === -1) foundIndex = i | ||
825 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize | ||
826 | } else { | ||
827 | if (foundIndex !== -1) i -= i - foundIndex | ||
828 | foundIndex = -1 | ||
829 | } | ||
830 | } | ||
831 | } else { | ||
832 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength | ||
833 | for (i = byteOffset; i >= 0; i--) { | ||
834 | var found = true | ||
835 | for (var j = 0; j < valLength; j++) { | ||
836 | if (read(arr, i + j) !== read(val, j)) { | ||
837 | found = false | ||
838 | break | ||
839 | } | ||
840 | } | ||
841 | if (found) return i | ||
842 | } | ||
843 | } | ||
844 | |||
845 | return -1 | ||
846 | } | ||
847 | |||
848 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) { | ||
849 | return this.indexOf(val, byteOffset, encoding) !== -1 | ||
850 | } | ||
851 | |||
852 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { | ||
853 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true) | ||
854 | } | ||
855 | |||
856 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { | ||
857 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false) | ||
858 | } | ||
859 | |||
860 | function hexWrite (buf, string, offset, length) { | ||
861 | offset = Number(offset) || 0 | ||
862 | var remaining = buf.length - offset | ||
863 | if (!length) { | ||
864 | length = remaining | ||
865 | } else { | ||
866 | length = Number(length) | ||
867 | if (length > remaining) { | ||
868 | length = remaining | ||
869 | } | ||
870 | } | ||
871 | |||
872 | // must be an even number of digits | ||
873 | var strLen = string.length | ||
874 | if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') | ||
875 | |||
876 | if (length > strLen / 2) { | ||
877 | length = strLen / 2 | ||
878 | } | ||
879 | for (var i = 0; i < length; ++i) { | ||
880 | var parsed = parseInt(string.substr(i * 2, 2), 16) | ||
881 | if (numberIsNaN(parsed)) return i | ||
882 | buf[offset + i] = parsed | ||
883 | } | ||
884 | return i | ||
885 | } | ||
886 | |||
887 | function utf8Write (buf, string, offset, length) { | ||
888 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | ||
889 | } | ||
890 | |||
891 | function asciiWrite (buf, string, offset, length) { | ||
892 | return blitBuffer(asciiToBytes(string), buf, offset, length) | ||
893 | } | ||
894 | |||
895 | function latin1Write (buf, string, offset, length) { | ||
896 | return asciiWrite(buf, string, offset, length) | ||
897 | } | ||
898 | |||
899 | function base64Write (buf, string, offset, length) { | ||
900 | return blitBuffer(base64ToBytes(string), buf, offset, length) | ||
901 | } | ||
902 | |||
903 | function ucs2Write (buf, string, offset, length) { | ||
904 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | ||
905 | } | ||
906 | |||
907 | Buffer.prototype.write = function write (string, offset, length, encoding) { | ||
908 | // Buffer#write(string) | ||
909 | if (offset === undefined) { | ||
910 | encoding = 'utf8' | ||
911 | length = this.length | ||
912 | offset = 0 | ||
913 | // Buffer#write(string, encoding) | ||
914 | } else if (length === undefined && typeof offset === 'string') { | ||
915 | encoding = offset | ||
916 | length = this.length | ||
917 | offset = 0 | ||
918 | // Buffer#write(string, offset[, length][, encoding]) | ||
919 | } else if (isFinite(offset)) { | ||
920 | offset = offset >>> 0 | ||
921 | if (isFinite(length)) { | ||
922 | length = length >>> 0 | ||
923 | if (encoding === undefined) encoding = 'utf8' | ||
924 | } else { | ||
925 | encoding = length | ||
926 | length = undefined | ||
927 | } | ||
928 | } else { | ||
929 | throw new Error( | ||
930 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported' | ||
931 | ) | ||
932 | } | ||
933 | |||
934 | var remaining = this.length - offset | ||
935 | if (length === undefined || length > remaining) length = remaining | ||
936 | |||
937 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | ||
938 | throw new RangeError('Attempt to write outside buffer bounds') | ||
939 | } | ||
940 | |||
941 | if (!encoding) encoding = 'utf8' | ||
942 | |||
943 | var loweredCase = false | ||
944 | for (;;) { | ||
945 | switch (encoding) { | ||
946 | case 'hex': | ||
947 | return hexWrite(this, string, offset, length) | ||
948 | |||
949 | case 'utf8': | ||
950 | case 'utf-8': | ||
951 | return utf8Write(this, string, offset, length) | ||
952 | |||
953 | case 'ascii': | ||
954 | return asciiWrite(this, string, offset, length) | ||
955 | |||
956 | case 'latin1': | ||
957 | case 'binary': | ||
958 | return latin1Write(this, string, offset, length) | ||
959 | |||
960 | case 'base64': | ||
961 | // Warning: maxLength not taken into account in base64Write | ||
962 | return base64Write(this, string, offset, length) | ||
963 | |||
964 | case 'ucs2': | ||
965 | case 'ucs-2': | ||
966 | case 'utf16le': | ||
967 | case 'utf-16le': | ||
968 | return ucs2Write(this, string, offset, length) | ||
969 | |||
970 | default: | ||
971 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
972 | encoding = ('' + encoding).toLowerCase() | ||
973 | loweredCase = true | ||
974 | } | ||
975 | } | ||
976 | } | ||
977 | |||
978 | Buffer.prototype.toJSON = function toJSON () { | ||
979 | return { | ||
980 | type: 'Buffer', | ||
981 | data: Array.prototype.slice.call(this._arr || this, 0) | ||
982 | } | ||
983 | } | ||
984 | |||
985 | function base64Slice (buf, start, end) { | ||
986 | if (start === 0 && end === buf.length) { | ||
987 | return base64.fromByteArray(buf) | ||
988 | } else { | ||
989 | return base64.fromByteArray(buf.slice(start, end)) | ||
990 | } | ||
991 | } | ||
992 | |||
993 | function utf8Slice (buf, start, end) { | ||
994 | end = Math.min(buf.length, end) | ||
995 | var res = [] | ||
996 | |||
997 | var i = start | ||
998 | while (i < end) { | ||
999 | var firstByte = buf[i] | ||
1000 | var codePoint = null | ||
1001 | var bytesPerSequence = (firstByte > 0xEF) ? 4 | ||
1002 | : (firstByte > 0xDF) ? 3 | ||
1003 | : (firstByte > 0xBF) ? 2 | ||
1004 | : 1 | ||
1005 | |||
1006 | if (i + bytesPerSequence <= end) { | ||
1007 | var secondByte, thirdByte, fourthByte, tempCodePoint | ||
1008 | |||
1009 | switch (bytesPerSequence) { | ||
1010 | case 1: | ||
1011 | if (firstByte < 0x80) { | ||
1012 | codePoint = firstByte | ||
1013 | } | ||
1014 | break | ||
1015 | case 2: | ||
1016 | secondByte = buf[i + 1] | ||
1017 | if ((secondByte & 0xC0) === 0x80) { | ||
1018 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | ||
1019 | if (tempCodePoint > 0x7F) { | ||
1020 | codePoint = tempCodePoint | ||
1021 | } | ||
1022 | } | ||
1023 | break | ||
1024 | case 3: | ||
1025 | secondByte = buf[i + 1] | ||
1026 | thirdByte = buf[i + 2] | ||
1027 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | ||
1028 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | ||
1029 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | ||
1030 | codePoint = tempCodePoint | ||
1031 | } | ||
1032 | } | ||
1033 | break | ||
1034 | case 4: | ||
1035 | secondByte = buf[i + 1] | ||
1036 | thirdByte = buf[i + 2] | ||
1037 | fourthByte = buf[i + 3] | ||
1038 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | ||
1039 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | ||
1040 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | ||
1041 | codePoint = tempCodePoint | ||
1042 | } | ||
1043 | } | ||
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | if (codePoint === null) { | ||
1048 | // we did not generate a valid codePoint so insert a | ||
1049 | // replacement char (U+FFFD) and advance only 1 byte | ||
1050 | codePoint = 0xFFFD | ||
1051 | bytesPerSequence = 1 | ||
1052 | } else if (codePoint > 0xFFFF) { | ||
1053 | // encode to utf16 (surrogate pair dance) | ||
1054 | codePoint -= 0x10000 | ||
1055 | res.push(codePoint >>> 10 & 0x3FF | 0xD800) | ||
1056 | codePoint = 0xDC00 | codePoint & 0x3FF | ||
1057 | } | ||
1058 | |||
1059 | res.push(codePoint) | ||
1060 | i += bytesPerSequence | ||
1061 | } | ||
1062 | |||
1063 | return decodeCodePointsArray(res) | ||
1064 | } | ||
1065 | |||
1066 | // Based on http://stackoverflow.com/a/22747272/680742, the browser with | ||
1067 | // the lowest limit is Chrome, with 0x10000 args. | ||
1068 | // We go 1 magnitude less, for safety | ||
1069 | var MAX_ARGUMENTS_LENGTH = 0x1000 | ||
1070 | |||
1071 | function decodeCodePointsArray (codePoints) { | ||
1072 | var len = codePoints.length | ||
1073 | if (len <= MAX_ARGUMENTS_LENGTH) { | ||
1074 | return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | ||
1075 | } | ||
1076 | |||
1077 | // Decode in chunks to avoid "call stack size exceeded". | ||
1078 | var res = '' | ||
1079 | var i = 0 | ||
1080 | while (i < len) { | ||
1081 | res += String.fromCharCode.apply( | ||
1082 | String, | ||
1083 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | ||
1084 | ) | ||
1085 | } | ||
1086 | return res | ||
1087 | } | ||
1088 | |||
1089 | function asciiSlice (buf, start, end) { | ||
1090 | var ret = '' | ||
1091 | end = Math.min(buf.length, end) | ||
1092 | |||
1093 | for (var i = start; i < end; ++i) { | ||
1094 | ret += String.fromCharCode(buf[i] & 0x7F) | ||
1095 | } | ||
1096 | return ret | ||
1097 | } | ||
1098 | |||
1099 | function latin1Slice (buf, start, end) { | ||
1100 | var ret = '' | ||
1101 | end = Math.min(buf.length, end) | ||
1102 | |||
1103 | for (var i = start; i < end; ++i) { | ||
1104 | ret += String.fromCharCode(buf[i]) | ||
1105 | } | ||
1106 | return ret | ||
1107 | } | ||
1108 | |||
1109 | function hexSlice (buf, start, end) { | ||
1110 | var len = buf.length | ||
1111 | |||
1112 | if (!start || start < 0) start = 0 | ||
1113 | if (!end || end < 0 || end > len) end = len | ||
1114 | |||
1115 | var out = '' | ||
1116 | for (var i = start; i < end; ++i) { | ||
1117 | out += toHex(buf[i]) | ||
1118 | } | ||
1119 | return out | ||
1120 | } | ||
1121 | |||
1122 | function utf16leSlice (buf, start, end) { | ||
1123 | var bytes = buf.slice(start, end) | ||
1124 | var res = '' | ||
1125 | for (var i = 0; i < bytes.length; i += 2) { | ||
1126 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) | ||
1127 | } | ||
1128 | return res | ||
1129 | } | ||
1130 | |||
1131 | Buffer.prototype.slice = function slice (start, end) { | ||
1132 | var len = this.length | ||
1133 | start = ~~start | ||
1134 | end = end === undefined ? len : ~~end | ||
1135 | |||
1136 | if (start < 0) { | ||
1137 | start += len | ||
1138 | if (start < 0) start = 0 | ||
1139 | } else if (start > len) { | ||
1140 | start = len | ||
1141 | } | ||
1142 | |||
1143 | if (end < 0) { | ||
1144 | end += len | ||
1145 | if (end < 0) end = 0 | ||
1146 | } else if (end > len) { | ||
1147 | end = len | ||
1148 | } | ||
1149 | |||
1150 | if (end < start) end = start | ||
1151 | |||
1152 | var newBuf = this.subarray(start, end) | ||
1153 | // Return an augmented `Uint8Array` instance | ||
1154 | newBuf.__proto__ = Buffer.prototype | ||
1155 | return newBuf | ||
1156 | } | ||
1157 | |||
1158 | /* | ||
1159 | * Need to make sure that buffer isn't trying to write out of bounds. | ||
1160 | */ | ||
1161 | function checkOffset (offset, ext, length) { | ||
1162 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | ||
1163 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | ||
1164 | } | ||
1165 | |||
1166 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { | ||
1167 | offset = offset >>> 0 | ||
1168 | byteLength = byteLength >>> 0 | ||
1169 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1170 | |||
1171 | var val = this[offset] | ||
1172 | var mul = 1 | ||
1173 | var i = 0 | ||
1174 | while (++i < byteLength && (mul *= 0x100)) { | ||
1175 | val += this[offset + i] * mul | ||
1176 | } | ||
1177 | |||
1178 | return val | ||
1179 | } | ||
1180 | |||
1181 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { | ||
1182 | offset = offset >>> 0 | ||
1183 | byteLength = byteLength >>> 0 | ||
1184 | if (!noAssert) { | ||
1185 | checkOffset(offset, byteLength, this.length) | ||
1186 | } | ||
1187 | |||
1188 | var val = this[offset + --byteLength] | ||
1189 | var mul = 1 | ||
1190 | while (byteLength > 0 && (mul *= 0x100)) { | ||
1191 | val += this[offset + --byteLength] * mul | ||
1192 | } | ||
1193 | |||
1194 | return val | ||
1195 | } | ||
1196 | |||
1197 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { | ||
1198 | offset = offset >>> 0 | ||
1199 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
1200 | return this[offset] | ||
1201 | } | ||
1202 | |||
1203 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { | ||
1204 | offset = offset >>> 0 | ||
1205 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1206 | return this[offset] | (this[offset + 1] << 8) | ||
1207 | } | ||
1208 | |||
1209 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { | ||
1210 | offset = offset >>> 0 | ||
1211 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1212 | return (this[offset] << 8) | this[offset + 1] | ||
1213 | } | ||
1214 | |||
1215 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { | ||
1216 | offset = offset >>> 0 | ||
1217 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1218 | |||
1219 | return ((this[offset]) | | ||
1220 | (this[offset + 1] << 8) | | ||
1221 | (this[offset + 2] << 16)) + | ||
1222 | (this[offset + 3] * 0x1000000) | ||
1223 | } | ||
1224 | |||
1225 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { | ||
1226 | offset = offset >>> 0 | ||
1227 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1228 | |||
1229 | return (this[offset] * 0x1000000) + | ||
1230 | ((this[offset + 1] << 16) | | ||
1231 | (this[offset + 2] << 8) | | ||
1232 | this[offset + 3]) | ||
1233 | } | ||
1234 | |||
1235 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { | ||
1236 | offset = offset >>> 0 | ||
1237 | byteLength = byteLength >>> 0 | ||
1238 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1239 | |||
1240 | var val = this[offset] | ||
1241 | var mul = 1 | ||
1242 | var i = 0 | ||
1243 | while (++i < byteLength && (mul *= 0x100)) { | ||
1244 | val += this[offset + i] * mul | ||
1245 | } | ||
1246 | mul *= 0x80 | ||
1247 | |||
1248 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
1249 | |||
1250 | return val | ||
1251 | } | ||
1252 | |||
1253 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { | ||
1254 | offset = offset >>> 0 | ||
1255 | byteLength = byteLength >>> 0 | ||
1256 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1257 | |||
1258 | var i = byteLength | ||
1259 | var mul = 1 | ||
1260 | var val = this[offset + --i] | ||
1261 | while (i > 0 && (mul *= 0x100)) { | ||
1262 | val += this[offset + --i] * mul | ||
1263 | } | ||
1264 | mul *= 0x80 | ||
1265 | |||
1266 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
1267 | |||
1268 | return val | ||
1269 | } | ||
1270 | |||
1271 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { | ||
1272 | offset = offset >>> 0 | ||
1273 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
1274 | if (!(this[offset] & 0x80)) return (this[offset]) | ||
1275 | return ((0xff - this[offset] + 1) * -1) | ||
1276 | } | ||
1277 | |||
1278 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { | ||
1279 | offset = offset >>> 0 | ||
1280 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1281 | var val = this[offset] | (this[offset + 1] << 8) | ||
1282 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
1283 | } | ||
1284 | |||
1285 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { | ||
1286 | offset = offset >>> 0 | ||
1287 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1288 | var val = this[offset + 1] | (this[offset] << 8) | ||
1289 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
1290 | } | ||
1291 | |||
1292 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { | ||
1293 | offset = offset >>> 0 | ||
1294 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1295 | |||
1296 | return (this[offset]) | | ||
1297 | (this[offset + 1] << 8) | | ||
1298 | (this[offset + 2] << 16) | | ||
1299 | (this[offset + 3] << 24) | ||
1300 | } | ||
1301 | |||
1302 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { | ||
1303 | offset = offset >>> 0 | ||
1304 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1305 | |||
1306 | return (this[offset] << 24) | | ||
1307 | (this[offset + 1] << 16) | | ||
1308 | (this[offset + 2] << 8) | | ||
1309 | (this[offset + 3]) | ||
1310 | } | ||
1311 | |||
1312 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { | ||
1313 | offset = offset >>> 0 | ||
1314 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1315 | return ieee754.read(this, offset, true, 23, 4) | ||
1316 | } | ||
1317 | |||
1318 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { | ||
1319 | offset = offset >>> 0 | ||
1320 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1321 | return ieee754.read(this, offset, false, 23, 4) | ||
1322 | } | ||
1323 | |||
1324 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { | ||
1325 | offset = offset >>> 0 | ||
1326 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
1327 | return ieee754.read(this, offset, true, 52, 8) | ||
1328 | } | ||
1329 | |||
1330 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { | ||
1331 | offset = offset >>> 0 | ||
1332 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
1333 | return ieee754.read(this, offset, false, 52, 8) | ||
1334 | } | ||
1335 | |||
1336 | function checkInt (buf, value, offset, ext, max, min) { | ||
1337 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') | ||
1338 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') | ||
1339 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
1340 | } | ||
1341 | |||
1342 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { | ||
1343 | value = +value | ||
1344 | offset = offset >>> 0 | ||
1345 | byteLength = byteLength >>> 0 | ||
1346 | if (!noAssert) { | ||
1347 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
1348 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
1349 | } | ||
1350 | |||
1351 | var mul = 1 | ||
1352 | var i = 0 | ||
1353 | this[offset] = value & 0xFF | ||
1354 | while (++i < byteLength && (mul *= 0x100)) { | ||
1355 | this[offset + i] = (value / mul) & 0xFF | ||
1356 | } | ||
1357 | |||
1358 | return offset + byteLength | ||
1359 | } | ||
1360 | |||
1361 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { | ||
1362 | value = +value | ||
1363 | offset = offset >>> 0 | ||
1364 | byteLength = byteLength >>> 0 | ||
1365 | if (!noAssert) { | ||
1366 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
1367 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
1368 | } | ||
1369 | |||
1370 | var i = byteLength - 1 | ||
1371 | var mul = 1 | ||
1372 | this[offset + i] = value & 0xFF | ||
1373 | while (--i >= 0 && (mul *= 0x100)) { | ||
1374 | this[offset + i] = (value / mul) & 0xFF | ||
1375 | } | ||
1376 | |||
1377 | return offset + byteLength | ||
1378 | } | ||
1379 | |||
1380 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { | ||
1381 | value = +value | ||
1382 | offset = offset >>> 0 | ||
1383 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | ||
1384 | this[offset] = (value & 0xff) | ||
1385 | return offset + 1 | ||
1386 | } | ||
1387 | |||
1388 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { | ||
1389 | value = +value | ||
1390 | offset = offset >>> 0 | ||
1391 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
1392 | this[offset] = (value & 0xff) | ||
1393 | this[offset + 1] = (value >>> 8) | ||
1394 | return offset + 2 | ||
1395 | } | ||
1396 | |||
1397 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { | ||
1398 | value = +value | ||
1399 | offset = offset >>> 0 | ||
1400 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
1401 | this[offset] = (value >>> 8) | ||
1402 | this[offset + 1] = (value & 0xff) | ||
1403 | return offset + 2 | ||
1404 | } | ||
1405 | |||
1406 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { | ||
1407 | value = +value | ||
1408 | offset = offset >>> 0 | ||
1409 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
1410 | this[offset + 3] = (value >>> 24) | ||
1411 | this[offset + 2] = (value >>> 16) | ||
1412 | this[offset + 1] = (value >>> 8) | ||
1413 | this[offset] = (value & 0xff) | ||
1414 | return offset + 4 | ||
1415 | } | ||
1416 | |||
1417 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { | ||
1418 | value = +value | ||
1419 | offset = offset >>> 0 | ||
1420 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
1421 | this[offset] = (value >>> 24) | ||
1422 | this[offset + 1] = (value >>> 16) | ||
1423 | this[offset + 2] = (value >>> 8) | ||
1424 | this[offset + 3] = (value & 0xff) | ||
1425 | return offset + 4 | ||
1426 | } | ||
1427 | |||
1428 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { | ||
1429 | value = +value | ||
1430 | offset = offset >>> 0 | ||
1431 | if (!noAssert) { | ||
1432 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
1433 | |||
1434 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
1435 | } | ||
1436 | |||
1437 | var i = 0 | ||
1438 | var mul = 1 | ||
1439 | var sub = 0 | ||
1440 | this[offset] = value & 0xFF | ||
1441 | while (++i < byteLength && (mul *= 0x100)) { | ||
1442 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | ||
1443 | sub = 1 | ||
1444 | } | ||
1445 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
1446 | } | ||
1447 | |||
1448 | return offset + byteLength | ||
1449 | } | ||
1450 | |||
1451 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { | ||
1452 | value = +value | ||
1453 | offset = offset >>> 0 | ||
1454 | if (!noAssert) { | ||
1455 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
1456 | |||
1457 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
1458 | } | ||
1459 | |||
1460 | var i = byteLength - 1 | ||
1461 | var mul = 1 | ||
1462 | var sub = 0 | ||
1463 | this[offset + i] = value & 0xFF | ||
1464 | while (--i >= 0 && (mul *= 0x100)) { | ||
1465 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | ||
1466 | sub = 1 | ||
1467 | } | ||
1468 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
1469 | } | ||
1470 | |||
1471 | return offset + byteLength | ||
1472 | } | ||
1473 | |||
1474 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { | ||
1475 | value = +value | ||
1476 | offset = offset >>> 0 | ||
1477 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | ||
1478 | if (value < 0) value = 0xff + value + 1 | ||
1479 | this[offset] = (value & 0xff) | ||
1480 | return offset + 1 | ||
1481 | } | ||
1482 | |||
1483 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { | ||
1484 | value = +value | ||
1485 | offset = offset >>> 0 | ||
1486 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
1487 | this[offset] = (value & 0xff) | ||
1488 | this[offset + 1] = (value >>> 8) | ||
1489 | return offset + 2 | ||
1490 | } | ||
1491 | |||
1492 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { | ||
1493 | value = +value | ||
1494 | offset = offset >>> 0 | ||
1495 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
1496 | this[offset] = (value >>> 8) | ||
1497 | this[offset + 1] = (value & 0xff) | ||
1498 | return offset + 2 | ||
1499 | } | ||
1500 | |||
1501 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { | ||
1502 | value = +value | ||
1503 | offset = offset >>> 0 | ||
1504 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
1505 | this[offset] = (value & 0xff) | ||
1506 | this[offset + 1] = (value >>> 8) | ||
1507 | this[offset + 2] = (value >>> 16) | ||
1508 | this[offset + 3] = (value >>> 24) | ||
1509 | return offset + 4 | ||
1510 | } | ||
1511 | |||
1512 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { | ||
1513 | value = +value | ||
1514 | offset = offset >>> 0 | ||
1515 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
1516 | if (value < 0) value = 0xffffffff + value + 1 | ||
1517 | this[offset] = (value >>> 24) | ||
1518 | this[offset + 1] = (value >>> 16) | ||
1519 | this[offset + 2] = (value >>> 8) | ||
1520 | this[offset + 3] = (value & 0xff) | ||
1521 | return offset + 4 | ||
1522 | } | ||
1523 | |||
1524 | function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
1525 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
1526 | if (offset < 0) throw new RangeError('Index out of range') | ||
1527 | } | ||
1528 | |||
1529 | function writeFloat (buf, value, offset, littleEndian, noAssert) { | ||
1530 | value = +value | ||
1531 | offset = offset >>> 0 | ||
1532 | if (!noAssert) { | ||
1533 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | ||
1534 | } | ||
1535 | ieee754.write(buf, value, offset, littleEndian, 23, 4) | ||
1536 | return offset + 4 | ||
1537 | } | ||
1538 | |||
1539 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { | ||
1540 | return writeFloat(this, value, offset, true, noAssert) | ||
1541 | } | ||
1542 | |||
1543 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { | ||
1544 | return writeFloat(this, value, offset, false, noAssert) | ||
1545 | } | ||
1546 | |||
1547 | function writeDouble (buf, value, offset, littleEndian, noAssert) { | ||
1548 | value = +value | ||
1549 | offset = offset >>> 0 | ||
1550 | if (!noAssert) { | ||
1551 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | ||
1552 | } | ||
1553 | ieee754.write(buf, value, offset, littleEndian, 52, 8) | ||
1554 | return offset + 8 | ||
1555 | } | ||
1556 | |||
1557 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { | ||
1558 | return writeDouble(this, value, offset, true, noAssert) | ||
1559 | } | ||
1560 | |||
1561 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { | ||
1562 | return writeDouble(this, value, offset, false, noAssert) | ||
1563 | } | ||
1564 | |||
1565 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
1566 | Buffer.prototype.copy = function copy (target, targetStart, start, end) { | ||
1567 | if (!start) start = 0 | ||
1568 | if (!end && end !== 0) end = this.length | ||
1569 | if (targetStart >= target.length) targetStart = target.length | ||
1570 | if (!targetStart) targetStart = 0 | ||
1571 | if (end > 0 && end < start) end = start | ||
1572 | |||
1573 | // Copy 0 bytes; we're done | ||
1574 | if (end === start) return 0 | ||
1575 | if (target.length === 0 || this.length === 0) return 0 | ||
1576 | |||
1577 | // Fatal error conditions | ||
1578 | if (targetStart < 0) { | ||
1579 | throw new RangeError('targetStart out of bounds') | ||
1580 | } | ||
1581 | if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') | ||
1582 | if (end < 0) throw new RangeError('sourceEnd out of bounds') | ||
1583 | |||
1584 | // Are we oob? | ||
1585 | if (end > this.length) end = this.length | ||
1586 | if (target.length - targetStart < end - start) { | ||
1587 | end = target.length - targetStart + start | ||
1588 | } | ||
1589 | |||
1590 | var len = end - start | ||
1591 | var i | ||
1592 | |||
1593 | if (this === target && start < targetStart && targetStart < end) { | ||
1594 | // descending copy from end | ||
1595 | for (i = len - 1; i >= 0; --i) { | ||
1596 | target[i + targetStart] = this[i + start] | ||
1597 | } | ||
1598 | } else if (len < 1000) { | ||
1599 | // ascending copy from start | ||
1600 | for (i = 0; i < len; ++i) { | ||
1601 | target[i + targetStart] = this[i + start] | ||
1602 | } | ||
1603 | } else { | ||
1604 | Uint8Array.prototype.set.call( | ||
1605 | target, | ||
1606 | this.subarray(start, start + len), | ||
1607 | targetStart | ||
1608 | ) | ||
1609 | } | ||
1610 | |||
1611 | return len | ||
1612 | } | ||
1613 | |||
1614 | // Usage: | ||
1615 | // buffer.fill(number[, offset[, end]]) | ||
1616 | // buffer.fill(buffer[, offset[, end]]) | ||
1617 | // buffer.fill(string[, offset[, end]][, encoding]) | ||
1618 | Buffer.prototype.fill = function fill (val, start, end, encoding) { | ||
1619 | // Handle string cases: | ||
1620 | if (typeof val === 'string') { | ||
1621 | if (typeof start === 'string') { | ||
1622 | encoding = start | ||
1623 | start = 0 | ||
1624 | end = this.length | ||
1625 | } else if (typeof end === 'string') { | ||
1626 | encoding = end | ||
1627 | end = this.length | ||
1628 | } | ||
1629 | if (val.length === 1) { | ||
1630 | var code = val.charCodeAt(0) | ||
1631 | if (code < 256) { | ||
1632 | val = code | ||
1633 | } | ||
1634 | } | ||
1635 | if (encoding !== undefined && typeof encoding !== 'string') { | ||
1636 | throw new TypeError('encoding must be a string') | ||
1637 | } | ||
1638 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { | ||
1639 | throw new TypeError('Unknown encoding: ' + encoding) | ||
1640 | } | ||
1641 | } else if (typeof val === 'number') { | ||
1642 | val = val & 255 | ||
1643 | } | ||
1644 | |||
1645 | // Invalid ranges are not set to a default, so can range check early. | ||
1646 | if (start < 0 || this.length < start || this.length < end) { | ||
1647 | throw new RangeError('Out of range index') | ||
1648 | } | ||
1649 | |||
1650 | if (end <= start) { | ||
1651 | return this | ||
1652 | } | ||
1653 | |||
1654 | start = start >>> 0 | ||
1655 | end = end === undefined ? this.length : end >>> 0 | ||
1656 | |||
1657 | if (!val) val = 0 | ||
1658 | |||
1659 | var i | ||
1660 | if (typeof val === 'number') { | ||
1661 | for (i = start; i < end; ++i) { | ||
1662 | this[i] = val | ||
1663 | } | ||
1664 | } else { | ||
1665 | var bytes = Buffer.isBuffer(val) | ||
1666 | ? val | ||
1667 | : new Buffer(val, encoding) | ||
1668 | var len = bytes.length | ||
1669 | for (i = 0; i < end - start; ++i) { | ||
1670 | this[i + start] = bytes[i % len] | ||
1671 | } | ||
1672 | } | ||
1673 | |||
1674 | return this | ||
1675 | } | ||
1676 | |||
1677 | // HELPER FUNCTIONS | ||
1678 | // ================ | ||
1679 | |||
1680 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g | ||
1681 | |||
1682 | function base64clean (str) { | ||
1683 | // Node strips out invalid characters like \n and \t from the string, base64-js does not | ||
1684 | str = str.trim().replace(INVALID_BASE64_RE, '') | ||
1685 | // Node converts strings with length < 2 to '' | ||
1686 | if (str.length < 2) return '' | ||
1687 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | ||
1688 | while (str.length % 4 !== 0) { | ||
1689 | str = str + '=' | ||
1690 | } | ||
1691 | return str | ||
1692 | } | ||
1693 | |||
1694 | function toHex (n) { | ||
1695 | if (n < 16) return '0' + n.toString(16) | ||
1696 | return n.toString(16) | ||
1697 | } | ||
1698 | |||
1699 | function utf8ToBytes (string, units) { | ||
1700 | units = units || Infinity | ||
1701 | var codePoint | ||
1702 | var length = string.length | ||
1703 | var leadSurrogate = null | ||
1704 | var bytes = [] | ||
1705 | |||
1706 | for (var i = 0; i < length; ++i) { | ||
1707 | codePoint = string.charCodeAt(i) | ||
1708 | |||
1709 | // is surrogate component | ||
1710 | if (codePoint > 0xD7FF && codePoint < 0xE000) { | ||
1711 | // last char was a lead | ||
1712 | if (!leadSurrogate) { | ||
1713 | // no lead yet | ||
1714 | if (codePoint > 0xDBFF) { | ||
1715 | // unexpected trail | ||
1716 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
1717 | continue | ||
1718 | } else if (i + 1 === length) { | ||
1719 | // unpaired lead | ||
1720 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
1721 | continue | ||
1722 | } | ||
1723 | |||
1724 | // valid lead | ||
1725 | leadSurrogate = codePoint | ||
1726 | |||
1727 | continue | ||
1728 | } | ||
1729 | |||
1730 | // 2 leads in a row | ||
1731 | if (codePoint < 0xDC00) { | ||
1732 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
1733 | leadSurrogate = codePoint | ||
1734 | continue | ||
1735 | } | ||
1736 | |||
1737 | // valid surrogate pair | ||
1738 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 | ||
1739 | } else if (leadSurrogate) { | ||
1740 | // valid bmp char, but last char was a lead | ||
1741 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
1742 | } | ||
1743 | |||
1744 | leadSurrogate = null | ||
1745 | |||
1746 | // encode utf8 | ||
1747 | if (codePoint < 0x80) { | ||
1748 | if ((units -= 1) < 0) break | ||
1749 | bytes.push(codePoint) | ||
1750 | } else if (codePoint < 0x800) { | ||
1751 | if ((units -= 2) < 0) break | ||
1752 | bytes.push( | ||
1753 | codePoint >> 0x6 | 0xC0, | ||
1754 | codePoint & 0x3F | 0x80 | ||
1755 | ) | ||
1756 | } else if (codePoint < 0x10000) { | ||
1757 | if ((units -= 3) < 0) break | ||
1758 | bytes.push( | ||
1759 | codePoint >> 0xC | 0xE0, | ||
1760 | codePoint >> 0x6 & 0x3F | 0x80, | ||
1761 | codePoint & 0x3F | 0x80 | ||
1762 | ) | ||
1763 | } else if (codePoint < 0x110000) { | ||
1764 | if ((units -= 4) < 0) break | ||
1765 | bytes.push( | ||
1766 | codePoint >> 0x12 | 0xF0, | ||
1767 | codePoint >> 0xC & 0x3F | 0x80, | ||
1768 | codePoint >> 0x6 & 0x3F | 0x80, | ||
1769 | codePoint & 0x3F | 0x80 | ||
1770 | ) | ||
1771 | } else { | ||
1772 | throw new Error('Invalid code point') | ||
1773 | } | ||
1774 | } | ||
1775 | |||
1776 | return bytes | ||
1777 | } | ||
1778 | |||
1779 | function asciiToBytes (str) { | ||
1780 | var byteArray = [] | ||
1781 | for (var i = 0; i < str.length; ++i) { | ||
1782 | // Node's code seems to be doing this and not & 0x7F.. | ||
1783 | byteArray.push(str.charCodeAt(i) & 0xFF) | ||
1784 | } | ||
1785 | return byteArray | ||
1786 | } | ||
1787 | |||
1788 | function utf16leToBytes (str, units) { | ||
1789 | var c, hi, lo | ||
1790 | var byteArray = [] | ||
1791 | for (var i = 0; i < str.length; ++i) { | ||
1792 | if ((units -= 2) < 0) break | ||
1793 | |||
1794 | c = str.charCodeAt(i) | ||
1795 | hi = c >> 8 | ||
1796 | lo = c % 256 | ||
1797 | byteArray.push(lo) | ||
1798 | byteArray.push(hi) | ||
1799 | } | ||
1800 | |||
1801 | return byteArray | ||
1802 | } | ||
1803 | |||
1804 | function base64ToBytes (str) { | ||
1805 | return base64.toByteArray(base64clean(str)) | ||
1806 | } | ||
1807 | |||
1808 | function blitBuffer (src, dst, offset, length) { | ||
1809 | for (var i = 0; i < length; ++i) { | ||
1810 | if ((i + offset >= dst.length) || (i >= src.length)) break | ||
1811 | dst[i + offset] = src[i] | ||
1812 | } | ||
1813 | return i | ||
1814 | } | ||
1815 | |||
1816 | // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView` | ||
1817 | function isArrayBufferView (obj) { | ||
1818 | return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj) | ||
1819 | } | ||
1820 | |||
1821 | function numberIsNaN (obj) { | ||
1822 | return obj !== obj // eslint-disable-line no-self-compare | ||
1823 | } | ||
1824 | |||
1825 | },{"base64-js":1,"ieee754":3}],3:[function(require,module,exports){ | ||
1826 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { | ||
1827 | var e, m | ||
1828 | var eLen = nBytes * 8 - mLen - 1 | ||
1829 | var eMax = (1 << eLen) - 1 | ||
1830 | var eBias = eMax >> 1 | ||
1831 | var nBits = -7 | ||
1832 | var i = isLE ? (nBytes - 1) : 0 | ||
1833 | var d = isLE ? -1 : 1 | ||
1834 | var s = buffer[offset + i] | ||
1835 | |||
1836 | i += d | ||
1837 | |||
1838 | e = s & ((1 << (-nBits)) - 1) | ||
1839 | s >>= (-nBits) | ||
1840 | nBits += eLen | ||
1841 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
1842 | |||
1843 | m = e & ((1 << (-nBits)) - 1) | ||
1844 | e >>= (-nBits) | ||
1845 | nBits += mLen | ||
1846 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
1847 | |||
1848 | if (e === 0) { | ||
1849 | e = 1 - eBias | ||
1850 | } else if (e === eMax) { | ||
1851 | return m ? NaN : ((s ? -1 : 1) * Infinity) | ||
1852 | } else { | ||
1853 | m = m + Math.pow(2, mLen) | ||
1854 | e = e - eBias | ||
1855 | } | ||
1856 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | ||
1857 | } | ||
1858 | |||
1859 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | ||
1860 | var e, m, c | ||
1861 | var eLen = nBytes * 8 - mLen - 1 | ||
1862 | var eMax = (1 << eLen) - 1 | ||
1863 | var eBias = eMax >> 1 | ||
1864 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | ||
1865 | var i = isLE ? 0 : (nBytes - 1) | ||
1866 | var d = isLE ? 1 : -1 | ||
1867 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | ||
1868 | |||
1869 | value = Math.abs(value) | ||
1870 | |||
1871 | if (isNaN(value) || value === Infinity) { | ||
1872 | m = isNaN(value) ? 1 : 0 | ||
1873 | e = eMax | ||
1874 | } else { | ||
1875 | e = Math.floor(Math.log(value) / Math.LN2) | ||
1876 | if (value * (c = Math.pow(2, -e)) < 1) { | ||
1877 | e-- | ||
1878 | c *= 2 | ||
1879 | } | ||
1880 | if (e + eBias >= 1) { | ||
1881 | value += rt / c | ||
1882 | } else { | ||
1883 | value += rt * Math.pow(2, 1 - eBias) | ||
1884 | } | ||
1885 | if (value * c >= 2) { | ||
1886 | e++ | ||
1887 | c /= 2 | ||
1888 | } | ||
1889 | |||
1890 | if (e + eBias >= eMax) { | ||
1891 | m = 0 | ||
1892 | e = eMax | ||
1893 | } else if (e + eBias >= 1) { | ||
1894 | m = (value * c - 1) * Math.pow(2, mLen) | ||
1895 | e = e + eBias | ||
1896 | } else { | ||
1897 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | ||
1898 | e = 0 | ||
1899 | } | ||
1900 | } | ||
1901 | |||
1902 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | ||
1903 | |||
1904 | e = (e << mLen) | m | ||
1905 | eLen += mLen | ||
1906 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
1907 | |||
1908 | buffer[offset + i - d] |= s * 128 | ||
1909 | } | ||
1910 | |||
1911 | },{}],4:[function(require,module,exports){ | ||
1912 | window.basex = require('base-x') | ||
1913 | },{"base-x":5}],5:[function(require,module,exports){ | ||
1914 | // base-x encoding | ||
1915 | // Forked from https://github.com/cryptocoinjs/bs58 | ||
1916 | // Originally written by Mike Hearn for BitcoinJ | ||
1917 | // Copyright (c) 2011 Google Inc | ||
1918 | // Ported to JavaScript by Stefan Thomas | ||
1919 | // Merged Buffer refactorings from base58-native by Stephen Pair | ||
1920 | // Copyright (c) 2013 BitPay Inc | ||
1921 | |||
1922 | var Buffer = require('safe-buffer').Buffer | ||
1923 | |||
1924 | module.exports = function base (ALPHABET) { | ||
1925 | var ALPHABET_MAP = {} | ||
1926 | var BASE = ALPHABET.length | ||
1927 | var LEADER = ALPHABET.charAt(0) | ||
1928 | |||
1929 | // pre-compute lookup table | ||
1930 | for (var z = 0; z < ALPHABET.length; z++) { | ||
1931 | var x = ALPHABET.charAt(z) | ||
1932 | |||
1933 | if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous') | ||
1934 | ALPHABET_MAP[x] = z | ||
1935 | } | ||
1936 | |||
1937 | function encode (source) { | ||
1938 | if (source.length === 0) return '' | ||
1939 | |||
1940 | var digits = [0] | ||
1941 | for (var i = 0; i < source.length; ++i) { | ||
1942 | for (var j = 0, carry = source[i]; j < digits.length; ++j) { | ||
1943 | carry += digits[j] << 8 | ||
1944 | digits[j] = carry % BASE | ||
1945 | carry = (carry / BASE) | 0 | ||
1946 | } | ||
1947 | |||
1948 | while (carry > 0) { | ||
1949 | digits.push(carry % BASE) | ||
1950 | carry = (carry / BASE) | 0 | ||
1951 | } | ||
1952 | } | ||
1953 | |||
1954 | var string = '' | ||
1955 | |||
1956 | // deal with leading zeros | ||
1957 | for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += ALPHABET[0] | ||
1958 | // convert digits to a string | ||
1959 | for (var q = digits.length - 1; q >= 0; --q) string += ALPHABET[digits[q]] | ||
1960 | |||
1961 | return string | ||
1962 | } | ||
1963 | |||
1964 | function decodeUnsafe (string) { | ||
1965 | if (string.length === 0) return Buffer.allocUnsafe(0) | ||
1966 | |||
1967 | var bytes = [0] | ||
1968 | for (var i = 0; i < string.length; i++) { | ||
1969 | var value = ALPHABET_MAP[string[i]] | ||
1970 | if (value === undefined) return | ||
1971 | |||
1972 | for (var j = 0, carry = value; j < bytes.length; ++j) { | ||
1973 | carry += bytes[j] * BASE | ||
1974 | bytes[j] = carry & 0xff | ||
1975 | carry >>= 8 | ||
1976 | } | ||
1977 | |||
1978 | while (carry > 0) { | ||
1979 | bytes.push(carry & 0xff) | ||
1980 | carry >>= 8 | ||
1981 | } | ||
1982 | } | ||
1983 | |||
1984 | // deal with leading zeros | ||
1985 | for (var k = 0; string[k] === LEADER && k < string.length - 1; ++k) { | ||
1986 | bytes.push(0) | ||
1987 | } | ||
1988 | |||
1989 | return Buffer.from(bytes.reverse()) | ||
1990 | } | ||
1991 | |||
1992 | function decode (string) { | ||
1993 | var buffer = decodeUnsafe(string) | ||
1994 | if (buffer) return buffer | ||
1995 | |||
1996 | throw new Error('Non-base' + BASE + ' character') | ||
1997 | } | ||
1998 | |||
1999 | return { | ||
2000 | encode: encode, | ||
2001 | decodeUnsafe: decodeUnsafe, | ||
2002 | decode: decode | ||
2003 | } | ||
2004 | } | ||
2005 | |||
2006 | },{"safe-buffer":6}],6:[function(require,module,exports){ | ||
2007 | module.exports = require('buffer') | ||
2008 | |||
2009 | },{"buffer":2}]},{},[4])(4) | ||
2010 | }); \ No newline at end of file | ||
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index b02d79f..ed1bb09 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js | |||
@@ -45,6 +45,16 @@ bitcoin.networks.dash = { | |||
45 | wif: 0xcc, | 45 | wif: 0xcc, |
46 | }; | 46 | }; |
47 | 47 | ||
48 | bitcoin.networks.game = { | ||
49 | bip32: { | ||
50 | public: 0x0488b21e, | ||
51 | private: 0x0488ade4 | ||
52 | }, | ||
53 | pubKeyHash: 0x26, | ||
54 | scriptHash: 0x05, | ||
55 | wif: 0xa6, | ||
56 | }; | ||
57 | |||
48 | bitcoin.networks.namecoin = { | 58 | bitcoin.networks.namecoin = { |
49 | bip32: { | 59 | bip32: { |
50 | public: 0x0488b21e, | 60 | public: 0x0488b21e, |
diff --git a/src/js/ethereumjs-util.js b/src/js/ethereumjs-util.js new file mode 100644 index 0000000..533a0c3 --- /dev/null +++ b/src/js/ethereumjs-util.js | |||
@@ -0,0 +1,18762 @@ | |||
1 | (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){ | ||
2 | (function (global){ | ||
3 | 'use strict'; | ||
4 | |||
5 | // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js | ||
6 | // original notice: | ||
7 | |||
8 | /*! | ||
9 | * The buffer module from node.js, for the browser. | ||
10 | * | ||
11 | * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
12 | * @license MIT | ||
13 | */ | ||
14 | function compare(a, b) { | ||
15 | if (a === b) { | ||
16 | return 0; | ||
17 | } | ||
18 | |||
19 | var x = a.length; | ||
20 | var y = b.length; | ||
21 | |||
22 | for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
23 | if (a[i] !== b[i]) { | ||
24 | x = a[i]; | ||
25 | y = b[i]; | ||
26 | break; | ||
27 | } | ||
28 | } | ||
29 | |||
30 | if (x < y) { | ||
31 | return -1; | ||
32 | } | ||
33 | if (y < x) { | ||
34 | return 1; | ||
35 | } | ||
36 | return 0; | ||
37 | } | ||
38 | function isBuffer(b) { | ||
39 | if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { | ||
40 | return global.Buffer.isBuffer(b); | ||
41 | } | ||
42 | return !!(b != null && b._isBuffer); | ||
43 | } | ||
44 | |||
45 | // based on node assert, original notice: | ||
46 | |||
47 | // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 | ||
48 | // | ||
49 | // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! | ||
50 | // | ||
51 | // Originally from narwhal.js (http://narwhaljs.org) | ||
52 | // Copyright (c) 2009 Thomas Robinson <280north.com> | ||
53 | // | ||
54 | // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
55 | // of this software and associated documentation files (the 'Software'), to | ||
56 | // deal in the Software without restriction, including without limitation the | ||
57 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
58 | // sell copies of the Software, and to permit persons to whom the Software is | ||
59 | // furnished to do so, subject to the following conditions: | ||
60 | // | ||
61 | // The above copyright notice and this permission notice shall be included in | ||
62 | // all copies or substantial portions of the Software. | ||
63 | // | ||
64 | // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
65 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
66 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
67 | // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
68 | // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
69 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
70 | |||
71 | var util = require('util/'); | ||
72 | var hasOwn = Object.prototype.hasOwnProperty; | ||
73 | var pSlice = Array.prototype.slice; | ||
74 | var functionsHaveNames = (function () { | ||
75 | return function foo() {}.name === 'foo'; | ||
76 | }()); | ||
77 | function pToString (obj) { | ||
78 | return Object.prototype.toString.call(obj); | ||
79 | } | ||
80 | function isView(arrbuf) { | ||
81 | if (isBuffer(arrbuf)) { | ||
82 | return false; | ||
83 | } | ||
84 | if (typeof global.ArrayBuffer !== 'function') { | ||
85 | return false; | ||
86 | } | ||
87 | if (typeof ArrayBuffer.isView === 'function') { | ||
88 | return ArrayBuffer.isView(arrbuf); | ||
89 | } | ||
90 | if (!arrbuf) { | ||
91 | return false; | ||
92 | } | ||
93 | if (arrbuf instanceof DataView) { | ||
94 | return true; | ||
95 | } | ||
96 | if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { | ||
97 | return true; | ||
98 | } | ||
99 | return false; | ||
100 | } | ||
101 | // 1. The assert module provides functions that throw | ||
102 | // AssertionError's when particular conditions are not met. The | ||
103 | // assert module must conform to the following interface. | ||
104 | |||
105 | var assert = module.exports = ok; | ||
106 | |||
107 | // 2. The AssertionError is defined in assert. | ||
108 | // new assert.AssertionError({ message: message, | ||
109 | // actual: actual, | ||
110 | // expected: expected }) | ||
111 | |||
112 | var regex = /\s*function\s+([^\(\s]*)\s*/; | ||
113 | // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js | ||
114 | function getName(func) { | ||
115 | if (!util.isFunction(func)) { | ||
116 | return; | ||
117 | } | ||
118 | if (functionsHaveNames) { | ||
119 | return func.name; | ||
120 | } | ||
121 | var str = func.toString(); | ||
122 | var match = str.match(regex); | ||
123 | return match && match[1]; | ||
124 | } | ||
125 | assert.AssertionError = function AssertionError(options) { | ||
126 | this.name = 'AssertionError'; | ||
127 | this.actual = options.actual; | ||
128 | this.expected = options.expected; | ||
129 | this.operator = options.operator; | ||
130 | if (options.message) { | ||
131 | this.message = options.message; | ||
132 | this.generatedMessage = false; | ||
133 | } else { | ||
134 | this.message = getMessage(this); | ||
135 | this.generatedMessage = true; | ||
136 | } | ||
137 | var stackStartFunction = options.stackStartFunction || fail; | ||
138 | if (Error.captureStackTrace) { | ||
139 | Error.captureStackTrace(this, stackStartFunction); | ||
140 | } else { | ||
141 | // non v8 browsers so we can have a stacktrace | ||
142 | var err = new Error(); | ||
143 | if (err.stack) { | ||
144 | var out = err.stack; | ||
145 | |||
146 | // try to strip useless frames | ||
147 | var fn_name = getName(stackStartFunction); | ||
148 | var idx = out.indexOf('\n' + fn_name); | ||
149 | if (idx >= 0) { | ||
150 | // once we have located the function frame | ||
151 | // we need to strip out everything before it (and its line) | ||
152 | var next_line = out.indexOf('\n', idx + 1); | ||
153 | out = out.substring(next_line + 1); | ||
154 | } | ||
155 | |||
156 | this.stack = out; | ||
157 | } | ||
158 | } | ||
159 | }; | ||
160 | |||
161 | // assert.AssertionError instanceof Error | ||
162 | util.inherits(assert.AssertionError, Error); | ||
163 | |||
164 | function truncate(s, n) { | ||
165 | if (typeof s === 'string') { | ||
166 | return s.length < n ? s : s.slice(0, n); | ||
167 | } else { | ||
168 | return s; | ||
169 | } | ||
170 | } | ||
171 | function inspect(something) { | ||
172 | if (functionsHaveNames || !util.isFunction(something)) { | ||
173 | return util.inspect(something); | ||
174 | } | ||
175 | var rawname = getName(something); | ||
176 | var name = rawname ? ': ' + rawname : ''; | ||
177 | return '[Function' + name + ']'; | ||
178 | } | ||
179 | function getMessage(self) { | ||
180 | return truncate(inspect(self.actual), 128) + ' ' + | ||
181 | self.operator + ' ' + | ||
182 | truncate(inspect(self.expected), 128); | ||
183 | } | ||
184 | |||
185 | // At present only the three keys mentioned above are used and | ||
186 | // understood by the spec. Implementations or sub modules can pass | ||
187 | // other keys to the AssertionError's constructor - they will be | ||
188 | // ignored. | ||
189 | |||
190 | // 3. All of the following functions must throw an AssertionError | ||
191 | // when a corresponding condition is not met, with a message that | ||
192 | // may be undefined if not provided. All assertion methods provide | ||
193 | // both the actual and expected values to the assertion error for | ||
194 | // display purposes. | ||
195 | |||
196 | function fail(actual, expected, message, operator, stackStartFunction) { | ||
197 | throw new assert.AssertionError({ | ||
198 | message: message, | ||
199 | actual: actual, | ||
200 | expected: expected, | ||
201 | operator: operator, | ||
202 | stackStartFunction: stackStartFunction | ||
203 | }); | ||
204 | } | ||
205 | |||
206 | // EXTENSION! allows for well behaved errors defined elsewhere. | ||
207 | assert.fail = fail; | ||
208 | |||
209 | // 4. Pure assertion tests whether a value is truthy, as determined | ||
210 | // by !!guard. | ||
211 | // assert.ok(guard, message_opt); | ||
212 | // This statement is equivalent to assert.equal(true, !!guard, | ||
213 | // message_opt);. To test strictly for the value true, use | ||
214 | // assert.strictEqual(true, guard, message_opt);. | ||
215 | |||
216 | function ok(value, message) { | ||
217 | if (!value) fail(value, true, message, '==', assert.ok); | ||
218 | } | ||
219 | assert.ok = ok; | ||
220 | |||
221 | // 5. The equality assertion tests shallow, coercive equality with | ||
222 | // ==. | ||
223 | // assert.equal(actual, expected, message_opt); | ||
224 | |||
225 | assert.equal = function equal(actual, expected, message) { | ||
226 | if (actual != expected) fail(actual, expected, message, '==', assert.equal); | ||
227 | }; | ||
228 | |||
229 | // 6. The non-equality assertion tests for whether two objects are not equal | ||
230 | // with != assert.notEqual(actual, expected, message_opt); | ||
231 | |||
232 | assert.notEqual = function notEqual(actual, expected, message) { | ||
233 | if (actual == expected) { | ||
234 | fail(actual, expected, message, '!=', assert.notEqual); | ||
235 | } | ||
236 | }; | ||
237 | |||
238 | // 7. The equivalence assertion tests a deep equality relation. | ||
239 | // assert.deepEqual(actual, expected, message_opt); | ||
240 | |||
241 | assert.deepEqual = function deepEqual(actual, expected, message) { | ||
242 | if (!_deepEqual(actual, expected, false)) { | ||
243 | fail(actual, expected, message, 'deepEqual', assert.deepEqual); | ||
244 | } | ||
245 | }; | ||
246 | |||
247 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | ||
248 | if (!_deepEqual(actual, expected, true)) { | ||
249 | fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); | ||
250 | } | ||
251 | }; | ||
252 | |||
253 | function _deepEqual(actual, expected, strict, memos) { | ||
254 | // 7.1. All identical values are equivalent, as determined by ===. | ||
255 | if (actual === expected) { | ||
256 | return true; | ||
257 | } else if (isBuffer(actual) && isBuffer(expected)) { | ||
258 | return compare(actual, expected) === 0; | ||
259 | |||
260 | // 7.2. If the expected value is a Date object, the actual value is | ||
261 | // equivalent if it is also a Date object that refers to the same time. | ||
262 | } else if (util.isDate(actual) && util.isDate(expected)) { | ||
263 | return actual.getTime() === expected.getTime(); | ||
264 | |||
265 | // 7.3 If the expected value is a RegExp object, the actual value is | ||
266 | // equivalent if it is also a RegExp object with the same source and | ||
267 | // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). | ||
268 | } else if (util.isRegExp(actual) && util.isRegExp(expected)) { | ||
269 | return actual.source === expected.source && | ||
270 | actual.global === expected.global && | ||
271 | actual.multiline === expected.multiline && | ||
272 | actual.lastIndex === expected.lastIndex && | ||
273 | actual.ignoreCase === expected.ignoreCase; | ||
274 | |||
275 | // 7.4. Other pairs that do not both pass typeof value == 'object', | ||
276 | // equivalence is determined by ==. | ||
277 | } else if ((actual === null || typeof actual !== 'object') && | ||
278 | (expected === null || typeof expected !== 'object')) { | ||
279 | return strict ? actual === expected : actual == expected; | ||
280 | |||
281 | // If both values are instances of typed arrays, wrap their underlying | ||
282 | // ArrayBuffers in a Buffer each to increase performance | ||
283 | // This optimization requires the arrays to have the same type as checked by | ||
284 | // Object.prototype.toString (aka pToString). Never perform binary | ||
285 | // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their | ||
286 | // bit patterns are not identical. | ||
287 | } else if (isView(actual) && isView(expected) && | ||
288 | pToString(actual) === pToString(expected) && | ||
289 | !(actual instanceof Float32Array || | ||
290 | actual instanceof Float64Array)) { | ||
291 | return compare(new Uint8Array(actual.buffer), | ||
292 | new Uint8Array(expected.buffer)) === 0; | ||
293 | |||
294 | // 7.5 For all other Object pairs, including Array objects, equivalence is | ||
295 | // determined by having the same number of owned properties (as verified | ||
296 | // with Object.prototype.hasOwnProperty.call), the same set of keys | ||
297 | // (although not necessarily the same order), equivalent values for every | ||
298 | // corresponding key, and an identical 'prototype' property. Note: this | ||
299 | // accounts for both named and indexed properties on Arrays. | ||
300 | } else if (isBuffer(actual) !== isBuffer(expected)) { | ||
301 | return false; | ||
302 | } else { | ||
303 | memos = memos || {actual: [], expected: []}; | ||
304 | |||
305 | var actualIndex = memos.actual.indexOf(actual); | ||
306 | if (actualIndex !== -1) { | ||
307 | if (actualIndex === memos.expected.indexOf(expected)) { | ||
308 | return true; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | memos.actual.push(actual); | ||
313 | memos.expected.push(expected); | ||
314 | |||
315 | return objEquiv(actual, expected, strict, memos); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | function isArguments(object) { | ||
320 | return Object.prototype.toString.call(object) == '[object Arguments]'; | ||
321 | } | ||
322 | |||
323 | function objEquiv(a, b, strict, actualVisitedObjects) { | ||
324 | if (a === null || a === undefined || b === null || b === undefined) | ||
325 | return false; | ||
326 | // if one is a primitive, the other must be same | ||
327 | if (util.isPrimitive(a) || util.isPrimitive(b)) | ||
328 | return a === b; | ||
329 | if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) | ||
330 | return false; | ||
331 | var aIsArgs = isArguments(a); | ||
332 | var bIsArgs = isArguments(b); | ||
333 | if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) | ||
334 | return false; | ||
335 | if (aIsArgs) { | ||
336 | a = pSlice.call(a); | ||
337 | b = pSlice.call(b); | ||
338 | return _deepEqual(a, b, strict); | ||
339 | } | ||
340 | var ka = objectKeys(a); | ||
341 | var kb = objectKeys(b); | ||
342 | var key, i; | ||
343 | // having the same number of owned properties (keys incorporates | ||
344 | // hasOwnProperty) | ||
345 | if (ka.length !== kb.length) | ||
346 | return false; | ||
347 | //the same set of keys (although not necessarily the same order), | ||
348 | ka.sort(); | ||
349 | kb.sort(); | ||
350 | //~~~cheap key test | ||
351 | for (i = ka.length - 1; i >= 0; i--) { | ||
352 | if (ka[i] !== kb[i]) | ||
353 | return false; | ||
354 | } | ||
355 | //equivalent values for every corresponding key, and | ||
356 | //~~~possibly expensive deep test | ||
357 | for (i = ka.length - 1; i >= 0; i--) { | ||
358 | key = ka[i]; | ||
359 | if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) | ||
360 | return false; | ||
361 | } | ||
362 | return true; | ||
363 | } | ||
364 | |||
365 | // 8. The non-equivalence assertion tests for any deep inequality. | ||
366 | // assert.notDeepEqual(actual, expected, message_opt); | ||
367 | |||
368 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | ||
369 | if (_deepEqual(actual, expected, false)) { | ||
370 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); | ||
371 | } | ||
372 | }; | ||
373 | |||
374 | assert.notDeepStrictEqual = notDeepStrictEqual; | ||
375 | function notDeepStrictEqual(actual, expected, message) { | ||
376 | if (_deepEqual(actual, expected, true)) { | ||
377 | fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); | ||
378 | } | ||
379 | } | ||
380 | |||
381 | |||
382 | // 9. The strict equality assertion tests strict equality, as determined by ===. | ||
383 | // assert.strictEqual(actual, expected, message_opt); | ||
384 | |||
385 | assert.strictEqual = function strictEqual(actual, expected, message) { | ||
386 | if (actual !== expected) { | ||
387 | fail(actual, expected, message, '===', assert.strictEqual); | ||
388 | } | ||
389 | }; | ||
390 | |||
391 | // 10. The strict non-equality assertion tests for strict inequality, as | ||
392 | // determined by !==. assert.notStrictEqual(actual, expected, message_opt); | ||
393 | |||
394 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | ||
395 | if (actual === expected) { | ||
396 | fail(actual, expected, message, '!==', assert.notStrictEqual); | ||
397 | } | ||
398 | }; | ||
399 | |||
400 | function expectedException(actual, expected) { | ||
401 | if (!actual || !expected) { | ||
402 | return false; | ||
403 | } | ||
404 | |||
405 | if (Object.prototype.toString.call(expected) == '[object RegExp]') { | ||
406 | return expected.test(actual); | ||
407 | } | ||
408 | |||
409 | try { | ||
410 | if (actual instanceof expected) { | ||
411 | return true; | ||
412 | } | ||
413 | } catch (e) { | ||
414 | // Ignore. The instanceof check doesn't work for arrow functions. | ||
415 | } | ||
416 | |||
417 | if (Error.isPrototypeOf(expected)) { | ||
418 | return false; | ||
419 | } | ||
420 | |||
421 | return expected.call({}, actual) === true; | ||
422 | } | ||
423 | |||
424 | function _tryBlock(block) { | ||
425 | var error; | ||
426 | try { | ||
427 | block(); | ||
428 | } catch (e) { | ||
429 | error = e; | ||
430 | } | ||
431 | return error; | ||
432 | } | ||
433 | |||
434 | function _throws(shouldThrow, block, expected, message) { | ||
435 | var actual; | ||
436 | |||
437 | if (typeof block !== 'function') { | ||
438 | throw new TypeError('"block" argument must be a function'); | ||
439 | } | ||
440 | |||
441 | if (typeof expected === 'string') { | ||
442 | message = expected; | ||
443 | expected = null; | ||
444 | } | ||
445 | |||
446 | actual = _tryBlock(block); | ||
447 | |||
448 | message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + | ||
449 | (message ? ' ' + message : '.'); | ||
450 | |||
451 | if (shouldThrow && !actual) { | ||
452 | fail(actual, expected, 'Missing expected exception' + message); | ||
453 | } | ||
454 | |||
455 | var userProvidedMessage = typeof message === 'string'; | ||
456 | var isUnwantedException = !shouldThrow && util.isError(actual); | ||
457 | var isUnexpectedException = !shouldThrow && actual && !expected; | ||
458 | |||
459 | if ((isUnwantedException && | ||
460 | userProvidedMessage && | ||
461 | expectedException(actual, expected)) || | ||
462 | isUnexpectedException) { | ||
463 | fail(actual, expected, 'Got unwanted exception' + message); | ||
464 | } | ||
465 | |||
466 | if ((shouldThrow && actual && expected && | ||
467 | !expectedException(actual, expected)) || (!shouldThrow && actual)) { | ||
468 | throw actual; | ||
469 | } | ||
470 | } | ||
471 | |||
472 | // 11. Expected to throw an error: | ||
473 | // assert.throws(block, Error_opt, message_opt); | ||
474 | |||
475 | assert.throws = function(block, /*optional*/error, /*optional*/message) { | ||
476 | _throws(true, block, error, message); | ||
477 | }; | ||
478 | |||
479 | // EXTENSION! This is annoying to write outside this module. | ||
480 | assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { | ||
481 | _throws(false, block, error, message); | ||
482 | }; | ||
483 | |||
484 | assert.ifError = function(err) { if (err) throw err; }; | ||
485 | |||
486 | var objectKeys = Object.keys || function (obj) { | ||
487 | var keys = []; | ||
488 | for (var key in obj) { | ||
489 | if (hasOwn.call(obj, key)) keys.push(key); | ||
490 | } | ||
491 | return keys; | ||
492 | }; | ||
493 | |||
494 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
495 | },{"util/":30}],2:[function(require,module,exports){ | ||
496 | 'use strict' | ||
497 | |||
498 | exports.byteLength = byteLength | ||
499 | exports.toByteArray = toByteArray | ||
500 | exports.fromByteArray = fromByteArray | ||
501 | |||
502 | var lookup = [] | ||
503 | var revLookup = [] | ||
504 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array | ||
505 | |||
506 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | ||
507 | for (var i = 0, len = code.length; i < len; ++i) { | ||
508 | lookup[i] = code[i] | ||
509 | revLookup[code.charCodeAt(i)] = i | ||
510 | } | ||
511 | |||
512 | revLookup['-'.charCodeAt(0)] = 62 | ||
513 | revLookup['_'.charCodeAt(0)] = 63 | ||
514 | |||
515 | function placeHoldersCount (b64) { | ||
516 | var len = b64.length | ||
517 | if (len % 4 > 0) { | ||
518 | throw new Error('Invalid string. Length must be a multiple of 4') | ||
519 | } | ||
520 | |||
521 | // the number of equal signs (place holders) | ||
522 | // if there are two placeholders, than the two characters before it | ||
523 | // represent one byte | ||
524 | // if there is only one, then the three characters before it represent 2 bytes | ||
525 | // this is just a cheap hack to not do indexOf twice | ||
526 | return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 | ||
527 | } | ||
528 | |||
529 | function byteLength (b64) { | ||
530 | // base64 is 4/3 + up to two characters of the original data | ||
531 | return b64.length * 3 / 4 - placeHoldersCount(b64) | ||
532 | } | ||
533 | |||
534 | function toByteArray (b64) { | ||
535 | var i, j, l, tmp, placeHolders, arr | ||
536 | var len = b64.length | ||
537 | placeHolders = placeHoldersCount(b64) | ||
538 | |||
539 | arr = new Arr(len * 3 / 4 - placeHolders) | ||
540 | |||
541 | // if there are placeholders, only get up to the last complete 4 chars | ||
542 | l = placeHolders > 0 ? len - 4 : len | ||
543 | |||
544 | var L = 0 | ||
545 | |||
546 | for (i = 0, j = 0; i < l; i += 4, j += 3) { | ||
547 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] | ||
548 | arr[L++] = (tmp >> 16) & 0xFF | ||
549 | arr[L++] = (tmp >> 8) & 0xFF | ||
550 | arr[L++] = tmp & 0xFF | ||
551 | } | ||
552 | |||
553 | if (placeHolders === 2) { | ||
554 | tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) | ||
555 | arr[L++] = tmp & 0xFF | ||
556 | } else if (placeHolders === 1) { | ||
557 | tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) | ||
558 | arr[L++] = (tmp >> 8) & 0xFF | ||
559 | arr[L++] = tmp & 0xFF | ||
560 | } | ||
561 | |||
562 | return arr | ||
563 | } | ||
564 | |||
565 | function tripletToBase64 (num) { | ||
566 | return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] | ||
567 | } | ||
568 | |||
569 | function encodeChunk (uint8, start, end) { | ||
570 | var tmp | ||
571 | var output = [] | ||
572 | for (var i = start; i < end; i += 3) { | ||
573 | tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) | ||
574 | output.push(tripletToBase64(tmp)) | ||
575 | } | ||
576 | return output.join('') | ||
577 | } | ||
578 | |||
579 | function fromByteArray (uint8) { | ||
580 | var tmp | ||
581 | var len = uint8.length | ||
582 | var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes | ||
583 | var output = '' | ||
584 | var parts = [] | ||
585 | var maxChunkLength = 16383 // must be multiple of 3 | ||
586 | |||
587 | // go through the array every three bytes, we'll deal with trailing stuff later | ||
588 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
589 | parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) | ||
590 | } | ||
591 | |||
592 | // pad the end with zeros, but make sure to not forget the extra bytes | ||
593 | if (extraBytes === 1) { | ||
594 | tmp = uint8[len - 1] | ||
595 | output += lookup[tmp >> 2] | ||
596 | output += lookup[(tmp << 4) & 0x3F] | ||
597 | output += '==' | ||
598 | } else if (extraBytes === 2) { | ||
599 | tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) | ||
600 | output += lookup[tmp >> 10] | ||
601 | output += lookup[(tmp >> 4) & 0x3F] | ||
602 | output += lookup[(tmp << 2) & 0x3F] | ||
603 | output += '=' | ||
604 | } | ||
605 | |||
606 | parts.push(output) | ||
607 | |||
608 | return parts.join('') | ||
609 | } | ||
610 | |||
611 | },{}],3:[function(require,module,exports){ | ||
612 | |||
613 | },{}],4:[function(require,module,exports){ | ||
614 | (function (global){ | ||
615 | 'use strict'; | ||
616 | |||
617 | var buffer = require('buffer'); | ||
618 | var Buffer = buffer.Buffer; | ||
619 | var SlowBuffer = buffer.SlowBuffer; | ||
620 | var MAX_LEN = buffer.kMaxLength || 2147483647; | ||
621 | exports.alloc = function alloc(size, fill, encoding) { | ||
622 | if (typeof Buffer.alloc === 'function') { | ||
623 | return Buffer.alloc(size, fill, encoding); | ||
624 | } | ||
625 | if (typeof encoding === 'number') { | ||
626 | throw new TypeError('encoding must not be number'); | ||
627 | } | ||
628 | if (typeof size !== 'number') { | ||
629 | throw new TypeError('size must be a number'); | ||
630 | } | ||
631 | if (size > MAX_LEN) { | ||
632 | throw new RangeError('size is too large'); | ||
633 | } | ||
634 | var enc = encoding; | ||
635 | var _fill = fill; | ||
636 | if (_fill === undefined) { | ||
637 | enc = undefined; | ||
638 | _fill = 0; | ||
639 | } | ||
640 | var buf = new Buffer(size); | ||
641 | if (typeof _fill === 'string') { | ||
642 | var fillBuf = new Buffer(_fill, enc); | ||
643 | var flen = fillBuf.length; | ||
644 | var i = -1; | ||
645 | while (++i < size) { | ||
646 | buf[i] = fillBuf[i % flen]; | ||
647 | } | ||
648 | } else { | ||
649 | buf.fill(_fill); | ||
650 | } | ||
651 | return buf; | ||
652 | } | ||
653 | exports.allocUnsafe = function allocUnsafe(size) { | ||
654 | if (typeof Buffer.allocUnsafe === 'function') { | ||
655 | return Buffer.allocUnsafe(size); | ||
656 | } | ||
657 | if (typeof size !== 'number') { | ||
658 | throw new TypeError('size must be a number'); | ||
659 | } | ||
660 | if (size > MAX_LEN) { | ||
661 | throw new RangeError('size is too large'); | ||
662 | } | ||
663 | return new Buffer(size); | ||
664 | } | ||
665 | exports.from = function from(value, encodingOrOffset, length) { | ||
666 | if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { | ||
667 | return Buffer.from(value, encodingOrOffset, length); | ||
668 | } | ||
669 | if (typeof value === 'number') { | ||
670 | throw new TypeError('"value" argument must not be a number'); | ||
671 | } | ||
672 | if (typeof value === 'string') { | ||
673 | return new Buffer(value, encodingOrOffset); | ||
674 | } | ||
675 | if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { | ||
676 | var offset = encodingOrOffset; | ||
677 | if (arguments.length === 1) { | ||
678 | return new Buffer(value); | ||
679 | } | ||
680 | if (typeof offset === 'undefined') { | ||
681 | offset = 0; | ||
682 | } | ||
683 | var len = length; | ||
684 | if (typeof len === 'undefined') { | ||
685 | len = value.byteLength - offset; | ||
686 | } | ||
687 | if (offset >= value.byteLength) { | ||
688 | throw new RangeError('\'offset\' is out of bounds'); | ||
689 | } | ||
690 | if (len > value.byteLength - offset) { | ||
691 | throw new RangeError('\'length\' is out of bounds'); | ||
692 | } | ||
693 | return new Buffer(value.slice(offset, offset + len)); | ||
694 | } | ||
695 | if (Buffer.isBuffer(value)) { | ||
696 | var out = new Buffer(value.length); | ||
697 | value.copy(out, 0, 0, value.length); | ||
698 | return out; | ||
699 | } | ||
700 | if (value) { | ||
701 | if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { | ||
702 | return new Buffer(value); | ||
703 | } | ||
704 | if (value.type === 'Buffer' && Array.isArray(value.data)) { | ||
705 | return new Buffer(value.data); | ||
706 | } | ||
707 | } | ||
708 | |||
709 | throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); | ||
710 | } | ||
711 | exports.allocUnsafeSlow = function allocUnsafeSlow(size) { | ||
712 | if (typeof Buffer.allocUnsafeSlow === 'function') { | ||
713 | return Buffer.allocUnsafeSlow(size); | ||
714 | } | ||
715 | if (typeof size !== 'number') { | ||
716 | throw new TypeError('size must be a number'); | ||
717 | } | ||
718 | if (size >= MAX_LEN) { | ||
719 | throw new RangeError('size is too large'); | ||
720 | } | ||
721 | return new SlowBuffer(size); | ||
722 | } | ||
723 | |||
724 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
725 | },{"buffer":5}],5:[function(require,module,exports){ | ||
726 | /*! | ||
727 | * The buffer module from node.js, for the browser. | ||
728 | * | ||
729 | * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
730 | * @license MIT | ||
731 | */ | ||
732 | /* eslint-disable no-proto */ | ||
733 | |||
734 | 'use strict' | ||
735 | |||
736 | var base64 = require('base64-js') | ||
737 | var ieee754 = require('ieee754') | ||
738 | |||
739 | exports.Buffer = Buffer | ||
740 | exports.SlowBuffer = SlowBuffer | ||
741 | exports.INSPECT_MAX_BYTES = 50 | ||
742 | |||
743 | var K_MAX_LENGTH = 0x7fffffff | ||
744 | exports.kMaxLength = K_MAX_LENGTH | ||
745 | |||
746 | /** | ||
747 | * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
748 | * === true Use Uint8Array implementation (fastest) | ||
749 | * === false Print warning and recommend using `buffer` v4.x which has an Object | ||
750 | * implementation (most compatible, even IE6) | ||
751 | * | ||
752 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
753 | * Opera 11.6+, iOS 4.2+. | ||
754 | * | ||
755 | * We report that the browser does not support typed arrays if the are not subclassable | ||
756 | * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` | ||
757 | * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support | ||
758 | * for __proto__ and has a buggy typed array implementation. | ||
759 | */ | ||
760 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() | ||
761 | |||
762 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && | ||
763 | typeof console.error === 'function') { | ||
764 | console.error( | ||
765 | 'This browser lacks typed array (Uint8Array) support which is required by ' + | ||
766 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' | ||
767 | ) | ||
768 | } | ||
769 | |||
770 | function typedArraySupport () { | ||
771 | // Can typed array instances can be augmented? | ||
772 | try { | ||
773 | var arr = new Uint8Array(1) | ||
774 | arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} | ||
775 | return arr.foo() === 42 | ||
776 | } catch (e) { | ||
777 | return false | ||
778 | } | ||
779 | } | ||
780 | |||
781 | function createBuffer (length) { | ||
782 | if (length > K_MAX_LENGTH) { | ||
783 | throw new RangeError('Invalid typed array length') | ||
784 | } | ||
785 | // Return an augmented `Uint8Array` instance | ||
786 | var buf = new Uint8Array(length) | ||
787 | buf.__proto__ = Buffer.prototype | ||
788 | return buf | ||
789 | } | ||
790 | |||
791 | /** | ||
792 | * The Buffer constructor returns instances of `Uint8Array` that have their | ||
793 | * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of | ||
794 | * `Uint8Array`, so the returned instances will have all the node `Buffer` methods | ||
795 | * and the `Uint8Array` methods. Square bracket notation works as expected -- it | ||
796 | * returns a single octet. | ||
797 | * | ||
798 | * The `Uint8Array` prototype remains unmodified. | ||
799 | */ | ||
800 | |||
801 | function Buffer (arg, encodingOrOffset, length) { | ||
802 | // Common case. | ||
803 | if (typeof arg === 'number') { | ||
804 | if (typeof encodingOrOffset === 'string') { | ||
805 | throw new Error( | ||
806 | 'If encoding is specified then the first argument must be a string' | ||
807 | ) | ||
808 | } | ||
809 | return allocUnsafe(arg) | ||
810 | } | ||
811 | return from(arg, encodingOrOffset, length) | ||
812 | } | ||
813 | |||
814 | // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
815 | if (typeof Symbol !== 'undefined' && Symbol.species && | ||
816 | Buffer[Symbol.species] === Buffer) { | ||
817 | Object.defineProperty(Buffer, Symbol.species, { | ||
818 | value: null, | ||
819 | configurable: true, | ||
820 | enumerable: false, | ||
821 | writable: false | ||
822 | }) | ||
823 | } | ||
824 | |||
825 | Buffer.poolSize = 8192 // not used by this implementation | ||
826 | |||
827 | function from (value, encodingOrOffset, length) { | ||
828 | if (typeof value === 'number') { | ||
829 | throw new TypeError('"value" argument must not be a number') | ||
830 | } | ||
831 | |||
832 | if (value instanceof ArrayBuffer) { | ||
833 | return fromArrayBuffer(value, encodingOrOffset, length) | ||
834 | } | ||
835 | |||
836 | if (typeof value === 'string') { | ||
837 | return fromString(value, encodingOrOffset) | ||
838 | } | ||
839 | |||
840 | return fromObject(value) | ||
841 | } | ||
842 | |||
843 | /** | ||
844 | * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError | ||
845 | * if value is a number. | ||
846 | * Buffer.from(str[, encoding]) | ||
847 | * Buffer.from(array) | ||
848 | * Buffer.from(buffer) | ||
849 | * Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||
850 | **/ | ||
851 | Buffer.from = function (value, encodingOrOffset, length) { | ||
852 | return from(value, encodingOrOffset, length) | ||
853 | } | ||
854 | |||
855 | // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: | ||
856 | // https://github.com/feross/buffer/pull/148 | ||
857 | Buffer.prototype.__proto__ = Uint8Array.prototype | ||
858 | Buffer.__proto__ = Uint8Array | ||
859 | |||
860 | function assertSize (size) { | ||
861 | if (typeof size !== 'number') { | ||
862 | throw new TypeError('"size" argument must be a number') | ||
863 | } else if (size < 0) { | ||
864 | throw new RangeError('"size" argument must not be negative') | ||
865 | } | ||
866 | } | ||
867 | |||
868 | function alloc (size, fill, encoding) { | ||
869 | assertSize(size) | ||
870 | if (size <= 0) { | ||
871 | return createBuffer(size) | ||
872 | } | ||
873 | if (fill !== undefined) { | ||
874 | // Only pay attention to encoding if it's a string. This | ||
875 | // prevents accidentally sending in a number that would | ||
876 | // be interpretted as a start offset. | ||
877 | return typeof encoding === 'string' | ||
878 | ? createBuffer(size).fill(fill, encoding) | ||
879 | : createBuffer(size).fill(fill) | ||
880 | } | ||
881 | return createBuffer(size) | ||
882 | } | ||
883 | |||
884 | /** | ||
885 | * Creates a new filled Buffer instance. | ||
886 | * alloc(size[, fill[, encoding]]) | ||
887 | **/ | ||
888 | Buffer.alloc = function (size, fill, encoding) { | ||
889 | return alloc(size, fill, encoding) | ||
890 | } | ||
891 | |||
892 | function allocUnsafe (size) { | ||
893 | assertSize(size) | ||
894 | return createBuffer(size < 0 ? 0 : checked(size) | 0) | ||
895 | } | ||
896 | |||
897 | /** | ||
898 | * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. | ||
899 | * */ | ||
900 | Buffer.allocUnsafe = function (size) { | ||
901 | return allocUnsafe(size) | ||
902 | } | ||
903 | /** | ||
904 | * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ||
905 | */ | ||
906 | Buffer.allocUnsafeSlow = function (size) { | ||
907 | return allocUnsafe(size) | ||
908 | } | ||
909 | |||
910 | function fromString (string, encoding) { | ||
911 | if (typeof encoding !== 'string' || encoding === '') { | ||
912 | encoding = 'utf8' | ||
913 | } | ||
914 | |||
915 | if (!Buffer.isEncoding(encoding)) { | ||
916 | throw new TypeError('"encoding" must be a valid string encoding') | ||
917 | } | ||
918 | |||
919 | var length = byteLength(string, encoding) | 0 | ||
920 | var buf = createBuffer(length) | ||
921 | |||
922 | var actual = buf.write(string, encoding) | ||
923 | |||
924 | if (actual !== length) { | ||
925 | // Writing a hex string, for example, that contains invalid characters will | ||
926 | // cause everything after the first invalid character to be ignored. (e.g. | ||
927 | // 'abxxcd' will be treated as 'ab') | ||
928 | buf = buf.slice(0, actual) | ||
929 | } | ||
930 | |||
931 | return buf | ||
932 | } | ||
933 | |||
934 | function fromArrayLike (array) { | ||
935 | var length = array.length < 0 ? 0 : checked(array.length) | 0 | ||
936 | var buf = createBuffer(length) | ||
937 | for (var i = 0; i < length; i += 1) { | ||
938 | buf[i] = array[i] & 255 | ||
939 | } | ||
940 | return buf | ||
941 | } | ||
942 | |||
943 | function fromArrayBuffer (array, byteOffset, length) { | ||
944 | if (byteOffset < 0 || array.byteLength < byteOffset) { | ||
945 | throw new RangeError('\'offset\' is out of bounds') | ||
946 | } | ||
947 | |||
948 | if (array.byteLength < byteOffset + (length || 0)) { | ||
949 | throw new RangeError('\'length\' is out of bounds') | ||
950 | } | ||
951 | |||
952 | var buf | ||
953 | if (byteOffset === undefined && length === undefined) { | ||
954 | buf = new Uint8Array(array) | ||
955 | } else if (length === undefined) { | ||
956 | buf = new Uint8Array(array, byteOffset) | ||
957 | } else { | ||
958 | buf = new Uint8Array(array, byteOffset, length) | ||
959 | } | ||
960 | |||
961 | // Return an augmented `Uint8Array` instance | ||
962 | buf.__proto__ = Buffer.prototype | ||
963 | return buf | ||
964 | } | ||
965 | |||
966 | function fromObject (obj) { | ||
967 | if (Buffer.isBuffer(obj)) { | ||
968 | var len = checked(obj.length) | 0 | ||
969 | var buf = createBuffer(len) | ||
970 | |||
971 | if (buf.length === 0) { | ||
972 | return buf | ||
973 | } | ||
974 | |||
975 | obj.copy(buf, 0, 0, len) | ||
976 | return buf | ||
977 | } | ||
978 | |||
979 | if (obj) { | ||
980 | if (ArrayBuffer.isView(obj) || 'length' in obj) { | ||
981 | if (typeof obj.length !== 'number' || isnan(obj.length)) { | ||
982 | return createBuffer(0) | ||
983 | } | ||
984 | return fromArrayLike(obj) | ||
985 | } | ||
986 | |||
987 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
988 | return fromArrayLike(obj.data) | ||
989 | } | ||
990 | } | ||
991 | |||
992 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') | ||
993 | } | ||
994 | |||
995 | function checked (length) { | ||
996 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when | ||
997 | // length is NaN (which is otherwise coerced to zero.) | ||
998 | if (length >= K_MAX_LENGTH) { | ||
999 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
1000 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') | ||
1001 | } | ||
1002 | return length | 0 | ||
1003 | } | ||
1004 | |||
1005 | function SlowBuffer (length) { | ||
1006 | if (+length != length) { // eslint-disable-line eqeqeq | ||
1007 | length = 0 | ||
1008 | } | ||
1009 | return Buffer.alloc(+length) | ||
1010 | } | ||
1011 | |||
1012 | Buffer.isBuffer = function isBuffer (b) { | ||
1013 | return b != null && b._isBuffer === true | ||
1014 | } | ||
1015 | |||
1016 | Buffer.compare = function compare (a, b) { | ||
1017 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
1018 | throw new TypeError('Arguments must be Buffers') | ||
1019 | } | ||
1020 | |||
1021 | if (a === b) return 0 | ||
1022 | |||
1023 | var x = a.length | ||
1024 | var y = b.length | ||
1025 | |||
1026 | for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
1027 | if (a[i] !== b[i]) { | ||
1028 | x = a[i] | ||
1029 | y = b[i] | ||
1030 | break | ||
1031 | } | ||
1032 | } | ||
1033 | |||
1034 | if (x < y) return -1 | ||
1035 | if (y < x) return 1 | ||
1036 | return 0 | ||
1037 | } | ||
1038 | |||
1039 | Buffer.isEncoding = function isEncoding (encoding) { | ||
1040 | switch (String(encoding).toLowerCase()) { | ||
1041 | case 'hex': | ||
1042 | case 'utf8': | ||
1043 | case 'utf-8': | ||
1044 | case 'ascii': | ||
1045 | case 'latin1': | ||
1046 | case 'binary': | ||
1047 | case 'base64': | ||
1048 | case 'ucs2': | ||
1049 | case 'ucs-2': | ||
1050 | case 'utf16le': | ||
1051 | case 'utf-16le': | ||
1052 | return true | ||
1053 | default: | ||
1054 | return false | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | Buffer.concat = function concat (list, length) { | ||
1059 | if (!Array.isArray(list)) { | ||
1060 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
1061 | } | ||
1062 | |||
1063 | if (list.length === 0) { | ||
1064 | return Buffer.alloc(0) | ||
1065 | } | ||
1066 | |||
1067 | var i | ||
1068 | if (length === undefined) { | ||
1069 | length = 0 | ||
1070 | for (i = 0; i < list.length; ++i) { | ||
1071 | length += list[i].length | ||
1072 | } | ||
1073 | } | ||
1074 | |||
1075 | var buffer = Buffer.allocUnsafe(length) | ||
1076 | var pos = 0 | ||
1077 | for (i = 0; i < list.length; ++i) { | ||
1078 | var buf = list[i] | ||
1079 | if (!Buffer.isBuffer(buf)) { | ||
1080 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
1081 | } | ||
1082 | buf.copy(buffer, pos) | ||
1083 | pos += buf.length | ||
1084 | } | ||
1085 | return buffer | ||
1086 | } | ||
1087 | |||
1088 | function byteLength (string, encoding) { | ||
1089 | if (Buffer.isBuffer(string)) { | ||
1090 | return string.length | ||
1091 | } | ||
1092 | if (ArrayBuffer.isView(string) || string instanceof ArrayBuffer) { | ||
1093 | return string.byteLength | ||
1094 | } | ||
1095 | if (typeof string !== 'string') { | ||
1096 | string = '' + string | ||
1097 | } | ||
1098 | |||
1099 | var len = string.length | ||
1100 | if (len === 0) return 0 | ||
1101 | |||
1102 | // Use a for loop to avoid recursion | ||
1103 | var loweredCase = false | ||
1104 | for (;;) { | ||
1105 | switch (encoding) { | ||
1106 | case 'ascii': | ||
1107 | case 'latin1': | ||
1108 | case 'binary': | ||
1109 | return len | ||
1110 | case 'utf8': | ||
1111 | case 'utf-8': | ||
1112 | case undefined: | ||
1113 | return utf8ToBytes(string).length | ||
1114 | case 'ucs2': | ||
1115 | case 'ucs-2': | ||
1116 | case 'utf16le': | ||
1117 | case 'utf-16le': | ||
1118 | return len * 2 | ||
1119 | case 'hex': | ||
1120 | return len >>> 1 | ||
1121 | case 'base64': | ||
1122 | return base64ToBytes(string).length | ||
1123 | default: | ||
1124 | if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
1125 | encoding = ('' + encoding).toLowerCase() | ||
1126 | loweredCase = true | ||
1127 | } | ||
1128 | } | ||
1129 | } | ||
1130 | Buffer.byteLength = byteLength | ||
1131 | |||
1132 | function slowToString (encoding, start, end) { | ||
1133 | var loweredCase = false | ||
1134 | |||
1135 | // No need to verify that "this.length <= MAX_UINT32" since it's a read-only | ||
1136 | // property of a typed array. | ||
1137 | |||
1138 | // This behaves neither like String nor Uint8Array in that we set start/end | ||
1139 | // to their upper/lower bounds if the value passed is out of range. | ||
1140 | // undefined is handled specially as per ECMA-262 6th Edition, | ||
1141 | // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. | ||
1142 | if (start === undefined || start < 0) { | ||
1143 | start = 0 | ||
1144 | } | ||
1145 | // Return early if start > this.length. Done here to prevent potential uint32 | ||
1146 | // coercion fail below. | ||
1147 | if (start > this.length) { | ||
1148 | return '' | ||
1149 | } | ||
1150 | |||
1151 | if (end === undefined || end > this.length) { | ||
1152 | end = this.length | ||
1153 | } | ||
1154 | |||
1155 | if (end <= 0) { | ||
1156 | return '' | ||
1157 | } | ||
1158 | |||
1159 | // Force coersion to uint32. This will also coerce falsey/NaN values to 0. | ||
1160 | end >>>= 0 | ||
1161 | start >>>= 0 | ||
1162 | |||
1163 | if (end <= start) { | ||
1164 | return '' | ||
1165 | } | ||
1166 | |||
1167 | if (!encoding) encoding = 'utf8' | ||
1168 | |||
1169 | while (true) { | ||
1170 | switch (encoding) { | ||
1171 | case 'hex': | ||
1172 | return hexSlice(this, start, end) | ||
1173 | |||
1174 | case 'utf8': | ||
1175 | case 'utf-8': | ||
1176 | return utf8Slice(this, start, end) | ||
1177 | |||
1178 | case 'ascii': | ||
1179 | return asciiSlice(this, start, end) | ||
1180 | |||
1181 | case 'latin1': | ||
1182 | case 'binary': | ||
1183 | return latin1Slice(this, start, end) | ||
1184 | |||
1185 | case 'base64': | ||
1186 | return base64Slice(this, start, end) | ||
1187 | |||
1188 | case 'ucs2': | ||
1189 | case 'ucs-2': | ||
1190 | case 'utf16le': | ||
1191 | case 'utf-16le': | ||
1192 | return utf16leSlice(this, start, end) | ||
1193 | |||
1194 | default: | ||
1195 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
1196 | encoding = (encoding + '').toLowerCase() | ||
1197 | loweredCase = true | ||
1198 | } | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) | ||
1203 | // to detect a Buffer instance. It's not possible to use `instanceof Buffer` | ||
1204 | // reliably in a browserify context because there could be multiple different | ||
1205 | // copies of the 'buffer' package in use. This method works even for Buffer | ||
1206 | // instances that were created from another copy of the `buffer` package. | ||
1207 | // See: https://github.com/feross/buffer/issues/154 | ||
1208 | Buffer.prototype._isBuffer = true | ||
1209 | |||
1210 | function swap (b, n, m) { | ||
1211 | var i = b[n] | ||
1212 | b[n] = b[m] | ||
1213 | b[m] = i | ||
1214 | } | ||
1215 | |||
1216 | Buffer.prototype.swap16 = function swap16 () { | ||
1217 | var len = this.length | ||
1218 | if (len % 2 !== 0) { | ||
1219 | throw new RangeError('Buffer size must be a multiple of 16-bits') | ||
1220 | } | ||
1221 | for (var i = 0; i < len; i += 2) { | ||
1222 | swap(this, i, i + 1) | ||
1223 | } | ||
1224 | return this | ||
1225 | } | ||
1226 | |||
1227 | Buffer.prototype.swap32 = function swap32 () { | ||
1228 | var len = this.length | ||
1229 | if (len % 4 !== 0) { | ||
1230 | throw new RangeError('Buffer size must be a multiple of 32-bits') | ||
1231 | } | ||
1232 | for (var i = 0; i < len; i += 4) { | ||
1233 | swap(this, i, i + 3) | ||
1234 | swap(this, i + 1, i + 2) | ||
1235 | } | ||
1236 | return this | ||
1237 | } | ||
1238 | |||
1239 | Buffer.prototype.swap64 = function swap64 () { | ||
1240 | var len = this.length | ||
1241 | if (len % 8 !== 0) { | ||
1242 | throw new RangeError('Buffer size must be a multiple of 64-bits') | ||
1243 | } | ||
1244 | for (var i = 0; i < len; i += 8) { | ||
1245 | swap(this, i, i + 7) | ||
1246 | swap(this, i + 1, i + 6) | ||
1247 | swap(this, i + 2, i + 5) | ||
1248 | swap(this, i + 3, i + 4) | ||
1249 | } | ||
1250 | return this | ||
1251 | } | ||
1252 | |||
1253 | Buffer.prototype.toString = function toString () { | ||
1254 | var length = this.length | ||
1255 | if (length === 0) return '' | ||
1256 | if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
1257 | return slowToString.apply(this, arguments) | ||
1258 | } | ||
1259 | |||
1260 | Buffer.prototype.equals = function equals (b) { | ||
1261 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
1262 | if (this === b) return true | ||
1263 | return Buffer.compare(this, b) === 0 | ||
1264 | } | ||
1265 | |||
1266 | Buffer.prototype.inspect = function inspect () { | ||
1267 | var str = '' | ||
1268 | var max = exports.INSPECT_MAX_BYTES | ||
1269 | if (this.length > 0) { | ||
1270 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
1271 | if (this.length > max) str += ' ... ' | ||
1272 | } | ||
1273 | return '<Buffer ' + str + '>' | ||
1274 | } | ||
1275 | |||
1276 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { | ||
1277 | if (!Buffer.isBuffer(target)) { | ||
1278 | throw new TypeError('Argument must be a Buffer') | ||
1279 | } | ||
1280 | |||
1281 | if (start === undefined) { | ||
1282 | start = 0 | ||
1283 | } | ||
1284 | if (end === undefined) { | ||
1285 | end = target ? target.length : 0 | ||
1286 | } | ||
1287 | if (thisStart === undefined) { | ||
1288 | thisStart = 0 | ||
1289 | } | ||
1290 | if (thisEnd === undefined) { | ||
1291 | thisEnd = this.length | ||
1292 | } | ||
1293 | |||
1294 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { | ||
1295 | throw new RangeError('out of range index') | ||
1296 | } | ||
1297 | |||
1298 | if (thisStart >= thisEnd && start >= end) { | ||
1299 | return 0 | ||
1300 | } | ||
1301 | if (thisStart >= thisEnd) { | ||
1302 | return -1 | ||
1303 | } | ||
1304 | if (start >= end) { | ||
1305 | return 1 | ||
1306 | } | ||
1307 | |||
1308 | start >>>= 0 | ||
1309 | end >>>= 0 | ||
1310 | thisStart >>>= 0 | ||
1311 | thisEnd >>>= 0 | ||
1312 | |||
1313 | if (this === target) return 0 | ||
1314 | |||
1315 | var x = thisEnd - thisStart | ||
1316 | var y = end - start | ||
1317 | var len = Math.min(x, y) | ||
1318 | |||
1319 | var thisCopy = this.slice(thisStart, thisEnd) | ||
1320 | var targetCopy = target.slice(start, end) | ||
1321 | |||
1322 | for (var i = 0; i < len; ++i) { | ||
1323 | if (thisCopy[i] !== targetCopy[i]) { | ||
1324 | x = thisCopy[i] | ||
1325 | y = targetCopy[i] | ||
1326 | break | ||
1327 | } | ||
1328 | } | ||
1329 | |||
1330 | if (x < y) return -1 | ||
1331 | if (y < x) return 1 | ||
1332 | return 0 | ||
1333 | } | ||
1334 | |||
1335 | // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, | ||
1336 | // OR the last index of `val` in `buffer` at offset <= `byteOffset`. | ||
1337 | // | ||
1338 | // Arguments: | ||
1339 | // - buffer - a Buffer to search | ||
1340 | // - val - a string, Buffer, or number | ||
1341 | // - byteOffset - an index into `buffer`; will be clamped to an int32 | ||
1342 | // - encoding - an optional encoding, relevant is val is a string | ||
1343 | // - dir - true for indexOf, false for lastIndexOf | ||
1344 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { | ||
1345 | // Empty buffer means no match | ||
1346 | if (buffer.length === 0) return -1 | ||
1347 | |||
1348 | // Normalize byteOffset | ||
1349 | if (typeof byteOffset === 'string') { | ||
1350 | encoding = byteOffset | ||
1351 | byteOffset = 0 | ||
1352 | } else if (byteOffset > 0x7fffffff) { | ||
1353 | byteOffset = 0x7fffffff | ||
1354 | } else if (byteOffset < -0x80000000) { | ||
1355 | byteOffset = -0x80000000 | ||
1356 | } | ||
1357 | byteOffset = +byteOffset // Coerce to Number. | ||
1358 | if (isNaN(byteOffset)) { | ||
1359 | // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
1360 | byteOffset = dir ? 0 : (buffer.length - 1) | ||
1361 | } | ||
1362 | |||
1363 | // Normalize byteOffset: negative offsets start from the end of the buffer | ||
1364 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset | ||
1365 | if (byteOffset >= buffer.length) { | ||
1366 | if (dir) return -1 | ||
1367 | else byteOffset = buffer.length - 1 | ||
1368 | } else if (byteOffset < 0) { | ||
1369 | if (dir) byteOffset = 0 | ||
1370 | else return -1 | ||
1371 | } | ||
1372 | |||
1373 | // Normalize val | ||
1374 | if (typeof val === 'string') { | ||
1375 | val = Buffer.from(val, encoding) | ||
1376 | } | ||
1377 | |||
1378 | // Finally, search either indexOf (if dir is true) or lastIndexOf | ||
1379 | if (Buffer.isBuffer(val)) { | ||
1380 | // Special case: looking for empty string/buffer always fails | ||
1381 | if (val.length === 0) { | ||
1382 | return -1 | ||
1383 | } | ||
1384 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir) | ||
1385 | } else if (typeof val === 'number') { | ||
1386 | val = val & 0xFF // Search for a byte value [0-255] | ||
1387 | if (typeof Uint8Array.prototype.indexOf === 'function') { | ||
1388 | if (dir) { | ||
1389 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) | ||
1390 | } else { | ||
1391 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) | ||
1392 | } | ||
1393 | } | ||
1394 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) | ||
1395 | } | ||
1396 | |||
1397 | throw new TypeError('val must be string, number or Buffer') | ||
1398 | } | ||
1399 | |||
1400 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) { | ||
1401 | var indexSize = 1 | ||
1402 | var arrLength = arr.length | ||
1403 | var valLength = val.length | ||
1404 | |||
1405 | if (encoding !== undefined) { | ||
1406 | encoding = String(encoding).toLowerCase() | ||
1407 | if (encoding === 'ucs2' || encoding === 'ucs-2' || | ||
1408 | encoding === 'utf16le' || encoding === 'utf-16le') { | ||
1409 | if (arr.length < 2 || val.length < 2) { | ||
1410 | return -1 | ||
1411 | } | ||
1412 | indexSize = 2 | ||
1413 | arrLength /= 2 | ||
1414 | valLength /= 2 | ||
1415 | byteOffset /= 2 | ||
1416 | } | ||
1417 | } | ||
1418 | |||
1419 | function read (buf, i) { | ||
1420 | if (indexSize === 1) { | ||
1421 | return buf[i] | ||
1422 | } else { | ||
1423 | return buf.readUInt16BE(i * indexSize) | ||
1424 | } | ||
1425 | } | ||
1426 | |||
1427 | var i | ||
1428 | if (dir) { | ||
1429 | var foundIndex = -1 | ||
1430 | for (i = byteOffset; i < arrLength; i++) { | ||
1431 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { | ||
1432 | if (foundIndex === -1) foundIndex = i | ||
1433 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize | ||
1434 | } else { | ||
1435 | if (foundIndex !== -1) i -= i - foundIndex | ||
1436 | foundIndex = -1 | ||
1437 | } | ||
1438 | } | ||
1439 | } else { | ||
1440 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength | ||
1441 | for (i = byteOffset; i >= 0; i--) { | ||
1442 | var found = true | ||
1443 | for (var j = 0; j < valLength; j++) { | ||
1444 | if (read(arr, i + j) !== read(val, j)) { | ||
1445 | found = false | ||
1446 | break | ||
1447 | } | ||
1448 | } | ||
1449 | if (found) return i | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | return -1 | ||
1454 | } | ||
1455 | |||
1456 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) { | ||
1457 | return this.indexOf(val, byteOffset, encoding) !== -1 | ||
1458 | } | ||
1459 | |||
1460 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { | ||
1461 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true) | ||
1462 | } | ||
1463 | |||
1464 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { | ||
1465 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false) | ||
1466 | } | ||
1467 | |||
1468 | function hexWrite (buf, string, offset, length) { | ||
1469 | offset = Number(offset) || 0 | ||
1470 | var remaining = buf.length - offset | ||
1471 | if (!length) { | ||
1472 | length = remaining | ||
1473 | } else { | ||
1474 | length = Number(length) | ||
1475 | if (length > remaining) { | ||
1476 | length = remaining | ||
1477 | } | ||
1478 | } | ||
1479 | |||
1480 | // must be an even number of digits | ||
1481 | var strLen = string.length | ||
1482 | if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') | ||
1483 | |||
1484 | if (length > strLen / 2) { | ||
1485 | length = strLen / 2 | ||
1486 | } | ||
1487 | for (var i = 0; i < length; ++i) { | ||
1488 | var parsed = parseInt(string.substr(i * 2, 2), 16) | ||
1489 | if (isNaN(parsed)) return i | ||
1490 | buf[offset + i] = parsed | ||
1491 | } | ||
1492 | return i | ||
1493 | } | ||
1494 | |||
1495 | function utf8Write (buf, string, offset, length) { | ||
1496 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | ||
1497 | } | ||
1498 | |||
1499 | function asciiWrite (buf, string, offset, length) { | ||
1500 | return blitBuffer(asciiToBytes(string), buf, offset, length) | ||
1501 | } | ||
1502 | |||
1503 | function latin1Write (buf, string, offset, length) { | ||
1504 | return asciiWrite(buf, string, offset, length) | ||
1505 | } | ||
1506 | |||
1507 | function base64Write (buf, string, offset, length) { | ||
1508 | return blitBuffer(base64ToBytes(string), buf, offset, length) | ||
1509 | } | ||
1510 | |||
1511 | function ucs2Write (buf, string, offset, length) { | ||
1512 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | ||
1513 | } | ||
1514 | |||
1515 | Buffer.prototype.write = function write (string, offset, length, encoding) { | ||
1516 | // Buffer#write(string) | ||
1517 | if (offset === undefined) { | ||
1518 | encoding = 'utf8' | ||
1519 | length = this.length | ||
1520 | offset = 0 | ||
1521 | // Buffer#write(string, encoding) | ||
1522 | } else if (length === undefined && typeof offset === 'string') { | ||
1523 | encoding = offset | ||
1524 | length = this.length | ||
1525 | offset = 0 | ||
1526 | // Buffer#write(string, offset[, length][, encoding]) | ||
1527 | } else if (isFinite(offset)) { | ||
1528 | offset = offset >>> 0 | ||
1529 | if (isFinite(length)) { | ||
1530 | length = length >>> 0 | ||
1531 | if (encoding === undefined) encoding = 'utf8' | ||
1532 | } else { | ||
1533 | encoding = length | ||
1534 | length = undefined | ||
1535 | } | ||
1536 | } else { | ||
1537 | throw new Error( | ||
1538 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported' | ||
1539 | ) | ||
1540 | } | ||
1541 | |||
1542 | var remaining = this.length - offset | ||
1543 | if (length === undefined || length > remaining) length = remaining | ||
1544 | |||
1545 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | ||
1546 | throw new RangeError('Attempt to write outside buffer bounds') | ||
1547 | } | ||
1548 | |||
1549 | if (!encoding) encoding = 'utf8' | ||
1550 | |||
1551 | var loweredCase = false | ||
1552 | for (;;) { | ||
1553 | switch (encoding) { | ||
1554 | case 'hex': | ||
1555 | return hexWrite(this, string, offset, length) | ||
1556 | |||
1557 | case 'utf8': | ||
1558 | case 'utf-8': | ||
1559 | return utf8Write(this, string, offset, length) | ||
1560 | |||
1561 | case 'ascii': | ||
1562 | return asciiWrite(this, string, offset, length) | ||
1563 | |||
1564 | case 'latin1': | ||
1565 | case 'binary': | ||
1566 | return latin1Write(this, string, offset, length) | ||
1567 | |||
1568 | case 'base64': | ||
1569 | // Warning: maxLength not taken into account in base64Write | ||
1570 | return base64Write(this, string, offset, length) | ||
1571 | |||
1572 | case 'ucs2': | ||
1573 | case 'ucs-2': | ||
1574 | case 'utf16le': | ||
1575 | case 'utf-16le': | ||
1576 | return ucs2Write(this, string, offset, length) | ||
1577 | |||
1578 | default: | ||
1579 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
1580 | encoding = ('' + encoding).toLowerCase() | ||
1581 | loweredCase = true | ||
1582 | } | ||
1583 | } | ||
1584 | } | ||
1585 | |||
1586 | Buffer.prototype.toJSON = function toJSON () { | ||
1587 | return { | ||
1588 | type: 'Buffer', | ||
1589 | data: Array.prototype.slice.call(this._arr || this, 0) | ||
1590 | } | ||
1591 | } | ||
1592 | |||
1593 | function base64Slice (buf, start, end) { | ||
1594 | if (start === 0 && end === buf.length) { | ||
1595 | return base64.fromByteArray(buf) | ||
1596 | } else { | ||
1597 | return base64.fromByteArray(buf.slice(start, end)) | ||
1598 | } | ||
1599 | } | ||
1600 | |||
1601 | function utf8Slice (buf, start, end) { | ||
1602 | end = Math.min(buf.length, end) | ||
1603 | var res = [] | ||
1604 | |||
1605 | var i = start | ||
1606 | while (i < end) { | ||
1607 | var firstByte = buf[i] | ||
1608 | var codePoint = null | ||
1609 | var bytesPerSequence = (firstByte > 0xEF) ? 4 | ||
1610 | : (firstByte > 0xDF) ? 3 | ||
1611 | : (firstByte > 0xBF) ? 2 | ||
1612 | : 1 | ||
1613 | |||
1614 | if (i + bytesPerSequence <= end) { | ||
1615 | var secondByte, thirdByte, fourthByte, tempCodePoint | ||
1616 | |||
1617 | switch (bytesPerSequence) { | ||
1618 | case 1: | ||
1619 | if (firstByte < 0x80) { | ||
1620 | codePoint = firstByte | ||
1621 | } | ||
1622 | break | ||
1623 | case 2: | ||
1624 | secondByte = buf[i + 1] | ||
1625 | if ((secondByte & 0xC0) === 0x80) { | ||
1626 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | ||
1627 | if (tempCodePoint > 0x7F) { | ||
1628 | codePoint = tempCodePoint | ||
1629 | } | ||
1630 | } | ||
1631 | break | ||
1632 | case 3: | ||
1633 | secondByte = buf[i + 1] | ||
1634 | thirdByte = buf[i + 2] | ||
1635 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | ||
1636 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | ||
1637 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | ||
1638 | codePoint = tempCodePoint | ||
1639 | } | ||
1640 | } | ||
1641 | break | ||
1642 | case 4: | ||
1643 | secondByte = buf[i + 1] | ||
1644 | thirdByte = buf[i + 2] | ||
1645 | fourthByte = buf[i + 3] | ||
1646 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | ||
1647 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | ||
1648 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | ||
1649 | codePoint = tempCodePoint | ||
1650 | } | ||
1651 | } | ||
1652 | } | ||
1653 | } | ||
1654 | |||
1655 | if (codePoint === null) { | ||
1656 | // we did not generate a valid codePoint so insert a | ||
1657 | // replacement char (U+FFFD) and advance only 1 byte | ||
1658 | codePoint = 0xFFFD | ||
1659 | bytesPerSequence = 1 | ||
1660 | } else if (codePoint > 0xFFFF) { | ||
1661 | // encode to utf16 (surrogate pair dance) | ||
1662 | codePoint -= 0x10000 | ||
1663 | res.push(codePoint >>> 10 & 0x3FF | 0xD800) | ||
1664 | codePoint = 0xDC00 | codePoint & 0x3FF | ||
1665 | } | ||
1666 | |||
1667 | res.push(codePoint) | ||
1668 | i += bytesPerSequence | ||
1669 | } | ||
1670 | |||
1671 | return decodeCodePointsArray(res) | ||
1672 | } | ||
1673 | |||
1674 | // Based on http://stackoverflow.com/a/22747272/680742, the browser with | ||
1675 | // the lowest limit is Chrome, with 0x10000 args. | ||
1676 | // We go 1 magnitude less, for safety | ||
1677 | var MAX_ARGUMENTS_LENGTH = 0x1000 | ||
1678 | |||
1679 | function decodeCodePointsArray (codePoints) { | ||
1680 | var len = codePoints.length | ||
1681 | if (len <= MAX_ARGUMENTS_LENGTH) { | ||
1682 | return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | ||
1683 | } | ||
1684 | |||
1685 | // Decode in chunks to avoid "call stack size exceeded". | ||
1686 | var res = '' | ||
1687 | var i = 0 | ||
1688 | while (i < len) { | ||
1689 | res += String.fromCharCode.apply( | ||
1690 | String, | ||
1691 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | ||
1692 | ) | ||
1693 | } | ||
1694 | return res | ||
1695 | } | ||
1696 | |||
1697 | function asciiSlice (buf, start, end) { | ||
1698 | var ret = '' | ||
1699 | end = Math.min(buf.length, end) | ||
1700 | |||
1701 | for (var i = start; i < end; ++i) { | ||
1702 | ret += String.fromCharCode(buf[i] & 0x7F) | ||
1703 | } | ||
1704 | return ret | ||
1705 | } | ||
1706 | |||
1707 | function latin1Slice (buf, start, end) { | ||
1708 | var ret = '' | ||
1709 | end = Math.min(buf.length, end) | ||
1710 | |||
1711 | for (var i = start; i < end; ++i) { | ||
1712 | ret += String.fromCharCode(buf[i]) | ||
1713 | } | ||
1714 | return ret | ||
1715 | } | ||
1716 | |||
1717 | function hexSlice (buf, start, end) { | ||
1718 | var len = buf.length | ||
1719 | |||
1720 | if (!start || start < 0) start = 0 | ||
1721 | if (!end || end < 0 || end > len) end = len | ||
1722 | |||
1723 | var out = '' | ||
1724 | for (var i = start; i < end; ++i) { | ||
1725 | out += toHex(buf[i]) | ||
1726 | } | ||
1727 | return out | ||
1728 | } | ||
1729 | |||
1730 | function utf16leSlice (buf, start, end) { | ||
1731 | var bytes = buf.slice(start, end) | ||
1732 | var res = '' | ||
1733 | for (var i = 0; i < bytes.length; i += 2) { | ||
1734 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) | ||
1735 | } | ||
1736 | return res | ||
1737 | } | ||
1738 | |||
1739 | Buffer.prototype.slice = function slice (start, end) { | ||
1740 | var len = this.length | ||
1741 | start = ~~start | ||
1742 | end = end === undefined ? len : ~~end | ||
1743 | |||
1744 | if (start < 0) { | ||
1745 | start += len | ||
1746 | if (start < 0) start = 0 | ||
1747 | } else if (start > len) { | ||
1748 | start = len | ||
1749 | } | ||
1750 | |||
1751 | if (end < 0) { | ||
1752 | end += len | ||
1753 | if (end < 0) end = 0 | ||
1754 | } else if (end > len) { | ||
1755 | end = len | ||
1756 | } | ||
1757 | |||
1758 | if (end < start) end = start | ||
1759 | |||
1760 | var newBuf = this.subarray(start, end) | ||
1761 | // Return an augmented `Uint8Array` instance | ||
1762 | newBuf.__proto__ = Buffer.prototype | ||
1763 | return newBuf | ||
1764 | } | ||
1765 | |||
1766 | /* | ||
1767 | * Need to make sure that buffer isn't trying to write out of bounds. | ||
1768 | */ | ||
1769 | function checkOffset (offset, ext, length) { | ||
1770 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | ||
1771 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | ||
1772 | } | ||
1773 | |||
1774 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { | ||
1775 | offset = offset >>> 0 | ||
1776 | byteLength = byteLength >>> 0 | ||
1777 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1778 | |||
1779 | var val = this[offset] | ||
1780 | var mul = 1 | ||
1781 | var i = 0 | ||
1782 | while (++i < byteLength && (mul *= 0x100)) { | ||
1783 | val += this[offset + i] * mul | ||
1784 | } | ||
1785 | |||
1786 | return val | ||
1787 | } | ||
1788 | |||
1789 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { | ||
1790 | offset = offset >>> 0 | ||
1791 | byteLength = byteLength >>> 0 | ||
1792 | if (!noAssert) { | ||
1793 | checkOffset(offset, byteLength, this.length) | ||
1794 | } | ||
1795 | |||
1796 | var val = this[offset + --byteLength] | ||
1797 | var mul = 1 | ||
1798 | while (byteLength > 0 && (mul *= 0x100)) { | ||
1799 | val += this[offset + --byteLength] * mul | ||
1800 | } | ||
1801 | |||
1802 | return val | ||
1803 | } | ||
1804 | |||
1805 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { | ||
1806 | offset = offset >>> 0 | ||
1807 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
1808 | return this[offset] | ||
1809 | } | ||
1810 | |||
1811 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { | ||
1812 | offset = offset >>> 0 | ||
1813 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1814 | return this[offset] | (this[offset + 1] << 8) | ||
1815 | } | ||
1816 | |||
1817 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { | ||
1818 | offset = offset >>> 0 | ||
1819 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1820 | return (this[offset] << 8) | this[offset + 1] | ||
1821 | } | ||
1822 | |||
1823 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { | ||
1824 | offset = offset >>> 0 | ||
1825 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1826 | |||
1827 | return ((this[offset]) | | ||
1828 | (this[offset + 1] << 8) | | ||
1829 | (this[offset + 2] << 16)) + | ||
1830 | (this[offset + 3] * 0x1000000) | ||
1831 | } | ||
1832 | |||
1833 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { | ||
1834 | offset = offset >>> 0 | ||
1835 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1836 | |||
1837 | return (this[offset] * 0x1000000) + | ||
1838 | ((this[offset + 1] << 16) | | ||
1839 | (this[offset + 2] << 8) | | ||
1840 | this[offset + 3]) | ||
1841 | } | ||
1842 | |||
1843 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { | ||
1844 | offset = offset >>> 0 | ||
1845 | byteLength = byteLength >>> 0 | ||
1846 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1847 | |||
1848 | var val = this[offset] | ||
1849 | var mul = 1 | ||
1850 | var i = 0 | ||
1851 | while (++i < byteLength && (mul *= 0x100)) { | ||
1852 | val += this[offset + i] * mul | ||
1853 | } | ||
1854 | mul *= 0x80 | ||
1855 | |||
1856 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
1857 | |||
1858 | return val | ||
1859 | } | ||
1860 | |||
1861 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { | ||
1862 | offset = offset >>> 0 | ||
1863 | byteLength = byteLength >>> 0 | ||
1864 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
1865 | |||
1866 | var i = byteLength | ||
1867 | var mul = 1 | ||
1868 | var val = this[offset + --i] | ||
1869 | while (i > 0 && (mul *= 0x100)) { | ||
1870 | val += this[offset + --i] * mul | ||
1871 | } | ||
1872 | mul *= 0x80 | ||
1873 | |||
1874 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
1875 | |||
1876 | return val | ||
1877 | } | ||
1878 | |||
1879 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { | ||
1880 | offset = offset >>> 0 | ||
1881 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
1882 | if (!(this[offset] & 0x80)) return (this[offset]) | ||
1883 | return ((0xff - this[offset] + 1) * -1) | ||
1884 | } | ||
1885 | |||
1886 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { | ||
1887 | offset = offset >>> 0 | ||
1888 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1889 | var val = this[offset] | (this[offset + 1] << 8) | ||
1890 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
1891 | } | ||
1892 | |||
1893 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { | ||
1894 | offset = offset >>> 0 | ||
1895 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
1896 | var val = this[offset + 1] | (this[offset] << 8) | ||
1897 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
1898 | } | ||
1899 | |||
1900 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { | ||
1901 | offset = offset >>> 0 | ||
1902 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1903 | |||
1904 | return (this[offset]) | | ||
1905 | (this[offset + 1] << 8) | | ||
1906 | (this[offset + 2] << 16) | | ||
1907 | (this[offset + 3] << 24) | ||
1908 | } | ||
1909 | |||
1910 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { | ||
1911 | offset = offset >>> 0 | ||
1912 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1913 | |||
1914 | return (this[offset] << 24) | | ||
1915 | (this[offset + 1] << 16) | | ||
1916 | (this[offset + 2] << 8) | | ||
1917 | (this[offset + 3]) | ||
1918 | } | ||
1919 | |||
1920 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { | ||
1921 | offset = offset >>> 0 | ||
1922 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1923 | return ieee754.read(this, offset, true, 23, 4) | ||
1924 | } | ||
1925 | |||
1926 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { | ||
1927 | offset = offset >>> 0 | ||
1928 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
1929 | return ieee754.read(this, offset, false, 23, 4) | ||
1930 | } | ||
1931 | |||
1932 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { | ||
1933 | offset = offset >>> 0 | ||
1934 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
1935 | return ieee754.read(this, offset, true, 52, 8) | ||
1936 | } | ||
1937 | |||
1938 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { | ||
1939 | offset = offset >>> 0 | ||
1940 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
1941 | return ieee754.read(this, offset, false, 52, 8) | ||
1942 | } | ||
1943 | |||
1944 | function checkInt (buf, value, offset, ext, max, min) { | ||
1945 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') | ||
1946 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') | ||
1947 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
1948 | } | ||
1949 | |||
1950 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { | ||
1951 | value = +value | ||
1952 | offset = offset >>> 0 | ||
1953 | byteLength = byteLength >>> 0 | ||
1954 | if (!noAssert) { | ||
1955 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
1956 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
1957 | } | ||
1958 | |||
1959 | var mul = 1 | ||
1960 | var i = 0 | ||
1961 | this[offset] = value & 0xFF | ||
1962 | while (++i < byteLength && (mul *= 0x100)) { | ||
1963 | this[offset + i] = (value / mul) & 0xFF | ||
1964 | } | ||
1965 | |||
1966 | return offset + byteLength | ||
1967 | } | ||
1968 | |||
1969 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { | ||
1970 | value = +value | ||
1971 | offset = offset >>> 0 | ||
1972 | byteLength = byteLength >>> 0 | ||
1973 | if (!noAssert) { | ||
1974 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
1975 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
1976 | } | ||
1977 | |||
1978 | var i = byteLength - 1 | ||
1979 | var mul = 1 | ||
1980 | this[offset + i] = value & 0xFF | ||
1981 | while (--i >= 0 && (mul *= 0x100)) { | ||
1982 | this[offset + i] = (value / mul) & 0xFF | ||
1983 | } | ||
1984 | |||
1985 | return offset + byteLength | ||
1986 | } | ||
1987 | |||
1988 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { | ||
1989 | value = +value | ||
1990 | offset = offset >>> 0 | ||
1991 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | ||
1992 | this[offset] = (value & 0xff) | ||
1993 | return offset + 1 | ||
1994 | } | ||
1995 | |||
1996 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { | ||
1997 | value = +value | ||
1998 | offset = offset >>> 0 | ||
1999 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
2000 | this[offset] = (value & 0xff) | ||
2001 | this[offset + 1] = (value >>> 8) | ||
2002 | return offset + 2 | ||
2003 | } | ||
2004 | |||
2005 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { | ||
2006 | value = +value | ||
2007 | offset = offset >>> 0 | ||
2008 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
2009 | this[offset] = (value >>> 8) | ||
2010 | this[offset + 1] = (value & 0xff) | ||
2011 | return offset + 2 | ||
2012 | } | ||
2013 | |||
2014 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { | ||
2015 | value = +value | ||
2016 | offset = offset >>> 0 | ||
2017 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
2018 | this[offset + 3] = (value >>> 24) | ||
2019 | this[offset + 2] = (value >>> 16) | ||
2020 | this[offset + 1] = (value >>> 8) | ||
2021 | this[offset] = (value & 0xff) | ||
2022 | return offset + 4 | ||
2023 | } | ||
2024 | |||
2025 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { | ||
2026 | value = +value | ||
2027 | offset = offset >>> 0 | ||
2028 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
2029 | this[offset] = (value >>> 24) | ||
2030 | this[offset + 1] = (value >>> 16) | ||
2031 | this[offset + 2] = (value >>> 8) | ||
2032 | this[offset + 3] = (value & 0xff) | ||
2033 | return offset + 4 | ||
2034 | } | ||
2035 | |||
2036 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { | ||
2037 | value = +value | ||
2038 | offset = offset >>> 0 | ||
2039 | if (!noAssert) { | ||
2040 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
2041 | |||
2042 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
2043 | } | ||
2044 | |||
2045 | var i = 0 | ||
2046 | var mul = 1 | ||
2047 | var sub = 0 | ||
2048 | this[offset] = value & 0xFF | ||
2049 | while (++i < byteLength && (mul *= 0x100)) { | ||
2050 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | ||
2051 | sub = 1 | ||
2052 | } | ||
2053 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
2054 | } | ||
2055 | |||
2056 | return offset + byteLength | ||
2057 | } | ||
2058 | |||
2059 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { | ||
2060 | value = +value | ||
2061 | offset = offset >>> 0 | ||
2062 | if (!noAssert) { | ||
2063 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
2064 | |||
2065 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
2066 | } | ||
2067 | |||
2068 | var i = byteLength - 1 | ||
2069 | var mul = 1 | ||
2070 | var sub = 0 | ||
2071 | this[offset + i] = value & 0xFF | ||
2072 | while (--i >= 0 && (mul *= 0x100)) { | ||
2073 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | ||
2074 | sub = 1 | ||
2075 | } | ||
2076 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
2077 | } | ||
2078 | |||
2079 | return offset + byteLength | ||
2080 | } | ||
2081 | |||
2082 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { | ||
2083 | value = +value | ||
2084 | offset = offset >>> 0 | ||
2085 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | ||
2086 | if (value < 0) value = 0xff + value + 1 | ||
2087 | this[offset] = (value & 0xff) | ||
2088 | return offset + 1 | ||
2089 | } | ||
2090 | |||
2091 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { | ||
2092 | value = +value | ||
2093 | offset = offset >>> 0 | ||
2094 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
2095 | this[offset] = (value & 0xff) | ||
2096 | this[offset + 1] = (value >>> 8) | ||
2097 | return offset + 2 | ||
2098 | } | ||
2099 | |||
2100 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { | ||
2101 | value = +value | ||
2102 | offset = offset >>> 0 | ||
2103 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
2104 | this[offset] = (value >>> 8) | ||
2105 | this[offset + 1] = (value & 0xff) | ||
2106 | return offset + 2 | ||
2107 | } | ||
2108 | |||
2109 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { | ||
2110 | value = +value | ||
2111 | offset = offset >>> 0 | ||
2112 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
2113 | this[offset] = (value & 0xff) | ||
2114 | this[offset + 1] = (value >>> 8) | ||
2115 | this[offset + 2] = (value >>> 16) | ||
2116 | this[offset + 3] = (value >>> 24) | ||
2117 | return offset + 4 | ||
2118 | } | ||
2119 | |||
2120 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { | ||
2121 | value = +value | ||
2122 | offset = offset >>> 0 | ||
2123 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
2124 | if (value < 0) value = 0xffffffff + value + 1 | ||
2125 | this[offset] = (value >>> 24) | ||
2126 | this[offset + 1] = (value >>> 16) | ||
2127 | this[offset + 2] = (value >>> 8) | ||
2128 | this[offset + 3] = (value & 0xff) | ||
2129 | return offset + 4 | ||
2130 | } | ||
2131 | |||
2132 | function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
2133 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
2134 | if (offset < 0) throw new RangeError('Index out of range') | ||
2135 | } | ||
2136 | |||
2137 | function writeFloat (buf, value, offset, littleEndian, noAssert) { | ||
2138 | value = +value | ||
2139 | offset = offset >>> 0 | ||
2140 | if (!noAssert) { | ||
2141 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | ||
2142 | } | ||
2143 | ieee754.write(buf, value, offset, littleEndian, 23, 4) | ||
2144 | return offset + 4 | ||
2145 | } | ||
2146 | |||
2147 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { | ||
2148 | return writeFloat(this, value, offset, true, noAssert) | ||
2149 | } | ||
2150 | |||
2151 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { | ||
2152 | return writeFloat(this, value, offset, false, noAssert) | ||
2153 | } | ||
2154 | |||
2155 | function writeDouble (buf, value, offset, littleEndian, noAssert) { | ||
2156 | value = +value | ||
2157 | offset = offset >>> 0 | ||
2158 | if (!noAssert) { | ||
2159 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | ||
2160 | } | ||
2161 | ieee754.write(buf, value, offset, littleEndian, 52, 8) | ||
2162 | return offset + 8 | ||
2163 | } | ||
2164 | |||
2165 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { | ||
2166 | return writeDouble(this, value, offset, true, noAssert) | ||
2167 | } | ||
2168 | |||
2169 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { | ||
2170 | return writeDouble(this, value, offset, false, noAssert) | ||
2171 | } | ||
2172 | |||
2173 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
2174 | Buffer.prototype.copy = function copy (target, targetStart, start, end) { | ||
2175 | if (!start) start = 0 | ||
2176 | if (!end && end !== 0) end = this.length | ||
2177 | if (targetStart >= target.length) targetStart = target.length | ||
2178 | if (!targetStart) targetStart = 0 | ||
2179 | if (end > 0 && end < start) end = start | ||
2180 | |||
2181 | // Copy 0 bytes; we're done | ||
2182 | if (end === start) return 0 | ||
2183 | if (target.length === 0 || this.length === 0) return 0 | ||
2184 | |||
2185 | // Fatal error conditions | ||
2186 | if (targetStart < 0) { | ||
2187 | throw new RangeError('targetStart out of bounds') | ||
2188 | } | ||
2189 | if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') | ||
2190 | if (end < 0) throw new RangeError('sourceEnd out of bounds') | ||
2191 | |||
2192 | // Are we oob? | ||
2193 | if (end > this.length) end = this.length | ||
2194 | if (target.length - targetStart < end - start) { | ||
2195 | end = target.length - targetStart + start | ||
2196 | } | ||
2197 | |||
2198 | var len = end - start | ||
2199 | var i | ||
2200 | |||
2201 | if (this === target && start < targetStart && targetStart < end) { | ||
2202 | // descending copy from end | ||
2203 | for (i = len - 1; i >= 0; --i) { | ||
2204 | target[i + targetStart] = this[i + start] | ||
2205 | } | ||
2206 | } else if (len < 1000) { | ||
2207 | // ascending copy from start | ||
2208 | for (i = 0; i < len; ++i) { | ||
2209 | target[i + targetStart] = this[i + start] | ||
2210 | } | ||
2211 | } else { | ||
2212 | Uint8Array.prototype.set.call( | ||
2213 | target, | ||
2214 | this.subarray(start, start + len), | ||
2215 | targetStart | ||
2216 | ) | ||
2217 | } | ||
2218 | |||
2219 | return len | ||
2220 | } | ||
2221 | |||
2222 | // Usage: | ||
2223 | // buffer.fill(number[, offset[, end]]) | ||
2224 | // buffer.fill(buffer[, offset[, end]]) | ||
2225 | // buffer.fill(string[, offset[, end]][, encoding]) | ||
2226 | Buffer.prototype.fill = function fill (val, start, end, encoding) { | ||
2227 | // Handle string cases: | ||
2228 | if (typeof val === 'string') { | ||
2229 | if (typeof start === 'string') { | ||
2230 | encoding = start | ||
2231 | start = 0 | ||
2232 | end = this.length | ||
2233 | } else if (typeof end === 'string') { | ||
2234 | encoding = end | ||
2235 | end = this.length | ||
2236 | } | ||
2237 | if (val.length === 1) { | ||
2238 | var code = val.charCodeAt(0) | ||
2239 | if (code < 256) { | ||
2240 | val = code | ||
2241 | } | ||
2242 | } | ||
2243 | if (encoding !== undefined && typeof encoding !== 'string') { | ||
2244 | throw new TypeError('encoding must be a string') | ||
2245 | } | ||
2246 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { | ||
2247 | throw new TypeError('Unknown encoding: ' + encoding) | ||
2248 | } | ||
2249 | } else if (typeof val === 'number') { | ||
2250 | val = val & 255 | ||
2251 | } | ||
2252 | |||
2253 | // Invalid ranges are not set to a default, so can range check early. | ||
2254 | if (start < 0 || this.length < start || this.length < end) { | ||
2255 | throw new RangeError('Out of range index') | ||
2256 | } | ||
2257 | |||
2258 | if (end <= start) { | ||
2259 | return this | ||
2260 | } | ||
2261 | |||
2262 | start = start >>> 0 | ||
2263 | end = end === undefined ? this.length : end >>> 0 | ||
2264 | |||
2265 | if (!val) val = 0 | ||
2266 | |||
2267 | var i | ||
2268 | if (typeof val === 'number') { | ||
2269 | for (i = start; i < end; ++i) { | ||
2270 | this[i] = val | ||
2271 | } | ||
2272 | } else { | ||
2273 | var bytes = Buffer.isBuffer(val) | ||
2274 | ? val | ||
2275 | : new Buffer(val, encoding) | ||
2276 | var len = bytes.length | ||
2277 | for (i = 0; i < end - start; ++i) { | ||
2278 | this[i + start] = bytes[i % len] | ||
2279 | } | ||
2280 | } | ||
2281 | |||
2282 | return this | ||
2283 | } | ||
2284 | |||
2285 | // HELPER FUNCTIONS | ||
2286 | // ================ | ||
2287 | |||
2288 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g | ||
2289 | |||
2290 | function base64clean (str) { | ||
2291 | // Node strips out invalid characters like \n and \t from the string, base64-js does not | ||
2292 | str = stringtrim(str).replace(INVALID_BASE64_RE, '') | ||
2293 | // Node converts strings with length < 2 to '' | ||
2294 | if (str.length < 2) return '' | ||
2295 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | ||
2296 | while (str.length % 4 !== 0) { | ||
2297 | str = str + '=' | ||
2298 | } | ||
2299 | return str | ||
2300 | } | ||
2301 | |||
2302 | function stringtrim (str) { | ||
2303 | if (str.trim) return str.trim() | ||
2304 | return str.replace(/^\s+|\s+$/g, '') | ||
2305 | } | ||
2306 | |||
2307 | function toHex (n) { | ||
2308 | if (n < 16) return '0' + n.toString(16) | ||
2309 | return n.toString(16) | ||
2310 | } | ||
2311 | |||
2312 | function utf8ToBytes (string, units) { | ||
2313 | units = units || Infinity | ||
2314 | var codePoint | ||
2315 | var length = string.length | ||
2316 | var leadSurrogate = null | ||
2317 | var bytes = [] | ||
2318 | |||
2319 | for (var i = 0; i < length; ++i) { | ||
2320 | codePoint = string.charCodeAt(i) | ||
2321 | |||
2322 | // is surrogate component | ||
2323 | if (codePoint > 0xD7FF && codePoint < 0xE000) { | ||
2324 | // last char was a lead | ||
2325 | if (!leadSurrogate) { | ||
2326 | // no lead yet | ||
2327 | if (codePoint > 0xDBFF) { | ||
2328 | // unexpected trail | ||
2329 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
2330 | continue | ||
2331 | } else if (i + 1 === length) { | ||
2332 | // unpaired lead | ||
2333 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
2334 | continue | ||
2335 | } | ||
2336 | |||
2337 | // valid lead | ||
2338 | leadSurrogate = codePoint | ||
2339 | |||
2340 | continue | ||
2341 | } | ||
2342 | |||
2343 | // 2 leads in a row | ||
2344 | if (codePoint < 0xDC00) { | ||
2345 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
2346 | leadSurrogate = codePoint | ||
2347 | continue | ||
2348 | } | ||
2349 | |||
2350 | // valid surrogate pair | ||
2351 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 | ||
2352 | } else if (leadSurrogate) { | ||
2353 | // valid bmp char, but last char was a lead | ||
2354 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
2355 | } | ||
2356 | |||
2357 | leadSurrogate = null | ||
2358 | |||
2359 | // encode utf8 | ||
2360 | if (codePoint < 0x80) { | ||
2361 | if ((units -= 1) < 0) break | ||
2362 | bytes.push(codePoint) | ||
2363 | } else if (codePoint < 0x800) { | ||
2364 | if ((units -= 2) < 0) break | ||
2365 | bytes.push( | ||
2366 | codePoint >> 0x6 | 0xC0, | ||
2367 | codePoint & 0x3F | 0x80 | ||
2368 | ) | ||
2369 | } else if (codePoint < 0x10000) { | ||
2370 | if ((units -= 3) < 0) break | ||
2371 | bytes.push( | ||
2372 | codePoint >> 0xC | 0xE0, | ||
2373 | codePoint >> 0x6 & 0x3F | 0x80, | ||
2374 | codePoint & 0x3F | 0x80 | ||
2375 | ) | ||
2376 | } else if (codePoint < 0x110000) { | ||
2377 | if ((units -= 4) < 0) break | ||
2378 | bytes.push( | ||
2379 | codePoint >> 0x12 | 0xF0, | ||
2380 | codePoint >> 0xC & 0x3F | 0x80, | ||
2381 | codePoint >> 0x6 & 0x3F | 0x80, | ||
2382 | codePoint & 0x3F | 0x80 | ||
2383 | ) | ||
2384 | } else { | ||
2385 | throw new Error('Invalid code point') | ||
2386 | } | ||
2387 | } | ||
2388 | |||
2389 | return bytes | ||
2390 | } | ||
2391 | |||
2392 | function asciiToBytes (str) { | ||
2393 | var byteArray = [] | ||
2394 | for (var i = 0; i < str.length; ++i) { | ||
2395 | // Node's code seems to be doing this and not & 0x7F.. | ||
2396 | byteArray.push(str.charCodeAt(i) & 0xFF) | ||
2397 | } | ||
2398 | return byteArray | ||
2399 | } | ||
2400 | |||
2401 | function utf16leToBytes (str, units) { | ||
2402 | var c, hi, lo | ||
2403 | var byteArray = [] | ||
2404 | for (var i = 0; i < str.length; ++i) { | ||
2405 | if ((units -= 2) < 0) break | ||
2406 | |||
2407 | c = str.charCodeAt(i) | ||
2408 | hi = c >> 8 | ||
2409 | lo = c % 256 | ||
2410 | byteArray.push(lo) | ||
2411 | byteArray.push(hi) | ||
2412 | } | ||
2413 | |||
2414 | return byteArray | ||
2415 | } | ||
2416 | |||
2417 | function base64ToBytes (str) { | ||
2418 | return base64.toByteArray(base64clean(str)) | ||
2419 | } | ||
2420 | |||
2421 | function blitBuffer (src, dst, offset, length) { | ||
2422 | for (var i = 0; i < length; ++i) { | ||
2423 | if ((i + offset >= dst.length) || (i >= src.length)) break | ||
2424 | dst[i + offset] = src[i] | ||
2425 | } | ||
2426 | return i | ||
2427 | } | ||
2428 | |||
2429 | function isnan (val) { | ||
2430 | return val !== val // eslint-disable-line no-self-compare | ||
2431 | } | ||
2432 | |||
2433 | },{"base64-js":2,"ieee754":8}],6:[function(require,module,exports){ | ||
2434 | (function (Buffer){ | ||
2435 | // Copyright Joyent, Inc. and other Node contributors. | ||
2436 | // | ||
2437 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
2438 | // copy of this software and associated documentation files (the | ||
2439 | // "Software"), to deal in the Software without restriction, including | ||
2440 | // without limitation the rights to use, copy, modify, merge, publish, | ||
2441 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
2442 | // persons to whom the Software is furnished to do so, subject to the | ||
2443 | // following conditions: | ||
2444 | // | ||
2445 | // The above copyright notice and this permission notice shall be included | ||
2446 | // in all copies or substantial portions of the Software. | ||
2447 | // | ||
2448 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
2449 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
2450 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
2451 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
2452 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
2453 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
2454 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
2455 | |||
2456 | // NOTE: These type checking functions intentionally don't use `instanceof` | ||
2457 | // because it is fragile and can be easily faked with `Object.create()`. | ||
2458 | |||
2459 | function isArray(arg) { | ||
2460 | if (Array.isArray) { | ||
2461 | return Array.isArray(arg); | ||
2462 | } | ||
2463 | return objectToString(arg) === '[object Array]'; | ||
2464 | } | ||
2465 | exports.isArray = isArray; | ||
2466 | |||
2467 | function isBoolean(arg) { | ||
2468 | return typeof arg === 'boolean'; | ||
2469 | } | ||
2470 | exports.isBoolean = isBoolean; | ||
2471 | |||
2472 | function isNull(arg) { | ||
2473 | return arg === null; | ||
2474 | } | ||
2475 | exports.isNull = isNull; | ||
2476 | |||
2477 | function isNullOrUndefined(arg) { | ||
2478 | return arg == null; | ||
2479 | } | ||
2480 | exports.isNullOrUndefined = isNullOrUndefined; | ||
2481 | |||
2482 | function isNumber(arg) { | ||
2483 | return typeof arg === 'number'; | ||
2484 | } | ||
2485 | exports.isNumber = isNumber; | ||
2486 | |||
2487 | function isString(arg) { | ||
2488 | return typeof arg === 'string'; | ||
2489 | } | ||
2490 | exports.isString = isString; | ||
2491 | |||
2492 | function isSymbol(arg) { | ||
2493 | return typeof arg === 'symbol'; | ||
2494 | } | ||
2495 | exports.isSymbol = isSymbol; | ||
2496 | |||
2497 | function isUndefined(arg) { | ||
2498 | return arg === void 0; | ||
2499 | } | ||
2500 | exports.isUndefined = isUndefined; | ||
2501 | |||
2502 | function isRegExp(re) { | ||
2503 | return objectToString(re) === '[object RegExp]'; | ||
2504 | } | ||
2505 | exports.isRegExp = isRegExp; | ||
2506 | |||
2507 | function isObject(arg) { | ||
2508 | return typeof arg === 'object' && arg !== null; | ||
2509 | } | ||
2510 | exports.isObject = isObject; | ||
2511 | |||
2512 | function isDate(d) { | ||
2513 | return objectToString(d) === '[object Date]'; | ||
2514 | } | ||
2515 | exports.isDate = isDate; | ||
2516 | |||
2517 | function isError(e) { | ||
2518 | return (objectToString(e) === '[object Error]' || e instanceof Error); | ||
2519 | } | ||
2520 | exports.isError = isError; | ||
2521 | |||
2522 | function isFunction(arg) { | ||
2523 | return typeof arg === 'function'; | ||
2524 | } | ||
2525 | exports.isFunction = isFunction; | ||
2526 | |||
2527 | function isPrimitive(arg) { | ||
2528 | return arg === null || | ||
2529 | typeof arg === 'boolean' || | ||
2530 | typeof arg === 'number' || | ||
2531 | typeof arg === 'string' || | ||
2532 | typeof arg === 'symbol' || // ES6 symbol | ||
2533 | typeof arg === 'undefined'; | ||
2534 | } | ||
2535 | exports.isPrimitive = isPrimitive; | ||
2536 | |||
2537 | exports.isBuffer = Buffer.isBuffer; | ||
2538 | |||
2539 | function objectToString(o) { | ||
2540 | return Object.prototype.toString.call(o); | ||
2541 | } | ||
2542 | |||
2543 | }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) | ||
2544 | },{"../../is-buffer/index.js":10}],7:[function(require,module,exports){ | ||
2545 | // Copyright Joyent, Inc. and other Node contributors. | ||
2546 | // | ||
2547 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
2548 | // copy of this software and associated documentation files (the | ||
2549 | // "Software"), to deal in the Software without restriction, including | ||
2550 | // without limitation the rights to use, copy, modify, merge, publish, | ||
2551 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
2552 | // persons to whom the Software is furnished to do so, subject to the | ||
2553 | // following conditions: | ||
2554 | // | ||
2555 | // The above copyright notice and this permission notice shall be included | ||
2556 | // in all copies or substantial portions of the Software. | ||
2557 | // | ||
2558 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
2559 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
2560 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
2561 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
2562 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
2563 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
2564 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
2565 | |||
2566 | function EventEmitter() { | ||
2567 | this._events = this._events || {}; | ||
2568 | this._maxListeners = this._maxListeners || undefined; | ||
2569 | } | ||
2570 | module.exports = EventEmitter; | ||
2571 | |||
2572 | // Backwards-compat with node 0.10.x | ||
2573 | EventEmitter.EventEmitter = EventEmitter; | ||
2574 | |||
2575 | EventEmitter.prototype._events = undefined; | ||
2576 | EventEmitter.prototype._maxListeners = undefined; | ||
2577 | |||
2578 | // By default EventEmitters will print a warning if more than 10 listeners are | ||
2579 | // added to it. This is a useful default which helps finding memory leaks. | ||
2580 | EventEmitter.defaultMaxListeners = 10; | ||
2581 | |||
2582 | // Obviously not all Emitters should be limited to 10. This function allows | ||
2583 | // that to be increased. Set to zero for unlimited. | ||
2584 | EventEmitter.prototype.setMaxListeners = function(n) { | ||
2585 | if (!isNumber(n) || n < 0 || isNaN(n)) | ||
2586 | throw TypeError('n must be a positive number'); | ||
2587 | this._maxListeners = n; | ||
2588 | return this; | ||
2589 | }; | ||
2590 | |||
2591 | EventEmitter.prototype.emit = function(type) { | ||
2592 | var er, handler, len, args, i, listeners; | ||
2593 | |||
2594 | if (!this._events) | ||
2595 | this._events = {}; | ||
2596 | |||
2597 | // If there is no 'error' event listener then throw. | ||
2598 | if (type === 'error') { | ||
2599 | if (!this._events.error || | ||
2600 | (isObject(this._events.error) && !this._events.error.length)) { | ||
2601 | er = arguments[1]; | ||
2602 | if (er instanceof Error) { | ||
2603 | throw er; // Unhandled 'error' event | ||
2604 | } else { | ||
2605 | // At least give some kind of context to the user | ||
2606 | var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); | ||
2607 | err.context = er; | ||
2608 | throw err; | ||
2609 | } | ||
2610 | } | ||
2611 | } | ||
2612 | |||
2613 | handler = this._events[type]; | ||
2614 | |||
2615 | if (isUndefined(handler)) | ||
2616 | return false; | ||
2617 | |||
2618 | if (isFunction(handler)) { | ||
2619 | switch (arguments.length) { | ||
2620 | // fast cases | ||
2621 | case 1: | ||
2622 | handler.call(this); | ||
2623 | break; | ||
2624 | case 2: | ||
2625 | handler.call(this, arguments[1]); | ||
2626 | break; | ||
2627 | case 3: | ||
2628 | handler.call(this, arguments[1], arguments[2]); | ||
2629 | break; | ||
2630 | // slower | ||
2631 | default: | ||
2632 | args = Array.prototype.slice.call(arguments, 1); | ||
2633 | handler.apply(this, args); | ||
2634 | } | ||
2635 | } else if (isObject(handler)) { | ||
2636 | args = Array.prototype.slice.call(arguments, 1); | ||
2637 | listeners = handler.slice(); | ||
2638 | len = listeners.length; | ||
2639 | for (i = 0; i < len; i++) | ||
2640 | listeners[i].apply(this, args); | ||
2641 | } | ||
2642 | |||
2643 | return true; | ||
2644 | }; | ||
2645 | |||
2646 | EventEmitter.prototype.addListener = function(type, listener) { | ||
2647 | var m; | ||
2648 | |||
2649 | if (!isFunction(listener)) | ||
2650 | throw TypeError('listener must be a function'); | ||
2651 | |||
2652 | if (!this._events) | ||
2653 | this._events = {}; | ||
2654 | |||
2655 | // To avoid recursion in the case that type === "newListener"! Before | ||
2656 | // adding it to the listeners, first emit "newListener". | ||
2657 | if (this._events.newListener) | ||
2658 | this.emit('newListener', type, | ||
2659 | isFunction(listener.listener) ? | ||
2660 | listener.listener : listener); | ||
2661 | |||
2662 | if (!this._events[type]) | ||
2663 | // Optimize the case of one listener. Don't need the extra array object. | ||
2664 | this._events[type] = listener; | ||
2665 | else if (isObject(this._events[type])) | ||
2666 | // If we've already got an array, just append. | ||
2667 | this._events[type].push(listener); | ||
2668 | else | ||
2669 | // Adding the second element, need to change to array. | ||
2670 | this._events[type] = [this._events[type], listener]; | ||
2671 | |||
2672 | // Check for listener leak | ||
2673 | if (isObject(this._events[type]) && !this._events[type].warned) { | ||
2674 | if (!isUndefined(this._maxListeners)) { | ||
2675 | m = this._maxListeners; | ||
2676 | } else { | ||
2677 | m = EventEmitter.defaultMaxListeners; | ||
2678 | } | ||
2679 | |||
2680 | if (m && m > 0 && this._events[type].length > m) { | ||
2681 | this._events[type].warned = true; | ||
2682 | console.error('(node) warning: possible EventEmitter memory ' + | ||
2683 | 'leak detected. %d listeners added. ' + | ||
2684 | 'Use emitter.setMaxListeners() to increase limit.', | ||
2685 | this._events[type].length); | ||
2686 | if (typeof console.trace === 'function') { | ||
2687 | // not supported in IE 10 | ||
2688 | console.trace(); | ||
2689 | } | ||
2690 | } | ||
2691 | } | ||
2692 | |||
2693 | return this; | ||
2694 | }; | ||
2695 | |||
2696 | EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
2697 | |||
2698 | EventEmitter.prototype.once = function(type, listener) { | ||
2699 | if (!isFunction(listener)) | ||
2700 | throw TypeError('listener must be a function'); | ||
2701 | |||
2702 | var fired = false; | ||
2703 | |||
2704 | function g() { | ||
2705 | this.removeListener(type, g); | ||
2706 | |||
2707 | if (!fired) { | ||
2708 | fired = true; | ||
2709 | listener.apply(this, arguments); | ||
2710 | } | ||
2711 | } | ||
2712 | |||
2713 | g.listener = listener; | ||
2714 | this.on(type, g); | ||
2715 | |||
2716 | return this; | ||
2717 | }; | ||
2718 | |||
2719 | // emits a 'removeListener' event iff the listener was removed | ||
2720 | EventEmitter.prototype.removeListener = function(type, listener) { | ||
2721 | var list, position, length, i; | ||
2722 | |||
2723 | if (!isFunction(listener)) | ||
2724 | throw TypeError('listener must be a function'); | ||
2725 | |||
2726 | if (!this._events || !this._events[type]) | ||
2727 | return this; | ||
2728 | |||
2729 | list = this._events[type]; | ||
2730 | length = list.length; | ||
2731 | position = -1; | ||
2732 | |||
2733 | if (list === listener || | ||
2734 | (isFunction(list.listener) && list.listener === listener)) { | ||
2735 | delete this._events[type]; | ||
2736 | if (this._events.removeListener) | ||
2737 | this.emit('removeListener', type, listener); | ||
2738 | |||
2739 | } else if (isObject(list)) { | ||
2740 | for (i = length; i-- > 0;) { | ||
2741 | if (list[i] === listener || | ||
2742 | (list[i].listener && list[i].listener === listener)) { | ||
2743 | position = i; | ||
2744 | break; | ||
2745 | } | ||
2746 | } | ||
2747 | |||
2748 | if (position < 0) | ||
2749 | return this; | ||
2750 | |||
2751 | if (list.length === 1) { | ||
2752 | list.length = 0; | ||
2753 | delete this._events[type]; | ||
2754 | } else { | ||
2755 | list.splice(position, 1); | ||
2756 | } | ||
2757 | |||
2758 | if (this._events.removeListener) | ||
2759 | this.emit('removeListener', type, listener); | ||
2760 | } | ||
2761 | |||
2762 | return this; | ||
2763 | }; | ||
2764 | |||
2765 | EventEmitter.prototype.removeAllListeners = function(type) { | ||
2766 | var key, listeners; | ||
2767 | |||
2768 | if (!this._events) | ||
2769 | return this; | ||
2770 | |||
2771 | // not listening for removeListener, no need to emit | ||
2772 | if (!this._events.removeListener) { | ||
2773 | if (arguments.length === 0) | ||
2774 | this._events = {}; | ||
2775 | else if (this._events[type]) | ||
2776 | delete this._events[type]; | ||
2777 | return this; | ||
2778 | } | ||
2779 | |||
2780 | // emit removeListener for all listeners on all events | ||
2781 | if (arguments.length === 0) { | ||
2782 | for (key in this._events) { | ||
2783 | if (key === 'removeListener') continue; | ||
2784 | this.removeAllListeners(key); | ||
2785 | } | ||
2786 | this.removeAllListeners('removeListener'); | ||
2787 | this._events = {}; | ||
2788 | return this; | ||
2789 | } | ||
2790 | |||
2791 | listeners = this._events[type]; | ||
2792 | |||
2793 | if (isFunction(listeners)) { | ||
2794 | this.removeListener(type, listeners); | ||
2795 | } else if (listeners) { | ||
2796 | // LIFO order | ||
2797 | while (listeners.length) | ||
2798 | this.removeListener(type, listeners[listeners.length - 1]); | ||
2799 | } | ||
2800 | delete this._events[type]; | ||
2801 | |||
2802 | return this; | ||
2803 | }; | ||
2804 | |||
2805 | EventEmitter.prototype.listeners = function(type) { | ||
2806 | var ret; | ||
2807 | if (!this._events || !this._events[type]) | ||
2808 | ret = []; | ||
2809 | else if (isFunction(this._events[type])) | ||
2810 | ret = [this._events[type]]; | ||
2811 | else | ||
2812 | ret = this._events[type].slice(); | ||
2813 | return ret; | ||
2814 | }; | ||
2815 | |||
2816 | EventEmitter.prototype.listenerCount = function(type) { | ||
2817 | if (this._events) { | ||
2818 | var evlistener = this._events[type]; | ||
2819 | |||
2820 | if (isFunction(evlistener)) | ||
2821 | return 1; | ||
2822 | else if (evlistener) | ||
2823 | return evlistener.length; | ||
2824 | } | ||
2825 | return 0; | ||
2826 | }; | ||
2827 | |||
2828 | EventEmitter.listenerCount = function(emitter, type) { | ||
2829 | return emitter.listenerCount(type); | ||
2830 | }; | ||
2831 | |||
2832 | function isFunction(arg) { | ||
2833 | return typeof arg === 'function'; | ||
2834 | } | ||
2835 | |||
2836 | function isNumber(arg) { | ||
2837 | return typeof arg === 'number'; | ||
2838 | } | ||
2839 | |||
2840 | function isObject(arg) { | ||
2841 | return typeof arg === 'object' && arg !== null; | ||
2842 | } | ||
2843 | |||
2844 | function isUndefined(arg) { | ||
2845 | return arg === void 0; | ||
2846 | } | ||
2847 | |||
2848 | },{}],8:[function(require,module,exports){ | ||
2849 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { | ||
2850 | var e, m | ||
2851 | var eLen = nBytes * 8 - mLen - 1 | ||
2852 | var eMax = (1 << eLen) - 1 | ||
2853 | var eBias = eMax >> 1 | ||
2854 | var nBits = -7 | ||
2855 | var i = isLE ? (nBytes - 1) : 0 | ||
2856 | var d = isLE ? -1 : 1 | ||
2857 | var s = buffer[offset + i] | ||
2858 | |||
2859 | i += d | ||
2860 | |||
2861 | e = s & ((1 << (-nBits)) - 1) | ||
2862 | s >>= (-nBits) | ||
2863 | nBits += eLen | ||
2864 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
2865 | |||
2866 | m = e & ((1 << (-nBits)) - 1) | ||
2867 | e >>= (-nBits) | ||
2868 | nBits += mLen | ||
2869 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
2870 | |||
2871 | if (e === 0) { | ||
2872 | e = 1 - eBias | ||
2873 | } else if (e === eMax) { | ||
2874 | return m ? NaN : ((s ? -1 : 1) * Infinity) | ||
2875 | } else { | ||
2876 | m = m + Math.pow(2, mLen) | ||
2877 | e = e - eBias | ||
2878 | } | ||
2879 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | ||
2880 | } | ||
2881 | |||
2882 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | ||
2883 | var e, m, c | ||
2884 | var eLen = nBytes * 8 - mLen - 1 | ||
2885 | var eMax = (1 << eLen) - 1 | ||
2886 | var eBias = eMax >> 1 | ||
2887 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | ||
2888 | var i = isLE ? 0 : (nBytes - 1) | ||
2889 | var d = isLE ? 1 : -1 | ||
2890 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | ||
2891 | |||
2892 | value = Math.abs(value) | ||
2893 | |||
2894 | if (isNaN(value) || value === Infinity) { | ||
2895 | m = isNaN(value) ? 1 : 0 | ||
2896 | e = eMax | ||
2897 | } else { | ||
2898 | e = Math.floor(Math.log(value) / Math.LN2) | ||
2899 | if (value * (c = Math.pow(2, -e)) < 1) { | ||
2900 | e-- | ||
2901 | c *= 2 | ||
2902 | } | ||
2903 | if (e + eBias >= 1) { | ||
2904 | value += rt / c | ||
2905 | } else { | ||
2906 | value += rt * Math.pow(2, 1 - eBias) | ||
2907 | } | ||
2908 | if (value * c >= 2) { | ||
2909 | e++ | ||
2910 | c /= 2 | ||
2911 | } | ||
2912 | |||
2913 | if (e + eBias >= eMax) { | ||
2914 | m = 0 | ||
2915 | e = eMax | ||
2916 | } else if (e + eBias >= 1) { | ||
2917 | m = (value * c - 1) * Math.pow(2, mLen) | ||
2918 | e = e + eBias | ||
2919 | } else { | ||
2920 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | ||
2921 | e = 0 | ||
2922 | } | ||
2923 | } | ||
2924 | |||
2925 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | ||
2926 | |||
2927 | e = (e << mLen) | m | ||
2928 | eLen += mLen | ||
2929 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
2930 | |||
2931 | buffer[offset + i - d] |= s * 128 | ||
2932 | } | ||
2933 | |||
2934 | },{}],9:[function(require,module,exports){ | ||
2935 | if (typeof Object.create === 'function') { | ||
2936 | // implementation from standard node.js 'util' module | ||
2937 | module.exports = function inherits(ctor, superCtor) { | ||
2938 | ctor.super_ = superCtor | ||
2939 | ctor.prototype = Object.create(superCtor.prototype, { | ||
2940 | constructor: { | ||
2941 | value: ctor, | ||
2942 | enumerable: false, | ||
2943 | writable: true, | ||
2944 | configurable: true | ||
2945 | } | ||
2946 | }); | ||
2947 | }; | ||
2948 | } else { | ||
2949 | // old school shim for old browsers | ||
2950 | module.exports = function inherits(ctor, superCtor) { | ||
2951 | ctor.super_ = superCtor | ||
2952 | var TempCtor = function () {} | ||
2953 | TempCtor.prototype = superCtor.prototype | ||
2954 | ctor.prototype = new TempCtor() | ||
2955 | ctor.prototype.constructor = ctor | ||
2956 | } | ||
2957 | } | ||
2958 | |||
2959 | },{}],10:[function(require,module,exports){ | ||
2960 | /*! | ||
2961 | * Determine if an object is a Buffer | ||
2962 | * | ||
2963 | * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
2964 | * @license MIT | ||
2965 | */ | ||
2966 | |||
2967 | // The _isBuffer check is for Safari 5-7 support, because it's missing | ||
2968 | // Object.prototype.constructor. Remove this eventually | ||
2969 | module.exports = function (obj) { | ||
2970 | return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) | ||
2971 | } | ||
2972 | |||
2973 | function isBuffer (obj) { | ||
2974 | return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) | ||
2975 | } | ||
2976 | |||
2977 | // For Node v0.10 support. Remove this eventually. | ||
2978 | function isSlowBuffer (obj) { | ||
2979 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) | ||
2980 | } | ||
2981 | |||
2982 | },{}],11:[function(require,module,exports){ | ||
2983 | var toString = {}.toString; | ||
2984 | |||
2985 | module.exports = Array.isArray || function (arr) { | ||
2986 | return toString.call(arr) == '[object Array]'; | ||
2987 | }; | ||
2988 | |||
2989 | },{}],12:[function(require,module,exports){ | ||
2990 | (function (process){ | ||
2991 | 'use strict'; | ||
2992 | |||
2993 | if (!process.version || | ||
2994 | process.version.indexOf('v0.') === 0 || | ||
2995 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { | ||
2996 | module.exports = nextTick; | ||
2997 | } else { | ||
2998 | module.exports = process.nextTick; | ||
2999 | } | ||
3000 | |||
3001 | function nextTick(fn, arg1, arg2, arg3) { | ||
3002 | if (typeof fn !== 'function') { | ||
3003 | throw new TypeError('"callback" argument must be a function'); | ||
3004 | } | ||
3005 | var len = arguments.length; | ||
3006 | var args, i; | ||
3007 | switch (len) { | ||
3008 | case 0: | ||
3009 | case 1: | ||
3010 | return process.nextTick(fn); | ||
3011 | case 2: | ||
3012 | return process.nextTick(function afterTickOne() { | ||
3013 | fn.call(null, arg1); | ||
3014 | }); | ||
3015 | case 3: | ||
3016 | return process.nextTick(function afterTickTwo() { | ||
3017 | fn.call(null, arg1, arg2); | ||
3018 | }); | ||
3019 | case 4: | ||
3020 | return process.nextTick(function afterTickThree() { | ||
3021 | fn.call(null, arg1, arg2, arg3); | ||
3022 | }); | ||
3023 | default: | ||
3024 | args = new Array(len - 1); | ||
3025 | i = 0; | ||
3026 | while (i < args.length) { | ||
3027 | args[i++] = arguments[i]; | ||
3028 | } | ||
3029 | return process.nextTick(function afterTick() { | ||
3030 | fn.apply(null, args); | ||
3031 | }); | ||
3032 | } | ||
3033 | } | ||
3034 | |||
3035 | }).call(this,require('_process')) | ||
3036 | },{"_process":13}],13:[function(require,module,exports){ | ||
3037 | // shim for using process in browser | ||
3038 | var process = module.exports = {}; | ||
3039 | |||
3040 | // cached from whatever global is present so that test runners that stub it | ||
3041 | // don't break things. But we need to wrap it in a try catch in case it is | ||
3042 | // wrapped in strict mode code which doesn't define any globals. It's inside a | ||
3043 | // function because try/catches deoptimize in certain engines. | ||
3044 | |||
3045 | var cachedSetTimeout; | ||
3046 | var cachedClearTimeout; | ||
3047 | |||
3048 | function defaultSetTimout() { | ||
3049 | throw new Error('setTimeout has not been defined'); | ||
3050 | } | ||
3051 | function defaultClearTimeout () { | ||
3052 | throw new Error('clearTimeout has not been defined'); | ||
3053 | } | ||
3054 | (function () { | ||
3055 | try { | ||
3056 | if (typeof setTimeout === 'function') { | ||
3057 | cachedSetTimeout = setTimeout; | ||
3058 | } else { | ||
3059 | cachedSetTimeout = defaultSetTimout; | ||
3060 | } | ||
3061 | } catch (e) { | ||
3062 | cachedSetTimeout = defaultSetTimout; | ||
3063 | } | ||
3064 | try { | ||
3065 | if (typeof clearTimeout === 'function') { | ||
3066 | cachedClearTimeout = clearTimeout; | ||
3067 | } else { | ||
3068 | cachedClearTimeout = defaultClearTimeout; | ||
3069 | } | ||
3070 | } catch (e) { | ||
3071 | cachedClearTimeout = defaultClearTimeout; | ||
3072 | } | ||
3073 | } ()) | ||
3074 | function runTimeout(fun) { | ||
3075 | if (cachedSetTimeout === setTimeout) { | ||
3076 | //normal enviroments in sane situations | ||
3077 | return setTimeout(fun, 0); | ||
3078 | } | ||
3079 | // if setTimeout wasn't available but was latter defined | ||
3080 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | ||
3081 | cachedSetTimeout = setTimeout; | ||
3082 | return setTimeout(fun, 0); | ||
3083 | } | ||
3084 | try { | ||
3085 | // when when somebody has screwed with setTimeout but no I.E. maddness | ||
3086 | return cachedSetTimeout(fun, 0); | ||
3087 | } catch(e){ | ||
3088 | try { | ||
3089 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
3090 | return cachedSetTimeout.call(null, fun, 0); | ||
3091 | } catch(e){ | ||
3092 | // 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 | ||
3093 | return cachedSetTimeout.call(this, fun, 0); | ||
3094 | } | ||
3095 | } | ||
3096 | |||
3097 | |||
3098 | } | ||
3099 | function runClearTimeout(marker) { | ||
3100 | if (cachedClearTimeout === clearTimeout) { | ||
3101 | //normal enviroments in sane situations | ||
3102 | return clearTimeout(marker); | ||
3103 | } | ||
3104 | // if clearTimeout wasn't available but was latter defined | ||
3105 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | ||
3106 | cachedClearTimeout = clearTimeout; | ||
3107 | return clearTimeout(marker); | ||
3108 | } | ||
3109 | try { | ||
3110 | // when when somebody has screwed with setTimeout but no I.E. maddness | ||
3111 | return cachedClearTimeout(marker); | ||
3112 | } catch (e){ | ||
3113 | try { | ||
3114 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | ||
3115 | return cachedClearTimeout.call(null, marker); | ||
3116 | } catch (e){ | ||
3117 | // 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. | ||
3118 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout | ||
3119 | return cachedClearTimeout.call(this, marker); | ||
3120 | } | ||
3121 | } | ||
3122 | |||
3123 | |||
3124 | |||
3125 | } | ||
3126 | var queue = []; | ||
3127 | var draining = false; | ||
3128 | var currentQueue; | ||
3129 | var queueIndex = -1; | ||
3130 | |||
3131 | function cleanUpNextTick() { | ||
3132 | if (!draining || !currentQueue) { | ||
3133 | return; | ||
3134 | } | ||
3135 | draining = false; | ||
3136 | if (currentQueue.length) { | ||
3137 | queue = currentQueue.concat(queue); | ||
3138 | } else { | ||
3139 | queueIndex = -1; | ||
3140 | } | ||
3141 | if (queue.length) { | ||
3142 | drainQueue(); | ||
3143 | } | ||
3144 | } | ||
3145 | |||
3146 | function drainQueue() { | ||
3147 | if (draining) { | ||
3148 | return; | ||
3149 | } | ||
3150 | var timeout = runTimeout(cleanUpNextTick); | ||
3151 | draining = true; | ||
3152 | |||
3153 | var len = queue.length; | ||
3154 | while(len) { | ||
3155 | currentQueue = queue; | ||
3156 | queue = []; | ||
3157 | while (++queueIndex < len) { | ||
3158 | if (currentQueue) { | ||
3159 | currentQueue[queueIndex].run(); | ||
3160 | } | ||
3161 | } | ||
3162 | queueIndex = -1; | ||
3163 | len = queue.length; | ||
3164 | } | ||
3165 | currentQueue = null; | ||
3166 | draining = false; | ||
3167 | runClearTimeout(timeout); | ||
3168 | } | ||
3169 | |||
3170 | process.nextTick = function (fun) { | ||
3171 | var args = new Array(arguments.length - 1); | ||
3172 | if (arguments.length > 1) { | ||
3173 | for (var i = 1; i < arguments.length; i++) { | ||
3174 | args[i - 1] = arguments[i]; | ||
3175 | } | ||
3176 | } | ||
3177 | queue.push(new Item(fun, args)); | ||
3178 | if (queue.length === 1 && !draining) { | ||
3179 | runTimeout(drainQueue); | ||
3180 | } | ||
3181 | }; | ||
3182 | |||
3183 | // v8 likes predictible objects | ||
3184 | function Item(fun, array) { | ||
3185 | this.fun = fun; | ||
3186 | this.array = array; | ||
3187 | } | ||
3188 | Item.prototype.run = function () { | ||
3189 | this.fun.apply(null, this.array); | ||
3190 | }; | ||
3191 | process.title = 'browser'; | ||
3192 | process.browser = true; | ||
3193 | process.env = {}; | ||
3194 | process.argv = []; | ||
3195 | process.version = ''; // empty string to avoid regexp issues | ||
3196 | process.versions = {}; | ||
3197 | |||
3198 | function noop() {} | ||
3199 | |||
3200 | process.on = noop; | ||
3201 | process.addListener = noop; | ||
3202 | process.once = noop; | ||
3203 | process.off = noop; | ||
3204 | process.removeListener = noop; | ||
3205 | process.removeAllListeners = noop; | ||
3206 | process.emit = noop; | ||
3207 | |||
3208 | process.binding = function (name) { | ||
3209 | throw new Error('process.binding is not supported'); | ||
3210 | }; | ||
3211 | |||
3212 | process.cwd = function () { return '/' }; | ||
3213 | process.chdir = function (dir) { | ||
3214 | throw new Error('process.chdir is not supported'); | ||
3215 | }; | ||
3216 | process.umask = function() { return 0; }; | ||
3217 | |||
3218 | },{}],14:[function(require,module,exports){ | ||
3219 | module.exports = require("./lib/_stream_duplex.js") | ||
3220 | |||
3221 | },{"./lib/_stream_duplex.js":15}],15:[function(require,module,exports){ | ||
3222 | // a duplex stream is just a stream that is both readable and writable. | ||
3223 | // Since JS doesn't have multiple prototypal inheritance, this class | ||
3224 | // prototypally inherits from Readable, and then parasitically from | ||
3225 | // Writable. | ||
3226 | |||
3227 | 'use strict'; | ||
3228 | |||
3229 | /*<replacement>*/ | ||
3230 | |||
3231 | var objectKeys = Object.keys || function (obj) { | ||
3232 | var keys = []; | ||
3233 | for (var key in obj) { | ||
3234 | keys.push(key); | ||
3235 | }return keys; | ||
3236 | }; | ||
3237 | /*</replacement>*/ | ||
3238 | |||
3239 | module.exports = Duplex; | ||
3240 | |||
3241 | /*<replacement>*/ | ||
3242 | var processNextTick = require('process-nextick-args'); | ||
3243 | /*</replacement>*/ | ||
3244 | |||
3245 | /*<replacement>*/ | ||
3246 | var util = require('core-util-is'); | ||
3247 | util.inherits = require('inherits'); | ||
3248 | /*</replacement>*/ | ||
3249 | |||
3250 | var Readable = require('./_stream_readable'); | ||
3251 | var Writable = require('./_stream_writable'); | ||
3252 | |||
3253 | util.inherits(Duplex, Readable); | ||
3254 | |||
3255 | var keys = objectKeys(Writable.prototype); | ||
3256 | for (var v = 0; v < keys.length; v++) { | ||
3257 | var method = keys[v]; | ||
3258 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; | ||
3259 | } | ||
3260 | |||
3261 | function Duplex(options) { | ||
3262 | if (!(this instanceof Duplex)) return new Duplex(options); | ||
3263 | |||
3264 | Readable.call(this, options); | ||
3265 | Writable.call(this, options); | ||
3266 | |||
3267 | if (options && options.readable === false) this.readable = false; | ||
3268 | |||
3269 | if (options && options.writable === false) this.writable = false; | ||
3270 | |||
3271 | this.allowHalfOpen = true; | ||
3272 | if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; | ||
3273 | |||
3274 | this.once('end', onend); | ||
3275 | } | ||
3276 | |||
3277 | // the no-half-open enforcer | ||
3278 | function onend() { | ||
3279 | // if we allow half-open state, or if the writable side ended, | ||
3280 | // then we're ok. | ||
3281 | if (this.allowHalfOpen || this._writableState.ended) return; | ||
3282 | |||
3283 | // no more data can be written. | ||
3284 | // But allow more writes to happen in this tick. | ||
3285 | processNextTick(onEndNT, this); | ||
3286 | } | ||
3287 | |||
3288 | function onEndNT(self) { | ||
3289 | self.end(); | ||
3290 | } | ||
3291 | |||
3292 | function forEach(xs, f) { | ||
3293 | for (var i = 0, l = xs.length; i < l; i++) { | ||
3294 | f(xs[i], i); | ||
3295 | } | ||
3296 | } | ||
3297 | },{"./_stream_readable":17,"./_stream_writable":19,"core-util-is":6,"inherits":9,"process-nextick-args":12}],16:[function(require,module,exports){ | ||
3298 | // a passthrough stream. | ||
3299 | // basically just the most minimal sort of Transform stream. | ||
3300 | // Every written chunk gets output as-is. | ||
3301 | |||
3302 | 'use strict'; | ||
3303 | |||
3304 | module.exports = PassThrough; | ||
3305 | |||
3306 | var Transform = require('./_stream_transform'); | ||
3307 | |||
3308 | /*<replacement>*/ | ||
3309 | var util = require('core-util-is'); | ||
3310 | util.inherits = require('inherits'); | ||
3311 | /*</replacement>*/ | ||
3312 | |||
3313 | util.inherits(PassThrough, Transform); | ||
3314 | |||
3315 | function PassThrough(options) { | ||
3316 | if (!(this instanceof PassThrough)) return new PassThrough(options); | ||
3317 | |||
3318 | Transform.call(this, options); | ||
3319 | } | ||
3320 | |||
3321 | PassThrough.prototype._transform = function (chunk, encoding, cb) { | ||
3322 | cb(null, chunk); | ||
3323 | }; | ||
3324 | },{"./_stream_transform":18,"core-util-is":6,"inherits":9}],17:[function(require,module,exports){ | ||
3325 | (function (process){ | ||
3326 | 'use strict'; | ||
3327 | |||
3328 | module.exports = Readable; | ||
3329 | |||
3330 | /*<replacement>*/ | ||
3331 | var processNextTick = require('process-nextick-args'); | ||
3332 | /*</replacement>*/ | ||
3333 | |||
3334 | /*<replacement>*/ | ||
3335 | var isArray = require('isarray'); | ||
3336 | /*</replacement>*/ | ||
3337 | |||
3338 | /*<replacement>*/ | ||
3339 | var Duplex; | ||
3340 | /*</replacement>*/ | ||
3341 | |||
3342 | Readable.ReadableState = ReadableState; | ||
3343 | |||
3344 | /*<replacement>*/ | ||
3345 | var EE = require('events').EventEmitter; | ||
3346 | |||
3347 | var EElistenerCount = function (emitter, type) { | ||
3348 | return emitter.listeners(type).length; | ||
3349 | }; | ||
3350 | /*</replacement>*/ | ||
3351 | |||
3352 | /*<replacement>*/ | ||
3353 | var Stream; | ||
3354 | (function () { | ||
3355 | try { | ||
3356 | Stream = require('st' + 'ream'); | ||
3357 | } catch (_) {} finally { | ||
3358 | if (!Stream) Stream = require('events').EventEmitter; | ||
3359 | } | ||
3360 | })(); | ||
3361 | /*</replacement>*/ | ||
3362 | |||
3363 | var Buffer = require('buffer').Buffer; | ||
3364 | /*<replacement>*/ | ||
3365 | var bufferShim = require('buffer-shims'); | ||
3366 | /*</replacement>*/ | ||
3367 | |||
3368 | /*<replacement>*/ | ||
3369 | var util = require('core-util-is'); | ||
3370 | util.inherits = require('inherits'); | ||
3371 | /*</replacement>*/ | ||
3372 | |||
3373 | /*<replacement>*/ | ||
3374 | var debugUtil = require('util'); | ||
3375 | var debug = void 0; | ||
3376 | if (debugUtil && debugUtil.debuglog) { | ||
3377 | debug = debugUtil.debuglog('stream'); | ||
3378 | } else { | ||
3379 | debug = function () {}; | ||
3380 | } | ||
3381 | /*</replacement>*/ | ||
3382 | |||
3383 | var BufferList = require('./internal/streams/BufferList'); | ||
3384 | var StringDecoder; | ||
3385 | |||
3386 | util.inherits(Readable, Stream); | ||
3387 | |||
3388 | function prependListener(emitter, event, fn) { | ||
3389 | // Sadly this is not cacheable as some libraries bundle their own | ||
3390 | // event emitter implementation with them. | ||
3391 | if (typeof emitter.prependListener === 'function') { | ||
3392 | return emitter.prependListener(event, fn); | ||
3393 | } else { | ||
3394 | // This is a hack to make sure that our error handler is attached before any | ||
3395 | // userland ones. NEVER DO THIS. This is here only because this code needs | ||
3396 | // to continue to work with older versions of Node.js that do not include | ||
3397 | // the prependListener() method. The goal is to eventually remove this hack. | ||
3398 | 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]]; | ||
3399 | } | ||
3400 | } | ||
3401 | |||
3402 | function ReadableState(options, stream) { | ||
3403 | Duplex = Duplex || require('./_stream_duplex'); | ||
3404 | |||
3405 | options = options || {}; | ||
3406 | |||
3407 | // object stream flag. Used to make read(n) ignore n and to | ||
3408 | // make all the buffer merging and length checks go away | ||
3409 | this.objectMode = !!options.objectMode; | ||
3410 | |||
3411 | if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; | ||
3412 | |||
3413 | // the point at which it stops calling _read() to fill the buffer | ||
3414 | // Note: 0 is a valid value, means "don't call _read preemptively ever" | ||
3415 | var hwm = options.highWaterMark; | ||
3416 | var defaultHwm = this.objectMode ? 16 : 16 * 1024; | ||
3417 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | ||
3418 | |||
3419 | // cast to ints. | ||
3420 | this.highWaterMark = ~ ~this.highWaterMark; | ||
3421 | |||
3422 | // A linked list is used to store data chunks instead of an array because the | ||
3423 | // linked list can remove elements from the beginning faster than | ||
3424 | // array.shift() | ||
3425 | this.buffer = new BufferList(); | ||
3426 | this.length = 0; | ||
3427 | this.pipes = null; | ||
3428 | this.pipesCount = 0; | ||
3429 | this.flowing = null; | ||
3430 | this.ended = false; | ||
3431 | this.endEmitted = false; | ||
3432 | this.reading = false; | ||
3433 | |||
3434 | // a flag to be able to tell if the onwrite cb is called immediately, | ||
3435 | // or on a later tick. We set this to true at first, because any | ||
3436 | // actions that shouldn't happen until "later" should generally also | ||
3437 | // not happen before the first write call. | ||
3438 | this.sync = true; | ||
3439 | |||
3440 | // whenever we return null, then we set a flag to say | ||
3441 | // that we're awaiting a 'readable' event emission. | ||
3442 | this.needReadable = false; | ||
3443 | this.emittedReadable = false; | ||
3444 | this.readableListening = false; | ||
3445 | this.resumeScheduled = false; | ||
3446 | |||
3447 | // Crypto is kind of old and crusty. Historically, its default string | ||
3448 | // encoding is 'binary' so we have to make this configurable. | ||
3449 | // Everything else in the universe uses 'utf8', though. | ||
3450 | this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
3451 | |||
3452 | // when piping, we only care about 'readable' events that happen | ||
3453 | // after read()ing all the bytes and not getting any pushback. | ||
3454 | this.ranOut = false; | ||
3455 | |||
3456 | // the number of writers that are awaiting a drain event in .pipe()s | ||
3457 | this.awaitDrain = 0; | ||
3458 | |||
3459 | // if true, a maybeReadMore has been scheduled | ||
3460 | this.readingMore = false; | ||
3461 | |||
3462 | this.decoder = null; | ||
3463 | this.encoding = null; | ||
3464 | if (options.encoding) { | ||
3465 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | ||
3466 | this.decoder = new StringDecoder(options.encoding); | ||
3467 | this.encoding = options.encoding; | ||
3468 | } | ||
3469 | } | ||
3470 | |||
3471 | function Readable(options) { | ||
3472 | Duplex = Duplex || require('./_stream_duplex'); | ||
3473 | |||
3474 | if (!(this instanceof Readable)) return new Readable(options); | ||
3475 | |||
3476 | this._readableState = new ReadableState(options, this); | ||
3477 | |||
3478 | // legacy | ||
3479 | this.readable = true; | ||
3480 | |||
3481 | if (options && typeof options.read === 'function') this._read = options.read; | ||
3482 | |||
3483 | Stream.call(this); | ||
3484 | } | ||
3485 | |||
3486 | // Manually shove something into the read() buffer. | ||
3487 | // This returns true if the highWaterMark has not been hit yet, | ||
3488 | // similar to how Writable.write() returns true if you should | ||
3489 | // write() some more. | ||
3490 | Readable.prototype.push = function (chunk, encoding) { | ||
3491 | var state = this._readableState; | ||
3492 | |||
3493 | if (!state.objectMode && typeof chunk === 'string') { | ||
3494 | encoding = encoding || state.defaultEncoding; | ||
3495 | if (encoding !== state.encoding) { | ||
3496 | chunk = bufferShim.from(chunk, encoding); | ||
3497 | encoding = ''; | ||
3498 | } | ||
3499 | } | ||
3500 | |||
3501 | return readableAddChunk(this, state, chunk, encoding, false); | ||
3502 | }; | ||
3503 | |||
3504 | // Unshift should *always* be something directly out of read() | ||
3505 | Readable.prototype.unshift = function (chunk) { | ||
3506 | var state = this._readableState; | ||
3507 | return readableAddChunk(this, state, chunk, '', true); | ||
3508 | }; | ||
3509 | |||
3510 | Readable.prototype.isPaused = function () { | ||
3511 | return this._readableState.flowing === false; | ||
3512 | }; | ||
3513 | |||
3514 | function readableAddChunk(stream, state, chunk, encoding, addToFront) { | ||
3515 | var er = chunkInvalid(state, chunk); | ||
3516 | if (er) { | ||
3517 | stream.emit('error', er); | ||
3518 | } else if (chunk === null) { | ||
3519 | state.reading = false; | ||
3520 | onEofChunk(stream, state); | ||
3521 | } else if (state.objectMode || chunk && chunk.length > 0) { | ||
3522 | if (state.ended && !addToFront) { | ||
3523 | var e = new Error('stream.push() after EOF'); | ||
3524 | stream.emit('error', e); | ||
3525 | } else if (state.endEmitted && addToFront) { | ||
3526 | var _e = new Error('stream.unshift() after end event'); | ||
3527 | stream.emit('error', _e); | ||
3528 | } else { | ||
3529 | var skipAdd; | ||
3530 | if (state.decoder && !addToFront && !encoding) { | ||
3531 | chunk = state.decoder.write(chunk); | ||
3532 | skipAdd = !state.objectMode && chunk.length === 0; | ||
3533 | } | ||
3534 | |||
3535 | if (!addToFront) state.reading = false; | ||
3536 | |||
3537 | // Don't add to the buffer if we've decoded to an empty string chunk and | ||
3538 | // we're not in object mode | ||
3539 | if (!skipAdd) { | ||
3540 | // if we want the data now, just emit it. | ||
3541 | if (state.flowing && state.length === 0 && !state.sync) { | ||
3542 | stream.emit('data', chunk); | ||
3543 | stream.read(0); | ||
3544 | } else { | ||
3545 | // update the buffer info. | ||
3546 | state.length += state.objectMode ? 1 : chunk.length; | ||
3547 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); | ||
3548 | |||
3549 | if (state.needReadable) emitReadable(stream); | ||
3550 | } | ||
3551 | } | ||
3552 | |||
3553 | maybeReadMore(stream, state); | ||
3554 | } | ||
3555 | } else if (!addToFront) { | ||
3556 | state.reading = false; | ||
3557 | } | ||
3558 | |||
3559 | return needMoreData(state); | ||
3560 | } | ||
3561 | |||
3562 | // if it's past the high water mark, we can push in some more. | ||
3563 | // Also, if we have no data yet, we can stand some | ||
3564 | // more bytes. This is to work around cases where hwm=0, | ||
3565 | // such as the repl. Also, if the push() triggered a | ||
3566 | // readable event, and the user called read(largeNumber) such that | ||
3567 | // needReadable was set, then we ought to push more, so that another | ||
3568 | // 'readable' event will be triggered. | ||
3569 | function needMoreData(state) { | ||
3570 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); | ||
3571 | } | ||
3572 | |||
3573 | // backwards compatibility. | ||
3574 | Readable.prototype.setEncoding = function (enc) { | ||
3575 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | ||
3576 | this._readableState.decoder = new StringDecoder(enc); | ||
3577 | this._readableState.encoding = enc; | ||
3578 | return this; | ||
3579 | }; | ||
3580 | |||
3581 | // Don't raise the hwm > 8MB | ||
3582 | var MAX_HWM = 0x800000; | ||
3583 | function computeNewHighWaterMark(n) { | ||
3584 | if (n >= MAX_HWM) { | ||
3585 | n = MAX_HWM; | ||
3586 | } else { | ||
3587 | // Get the next highest power of 2 to prevent increasing hwm excessively in | ||
3588 | // tiny amounts | ||
3589 | n--; | ||
3590 | n |= n >>> 1; | ||
3591 | n |= n >>> 2; | ||
3592 | n |= n >>> 4; | ||
3593 | n |= n >>> 8; | ||
3594 | n |= n >>> 16; | ||
3595 | n++; | ||
3596 | } | ||
3597 | return n; | ||
3598 | } | ||
3599 | |||
3600 | // This function is designed to be inlinable, so please take care when making | ||
3601 | // changes to the function body. | ||
3602 | function howMuchToRead(n, state) { | ||
3603 | if (n <= 0 || state.length === 0 && state.ended) return 0; | ||
3604 | if (state.objectMode) return 1; | ||
3605 | if (n !== n) { | ||
3606 | // Only flow one buffer at a time | ||
3607 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; | ||
3608 | } | ||
3609 | // If we're asking for more than the current hwm, then raise the hwm. | ||
3610 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); | ||
3611 | if (n <= state.length) return n; | ||
3612 | // Don't have enough | ||
3613 | if (!state.ended) { | ||
3614 | state.needReadable = true; | ||
3615 | return 0; | ||
3616 | } | ||
3617 | return state.length; | ||
3618 | } | ||
3619 | |||
3620 | // you can override either this method, or the async _read(n) below. | ||
3621 | Readable.prototype.read = function (n) { | ||
3622 | debug('read', n); | ||
3623 | n = parseInt(n, 10); | ||
3624 | var state = this._readableState; | ||
3625 | var nOrig = n; | ||
3626 | |||
3627 | if (n !== 0) state.emittedReadable = false; | ||
3628 | |||
3629 | // if we're doing read(0) to trigger a readable event, but we | ||
3630 | // already have a bunch of data in the buffer, then just trigger | ||
3631 | // the 'readable' event and move on. | ||
3632 | if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { | ||
3633 | debug('read: emitReadable', state.length, state.ended); | ||
3634 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); | ||
3635 | return null; | ||
3636 | } | ||
3637 | |||
3638 | n = howMuchToRead(n, state); | ||
3639 | |||
3640 | // if we've ended, and we're now clear, then finish it up. | ||
3641 | if (n === 0 && state.ended) { | ||
3642 | if (state.length === 0) endReadable(this); | ||
3643 | return null; | ||
3644 | } | ||
3645 | |||
3646 | // All the actual chunk generation logic needs to be | ||
3647 | // *below* the call to _read. The reason is that in certain | ||
3648 | // synthetic stream cases, such as passthrough streams, _read | ||
3649 | // may be a completely synchronous operation which may change | ||
3650 | // the state of the read buffer, providing enough data when | ||
3651 | // before there was *not* enough. | ||
3652 | // | ||
3653 | // So, the steps are: | ||
3654 | // 1. Figure out what the state of things will be after we do | ||
3655 | // a read from the buffer. | ||
3656 | // | ||
3657 | // 2. If that resulting state will trigger a _read, then call _read. | ||
3658 | // Note that this may be asynchronous, or synchronous. Yes, it is | ||
3659 | // deeply ugly to write APIs this way, but that still doesn't mean | ||
3660 | // that the Readable class should behave improperly, as streams are | ||
3661 | // designed to be sync/async agnostic. | ||
3662 | // Take note if the _read call is sync or async (ie, if the read call | ||
3663 | // has returned yet), so that we know whether or not it's safe to emit | ||
3664 | // 'readable' etc. | ||
3665 | // | ||
3666 | // 3. Actually pull the requested chunks out of the buffer and return. | ||
3667 | |||
3668 | // if we need a readable event, then we need to do some reading. | ||
3669 | var doRead = state.needReadable; | ||
3670 | debug('need readable', doRead); | ||
3671 | |||
3672 | // if we currently have less than the highWaterMark, then also read some | ||
3673 | if (state.length === 0 || state.length - n < state.highWaterMark) { | ||
3674 | doRead = true; | ||
3675 | debug('length less than watermark', doRead); | ||
3676 | } | ||
3677 | |||
3678 | // however, if we've ended, then there's no point, and if we're already | ||
3679 | // reading, then it's unnecessary. | ||
3680 | if (state.ended || state.reading) { | ||
3681 | doRead = false; | ||
3682 | debug('reading or ended', doRead); | ||
3683 | } else if (doRead) { | ||
3684 | debug('do read'); | ||
3685 | state.reading = true; | ||
3686 | state.sync = true; | ||
3687 | // if the length is currently zero, then we *need* a readable event. | ||
3688 | if (state.length === 0) state.needReadable = true; | ||
3689 | // call internal read method | ||
3690 | this._read(state.highWaterMark); | ||
3691 | state.sync = false; | ||
3692 | // If _read pushed data synchronously, then `reading` will be false, | ||
3693 | // and we need to re-evaluate how much data we can return to the user. | ||
3694 | if (!state.reading) n = howMuchToRead(nOrig, state); | ||
3695 | } | ||
3696 | |||
3697 | var ret; | ||
3698 | if (n > 0) ret = fromList(n, state);else ret = null; | ||
3699 | |||
3700 | if (ret === null) { | ||
3701 | state.needReadable = true; | ||
3702 | n = 0; | ||
3703 | } else { | ||
3704 | state.length -= n; | ||
3705 | } | ||
3706 | |||
3707 | if (state.length === 0) { | ||
3708 | // If we have nothing in the buffer, then we want to know | ||
3709 | // as soon as we *do* get something into the buffer. | ||
3710 | if (!state.ended) state.needReadable = true; | ||
3711 | |||
3712 | // If we tried to read() past the EOF, then emit end on the next tick. | ||
3713 | if (nOrig !== n && state.ended) endReadable(this); | ||
3714 | } | ||
3715 | |||
3716 | if (ret !== null) this.emit('data', ret); | ||
3717 | |||
3718 | return ret; | ||
3719 | }; | ||
3720 | |||
3721 | function chunkInvalid(state, chunk) { | ||
3722 | var er = null; | ||
3723 | if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { | ||
3724 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
3725 | } | ||
3726 | return er; | ||
3727 | } | ||
3728 | |||
3729 | function onEofChunk(stream, state) { | ||
3730 | if (state.ended) return; | ||
3731 | if (state.decoder) { | ||
3732 | var chunk = state.decoder.end(); | ||
3733 | if (chunk && chunk.length) { | ||
3734 | state.buffer.push(chunk); | ||
3735 | state.length += state.objectMode ? 1 : chunk.length; | ||
3736 | } | ||
3737 | } | ||
3738 | state.ended = true; | ||
3739 | |||
3740 | // emit 'readable' now to make sure it gets picked up. | ||
3741 | emitReadable(stream); | ||
3742 | } | ||
3743 | |||
3744 | // Don't emit readable right away in sync mode, because this can trigger | ||
3745 | // another read() call => stack overflow. This way, it might trigger | ||
3746 | // a nextTick recursion warning, but that's not so bad. | ||
3747 | function emitReadable(stream) { | ||
3748 | var state = stream._readableState; | ||
3749 | state.needReadable = false; | ||
3750 | if (!state.emittedReadable) { | ||
3751 | debug('emitReadable', state.flowing); | ||
3752 | state.emittedReadable = true; | ||
3753 | if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); | ||
3754 | } | ||
3755 | } | ||
3756 | |||
3757 | function emitReadable_(stream) { | ||
3758 | debug('emit readable'); | ||
3759 | stream.emit('readable'); | ||
3760 | flow(stream); | ||
3761 | } | ||
3762 | |||
3763 | // at this point, the user has presumably seen the 'readable' event, | ||
3764 | // and called read() to consume some data. that may have triggered | ||
3765 | // in turn another _read(n) call, in which case reading = true if | ||
3766 | // it's in progress. | ||
3767 | // However, if we're not ended, or reading, and the length < hwm, | ||
3768 | // then go ahead and try to read some more preemptively. | ||
3769 | function maybeReadMore(stream, state) { | ||
3770 | if (!state.readingMore) { | ||
3771 | state.readingMore = true; | ||
3772 | processNextTick(maybeReadMore_, stream, state); | ||
3773 | } | ||
3774 | } | ||
3775 | |||
3776 | function maybeReadMore_(stream, state) { | ||
3777 | var len = state.length; | ||
3778 | while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { | ||
3779 | debug('maybeReadMore read 0'); | ||
3780 | stream.read(0); | ||
3781 | if (len === state.length) | ||
3782 | // didn't get any data, stop spinning. | ||
3783 | break;else len = state.length; | ||
3784 | } | ||
3785 | state.readingMore = false; | ||
3786 | } | ||
3787 | |||
3788 | // abstract method. to be overridden in specific implementation classes. | ||
3789 | // call cb(er, data) where data is <= n in length. | ||
3790 | // for virtual (non-string, non-buffer) streams, "length" is somewhat | ||
3791 | // arbitrary, and perhaps not very meaningful. | ||
3792 | Readable.prototype._read = function (n) { | ||
3793 | this.emit('error', new Error('_read() is not implemented')); | ||
3794 | }; | ||
3795 | |||
3796 | Readable.prototype.pipe = function (dest, pipeOpts) { | ||
3797 | var src = this; | ||
3798 | var state = this._readableState; | ||
3799 | |||
3800 | switch (state.pipesCount) { | ||
3801 | case 0: | ||
3802 | state.pipes = dest; | ||
3803 | break; | ||
3804 | case 1: | ||
3805 | state.pipes = [state.pipes, dest]; | ||
3806 | break; | ||
3807 | default: | ||
3808 | state.pipes.push(dest); | ||
3809 | break; | ||
3810 | } | ||
3811 | state.pipesCount += 1; | ||
3812 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); | ||
3813 | |||
3814 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; | ||
3815 | |||
3816 | var endFn = doEnd ? onend : cleanup; | ||
3817 | if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); | ||
3818 | |||
3819 | dest.on('unpipe', onunpipe); | ||
3820 | function onunpipe(readable) { | ||
3821 | debug('onunpipe'); | ||
3822 | if (readable === src) { | ||
3823 | cleanup(); | ||
3824 | } | ||
3825 | } | ||
3826 | |||
3827 | function onend() { | ||
3828 | debug('onend'); | ||
3829 | dest.end(); | ||
3830 | } | ||
3831 | |||
3832 | // when the dest drains, it reduces the awaitDrain counter | ||
3833 | // on the source. This would be more elegant with a .once() | ||
3834 | // handler in flow(), but adding and removing repeatedly is | ||
3835 | // too slow. | ||
3836 | var ondrain = pipeOnDrain(src); | ||
3837 | dest.on('drain', ondrain); | ||
3838 | |||
3839 | var cleanedUp = false; | ||
3840 | function cleanup() { | ||
3841 | debug('cleanup'); | ||
3842 | // cleanup event handlers once the pipe is broken | ||
3843 | dest.removeListener('close', onclose); | ||
3844 | dest.removeListener('finish', onfinish); | ||
3845 | dest.removeListener('drain', ondrain); | ||
3846 | dest.removeListener('error', onerror); | ||
3847 | dest.removeListener('unpipe', onunpipe); | ||
3848 | src.removeListener('end', onend); | ||
3849 | src.removeListener('end', cleanup); | ||
3850 | src.removeListener('data', ondata); | ||
3851 | |||
3852 | cleanedUp = true; | ||
3853 | |||
3854 | // if the reader is waiting for a drain event from this | ||
3855 | // specific writer, then it would cause it to never start | ||
3856 | // flowing again. | ||
3857 | // So, if this is awaiting a drain, then we just call it now. | ||
3858 | // If we don't know, then assume that we are waiting for one. | ||
3859 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); | ||
3860 | } | ||
3861 | |||
3862 | // If the user pushes more data while we're writing to dest then we'll end up | ||
3863 | // in ondata again. However, we only want to increase awaitDrain once because | ||
3864 | // dest will only emit one 'drain' event for the multiple writes. | ||
3865 | // => Introduce a guard on increasing awaitDrain. | ||
3866 | var increasedAwaitDrain = false; | ||
3867 | src.on('data', ondata); | ||
3868 | function ondata(chunk) { | ||
3869 | debug('ondata'); | ||
3870 | increasedAwaitDrain = false; | ||
3871 | var ret = dest.write(chunk); | ||
3872 | if (false === ret && !increasedAwaitDrain) { | ||
3873 | // If the user unpiped during `dest.write()`, it is possible | ||
3874 | // to get stuck in a permanently paused state if that write | ||
3875 | // also returned false. | ||
3876 | // => Check whether `dest` is still a piping destination. | ||
3877 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { | ||
3878 | debug('false write response, pause', src._readableState.awaitDrain); | ||
3879 | src._readableState.awaitDrain++; | ||
3880 | increasedAwaitDrain = true; | ||
3881 | } | ||
3882 | src.pause(); | ||
3883 | } | ||
3884 | } | ||
3885 | |||
3886 | // if the dest has an error, then stop piping into it. | ||
3887 | // however, don't suppress the throwing behavior for this. | ||
3888 | function onerror(er) { | ||
3889 | debug('onerror', er); | ||
3890 | unpipe(); | ||
3891 | dest.removeListener('error', onerror); | ||
3892 | if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); | ||
3893 | } | ||
3894 | |||
3895 | // Make sure our error handler is attached before userland ones. | ||
3896 | prependListener(dest, 'error', onerror); | ||
3897 | |||
3898 | // Both close and finish should trigger unpipe, but only once. | ||
3899 | function onclose() { | ||
3900 | dest.removeListener('finish', onfinish); | ||
3901 | unpipe(); | ||
3902 | } | ||
3903 | dest.once('close', onclose); | ||
3904 | function onfinish() { | ||
3905 | debug('onfinish'); | ||
3906 | dest.removeListener('close', onclose); | ||
3907 | unpipe(); | ||
3908 | } | ||
3909 | dest.once('finish', onfinish); | ||
3910 | |||
3911 | function unpipe() { | ||
3912 | debug('unpipe'); | ||
3913 | src.unpipe(dest); | ||
3914 | } | ||
3915 | |||
3916 | // tell the dest that it's being piped to | ||
3917 | dest.emit('pipe', src); | ||
3918 | |||
3919 | // start the flow if it hasn't been started already. | ||
3920 | if (!state.flowing) { | ||
3921 | debug('pipe resume'); | ||
3922 | src.resume(); | ||
3923 | } | ||
3924 | |||
3925 | return dest; | ||
3926 | }; | ||
3927 | |||
3928 | function pipeOnDrain(src) { | ||
3929 | return function () { | ||
3930 | var state = src._readableState; | ||
3931 | debug('pipeOnDrain', state.awaitDrain); | ||
3932 | if (state.awaitDrain) state.awaitDrain--; | ||
3933 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { | ||
3934 | state.flowing = true; | ||
3935 | flow(src); | ||
3936 | } | ||
3937 | }; | ||
3938 | } | ||
3939 | |||
3940 | Readable.prototype.unpipe = function (dest) { | ||
3941 | var state = this._readableState; | ||
3942 | |||
3943 | // if we're not piping anywhere, then do nothing. | ||
3944 | if (state.pipesCount === 0) return this; | ||
3945 | |||
3946 | // just one destination. most common case. | ||
3947 | if (state.pipesCount === 1) { | ||
3948 | // passed in one, but it's not the right one. | ||
3949 | if (dest && dest !== state.pipes) return this; | ||
3950 | |||
3951 | if (!dest) dest = state.pipes; | ||
3952 | |||
3953 | // got a match. | ||
3954 | state.pipes = null; | ||
3955 | state.pipesCount = 0; | ||
3956 | state.flowing = false; | ||
3957 | if (dest) dest.emit('unpipe', this); | ||
3958 | return this; | ||
3959 | } | ||
3960 | |||
3961 | // slow case. multiple pipe destinations. | ||
3962 | |||
3963 | if (!dest) { | ||
3964 | // remove all. | ||
3965 | var dests = state.pipes; | ||
3966 | var len = state.pipesCount; | ||
3967 | state.pipes = null; | ||
3968 | state.pipesCount = 0; | ||
3969 | state.flowing = false; | ||
3970 | |||
3971 | for (var i = 0; i < len; i++) { | ||
3972 | dests[i].emit('unpipe', this); | ||
3973 | }return this; | ||
3974 | } | ||
3975 | |||
3976 | // try to find the right one. | ||
3977 | var index = indexOf(state.pipes, dest); | ||
3978 | if (index === -1) return this; | ||
3979 | |||
3980 | state.pipes.splice(index, 1); | ||
3981 | state.pipesCount -= 1; | ||
3982 | if (state.pipesCount === 1) state.pipes = state.pipes[0]; | ||
3983 | |||
3984 | dest.emit('unpipe', this); | ||
3985 | |||
3986 | return this; | ||
3987 | }; | ||
3988 | |||
3989 | // set up data events if they are asked for | ||
3990 | // Ensure readable listeners eventually get something | ||
3991 | Readable.prototype.on = function (ev, fn) { | ||
3992 | var res = Stream.prototype.on.call(this, ev, fn); | ||
3993 | |||
3994 | if (ev === 'data') { | ||
3995 | // Start flowing on next tick if stream isn't explicitly paused | ||
3996 | if (this._readableState.flowing !== false) this.resume(); | ||
3997 | } else if (ev === 'readable') { | ||
3998 | var state = this._readableState; | ||
3999 | if (!state.endEmitted && !state.readableListening) { | ||
4000 | state.readableListening = state.needReadable = true; | ||
4001 | state.emittedReadable = false; | ||
4002 | if (!state.reading) { | ||
4003 | processNextTick(nReadingNextTick, this); | ||
4004 | } else if (state.length) { | ||
4005 | emitReadable(this, state); | ||
4006 | } | ||
4007 | } | ||
4008 | } | ||
4009 | |||
4010 | return res; | ||
4011 | }; | ||
4012 | Readable.prototype.addListener = Readable.prototype.on; | ||
4013 | |||
4014 | function nReadingNextTick(self) { | ||
4015 | debug('readable nexttick read 0'); | ||
4016 | self.read(0); | ||
4017 | } | ||
4018 | |||
4019 | // pause() and resume() are remnants of the legacy readable stream API | ||
4020 | // If the user uses them, then switch into old mode. | ||
4021 | Readable.prototype.resume = function () { | ||
4022 | var state = this._readableState; | ||
4023 | if (!state.flowing) { | ||
4024 | debug('resume'); | ||
4025 | state.flowing = true; | ||
4026 | resume(this, state); | ||
4027 | } | ||
4028 | return this; | ||
4029 | }; | ||
4030 | |||
4031 | function resume(stream, state) { | ||
4032 | if (!state.resumeScheduled) { | ||
4033 | state.resumeScheduled = true; | ||
4034 | processNextTick(resume_, stream, state); | ||
4035 | } | ||
4036 | } | ||
4037 | |||
4038 | function resume_(stream, state) { | ||
4039 | if (!state.reading) { | ||
4040 | debug('resume read 0'); | ||
4041 | stream.read(0); | ||
4042 | } | ||
4043 | |||
4044 | state.resumeScheduled = false; | ||
4045 | state.awaitDrain = 0; | ||
4046 | stream.emit('resume'); | ||
4047 | flow(stream); | ||
4048 | if (state.flowing && !state.reading) stream.read(0); | ||
4049 | } | ||
4050 | |||
4051 | Readable.prototype.pause = function () { | ||
4052 | debug('call pause flowing=%j', this._readableState.flowing); | ||
4053 | if (false !== this._readableState.flowing) { | ||
4054 | debug('pause'); | ||
4055 | this._readableState.flowing = false; | ||
4056 | this.emit('pause'); | ||
4057 | } | ||
4058 | return this; | ||
4059 | }; | ||
4060 | |||
4061 | function flow(stream) { | ||
4062 | var state = stream._readableState; | ||
4063 | debug('flow', state.flowing); | ||
4064 | while (state.flowing && stream.read() !== null) {} | ||
4065 | } | ||
4066 | |||
4067 | // wrap an old-style stream as the async data source. | ||
4068 | // This is *not* part of the readable stream interface. | ||
4069 | // It is an ugly unfortunate mess of history. | ||
4070 | Readable.prototype.wrap = function (stream) { | ||
4071 | var state = this._readableState; | ||
4072 | var paused = false; | ||
4073 | |||
4074 | var self = this; | ||
4075 | stream.on('end', function () { | ||
4076 | debug('wrapped end'); | ||
4077 | if (state.decoder && !state.ended) { | ||
4078 | var chunk = state.decoder.end(); | ||
4079 | if (chunk && chunk.length) self.push(chunk); | ||
4080 | } | ||
4081 | |||
4082 | self.push(null); | ||
4083 | }); | ||
4084 | |||
4085 | stream.on('data', function (chunk) { | ||
4086 | debug('wrapped data'); | ||
4087 | if (state.decoder) chunk = state.decoder.write(chunk); | ||
4088 | |||
4089 | // don't skip over falsy values in objectMode | ||
4090 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; | ||
4091 | |||
4092 | var ret = self.push(chunk); | ||
4093 | if (!ret) { | ||
4094 | paused = true; | ||
4095 | stream.pause(); | ||
4096 | } | ||
4097 | }); | ||
4098 | |||
4099 | // proxy all the other methods. | ||
4100 | // important when wrapping filters and duplexes. | ||
4101 | for (var i in stream) { | ||
4102 | if (this[i] === undefined && typeof stream[i] === 'function') { | ||
4103 | this[i] = function (method) { | ||
4104 | return function () { | ||
4105 | return stream[method].apply(stream, arguments); | ||
4106 | }; | ||
4107 | }(i); | ||
4108 | } | ||
4109 | } | ||
4110 | |||
4111 | // proxy certain important events. | ||
4112 | var events = ['error', 'close', 'destroy', 'pause', 'resume']; | ||
4113 | forEach(events, function (ev) { | ||
4114 | stream.on(ev, self.emit.bind(self, ev)); | ||
4115 | }); | ||
4116 | |||
4117 | // when we try to consume some more bytes, simply unpause the | ||
4118 | // underlying stream. | ||
4119 | self._read = function (n) { | ||
4120 | debug('wrapped _read', n); | ||
4121 | if (paused) { | ||
4122 | paused = false; | ||
4123 | stream.resume(); | ||
4124 | } | ||
4125 | }; | ||
4126 | |||
4127 | return self; | ||
4128 | }; | ||
4129 | |||
4130 | // exposed for testing purposes only. | ||
4131 | Readable._fromList = fromList; | ||
4132 | |||
4133 | // Pluck off n bytes from an array of buffers. | ||
4134 | // Length is the combined lengths of all the buffers in the list. | ||
4135 | // This function is designed to be inlinable, so please take care when making | ||
4136 | // changes to the function body. | ||
4137 | function fromList(n, state) { | ||
4138 | // nothing buffered | ||
4139 | if (state.length === 0) return null; | ||
4140 | |||
4141 | var ret; | ||
4142 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { | ||
4143 | // read it all, truncate the list | ||
4144 | 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); | ||
4145 | state.buffer.clear(); | ||
4146 | } else { | ||
4147 | // read part of list | ||
4148 | ret = fromListPartial(n, state.buffer, state.decoder); | ||
4149 | } | ||
4150 | |||
4151 | return ret; | ||
4152 | } | ||
4153 | |||
4154 | // Extracts only enough buffered data to satisfy the amount requested. | ||
4155 | // This function is designed to be inlinable, so please take care when making | ||
4156 | // changes to the function body. | ||
4157 | function fromListPartial(n, list, hasStrings) { | ||
4158 | var ret; | ||
4159 | if (n < list.head.data.length) { | ||
4160 | // slice is the same for buffers and strings | ||
4161 | ret = list.head.data.slice(0, n); | ||
4162 | list.head.data = list.head.data.slice(n); | ||
4163 | } else if (n === list.head.data.length) { | ||
4164 | // first chunk is a perfect match | ||
4165 | ret = list.shift(); | ||
4166 | } else { | ||
4167 | // result spans more than one buffer | ||
4168 | ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); | ||
4169 | } | ||
4170 | return ret; | ||
4171 | } | ||
4172 | |||
4173 | // Copies a specified amount of characters from the list of buffered data | ||
4174 | // chunks. | ||
4175 | // This function is designed to be inlinable, so please take care when making | ||
4176 | // changes to the function body. | ||
4177 | function copyFromBufferString(n, list) { | ||
4178 | var p = list.head; | ||
4179 | var c = 1; | ||
4180 | var ret = p.data; | ||
4181 | n -= ret.length; | ||
4182 | while (p = p.next) { | ||
4183 | var str = p.data; | ||
4184 | var nb = n > str.length ? str.length : n; | ||
4185 | if (nb === str.length) ret += str;else ret += str.slice(0, n); | ||
4186 | n -= nb; | ||
4187 | if (n === 0) { | ||
4188 | if (nb === str.length) { | ||
4189 | ++c; | ||
4190 | if (p.next) list.head = p.next;else list.head = list.tail = null; | ||
4191 | } else { | ||
4192 | list.head = p; | ||
4193 | p.data = str.slice(nb); | ||
4194 | } | ||
4195 | break; | ||
4196 | } | ||
4197 | ++c; | ||
4198 | } | ||
4199 | list.length -= c; | ||
4200 | return ret; | ||
4201 | } | ||
4202 | |||
4203 | // Copies a specified amount of bytes from the list of buffered data chunks. | ||
4204 | // This function is designed to be inlinable, so please take care when making | ||
4205 | // changes to the function body. | ||
4206 | function copyFromBuffer(n, list) { | ||
4207 | var ret = bufferShim.allocUnsafe(n); | ||
4208 | var p = list.head; | ||
4209 | var c = 1; | ||
4210 | p.data.copy(ret); | ||
4211 | n -= p.data.length; | ||
4212 | while (p = p.next) { | ||
4213 | var buf = p.data; | ||
4214 | var nb = n > buf.length ? buf.length : n; | ||
4215 | buf.copy(ret, ret.length - n, 0, nb); | ||
4216 | n -= nb; | ||
4217 | if (n === 0) { | ||
4218 | if (nb === buf.length) { | ||
4219 | ++c; | ||
4220 | if (p.next) list.head = p.next;else list.head = list.tail = null; | ||
4221 | } else { | ||
4222 | list.head = p; | ||
4223 | p.data = buf.slice(nb); | ||
4224 | } | ||
4225 | break; | ||
4226 | } | ||
4227 | ++c; | ||
4228 | } | ||
4229 | list.length -= c; | ||
4230 | return ret; | ||
4231 | } | ||
4232 | |||
4233 | function endReadable(stream) { | ||
4234 | var state = stream._readableState; | ||
4235 | |||
4236 | // If we get here before consuming all the bytes, then that is a | ||
4237 | // bug in node. Should never happen. | ||
4238 | if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); | ||
4239 | |||
4240 | if (!state.endEmitted) { | ||
4241 | state.ended = true; | ||
4242 | processNextTick(endReadableNT, state, stream); | ||
4243 | } | ||
4244 | } | ||
4245 | |||
4246 | function endReadableNT(state, stream) { | ||
4247 | // Check that we didn't get one last unshift. | ||
4248 | if (!state.endEmitted && state.length === 0) { | ||
4249 | state.endEmitted = true; | ||
4250 | stream.readable = false; | ||
4251 | stream.emit('end'); | ||
4252 | } | ||
4253 | } | ||
4254 | |||
4255 | function forEach(xs, f) { | ||
4256 | for (var i = 0, l = xs.length; i < l; i++) { | ||
4257 | f(xs[i], i); | ||
4258 | } | ||
4259 | } | ||
4260 | |||
4261 | function indexOf(xs, x) { | ||
4262 | for (var i = 0, l = xs.length; i < l; i++) { | ||
4263 | if (xs[i] === x) return i; | ||
4264 | } | ||
4265 | return -1; | ||
4266 | } | ||
4267 | }).call(this,require('_process')) | ||
4268 | },{"./_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){ | ||
4269 | // a transform stream is a readable/writable stream where you do | ||
4270 | // something with the data. Sometimes it's called a "filter", | ||
4271 | // but that's not a great name for it, since that implies a thing where | ||
4272 | // some bits pass through, and others are simply ignored. (That would | ||
4273 | // be a valid example of a transform, of course.) | ||
4274 | // | ||
4275 | // While the output is causally related to the input, it's not a | ||
4276 | // necessarily symmetric or synchronous transformation. For example, | ||
4277 | // a zlib stream might take multiple plain-text writes(), and then | ||
4278 | // emit a single compressed chunk some time in the future. | ||
4279 | // | ||
4280 | // Here's how this works: | ||
4281 | // | ||
4282 | // The Transform stream has all the aspects of the readable and writable | ||
4283 | // stream classes. When you write(chunk), that calls _write(chunk,cb) | ||
4284 | // internally, and returns false if there's a lot of pending writes | ||
4285 | // buffered up. When you call read(), that calls _read(n) until | ||
4286 | // there's enough pending readable data buffered up. | ||
4287 | // | ||
4288 | // In a transform stream, the written data is placed in a buffer. When | ||
4289 | // _read(n) is called, it transforms the queued up data, calling the | ||
4290 | // buffered _write cb's as it consumes chunks. If consuming a single | ||
4291 | // written chunk would result in multiple output chunks, then the first | ||
4292 | // outputted bit calls the readcb, and subsequent chunks just go into | ||
4293 | // the read buffer, and will cause it to emit 'readable' if necessary. | ||
4294 | // | ||
4295 | // This way, back-pressure is actually determined by the reading side, | ||
4296 | // since _read has to be called to start processing a new chunk. However, | ||
4297 | // a pathological inflate type of transform can cause excessive buffering | ||
4298 | // here. For example, imagine a stream where every byte of input is | ||
4299 | // interpreted as an integer from 0-255, and then results in that many | ||
4300 | // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in | ||
4301 | // 1kb of data being output. In this case, you could write a very small | ||
4302 | // amount of input, and end up with a very large amount of output. In | ||
4303 | // such a pathological inflating mechanism, there'd be no way to tell | ||
4304 | // the system to stop doing the transform. A single 4MB write could | ||
4305 | // cause the system to run out of memory. | ||
4306 | // | ||
4307 | // However, even in such a pathological case, only a single written chunk | ||
4308 | // would be consumed, and then the rest would wait (un-transformed) until | ||
4309 | // the results of the previous transformed chunk were consumed. | ||
4310 | |||
4311 | 'use strict'; | ||
4312 | |||
4313 | module.exports = Transform; | ||
4314 | |||
4315 | var Duplex = require('./_stream_duplex'); | ||
4316 | |||
4317 | /*<replacement>*/ | ||
4318 | var util = require('core-util-is'); | ||
4319 | util.inherits = require('inherits'); | ||
4320 | /*</replacement>*/ | ||
4321 | |||
4322 | util.inherits(Transform, Duplex); | ||
4323 | |||
4324 | function TransformState(stream) { | ||
4325 | this.afterTransform = function (er, data) { | ||
4326 | return afterTransform(stream, er, data); | ||
4327 | }; | ||
4328 | |||
4329 | this.needTransform = false; | ||
4330 | this.transforming = false; | ||
4331 | this.writecb = null; | ||
4332 | this.writechunk = null; | ||
4333 | this.writeencoding = null; | ||
4334 | } | ||
4335 | |||
4336 | function afterTransform(stream, er, data) { | ||
4337 | var ts = stream._transformState; | ||
4338 | ts.transforming = false; | ||
4339 | |||
4340 | var cb = ts.writecb; | ||
4341 | |||
4342 | if (!cb) return stream.emit('error', new Error('no writecb in Transform class')); | ||
4343 | |||
4344 | ts.writechunk = null; | ||
4345 | ts.writecb = null; | ||
4346 | |||
4347 | if (data !== null && data !== undefined) stream.push(data); | ||
4348 | |||
4349 | cb(er); | ||
4350 | |||
4351 | var rs = stream._readableState; | ||
4352 | rs.reading = false; | ||
4353 | if (rs.needReadable || rs.length < rs.highWaterMark) { | ||
4354 | stream._read(rs.highWaterMark); | ||
4355 | } | ||
4356 | } | ||
4357 | |||
4358 | function Transform(options) { | ||
4359 | if (!(this instanceof Transform)) return new Transform(options); | ||
4360 | |||
4361 | Duplex.call(this, options); | ||
4362 | |||
4363 | this._transformState = new TransformState(this); | ||
4364 | |||
4365 | var stream = this; | ||
4366 | |||
4367 | // start out asking for a readable event once data is transformed. | ||
4368 | this._readableState.needReadable = true; | ||
4369 | |||
4370 | // we have implemented the _read method, and done the other things | ||
4371 | // that Readable wants before the first _read call, so unset the | ||
4372 | // sync guard flag. | ||
4373 | this._readableState.sync = false; | ||
4374 | |||
4375 | if (options) { | ||
4376 | if (typeof options.transform === 'function') this._transform = options.transform; | ||
4377 | |||
4378 | if (typeof options.flush === 'function') this._flush = options.flush; | ||
4379 | } | ||
4380 | |||
4381 | // When the writable side finishes, then flush out anything remaining. | ||
4382 | this.once('prefinish', function () { | ||
4383 | if (typeof this._flush === 'function') this._flush(function (er, data) { | ||
4384 | done(stream, er, data); | ||
4385 | });else done(stream); | ||
4386 | }); | ||
4387 | } | ||
4388 | |||
4389 | Transform.prototype.push = function (chunk, encoding) { | ||
4390 | this._transformState.needTransform = false; | ||
4391 | return Duplex.prototype.push.call(this, chunk, encoding); | ||
4392 | }; | ||
4393 | |||
4394 | // This is the part where you do stuff! | ||
4395 | // override this function in implementation classes. | ||
4396 | // 'chunk' is an input chunk. | ||
4397 | // | ||
4398 | // Call `push(newChunk)` to pass along transformed output | ||
4399 | // to the readable side. You may call 'push' zero or more times. | ||
4400 | // | ||
4401 | // Call `cb(err)` when you are done with this chunk. If you pass | ||
4402 | // an error, then that'll put the hurt on the whole operation. If you | ||
4403 | // never call cb(), then you'll never get another chunk. | ||
4404 | Transform.prototype._transform = function (chunk, encoding, cb) { | ||
4405 | throw new Error('_transform() is not implemented'); | ||
4406 | }; | ||
4407 | |||
4408 | Transform.prototype._write = function (chunk, encoding, cb) { | ||
4409 | var ts = this._transformState; | ||
4410 | ts.writecb = cb; | ||
4411 | ts.writechunk = chunk; | ||
4412 | ts.writeencoding = encoding; | ||
4413 | if (!ts.transforming) { | ||
4414 | var rs = this._readableState; | ||
4415 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); | ||
4416 | } | ||
4417 | }; | ||
4418 | |||
4419 | // Doesn't matter what the args are here. | ||
4420 | // _transform does all the work. | ||
4421 | // That we got here means that the readable side wants more data. | ||
4422 | Transform.prototype._read = function (n) { | ||
4423 | var ts = this._transformState; | ||
4424 | |||
4425 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) { | ||
4426 | ts.transforming = true; | ||
4427 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); | ||
4428 | } else { | ||
4429 | // mark that we need a transform, so that any data that comes in | ||
4430 | // will get processed, now that we've asked for it. | ||
4431 | ts.needTransform = true; | ||
4432 | } | ||
4433 | }; | ||
4434 | |||
4435 | function done(stream, er, data) { | ||
4436 | if (er) return stream.emit('error', er); | ||
4437 | |||
4438 | if (data !== null && data !== undefined) stream.push(data); | ||
4439 | |||
4440 | // if there's nothing in the write buffer, then that means | ||
4441 | // that nothing more will ever be provided | ||
4442 | var ws = stream._writableState; | ||
4443 | var ts = stream._transformState; | ||
4444 | |||
4445 | if (ws.length) throw new Error('Calling transform done when ws.length != 0'); | ||
4446 | |||
4447 | if (ts.transforming) throw new Error('Calling transform done when still transforming'); | ||
4448 | |||
4449 | return stream.push(null); | ||
4450 | } | ||
4451 | },{"./_stream_duplex":15,"core-util-is":6,"inherits":9}],19:[function(require,module,exports){ | ||
4452 | (function (process){ | ||
4453 | // A bit simpler than readable streams. | ||
4454 | // Implement an async ._write(chunk, encoding, cb), and it'll handle all | ||
4455 | // the drain event emission and buffering. | ||
4456 | |||
4457 | 'use strict'; | ||
4458 | |||
4459 | module.exports = Writable; | ||
4460 | |||
4461 | /*<replacement>*/ | ||
4462 | var processNextTick = require('process-nextick-args'); | ||
4463 | /*</replacement>*/ | ||
4464 | |||
4465 | /*<replacement>*/ | ||
4466 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; | ||
4467 | /*</replacement>*/ | ||
4468 | |||
4469 | /*<replacement>*/ | ||
4470 | var Duplex; | ||
4471 | /*</replacement>*/ | ||
4472 | |||
4473 | Writable.WritableState = WritableState; | ||
4474 | |||
4475 | /*<replacement>*/ | ||
4476 | var util = require('core-util-is'); | ||
4477 | util.inherits = require('inherits'); | ||
4478 | /*</replacement>*/ | ||
4479 | |||
4480 | /*<replacement>*/ | ||
4481 | var internalUtil = { | ||
4482 | deprecate: require('util-deprecate') | ||
4483 | }; | ||
4484 | /*</replacement>*/ | ||
4485 | |||
4486 | /*<replacement>*/ | ||
4487 | var Stream; | ||
4488 | (function () { | ||
4489 | try { | ||
4490 | Stream = require('st' + 'ream'); | ||
4491 | } catch (_) {} finally { | ||
4492 | if (!Stream) Stream = require('events').EventEmitter; | ||
4493 | } | ||
4494 | })(); | ||
4495 | /*</replacement>*/ | ||
4496 | |||
4497 | var Buffer = require('buffer').Buffer; | ||
4498 | /*<replacement>*/ | ||
4499 | var bufferShim = require('buffer-shims'); | ||
4500 | /*</replacement>*/ | ||
4501 | |||
4502 | util.inherits(Writable, Stream); | ||
4503 | |||
4504 | function nop() {} | ||
4505 | |||
4506 | function WriteReq(chunk, encoding, cb) { | ||
4507 | this.chunk = chunk; | ||
4508 | this.encoding = encoding; | ||
4509 | this.callback = cb; | ||
4510 | this.next = null; | ||
4511 | } | ||
4512 | |||
4513 | function WritableState(options, stream) { | ||
4514 | Duplex = Duplex || require('./_stream_duplex'); | ||
4515 | |||
4516 | options = options || {}; | ||
4517 | |||
4518 | // object stream flag to indicate whether or not this stream | ||
4519 | // contains buffers or objects. | ||
4520 | this.objectMode = !!options.objectMode; | ||
4521 | |||
4522 | if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; | ||
4523 | |||
4524 | // the point at which write() starts returning false | ||
4525 | // Note: 0 is a valid value, means that we always return false if | ||
4526 | // the entire buffer is not flushed immediately on write() | ||
4527 | var hwm = options.highWaterMark; | ||
4528 | var defaultHwm = this.objectMode ? 16 : 16 * 1024; | ||
4529 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | ||
4530 | |||
4531 | // cast to ints. | ||
4532 | this.highWaterMark = ~ ~this.highWaterMark; | ||
4533 | |||
4534 | // drain event flag. | ||
4535 | this.needDrain = false; | ||
4536 | // at the start of calling end() | ||
4537 | this.ending = false; | ||
4538 | // when end() has been called, and returned | ||
4539 | this.ended = false; | ||
4540 | // when 'finish' is emitted | ||
4541 | this.finished = false; | ||
4542 | |||
4543 | // should we decode strings into buffers before passing to _write? | ||
4544 | // this is here so that some node-core streams can optimize string | ||
4545 | // handling at a lower level. | ||
4546 | var noDecode = options.decodeStrings === false; | ||
4547 | this.decodeStrings = !noDecode; | ||
4548 | |||
4549 | // Crypto is kind of old and crusty. Historically, its default string | ||
4550 | // encoding is 'binary' so we have to make this configurable. | ||
4551 | // Everything else in the universe uses 'utf8', though. | ||
4552 | this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
4553 | |||
4554 | // not an actual buffer we keep track of, but a measurement | ||
4555 | // of how much we're waiting to get pushed to some underlying | ||
4556 | // socket or file. | ||
4557 | this.length = 0; | ||
4558 | |||
4559 | // a flag to see when we're in the middle of a write. | ||
4560 | this.writing = false; | ||
4561 | |||
4562 | // when true all writes will be buffered until .uncork() call | ||
4563 | this.corked = 0; | ||
4564 | |||
4565 | // a flag to be able to tell if the onwrite cb is called immediately, | ||
4566 | // or on a later tick. We set this to true at first, because any | ||
4567 | // actions that shouldn't happen until "later" should generally also | ||
4568 | // not happen before the first write call. | ||
4569 | this.sync = true; | ||
4570 | |||
4571 | // a flag to know if we're processing previously buffered items, which | ||
4572 | // may call the _write() callback in the same tick, so that we don't | ||
4573 | // end up in an overlapped onwrite situation. | ||
4574 | this.bufferProcessing = false; | ||
4575 | |||
4576 | // the callback that's passed to _write(chunk,cb) | ||
4577 | this.onwrite = function (er) { | ||
4578 | onwrite(stream, er); | ||
4579 | }; | ||
4580 | |||
4581 | // the callback that the user supplies to write(chunk,encoding,cb) | ||
4582 | this.writecb = null; | ||
4583 | |||
4584 | // the amount that is being written when _write is called. | ||
4585 | this.writelen = 0; | ||
4586 | |||
4587 | this.bufferedRequest = null; | ||
4588 | this.lastBufferedRequest = null; | ||
4589 | |||
4590 | // number of pending user-supplied write callbacks | ||
4591 | // this must be 0 before 'finish' can be emitted | ||
4592 | this.pendingcb = 0; | ||
4593 | |||
4594 | // emit prefinish if the only thing we're waiting for is _write cbs | ||
4595 | // This is relevant for synchronous Transform streams | ||
4596 | this.prefinished = false; | ||
4597 | |||
4598 | // True if the error was already emitted and should not be thrown again | ||
4599 | this.errorEmitted = false; | ||
4600 | |||
4601 | // count buffered requests | ||
4602 | this.bufferedRequestCount = 0; | ||
4603 | |||
4604 | // allocate the first CorkedRequest, there is always | ||
4605 | // one allocated and free to use, and we maintain at most two | ||
4606 | this.corkedRequestsFree = new CorkedRequest(this); | ||
4607 | } | ||
4608 | |||
4609 | WritableState.prototype.getBuffer = function getBuffer() { | ||
4610 | var current = this.bufferedRequest; | ||
4611 | var out = []; | ||
4612 | while (current) { | ||
4613 | out.push(current); | ||
4614 | current = current.next; | ||
4615 | } | ||
4616 | return out; | ||
4617 | }; | ||
4618 | |||
4619 | (function () { | ||
4620 | try { | ||
4621 | Object.defineProperty(WritableState.prototype, 'buffer', { | ||
4622 | get: internalUtil.deprecate(function () { | ||
4623 | return this.getBuffer(); | ||
4624 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') | ||
4625 | }); | ||
4626 | } catch (_) {} | ||
4627 | })(); | ||
4628 | |||
4629 | // Test _writableState for inheritance to account for Duplex streams, | ||
4630 | // whose prototype chain only points to Readable. | ||
4631 | var realHasInstance; | ||
4632 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') { | ||
4633 | realHasInstance = Function.prototype[Symbol.hasInstance]; | ||
4634 | Object.defineProperty(Writable, Symbol.hasInstance, { | ||
4635 | value: function (object) { | ||
4636 | if (realHasInstance.call(this, object)) return true; | ||
4637 | |||
4638 | return object && object._writableState instanceof WritableState; | ||
4639 | } | ||
4640 | }); | ||
4641 | } else { | ||
4642 | realHasInstance = function (object) { | ||
4643 | return object instanceof this; | ||
4644 | }; | ||
4645 | } | ||
4646 | |||
4647 | function Writable(options) { | ||
4648 | Duplex = Duplex || require('./_stream_duplex'); | ||
4649 | |||
4650 | // Writable ctor is applied to Duplexes, too. | ||
4651 | // `realHasInstance` is necessary because using plain `instanceof` | ||
4652 | // would return false, as no `_writableState` property is attached. | ||
4653 | |||
4654 | // Trying to use the custom `instanceof` for Writable here will also break the | ||
4655 | // Node.js LazyTransform implementation, which has a non-trivial getter for | ||
4656 | // `_writableState` that would lead to infinite recursion. | ||
4657 | if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) { | ||
4658 | return new Writable(options); | ||
4659 | } | ||
4660 | |||
4661 | this._writableState = new WritableState(options, this); | ||
4662 | |||
4663 | // legacy. | ||
4664 | this.writable = true; | ||
4665 | |||
4666 | if (options) { | ||
4667 | if (typeof options.write === 'function') this._write = options.write; | ||
4668 | |||
4669 | if (typeof options.writev === 'function') this._writev = options.writev; | ||
4670 | } | ||
4671 | |||
4672 | Stream.call(this); | ||
4673 | } | ||
4674 | |||
4675 | // Otherwise people can pipe Writable streams, which is just wrong. | ||
4676 | Writable.prototype.pipe = function () { | ||
4677 | this.emit('error', new Error('Cannot pipe, not readable')); | ||
4678 | }; | ||
4679 | |||
4680 | function writeAfterEnd(stream, cb) { | ||
4681 | var er = new Error('write after end'); | ||
4682 | // TODO: defer error events consistently everywhere, not just the cb | ||
4683 | stream.emit('error', er); | ||
4684 | processNextTick(cb, er); | ||
4685 | } | ||
4686 | |||
4687 | // If we get something that is not a buffer, string, null, or undefined, | ||
4688 | // and we're not in objectMode, then that's an error. | ||
4689 | // Otherwise stream chunks are all considered to be of length=1, and the | ||
4690 | // watermarks determine how many objects to keep in the buffer, rather than | ||
4691 | // how many bytes or characters. | ||
4692 | function validChunk(stream, state, chunk, cb) { | ||
4693 | var valid = true; | ||
4694 | var er = false; | ||
4695 | // Always throw error if a null is written | ||
4696 | // if we are not in object mode then throw | ||
4697 | // if it is not a buffer, string, or undefined. | ||
4698 | if (chunk === null) { | ||
4699 | er = new TypeError('May not write null values to stream'); | ||
4700 | } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { | ||
4701 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
4702 | } | ||
4703 | if (er) { | ||
4704 | stream.emit('error', er); | ||
4705 | processNextTick(cb, er); | ||
4706 | valid = false; | ||
4707 | } | ||
4708 | return valid; | ||
4709 | } | ||
4710 | |||
4711 | Writable.prototype.write = function (chunk, encoding, cb) { | ||
4712 | var state = this._writableState; | ||
4713 | var ret = false; | ||
4714 | |||
4715 | if (typeof encoding === 'function') { | ||
4716 | cb = encoding; | ||
4717 | encoding = null; | ||
4718 | } | ||
4719 | |||
4720 | if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; | ||
4721 | |||
4722 | if (typeof cb !== 'function') cb = nop; | ||
4723 | |||
4724 | if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { | ||
4725 | state.pendingcb++; | ||
4726 | ret = writeOrBuffer(this, state, chunk, encoding, cb); | ||
4727 | } | ||
4728 | |||
4729 | return ret; | ||
4730 | }; | ||
4731 | |||
4732 | Writable.prototype.cork = function () { | ||
4733 | var state = this._writableState; | ||
4734 | |||
4735 | state.corked++; | ||
4736 | }; | ||
4737 | |||
4738 | Writable.prototype.uncork = function () { | ||
4739 | var state = this._writableState; | ||
4740 | |||
4741 | if (state.corked) { | ||
4742 | state.corked--; | ||
4743 | |||
4744 | if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); | ||
4745 | } | ||
4746 | }; | ||
4747 | |||
4748 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { | ||
4749 | // node::ParseEncoding() requires lower case. | ||
4750 | if (typeof encoding === 'string') encoding = encoding.toLowerCase(); | ||
4751 | 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); | ||
4752 | this._writableState.defaultEncoding = encoding; | ||
4753 | return this; | ||
4754 | }; | ||
4755 | |||
4756 | function decodeChunk(state, chunk, encoding) { | ||
4757 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { | ||
4758 | chunk = bufferShim.from(chunk, encoding); | ||
4759 | } | ||
4760 | return chunk; | ||
4761 | } | ||
4762 | |||
4763 | // if we're already writing something, then just put this | ||
4764 | // in the queue, and wait our turn. Otherwise, call _write | ||
4765 | // If we return false, then we need a drain event, so set that flag. | ||
4766 | function writeOrBuffer(stream, state, chunk, encoding, cb) { | ||
4767 | chunk = decodeChunk(state, chunk, encoding); | ||
4768 | |||
4769 | if (Buffer.isBuffer(chunk)) encoding = 'buffer'; | ||
4770 | var len = state.objectMode ? 1 : chunk.length; | ||
4771 | |||
4772 | state.length += len; | ||
4773 | |||
4774 | var ret = state.length < state.highWaterMark; | ||
4775 | // we must ensure that previous needDrain will not be reset to false. | ||
4776 | if (!ret) state.needDrain = true; | ||
4777 | |||
4778 | if (state.writing || state.corked) { | ||
4779 | var last = state.lastBufferedRequest; | ||
4780 | state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); | ||
4781 | if (last) { | ||
4782 | last.next = state.lastBufferedRequest; | ||
4783 | } else { | ||
4784 | state.bufferedRequest = state.lastBufferedRequest; | ||
4785 | } | ||
4786 | state.bufferedRequestCount += 1; | ||
4787 | } else { | ||
4788 | doWrite(stream, state, false, len, chunk, encoding, cb); | ||
4789 | } | ||
4790 | |||
4791 | return ret; | ||
4792 | } | ||
4793 | |||
4794 | function doWrite(stream, state, writev, len, chunk, encoding, cb) { | ||
4795 | state.writelen = len; | ||
4796 | state.writecb = cb; | ||
4797 | state.writing = true; | ||
4798 | state.sync = true; | ||
4799 | if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); | ||
4800 | state.sync = false; | ||
4801 | } | ||
4802 | |||
4803 | function onwriteError(stream, state, sync, er, cb) { | ||
4804 | --state.pendingcb; | ||
4805 | if (sync) processNextTick(cb, er);else cb(er); | ||
4806 | |||
4807 | stream._writableState.errorEmitted = true; | ||
4808 | stream.emit('error', er); | ||
4809 | } | ||
4810 | |||
4811 | function onwriteStateUpdate(state) { | ||
4812 | state.writing = false; | ||
4813 | state.writecb = null; | ||
4814 | state.length -= state.writelen; | ||
4815 | state.writelen = 0; | ||
4816 | } | ||
4817 | |||
4818 | function onwrite(stream, er) { | ||
4819 | var state = stream._writableState; | ||
4820 | var sync = state.sync; | ||
4821 | var cb = state.writecb; | ||
4822 | |||
4823 | onwriteStateUpdate(state); | ||
4824 | |||
4825 | if (er) onwriteError(stream, state, sync, er, cb);else { | ||
4826 | // Check if we're actually ready to finish, but don't emit yet | ||
4827 | var finished = needFinish(state); | ||
4828 | |||
4829 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { | ||
4830 | clearBuffer(stream, state); | ||
4831 | } | ||
4832 | |||
4833 | if (sync) { | ||
4834 | /*<replacement>*/ | ||
4835 | asyncWrite(afterWrite, stream, state, finished, cb); | ||
4836 | /*</replacement>*/ | ||
4837 | } else { | ||
4838 | afterWrite(stream, state, finished, cb); | ||
4839 | } | ||
4840 | } | ||
4841 | } | ||
4842 | |||
4843 | function afterWrite(stream, state, finished, cb) { | ||
4844 | if (!finished) onwriteDrain(stream, state); | ||
4845 | state.pendingcb--; | ||
4846 | cb(); | ||
4847 | finishMaybe(stream, state); | ||
4848 | } | ||
4849 | |||
4850 | // Must force callback to be called on nextTick, so that we don't | ||
4851 | // emit 'drain' before the write() consumer gets the 'false' return | ||
4852 | // value, and has a chance to attach a 'drain' listener. | ||
4853 | function onwriteDrain(stream, state) { | ||
4854 | if (state.length === 0 && state.needDrain) { | ||
4855 | state.needDrain = false; | ||
4856 | stream.emit('drain'); | ||
4857 | } | ||
4858 | } | ||
4859 | |||
4860 | // if there's something in the buffer waiting, then process it | ||
4861 | function clearBuffer(stream, state) { | ||
4862 | state.bufferProcessing = true; | ||
4863 | var entry = state.bufferedRequest; | ||
4864 | |||
4865 | if (stream._writev && entry && entry.next) { | ||
4866 | // Fast case, write everything using _writev() | ||
4867 | var l = state.bufferedRequestCount; | ||
4868 | var buffer = new Array(l); | ||
4869 | var holder = state.corkedRequestsFree; | ||
4870 | holder.entry = entry; | ||
4871 | |||
4872 | var count = 0; | ||
4873 | while (entry) { | ||
4874 | buffer[count] = entry; | ||
4875 | entry = entry.next; | ||
4876 | count += 1; | ||
4877 | } | ||
4878 | |||
4879 | doWrite(stream, state, true, state.length, buffer, '', holder.finish); | ||
4880 | |||
4881 | // doWrite is almost always async, defer these to save a bit of time | ||
4882 | // as the hot path ends with doWrite | ||
4883 | state.pendingcb++; | ||
4884 | state.lastBufferedRequest = null; | ||
4885 | if (holder.next) { | ||
4886 | state.corkedRequestsFree = holder.next; | ||
4887 | holder.next = null; | ||
4888 | } else { | ||
4889 | state.corkedRequestsFree = new CorkedRequest(state); | ||
4890 | } | ||
4891 | } else { | ||
4892 | // Slow case, write chunks one-by-one | ||
4893 | while (entry) { | ||
4894 | var chunk = entry.chunk; | ||
4895 | var encoding = entry.encoding; | ||
4896 | var cb = entry.callback; | ||
4897 | var len = state.objectMode ? 1 : chunk.length; | ||
4898 | |||
4899 | doWrite(stream, state, false, len, chunk, encoding, cb); | ||
4900 | entry = entry.next; | ||
4901 | // if we didn't call the onwrite immediately, then | ||
4902 | // it means that we need to wait until it does. | ||
4903 | // also, that means that the chunk and cb are currently | ||
4904 | // being processed, so move the buffer counter past them. | ||
4905 | if (state.writing) { | ||
4906 | break; | ||
4907 | } | ||
4908 | } | ||
4909 | |||
4910 | if (entry === null) state.lastBufferedRequest = null; | ||
4911 | } | ||
4912 | |||
4913 | state.bufferedRequestCount = 0; | ||
4914 | state.bufferedRequest = entry; | ||
4915 | state.bufferProcessing = false; | ||
4916 | } | ||
4917 | |||
4918 | Writable.prototype._write = function (chunk, encoding, cb) { | ||
4919 | cb(new Error('_write() is not implemented')); | ||
4920 | }; | ||
4921 | |||
4922 | Writable.prototype._writev = null; | ||
4923 | |||
4924 | Writable.prototype.end = function (chunk, encoding, cb) { | ||
4925 | var state = this._writableState; | ||
4926 | |||
4927 | if (typeof chunk === 'function') { | ||
4928 | cb = chunk; | ||
4929 | chunk = null; | ||
4930 | encoding = null; | ||
4931 | } else if (typeof encoding === 'function') { | ||
4932 | cb = encoding; | ||
4933 | encoding = null; | ||
4934 | } | ||
4935 | |||
4936 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); | ||
4937 | |||
4938 | // .end() fully uncorks | ||
4939 | if (state.corked) { | ||
4940 | state.corked = 1; | ||
4941 | this.uncork(); | ||
4942 | } | ||
4943 | |||
4944 | // ignore unnecessary end() calls. | ||
4945 | if (!state.ending && !state.finished) endWritable(this, state, cb); | ||
4946 | }; | ||
4947 | |||
4948 | function needFinish(state) { | ||
4949 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; | ||
4950 | } | ||
4951 | |||
4952 | function prefinish(stream, state) { | ||
4953 | if (!state.prefinished) { | ||
4954 | state.prefinished = true; | ||
4955 | stream.emit('prefinish'); | ||
4956 | } | ||
4957 | } | ||
4958 | |||
4959 | function finishMaybe(stream, state) { | ||
4960 | var need = needFinish(state); | ||
4961 | if (need) { | ||
4962 | if (state.pendingcb === 0) { | ||
4963 | prefinish(stream, state); | ||
4964 | state.finished = true; | ||
4965 | stream.emit('finish'); | ||
4966 | } else { | ||
4967 | prefinish(stream, state); | ||
4968 | } | ||
4969 | } | ||
4970 | return need; | ||
4971 | } | ||
4972 | |||
4973 | function endWritable(stream, state, cb) { | ||
4974 | state.ending = true; | ||
4975 | finishMaybe(stream, state); | ||
4976 | if (cb) { | ||
4977 | if (state.finished) processNextTick(cb);else stream.once('finish', cb); | ||
4978 | } | ||
4979 | state.ended = true; | ||
4980 | stream.writable = false; | ||
4981 | } | ||
4982 | |||
4983 | // It seems a linked list but it is not | ||
4984 | // there will be only 2 of these for each stream | ||
4985 | function CorkedRequest(state) { | ||
4986 | var _this = this; | ||
4987 | |||
4988 | this.next = null; | ||
4989 | this.entry = null; | ||
4990 | |||
4991 | this.finish = function (err) { | ||
4992 | var entry = _this.entry; | ||
4993 | _this.entry = null; | ||
4994 | while (entry) { | ||
4995 | var cb = entry.callback; | ||
4996 | state.pendingcb--; | ||
4997 | cb(err); | ||
4998 | entry = entry.next; | ||
4999 | } | ||
5000 | if (state.corkedRequestsFree) { | ||
5001 | state.corkedRequestsFree.next = _this; | ||
5002 | } else { | ||
5003 | state.corkedRequestsFree = _this; | ||
5004 | } | ||
5005 | }; | ||
5006 | } | ||
5007 | }).call(this,require('_process')) | ||
5008 | },{"./_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){ | ||
5009 | 'use strict'; | ||
5010 | |||
5011 | var Buffer = require('buffer').Buffer; | ||
5012 | /*<replacement>*/ | ||
5013 | var bufferShim = require('buffer-shims'); | ||
5014 | /*</replacement>*/ | ||
5015 | |||
5016 | module.exports = BufferList; | ||
5017 | |||
5018 | function BufferList() { | ||
5019 | this.head = null; | ||
5020 | this.tail = null; | ||
5021 | this.length = 0; | ||
5022 | } | ||
5023 | |||
5024 | BufferList.prototype.push = function (v) { | ||
5025 | var entry = { data: v, next: null }; | ||
5026 | if (this.length > 0) this.tail.next = entry;else this.head = entry; | ||
5027 | this.tail = entry; | ||
5028 | ++this.length; | ||
5029 | }; | ||
5030 | |||
5031 | BufferList.prototype.unshift = function (v) { | ||
5032 | var entry = { data: v, next: this.head }; | ||
5033 | if (this.length === 0) this.tail = entry; | ||
5034 | this.head = entry; | ||
5035 | ++this.length; | ||
5036 | }; | ||
5037 | |||
5038 | BufferList.prototype.shift = function () { | ||
5039 | if (this.length === 0) return; | ||
5040 | var ret = this.head.data; | ||
5041 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
5042 | --this.length; | ||
5043 | return ret; | ||
5044 | }; | ||
5045 | |||
5046 | BufferList.prototype.clear = function () { | ||
5047 | this.head = this.tail = null; | ||
5048 | this.length = 0; | ||
5049 | }; | ||
5050 | |||
5051 | BufferList.prototype.join = function (s) { | ||
5052 | if (this.length === 0) return ''; | ||
5053 | var p = this.head; | ||
5054 | var ret = '' + p.data; | ||
5055 | while (p = p.next) { | ||
5056 | ret += s + p.data; | ||
5057 | }return ret; | ||
5058 | }; | ||
5059 | |||
5060 | BufferList.prototype.concat = function (n) { | ||
5061 | if (this.length === 0) return bufferShim.alloc(0); | ||
5062 | if (this.length === 1) return this.head.data; | ||
5063 | var ret = bufferShim.allocUnsafe(n >>> 0); | ||
5064 | var p = this.head; | ||
5065 | var i = 0; | ||
5066 | while (p) { | ||
5067 | p.data.copy(ret, i); | ||
5068 | i += p.data.length; | ||
5069 | p = p.next; | ||
5070 | } | ||
5071 | return ret; | ||
5072 | }; | ||
5073 | },{"buffer":5,"buffer-shims":4}],21:[function(require,module,exports){ | ||
5074 | module.exports = require("./lib/_stream_passthrough.js") | ||
5075 | |||
5076 | },{"./lib/_stream_passthrough.js":16}],22:[function(require,module,exports){ | ||
5077 | (function (process){ | ||
5078 | var Stream = (function (){ | ||
5079 | try { | ||
5080 | return require('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify | ||
5081 | } catch(_){} | ||
5082 | }()); | ||
5083 | exports = module.exports = require('./lib/_stream_readable.js'); | ||
5084 | exports.Stream = Stream || exports; | ||
5085 | exports.Readable = exports; | ||
5086 | exports.Writable = require('./lib/_stream_writable.js'); | ||
5087 | exports.Duplex = require('./lib/_stream_duplex.js'); | ||
5088 | exports.Transform = require('./lib/_stream_transform.js'); | ||
5089 | exports.PassThrough = require('./lib/_stream_passthrough.js'); | ||
5090 | |||
5091 | if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) { | ||
5092 | module.exports = Stream; | ||
5093 | } | ||
5094 | |||
5095 | }).call(this,require('_process')) | ||
5096 | },{"./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){ | ||
5097 | module.exports = require("./lib/_stream_transform.js") | ||
5098 | |||
5099 | },{"./lib/_stream_transform.js":18}],24:[function(require,module,exports){ | ||
5100 | module.exports = require("./lib/_stream_writable.js") | ||
5101 | |||
5102 | },{"./lib/_stream_writable.js":19}],25:[function(require,module,exports){ | ||
5103 | // Copyright Joyent, Inc. and other Node contributors. | ||
5104 | // | ||
5105 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5106 | // copy of this software and associated documentation files (the | ||
5107 | // "Software"), to deal in the Software without restriction, including | ||
5108 | // without limitation the rights to use, copy, modify, merge, publish, | ||
5109 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
5110 | // persons to whom the Software is furnished to do so, subject to the | ||
5111 | // following conditions: | ||
5112 | // | ||
5113 | // The above copyright notice and this permission notice shall be included | ||
5114 | // in all copies or substantial portions of the Software. | ||
5115 | // | ||
5116 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
5117 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
5118 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
5119 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
5120 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
5121 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
5122 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
5123 | |||
5124 | module.exports = Stream; | ||
5125 | |||
5126 | var EE = require('events').EventEmitter; | ||
5127 | var inherits = require('inherits'); | ||
5128 | |||
5129 | inherits(Stream, EE); | ||
5130 | Stream.Readable = require('readable-stream/readable.js'); | ||
5131 | Stream.Writable = require('readable-stream/writable.js'); | ||
5132 | Stream.Duplex = require('readable-stream/duplex.js'); | ||
5133 | Stream.Transform = require('readable-stream/transform.js'); | ||
5134 | Stream.PassThrough = require('readable-stream/passthrough.js'); | ||
5135 | |||
5136 | // Backwards-compat with node 0.4.x | ||
5137 | Stream.Stream = Stream; | ||
5138 | |||
5139 | |||
5140 | |||
5141 | // old-style streams. Note that the pipe method (the only relevant | ||
5142 | // part of this class) is overridden in the Readable class. | ||
5143 | |||
5144 | function Stream() { | ||
5145 | EE.call(this); | ||
5146 | } | ||
5147 | |||
5148 | Stream.prototype.pipe = function(dest, options) { | ||
5149 | var source = this; | ||
5150 | |||
5151 | function ondata(chunk) { | ||
5152 | if (dest.writable) { | ||
5153 | if (false === dest.write(chunk) && source.pause) { | ||
5154 | source.pause(); | ||
5155 | } | ||
5156 | } | ||
5157 | } | ||
5158 | |||
5159 | source.on('data', ondata); | ||
5160 | |||
5161 | function ondrain() { | ||
5162 | if (source.readable && source.resume) { | ||
5163 | source.resume(); | ||
5164 | } | ||
5165 | } | ||
5166 | |||
5167 | dest.on('drain', ondrain); | ||
5168 | |||
5169 | // If the 'end' option is not supplied, dest.end() will be called when | ||
5170 | // source gets the 'end' or 'close' events. Only dest.end() once. | ||
5171 | if (!dest._isStdio && (!options || options.end !== false)) { | ||
5172 | source.on('end', onend); | ||
5173 | source.on('close', onclose); | ||
5174 | } | ||
5175 | |||
5176 | var didOnEnd = false; | ||
5177 | function onend() { | ||
5178 | if (didOnEnd) return; | ||
5179 | didOnEnd = true; | ||
5180 | |||
5181 | dest.end(); | ||
5182 | } | ||
5183 | |||
5184 | |||
5185 | function onclose() { | ||
5186 | if (didOnEnd) return; | ||
5187 | didOnEnd = true; | ||
5188 | |||
5189 | if (typeof dest.destroy === 'function') dest.destroy(); | ||
5190 | } | ||
5191 | |||
5192 | // don't leave dangling pipes when there are errors. | ||
5193 | function onerror(er) { | ||
5194 | cleanup(); | ||
5195 | if (EE.listenerCount(this, 'error') === 0) { | ||
5196 | throw er; // Unhandled stream error in pipe. | ||
5197 | } | ||
5198 | } | ||
5199 | |||
5200 | source.on('error', onerror); | ||
5201 | dest.on('error', onerror); | ||
5202 | |||
5203 | // remove all the event listeners that were added. | ||
5204 | function cleanup() { | ||
5205 | source.removeListener('data', ondata); | ||
5206 | dest.removeListener('drain', ondrain); | ||
5207 | |||
5208 | source.removeListener('end', onend); | ||
5209 | source.removeListener('close', onclose); | ||
5210 | |||
5211 | source.removeListener('error', onerror); | ||
5212 | dest.removeListener('error', onerror); | ||
5213 | |||
5214 | source.removeListener('end', cleanup); | ||
5215 | source.removeListener('close', cleanup); | ||
5216 | |||
5217 | dest.removeListener('close', cleanup); | ||
5218 | } | ||
5219 | |||
5220 | source.on('end', cleanup); | ||
5221 | source.on('close', cleanup); | ||
5222 | |||
5223 | dest.on('close', cleanup); | ||
5224 | |||
5225 | dest.emit('pipe', source); | ||
5226 | |||
5227 | // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
5228 | return dest; | ||
5229 | }; | ||
5230 | |||
5231 | },{"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){ | ||
5232 | // Copyright Joyent, Inc. and other Node contributors. | ||
5233 | // | ||
5234 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5235 | // copy of this software and associated documentation files (the | ||
5236 | // "Software"), to deal in the Software without restriction, including | ||
5237 | // without limitation the rights to use, copy, modify, merge, publish, | ||
5238 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
5239 | // persons to whom the Software is furnished to do so, subject to the | ||
5240 | // following conditions: | ||
5241 | // | ||
5242 | // The above copyright notice and this permission notice shall be included | ||
5243 | // in all copies or substantial portions of the Software. | ||
5244 | // | ||
5245 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
5246 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
5247 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
5248 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
5249 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
5250 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
5251 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
5252 | |||
5253 | var Buffer = require('buffer').Buffer; | ||
5254 | |||
5255 | var isBufferEncoding = Buffer.isEncoding | ||
5256 | || function(encoding) { | ||
5257 | switch (encoding && encoding.toLowerCase()) { | ||
5258 | 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; | ||
5259 | default: return false; | ||
5260 | } | ||
5261 | } | ||
5262 | |||
5263 | |||
5264 | function assertEncoding(encoding) { | ||
5265 | if (encoding && !isBufferEncoding(encoding)) { | ||
5266 | throw new Error('Unknown encoding: ' + encoding); | ||
5267 | } | ||
5268 | } | ||
5269 | |||
5270 | // StringDecoder provides an interface for efficiently splitting a series of | ||
5271 | // buffers into a series of JS strings without breaking apart multi-byte | ||
5272 | // characters. CESU-8 is handled as part of the UTF-8 encoding. | ||
5273 | // | ||
5274 | // @TODO Handling all encodings inside a single object makes it very difficult | ||
5275 | // to reason about this code, so it should be split up in the future. | ||
5276 | // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code | ||
5277 | // points as used by CESU-8. | ||
5278 | var StringDecoder = exports.StringDecoder = function(encoding) { | ||
5279 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); | ||
5280 | assertEncoding(encoding); | ||
5281 | switch (this.encoding) { | ||
5282 | case 'utf8': | ||
5283 | // CESU-8 represents each of Surrogate Pair by 3-bytes | ||
5284 | this.surrogateSize = 3; | ||
5285 | break; | ||
5286 | case 'ucs2': | ||
5287 | case 'utf16le': | ||
5288 | // UTF-16 represents each of Surrogate Pair by 2-bytes | ||
5289 | this.surrogateSize = 2; | ||
5290 | this.detectIncompleteChar = utf16DetectIncompleteChar; | ||
5291 | break; | ||
5292 | case 'base64': | ||
5293 | // Base-64 stores 3 bytes in 4 chars, and pads the remainder. | ||
5294 | this.surrogateSize = 3; | ||
5295 | this.detectIncompleteChar = base64DetectIncompleteChar; | ||
5296 | break; | ||
5297 | default: | ||
5298 | this.write = passThroughWrite; | ||
5299 | return; | ||
5300 | } | ||
5301 | |||
5302 | // Enough space to store all bytes of a single character. UTF-8 needs 4 | ||
5303 | // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). | ||
5304 | this.charBuffer = new Buffer(6); | ||
5305 | // Number of bytes received for the current incomplete multi-byte character. | ||
5306 | this.charReceived = 0; | ||
5307 | // Number of bytes expected for the current incomplete multi-byte character. | ||
5308 | this.charLength = 0; | ||
5309 | }; | ||
5310 | |||
5311 | |||
5312 | // write decodes the given buffer and returns it as JS string that is | ||
5313 | // guaranteed to not contain any partial multi-byte characters. Any partial | ||
5314 | // character found at the end of the buffer is buffered up, and will be | ||
5315 | // returned when calling write again with the remaining bytes. | ||
5316 | // | ||
5317 | // Note: Converting a Buffer containing an orphan surrogate to a String | ||
5318 | // currently works, but converting a String to a Buffer (via `new Buffer`, or | ||
5319 | // Buffer#write) will replace incomplete surrogates with the unicode | ||
5320 | // replacement character. See https://codereview.chromium.org/121173009/ . | ||
5321 | StringDecoder.prototype.write = function(buffer) { | ||
5322 | var charStr = ''; | ||
5323 | // if our last write ended with an incomplete multibyte character | ||
5324 | while (this.charLength) { | ||
5325 | // determine how many remaining bytes this buffer has to offer for this char | ||
5326 | var available = (buffer.length >= this.charLength - this.charReceived) ? | ||
5327 | this.charLength - this.charReceived : | ||
5328 | buffer.length; | ||
5329 | |||
5330 | // add the new bytes to the char buffer | ||
5331 | buffer.copy(this.charBuffer, this.charReceived, 0, available); | ||
5332 | this.charReceived += available; | ||
5333 | |||
5334 | if (this.charReceived < this.charLength) { | ||
5335 | // still not enough chars in this buffer? wait for more ... | ||
5336 | return ''; | ||
5337 | } | ||
5338 | |||
5339 | // remove bytes belonging to the current character from the buffer | ||
5340 | buffer = buffer.slice(available, buffer.length); | ||
5341 | |||
5342 | // get the character that was split | ||
5343 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); | ||
5344 | |||
5345 | // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character | ||
5346 | var charCode = charStr.charCodeAt(charStr.length - 1); | ||
5347 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { | ||
5348 | this.charLength += this.surrogateSize; | ||
5349 | charStr = ''; | ||
5350 | continue; | ||
5351 | } | ||
5352 | this.charReceived = this.charLength = 0; | ||
5353 | |||
5354 | // if there are no more bytes in this buffer, just emit our char | ||
5355 | if (buffer.length === 0) { | ||
5356 | return charStr; | ||
5357 | } | ||
5358 | break; | ||
5359 | } | ||
5360 | |||
5361 | // determine and set charLength / charReceived | ||
5362 | this.detectIncompleteChar(buffer); | ||
5363 | |||
5364 | var end = buffer.length; | ||
5365 | if (this.charLength) { | ||
5366 | // buffer the incomplete character bytes we got | ||
5367 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); | ||
5368 | end -= this.charReceived; | ||
5369 | } | ||
5370 | |||
5371 | charStr += buffer.toString(this.encoding, 0, end); | ||
5372 | |||
5373 | var end = charStr.length - 1; | ||
5374 | var charCode = charStr.charCodeAt(end); | ||
5375 | // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character | ||
5376 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { | ||
5377 | var size = this.surrogateSize; | ||
5378 | this.charLength += size; | ||
5379 | this.charReceived += size; | ||
5380 | this.charBuffer.copy(this.charBuffer, size, 0, size); | ||
5381 | buffer.copy(this.charBuffer, 0, 0, size); | ||
5382 | return charStr.substring(0, end); | ||
5383 | } | ||
5384 | |||
5385 | // or just emit the charStr | ||
5386 | return charStr; | ||
5387 | }; | ||
5388 | |||
5389 | // detectIncompleteChar determines if there is an incomplete UTF-8 character at | ||
5390 | // the end of the given buffer. If so, it sets this.charLength to the byte | ||
5391 | // length that character, and sets this.charReceived to the number of bytes | ||
5392 | // that are available for this character. | ||
5393 | StringDecoder.prototype.detectIncompleteChar = function(buffer) { | ||
5394 | // determine how many bytes we have to check at the end of this buffer | ||
5395 | var i = (buffer.length >= 3) ? 3 : buffer.length; | ||
5396 | |||
5397 | // Figure out if one of the last i bytes of our buffer announces an | ||
5398 | // incomplete char. | ||
5399 | for (; i > 0; i--) { | ||
5400 | var c = buffer[buffer.length - i]; | ||
5401 | |||
5402 | // See http://en.wikipedia.org/wiki/UTF-8#Description | ||
5403 | |||
5404 | // 110XXXXX | ||
5405 | if (i == 1 && c >> 5 == 0x06) { | ||
5406 | this.charLength = 2; | ||
5407 | break; | ||
5408 | } | ||
5409 | |||
5410 | // 1110XXXX | ||
5411 | if (i <= 2 && c >> 4 == 0x0E) { | ||
5412 | this.charLength = 3; | ||
5413 | break; | ||
5414 | } | ||
5415 | |||
5416 | // 11110XXX | ||
5417 | if (i <= 3 && c >> 3 == 0x1E) { | ||
5418 | this.charLength = 4; | ||
5419 | break; | ||
5420 | } | ||
5421 | } | ||
5422 | this.charReceived = i; | ||
5423 | }; | ||
5424 | |||
5425 | StringDecoder.prototype.end = function(buffer) { | ||
5426 | var res = ''; | ||
5427 | if (buffer && buffer.length) | ||
5428 | res = this.write(buffer); | ||
5429 | |||
5430 | if (this.charReceived) { | ||
5431 | var cr = this.charReceived; | ||
5432 | var buf = this.charBuffer; | ||
5433 | var enc = this.encoding; | ||
5434 | res += buf.slice(0, cr).toString(enc); | ||
5435 | } | ||
5436 | |||
5437 | return res; | ||
5438 | }; | ||
5439 | |||
5440 | function passThroughWrite(buffer) { | ||
5441 | return buffer.toString(this.encoding); | ||
5442 | } | ||
5443 | |||
5444 | function utf16DetectIncompleteChar(buffer) { | ||
5445 | this.charReceived = buffer.length % 2; | ||
5446 | this.charLength = this.charReceived ? 2 : 0; | ||
5447 | } | ||
5448 | |||
5449 | function base64DetectIncompleteChar(buffer) { | ||
5450 | this.charReceived = buffer.length % 3; | ||
5451 | this.charLength = this.charReceived ? 3 : 0; | ||
5452 | } | ||
5453 | |||
5454 | },{"buffer":5}],27:[function(require,module,exports){ | ||
5455 | (function (global){ | ||
5456 | |||
5457 | /** | ||
5458 | * Module exports. | ||
5459 | */ | ||
5460 | |||
5461 | module.exports = deprecate; | ||
5462 | |||
5463 | /** | ||
5464 | * Mark that a method should not be used. | ||
5465 | * Returns a modified function which warns once by default. | ||
5466 | * | ||
5467 | * If `localStorage.noDeprecation = true` is set, then it is a no-op. | ||
5468 | * | ||
5469 | * If `localStorage.throwDeprecation = true` is set, then deprecated functions | ||
5470 | * will throw an Error when invoked. | ||
5471 | * | ||
5472 | * If `localStorage.traceDeprecation = true` is set, then deprecated functions | ||
5473 | * will invoke `console.trace()` instead of `console.error()`. | ||
5474 | * | ||
5475 | * @param {Function} fn - the function to deprecate | ||
5476 | * @param {String} msg - the string to print to the console when `fn` is invoked | ||
5477 | * @returns {Function} a new "deprecated" version of `fn` | ||
5478 | * @api public | ||
5479 | */ | ||
5480 | |||
5481 | function deprecate (fn, msg) { | ||
5482 | if (config('noDeprecation')) { | ||
5483 | return fn; | ||
5484 | } | ||
5485 | |||
5486 | var warned = false; | ||
5487 | function deprecated() { | ||
5488 | if (!warned) { | ||
5489 | if (config('throwDeprecation')) { | ||
5490 | throw new Error(msg); | ||
5491 | } else if (config('traceDeprecation')) { | ||
5492 | console.trace(msg); | ||
5493 | } else { | ||
5494 | console.warn(msg); | ||
5495 | } | ||
5496 | warned = true; | ||
5497 | } | ||
5498 | return fn.apply(this, arguments); | ||
5499 | } | ||
5500 | |||
5501 | return deprecated; | ||
5502 | } | ||
5503 | |||
5504 | /** | ||
5505 | * Checks `localStorage` for boolean values for the given `name`. | ||
5506 | * | ||
5507 | * @param {String} name | ||
5508 | * @returns {Boolean} | ||
5509 | * @api private | ||
5510 | */ | ||
5511 | |||
5512 | function config (name) { | ||
5513 | // accessing global.localStorage can trigger a DOMException in sandboxed iframes | ||
5514 | try { | ||
5515 | if (!global.localStorage) return false; | ||
5516 | } catch (_) { | ||
5517 | return false; | ||
5518 | } | ||
5519 | var val = global.localStorage[name]; | ||
5520 | if (null == val) return false; | ||
5521 | return String(val).toLowerCase() === 'true'; | ||
5522 | } | ||
5523 | |||
5524 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
5525 | },{}],28:[function(require,module,exports){ | ||
5526 | arguments[4][9][0].apply(exports,arguments) | ||
5527 | },{"dup":9}],29:[function(require,module,exports){ | ||
5528 | module.exports = function isBuffer(arg) { | ||
5529 | return arg && typeof arg === 'object' | ||
5530 | && typeof arg.copy === 'function' | ||
5531 | && typeof arg.fill === 'function' | ||
5532 | && typeof arg.readUInt8 === 'function'; | ||
5533 | } | ||
5534 | },{}],30:[function(require,module,exports){ | ||
5535 | (function (process,global){ | ||
5536 | // Copyright Joyent, Inc. and other Node contributors. | ||
5537 | // | ||
5538 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5539 | // copy of this software and associated documentation files (the | ||
5540 | // "Software"), to deal in the Software without restriction, including | ||
5541 | // without limitation the rights to use, copy, modify, merge, publish, | ||
5542 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
5543 | // persons to whom the Software is furnished to do so, subject to the | ||
5544 | // following conditions: | ||
5545 | // | ||
5546 | // The above copyright notice and this permission notice shall be included | ||
5547 | // in all copies or substantial portions of the Software. | ||
5548 | // | ||
5549 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
5550 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
5551 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
5552 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
5553 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
5554 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
5555 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
5556 | |||
5557 | var formatRegExp = /%[sdj%]/g; | ||
5558 | exports.format = function(f) { | ||
5559 | if (!isString(f)) { | ||
5560 | var objects = []; | ||
5561 | for (var i = 0; i < arguments.length; i++) { | ||
5562 | objects.push(inspect(arguments[i])); | ||
5563 | } | ||
5564 | return objects.join(' '); | ||
5565 | } | ||
5566 | |||
5567 | var i = 1; | ||
5568 | var args = arguments; | ||
5569 | var len = args.length; | ||
5570 | var str = String(f).replace(formatRegExp, function(x) { | ||
5571 | if (x === '%%') return '%'; | ||
5572 | if (i >= len) return x; | ||
5573 | switch (x) { | ||
5574 | case '%s': return String(args[i++]); | ||
5575 | case '%d': return Number(args[i++]); | ||
5576 | case '%j': | ||
5577 | try { | ||
5578 | return JSON.stringify(args[i++]); | ||
5579 | } catch (_) { | ||
5580 | return '[Circular]'; | ||
5581 | } | ||
5582 | default: | ||
5583 | return x; | ||
5584 | } | ||
5585 | }); | ||
5586 | for (var x = args[i]; i < len; x = args[++i]) { | ||
5587 | if (isNull(x) || !isObject(x)) { | ||
5588 | str += ' ' + x; | ||
5589 | } else { | ||
5590 | str += ' ' + inspect(x); | ||
5591 | } | ||
5592 | } | ||
5593 | return str; | ||
5594 | }; | ||
5595 | |||
5596 | |||
5597 | // Mark that a method should not be used. | ||
5598 | // Returns a modified function which warns once by default. | ||
5599 | // If --no-deprecation is set, then it is a no-op. | ||
5600 | exports.deprecate = function(fn, msg) { | ||
5601 | // Allow for deprecating things in the process of starting up. | ||
5602 | if (isUndefined(global.process)) { | ||
5603 | return function() { | ||
5604 | return exports.deprecate(fn, msg).apply(this, arguments); | ||
5605 | }; | ||
5606 | } | ||
5607 | |||
5608 | if (process.noDeprecation === true) { | ||
5609 | return fn; | ||
5610 | } | ||
5611 | |||
5612 | var warned = false; | ||
5613 | function deprecated() { | ||
5614 | if (!warned) { | ||
5615 | if (process.throwDeprecation) { | ||
5616 | throw new Error(msg); | ||
5617 | } else if (process.traceDeprecation) { | ||
5618 | console.trace(msg); | ||
5619 | } else { | ||
5620 | console.error(msg); | ||
5621 | } | ||
5622 | warned = true; | ||
5623 | } | ||
5624 | return fn.apply(this, arguments); | ||
5625 | } | ||
5626 | |||
5627 | return deprecated; | ||
5628 | }; | ||
5629 | |||
5630 | |||
5631 | var debugs = {}; | ||
5632 | var debugEnviron; | ||
5633 | exports.debuglog = function(set) { | ||
5634 | if (isUndefined(debugEnviron)) | ||
5635 | debugEnviron = process.env.NODE_DEBUG || ''; | ||
5636 | set = set.toUpperCase(); | ||
5637 | if (!debugs[set]) { | ||
5638 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { | ||
5639 | var pid = process.pid; | ||
5640 | debugs[set] = function() { | ||
5641 | var msg = exports.format.apply(exports, arguments); | ||
5642 | console.error('%s %d: %s', set, pid, msg); | ||
5643 | }; | ||
5644 | } else { | ||
5645 | debugs[set] = function() {}; | ||
5646 | } | ||
5647 | } | ||
5648 | return debugs[set]; | ||
5649 | }; | ||
5650 | |||
5651 | |||
5652 | /** | ||
5653 | * Echos the value of a value. Trys to print the value out | ||
5654 | * in the best way possible given the different types. | ||
5655 | * | ||
5656 | * @param {Object} obj The object to print out. | ||
5657 | * @param {Object} opts Optional options object that alters the output. | ||
5658 | */ | ||
5659 | /* legacy: obj, showHidden, depth, colors*/ | ||
5660 | function inspect(obj, opts) { | ||
5661 | // default options | ||
5662 | var ctx = { | ||
5663 | seen: [], | ||
5664 | stylize: stylizeNoColor | ||
5665 | }; | ||
5666 | // legacy... | ||
5667 | if (arguments.length >= 3) ctx.depth = arguments[2]; | ||
5668 | if (arguments.length >= 4) ctx.colors = arguments[3]; | ||
5669 | if (isBoolean(opts)) { | ||
5670 | // legacy... | ||
5671 | ctx.showHidden = opts; | ||
5672 | } else if (opts) { | ||
5673 | // got an "options" object | ||
5674 | exports._extend(ctx, opts); | ||
5675 | } | ||
5676 | // set default options | ||
5677 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false; | ||
5678 | if (isUndefined(ctx.depth)) ctx.depth = 2; | ||
5679 | if (isUndefined(ctx.colors)) ctx.colors = false; | ||
5680 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true; | ||
5681 | if (ctx.colors) ctx.stylize = stylizeWithColor; | ||
5682 | return formatValue(ctx, obj, ctx.depth); | ||
5683 | } | ||
5684 | exports.inspect = inspect; | ||
5685 | |||
5686 | |||
5687 | // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics | ||
5688 | inspect.colors = { | ||
5689 | 'bold' : [1, 22], | ||
5690 | 'italic' : [3, 23], | ||
5691 | 'underline' : [4, 24], | ||
5692 | 'inverse' : [7, 27], | ||
5693 | 'white' : [37, 39], | ||
5694 | 'grey' : [90, 39], | ||
5695 | 'black' : [30, 39], | ||
5696 | 'blue' : [34, 39], | ||
5697 | 'cyan' : [36, 39], | ||
5698 | 'green' : [32, 39], | ||
5699 | 'magenta' : [35, 39], | ||
5700 | 'red' : [31, 39], | ||
5701 | 'yellow' : [33, 39] | ||
5702 | }; | ||
5703 | |||
5704 | // Don't use 'blue' not visible on cmd.exe | ||
5705 | inspect.styles = { | ||
5706 | 'special': 'cyan', | ||
5707 | 'number': 'yellow', | ||
5708 | 'boolean': 'yellow', | ||
5709 | 'undefined': 'grey', | ||
5710 | 'null': 'bold', | ||
5711 | 'string': 'green', | ||
5712 | 'date': 'magenta', | ||
5713 | // "name": intentionally not styling | ||
5714 | 'regexp': 'red' | ||
5715 | }; | ||
5716 | |||
5717 | |||
5718 | function stylizeWithColor(str, styleType) { | ||
5719 | var style = inspect.styles[styleType]; | ||
5720 | |||
5721 | if (style) { | ||
5722 | return '\u001b[' + inspect.colors[style][0] + 'm' + str + | ||
5723 | '\u001b[' + inspect.colors[style][1] + 'm'; | ||
5724 | } else { | ||
5725 | return str; | ||
5726 | } | ||
5727 | } | ||
5728 | |||
5729 | |||
5730 | function stylizeNoColor(str, styleType) { | ||
5731 | return str; | ||
5732 | } | ||
5733 | |||
5734 | |||
5735 | function arrayToHash(array) { | ||
5736 | var hash = {}; | ||
5737 | |||
5738 | array.forEach(function(val, idx) { | ||
5739 | hash[val] = true; | ||
5740 | }); | ||
5741 | |||
5742 | return hash; | ||
5743 | } | ||
5744 | |||
5745 | |||
5746 | function formatValue(ctx, value, recurseTimes) { | ||
5747 | // Provide a hook for user-specified inspect functions. | ||
5748 | // Check that value is an object with an inspect function on it | ||
5749 | if (ctx.customInspect && | ||
5750 | value && | ||
5751 | isFunction(value.inspect) && | ||
5752 | // Filter out the util module, it's inspect function is special | ||
5753 | value.inspect !== exports.inspect && | ||
5754 | // Also filter out any prototype objects using the circular check. | ||
5755 | !(value.constructor && value.constructor.prototype === value)) { | ||
5756 | var ret = value.inspect(recurseTimes, ctx); | ||
5757 | if (!isString(ret)) { | ||
5758 | ret = formatValue(ctx, ret, recurseTimes); | ||
5759 | } | ||
5760 | return ret; | ||
5761 | } | ||
5762 | |||
5763 | // Primitive types cannot have properties | ||
5764 | var primitive = formatPrimitive(ctx, value); | ||
5765 | if (primitive) { | ||
5766 | return primitive; | ||
5767 | } | ||
5768 | |||
5769 | // Look up the keys of the object. | ||
5770 | var keys = Object.keys(value); | ||
5771 | var visibleKeys = arrayToHash(keys); | ||
5772 | |||
5773 | if (ctx.showHidden) { | ||
5774 | keys = Object.getOwnPropertyNames(value); | ||
5775 | } | ||
5776 | |||
5777 | // IE doesn't make error fields non-enumerable | ||
5778 | // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx | ||
5779 | if (isError(value) | ||
5780 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { | ||
5781 | return formatError(value); | ||
5782 | } | ||
5783 | |||
5784 | // Some type of object without properties can be shortcutted. | ||
5785 | if (keys.length === 0) { | ||
5786 | if (isFunction(value)) { | ||
5787 | var name = value.name ? ': ' + value.name : ''; | ||
5788 | return ctx.stylize('[Function' + name + ']', 'special'); | ||
5789 | } | ||
5790 | if (isRegExp(value)) { | ||
5791 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | ||
5792 | } | ||
5793 | if (isDate(value)) { | ||
5794 | return ctx.stylize(Date.prototype.toString.call(value), 'date'); | ||
5795 | } | ||
5796 | if (isError(value)) { | ||
5797 | return formatError(value); | ||
5798 | } | ||
5799 | } | ||
5800 | |||
5801 | var base = '', array = false, braces = ['{', '}']; | ||
5802 | |||
5803 | // Make Array say that they are Array | ||
5804 | if (isArray(value)) { | ||
5805 | array = true; | ||
5806 | braces = ['[', ']']; | ||
5807 | } | ||
5808 | |||
5809 | // Make functions say that they are functions | ||
5810 | if (isFunction(value)) { | ||
5811 | var n = value.name ? ': ' + value.name : ''; | ||
5812 | base = ' [Function' + n + ']'; | ||
5813 | } | ||
5814 | |||
5815 | // Make RegExps say that they are RegExps | ||
5816 | if (isRegExp(value)) { | ||
5817 | base = ' ' + RegExp.prototype.toString.call(value); | ||
5818 | } | ||
5819 | |||
5820 | // Make dates with properties first say the date | ||
5821 | if (isDate(value)) { | ||
5822 | base = ' ' + Date.prototype.toUTCString.call(value); | ||
5823 | } | ||
5824 | |||
5825 | // Make error with message first say the error | ||
5826 | if (isError(value)) { | ||
5827 | base = ' ' + formatError(value); | ||
5828 | } | ||
5829 | |||
5830 | if (keys.length === 0 && (!array || value.length == 0)) { | ||
5831 | return braces[0] + base + braces[1]; | ||
5832 | } | ||
5833 | |||
5834 | if (recurseTimes < 0) { | ||
5835 | if (isRegExp(value)) { | ||
5836 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | ||
5837 | } else { | ||
5838 | return ctx.stylize('[Object]', 'special'); | ||
5839 | } | ||
5840 | } | ||
5841 | |||
5842 | ctx.seen.push(value); | ||
5843 | |||
5844 | var output; | ||
5845 | if (array) { | ||
5846 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); | ||
5847 | } else { | ||
5848 | output = keys.map(function(key) { | ||
5849 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); | ||
5850 | }); | ||
5851 | } | ||
5852 | |||
5853 | ctx.seen.pop(); | ||
5854 | |||
5855 | return reduceToSingleString(output, base, braces); | ||
5856 | } | ||
5857 | |||
5858 | |||
5859 | function formatPrimitive(ctx, value) { | ||
5860 | if (isUndefined(value)) | ||
5861 | return ctx.stylize('undefined', 'undefined'); | ||
5862 | if (isString(value)) { | ||
5863 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | ||
5864 | .replace(/'/g, "\\'") | ||
5865 | .replace(/\\"/g, '"') + '\''; | ||
5866 | return ctx.stylize(simple, 'string'); | ||
5867 | } | ||
5868 | if (isNumber(value)) | ||
5869 | return ctx.stylize('' + value, 'number'); | ||
5870 | if (isBoolean(value)) | ||
5871 | return ctx.stylize('' + value, 'boolean'); | ||
5872 | // For some reason typeof null is "object", so special case here. | ||
5873 | if (isNull(value)) | ||
5874 | return ctx.stylize('null', 'null'); | ||
5875 | } | ||
5876 | |||
5877 | |||
5878 | function formatError(value) { | ||
5879 | return '[' + Error.prototype.toString.call(value) + ']'; | ||
5880 | } | ||
5881 | |||
5882 | |||
5883 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { | ||
5884 | var output = []; | ||
5885 | for (var i = 0, l = value.length; i < l; ++i) { | ||
5886 | if (hasOwnProperty(value, String(i))) { | ||
5887 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | ||
5888 | String(i), true)); | ||
5889 | } else { | ||
5890 | output.push(''); | ||
5891 | } | ||
5892 | } | ||
5893 | keys.forEach(function(key) { | ||
5894 | if (!key.match(/^\d+$/)) { | ||
5895 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | ||
5896 | key, true)); | ||
5897 | } | ||
5898 | }); | ||
5899 | return output; | ||
5900 | } | ||
5901 | |||
5902 | |||
5903 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { | ||
5904 | var name, str, desc; | ||
5905 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; | ||
5906 | if (desc.get) { | ||
5907 | if (desc.set) { | ||
5908 | str = ctx.stylize('[Getter/Setter]', 'special'); | ||
5909 | } else { | ||
5910 | str = ctx.stylize('[Getter]', 'special'); | ||
5911 | } | ||
5912 | } else { | ||
5913 | if (desc.set) { | ||
5914 | str = ctx.stylize('[Setter]', 'special'); | ||
5915 | } | ||
5916 | } | ||
5917 | if (!hasOwnProperty(visibleKeys, key)) { | ||
5918 | name = '[' + key + ']'; | ||
5919 | } | ||
5920 | if (!str) { | ||
5921 | if (ctx.seen.indexOf(desc.value) < 0) { | ||
5922 | if (isNull(recurseTimes)) { | ||
5923 | str = formatValue(ctx, desc.value, null); | ||
5924 | } else { | ||
5925 | str = formatValue(ctx, desc.value, recurseTimes - 1); | ||
5926 | } | ||
5927 | if (str.indexOf('\n') > -1) { | ||
5928 | if (array) { | ||
5929 | str = str.split('\n').map(function(line) { | ||
5930 | return ' ' + line; | ||
5931 | }).join('\n').substr(2); | ||
5932 | } else { | ||
5933 | str = '\n' + str.split('\n').map(function(line) { | ||
5934 | return ' ' + line; | ||
5935 | }).join('\n'); | ||
5936 | } | ||
5937 | } | ||
5938 | } else { | ||
5939 | str = ctx.stylize('[Circular]', 'special'); | ||
5940 | } | ||
5941 | } | ||
5942 | if (isUndefined(name)) { | ||
5943 | if (array && key.match(/^\d+$/)) { | ||
5944 | return str; | ||
5945 | } | ||
5946 | name = JSON.stringify('' + key); | ||
5947 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { | ||
5948 | name = name.substr(1, name.length - 2); | ||
5949 | name = ctx.stylize(name, 'name'); | ||
5950 | } else { | ||
5951 | name = name.replace(/'/g, "\\'") | ||
5952 | .replace(/\\"/g, '"') | ||
5953 | .replace(/(^"|"$)/g, "'"); | ||
5954 | name = ctx.stylize(name, 'string'); | ||
5955 | } | ||
5956 | } | ||
5957 | |||
5958 | return name + ': ' + str; | ||
5959 | } | ||
5960 | |||
5961 | |||
5962 | function reduceToSingleString(output, base, braces) { | ||
5963 | var numLinesEst = 0; | ||
5964 | var length = output.reduce(function(prev, cur) { | ||
5965 | numLinesEst++; | ||
5966 | if (cur.indexOf('\n') >= 0) numLinesEst++; | ||
5967 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; | ||
5968 | }, 0); | ||
5969 | |||
5970 | if (length > 60) { | ||
5971 | return braces[0] + | ||
5972 | (base === '' ? '' : base + '\n ') + | ||
5973 | ' ' + | ||
5974 | output.join(',\n ') + | ||
5975 | ' ' + | ||
5976 | braces[1]; | ||
5977 | } | ||
5978 | |||
5979 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; | ||
5980 | } | ||
5981 | |||
5982 | |||
5983 | // NOTE: These type checking functions intentionally don't use `instanceof` | ||
5984 | // because it is fragile and can be easily faked with `Object.create()`. | ||
5985 | function isArray(ar) { | ||
5986 | return Array.isArray(ar); | ||
5987 | } | ||
5988 | exports.isArray = isArray; | ||
5989 | |||
5990 | function isBoolean(arg) { | ||
5991 | return typeof arg === 'boolean'; | ||
5992 | } | ||
5993 | exports.isBoolean = isBoolean; | ||
5994 | |||
5995 | function isNull(arg) { | ||
5996 | return arg === null; | ||
5997 | } | ||
5998 | exports.isNull = isNull; | ||
5999 | |||
6000 | function isNullOrUndefined(arg) { | ||
6001 | return arg == null; | ||
6002 | } | ||
6003 | exports.isNullOrUndefined = isNullOrUndefined; | ||
6004 | |||
6005 | function isNumber(arg) { | ||
6006 | return typeof arg === 'number'; | ||
6007 | } | ||
6008 | exports.isNumber = isNumber; | ||
6009 | |||
6010 | function isString(arg) { | ||
6011 | return typeof arg === 'string'; | ||
6012 | } | ||
6013 | exports.isString = isString; | ||
6014 | |||
6015 | function isSymbol(arg) { | ||
6016 | return typeof arg === 'symbol'; | ||
6017 | } | ||
6018 | exports.isSymbol = isSymbol; | ||
6019 | |||
6020 | function isUndefined(arg) { | ||
6021 | return arg === void 0; | ||
6022 | } | ||
6023 | exports.isUndefined = isUndefined; | ||
6024 | |||
6025 | function isRegExp(re) { | ||
6026 | return isObject(re) && objectToString(re) === '[object RegExp]'; | ||
6027 | } | ||
6028 | exports.isRegExp = isRegExp; | ||
6029 | |||
6030 | function isObject(arg) { | ||
6031 | return typeof arg === 'object' && arg !== null; | ||
6032 | } | ||
6033 | exports.isObject = isObject; | ||
6034 | |||
6035 | function isDate(d) { | ||
6036 | return isObject(d) && objectToString(d) === '[object Date]'; | ||
6037 | } | ||
6038 | exports.isDate = isDate; | ||
6039 | |||
6040 | function isError(e) { | ||
6041 | return isObject(e) && | ||
6042 | (objectToString(e) === '[object Error]' || e instanceof Error); | ||
6043 | } | ||
6044 | exports.isError = isError; | ||
6045 | |||
6046 | function isFunction(arg) { | ||
6047 | return typeof arg === 'function'; | ||
6048 | } | ||
6049 | exports.isFunction = isFunction; | ||
6050 | |||
6051 | function isPrimitive(arg) { | ||
6052 | return arg === null || | ||
6053 | typeof arg === 'boolean' || | ||
6054 | typeof arg === 'number' || | ||
6055 | typeof arg === 'string' || | ||
6056 | typeof arg === 'symbol' || // ES6 symbol | ||
6057 | typeof arg === 'undefined'; | ||
6058 | } | ||
6059 | exports.isPrimitive = isPrimitive; | ||
6060 | |||
6061 | exports.isBuffer = require('./support/isBuffer'); | ||
6062 | |||
6063 | function objectToString(o) { | ||
6064 | return Object.prototype.toString.call(o); | ||
6065 | } | ||
6066 | |||
6067 | |||
6068 | function pad(n) { | ||
6069 | return n < 10 ? '0' + n.toString(10) : n.toString(10); | ||
6070 | } | ||
6071 | |||
6072 | |||
6073 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', | ||
6074 | 'Oct', 'Nov', 'Dec']; | ||
6075 | |||
6076 | // 26 Feb 16:19:34 | ||
6077 | function timestamp() { | ||
6078 | var d = new Date(); | ||
6079 | var time = [pad(d.getHours()), | ||
6080 | pad(d.getMinutes()), | ||
6081 | pad(d.getSeconds())].join(':'); | ||
6082 | return [d.getDate(), months[d.getMonth()], time].join(' '); | ||
6083 | } | ||
6084 | |||
6085 | |||
6086 | // log is just a thin wrapper to console.log that prepends a timestamp | ||
6087 | exports.log = function() { | ||
6088 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); | ||
6089 | }; | ||
6090 | |||
6091 | |||
6092 | /** | ||
6093 | * Inherit the prototype methods from one constructor into another. | ||
6094 | * | ||
6095 | * The Function.prototype.inherits from lang.js rewritten as a standalone | ||
6096 | * function (not on Function.prototype). NOTE: If this file is to be loaded | ||
6097 | * during bootstrapping this function needs to be rewritten using some native | ||
6098 | * functions as prototype setup using normal JavaScript does not work as | ||
6099 | * expected during bootstrapping (see mirror.js in r114903). | ||
6100 | * | ||
6101 | * @param {function} ctor Constructor function which needs to inherit the | ||
6102 | * prototype. | ||
6103 | * @param {function} superCtor Constructor function to inherit prototype from. | ||
6104 | */ | ||
6105 | exports.inherits = require('inherits'); | ||
6106 | |||
6107 | exports._extend = function(origin, add) { | ||
6108 | // Don't do anything if add isn't an object | ||
6109 | if (!add || !isObject(add)) return origin; | ||
6110 | |||
6111 | var keys = Object.keys(add); | ||
6112 | var i = keys.length; | ||
6113 | while (i--) { | ||
6114 | origin[keys[i]] = add[keys[i]]; | ||
6115 | } | ||
6116 | return origin; | ||
6117 | }; | ||
6118 | |||
6119 | function hasOwnProperty(obj, prop) { | ||
6120 | return Object.prototype.hasOwnProperty.call(obj, prop); | ||
6121 | } | ||
6122 | |||
6123 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
6124 | },{"./support/isBuffer":29,"_process":13,"inherits":28}],31:[function(require,module,exports){ | ||
6125 | (function (Buffer){ | ||
6126 | const createKeccakHash = require('keccak') | ||
6127 | const secp256k1 = require('secp256k1') | ||
6128 | const assert = require('assert') | ||
6129 | const rlp = require('rlp') | ||
6130 | const BN = require('bn.js') | ||
6131 | const createHash = require('create-hash') | ||
6132 | Object.assign(exports, require('ethjs-util')) | ||
6133 | |||
6134 | /** | ||
6135 | * the max integer that this VM can handle (a ```BN```) | ||
6136 | * @var {BN} MAX_INTEGER | ||
6137 | */ | ||
6138 | exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16) | ||
6139 | |||
6140 | /** | ||
6141 | * 2^256 (a ```BN```) | ||
6142 | * @var {BN} TWO_POW256 | ||
6143 | */ | ||
6144 | exports.TWO_POW256 = new BN('10000000000000000000000000000000000000000000000000000000000000000', 16) | ||
6145 | |||
6146 | /** | ||
6147 | * SHA3-256 hash of null (a ```String```) | ||
6148 | * @var {String} SHA3_NULL_S | ||
6149 | */ | ||
6150 | exports.SHA3_NULL_S = 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' | ||
6151 | |||
6152 | /** | ||
6153 | * SHA3-256 hash of null (a ```Buffer```) | ||
6154 | * @var {Buffer} SHA3_NULL | ||
6155 | */ | ||
6156 | exports.SHA3_NULL = Buffer.from(exports.SHA3_NULL_S, 'hex') | ||
6157 | |||
6158 | /** | ||
6159 | * SHA3-256 of an RLP of an empty array (a ```String```) | ||
6160 | * @var {String} SHA3_RLP_ARRAY_S | ||
6161 | */ | ||
6162 | exports.SHA3_RLP_ARRAY_S = '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347' | ||
6163 | |||
6164 | /** | ||
6165 | * SHA3-256 of an RLP of an empty array (a ```Buffer```) | ||
6166 | * @var {Buffer} SHA3_RLP_ARRAY | ||
6167 | */ | ||
6168 | exports.SHA3_RLP_ARRAY = Buffer.from(exports.SHA3_RLP_ARRAY_S, 'hex') | ||
6169 | |||
6170 | /** | ||
6171 | * SHA3-256 hash of the RLP of null (a ```String```) | ||
6172 | * @var {String} SHA3_RLP_S | ||
6173 | */ | ||
6174 | exports.SHA3_RLP_S = '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421' | ||
6175 | |||
6176 | /** | ||
6177 | * SHA3-256 hash of the RLP of null (a ```Buffer```) | ||
6178 | * @var {Buffer} SHA3_RLP | ||
6179 | */ | ||
6180 | exports.SHA3_RLP = Buffer.from(exports.SHA3_RLP_S, 'hex') | ||
6181 | |||
6182 | /** | ||
6183 | * [`BN`](https://github.com/indutny/bn.js) | ||
6184 | * @var {Function} | ||
6185 | */ | ||
6186 | exports.BN = BN | ||
6187 | |||
6188 | /** | ||
6189 | * [`rlp`](https://github.com/ethereumjs/rlp) | ||
6190 | * @var {Function} | ||
6191 | */ | ||
6192 | exports.rlp = rlp | ||
6193 | |||
6194 | /** | ||
6195 | * [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) | ||
6196 | * @var {Object} | ||
6197 | */ | ||
6198 | exports.secp256k1 = secp256k1 | ||
6199 | |||
6200 | /** | ||
6201 | * Returns a buffer filled with 0s | ||
6202 | * @method zeros | ||
6203 | * @param {Number} bytes the number of bytes the buffer should be | ||
6204 | * @return {Buffer} | ||
6205 | */ | ||
6206 | exports.zeros = function (bytes) { | ||
6207 | return Buffer.allocUnsafe(bytes).fill(0) | ||
6208 | } | ||
6209 | |||
6210 | /** | ||
6211 | * Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. | ||
6212 | * Or it truncates the beginning if it exceeds. | ||
6213 | * @method lsetLength | ||
6214 | * @param {Buffer|Array} msg the value to pad | ||
6215 | * @param {Number} length the number of bytes the output should be | ||
6216 | * @param {Boolean} [right=false] whether to start padding form the left or right | ||
6217 | * @return {Buffer|Array} | ||
6218 | */ | ||
6219 | exports.setLengthLeft = exports.setLength = function (msg, length, right) { | ||
6220 | var buf = exports.zeros(length) | ||
6221 | msg = exports.toBuffer(msg) | ||
6222 | if (right) { | ||
6223 | if (msg.length < length) { | ||
6224 | msg.copy(buf) | ||
6225 | return buf | ||
6226 | } | ||
6227 | return msg.slice(0, length) | ||
6228 | } else { | ||
6229 | if (msg.length < length) { | ||
6230 | msg.copy(buf, length - msg.length) | ||
6231 | return buf | ||
6232 | } | ||
6233 | return msg.slice(-length) | ||
6234 | } | ||
6235 | } | ||
6236 | |||
6237 | /** | ||
6238 | * Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. | ||
6239 | * Or it truncates the beginning if it exceeds. | ||
6240 | * @param {Buffer|Array} msg the value to pad | ||
6241 | * @param {Number} length the number of bytes the output should be | ||
6242 | * @return {Buffer|Array} | ||
6243 | */ | ||
6244 | exports.setLengthRight = function (msg, length) { | ||
6245 | return exports.setLength(msg, length, true) | ||
6246 | } | ||
6247 | |||
6248 | /** | ||
6249 | * Trims leading zeros from a `Buffer` or an `Array` | ||
6250 | * @param {Buffer|Array|String} a | ||
6251 | * @return {Buffer|Array|String} | ||
6252 | */ | ||
6253 | exports.unpad = exports.stripZeros = function (a) { | ||
6254 | a = exports.stripHexPrefix(a) | ||
6255 | var first = a[0] | ||
6256 | while (a.length > 0 && first.toString() === '0') { | ||
6257 | a = a.slice(1) | ||
6258 | first = a[0] | ||
6259 | } | ||
6260 | return a | ||
6261 | } | ||
6262 | /** | ||
6263 | * 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. | ||
6264 | * @param {*} v the value | ||
6265 | */ | ||
6266 | exports.toBuffer = function (v) { | ||
6267 | if (!Buffer.isBuffer(v)) { | ||
6268 | if (Array.isArray(v)) { | ||
6269 | v = Buffer.from(v) | ||
6270 | } else if (typeof v === 'string') { | ||
6271 | if (exports.isHexPrefixed(v)) { | ||
6272 | v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), 'hex') | ||
6273 | } else { | ||
6274 | v = Buffer.from(v) | ||
6275 | } | ||
6276 | } else if (typeof v === 'number') { | ||
6277 | v = exports.intToBuffer(v) | ||
6278 | } else if (v === null || v === undefined) { | ||
6279 | v = Buffer.allocUnsafe(0) | ||
6280 | } else if (v.toArray) { | ||
6281 | // converts a BN to a Buffer | ||
6282 | v = Buffer.from(v.toArray()) | ||
6283 | } else { | ||
6284 | throw new Error('invalid type') | ||
6285 | } | ||
6286 | } | ||
6287 | return v | ||
6288 | } | ||
6289 | |||
6290 | /** | ||
6291 | * Converts a `Buffer` to a `Number` | ||
6292 | * @param {Buffer} buf | ||
6293 | * @return {Number} | ||
6294 | * @throws If the input number exceeds 53 bits. | ||
6295 | */ | ||
6296 | exports.bufferToInt = function (buf) { | ||
6297 | return new BN(exports.toBuffer(buf)).toNumber() | ||
6298 | } | ||
6299 | |||
6300 | /** | ||
6301 | * Converts a `Buffer` into a hex `String` | ||
6302 | * @param {Buffer} buf | ||
6303 | * @return {String} | ||
6304 | */ | ||
6305 | exports.bufferToHex = function (buf) { | ||
6306 | buf = exports.toBuffer(buf) | ||
6307 | return '0x' + buf.toString('hex') | ||
6308 | } | ||
6309 | |||
6310 | /** | ||
6311 | * Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers. | ||
6312 | * @param {Buffer} num | ||
6313 | * @return {BN} | ||
6314 | */ | ||
6315 | exports.fromSigned = function (num) { | ||
6316 | return new BN(num).fromTwos(256) | ||
6317 | } | ||
6318 | |||
6319 | /** | ||
6320 | * Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers. | ||
6321 | * @param {BN} num | ||
6322 | * @return {Buffer} | ||
6323 | */ | ||
6324 | exports.toUnsigned = function (num) { | ||
6325 | return Buffer.from(num.toTwos(256).toArray()) | ||
6326 | } | ||
6327 | |||
6328 | /** | ||
6329 | * Creates SHA-3 hash of the input | ||
6330 | * @param {Buffer|Array|String|Number} a the input data | ||
6331 | * @param {Number} [bits=256] the SHA width | ||
6332 | * @return {Buffer} | ||
6333 | */ | ||
6334 | exports.sha3 = function (a, bits) { | ||
6335 | a = exports.toBuffer(a) | ||
6336 | if (!bits) bits = 256 | ||
6337 | |||
6338 | return createKeccakHash('keccak' + bits).update(a).digest() | ||
6339 | } | ||
6340 | |||
6341 | /** | ||
6342 | * Creates SHA256 hash of the input | ||
6343 | * @param {Buffer|Array|String|Number} a the input data | ||
6344 | * @return {Buffer} | ||
6345 | */ | ||
6346 | exports.sha256 = function (a) { | ||
6347 | a = exports.toBuffer(a) | ||
6348 | return createHash('sha256').update(a).digest() | ||
6349 | } | ||
6350 | |||
6351 | /** | ||
6352 | * Creates RIPEMD160 hash of the input | ||
6353 | * @param {Buffer|Array|String|Number} a the input data | ||
6354 | * @param {Boolean} padded whether it should be padded to 256 bits or not | ||
6355 | * @return {Buffer} | ||
6356 | */ | ||
6357 | exports.ripemd160 = function (a, padded) { | ||
6358 | a = exports.toBuffer(a) | ||
6359 | var hash = createHash('rmd160').update(a).digest() | ||
6360 | if (padded === true) { | ||
6361 | return exports.setLength(hash, 32) | ||
6362 | } else { | ||
6363 | return hash | ||
6364 | } | ||
6365 | } | ||
6366 | |||
6367 | /** | ||
6368 | * Creates SHA-3 hash of the RLP encoded version of the input | ||
6369 | * @param {Buffer|Array|String|Number} a the input data | ||
6370 | * @return {Buffer} | ||
6371 | */ | ||
6372 | exports.rlphash = function (a) { | ||
6373 | return exports.sha3(rlp.encode(a)) | ||
6374 | } | ||
6375 | |||
6376 | /** | ||
6377 | * Checks if the private key satisfies the rules of the curve secp256k1. | ||
6378 | * @param {Buffer} privateKey | ||
6379 | * @return {Boolean} | ||
6380 | */ | ||
6381 | exports.isValidPrivate = function (privateKey) { | ||
6382 | return secp256k1.privateKeyVerify(privateKey) | ||
6383 | } | ||
6384 | |||
6385 | /** | ||
6386 | * Checks if the public key satisfies the rules of the curve secp256k1 | ||
6387 | * and the requirements of Ethereum. | ||
6388 | * @param {Buffer} publicKey The two points of an uncompressed key, unless sanitize is enabled | ||
6389 | * @param {Boolean} [sanitize=false] Accept public keys in other formats | ||
6390 | * @return {Boolean} | ||
6391 | */ | ||
6392 | exports.isValidPublic = function (publicKey, sanitize) { | ||
6393 | if (publicKey.length === 64) { | ||
6394 | // Convert to SEC1 for secp256k1 | ||
6395 | return secp256k1.publicKeyVerify(Buffer.concat([ Buffer.from([4]), publicKey ])) | ||
6396 | } | ||
6397 | |||
6398 | if (!sanitize) { | ||
6399 | return false | ||
6400 | } | ||
6401 | |||
6402 | return secp256k1.publicKeyVerify(publicKey) | ||
6403 | } | ||
6404 | |||
6405 | /** | ||
6406 | * Returns the ethereum address of a given public key. | ||
6407 | * Accepts "Ethereum public keys" and SEC1 encoded keys. | ||
6408 | * @param {Buffer} pubKey The two points of an uncompressed key, unless sanitize is enabled | ||
6409 | * @param {Boolean} [sanitize=false] Accept public keys in other formats | ||
6410 | * @return {Buffer} | ||
6411 | */ | ||
6412 | exports.pubToAddress = exports.publicToAddress = function (pubKey, sanitize) { | ||
6413 | pubKey = exports.toBuffer(pubKey) | ||
6414 | if (sanitize && (pubKey.length !== 64)) { | ||
6415 | pubKey = secp256k1.publicKeyConvert(pubKey, false).slice(1) | ||
6416 | } | ||
6417 | assert(pubKey.length === 64) | ||
6418 | // Only take the lower 160bits of the hash | ||
6419 | return exports.sha3(pubKey).slice(-20) | ||
6420 | } | ||
6421 | |||
6422 | /** | ||
6423 | * Returns the ethereum public key of a given private key | ||
6424 | * @param {Buffer} privateKey A private key must be 256 bits wide | ||
6425 | * @return {Buffer} | ||
6426 | */ | ||
6427 | var privateToPublic = exports.privateToPublic = function (privateKey) { | ||
6428 | privateKey = exports.toBuffer(privateKey) | ||
6429 | // skip the type flag and use the X, Y points | ||
6430 | return secp256k1.publicKeyCreate(privateKey, false).slice(1) | ||
6431 | } | ||
6432 | |||
6433 | /** | ||
6434 | * Converts a public key to the Ethereum format. | ||
6435 | * @param {Buffer} publicKey | ||
6436 | * @return {Buffer} | ||
6437 | */ | ||
6438 | exports.importPublic = function (publicKey) { | ||
6439 | publicKey = exports.toBuffer(publicKey) | ||
6440 | if (publicKey.length !== 64) { | ||
6441 | publicKey = secp256k1.publicKeyConvert(publicKey, false).slice(1) | ||
6442 | } | ||
6443 | return publicKey | ||
6444 | } | ||
6445 | |||
6446 | /** | ||
6447 | * ECDSA sign | ||
6448 | * @param {Buffer} msgHash | ||
6449 | * @param {Buffer} privateKey | ||
6450 | * @return {Object} | ||
6451 | */ | ||
6452 | exports.ecsign = function (msgHash, privateKey) { | ||
6453 | var sig = secp256k1.sign(msgHash, privateKey) | ||
6454 | |||
6455 | var ret = {} | ||
6456 | ret.r = sig.signature.slice(0, 32) | ||
6457 | ret.s = sig.signature.slice(32, 64) | ||
6458 | ret.v = sig.recovery + 27 | ||
6459 | return ret | ||
6460 | } | ||
6461 | |||
6462 | /** | ||
6463 | * Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call. | ||
6464 | * The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign` | ||
6465 | * call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key | ||
6466 | * used to produce the signature. | ||
6467 | * @param message | ||
6468 | * @returns {Buffer} hash | ||
6469 | */ | ||
6470 | exports.hashPersonalMessage = function (message) { | ||
6471 | var prefix = exports.toBuffer('\u0019Ethereum Signed Message:\n' + message.length.toString()) | ||
6472 | return exports.sha3(Buffer.concat([prefix, message])) | ||
6473 | } | ||
6474 | |||
6475 | /** | ||
6476 | * ECDSA public key recovery from signature | ||
6477 | * @param {Buffer} msgHash | ||
6478 | * @param {Number} v | ||
6479 | * @param {Buffer} r | ||
6480 | * @param {Buffer} s | ||
6481 | * @return {Buffer} publicKey | ||
6482 | */ | ||
6483 | exports.ecrecover = function (msgHash, v, r, s) { | ||
6484 | var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64) | ||
6485 | var recovery = v - 27 | ||
6486 | if (recovery !== 0 && recovery !== 1) { | ||
6487 | throw new Error('Invalid signature v value') | ||
6488 | } | ||
6489 | var senderPubKey = secp256k1.recover(msgHash, signature, recovery) | ||
6490 | return secp256k1.publicKeyConvert(senderPubKey, false).slice(1) | ||
6491 | } | ||
6492 | |||
6493 | /** | ||
6494 | * Convert signature parameters into the format of `eth_sign` RPC method | ||
6495 | * @param {Number} v | ||
6496 | * @param {Buffer} r | ||
6497 | * @param {Buffer} s | ||
6498 | * @return {String} sig | ||
6499 | */ | ||
6500 | exports.toRpcSig = function (v, r, s) { | ||
6501 | // NOTE: with potential introduction of chainId this might need to be updated | ||
6502 | if (v !== 27 && v !== 28) { | ||
6503 | throw new Error('Invalid recovery id') | ||
6504 | } | ||
6505 | |||
6506 | // geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin | ||
6507 | // FIXME: this might change in the future - https://github.com/ethereum/go-ethereum/issues/2053 | ||
6508 | return exports.bufferToHex(Buffer.concat([ | ||
6509 | exports.setLengthLeft(r, 32), | ||
6510 | exports.setLengthLeft(s, 32), | ||
6511 | exports.toBuffer(v - 27) | ||
6512 | ])) | ||
6513 | } | ||
6514 | |||
6515 | /** | ||
6516 | * Convert signature format of the `eth_sign` RPC method to signature parameters | ||
6517 | * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053 | ||
6518 | * @param {String} sig | ||
6519 | * @return {Object} | ||
6520 | */ | ||
6521 | exports.fromRpcSig = function (sig) { | ||
6522 | sig = exports.toBuffer(sig) | ||
6523 | |||
6524 | // NOTE: with potential introduction of chainId this might need to be updated | ||
6525 | if (sig.length !== 65) { | ||
6526 | throw new Error('Invalid signature length') | ||
6527 | } | ||
6528 | |||
6529 | var v = sig[64] | ||
6530 | // support both versions of `eth_sign` responses | ||
6531 | if (v < 27) { | ||
6532 | v += 27 | ||
6533 | } | ||
6534 | |||
6535 | return { | ||
6536 | v: v, | ||
6537 | r: sig.slice(0, 32), | ||
6538 | s: sig.slice(32, 64) | ||
6539 | } | ||
6540 | } | ||
6541 | |||
6542 | /** | ||
6543 | * Returns the ethereum address of a given private key | ||
6544 | * @param {Buffer} privateKey A private key must be 256 bits wide | ||
6545 | * @return {Buffer} | ||
6546 | */ | ||
6547 | exports.privateToAddress = function (privateKey) { | ||
6548 | return exports.publicToAddress(privateToPublic(privateKey)) | ||
6549 | } | ||
6550 | |||
6551 | /** | ||
6552 | * Checks if the address is a valid. Accepts checksummed addresses too | ||
6553 | * @param {String} address | ||
6554 | * @return {Boolean} | ||
6555 | */ | ||
6556 | exports.isValidAddress = function (address) { | ||
6557 | return /^0x[0-9a-fA-F]{40}$/i.test(address) | ||
6558 | } | ||
6559 | |||
6560 | /** | ||
6561 | * Returns a checksummed address | ||
6562 | * @param {String} address | ||
6563 | * @return {String} | ||
6564 | */ | ||
6565 | exports.toChecksumAddress = function (address) { | ||
6566 | address = exports.stripHexPrefix(address).toLowerCase() | ||
6567 | var hash = exports.sha3(address).toString('hex') | ||
6568 | var ret = '0x' | ||
6569 | |||
6570 | for (var i = 0; i < address.length; i++) { | ||
6571 | if (parseInt(hash[i], 16) >= 8) { | ||
6572 | ret += address[i].toUpperCase() | ||
6573 | } else { | ||
6574 | ret += address[i] | ||
6575 | } | ||
6576 | } | ||
6577 | |||
6578 | return ret | ||
6579 | } | ||
6580 | |||
6581 | /** | ||
6582 | * Checks if the address is a valid checksummed address | ||
6583 | * @param {Buffer} address | ||
6584 | * @return {Boolean} | ||
6585 | */ | ||
6586 | exports.isValidChecksumAddress = function (address) { | ||
6587 | return exports.isValidAddress(address) && (exports.toChecksumAddress(address) === address) | ||
6588 | } | ||
6589 | |||
6590 | /** | ||
6591 | * Generates an address of a newly created contract | ||
6592 | * @param {Buffer} from the address which is creating this new address | ||
6593 | * @param {Buffer} nonce the nonce of the from account | ||
6594 | * @return {Buffer} | ||
6595 | */ | ||
6596 | exports.generateAddress = function (from, nonce) { | ||
6597 | from = exports.toBuffer(from) | ||
6598 | nonce = new BN(nonce) | ||
6599 | |||
6600 | if (nonce.isZero()) { | ||
6601 | // in RLP we want to encode null in the case of zero nonce | ||
6602 | // read the RLP documentation for an answer if you dare | ||
6603 | nonce = null | ||
6604 | } else { | ||
6605 | nonce = Buffer.from(nonce.toArray()) | ||
6606 | } | ||
6607 | |||
6608 | // Only take the lower 160bits of the hash | ||
6609 | return exports.rlphash([from, nonce]).slice(-20) | ||
6610 | } | ||
6611 | |||
6612 | /** | ||
6613 | * Returns true if the supplied address belongs to a precompiled account | ||
6614 | * @param {Buffer|String} address | ||
6615 | * @return {Boolean} | ||
6616 | */ | ||
6617 | exports.isPrecompiled = function (address) { | ||
6618 | var a = exports.unpad(address) | ||
6619 | return a.length === 1 && a[0] > 0 && a[0] < 5 | ||
6620 | } | ||
6621 | |||
6622 | /** | ||
6623 | * Adds "0x" to a given `String` if it does not already start with "0x" | ||
6624 | * @param {String} str | ||
6625 | * @return {String} | ||
6626 | */ | ||
6627 | exports.addHexPrefix = function (str) { | ||
6628 | if (typeof str !== 'string') { | ||
6629 | return str | ||
6630 | } | ||
6631 | |||
6632 | return exports.isHexPrefixed(str) ? str : '0x' + str | ||
6633 | } | ||
6634 | |||
6635 | /** | ||
6636 | * Validate ECDSA signature | ||
6637 | * @method isValidSignature | ||
6638 | * @param {Buffer} v | ||
6639 | * @param {Buffer} r | ||
6640 | * @param {Buffer} s | ||
6641 | * @param {Boolean} [homestead=true] | ||
6642 | * @return {Boolean} | ||
6643 | */ | ||
6644 | |||
6645 | exports.isValidSignature = function (v, r, s, homestead) { | ||
6646 | const SECP256K1_N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16) | ||
6647 | const SECP256K1_N = new BN('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16) | ||
6648 | |||
6649 | if (r.length !== 32 || s.length !== 32) { | ||
6650 | return false | ||
6651 | } | ||
6652 | |||
6653 | if (v !== 27 && v !== 28) { | ||
6654 | return false | ||
6655 | } | ||
6656 | |||
6657 | r = new BN(r) | ||
6658 | s = new BN(s) | ||
6659 | |||
6660 | if (r.isZero() || r.gt(SECP256K1_N) || s.isZero() || s.gt(SECP256K1_N)) { | ||
6661 | return false | ||
6662 | } | ||
6663 | |||
6664 | if ((homestead === false) && (new BN(s).cmp(SECP256K1_N_DIV_2) === 1)) { | ||
6665 | return false | ||
6666 | } | ||
6667 | |||
6668 | return true | ||
6669 | } | ||
6670 | |||
6671 | /** | ||
6672 | * Converts a `Buffer` or `Array` to JSON | ||
6673 | * @param {Buffer|Array} ba | ||
6674 | * @return {Array|String|null} | ||
6675 | */ | ||
6676 | exports.baToJSON = function (ba) { | ||
6677 | if (Buffer.isBuffer(ba)) { | ||
6678 | return '0x' + ba.toString('hex') | ||
6679 | } else if (ba instanceof Array) { | ||
6680 | var array = [] | ||
6681 | for (var i = 0; i < ba.length; i++) { | ||
6682 | array.push(exports.baToJSON(ba[i])) | ||
6683 | } | ||
6684 | return array | ||
6685 | } | ||
6686 | } | ||
6687 | |||
6688 | /** | ||
6689 | * Defines properties on a `Object`. It make the assumption that underlying data is binary. | ||
6690 | * @param {Object} self the `Object` to define properties on | ||
6691 | * @param {Array} fields an array fields to define. Fields can contain: | ||
6692 | * * `name` - the name of the properties | ||
6693 | * * `length` - the number of bytes the field can have | ||
6694 | * * `allowLess` - if the field can be less than the length | ||
6695 | * * `allowEmpty` | ||
6696 | * @param {*} data data to be validated against the definitions | ||
6697 | */ | ||
6698 | exports.defineProperties = function (self, fields, data) { | ||
6699 | self.raw = [] | ||
6700 | self._fields = [] | ||
6701 | |||
6702 | // attach the `toJSON` | ||
6703 | self.toJSON = function (label) { | ||
6704 | if (label) { | ||
6705 | var obj = {} | ||
6706 | self._fields.forEach(function (field) { | ||
6707 | obj[field] = '0x' + self[field].toString('hex') | ||
6708 | }) | ||
6709 | return obj | ||
6710 | } | ||
6711 | return exports.baToJSON(this.raw) | ||
6712 | } | ||
6713 | |||
6714 | self.serialize = function serialize () { | ||
6715 | return rlp.encode(self.raw) | ||
6716 | } | ||
6717 | |||
6718 | fields.forEach(function (field, i) { | ||
6719 | self._fields.push(field.name) | ||
6720 | function getter () { | ||
6721 | return self.raw[i] | ||
6722 | } | ||
6723 | function setter (v) { | ||
6724 | v = exports.toBuffer(v) | ||
6725 | |||
6726 | if (v.toString('hex') === '00' && !field.allowZero) { | ||
6727 | v = Buffer.allocUnsafe(0) | ||
6728 | } | ||
6729 | |||
6730 | if (field.allowLess && field.length) { | ||
6731 | v = exports.stripZeros(v) | ||
6732 | assert(field.length >= v.length, 'The field ' + field.name + ' must not have more ' + field.length + ' bytes') | ||
6733 | } else if (!(field.allowZero && v.length === 0) && field.length) { | ||
6734 | assert(field.length === v.length, 'The field ' + field.name + ' must have byte length of ' + field.length) | ||
6735 | } | ||
6736 | |||
6737 | self.raw[i] = v | ||
6738 | } | ||
6739 | |||
6740 | Object.defineProperty(self, field.name, { | ||
6741 | enumerable: true, | ||
6742 | configurable: true, | ||
6743 | get: getter, | ||
6744 | set: setter | ||
6745 | }) | ||
6746 | |||
6747 | if (field.default) { | ||
6748 | self[field.name] = field.default | ||
6749 | } | ||
6750 | |||
6751 | // attach alias | ||
6752 | if (field.alias) { | ||
6753 | Object.defineProperty(self, field.alias, { | ||
6754 | enumerable: false, | ||
6755 | configurable: true, | ||
6756 | set: setter, | ||
6757 | get: getter | ||
6758 | }) | ||
6759 | } | ||
6760 | }) | ||
6761 | |||
6762 | // if the constuctor is passed data | ||
6763 | if (data) { | ||
6764 | if (typeof data === 'string') { | ||
6765 | data = Buffer.from(exports.stripHexPrefix(data), 'hex') | ||
6766 | } | ||
6767 | |||
6768 | if (Buffer.isBuffer(data)) { | ||
6769 | data = rlp.decode(data) | ||
6770 | } | ||
6771 | |||
6772 | if (Array.isArray(data)) { | ||
6773 | if (data.length > self._fields.length) { | ||
6774 | throw (new Error('wrong number of fields in data')) | ||
6775 | } | ||
6776 | |||
6777 | // make sure all the items are buffers | ||
6778 | data.forEach(function (d, i) { | ||
6779 | self[self._fields[i]] = exports.toBuffer(d) | ||
6780 | }) | ||
6781 | } else if (typeof data === 'object') { | ||
6782 | const keys = Object.keys(data) | ||
6783 | fields.forEach(function (field) { | ||
6784 | if (keys.indexOf(field.name) !== -1) self[field.name] = data[field.name] | ||
6785 | if (keys.indexOf(field.alias) !== -1) self[field.alias] = data[field.alias] | ||
6786 | }) | ||
6787 | } else { | ||
6788 | throw new Error('invalid data') | ||
6789 | } | ||
6790 | } | ||
6791 | } | ||
6792 | |||
6793 | }).call(this,require("buffer").Buffer) | ||
6794 | },{"assert":1,"bn.js":33,"buffer":5,"create-hash":36,"ethjs-util":56,"keccak":65,"rlp":72,"secp256k1":73}],32:[function(require,module,exports){ | ||
6795 | (function (Buffer){ | ||
6796 | // Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki | ||
6797 | // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] | ||
6798 | // NOTE: SIGHASH byte ignored AND restricted, truncate before use | ||
6799 | |||
6800 | function check (buffer) { | ||
6801 | if (buffer.length < 8) return false | ||
6802 | if (buffer.length > 72) return false | ||
6803 | if (buffer[0] !== 0x30) return false | ||
6804 | if (buffer[1] !== buffer.length - 2) return false | ||
6805 | if (buffer[2] !== 0x02) return false | ||
6806 | |||
6807 | var lenR = buffer[3] | ||
6808 | if (lenR === 0) return false | ||
6809 | if (5 + lenR >= buffer.length) return false | ||
6810 | if (buffer[4 + lenR] !== 0x02) return false | ||
6811 | |||
6812 | var lenS = buffer[5 + lenR] | ||
6813 | if (lenS === 0) return false | ||
6814 | if ((6 + lenR + lenS) !== buffer.length) return false | ||
6815 | |||
6816 | if (buffer[4] & 0x80) return false | ||
6817 | if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) return false | ||
6818 | |||
6819 | if (buffer[lenR + 6] & 0x80) return false | ||
6820 | if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) return false | ||
6821 | return true | ||
6822 | } | ||
6823 | |||
6824 | function decode (buffer) { | ||
6825 | if (buffer.length < 8) throw new Error('DER sequence length is too short') | ||
6826 | if (buffer.length > 72) throw new Error('DER sequence length is too long') | ||
6827 | if (buffer[0] !== 0x30) throw new Error('Expected DER sequence') | ||
6828 | if (buffer[1] !== buffer.length - 2) throw new Error('DER sequence length is invalid') | ||
6829 | if (buffer[2] !== 0x02) throw new Error('Expected DER integer') | ||
6830 | |||
6831 | var lenR = buffer[3] | ||
6832 | if (lenR === 0) throw new Error('R length is zero') | ||
6833 | if (5 + lenR >= buffer.length) throw new Error('R length is too long') | ||
6834 | if (buffer[4 + lenR] !== 0x02) throw new Error('Expected DER integer (2)') | ||
6835 | |||
6836 | var lenS = buffer[5 + lenR] | ||
6837 | if (lenS === 0) throw new Error('S length is zero') | ||
6838 | if ((6 + lenR + lenS) !== buffer.length) throw new Error('S length is invalid') | ||
6839 | |||
6840 | if (buffer[4] & 0x80) throw new Error('R value is negative') | ||
6841 | if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) throw new Error('R value excessively padded') | ||
6842 | |||
6843 | if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative') | ||
6844 | if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) throw new Error('S value excessively padded') | ||
6845 | |||
6846 | // non-BIP66 - extract R, S values | ||
6847 | return { | ||
6848 | r: buffer.slice(4, 4 + lenR), | ||
6849 | s: buffer.slice(6 + lenR) | ||
6850 | } | ||
6851 | } | ||
6852 | |||
6853 | /* | ||
6854 | * Expects r and s to be positive DER integers. | ||
6855 | * | ||
6856 | * The DER format uses the most significant bit as a sign bit (& 0x80). | ||
6857 | * If the significant bit is set AND the integer is positive, a 0x00 is prepended. | ||
6858 | * | ||
6859 | * Examples: | ||
6860 | * | ||
6861 | * 0 => 0x00 | ||
6862 | * 1 => 0x01 | ||
6863 | * -1 => 0xff | ||
6864 | * 127 => 0x7f | ||
6865 | * -127 => 0x81 | ||
6866 | * 128 => 0x0080 | ||
6867 | * -128 => 0x80 | ||
6868 | * 255 => 0x00ff | ||
6869 | * -255 => 0xff01 | ||
6870 | * 16300 => 0x3fac | ||
6871 | * -16300 => 0xc054 | ||
6872 | * 62300 => 0x00f35c | ||
6873 | * -62300 => 0xff0ca4 | ||
6874 | */ | ||
6875 | function encode (r, s) { | ||
6876 | var lenR = r.length | ||
6877 | var lenS = s.length | ||
6878 | if (lenR === 0) throw new Error('R length is zero') | ||
6879 | if (lenS === 0) throw new Error('S length is zero') | ||
6880 | if (lenR > 33) throw new Error('R length is too long') | ||
6881 | if (lenS > 33) throw new Error('S length is too long') | ||
6882 | if (r[0] & 0x80) throw new Error('R value is negative') | ||
6883 | if (s[0] & 0x80) throw new Error('S value is negative') | ||
6884 | if (lenR > 1 && (r[0] === 0x00) && !(r[1] & 0x80)) throw new Error('R value excessively padded') | ||
6885 | if (lenS > 1 && (s[0] === 0x00) && !(s[1] & 0x80)) throw new Error('S value excessively padded') | ||
6886 | |||
6887 | var signature = new Buffer(6 + lenR + lenS) | ||
6888 | |||
6889 | // 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] | ||
6890 | signature[0] = 0x30 | ||
6891 | signature[1] = signature.length - 2 | ||
6892 | signature[2] = 0x02 | ||
6893 | signature[3] = r.length | ||
6894 | r.copy(signature, 4) | ||
6895 | signature[4 + lenR] = 0x02 | ||
6896 | signature[5 + lenR] = s.length | ||
6897 | s.copy(signature, 6 + lenR) | ||
6898 | |||
6899 | return signature | ||
6900 | } | ||
6901 | |||
6902 | module.exports = { | ||
6903 | check: check, | ||
6904 | decode: decode, | ||
6905 | encode: encode | ||
6906 | } | ||
6907 | |||
6908 | }).call(this,require("buffer").Buffer) | ||
6909 | },{"buffer":5}],33:[function(require,module,exports){ | ||
6910 | (function (module, exports) { | ||
6911 | 'use strict'; | ||
6912 | |||
6913 | // Utils | ||
6914 | function assert (val, msg) { | ||
6915 | if (!val) throw new Error(msg || 'Assertion failed'); | ||
6916 | } | ||
6917 | |||
6918 | // Could use `inherits` module, but don't want to move from single file | ||
6919 | // architecture yet. | ||
6920 | function inherits (ctor, superCtor) { | ||
6921 | ctor.super_ = superCtor; | ||
6922 | var TempCtor = function () {}; | ||
6923 | TempCtor.prototype = superCtor.prototype; | ||
6924 | ctor.prototype = new TempCtor(); | ||
6925 | ctor.prototype.constructor = ctor; | ||
6926 | } | ||
6927 | |||
6928 | // BN | ||
6929 | |||
6930 | function BN (number, base, endian) { | ||
6931 | if (BN.isBN(number)) { | ||
6932 | return number; | ||
6933 | } | ||
6934 | |||
6935 | this.negative = 0; | ||
6936 | this.words = null; | ||
6937 | this.length = 0; | ||
6938 | |||
6939 | // Reduction context | ||
6940 | this.red = null; | ||
6941 | |||
6942 | if (number !== null) { | ||
6943 | if (base === 'le' || base === 'be') { | ||
6944 | endian = base; | ||
6945 | base = 10; | ||
6946 | } | ||
6947 | |||
6948 | this._init(number || 0, base || 10, endian || 'be'); | ||
6949 | } | ||
6950 | } | ||
6951 | if (typeof module === 'object') { | ||
6952 | module.exports = BN; | ||
6953 | } else { | ||
6954 | exports.BN = BN; | ||
6955 | } | ||
6956 | |||
6957 | BN.BN = BN; | ||
6958 | BN.wordSize = 26; | ||
6959 | |||
6960 | var Buffer; | ||
6961 | try { | ||
6962 | Buffer = require('buf' + 'fer').Buffer; | ||
6963 | } catch (e) { | ||
6964 | } | ||
6965 | |||
6966 | BN.isBN = function isBN (num) { | ||
6967 | if (num instanceof BN) { | ||
6968 | return true; | ||
6969 | } | ||
6970 | |||
6971 | return num !== null && typeof num === 'object' && | ||
6972 | num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); | ||
6973 | }; | ||
6974 | |||
6975 | BN.max = function max (left, right) { | ||
6976 | if (left.cmp(right) > 0) return left; | ||
6977 | return right; | ||
6978 | }; | ||
6979 | |||
6980 | BN.min = function min (left, right) { | ||
6981 | if (left.cmp(right) < 0) return left; | ||
6982 | return right; | ||
6983 | }; | ||
6984 | |||
6985 | BN.prototype._init = function init (number, base, endian) { | ||
6986 | if (typeof number === 'number') { | ||
6987 | return this._initNumber(number, base, endian); | ||
6988 | } | ||
6989 | |||
6990 | if (typeof number === 'object') { | ||
6991 | return this._initArray(number, base, endian); | ||
6992 | } | ||
6993 | |||
6994 | if (base === 'hex') { | ||
6995 | base = 16; | ||
6996 | } | ||
6997 | assert(base === (base | 0) && base >= 2 && base <= 36); | ||
6998 | |||
6999 | number = number.toString().replace(/\s+/g, ''); | ||
7000 | var start = 0; | ||
7001 | if (number[0] === '-') { | ||
7002 | start++; | ||
7003 | } | ||
7004 | |||
7005 | if (base === 16) { | ||
7006 | this._parseHex(number, start); | ||
7007 | } else { | ||
7008 | this._parseBase(number, base, start); | ||
7009 | } | ||
7010 | |||
7011 | if (number[0] === '-') { | ||
7012 | this.negative = 1; | ||
7013 | } | ||
7014 | |||
7015 | this.strip(); | ||
7016 | |||
7017 | if (endian !== 'le') return; | ||
7018 | |||
7019 | this._initArray(this.toArray(), base, endian); | ||
7020 | }; | ||
7021 | |||
7022 | BN.prototype._initNumber = function _initNumber (number, base, endian) { | ||
7023 | if (number < 0) { | ||
7024 | this.negative = 1; | ||
7025 | number = -number; | ||
7026 | } | ||
7027 | if (number < 0x4000000) { | ||
7028 | this.words = [ number & 0x3ffffff ]; | ||
7029 | this.length = 1; | ||
7030 | } else if (number < 0x10000000000000) { | ||
7031 | this.words = [ | ||
7032 | number & 0x3ffffff, | ||
7033 | (number / 0x4000000) & 0x3ffffff | ||
7034 | ]; | ||
7035 | this.length = 2; | ||
7036 | } else { | ||
7037 | assert(number < 0x20000000000000); // 2 ^ 53 (unsafe) | ||
7038 | this.words = [ | ||
7039 | number & 0x3ffffff, | ||
7040 | (number / 0x4000000) & 0x3ffffff, | ||
7041 | 1 | ||
7042 | ]; | ||
7043 | this.length = 3; | ||
7044 | } | ||
7045 | |||
7046 | if (endian !== 'le') return; | ||
7047 | |||
7048 | // Reverse the bytes | ||
7049 | this._initArray(this.toArray(), base, endian); | ||
7050 | }; | ||
7051 | |||
7052 | BN.prototype._initArray = function _initArray (number, base, endian) { | ||
7053 | // Perhaps a Uint8Array | ||
7054 | assert(typeof number.length === 'number'); | ||
7055 | if (number.length <= 0) { | ||
7056 | this.words = [ 0 ]; | ||
7057 | this.length = 1; | ||
7058 | return this; | ||
7059 | } | ||
7060 | |||
7061 | this.length = Math.ceil(number.length / 3); | ||
7062 | this.words = new Array(this.length); | ||
7063 | for (var i = 0; i < this.length; i++) { | ||
7064 | this.words[i] = 0; | ||
7065 | } | ||
7066 | |||
7067 | var j, w; | ||
7068 | var off = 0; | ||
7069 | if (endian === 'be') { | ||
7070 | for (i = number.length - 1, j = 0; i >= 0; i -= 3) { | ||
7071 | w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16); | ||
7072 | this.words[j] |= (w << off) & 0x3ffffff; | ||
7073 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; | ||
7074 | off += 24; | ||
7075 | if (off >= 26) { | ||
7076 | off -= 26; | ||
7077 | j++; | ||
7078 | } | ||
7079 | } | ||
7080 | } else if (endian === 'le') { | ||
7081 | for (i = 0, j = 0; i < number.length; i += 3) { | ||
7082 | w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16); | ||
7083 | this.words[j] |= (w << off) & 0x3ffffff; | ||
7084 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; | ||
7085 | off += 24; | ||
7086 | if (off >= 26) { | ||
7087 | off -= 26; | ||
7088 | j++; | ||
7089 | } | ||
7090 | } | ||
7091 | } | ||
7092 | return this.strip(); | ||
7093 | }; | ||
7094 | |||
7095 | function parseHex (str, start, end) { | ||
7096 | var r = 0; | ||
7097 | var len = Math.min(str.length, end); | ||
7098 | for (var i = start; i < len; i++) { | ||
7099 | var c = str.charCodeAt(i) - 48; | ||
7100 | |||
7101 | r <<= 4; | ||
7102 | |||
7103 | // 'a' - 'f' | ||
7104 | if (c >= 49 && c <= 54) { | ||
7105 | r |= c - 49 + 0xa; | ||
7106 | |||
7107 | // 'A' - 'F' | ||
7108 | } else if (c >= 17 && c <= 22) { | ||
7109 | r |= c - 17 + 0xa; | ||
7110 | |||
7111 | // '0' - '9' | ||
7112 | } else { | ||
7113 | r |= c & 0xf; | ||
7114 | } | ||
7115 | } | ||
7116 | return r; | ||
7117 | } | ||
7118 | |||
7119 | BN.prototype._parseHex = function _parseHex (number, start) { | ||
7120 | // Create possibly bigger array to ensure that it fits the number | ||
7121 | this.length = Math.ceil((number.length - start) / 6); | ||
7122 | this.words = new Array(this.length); | ||
7123 | for (var i = 0; i < this.length; i++) { | ||
7124 | this.words[i] = 0; | ||
7125 | } | ||
7126 | |||
7127 | var j, w; | ||
7128 | // Scan 24-bit chunks and add them to the number | ||
7129 | var off = 0; | ||
7130 | for (i = number.length - 6, j = 0; i >= start; i -= 6) { | ||
7131 | w = parseHex(number, i, i + 6); | ||
7132 | this.words[j] |= (w << off) & 0x3ffffff; | ||
7133 | // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb | ||
7134 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; | ||
7135 | off += 24; | ||
7136 | if (off >= 26) { | ||
7137 | off -= 26; | ||
7138 | j++; | ||
7139 | } | ||
7140 | } | ||
7141 | if (i + 6 !== start) { | ||
7142 | w = parseHex(number, start, i + 6); | ||
7143 | this.words[j] |= (w << off) & 0x3ffffff; | ||
7144 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; | ||
7145 | } | ||
7146 | this.strip(); | ||
7147 | }; | ||
7148 | |||
7149 | function parseBase (str, start, end, mul) { | ||
7150 | var r = 0; | ||
7151 | var len = Math.min(str.length, end); | ||
7152 | for (var i = start; i < len; i++) { | ||
7153 | var c = str.charCodeAt(i) - 48; | ||
7154 | |||
7155 | r *= mul; | ||
7156 | |||
7157 | // 'a' | ||
7158 | if (c >= 49) { | ||
7159 | r += c - 49 + 0xa; | ||
7160 | |||
7161 | // 'A' | ||
7162 | } else if (c >= 17) { | ||
7163 | r += c - 17 + 0xa; | ||
7164 | |||
7165 | // '0' - '9' | ||
7166 | } else { | ||
7167 | r += c; | ||
7168 | } | ||
7169 | } | ||
7170 | return r; | ||
7171 | } | ||
7172 | |||
7173 | BN.prototype._parseBase = function _parseBase (number, base, start) { | ||
7174 | // Initialize as zero | ||
7175 | this.words = [ 0 ]; | ||
7176 | this.length = 1; | ||
7177 | |||
7178 | // Find length of limb in base | ||
7179 | for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) { | ||
7180 | limbLen++; | ||
7181 | } | ||
7182 | limbLen--; | ||
7183 | limbPow = (limbPow / base) | 0; | ||
7184 | |||
7185 | var total = number.length - start; | ||
7186 | var mod = total % limbLen; | ||
7187 | var end = Math.min(total, total - mod) + start; | ||
7188 | |||
7189 | var word = 0; | ||
7190 | for (var i = start; i < end; i += limbLen) { | ||
7191 | word = parseBase(number, i, i + limbLen, base); | ||
7192 | |||
7193 | this.imuln(limbPow); | ||
7194 | if (this.words[0] + word < 0x4000000) { | ||
7195 | this.words[0] += word; | ||
7196 | } else { | ||
7197 | this._iaddn(word); | ||
7198 | } | ||
7199 | } | ||
7200 | |||
7201 | if (mod !== 0) { | ||
7202 | var pow = 1; | ||
7203 | word = parseBase(number, i, number.length, base); | ||
7204 | |||
7205 | for (i = 0; i < mod; i++) { | ||
7206 | pow *= base; | ||
7207 | } | ||
7208 | |||
7209 | this.imuln(pow); | ||
7210 | if (this.words[0] + word < 0x4000000) { | ||
7211 | this.words[0] += word; | ||
7212 | } else { | ||
7213 | this._iaddn(word); | ||
7214 | } | ||
7215 | } | ||
7216 | }; | ||
7217 | |||
7218 | BN.prototype.copy = function copy (dest) { | ||
7219 | dest.words = new Array(this.length); | ||
7220 | for (var i = 0; i < this.length; i++) { | ||
7221 | dest.words[i] = this.words[i]; | ||
7222 | } | ||
7223 | dest.length = this.length; | ||
7224 | dest.negative = this.negative; | ||
7225 | dest.red = this.red; | ||
7226 | }; | ||
7227 | |||
7228 | BN.prototype.clone = function clone () { | ||
7229 | var r = new BN(null); | ||
7230 | this.copy(r); | ||
7231 | return r; | ||
7232 | }; | ||
7233 | |||
7234 | BN.prototype._expand = function _expand (size) { | ||
7235 | while (this.length < size) { | ||
7236 | this.words[this.length++] = 0; | ||
7237 | } | ||
7238 | return this; | ||
7239 | }; | ||
7240 | |||
7241 | // Remove leading `0` from `this` | ||
7242 | BN.prototype.strip = function strip () { | ||
7243 | while (this.length > 1 && this.words[this.length - 1] === 0) { | ||
7244 | this.length--; | ||
7245 | } | ||
7246 | return this._normSign(); | ||
7247 | }; | ||
7248 | |||
7249 | BN.prototype._normSign = function _normSign () { | ||
7250 | // -0 = 0 | ||
7251 | if (this.length === 1 && this.words[0] === 0) { | ||
7252 | this.negative = 0; | ||
7253 | } | ||
7254 | return this; | ||
7255 | }; | ||
7256 | |||
7257 | BN.prototype.inspect = function inspect () { | ||
7258 | return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>'; | ||
7259 | }; | ||
7260 | |||
7261 | /* | ||
7262 | |||
7263 | var zeros = []; | ||
7264 | var groupSizes = []; | ||
7265 | var groupBases = []; | ||
7266 | |||
7267 | var s = ''; | ||
7268 | var i = -1; | ||
7269 | while (++i < BN.wordSize) { | ||
7270 | zeros[i] = s; | ||
7271 | s += '0'; | ||
7272 | } | ||
7273 | groupSizes[0] = 0; | ||
7274 | groupSizes[1] = 0; | ||
7275 | groupBases[0] = 0; | ||
7276 | groupBases[1] = 0; | ||
7277 | var base = 2 - 1; | ||
7278 | while (++base < 36 + 1) { | ||
7279 | var groupSize = 0; | ||
7280 | var groupBase = 1; | ||
7281 | while (groupBase < (1 << BN.wordSize) / base) { | ||
7282 | groupBase *= base; | ||
7283 | groupSize += 1; | ||
7284 | } | ||
7285 | groupSizes[base] = groupSize; | ||
7286 | groupBases[base] = groupBase; | ||
7287 | } | ||
7288 | |||
7289 | */ | ||
7290 | |||
7291 | var zeros = [ | ||
7292 | '', | ||
7293 | '0', | ||
7294 | '00', | ||
7295 | '000', | ||
7296 | '0000', | ||
7297 | '00000', | ||
7298 | '000000', | ||
7299 | '0000000', | ||
7300 | '00000000', | ||
7301 | '000000000', | ||
7302 | '0000000000', | ||
7303 | '00000000000', | ||
7304 | '000000000000', | ||
7305 | '0000000000000', | ||
7306 | '00000000000000', | ||
7307 | '000000000000000', | ||
7308 | '0000000000000000', | ||
7309 | '00000000000000000', | ||
7310 | '000000000000000000', | ||
7311 | '0000000000000000000', | ||
7312 | '00000000000000000000', | ||
7313 | '000000000000000000000', | ||
7314 | '0000000000000000000000', | ||
7315 | '00000000000000000000000', | ||
7316 | '000000000000000000000000', | ||
7317 | '0000000000000000000000000' | ||
7318 | ]; | ||
7319 | |||
7320 | var groupSizes = [ | ||
7321 | 0, 0, | ||
7322 | 25, 16, 12, 11, 10, 9, 8, | ||
7323 | 8, 7, 7, 7, 7, 6, 6, | ||
7324 | 6, 6, 6, 6, 6, 5, 5, | ||
7325 | 5, 5, 5, 5, 5, 5, 5, | ||
7326 | 5, 5, 5, 5, 5, 5, 5 | ||
7327 | ]; | ||
7328 | |||
7329 | var groupBases = [ | ||
7330 | 0, 0, | ||
7331 | 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, | ||
7332 | 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, | ||
7333 | 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, | ||
7334 | 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, | ||
7335 | 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176 | ||
7336 | ]; | ||
7337 | |||
7338 | BN.prototype.toString = function toString (base, padding) { | ||
7339 | base = base || 10; | ||
7340 | padding = padding | 0 || 1; | ||
7341 | |||
7342 | var out; | ||
7343 | if (base === 16 || base === 'hex') { | ||
7344 | out = ''; | ||
7345 | var off = 0; | ||
7346 | var carry = 0; | ||
7347 | for (var i = 0; i < this.length; i++) { | ||
7348 | var w = this.words[i]; | ||
7349 | var word = (((w << off) | carry) & 0xffffff).toString(16); | ||
7350 | carry = (w >>> (24 - off)) & 0xffffff; | ||
7351 | if (carry !== 0 || i !== this.length - 1) { | ||
7352 | out = zeros[6 - word.length] + word + out; | ||
7353 | } else { | ||
7354 | out = word + out; | ||
7355 | } | ||
7356 | off += 2; | ||
7357 | if (off >= 26) { | ||
7358 | off -= 26; | ||
7359 | i--; | ||
7360 | } | ||
7361 | } | ||
7362 | if (carry !== 0) { | ||
7363 | out = carry.toString(16) + out; | ||
7364 | } | ||
7365 | while (out.length % padding !== 0) { | ||
7366 | out = '0' + out; | ||
7367 | } | ||
7368 | if (this.negative !== 0) { | ||
7369 | out = '-' + out; | ||
7370 | } | ||
7371 | return out; | ||
7372 | } | ||
7373 | |||
7374 | if (base === (base | 0) && base >= 2 && base <= 36) { | ||
7375 | // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); | ||
7376 | var groupSize = groupSizes[base]; | ||
7377 | // var groupBase = Math.pow(base, groupSize); | ||
7378 | var groupBase = groupBases[base]; | ||
7379 | out = ''; | ||
7380 | var c = this.clone(); | ||
7381 | c.negative = 0; | ||
7382 | while (!c.isZero()) { | ||
7383 | var r = c.modn(groupBase).toString(base); | ||
7384 | c = c.idivn(groupBase); | ||
7385 | |||
7386 | if (!c.isZero()) { | ||
7387 | out = zeros[groupSize - r.length] + r + out; | ||
7388 | } else { | ||
7389 | out = r + out; | ||
7390 | } | ||
7391 | } | ||
7392 | if (this.isZero()) { | ||
7393 | out = '0' + out; | ||
7394 | } | ||
7395 | while (out.length % padding !== 0) { | ||
7396 | out = '0' + out; | ||
7397 | } | ||
7398 | if (this.negative !== 0) { | ||
7399 | out = '-' + out; | ||
7400 | } | ||
7401 | return out; | ||
7402 | } | ||
7403 | |||
7404 | assert(false, 'Base should be between 2 and 36'); | ||
7405 | }; | ||
7406 | |||
7407 | BN.prototype.toNumber = function toNumber () { | ||
7408 | var ret = this.words[0]; | ||
7409 | if (this.length === 2) { | ||
7410 | ret += this.words[1] * 0x4000000; | ||
7411 | } else if (this.length === 3 && this.words[2] === 0x01) { | ||
7412 | // NOTE: at this stage it is known that the top bit is set | ||
7413 | ret += 0x10000000000000 + (this.words[1] * 0x4000000); | ||
7414 | } else if (this.length > 2) { | ||
7415 | assert(false, 'Number can only safely store up to 53 bits'); | ||
7416 | } | ||
7417 | return (this.negative !== 0) ? -ret : ret; | ||
7418 | }; | ||
7419 | |||
7420 | BN.prototype.toJSON = function toJSON () { | ||
7421 | return this.toString(16); | ||
7422 | }; | ||
7423 | |||
7424 | BN.prototype.toBuffer = function toBuffer (endian, length) { | ||
7425 | assert(typeof Buffer !== 'undefined'); | ||
7426 | return this.toArrayLike(Buffer, endian, length); | ||
7427 | }; | ||
7428 | |||
7429 | BN.prototype.toArray = function toArray (endian, length) { | ||
7430 | return this.toArrayLike(Array, endian, length); | ||
7431 | }; | ||
7432 | |||
7433 | BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) { | ||
7434 | var byteLength = this.byteLength(); | ||
7435 | var reqLength = length || Math.max(1, byteLength); | ||
7436 | assert(byteLength <= reqLength, 'byte array longer than desired length'); | ||
7437 | assert(reqLength > 0, 'Requested array length <= 0'); | ||
7438 | |||
7439 | this.strip(); | ||
7440 | var littleEndian = endian === 'le'; | ||
7441 | var res = new ArrayType(reqLength); | ||
7442 | |||
7443 | var b, i; | ||
7444 | var q = this.clone(); | ||
7445 | if (!littleEndian) { | ||
7446 | // Assume big-endian | ||
7447 | for (i = 0; i < reqLength - byteLength; i++) { | ||
7448 | res[i] = 0; | ||
7449 | } | ||
7450 | |||
7451 | for (i = 0; !q.isZero(); i++) { | ||
7452 | b = q.andln(0xff); | ||
7453 | q.iushrn(8); | ||
7454 | |||
7455 | res[reqLength - i - 1] = b; | ||
7456 | } | ||
7457 | } else { | ||
7458 | for (i = 0; !q.isZero(); i++) { | ||
7459 | b = q.andln(0xff); | ||
7460 | q.iushrn(8); | ||
7461 | |||
7462 | res[i] = b; | ||
7463 | } | ||
7464 | |||
7465 | for (; i < reqLength; i++) { | ||
7466 | res[i] = 0; | ||
7467 | } | ||
7468 | } | ||
7469 | |||
7470 | return res; | ||
7471 | }; | ||
7472 | |||
7473 | if (Math.clz32) { | ||
7474 | BN.prototype._countBits = function _countBits (w) { | ||
7475 | return 32 - Math.clz32(w); | ||
7476 | }; | ||
7477 | } else { | ||
7478 | BN.prototype._countBits = function _countBits (w) { | ||
7479 | var t = w; | ||
7480 | var r = 0; | ||
7481 | if (t >= 0x1000) { | ||
7482 | r += 13; | ||
7483 | t >>>= 13; | ||
7484 | } | ||
7485 | if (t >= 0x40) { | ||
7486 | r += 7; | ||
7487 | t >>>= 7; | ||
7488 | } | ||
7489 | if (t >= 0x8) { | ||
7490 | r += 4; | ||
7491 | t >>>= 4; | ||
7492 | } | ||
7493 | if (t >= 0x02) { | ||
7494 | r += 2; | ||
7495 | t >>>= 2; | ||
7496 | } | ||
7497 | return r + t; | ||
7498 | }; | ||
7499 | } | ||
7500 | |||
7501 | BN.prototype._zeroBits = function _zeroBits (w) { | ||
7502 | // Short-cut | ||
7503 | if (w === 0) return 26; | ||
7504 | |||
7505 | var t = w; | ||
7506 | var r = 0; | ||
7507 | if ((t & 0x1fff) === 0) { | ||
7508 | r += 13; | ||
7509 | t >>>= 13; | ||
7510 | } | ||
7511 | if ((t & 0x7f) === 0) { | ||
7512 | r += 7; | ||
7513 | t >>>= 7; | ||
7514 | } | ||
7515 | if ((t & 0xf) === 0) { | ||
7516 | r += 4; | ||
7517 | t >>>= 4; | ||
7518 | } | ||
7519 | if ((t & 0x3) === 0) { | ||
7520 | r += 2; | ||
7521 | t >>>= 2; | ||
7522 | } | ||
7523 | if ((t & 0x1) === 0) { | ||
7524 | r++; | ||
7525 | } | ||
7526 | return r; | ||
7527 | }; | ||
7528 | |||
7529 | // Return number of used bits in a BN | ||
7530 | BN.prototype.bitLength = function bitLength () { | ||
7531 | var w = this.words[this.length - 1]; | ||
7532 | var hi = this._countBits(w); | ||
7533 | return (this.length - 1) * 26 + hi; | ||
7534 | }; | ||
7535 | |||
7536 | function toBitArray (num) { | ||
7537 | var w = new Array(num.bitLength()); | ||
7538 | |||
7539 | for (var bit = 0; bit < w.length; bit++) { | ||
7540 | var off = (bit / 26) | 0; | ||
7541 | var wbit = bit % 26; | ||
7542 | |||
7543 | w[bit] = (num.words[off] & (1 << wbit)) >>> wbit; | ||
7544 | } | ||
7545 | |||
7546 | return w; | ||
7547 | } | ||
7548 | |||
7549 | // Number of trailing zero bits | ||
7550 | BN.prototype.zeroBits = function zeroBits () { | ||
7551 | if (this.isZero()) return 0; | ||
7552 | |||
7553 | var r = 0; | ||
7554 | for (var i = 0; i < this.length; i++) { | ||
7555 | var b = this._zeroBits(this.words[i]); | ||
7556 | r += b; | ||
7557 | if (b !== 26) break; | ||
7558 | } | ||
7559 | return r; | ||
7560 | }; | ||
7561 | |||
7562 | BN.prototype.byteLength = function byteLength () { | ||
7563 | return Math.ceil(this.bitLength() / 8); | ||
7564 | }; | ||
7565 | |||
7566 | BN.prototype.toTwos = function toTwos (width) { | ||
7567 | if (this.negative !== 0) { | ||
7568 | return this.abs().inotn(width).iaddn(1); | ||
7569 | } | ||
7570 | return this.clone(); | ||
7571 | }; | ||
7572 | |||
7573 | BN.prototype.fromTwos = function fromTwos (width) { | ||
7574 | if (this.testn(width - 1)) { | ||
7575 | return this.notn(width).iaddn(1).ineg(); | ||
7576 | } | ||
7577 | return this.clone(); | ||
7578 | }; | ||
7579 | |||
7580 | BN.prototype.isNeg = function isNeg () { | ||
7581 | return this.negative !== 0; | ||
7582 | }; | ||
7583 | |||
7584 | // Return negative clone of `this` | ||
7585 | BN.prototype.neg = function neg () { | ||
7586 | return this.clone().ineg(); | ||
7587 | }; | ||
7588 | |||
7589 | BN.prototype.ineg = function ineg () { | ||
7590 | if (!this.isZero()) { | ||
7591 | this.negative ^= 1; | ||
7592 | } | ||
7593 | |||
7594 | return this; | ||
7595 | }; | ||
7596 | |||
7597 | // Or `num` with `this` in-place | ||
7598 | BN.prototype.iuor = function iuor (num) { | ||
7599 | while (this.length < num.length) { | ||
7600 | this.words[this.length++] = 0; | ||
7601 | } | ||
7602 | |||
7603 | for (var i = 0; i < num.length; i++) { | ||
7604 | this.words[i] = this.words[i] | num.words[i]; | ||
7605 | } | ||
7606 | |||
7607 | return this.strip(); | ||
7608 | }; | ||
7609 | |||
7610 | BN.prototype.ior = function ior (num) { | ||
7611 | assert((this.negative | num.negative) === 0); | ||
7612 | return this.iuor(num); | ||
7613 | }; | ||
7614 | |||
7615 | // Or `num` with `this` | ||
7616 | BN.prototype.or = function or (num) { | ||
7617 | if (this.length > num.length) return this.clone().ior(num); | ||
7618 | return num.clone().ior(this); | ||
7619 | }; | ||
7620 | |||
7621 | BN.prototype.uor = function uor (num) { | ||
7622 | if (this.length > num.length) return this.clone().iuor(num); | ||
7623 | return num.clone().iuor(this); | ||
7624 | }; | ||
7625 | |||
7626 | // And `num` with `this` in-place | ||
7627 | BN.prototype.iuand = function iuand (num) { | ||
7628 | // b = min-length(num, this) | ||
7629 | var b; | ||
7630 | if (this.length > num.length) { | ||
7631 | b = num; | ||
7632 | } else { | ||
7633 | b = this; | ||
7634 | } | ||
7635 | |||
7636 | for (var i = 0; i < b.length; i++) { | ||
7637 | this.words[i] = this.words[i] & num.words[i]; | ||
7638 | } | ||
7639 | |||
7640 | this.length = b.length; | ||
7641 | |||
7642 | return this.strip(); | ||
7643 | }; | ||
7644 | |||
7645 | BN.prototype.iand = function iand (num) { | ||
7646 | assert((this.negative | num.negative) === 0); | ||
7647 | return this.iuand(num); | ||
7648 | }; | ||
7649 | |||
7650 | // And `num` with `this` | ||
7651 | BN.prototype.and = function and (num) { | ||
7652 | if (this.length > num.length) return this.clone().iand(num); | ||
7653 | return num.clone().iand(this); | ||
7654 | }; | ||
7655 | |||
7656 | BN.prototype.uand = function uand (num) { | ||
7657 | if (this.length > num.length) return this.clone().iuand(num); | ||
7658 | return num.clone().iuand(this); | ||
7659 | }; | ||
7660 | |||
7661 | // Xor `num` with `this` in-place | ||
7662 | BN.prototype.iuxor = function iuxor (num) { | ||
7663 | // a.length > b.length | ||
7664 | var a; | ||
7665 | var b; | ||
7666 | if (this.length > num.length) { | ||
7667 | a = this; | ||
7668 | b = num; | ||
7669 | } else { | ||
7670 | a = num; | ||
7671 | b = this; | ||
7672 | } | ||
7673 | |||
7674 | for (var i = 0; i < b.length; i++) { | ||
7675 | this.words[i] = a.words[i] ^ b.words[i]; | ||
7676 | } | ||
7677 | |||
7678 | if (this !== a) { | ||
7679 | for (; i < a.length; i++) { | ||
7680 | this.words[i] = a.words[i]; | ||
7681 | } | ||
7682 | } | ||
7683 | |||
7684 | this.length = a.length; | ||
7685 | |||
7686 | return this.strip(); | ||
7687 | }; | ||
7688 | |||
7689 | BN.prototype.ixor = function ixor (num) { | ||
7690 | assert((this.negative | num.negative) === 0); | ||
7691 | return this.iuxor(num); | ||
7692 | }; | ||
7693 | |||
7694 | // Xor `num` with `this` | ||
7695 | BN.prototype.xor = function xor (num) { | ||
7696 | if (this.length > num.length) return this.clone().ixor(num); | ||
7697 | return num.clone().ixor(this); | ||
7698 | }; | ||
7699 | |||
7700 | BN.prototype.uxor = function uxor (num) { | ||
7701 | if (this.length > num.length) return this.clone().iuxor(num); | ||
7702 | return num.clone().iuxor(this); | ||
7703 | }; | ||
7704 | |||
7705 | // Not ``this`` with ``width`` bitwidth | ||
7706 | BN.prototype.inotn = function inotn (width) { | ||
7707 | assert(typeof width === 'number' && width >= 0); | ||
7708 | |||
7709 | var bytesNeeded = Math.ceil(width / 26) | 0; | ||
7710 | var bitsLeft = width % 26; | ||
7711 | |||
7712 | // Extend the buffer with leading zeroes | ||
7713 | this._expand(bytesNeeded); | ||
7714 | |||
7715 | if (bitsLeft > 0) { | ||
7716 | bytesNeeded--; | ||
7717 | } | ||
7718 | |||
7719 | // Handle complete words | ||
7720 | for (var i = 0; i < bytesNeeded; i++) { | ||
7721 | this.words[i] = ~this.words[i] & 0x3ffffff; | ||
7722 | } | ||
7723 | |||
7724 | // Handle the residue | ||
7725 | if (bitsLeft > 0) { | ||
7726 | this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft)); | ||
7727 | } | ||
7728 | |||
7729 | // And remove leading zeroes | ||
7730 | return this.strip(); | ||
7731 | }; | ||
7732 | |||
7733 | BN.prototype.notn = function notn (width) { | ||
7734 | return this.clone().inotn(width); | ||
7735 | }; | ||
7736 | |||
7737 | // Set `bit` of `this` | ||
7738 | BN.prototype.setn = function setn (bit, val) { | ||
7739 | assert(typeof bit === 'number' && bit >= 0); | ||
7740 | |||
7741 | var off = (bit / 26) | 0; | ||
7742 | var wbit = bit % 26; | ||
7743 | |||
7744 | this._expand(off + 1); | ||
7745 | |||
7746 | if (val) { | ||
7747 | this.words[off] = this.words[off] | (1 << wbit); | ||
7748 | } else { | ||
7749 | this.words[off] = this.words[off] & ~(1 << wbit); | ||
7750 | } | ||
7751 | |||
7752 | return this.strip(); | ||
7753 | }; | ||
7754 | |||
7755 | // Add `num` to `this` in-place | ||
7756 | BN.prototype.iadd = function iadd (num) { | ||
7757 | var r; | ||
7758 | |||
7759 | // negative + positive | ||
7760 | if (this.negative !== 0 && num.negative === 0) { | ||
7761 | this.negative = 0; | ||
7762 | r = this.isub(num); | ||
7763 | this.negative ^= 1; | ||
7764 | return this._normSign(); | ||
7765 | |||
7766 | // positive + negative | ||
7767 | } else if (this.negative === 0 && num.negative !== 0) { | ||
7768 | num.negative = 0; | ||
7769 | r = this.isub(num); | ||
7770 | num.negative = 1; | ||
7771 | return r._normSign(); | ||
7772 | } | ||
7773 | |||
7774 | // a.length > b.length | ||
7775 | var a, b; | ||
7776 | if (this.length > num.length) { | ||
7777 | a = this; | ||
7778 | b = num; | ||
7779 | } else { | ||
7780 | a = num; | ||
7781 | b = this; | ||
7782 | } | ||
7783 | |||
7784 | var carry = 0; | ||
7785 | for (var i = 0; i < b.length; i++) { | ||
7786 | r = (a.words[i] | 0) + (b.words[i] | 0) + carry; | ||
7787 | this.words[i] = r & 0x3ffffff; | ||
7788 | carry = r >>> 26; | ||
7789 | } | ||
7790 | for (; carry !== 0 && i < a.length; i++) { | ||
7791 | r = (a.words[i] | 0) + carry; | ||
7792 | this.words[i] = r & 0x3ffffff; | ||
7793 | carry = r >>> 26; | ||
7794 | } | ||
7795 | |||
7796 | this.length = a.length; | ||
7797 | if (carry !== 0) { | ||
7798 | this.words[this.length] = carry; | ||
7799 | this.length++; | ||
7800 | // Copy the rest of the words | ||
7801 | } else if (a !== this) { | ||
7802 | for (; i < a.length; i++) { | ||
7803 | this.words[i] = a.words[i]; | ||
7804 | } | ||
7805 | } | ||
7806 | |||
7807 | return this; | ||
7808 | }; | ||
7809 | |||
7810 | // Add `num` to `this` | ||
7811 | BN.prototype.add = function add (num) { | ||
7812 | var res; | ||
7813 | if (num.negative !== 0 && this.negative === 0) { | ||
7814 | num.negative = 0; | ||
7815 | res = this.sub(num); | ||
7816 | num.negative ^= 1; | ||
7817 | return res; | ||
7818 | } else if (num.negative === 0 && this.negative !== 0) { | ||
7819 | this.negative = 0; | ||
7820 | res = num.sub(this); | ||
7821 | this.negative = 1; | ||
7822 | return res; | ||
7823 | } | ||
7824 | |||
7825 | if (this.length > num.length) return this.clone().iadd(num); | ||
7826 | |||
7827 | return num.clone().iadd(this); | ||
7828 | }; | ||
7829 | |||
7830 | // Subtract `num` from `this` in-place | ||
7831 | BN.prototype.isub = function isub (num) { | ||
7832 | // this - (-num) = this + num | ||
7833 | if (num.negative !== 0) { | ||
7834 | num.negative = 0; | ||
7835 | var r = this.iadd(num); | ||
7836 | num.negative = 1; | ||
7837 | return r._normSign(); | ||
7838 | |||
7839 | // -this - num = -(this + num) | ||
7840 | } else if (this.negative !== 0) { | ||
7841 | this.negative = 0; | ||
7842 | this.iadd(num); | ||
7843 | this.negative = 1; | ||
7844 | return this._normSign(); | ||
7845 | } | ||
7846 | |||
7847 | // At this point both numbers are positive | ||
7848 | var cmp = this.cmp(num); | ||
7849 | |||
7850 | // Optimization - zeroify | ||
7851 | if (cmp === 0) { | ||
7852 | this.negative = 0; | ||
7853 | this.length = 1; | ||
7854 | this.words[0] = 0; | ||
7855 | return this; | ||
7856 | } | ||
7857 | |||
7858 | // a > b | ||
7859 | var a, b; | ||
7860 | if (cmp > 0) { | ||
7861 | a = this; | ||
7862 | b = num; | ||
7863 | } else { | ||
7864 | a = num; | ||
7865 | b = this; | ||
7866 | } | ||
7867 | |||
7868 | var carry = 0; | ||
7869 | for (var i = 0; i < b.length; i++) { | ||
7870 | r = (a.words[i] | 0) - (b.words[i] | 0) + carry; | ||
7871 | carry = r >> 26; | ||
7872 | this.words[i] = r & 0x3ffffff; | ||
7873 | } | ||
7874 | for (; carry !== 0 && i < a.length; i++) { | ||
7875 | r = (a.words[i] | 0) + carry; | ||
7876 | carry = r >> 26; | ||
7877 | this.words[i] = r & 0x3ffffff; | ||
7878 | } | ||
7879 | |||
7880 | // Copy rest of the words | ||
7881 | if (carry === 0 && i < a.length && a !== this) { | ||
7882 | for (; i < a.length; i++) { | ||
7883 | this.words[i] = a.words[i]; | ||
7884 | } | ||
7885 | } | ||
7886 | |||
7887 | this.length = Math.max(this.length, i); | ||
7888 | |||
7889 | if (a !== this) { | ||
7890 | this.negative = 1; | ||
7891 | } | ||
7892 | |||
7893 | return this.strip(); | ||
7894 | }; | ||
7895 | |||
7896 | // Subtract `num` from `this` | ||
7897 | BN.prototype.sub = function sub (num) { | ||
7898 | return this.clone().isub(num); | ||
7899 | }; | ||
7900 | |||
7901 | function smallMulTo (self, num, out) { | ||
7902 | out.negative = num.negative ^ self.negative; | ||
7903 | var len = (self.length + num.length) | 0; | ||
7904 | out.length = len; | ||
7905 | len = (len - 1) | 0; | ||
7906 | |||
7907 | // Peel one iteration (compiler can't do it, because of code complexity) | ||
7908 | var a = self.words[0] | 0; | ||
7909 | var b = num.words[0] | 0; | ||
7910 | var r = a * b; | ||
7911 | |||
7912 | var lo = r & 0x3ffffff; | ||
7913 | var carry = (r / 0x4000000) | 0; | ||
7914 | out.words[0] = lo; | ||
7915 | |||
7916 | for (var k = 1; k < len; k++) { | ||
7917 | // Sum all words with the same `i + j = k` and accumulate `ncarry`, | ||
7918 | // note that ncarry could be >= 0x3ffffff | ||
7919 | var ncarry = carry >>> 26; | ||
7920 | var rword = carry & 0x3ffffff; | ||
7921 | var maxJ = Math.min(k, num.length - 1); | ||
7922 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { | ||
7923 | var i = (k - j) | 0; | ||
7924 | a = self.words[i] | 0; | ||
7925 | b = num.words[j] | 0; | ||
7926 | r = a * b + rword; | ||
7927 | ncarry += (r / 0x4000000) | 0; | ||
7928 | rword = r & 0x3ffffff; | ||
7929 | } | ||
7930 | out.words[k] = rword | 0; | ||
7931 | carry = ncarry | 0; | ||
7932 | } | ||
7933 | if (carry !== 0) { | ||
7934 | out.words[k] = carry | 0; | ||
7935 | } else { | ||
7936 | out.length--; | ||
7937 | } | ||
7938 | |||
7939 | return out.strip(); | ||
7940 | } | ||
7941 | |||
7942 | // TODO(indutny): it may be reasonable to omit it for users who don't need | ||
7943 | // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit | ||
7944 | // multiplication (like elliptic secp256k1). | ||
7945 | var comb10MulTo = function comb10MulTo (self, num, out) { | ||
7946 | var a = self.words; | ||
7947 | var b = num.words; | ||
7948 | var o = out.words; | ||
7949 | var c = 0; | ||
7950 | var lo; | ||
7951 | var mid; | ||
7952 | var hi; | ||
7953 | var a0 = a[0] | 0; | ||
7954 | var al0 = a0 & 0x1fff; | ||
7955 | var ah0 = a0 >>> 13; | ||
7956 | var a1 = a[1] | 0; | ||
7957 | var al1 = a1 & 0x1fff; | ||
7958 | var ah1 = a1 >>> 13; | ||
7959 | var a2 = a[2] | 0; | ||
7960 | var al2 = a2 & 0x1fff; | ||
7961 | var ah2 = a2 >>> 13; | ||
7962 | var a3 = a[3] | 0; | ||
7963 | var al3 = a3 & 0x1fff; | ||
7964 | var ah3 = a3 >>> 13; | ||
7965 | var a4 = a[4] | 0; | ||
7966 | var al4 = a4 & 0x1fff; | ||
7967 | var ah4 = a4 >>> 13; | ||
7968 | var a5 = a[5] | 0; | ||
7969 | var al5 = a5 & 0x1fff; | ||
7970 | var ah5 = a5 >>> 13; | ||
7971 | var a6 = a[6] | 0; | ||
7972 | var al6 = a6 & 0x1fff; | ||
7973 | var ah6 = a6 >>> 13; | ||
7974 | var a7 = a[7] | 0; | ||
7975 | var al7 = a7 & 0x1fff; | ||
7976 | var ah7 = a7 >>> 13; | ||
7977 | var a8 = a[8] | 0; | ||
7978 | var al8 = a8 & 0x1fff; | ||
7979 | var ah8 = a8 >>> 13; | ||
7980 | var a9 = a[9] | 0; | ||
7981 | var al9 = a9 & 0x1fff; | ||
7982 | var ah9 = a9 >>> 13; | ||
7983 | var b0 = b[0] | 0; | ||
7984 | var bl0 = b0 & 0x1fff; | ||
7985 | var bh0 = b0 >>> 13; | ||
7986 | var b1 = b[1] | 0; | ||
7987 | var bl1 = b1 & 0x1fff; | ||
7988 | var bh1 = b1 >>> 13; | ||
7989 | var b2 = b[2] | 0; | ||
7990 | var bl2 = b2 & 0x1fff; | ||
7991 | var bh2 = b2 >>> 13; | ||
7992 | var b3 = b[3] | 0; | ||
7993 | var bl3 = b3 & 0x1fff; | ||
7994 | var bh3 = b3 >>> 13; | ||
7995 | var b4 = b[4] | 0; | ||
7996 | var bl4 = b4 & 0x1fff; | ||
7997 | var bh4 = b4 >>> 13; | ||
7998 | var b5 = b[5] | 0; | ||
7999 | var bl5 = b5 & 0x1fff; | ||
8000 | var bh5 = b5 >>> 13; | ||
8001 | var b6 = b[6] | 0; | ||
8002 | var bl6 = b6 & 0x1fff; | ||
8003 | var bh6 = b6 >>> 13; | ||
8004 | var b7 = b[7] | 0; | ||
8005 | var bl7 = b7 & 0x1fff; | ||
8006 | var bh7 = b7 >>> 13; | ||
8007 | var b8 = b[8] | 0; | ||
8008 | var bl8 = b8 & 0x1fff; | ||
8009 | var bh8 = b8 >>> 13; | ||
8010 | var b9 = b[9] | 0; | ||
8011 | var bl9 = b9 & 0x1fff; | ||
8012 | var bh9 = b9 >>> 13; | ||
8013 | |||
8014 | out.negative = self.negative ^ num.negative; | ||
8015 | out.length = 19; | ||
8016 | /* k = 0 */ | ||
8017 | lo = Math.imul(al0, bl0); | ||
8018 | mid = Math.imul(al0, bh0); | ||
8019 | mid = (mid + Math.imul(ah0, bl0)) | 0; | ||
8020 | hi = Math.imul(ah0, bh0); | ||
8021 | var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8022 | c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0; | ||
8023 | w0 &= 0x3ffffff; | ||
8024 | /* k = 1 */ | ||
8025 | lo = Math.imul(al1, bl0); | ||
8026 | mid = Math.imul(al1, bh0); | ||
8027 | mid = (mid + Math.imul(ah1, bl0)) | 0; | ||
8028 | hi = Math.imul(ah1, bh0); | ||
8029 | lo = (lo + Math.imul(al0, bl1)) | 0; | ||
8030 | mid = (mid + Math.imul(al0, bh1)) | 0; | ||
8031 | mid = (mid + Math.imul(ah0, bl1)) | 0; | ||
8032 | hi = (hi + Math.imul(ah0, bh1)) | 0; | ||
8033 | var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8034 | c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0; | ||
8035 | w1 &= 0x3ffffff; | ||
8036 | /* k = 2 */ | ||
8037 | lo = Math.imul(al2, bl0); | ||
8038 | mid = Math.imul(al2, bh0); | ||
8039 | mid = (mid + Math.imul(ah2, bl0)) | 0; | ||
8040 | hi = Math.imul(ah2, bh0); | ||
8041 | lo = (lo + Math.imul(al1, bl1)) | 0; | ||
8042 | mid = (mid + Math.imul(al1, bh1)) | 0; | ||
8043 | mid = (mid + Math.imul(ah1, bl1)) | 0; | ||
8044 | hi = (hi + Math.imul(ah1, bh1)) | 0; | ||
8045 | lo = (lo + Math.imul(al0, bl2)) | 0; | ||
8046 | mid = (mid + Math.imul(al0, bh2)) | 0; | ||
8047 | mid = (mid + Math.imul(ah0, bl2)) | 0; | ||
8048 | hi = (hi + Math.imul(ah0, bh2)) | 0; | ||
8049 | var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8050 | c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0; | ||
8051 | w2 &= 0x3ffffff; | ||
8052 | /* k = 3 */ | ||
8053 | lo = Math.imul(al3, bl0); | ||
8054 | mid = Math.imul(al3, bh0); | ||
8055 | mid = (mid + Math.imul(ah3, bl0)) | 0; | ||
8056 | hi = Math.imul(ah3, bh0); | ||
8057 | lo = (lo + Math.imul(al2, bl1)) | 0; | ||
8058 | mid = (mid + Math.imul(al2, bh1)) | 0; | ||
8059 | mid = (mid + Math.imul(ah2, bl1)) | 0; | ||
8060 | hi = (hi + Math.imul(ah2, bh1)) | 0; | ||
8061 | lo = (lo + Math.imul(al1, bl2)) | 0; | ||
8062 | mid = (mid + Math.imul(al1, bh2)) | 0; | ||
8063 | mid = (mid + Math.imul(ah1, bl2)) | 0; | ||
8064 | hi = (hi + Math.imul(ah1, bh2)) | 0; | ||
8065 | lo = (lo + Math.imul(al0, bl3)) | 0; | ||
8066 | mid = (mid + Math.imul(al0, bh3)) | 0; | ||
8067 | mid = (mid + Math.imul(ah0, bl3)) | 0; | ||
8068 | hi = (hi + Math.imul(ah0, bh3)) | 0; | ||
8069 | var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8070 | c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0; | ||
8071 | w3 &= 0x3ffffff; | ||
8072 | /* k = 4 */ | ||
8073 | lo = Math.imul(al4, bl0); | ||
8074 | mid = Math.imul(al4, bh0); | ||
8075 | mid = (mid + Math.imul(ah4, bl0)) | 0; | ||
8076 | hi = Math.imul(ah4, bh0); | ||
8077 | lo = (lo + Math.imul(al3, bl1)) | 0; | ||
8078 | mid = (mid + Math.imul(al3, bh1)) | 0; | ||
8079 | mid = (mid + Math.imul(ah3, bl1)) | 0; | ||
8080 | hi = (hi + Math.imul(ah3, bh1)) | 0; | ||
8081 | lo = (lo + Math.imul(al2, bl2)) | 0; | ||
8082 | mid = (mid + Math.imul(al2, bh2)) | 0; | ||
8083 | mid = (mid + Math.imul(ah2, bl2)) | 0; | ||
8084 | hi = (hi + Math.imul(ah2, bh2)) | 0; | ||
8085 | lo = (lo + Math.imul(al1, bl3)) | 0; | ||
8086 | mid = (mid + Math.imul(al1, bh3)) | 0; | ||
8087 | mid = (mid + Math.imul(ah1, bl3)) | 0; | ||
8088 | hi = (hi + Math.imul(ah1, bh3)) | 0; | ||
8089 | lo = (lo + Math.imul(al0, bl4)) | 0; | ||
8090 | mid = (mid + Math.imul(al0, bh4)) | 0; | ||
8091 | mid = (mid + Math.imul(ah0, bl4)) | 0; | ||
8092 | hi = (hi + Math.imul(ah0, bh4)) | 0; | ||
8093 | var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8094 | c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0; | ||
8095 | w4 &= 0x3ffffff; | ||
8096 | /* k = 5 */ | ||
8097 | lo = Math.imul(al5, bl0); | ||
8098 | mid = Math.imul(al5, bh0); | ||
8099 | mid = (mid + Math.imul(ah5, bl0)) | 0; | ||
8100 | hi = Math.imul(ah5, bh0); | ||
8101 | lo = (lo + Math.imul(al4, bl1)) | 0; | ||
8102 | mid = (mid + Math.imul(al4, bh1)) | 0; | ||
8103 | mid = (mid + Math.imul(ah4, bl1)) | 0; | ||
8104 | hi = (hi + Math.imul(ah4, bh1)) | 0; | ||
8105 | lo = (lo + Math.imul(al3, bl2)) | 0; | ||
8106 | mid = (mid + Math.imul(al3, bh2)) | 0; | ||
8107 | mid = (mid + Math.imul(ah3, bl2)) | 0; | ||
8108 | hi = (hi + Math.imul(ah3, bh2)) | 0; | ||
8109 | lo = (lo + Math.imul(al2, bl3)) | 0; | ||
8110 | mid = (mid + Math.imul(al2, bh3)) | 0; | ||
8111 | mid = (mid + Math.imul(ah2, bl3)) | 0; | ||
8112 | hi = (hi + Math.imul(ah2, bh3)) | 0; | ||
8113 | lo = (lo + Math.imul(al1, bl4)) | 0; | ||
8114 | mid = (mid + Math.imul(al1, bh4)) | 0; | ||
8115 | mid = (mid + Math.imul(ah1, bl4)) | 0; | ||
8116 | hi = (hi + Math.imul(ah1, bh4)) | 0; | ||
8117 | lo = (lo + Math.imul(al0, bl5)) | 0; | ||
8118 | mid = (mid + Math.imul(al0, bh5)) | 0; | ||
8119 | mid = (mid + Math.imul(ah0, bl5)) | 0; | ||
8120 | hi = (hi + Math.imul(ah0, bh5)) | 0; | ||
8121 | var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8122 | c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0; | ||
8123 | w5 &= 0x3ffffff; | ||
8124 | /* k = 6 */ | ||
8125 | lo = Math.imul(al6, bl0); | ||
8126 | mid = Math.imul(al6, bh0); | ||
8127 | mid = (mid + Math.imul(ah6, bl0)) | 0; | ||
8128 | hi = Math.imul(ah6, bh0); | ||
8129 | lo = (lo + Math.imul(al5, bl1)) | 0; | ||
8130 | mid = (mid + Math.imul(al5, bh1)) | 0; | ||
8131 | mid = (mid + Math.imul(ah5, bl1)) | 0; | ||
8132 | hi = (hi + Math.imul(ah5, bh1)) | 0; | ||
8133 | lo = (lo + Math.imul(al4, bl2)) | 0; | ||
8134 | mid = (mid + Math.imul(al4, bh2)) | 0; | ||
8135 | mid = (mid + Math.imul(ah4, bl2)) | 0; | ||
8136 | hi = (hi + Math.imul(ah4, bh2)) | 0; | ||
8137 | lo = (lo + Math.imul(al3, bl3)) | 0; | ||
8138 | mid = (mid + Math.imul(al3, bh3)) | 0; | ||
8139 | mid = (mid + Math.imul(ah3, bl3)) | 0; | ||
8140 | hi = (hi + Math.imul(ah3, bh3)) | 0; | ||
8141 | lo = (lo + Math.imul(al2, bl4)) | 0; | ||
8142 | mid = (mid + Math.imul(al2, bh4)) | 0; | ||
8143 | mid = (mid + Math.imul(ah2, bl4)) | 0; | ||
8144 | hi = (hi + Math.imul(ah2, bh4)) | 0; | ||
8145 | lo = (lo + Math.imul(al1, bl5)) | 0; | ||
8146 | mid = (mid + Math.imul(al1, bh5)) | 0; | ||
8147 | mid = (mid + Math.imul(ah1, bl5)) | 0; | ||
8148 | hi = (hi + Math.imul(ah1, bh5)) | 0; | ||
8149 | lo = (lo + Math.imul(al0, bl6)) | 0; | ||
8150 | mid = (mid + Math.imul(al0, bh6)) | 0; | ||
8151 | mid = (mid + Math.imul(ah0, bl6)) | 0; | ||
8152 | hi = (hi + Math.imul(ah0, bh6)) | 0; | ||
8153 | var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8154 | c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0; | ||
8155 | w6 &= 0x3ffffff; | ||
8156 | /* k = 7 */ | ||
8157 | lo = Math.imul(al7, bl0); | ||
8158 | mid = Math.imul(al7, bh0); | ||
8159 | mid = (mid + Math.imul(ah7, bl0)) | 0; | ||
8160 | hi = Math.imul(ah7, bh0); | ||
8161 | lo = (lo + Math.imul(al6, bl1)) | 0; | ||
8162 | mid = (mid + Math.imul(al6, bh1)) | 0; | ||
8163 | mid = (mid + Math.imul(ah6, bl1)) | 0; | ||
8164 | hi = (hi + Math.imul(ah6, bh1)) | 0; | ||
8165 | lo = (lo + Math.imul(al5, bl2)) | 0; | ||
8166 | mid = (mid + Math.imul(al5, bh2)) | 0; | ||
8167 | mid = (mid + Math.imul(ah5, bl2)) | 0; | ||
8168 | hi = (hi + Math.imul(ah5, bh2)) | 0; | ||
8169 | lo = (lo + Math.imul(al4, bl3)) | 0; | ||
8170 | mid = (mid + Math.imul(al4, bh3)) | 0; | ||
8171 | mid = (mid + Math.imul(ah4, bl3)) | 0; | ||
8172 | hi = (hi + Math.imul(ah4, bh3)) | 0; | ||
8173 | lo = (lo + Math.imul(al3, bl4)) | 0; | ||
8174 | mid = (mid + Math.imul(al3, bh4)) | 0; | ||
8175 | mid = (mid + Math.imul(ah3, bl4)) | 0; | ||
8176 | hi = (hi + Math.imul(ah3, bh4)) | 0; | ||
8177 | lo = (lo + Math.imul(al2, bl5)) | 0; | ||
8178 | mid = (mid + Math.imul(al2, bh5)) | 0; | ||
8179 | mid = (mid + Math.imul(ah2, bl5)) | 0; | ||
8180 | hi = (hi + Math.imul(ah2, bh5)) | 0; | ||
8181 | lo = (lo + Math.imul(al1, bl6)) | 0; | ||
8182 | mid = (mid + Math.imul(al1, bh6)) | 0; | ||
8183 | mid = (mid + Math.imul(ah1, bl6)) | 0; | ||
8184 | hi = (hi + Math.imul(ah1, bh6)) | 0; | ||
8185 | lo = (lo + Math.imul(al0, bl7)) | 0; | ||
8186 | mid = (mid + Math.imul(al0, bh7)) | 0; | ||
8187 | mid = (mid + Math.imul(ah0, bl7)) | 0; | ||
8188 | hi = (hi + Math.imul(ah0, bh7)) | 0; | ||
8189 | var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8190 | c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0; | ||
8191 | w7 &= 0x3ffffff; | ||
8192 | /* k = 8 */ | ||
8193 | lo = Math.imul(al8, bl0); | ||
8194 | mid = Math.imul(al8, bh0); | ||
8195 | mid = (mid + Math.imul(ah8, bl0)) | 0; | ||
8196 | hi = Math.imul(ah8, bh0); | ||
8197 | lo = (lo + Math.imul(al7, bl1)) | 0; | ||
8198 | mid = (mid + Math.imul(al7, bh1)) | 0; | ||
8199 | mid = (mid + Math.imul(ah7, bl1)) | 0; | ||
8200 | hi = (hi + Math.imul(ah7, bh1)) | 0; | ||
8201 | lo = (lo + Math.imul(al6, bl2)) | 0; | ||
8202 | mid = (mid + Math.imul(al6, bh2)) | 0; | ||
8203 | mid = (mid + Math.imul(ah6, bl2)) | 0; | ||
8204 | hi = (hi + Math.imul(ah6, bh2)) | 0; | ||
8205 | lo = (lo + Math.imul(al5, bl3)) | 0; | ||
8206 | mid = (mid + Math.imul(al5, bh3)) | 0; | ||
8207 | mid = (mid + Math.imul(ah5, bl3)) | 0; | ||
8208 | hi = (hi + Math.imul(ah5, bh3)) | 0; | ||
8209 | lo = (lo + Math.imul(al4, bl4)) | 0; | ||
8210 | mid = (mid + Math.imul(al4, bh4)) | 0; | ||
8211 | mid = (mid + Math.imul(ah4, bl4)) | 0; | ||
8212 | hi = (hi + Math.imul(ah4, bh4)) | 0; | ||
8213 | lo = (lo + Math.imul(al3, bl5)) | 0; | ||
8214 | mid = (mid + Math.imul(al3, bh5)) | 0; | ||
8215 | mid = (mid + Math.imul(ah3, bl5)) | 0; | ||
8216 | hi = (hi + Math.imul(ah3, bh5)) | 0; | ||
8217 | lo = (lo + Math.imul(al2, bl6)) | 0; | ||
8218 | mid = (mid + Math.imul(al2, bh6)) | 0; | ||
8219 | mid = (mid + Math.imul(ah2, bl6)) | 0; | ||
8220 | hi = (hi + Math.imul(ah2, bh6)) | 0; | ||
8221 | lo = (lo + Math.imul(al1, bl7)) | 0; | ||
8222 | mid = (mid + Math.imul(al1, bh7)) | 0; | ||
8223 | mid = (mid + Math.imul(ah1, bl7)) | 0; | ||
8224 | hi = (hi + Math.imul(ah1, bh7)) | 0; | ||
8225 | lo = (lo + Math.imul(al0, bl8)) | 0; | ||
8226 | mid = (mid + Math.imul(al0, bh8)) | 0; | ||
8227 | mid = (mid + Math.imul(ah0, bl8)) | 0; | ||
8228 | hi = (hi + Math.imul(ah0, bh8)) | 0; | ||
8229 | var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8230 | c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0; | ||
8231 | w8 &= 0x3ffffff; | ||
8232 | /* k = 9 */ | ||
8233 | lo = Math.imul(al9, bl0); | ||
8234 | mid = Math.imul(al9, bh0); | ||
8235 | mid = (mid + Math.imul(ah9, bl0)) | 0; | ||
8236 | hi = Math.imul(ah9, bh0); | ||
8237 | lo = (lo + Math.imul(al8, bl1)) | 0; | ||
8238 | mid = (mid + Math.imul(al8, bh1)) | 0; | ||
8239 | mid = (mid + Math.imul(ah8, bl1)) | 0; | ||
8240 | hi = (hi + Math.imul(ah8, bh1)) | 0; | ||
8241 | lo = (lo + Math.imul(al7, bl2)) | 0; | ||
8242 | mid = (mid + Math.imul(al7, bh2)) | 0; | ||
8243 | mid = (mid + Math.imul(ah7, bl2)) | 0; | ||
8244 | hi = (hi + Math.imul(ah7, bh2)) | 0; | ||
8245 | lo = (lo + Math.imul(al6, bl3)) | 0; | ||
8246 | mid = (mid + Math.imul(al6, bh3)) | 0; | ||
8247 | mid = (mid + Math.imul(ah6, bl3)) | 0; | ||
8248 | hi = (hi + Math.imul(ah6, bh3)) | 0; | ||
8249 | lo = (lo + Math.imul(al5, bl4)) | 0; | ||
8250 | mid = (mid + Math.imul(al5, bh4)) | 0; | ||
8251 | mid = (mid + Math.imul(ah5, bl4)) | 0; | ||
8252 | hi = (hi + Math.imul(ah5, bh4)) | 0; | ||
8253 | lo = (lo + Math.imul(al4, bl5)) | 0; | ||
8254 | mid = (mid + Math.imul(al4, bh5)) | 0; | ||
8255 | mid = (mid + Math.imul(ah4, bl5)) | 0; | ||
8256 | hi = (hi + Math.imul(ah4, bh5)) | 0; | ||
8257 | lo = (lo + Math.imul(al3, bl6)) | 0; | ||
8258 | mid = (mid + Math.imul(al3, bh6)) | 0; | ||
8259 | mid = (mid + Math.imul(ah3, bl6)) | 0; | ||
8260 | hi = (hi + Math.imul(ah3, bh6)) | 0; | ||
8261 | lo = (lo + Math.imul(al2, bl7)) | 0; | ||
8262 | mid = (mid + Math.imul(al2, bh7)) | 0; | ||
8263 | mid = (mid + Math.imul(ah2, bl7)) | 0; | ||
8264 | hi = (hi + Math.imul(ah2, bh7)) | 0; | ||
8265 | lo = (lo + Math.imul(al1, bl8)) | 0; | ||
8266 | mid = (mid + Math.imul(al1, bh8)) | 0; | ||
8267 | mid = (mid + Math.imul(ah1, bl8)) | 0; | ||
8268 | hi = (hi + Math.imul(ah1, bh8)) | 0; | ||
8269 | lo = (lo + Math.imul(al0, bl9)) | 0; | ||
8270 | mid = (mid + Math.imul(al0, bh9)) | 0; | ||
8271 | mid = (mid + Math.imul(ah0, bl9)) | 0; | ||
8272 | hi = (hi + Math.imul(ah0, bh9)) | 0; | ||
8273 | var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8274 | c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0; | ||
8275 | w9 &= 0x3ffffff; | ||
8276 | /* k = 10 */ | ||
8277 | lo = Math.imul(al9, bl1); | ||
8278 | mid = Math.imul(al9, bh1); | ||
8279 | mid = (mid + Math.imul(ah9, bl1)) | 0; | ||
8280 | hi = Math.imul(ah9, bh1); | ||
8281 | lo = (lo + Math.imul(al8, bl2)) | 0; | ||
8282 | mid = (mid + Math.imul(al8, bh2)) | 0; | ||
8283 | mid = (mid + Math.imul(ah8, bl2)) | 0; | ||
8284 | hi = (hi + Math.imul(ah8, bh2)) | 0; | ||
8285 | lo = (lo + Math.imul(al7, bl3)) | 0; | ||
8286 | mid = (mid + Math.imul(al7, bh3)) | 0; | ||
8287 | mid = (mid + Math.imul(ah7, bl3)) | 0; | ||
8288 | hi = (hi + Math.imul(ah7, bh3)) | 0; | ||
8289 | lo = (lo + Math.imul(al6, bl4)) | 0; | ||
8290 | mid = (mid + Math.imul(al6, bh4)) | 0; | ||
8291 | mid = (mid + Math.imul(ah6, bl4)) | 0; | ||
8292 | hi = (hi + Math.imul(ah6, bh4)) | 0; | ||
8293 | lo = (lo + Math.imul(al5, bl5)) | 0; | ||
8294 | mid = (mid + Math.imul(al5, bh5)) | 0; | ||
8295 | mid = (mid + Math.imul(ah5, bl5)) | 0; | ||
8296 | hi = (hi + Math.imul(ah5, bh5)) | 0; | ||
8297 | lo = (lo + Math.imul(al4, bl6)) | 0; | ||
8298 | mid = (mid + Math.imul(al4, bh6)) | 0; | ||
8299 | mid = (mid + Math.imul(ah4, bl6)) | 0; | ||
8300 | hi = (hi + Math.imul(ah4, bh6)) | 0; | ||
8301 | lo = (lo + Math.imul(al3, bl7)) | 0; | ||
8302 | mid = (mid + Math.imul(al3, bh7)) | 0; | ||
8303 | mid = (mid + Math.imul(ah3, bl7)) | 0; | ||
8304 | hi = (hi + Math.imul(ah3, bh7)) | 0; | ||
8305 | lo = (lo + Math.imul(al2, bl8)) | 0; | ||
8306 | mid = (mid + Math.imul(al2, bh8)) | 0; | ||
8307 | mid = (mid + Math.imul(ah2, bl8)) | 0; | ||
8308 | hi = (hi + Math.imul(ah2, bh8)) | 0; | ||
8309 | lo = (lo + Math.imul(al1, bl9)) | 0; | ||
8310 | mid = (mid + Math.imul(al1, bh9)) | 0; | ||
8311 | mid = (mid + Math.imul(ah1, bl9)) | 0; | ||
8312 | hi = (hi + Math.imul(ah1, bh9)) | 0; | ||
8313 | var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8314 | c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0; | ||
8315 | w10 &= 0x3ffffff; | ||
8316 | /* k = 11 */ | ||
8317 | lo = Math.imul(al9, bl2); | ||
8318 | mid = Math.imul(al9, bh2); | ||
8319 | mid = (mid + Math.imul(ah9, bl2)) | 0; | ||
8320 | hi = Math.imul(ah9, bh2); | ||
8321 | lo = (lo + Math.imul(al8, bl3)) | 0; | ||
8322 | mid = (mid + Math.imul(al8, bh3)) | 0; | ||
8323 | mid = (mid + Math.imul(ah8, bl3)) | 0; | ||
8324 | hi = (hi + Math.imul(ah8, bh3)) | 0; | ||
8325 | lo = (lo + Math.imul(al7, bl4)) | 0; | ||
8326 | mid = (mid + Math.imul(al7, bh4)) | 0; | ||
8327 | mid = (mid + Math.imul(ah7, bl4)) | 0; | ||
8328 | hi = (hi + Math.imul(ah7, bh4)) | 0; | ||
8329 | lo = (lo + Math.imul(al6, bl5)) | 0; | ||
8330 | mid = (mid + Math.imul(al6, bh5)) | 0; | ||
8331 | mid = (mid + Math.imul(ah6, bl5)) | 0; | ||
8332 | hi = (hi + Math.imul(ah6, bh5)) | 0; | ||
8333 | lo = (lo + Math.imul(al5, bl6)) | 0; | ||
8334 | mid = (mid + Math.imul(al5, bh6)) | 0; | ||
8335 | mid = (mid + Math.imul(ah5, bl6)) | 0; | ||
8336 | hi = (hi + Math.imul(ah5, bh6)) | 0; | ||
8337 | lo = (lo + Math.imul(al4, bl7)) | 0; | ||
8338 | mid = (mid + Math.imul(al4, bh7)) | 0; | ||
8339 | mid = (mid + Math.imul(ah4, bl7)) | 0; | ||
8340 | hi = (hi + Math.imul(ah4, bh7)) | 0; | ||
8341 | lo = (lo + Math.imul(al3, bl8)) | 0; | ||
8342 | mid = (mid + Math.imul(al3, bh8)) | 0; | ||
8343 | mid = (mid + Math.imul(ah3, bl8)) | 0; | ||
8344 | hi = (hi + Math.imul(ah3, bh8)) | 0; | ||
8345 | lo = (lo + Math.imul(al2, bl9)) | 0; | ||
8346 | mid = (mid + Math.imul(al2, bh9)) | 0; | ||
8347 | mid = (mid + Math.imul(ah2, bl9)) | 0; | ||
8348 | hi = (hi + Math.imul(ah2, bh9)) | 0; | ||
8349 | var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8350 | c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0; | ||
8351 | w11 &= 0x3ffffff; | ||
8352 | /* k = 12 */ | ||
8353 | lo = Math.imul(al9, bl3); | ||
8354 | mid = Math.imul(al9, bh3); | ||
8355 | mid = (mid + Math.imul(ah9, bl3)) | 0; | ||
8356 | hi = Math.imul(ah9, bh3); | ||
8357 | lo = (lo + Math.imul(al8, bl4)) | 0; | ||
8358 | mid = (mid + Math.imul(al8, bh4)) | 0; | ||
8359 | mid = (mid + Math.imul(ah8, bl4)) | 0; | ||
8360 | hi = (hi + Math.imul(ah8, bh4)) | 0; | ||
8361 | lo = (lo + Math.imul(al7, bl5)) | 0; | ||
8362 | mid = (mid + Math.imul(al7, bh5)) | 0; | ||
8363 | mid = (mid + Math.imul(ah7, bl5)) | 0; | ||
8364 | hi = (hi + Math.imul(ah7, bh5)) | 0; | ||
8365 | lo = (lo + Math.imul(al6, bl6)) | 0; | ||
8366 | mid = (mid + Math.imul(al6, bh6)) | 0; | ||
8367 | mid = (mid + Math.imul(ah6, bl6)) | 0; | ||
8368 | hi = (hi + Math.imul(ah6, bh6)) | 0; | ||
8369 | lo = (lo + Math.imul(al5, bl7)) | 0; | ||
8370 | mid = (mid + Math.imul(al5, bh7)) | 0; | ||
8371 | mid = (mid + Math.imul(ah5, bl7)) | 0; | ||
8372 | hi = (hi + Math.imul(ah5, bh7)) | 0; | ||
8373 | lo = (lo + Math.imul(al4, bl8)) | 0; | ||
8374 | mid = (mid + Math.imul(al4, bh8)) | 0; | ||
8375 | mid = (mid + Math.imul(ah4, bl8)) | 0; | ||
8376 | hi = (hi + Math.imul(ah4, bh8)) | 0; | ||
8377 | lo = (lo + Math.imul(al3, bl9)) | 0; | ||
8378 | mid = (mid + Math.imul(al3, bh9)) | 0; | ||
8379 | mid = (mid + Math.imul(ah3, bl9)) | 0; | ||
8380 | hi = (hi + Math.imul(ah3, bh9)) | 0; | ||
8381 | var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8382 | c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0; | ||
8383 | w12 &= 0x3ffffff; | ||
8384 | /* k = 13 */ | ||
8385 | lo = Math.imul(al9, bl4); | ||
8386 | mid = Math.imul(al9, bh4); | ||
8387 | mid = (mid + Math.imul(ah9, bl4)) | 0; | ||
8388 | hi = Math.imul(ah9, bh4); | ||
8389 | lo = (lo + Math.imul(al8, bl5)) | 0; | ||
8390 | mid = (mid + Math.imul(al8, bh5)) | 0; | ||
8391 | mid = (mid + Math.imul(ah8, bl5)) | 0; | ||
8392 | hi = (hi + Math.imul(ah8, bh5)) | 0; | ||
8393 | lo = (lo + Math.imul(al7, bl6)) | 0; | ||
8394 | mid = (mid + Math.imul(al7, bh6)) | 0; | ||
8395 | mid = (mid + Math.imul(ah7, bl6)) | 0; | ||
8396 | hi = (hi + Math.imul(ah7, bh6)) | 0; | ||
8397 | lo = (lo + Math.imul(al6, bl7)) | 0; | ||
8398 | mid = (mid + Math.imul(al6, bh7)) | 0; | ||
8399 | mid = (mid + Math.imul(ah6, bl7)) | 0; | ||
8400 | hi = (hi + Math.imul(ah6, bh7)) | 0; | ||
8401 | lo = (lo + Math.imul(al5, bl8)) | 0; | ||
8402 | mid = (mid + Math.imul(al5, bh8)) | 0; | ||
8403 | mid = (mid + Math.imul(ah5, bl8)) | 0; | ||
8404 | hi = (hi + Math.imul(ah5, bh8)) | 0; | ||
8405 | lo = (lo + Math.imul(al4, bl9)) | 0; | ||
8406 | mid = (mid + Math.imul(al4, bh9)) | 0; | ||
8407 | mid = (mid + Math.imul(ah4, bl9)) | 0; | ||
8408 | hi = (hi + Math.imul(ah4, bh9)) | 0; | ||
8409 | var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8410 | c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0; | ||
8411 | w13 &= 0x3ffffff; | ||
8412 | /* k = 14 */ | ||
8413 | lo = Math.imul(al9, bl5); | ||
8414 | mid = Math.imul(al9, bh5); | ||
8415 | mid = (mid + Math.imul(ah9, bl5)) | 0; | ||
8416 | hi = Math.imul(ah9, bh5); | ||
8417 | lo = (lo + Math.imul(al8, bl6)) | 0; | ||
8418 | mid = (mid + Math.imul(al8, bh6)) | 0; | ||
8419 | mid = (mid + Math.imul(ah8, bl6)) | 0; | ||
8420 | hi = (hi + Math.imul(ah8, bh6)) | 0; | ||
8421 | lo = (lo + Math.imul(al7, bl7)) | 0; | ||
8422 | mid = (mid + Math.imul(al7, bh7)) | 0; | ||
8423 | mid = (mid + Math.imul(ah7, bl7)) | 0; | ||
8424 | hi = (hi + Math.imul(ah7, bh7)) | 0; | ||
8425 | lo = (lo + Math.imul(al6, bl8)) | 0; | ||
8426 | mid = (mid + Math.imul(al6, bh8)) | 0; | ||
8427 | mid = (mid + Math.imul(ah6, bl8)) | 0; | ||
8428 | hi = (hi + Math.imul(ah6, bh8)) | 0; | ||
8429 | lo = (lo + Math.imul(al5, bl9)) | 0; | ||
8430 | mid = (mid + Math.imul(al5, bh9)) | 0; | ||
8431 | mid = (mid + Math.imul(ah5, bl9)) | 0; | ||
8432 | hi = (hi + Math.imul(ah5, bh9)) | 0; | ||
8433 | var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8434 | c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0; | ||
8435 | w14 &= 0x3ffffff; | ||
8436 | /* k = 15 */ | ||
8437 | lo = Math.imul(al9, bl6); | ||
8438 | mid = Math.imul(al9, bh6); | ||
8439 | mid = (mid + Math.imul(ah9, bl6)) | 0; | ||
8440 | hi = Math.imul(ah9, bh6); | ||
8441 | lo = (lo + Math.imul(al8, bl7)) | 0; | ||
8442 | mid = (mid + Math.imul(al8, bh7)) | 0; | ||
8443 | mid = (mid + Math.imul(ah8, bl7)) | 0; | ||
8444 | hi = (hi + Math.imul(ah8, bh7)) | 0; | ||
8445 | lo = (lo + Math.imul(al7, bl8)) | 0; | ||
8446 | mid = (mid + Math.imul(al7, bh8)) | 0; | ||
8447 | mid = (mid + Math.imul(ah7, bl8)) | 0; | ||
8448 | hi = (hi + Math.imul(ah7, bh8)) | 0; | ||
8449 | lo = (lo + Math.imul(al6, bl9)) | 0; | ||
8450 | mid = (mid + Math.imul(al6, bh9)) | 0; | ||
8451 | mid = (mid + Math.imul(ah6, bl9)) | 0; | ||
8452 | hi = (hi + Math.imul(ah6, bh9)) | 0; | ||
8453 | var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8454 | c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0; | ||
8455 | w15 &= 0x3ffffff; | ||
8456 | /* k = 16 */ | ||
8457 | lo = Math.imul(al9, bl7); | ||
8458 | mid = Math.imul(al9, bh7); | ||
8459 | mid = (mid + Math.imul(ah9, bl7)) | 0; | ||
8460 | hi = Math.imul(ah9, bh7); | ||
8461 | lo = (lo + Math.imul(al8, bl8)) | 0; | ||
8462 | mid = (mid + Math.imul(al8, bh8)) | 0; | ||
8463 | mid = (mid + Math.imul(ah8, bl8)) | 0; | ||
8464 | hi = (hi + Math.imul(ah8, bh8)) | 0; | ||
8465 | lo = (lo + Math.imul(al7, bl9)) | 0; | ||
8466 | mid = (mid + Math.imul(al7, bh9)) | 0; | ||
8467 | mid = (mid + Math.imul(ah7, bl9)) | 0; | ||
8468 | hi = (hi + Math.imul(ah7, bh9)) | 0; | ||
8469 | var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8470 | c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0; | ||
8471 | w16 &= 0x3ffffff; | ||
8472 | /* k = 17 */ | ||
8473 | lo = Math.imul(al9, bl8); | ||
8474 | mid = Math.imul(al9, bh8); | ||
8475 | mid = (mid + Math.imul(ah9, bl8)) | 0; | ||
8476 | hi = Math.imul(ah9, bh8); | ||
8477 | lo = (lo + Math.imul(al8, bl9)) | 0; | ||
8478 | mid = (mid + Math.imul(al8, bh9)) | 0; | ||
8479 | mid = (mid + Math.imul(ah8, bl9)) | 0; | ||
8480 | hi = (hi + Math.imul(ah8, bh9)) | 0; | ||
8481 | var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8482 | c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0; | ||
8483 | w17 &= 0x3ffffff; | ||
8484 | /* k = 18 */ | ||
8485 | lo = Math.imul(al9, bl9); | ||
8486 | mid = Math.imul(al9, bh9); | ||
8487 | mid = (mid + Math.imul(ah9, bl9)) | 0; | ||
8488 | hi = Math.imul(ah9, bh9); | ||
8489 | var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
8490 | c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0; | ||
8491 | w18 &= 0x3ffffff; | ||
8492 | o[0] = w0; | ||
8493 | o[1] = w1; | ||
8494 | o[2] = w2; | ||
8495 | o[3] = w3; | ||
8496 | o[4] = w4; | ||
8497 | o[5] = w5; | ||
8498 | o[6] = w6; | ||
8499 | o[7] = w7; | ||
8500 | o[8] = w8; | ||
8501 | o[9] = w9; | ||
8502 | o[10] = w10; | ||
8503 | o[11] = w11; | ||
8504 | o[12] = w12; | ||
8505 | o[13] = w13; | ||
8506 | o[14] = w14; | ||
8507 | o[15] = w15; | ||
8508 | o[16] = w16; | ||
8509 | o[17] = w17; | ||
8510 | o[18] = w18; | ||
8511 | if (c !== 0) { | ||
8512 | o[19] = c; | ||
8513 | out.length++; | ||
8514 | } | ||
8515 | return out; | ||
8516 | }; | ||
8517 | |||
8518 | // Polyfill comb | ||
8519 | if (!Math.imul) { | ||
8520 | comb10MulTo = smallMulTo; | ||
8521 | } | ||
8522 | |||
8523 | function bigMulTo (self, num, out) { | ||
8524 | out.negative = num.negative ^ self.negative; | ||
8525 | out.length = self.length + num.length; | ||
8526 | |||
8527 | var carry = 0; | ||
8528 | var hncarry = 0; | ||
8529 | for (var k = 0; k < out.length - 1; k++) { | ||
8530 | // Sum all words with the same `i + j = k` and accumulate `ncarry`, | ||
8531 | // note that ncarry could be >= 0x3ffffff | ||
8532 | var ncarry = hncarry; | ||
8533 | hncarry = 0; | ||
8534 | var rword = carry & 0x3ffffff; | ||
8535 | var maxJ = Math.min(k, num.length - 1); | ||
8536 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { | ||
8537 | var i = k - j; | ||
8538 | var a = self.words[i] | 0; | ||
8539 | var b = num.words[j] | 0; | ||
8540 | var r = a * b; | ||
8541 | |||
8542 | var lo = r & 0x3ffffff; | ||
8543 | ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0; | ||
8544 | lo = (lo + rword) | 0; | ||
8545 | rword = lo & 0x3ffffff; | ||
8546 | ncarry = (ncarry + (lo >>> 26)) | 0; | ||
8547 | |||
8548 | hncarry += ncarry >>> 26; | ||
8549 | ncarry &= 0x3ffffff; | ||
8550 | } | ||
8551 | out.words[k] = rword; | ||
8552 | carry = ncarry; | ||
8553 | ncarry = hncarry; | ||
8554 | } | ||
8555 | if (carry !== 0) { | ||
8556 | out.words[k] = carry; | ||
8557 | } else { | ||
8558 | out.length--; | ||
8559 | } | ||
8560 | |||
8561 | return out.strip(); | ||
8562 | } | ||
8563 | |||
8564 | function jumboMulTo (self, num, out) { | ||
8565 | var fftm = new FFTM(); | ||
8566 | return fftm.mulp(self, num, out); | ||
8567 | } | ||
8568 | |||
8569 | BN.prototype.mulTo = function mulTo (num, out) { | ||
8570 | var res; | ||
8571 | var len = this.length + num.length; | ||
8572 | if (this.length === 10 && num.length === 10) { | ||
8573 | res = comb10MulTo(this, num, out); | ||
8574 | } else if (len < 63) { | ||
8575 | res = smallMulTo(this, num, out); | ||
8576 | } else if (len < 1024) { | ||
8577 | res = bigMulTo(this, num, out); | ||
8578 | } else { | ||
8579 | res = jumboMulTo(this, num, out); | ||
8580 | } | ||
8581 | |||
8582 | return res; | ||
8583 | }; | ||
8584 | |||
8585 | // Cooley-Tukey algorithm for FFT | ||
8586 | // slightly revisited to rely on looping instead of recursion | ||
8587 | |||
8588 | function FFTM (x, y) { | ||
8589 | this.x = x; | ||
8590 | this.y = y; | ||
8591 | } | ||
8592 | |||
8593 | FFTM.prototype.makeRBT = function makeRBT (N) { | ||
8594 | var t = new Array(N); | ||
8595 | var l = BN.prototype._countBits(N) - 1; | ||
8596 | for (var i = 0; i < N; i++) { | ||
8597 | t[i] = this.revBin(i, l, N); | ||
8598 | } | ||
8599 | |||
8600 | return t; | ||
8601 | }; | ||
8602 | |||
8603 | // Returns binary-reversed representation of `x` | ||
8604 | FFTM.prototype.revBin = function revBin (x, l, N) { | ||
8605 | if (x === 0 || x === N - 1) return x; | ||
8606 | |||
8607 | var rb = 0; | ||
8608 | for (var i = 0; i < l; i++) { | ||
8609 | rb |= (x & 1) << (l - i - 1); | ||
8610 | x >>= 1; | ||
8611 | } | ||
8612 | |||
8613 | return rb; | ||
8614 | }; | ||
8615 | |||
8616 | // Performs "tweedling" phase, therefore 'emulating' | ||
8617 | // behaviour of the recursive algorithm | ||
8618 | FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) { | ||
8619 | for (var i = 0; i < N; i++) { | ||
8620 | rtws[i] = rws[rbt[i]]; | ||
8621 | itws[i] = iws[rbt[i]]; | ||
8622 | } | ||
8623 | }; | ||
8624 | |||
8625 | FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) { | ||
8626 | this.permute(rbt, rws, iws, rtws, itws, N); | ||
8627 | |||
8628 | for (var s = 1; s < N; s <<= 1) { | ||
8629 | var l = s << 1; | ||
8630 | |||
8631 | var rtwdf = Math.cos(2 * Math.PI / l); | ||
8632 | var itwdf = Math.sin(2 * Math.PI / l); | ||
8633 | |||
8634 | for (var p = 0; p < N; p += l) { | ||
8635 | var rtwdf_ = rtwdf; | ||
8636 | var itwdf_ = itwdf; | ||
8637 | |||
8638 | for (var j = 0; j < s; j++) { | ||
8639 | var re = rtws[p + j]; | ||
8640 | var ie = itws[p + j]; | ||
8641 | |||
8642 | var ro = rtws[p + j + s]; | ||
8643 | var io = itws[p + j + s]; | ||
8644 | |||
8645 | var rx = rtwdf_ * ro - itwdf_ * io; | ||
8646 | |||
8647 | io = rtwdf_ * io + itwdf_ * ro; | ||
8648 | ro = rx; | ||
8649 | |||
8650 | rtws[p + j] = re + ro; | ||
8651 | itws[p + j] = ie + io; | ||
8652 | |||
8653 | rtws[p + j + s] = re - ro; | ||
8654 | itws[p + j + s] = ie - io; | ||
8655 | |||
8656 | /* jshint maxdepth : false */ | ||
8657 | if (j !== l) { | ||
8658 | rx = rtwdf * rtwdf_ - itwdf * itwdf_; | ||
8659 | |||
8660 | itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; | ||
8661 | rtwdf_ = rx; | ||
8662 | } | ||
8663 | } | ||
8664 | } | ||
8665 | } | ||
8666 | }; | ||
8667 | |||
8668 | FFTM.prototype.guessLen13b = function guessLen13b (n, m) { | ||
8669 | var N = Math.max(m, n) | 1; | ||
8670 | var odd = N & 1; | ||
8671 | var i = 0; | ||
8672 | for (N = N / 2 | 0; N; N = N >>> 1) { | ||
8673 | i++; | ||
8674 | } | ||
8675 | |||
8676 | return 1 << i + 1 + odd; | ||
8677 | }; | ||
8678 | |||
8679 | FFTM.prototype.conjugate = function conjugate (rws, iws, N) { | ||
8680 | if (N <= 1) return; | ||
8681 | |||
8682 | for (var i = 0; i < N / 2; i++) { | ||
8683 | var t = rws[i]; | ||
8684 | |||
8685 | rws[i] = rws[N - i - 1]; | ||
8686 | rws[N - i - 1] = t; | ||
8687 | |||
8688 | t = iws[i]; | ||
8689 | |||
8690 | iws[i] = -iws[N - i - 1]; | ||
8691 | iws[N - i - 1] = -t; | ||
8692 | } | ||
8693 | }; | ||
8694 | |||
8695 | FFTM.prototype.normalize13b = function normalize13b (ws, N) { | ||
8696 | var carry = 0; | ||
8697 | for (var i = 0; i < N / 2; i++) { | ||
8698 | var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + | ||
8699 | Math.round(ws[2 * i] / N) + | ||
8700 | carry; | ||
8701 | |||
8702 | ws[i] = w & 0x3ffffff; | ||
8703 | |||
8704 | if (w < 0x4000000) { | ||
8705 | carry = 0; | ||
8706 | } else { | ||
8707 | carry = w / 0x4000000 | 0; | ||
8708 | } | ||
8709 | } | ||
8710 | |||
8711 | return ws; | ||
8712 | }; | ||
8713 | |||
8714 | FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) { | ||
8715 | var carry = 0; | ||
8716 | for (var i = 0; i < len; i++) { | ||
8717 | carry = carry + (ws[i] | 0); | ||
8718 | |||
8719 | rws[2 * i] = carry & 0x1fff; carry = carry >>> 13; | ||
8720 | rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13; | ||
8721 | } | ||
8722 | |||
8723 | // Pad with zeroes | ||
8724 | for (i = 2 * len; i < N; ++i) { | ||
8725 | rws[i] = 0; | ||
8726 | } | ||
8727 | |||
8728 | assert(carry === 0); | ||
8729 | assert((carry & ~0x1fff) === 0); | ||
8730 | }; | ||
8731 | |||
8732 | FFTM.prototype.stub = function stub (N) { | ||
8733 | var ph = new Array(N); | ||
8734 | for (var i = 0; i < N; i++) { | ||
8735 | ph[i] = 0; | ||
8736 | } | ||
8737 | |||
8738 | return ph; | ||
8739 | }; | ||
8740 | |||
8741 | FFTM.prototype.mulp = function mulp (x, y, out) { | ||
8742 | var N = 2 * this.guessLen13b(x.length, y.length); | ||
8743 | |||
8744 | var rbt = this.makeRBT(N); | ||
8745 | |||
8746 | var _ = this.stub(N); | ||
8747 | |||
8748 | var rws = new Array(N); | ||
8749 | var rwst = new Array(N); | ||
8750 | var iwst = new Array(N); | ||
8751 | |||
8752 | var nrws = new Array(N); | ||
8753 | var nrwst = new Array(N); | ||
8754 | var niwst = new Array(N); | ||
8755 | |||
8756 | var rmws = out.words; | ||
8757 | rmws.length = N; | ||
8758 | |||
8759 | this.convert13b(x.words, x.length, rws, N); | ||
8760 | this.convert13b(y.words, y.length, nrws, N); | ||
8761 | |||
8762 | this.transform(rws, _, rwst, iwst, N, rbt); | ||
8763 | this.transform(nrws, _, nrwst, niwst, N, rbt); | ||
8764 | |||
8765 | for (var i = 0; i < N; i++) { | ||
8766 | var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; | ||
8767 | iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; | ||
8768 | rwst[i] = rx; | ||
8769 | } | ||
8770 | |||
8771 | this.conjugate(rwst, iwst, N); | ||
8772 | this.transform(rwst, iwst, rmws, _, N, rbt); | ||
8773 | this.conjugate(rmws, _, N); | ||
8774 | this.normalize13b(rmws, N); | ||
8775 | |||
8776 | out.negative = x.negative ^ y.negative; | ||
8777 | out.length = x.length + y.length; | ||
8778 | return out.strip(); | ||
8779 | }; | ||
8780 | |||
8781 | // Multiply `this` by `num` | ||
8782 | BN.prototype.mul = function mul (num) { | ||
8783 | var out = new BN(null); | ||
8784 | out.words = new Array(this.length + num.length); | ||
8785 | return this.mulTo(num, out); | ||
8786 | }; | ||
8787 | |||
8788 | // Multiply employing FFT | ||
8789 | BN.prototype.mulf = function mulf (num) { | ||
8790 | var out = new BN(null); | ||
8791 | out.words = new Array(this.length + num.length); | ||
8792 | return jumboMulTo(this, num, out); | ||
8793 | }; | ||
8794 | |||
8795 | // In-place Multiplication | ||
8796 | BN.prototype.imul = function imul (num) { | ||
8797 | return this.clone().mulTo(num, this); | ||
8798 | }; | ||
8799 | |||
8800 | BN.prototype.imuln = function imuln (num) { | ||
8801 | assert(typeof num === 'number'); | ||
8802 | assert(num < 0x4000000); | ||
8803 | |||
8804 | // Carry | ||
8805 | var carry = 0; | ||
8806 | for (var i = 0; i < this.length; i++) { | ||
8807 | var w = (this.words[i] | 0) * num; | ||
8808 | var lo = (w & 0x3ffffff) + (carry & 0x3ffffff); | ||
8809 | carry >>= 26; | ||
8810 | carry += (w / 0x4000000) | 0; | ||
8811 | // NOTE: lo is 27bit maximum | ||
8812 | carry += lo >>> 26; | ||
8813 | this.words[i] = lo & 0x3ffffff; | ||
8814 | } | ||
8815 | |||
8816 | if (carry !== 0) { | ||
8817 | this.words[i] = carry; | ||
8818 | this.length++; | ||
8819 | } | ||
8820 | |||
8821 | return this; | ||
8822 | }; | ||
8823 | |||
8824 | BN.prototype.muln = function muln (num) { | ||
8825 | return this.clone().imuln(num); | ||
8826 | }; | ||
8827 | |||
8828 | // `this` * `this` | ||
8829 | BN.prototype.sqr = function sqr () { | ||
8830 | return this.mul(this); | ||
8831 | }; | ||
8832 | |||
8833 | // `this` * `this` in-place | ||
8834 | BN.prototype.isqr = function isqr () { | ||
8835 | return this.imul(this.clone()); | ||
8836 | }; | ||
8837 | |||
8838 | // Math.pow(`this`, `num`) | ||
8839 | BN.prototype.pow = function pow (num) { | ||
8840 | var w = toBitArray(num); | ||
8841 | if (w.length === 0) return new BN(1); | ||
8842 | |||
8843 | // Skip leading zeroes | ||
8844 | var res = this; | ||
8845 | for (var i = 0; i < w.length; i++, res = res.sqr()) { | ||
8846 | if (w[i] !== 0) break; | ||
8847 | } | ||
8848 | |||
8849 | if (++i < w.length) { | ||
8850 | for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { | ||
8851 | if (w[i] === 0) continue; | ||
8852 | |||
8853 | res = res.mul(q); | ||
8854 | } | ||
8855 | } | ||
8856 | |||
8857 | return res; | ||
8858 | }; | ||
8859 | |||
8860 | // Shift-left in-place | ||
8861 | BN.prototype.iushln = function iushln (bits) { | ||
8862 | assert(typeof bits === 'number' && bits >= 0); | ||
8863 | var r = bits % 26; | ||
8864 | var s = (bits - r) / 26; | ||
8865 | var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r); | ||
8866 | var i; | ||
8867 | |||
8868 | if (r !== 0) { | ||
8869 | var carry = 0; | ||
8870 | |||
8871 | for (i = 0; i < this.length; i++) { | ||
8872 | var newCarry = this.words[i] & carryMask; | ||
8873 | var c = ((this.words[i] | 0) - newCarry) << r; | ||
8874 | this.words[i] = c | carry; | ||
8875 | carry = newCarry >>> (26 - r); | ||
8876 | } | ||
8877 | |||
8878 | if (carry) { | ||
8879 | this.words[i] = carry; | ||
8880 | this.length++; | ||
8881 | } | ||
8882 | } | ||
8883 | |||
8884 | if (s !== 0) { | ||
8885 | for (i = this.length - 1; i >= 0; i--) { | ||
8886 | this.words[i + s] = this.words[i]; | ||
8887 | } | ||
8888 | |||
8889 | for (i = 0; i < s; i++) { | ||
8890 | this.words[i] = 0; | ||
8891 | } | ||
8892 | |||
8893 | this.length += s; | ||
8894 | } | ||
8895 | |||
8896 | return this.strip(); | ||
8897 | }; | ||
8898 | |||
8899 | BN.prototype.ishln = function ishln (bits) { | ||
8900 | // TODO(indutny): implement me | ||
8901 | assert(this.negative === 0); | ||
8902 | return this.iushln(bits); | ||
8903 | }; | ||
8904 | |||
8905 | // Shift-right in-place | ||
8906 | // NOTE: `hint` is a lowest bit before trailing zeroes | ||
8907 | // NOTE: if `extended` is present - it will be filled with destroyed bits | ||
8908 | BN.prototype.iushrn = function iushrn (bits, hint, extended) { | ||
8909 | assert(typeof bits === 'number' && bits >= 0); | ||
8910 | var h; | ||
8911 | if (hint) { | ||
8912 | h = (hint - (hint % 26)) / 26; | ||
8913 | } else { | ||
8914 | h = 0; | ||
8915 | } | ||
8916 | |||
8917 | var r = bits % 26; | ||
8918 | var s = Math.min((bits - r) / 26, this.length); | ||
8919 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); | ||
8920 | var maskedWords = extended; | ||
8921 | |||
8922 | h -= s; | ||
8923 | h = Math.max(0, h); | ||
8924 | |||
8925 | // Extended mode, copy masked part | ||
8926 | if (maskedWords) { | ||
8927 | for (var i = 0; i < s; i++) { | ||
8928 | maskedWords.words[i] = this.words[i]; | ||
8929 | } | ||
8930 | maskedWords.length = s; | ||
8931 | } | ||
8932 | |||
8933 | if (s === 0) { | ||
8934 | // No-op, we should not move anything at all | ||
8935 | } else if (this.length > s) { | ||
8936 | this.length -= s; | ||
8937 | for (i = 0; i < this.length; i++) { | ||
8938 | this.words[i] = this.words[i + s]; | ||
8939 | } | ||
8940 | } else { | ||
8941 | this.words[0] = 0; | ||
8942 | this.length = 1; | ||
8943 | } | ||
8944 | |||
8945 | var carry = 0; | ||
8946 | for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { | ||
8947 | var word = this.words[i] | 0; | ||
8948 | this.words[i] = (carry << (26 - r)) | (word >>> r); | ||
8949 | carry = word & mask; | ||
8950 | } | ||
8951 | |||
8952 | // Push carried bits as a mask | ||
8953 | if (maskedWords && carry !== 0) { | ||
8954 | maskedWords.words[maskedWords.length++] = carry; | ||
8955 | } | ||
8956 | |||
8957 | if (this.length === 0) { | ||
8958 | this.words[0] = 0; | ||
8959 | this.length = 1; | ||
8960 | } | ||
8961 | |||
8962 | return this.strip(); | ||
8963 | }; | ||
8964 | |||
8965 | BN.prototype.ishrn = function ishrn (bits, hint, extended) { | ||
8966 | // TODO(indutny): implement me | ||
8967 | assert(this.negative === 0); | ||
8968 | return this.iushrn(bits, hint, extended); | ||
8969 | }; | ||
8970 | |||
8971 | // Shift-left | ||
8972 | BN.prototype.shln = function shln (bits) { | ||
8973 | return this.clone().ishln(bits); | ||
8974 | }; | ||
8975 | |||
8976 | BN.prototype.ushln = function ushln (bits) { | ||
8977 | return this.clone().iushln(bits); | ||
8978 | }; | ||
8979 | |||
8980 | // Shift-right | ||
8981 | BN.prototype.shrn = function shrn (bits) { | ||
8982 | return this.clone().ishrn(bits); | ||
8983 | }; | ||
8984 | |||
8985 | BN.prototype.ushrn = function ushrn (bits) { | ||
8986 | return this.clone().iushrn(bits); | ||
8987 | }; | ||
8988 | |||
8989 | // Test if n bit is set | ||
8990 | BN.prototype.testn = function testn (bit) { | ||
8991 | assert(typeof bit === 'number' && bit >= 0); | ||
8992 | var r = bit % 26; | ||
8993 | var s = (bit - r) / 26; | ||
8994 | var q = 1 << r; | ||
8995 | |||
8996 | // Fast case: bit is much higher than all existing words | ||
8997 | if (this.length <= s) return false; | ||
8998 | |||
8999 | // Check bit and return | ||
9000 | var w = this.words[s]; | ||
9001 | |||
9002 | return !!(w & q); | ||
9003 | }; | ||
9004 | |||
9005 | // Return only lowers bits of number (in-place) | ||
9006 | BN.prototype.imaskn = function imaskn (bits) { | ||
9007 | assert(typeof bits === 'number' && bits >= 0); | ||
9008 | var r = bits % 26; | ||
9009 | var s = (bits - r) / 26; | ||
9010 | |||
9011 | assert(this.negative === 0, 'imaskn works only with positive numbers'); | ||
9012 | |||
9013 | if (this.length <= s) { | ||
9014 | return this; | ||
9015 | } | ||
9016 | |||
9017 | if (r !== 0) { | ||
9018 | s++; | ||
9019 | } | ||
9020 | this.length = Math.min(s, this.length); | ||
9021 | |||
9022 | if (r !== 0) { | ||
9023 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); | ||
9024 | this.words[this.length - 1] &= mask; | ||
9025 | } | ||
9026 | |||
9027 | return this.strip(); | ||
9028 | }; | ||
9029 | |||
9030 | // Return only lowers bits of number | ||
9031 | BN.prototype.maskn = function maskn (bits) { | ||
9032 | return this.clone().imaskn(bits); | ||
9033 | }; | ||
9034 | |||
9035 | // Add plain number `num` to `this` | ||
9036 | BN.prototype.iaddn = function iaddn (num) { | ||
9037 | assert(typeof num === 'number'); | ||
9038 | assert(num < 0x4000000); | ||
9039 | if (num < 0) return this.isubn(-num); | ||
9040 | |||
9041 | // Possible sign change | ||
9042 | if (this.negative !== 0) { | ||
9043 | if (this.length === 1 && (this.words[0] | 0) < num) { | ||
9044 | this.words[0] = num - (this.words[0] | 0); | ||
9045 | this.negative = 0; | ||
9046 | return this; | ||
9047 | } | ||
9048 | |||
9049 | this.negative = 0; | ||
9050 | this.isubn(num); | ||
9051 | this.negative = 1; | ||
9052 | return this; | ||
9053 | } | ||
9054 | |||
9055 | // Add without checks | ||
9056 | return this._iaddn(num); | ||
9057 | }; | ||
9058 | |||
9059 | BN.prototype._iaddn = function _iaddn (num) { | ||
9060 | this.words[0] += num; | ||
9061 | |||
9062 | // Carry | ||
9063 | for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) { | ||
9064 | this.words[i] -= 0x4000000; | ||
9065 | if (i === this.length - 1) { | ||
9066 | this.words[i + 1] = 1; | ||
9067 | } else { | ||
9068 | this.words[i + 1]++; | ||
9069 | } | ||
9070 | } | ||
9071 | this.length = Math.max(this.length, i + 1); | ||
9072 | |||
9073 | return this; | ||
9074 | }; | ||
9075 | |||
9076 | // Subtract plain number `num` from `this` | ||
9077 | BN.prototype.isubn = function isubn (num) { | ||
9078 | assert(typeof num === 'number'); | ||
9079 | assert(num < 0x4000000); | ||
9080 | if (num < 0) return this.iaddn(-num); | ||
9081 | |||
9082 | if (this.negative !== 0) { | ||
9083 | this.negative = 0; | ||
9084 | this.iaddn(num); | ||
9085 | this.negative = 1; | ||
9086 | return this; | ||
9087 | } | ||
9088 | |||
9089 | this.words[0] -= num; | ||
9090 | |||
9091 | if (this.length === 1 && this.words[0] < 0) { | ||
9092 | this.words[0] = -this.words[0]; | ||
9093 | this.negative = 1; | ||
9094 | } else { | ||
9095 | // Carry | ||
9096 | for (var i = 0; i < this.length && this.words[i] < 0; i++) { | ||
9097 | this.words[i] += 0x4000000; | ||
9098 | this.words[i + 1] -= 1; | ||
9099 | } | ||
9100 | } | ||
9101 | |||
9102 | return this.strip(); | ||
9103 | }; | ||
9104 | |||
9105 | BN.prototype.addn = function addn (num) { | ||
9106 | return this.clone().iaddn(num); | ||
9107 | }; | ||
9108 | |||
9109 | BN.prototype.subn = function subn (num) { | ||
9110 | return this.clone().isubn(num); | ||
9111 | }; | ||
9112 | |||
9113 | BN.prototype.iabs = function iabs () { | ||
9114 | this.negative = 0; | ||
9115 | |||
9116 | return this; | ||
9117 | }; | ||
9118 | |||
9119 | BN.prototype.abs = function abs () { | ||
9120 | return this.clone().iabs(); | ||
9121 | }; | ||
9122 | |||
9123 | BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) { | ||
9124 | var len = num.length + shift; | ||
9125 | var i; | ||
9126 | |||
9127 | this._expand(len); | ||
9128 | |||
9129 | var w; | ||
9130 | var carry = 0; | ||
9131 | for (i = 0; i < num.length; i++) { | ||
9132 | w = (this.words[i + shift] | 0) + carry; | ||
9133 | var right = (num.words[i] | 0) * mul; | ||
9134 | w -= right & 0x3ffffff; | ||
9135 | carry = (w >> 26) - ((right / 0x4000000) | 0); | ||
9136 | this.words[i + shift] = w & 0x3ffffff; | ||
9137 | } | ||
9138 | for (; i < this.length - shift; i++) { | ||
9139 | w = (this.words[i + shift] | 0) + carry; | ||
9140 | carry = w >> 26; | ||
9141 | this.words[i + shift] = w & 0x3ffffff; | ||
9142 | } | ||
9143 | |||
9144 | if (carry === 0) return this.strip(); | ||
9145 | |||
9146 | // Subtraction overflow | ||
9147 | assert(carry === -1); | ||
9148 | carry = 0; | ||
9149 | for (i = 0; i < this.length; i++) { | ||
9150 | w = -(this.words[i] | 0) + carry; | ||
9151 | carry = w >> 26; | ||
9152 | this.words[i] = w & 0x3ffffff; | ||
9153 | } | ||
9154 | this.negative = 1; | ||
9155 | |||
9156 | return this.strip(); | ||
9157 | }; | ||
9158 | |||
9159 | BN.prototype._wordDiv = function _wordDiv (num, mode) { | ||
9160 | var shift = this.length - num.length; | ||
9161 | |||
9162 | var a = this.clone(); | ||
9163 | var b = num; | ||
9164 | |||
9165 | // Normalize | ||
9166 | var bhi = b.words[b.length - 1] | 0; | ||
9167 | var bhiBits = this._countBits(bhi); | ||
9168 | shift = 26 - bhiBits; | ||
9169 | if (shift !== 0) { | ||
9170 | b = b.ushln(shift); | ||
9171 | a.iushln(shift); | ||
9172 | bhi = b.words[b.length - 1] | 0; | ||
9173 | } | ||
9174 | |||
9175 | // Initialize quotient | ||
9176 | var m = a.length - b.length; | ||
9177 | var q; | ||
9178 | |||
9179 | if (mode !== 'mod') { | ||
9180 | q = new BN(null); | ||
9181 | q.length = m + 1; | ||
9182 | q.words = new Array(q.length); | ||
9183 | for (var i = 0; i < q.length; i++) { | ||
9184 | q.words[i] = 0; | ||
9185 | } | ||
9186 | } | ||
9187 | |||
9188 | var diff = a.clone()._ishlnsubmul(b, 1, m); | ||
9189 | if (diff.negative === 0) { | ||
9190 | a = diff; | ||
9191 | if (q) { | ||
9192 | q.words[m] = 1; | ||
9193 | } | ||
9194 | } | ||
9195 | |||
9196 | for (var j = m - 1; j >= 0; j--) { | ||
9197 | var qj = (a.words[b.length + j] | 0) * 0x4000000 + | ||
9198 | (a.words[b.length + j - 1] | 0); | ||
9199 | |||
9200 | // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max | ||
9201 | // (0x7ffffff) | ||
9202 | qj = Math.min((qj / bhi) | 0, 0x3ffffff); | ||
9203 | |||
9204 | a._ishlnsubmul(b, qj, j); | ||
9205 | while (a.negative !== 0) { | ||
9206 | qj--; | ||
9207 | a.negative = 0; | ||
9208 | a._ishlnsubmul(b, 1, j); | ||
9209 | if (!a.isZero()) { | ||
9210 | a.negative ^= 1; | ||
9211 | } | ||
9212 | } | ||
9213 | if (q) { | ||
9214 | q.words[j] = qj; | ||
9215 | } | ||
9216 | } | ||
9217 | if (q) { | ||
9218 | q.strip(); | ||
9219 | } | ||
9220 | a.strip(); | ||
9221 | |||
9222 | // Denormalize | ||
9223 | if (mode !== 'div' && shift !== 0) { | ||
9224 | a.iushrn(shift); | ||
9225 | } | ||
9226 | |||
9227 | return { | ||
9228 | div: q || null, | ||
9229 | mod: a | ||
9230 | }; | ||
9231 | }; | ||
9232 | |||
9233 | // NOTE: 1) `mode` can be set to `mod` to request mod only, | ||
9234 | // to `div` to request div only, or be absent to | ||
9235 | // request both div & mod | ||
9236 | // 2) `positive` is true if unsigned mod is requested | ||
9237 | BN.prototype.divmod = function divmod (num, mode, positive) { | ||
9238 | assert(!num.isZero()); | ||
9239 | |||
9240 | if (this.isZero()) { | ||
9241 | return { | ||
9242 | div: new BN(0), | ||
9243 | mod: new BN(0) | ||
9244 | }; | ||
9245 | } | ||
9246 | |||
9247 | var div, mod, res; | ||
9248 | if (this.negative !== 0 && num.negative === 0) { | ||
9249 | res = this.neg().divmod(num, mode); | ||
9250 | |||
9251 | if (mode !== 'mod') { | ||
9252 | div = res.div.neg(); | ||
9253 | } | ||
9254 | |||
9255 | if (mode !== 'div') { | ||
9256 | mod = res.mod.neg(); | ||
9257 | if (positive && mod.negative !== 0) { | ||
9258 | mod.iadd(num); | ||
9259 | } | ||
9260 | } | ||
9261 | |||
9262 | return { | ||
9263 | div: div, | ||
9264 | mod: mod | ||
9265 | }; | ||
9266 | } | ||
9267 | |||
9268 | if (this.negative === 0 && num.negative !== 0) { | ||
9269 | res = this.divmod(num.neg(), mode); | ||
9270 | |||
9271 | if (mode !== 'mod') { | ||
9272 | div = res.div.neg(); | ||
9273 | } | ||
9274 | |||
9275 | return { | ||
9276 | div: div, | ||
9277 | mod: res.mod | ||
9278 | }; | ||
9279 | } | ||
9280 | |||
9281 | if ((this.negative & num.negative) !== 0) { | ||
9282 | res = this.neg().divmod(num.neg(), mode); | ||
9283 | |||
9284 | if (mode !== 'div') { | ||
9285 | mod = res.mod.neg(); | ||
9286 | if (positive && mod.negative !== 0) { | ||
9287 | mod.isub(num); | ||
9288 | } | ||
9289 | } | ||
9290 | |||
9291 | return { | ||
9292 | div: res.div, | ||
9293 | mod: mod | ||
9294 | }; | ||
9295 | } | ||
9296 | |||
9297 | // Both numbers are positive at this point | ||
9298 | |||
9299 | // Strip both numbers to approximate shift value | ||
9300 | if (num.length > this.length || this.cmp(num) < 0) { | ||
9301 | return { | ||
9302 | div: new BN(0), | ||
9303 | mod: this | ||
9304 | }; | ||
9305 | } | ||
9306 | |||
9307 | // Very short reduction | ||
9308 | if (num.length === 1) { | ||
9309 | if (mode === 'div') { | ||
9310 | return { | ||
9311 | div: this.divn(num.words[0]), | ||
9312 | mod: null | ||
9313 | }; | ||
9314 | } | ||
9315 | |||
9316 | if (mode === 'mod') { | ||
9317 | return { | ||
9318 | div: null, | ||
9319 | mod: new BN(this.modn(num.words[0])) | ||
9320 | }; | ||
9321 | } | ||
9322 | |||
9323 | return { | ||
9324 | div: this.divn(num.words[0]), | ||
9325 | mod: new BN(this.modn(num.words[0])) | ||
9326 | }; | ||
9327 | } | ||
9328 | |||
9329 | return this._wordDiv(num, mode); | ||
9330 | }; | ||
9331 | |||
9332 | // Find `this` / `num` | ||
9333 | BN.prototype.div = function div (num) { | ||
9334 | return this.divmod(num, 'div', false).div; | ||
9335 | }; | ||
9336 | |||
9337 | // Find `this` % `num` | ||
9338 | BN.prototype.mod = function mod (num) { | ||
9339 | return this.divmod(num, 'mod', false).mod; | ||
9340 | }; | ||
9341 | |||
9342 | BN.prototype.umod = function umod (num) { | ||
9343 | return this.divmod(num, 'mod', true).mod; | ||
9344 | }; | ||
9345 | |||
9346 | // Find Round(`this` / `num`) | ||
9347 | BN.prototype.divRound = function divRound (num) { | ||
9348 | var dm = this.divmod(num); | ||
9349 | |||
9350 | // Fast case - exact division | ||
9351 | if (dm.mod.isZero()) return dm.div; | ||
9352 | |||
9353 | var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; | ||
9354 | |||
9355 | var half = num.ushrn(1); | ||
9356 | var r2 = num.andln(1); | ||
9357 | var cmp = mod.cmp(half); | ||
9358 | |||
9359 | // Round down | ||
9360 | if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; | ||
9361 | |||
9362 | // Round up | ||
9363 | return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); | ||
9364 | }; | ||
9365 | |||
9366 | BN.prototype.modn = function modn (num) { | ||
9367 | assert(num <= 0x3ffffff); | ||
9368 | var p = (1 << 26) % num; | ||
9369 | |||
9370 | var acc = 0; | ||
9371 | for (var i = this.length - 1; i >= 0; i--) { | ||
9372 | acc = (p * acc + (this.words[i] | 0)) % num; | ||
9373 | } | ||
9374 | |||
9375 | return acc; | ||
9376 | }; | ||
9377 | |||
9378 | // In-place division by number | ||
9379 | BN.prototype.idivn = function idivn (num) { | ||
9380 | assert(num <= 0x3ffffff); | ||
9381 | |||
9382 | var carry = 0; | ||
9383 | for (var i = this.length - 1; i >= 0; i--) { | ||
9384 | var w = (this.words[i] | 0) + carry * 0x4000000; | ||
9385 | this.words[i] = (w / num) | 0; | ||
9386 | carry = w % num; | ||
9387 | } | ||
9388 | |||
9389 | return this.strip(); | ||
9390 | }; | ||
9391 | |||
9392 | BN.prototype.divn = function divn (num) { | ||
9393 | return this.clone().idivn(num); | ||
9394 | }; | ||
9395 | |||
9396 | BN.prototype.egcd = function egcd (p) { | ||
9397 | assert(p.negative === 0); | ||
9398 | assert(!p.isZero()); | ||
9399 | |||
9400 | var x = this; | ||
9401 | var y = p.clone(); | ||
9402 | |||
9403 | if (x.negative !== 0) { | ||
9404 | x = x.umod(p); | ||
9405 | } else { | ||
9406 | x = x.clone(); | ||
9407 | } | ||
9408 | |||
9409 | // A * x + B * y = x | ||
9410 | var A = new BN(1); | ||
9411 | var B = new BN(0); | ||
9412 | |||
9413 | // C * x + D * y = y | ||
9414 | var C = new BN(0); | ||
9415 | var D = new BN(1); | ||
9416 | |||
9417 | var g = 0; | ||
9418 | |||
9419 | while (x.isEven() && y.isEven()) { | ||
9420 | x.iushrn(1); | ||
9421 | y.iushrn(1); | ||
9422 | ++g; | ||
9423 | } | ||
9424 | |||
9425 | var yp = y.clone(); | ||
9426 | var xp = x.clone(); | ||
9427 | |||
9428 | while (!x.isZero()) { | ||
9429 | for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); | ||
9430 | if (i > 0) { | ||
9431 | x.iushrn(i); | ||
9432 | while (i-- > 0) { | ||
9433 | if (A.isOdd() || B.isOdd()) { | ||
9434 | A.iadd(yp); | ||
9435 | B.isub(xp); | ||
9436 | } | ||
9437 | |||
9438 | A.iushrn(1); | ||
9439 | B.iushrn(1); | ||
9440 | } | ||
9441 | } | ||
9442 | |||
9443 | for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); | ||
9444 | if (j > 0) { | ||
9445 | y.iushrn(j); | ||
9446 | while (j-- > 0) { | ||
9447 | if (C.isOdd() || D.isOdd()) { | ||
9448 | C.iadd(yp); | ||
9449 | D.isub(xp); | ||
9450 | } | ||
9451 | |||
9452 | C.iushrn(1); | ||
9453 | D.iushrn(1); | ||
9454 | } | ||
9455 | } | ||
9456 | |||
9457 | if (x.cmp(y) >= 0) { | ||
9458 | x.isub(y); | ||
9459 | A.isub(C); | ||
9460 | B.isub(D); | ||
9461 | } else { | ||
9462 | y.isub(x); | ||
9463 | C.isub(A); | ||
9464 | D.isub(B); | ||
9465 | } | ||
9466 | } | ||
9467 | |||
9468 | return { | ||
9469 | a: C, | ||
9470 | b: D, | ||
9471 | gcd: y.iushln(g) | ||
9472 | }; | ||
9473 | }; | ||
9474 | |||
9475 | // This is reduced incarnation of the binary EEA | ||
9476 | // above, designated to invert members of the | ||
9477 | // _prime_ fields F(p) at a maximal speed | ||
9478 | BN.prototype._invmp = function _invmp (p) { | ||
9479 | assert(p.negative === 0); | ||
9480 | assert(!p.isZero()); | ||
9481 | |||
9482 | var a = this; | ||
9483 | var b = p.clone(); | ||
9484 | |||
9485 | if (a.negative !== 0) { | ||
9486 | a = a.umod(p); | ||
9487 | } else { | ||
9488 | a = a.clone(); | ||
9489 | } | ||
9490 | |||
9491 | var x1 = new BN(1); | ||
9492 | var x2 = new BN(0); | ||
9493 | |||
9494 | var delta = b.clone(); | ||
9495 | |||
9496 | while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { | ||
9497 | for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); | ||
9498 | if (i > 0) { | ||
9499 | a.iushrn(i); | ||
9500 | while (i-- > 0) { | ||
9501 | if (x1.isOdd()) { | ||
9502 | x1.iadd(delta); | ||
9503 | } | ||
9504 | |||
9505 | x1.iushrn(1); | ||
9506 | } | ||
9507 | } | ||
9508 | |||
9509 | for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); | ||
9510 | if (j > 0) { | ||
9511 | b.iushrn(j); | ||
9512 | while (j-- > 0) { | ||
9513 | if (x2.isOdd()) { | ||
9514 | x2.iadd(delta); | ||
9515 | } | ||
9516 | |||
9517 | x2.iushrn(1); | ||
9518 | } | ||
9519 | } | ||
9520 | |||
9521 | if (a.cmp(b) >= 0) { | ||
9522 | a.isub(b); | ||
9523 | x1.isub(x2); | ||
9524 | } else { | ||
9525 | b.isub(a); | ||
9526 | x2.isub(x1); | ||
9527 | } | ||
9528 | } | ||
9529 | |||
9530 | var res; | ||
9531 | if (a.cmpn(1) === 0) { | ||
9532 | res = x1; | ||
9533 | } else { | ||
9534 | res = x2; | ||
9535 | } | ||
9536 | |||
9537 | if (res.cmpn(0) < 0) { | ||
9538 | res.iadd(p); | ||
9539 | } | ||
9540 | |||
9541 | return res; | ||
9542 | }; | ||
9543 | |||
9544 | BN.prototype.gcd = function gcd (num) { | ||
9545 | if (this.isZero()) return num.abs(); | ||
9546 | if (num.isZero()) return this.abs(); | ||
9547 | |||
9548 | var a = this.clone(); | ||
9549 | var b = num.clone(); | ||
9550 | a.negative = 0; | ||
9551 | b.negative = 0; | ||
9552 | |||
9553 | // Remove common factor of two | ||
9554 | for (var shift = 0; a.isEven() && b.isEven(); shift++) { | ||
9555 | a.iushrn(1); | ||
9556 | b.iushrn(1); | ||
9557 | } | ||
9558 | |||
9559 | do { | ||
9560 | while (a.isEven()) { | ||
9561 | a.iushrn(1); | ||
9562 | } | ||
9563 | while (b.isEven()) { | ||
9564 | b.iushrn(1); | ||
9565 | } | ||
9566 | |||
9567 | var r = a.cmp(b); | ||
9568 | if (r < 0) { | ||
9569 | // Swap `a` and `b` to make `a` always bigger than `b` | ||
9570 | var t = a; | ||
9571 | a = b; | ||
9572 | b = t; | ||
9573 | } else if (r === 0 || b.cmpn(1) === 0) { | ||
9574 | break; | ||
9575 | } | ||
9576 | |||
9577 | a.isub(b); | ||
9578 | } while (true); | ||
9579 | |||
9580 | return b.iushln(shift); | ||
9581 | }; | ||
9582 | |||
9583 | // Invert number in the field F(num) | ||
9584 | BN.prototype.invm = function invm (num) { | ||
9585 | return this.egcd(num).a.umod(num); | ||
9586 | }; | ||
9587 | |||
9588 | BN.prototype.isEven = function isEven () { | ||
9589 | return (this.words[0] & 1) === 0; | ||
9590 | }; | ||
9591 | |||
9592 | BN.prototype.isOdd = function isOdd () { | ||
9593 | return (this.words[0] & 1) === 1; | ||
9594 | }; | ||
9595 | |||
9596 | // And first word and num | ||
9597 | BN.prototype.andln = function andln (num) { | ||
9598 | return this.words[0] & num; | ||
9599 | }; | ||
9600 | |||
9601 | // Increment at the bit position in-line | ||
9602 | BN.prototype.bincn = function bincn (bit) { | ||
9603 | assert(typeof bit === 'number'); | ||
9604 | var r = bit % 26; | ||
9605 | var s = (bit - r) / 26; | ||
9606 | var q = 1 << r; | ||
9607 | |||
9608 | // Fast case: bit is much higher than all existing words | ||
9609 | if (this.length <= s) { | ||
9610 | this._expand(s + 1); | ||
9611 | this.words[s] |= q; | ||
9612 | return this; | ||
9613 | } | ||
9614 | |||
9615 | // Add bit and propagate, if needed | ||
9616 | var carry = q; | ||
9617 | for (var i = s; carry !== 0 && i < this.length; i++) { | ||
9618 | var w = this.words[i] | 0; | ||
9619 | w += carry; | ||
9620 | carry = w >>> 26; | ||
9621 | w &= 0x3ffffff; | ||
9622 | this.words[i] = w; | ||
9623 | } | ||
9624 | if (carry !== 0) { | ||
9625 | this.words[i] = carry; | ||
9626 | this.length++; | ||
9627 | } | ||
9628 | return this; | ||
9629 | }; | ||
9630 | |||
9631 | BN.prototype.isZero = function isZero () { | ||
9632 | return this.length === 1 && this.words[0] === 0; | ||
9633 | }; | ||
9634 | |||
9635 | BN.prototype.cmpn = function cmpn (num) { | ||
9636 | var negative = num < 0; | ||
9637 | |||
9638 | if (this.negative !== 0 && !negative) return -1; | ||
9639 | if (this.negative === 0 && negative) return 1; | ||
9640 | |||
9641 | this.strip(); | ||
9642 | |||
9643 | var res; | ||
9644 | if (this.length > 1) { | ||
9645 | res = 1; | ||
9646 | } else { | ||
9647 | if (negative) { | ||
9648 | num = -num; | ||
9649 | } | ||
9650 | |||
9651 | assert(num <= 0x3ffffff, 'Number is too big'); | ||
9652 | |||
9653 | var w = this.words[0] | 0; | ||
9654 | res = w === num ? 0 : w < num ? -1 : 1; | ||
9655 | } | ||
9656 | if (this.negative !== 0) return -res | 0; | ||
9657 | return res; | ||
9658 | }; | ||
9659 | |||
9660 | // Compare two numbers and return: | ||
9661 | // 1 - if `this` > `num` | ||
9662 | // 0 - if `this` == `num` | ||
9663 | // -1 - if `this` < `num` | ||
9664 | BN.prototype.cmp = function cmp (num) { | ||
9665 | if (this.negative !== 0 && num.negative === 0) return -1; | ||
9666 | if (this.negative === 0 && num.negative !== 0) return 1; | ||
9667 | |||
9668 | var res = this.ucmp(num); | ||
9669 | if (this.negative !== 0) return -res | 0; | ||
9670 | return res; | ||
9671 | }; | ||
9672 | |||
9673 | // Unsigned comparison | ||
9674 | BN.prototype.ucmp = function ucmp (num) { | ||
9675 | // At this point both numbers have the same sign | ||
9676 | if (this.length > num.length) return 1; | ||
9677 | if (this.length < num.length) return -1; | ||
9678 | |||
9679 | var res = 0; | ||
9680 | for (var i = this.length - 1; i >= 0; i--) { | ||
9681 | var a = this.words[i] | 0; | ||
9682 | var b = num.words[i] | 0; | ||
9683 | |||
9684 | if (a === b) continue; | ||
9685 | if (a < b) { | ||
9686 | res = -1; | ||
9687 | } else if (a > b) { | ||
9688 | res = 1; | ||
9689 | } | ||
9690 | break; | ||
9691 | } | ||
9692 | return res; | ||
9693 | }; | ||
9694 | |||
9695 | BN.prototype.gtn = function gtn (num) { | ||
9696 | return this.cmpn(num) === 1; | ||
9697 | }; | ||
9698 | |||
9699 | BN.prototype.gt = function gt (num) { | ||
9700 | return this.cmp(num) === 1; | ||
9701 | }; | ||
9702 | |||
9703 | BN.prototype.gten = function gten (num) { | ||
9704 | return this.cmpn(num) >= 0; | ||
9705 | }; | ||
9706 | |||
9707 | BN.prototype.gte = function gte (num) { | ||
9708 | return this.cmp(num) >= 0; | ||
9709 | }; | ||
9710 | |||
9711 | BN.prototype.ltn = function ltn (num) { | ||
9712 | return this.cmpn(num) === -1; | ||
9713 | }; | ||
9714 | |||
9715 | BN.prototype.lt = function lt (num) { | ||
9716 | return this.cmp(num) === -1; | ||
9717 | }; | ||
9718 | |||
9719 | BN.prototype.lten = function lten (num) { | ||
9720 | return this.cmpn(num) <= 0; | ||
9721 | }; | ||
9722 | |||
9723 | BN.prototype.lte = function lte (num) { | ||
9724 | return this.cmp(num) <= 0; | ||
9725 | }; | ||
9726 | |||
9727 | BN.prototype.eqn = function eqn (num) { | ||
9728 | return this.cmpn(num) === 0; | ||
9729 | }; | ||
9730 | |||
9731 | BN.prototype.eq = function eq (num) { | ||
9732 | return this.cmp(num) === 0; | ||
9733 | }; | ||
9734 | |||
9735 | // | ||
9736 | // A reduce context, could be using montgomery or something better, depending | ||
9737 | // on the `m` itself. | ||
9738 | // | ||
9739 | BN.red = function red (num) { | ||
9740 | return new Red(num); | ||
9741 | }; | ||
9742 | |||
9743 | BN.prototype.toRed = function toRed (ctx) { | ||
9744 | assert(!this.red, 'Already a number in reduction context'); | ||
9745 | assert(this.negative === 0, 'red works only with positives'); | ||
9746 | return ctx.convertTo(this)._forceRed(ctx); | ||
9747 | }; | ||
9748 | |||
9749 | BN.prototype.fromRed = function fromRed () { | ||
9750 | assert(this.red, 'fromRed works only with numbers in reduction context'); | ||
9751 | return this.red.convertFrom(this); | ||
9752 | }; | ||
9753 | |||
9754 | BN.prototype._forceRed = function _forceRed (ctx) { | ||
9755 | this.red = ctx; | ||
9756 | return this; | ||
9757 | }; | ||
9758 | |||
9759 | BN.prototype.forceRed = function forceRed (ctx) { | ||
9760 | assert(!this.red, 'Already a number in reduction context'); | ||
9761 | return this._forceRed(ctx); | ||
9762 | }; | ||
9763 | |||
9764 | BN.prototype.redAdd = function redAdd (num) { | ||
9765 | assert(this.red, 'redAdd works only with red numbers'); | ||
9766 | return this.red.add(this, num); | ||
9767 | }; | ||
9768 | |||
9769 | BN.prototype.redIAdd = function redIAdd (num) { | ||
9770 | assert(this.red, 'redIAdd works only with red numbers'); | ||
9771 | return this.red.iadd(this, num); | ||
9772 | }; | ||
9773 | |||
9774 | BN.prototype.redSub = function redSub (num) { | ||
9775 | assert(this.red, 'redSub works only with red numbers'); | ||
9776 | return this.red.sub(this, num); | ||
9777 | }; | ||
9778 | |||
9779 | BN.prototype.redISub = function redISub (num) { | ||
9780 | assert(this.red, 'redISub works only with red numbers'); | ||
9781 | return this.red.isub(this, num); | ||
9782 | }; | ||
9783 | |||
9784 | BN.prototype.redShl = function redShl (num) { | ||
9785 | assert(this.red, 'redShl works only with red numbers'); | ||
9786 | return this.red.shl(this, num); | ||
9787 | }; | ||
9788 | |||
9789 | BN.prototype.redMul = function redMul (num) { | ||
9790 | assert(this.red, 'redMul works only with red numbers'); | ||
9791 | this.red._verify2(this, num); | ||
9792 | return this.red.mul(this, num); | ||
9793 | }; | ||
9794 | |||
9795 | BN.prototype.redIMul = function redIMul (num) { | ||
9796 | assert(this.red, 'redMul works only with red numbers'); | ||
9797 | this.red._verify2(this, num); | ||
9798 | return this.red.imul(this, num); | ||
9799 | }; | ||
9800 | |||
9801 | BN.prototype.redSqr = function redSqr () { | ||
9802 | assert(this.red, 'redSqr works only with red numbers'); | ||
9803 | this.red._verify1(this); | ||
9804 | return this.red.sqr(this); | ||
9805 | }; | ||
9806 | |||
9807 | BN.prototype.redISqr = function redISqr () { | ||
9808 | assert(this.red, 'redISqr works only with red numbers'); | ||
9809 | this.red._verify1(this); | ||
9810 | return this.red.isqr(this); | ||
9811 | }; | ||
9812 | |||
9813 | // Square root over p | ||
9814 | BN.prototype.redSqrt = function redSqrt () { | ||
9815 | assert(this.red, 'redSqrt works only with red numbers'); | ||
9816 | this.red._verify1(this); | ||
9817 | return this.red.sqrt(this); | ||
9818 | }; | ||
9819 | |||
9820 | BN.prototype.redInvm = function redInvm () { | ||
9821 | assert(this.red, 'redInvm works only with red numbers'); | ||
9822 | this.red._verify1(this); | ||
9823 | return this.red.invm(this); | ||
9824 | }; | ||
9825 | |||
9826 | // Return negative clone of `this` % `red modulo` | ||
9827 | BN.prototype.redNeg = function redNeg () { | ||
9828 | assert(this.red, 'redNeg works only with red numbers'); | ||
9829 | this.red._verify1(this); | ||
9830 | return this.red.neg(this); | ||
9831 | }; | ||
9832 | |||
9833 | BN.prototype.redPow = function redPow (num) { | ||
9834 | assert(this.red && !num.red, 'redPow(normalNum)'); | ||
9835 | this.red._verify1(this); | ||
9836 | return this.red.pow(this, num); | ||
9837 | }; | ||
9838 | |||
9839 | // Prime numbers with efficient reduction | ||
9840 | var primes = { | ||
9841 | k256: null, | ||
9842 | p224: null, | ||
9843 | p192: null, | ||
9844 | p25519: null | ||
9845 | }; | ||
9846 | |||
9847 | // Pseudo-Mersenne prime | ||
9848 | function MPrime (name, p) { | ||
9849 | // P = 2 ^ N - K | ||
9850 | this.name = name; | ||
9851 | this.p = new BN(p, 16); | ||
9852 | this.n = this.p.bitLength(); | ||
9853 | this.k = new BN(1).iushln(this.n).isub(this.p); | ||
9854 | |||
9855 | this.tmp = this._tmp(); | ||
9856 | } | ||
9857 | |||
9858 | MPrime.prototype._tmp = function _tmp () { | ||
9859 | var tmp = new BN(null); | ||
9860 | tmp.words = new Array(Math.ceil(this.n / 13)); | ||
9861 | return tmp; | ||
9862 | }; | ||
9863 | |||
9864 | MPrime.prototype.ireduce = function ireduce (num) { | ||
9865 | // Assumes that `num` is less than `P^2` | ||
9866 | // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) | ||
9867 | var r = num; | ||
9868 | var rlen; | ||
9869 | |||
9870 | do { | ||
9871 | this.split(r, this.tmp); | ||
9872 | r = this.imulK(r); | ||
9873 | r = r.iadd(this.tmp); | ||
9874 | rlen = r.bitLength(); | ||
9875 | } while (rlen > this.n); | ||
9876 | |||
9877 | var cmp = rlen < this.n ? -1 : r.ucmp(this.p); | ||
9878 | if (cmp === 0) { | ||
9879 | r.words[0] = 0; | ||
9880 | r.length = 1; | ||
9881 | } else if (cmp > 0) { | ||
9882 | r.isub(this.p); | ||
9883 | } else { | ||
9884 | r.strip(); | ||
9885 | } | ||
9886 | |||
9887 | return r; | ||
9888 | }; | ||
9889 | |||
9890 | MPrime.prototype.split = function split (input, out) { | ||
9891 | input.iushrn(this.n, 0, out); | ||
9892 | }; | ||
9893 | |||
9894 | MPrime.prototype.imulK = function imulK (num) { | ||
9895 | return num.imul(this.k); | ||
9896 | }; | ||
9897 | |||
9898 | function K256 () { | ||
9899 | MPrime.call( | ||
9900 | this, | ||
9901 | 'k256', | ||
9902 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f'); | ||
9903 | } | ||
9904 | inherits(K256, MPrime); | ||
9905 | |||
9906 | K256.prototype.split = function split (input, output) { | ||
9907 | // 256 = 9 * 26 + 22 | ||
9908 | var mask = 0x3fffff; | ||
9909 | |||
9910 | var outLen = Math.min(input.length, 9); | ||
9911 | for (var i = 0; i < outLen; i++) { | ||
9912 | output.words[i] = input.words[i]; | ||
9913 | } | ||
9914 | output.length = outLen; | ||
9915 | |||
9916 | if (input.length <= 9) { | ||
9917 | input.words[0] = 0; | ||
9918 | input.length = 1; | ||
9919 | return; | ||
9920 | } | ||
9921 | |||
9922 | // Shift by 9 limbs | ||
9923 | var prev = input.words[9]; | ||
9924 | output.words[output.length++] = prev & mask; | ||
9925 | |||
9926 | for (i = 10; i < input.length; i++) { | ||
9927 | var next = input.words[i] | 0; | ||
9928 | input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22); | ||
9929 | prev = next; | ||
9930 | } | ||
9931 | prev >>>= 22; | ||
9932 | input.words[i - 10] = prev; | ||
9933 | if (prev === 0 && input.length > 10) { | ||
9934 | input.length -= 10; | ||
9935 | } else { | ||
9936 | input.length -= 9; | ||
9937 | } | ||
9938 | }; | ||
9939 | |||
9940 | K256.prototype.imulK = function imulK (num) { | ||
9941 | // K = 0x1000003d1 = [ 0x40, 0x3d1 ] | ||
9942 | num.words[num.length] = 0; | ||
9943 | num.words[num.length + 1] = 0; | ||
9944 | num.length += 2; | ||
9945 | |||
9946 | // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 | ||
9947 | var lo = 0; | ||
9948 | for (var i = 0; i < num.length; i++) { | ||
9949 | var w = num.words[i] | 0; | ||
9950 | lo += w * 0x3d1; | ||
9951 | num.words[i] = lo & 0x3ffffff; | ||
9952 | lo = w * 0x40 + ((lo / 0x4000000) | 0); | ||
9953 | } | ||
9954 | |||
9955 | // Fast length reduction | ||
9956 | if (num.words[num.length - 1] === 0) { | ||
9957 | num.length--; | ||
9958 | if (num.words[num.length - 1] === 0) { | ||
9959 | num.length--; | ||
9960 | } | ||
9961 | } | ||
9962 | return num; | ||
9963 | }; | ||
9964 | |||
9965 | function P224 () { | ||
9966 | MPrime.call( | ||
9967 | this, | ||
9968 | 'p224', | ||
9969 | 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001'); | ||
9970 | } | ||
9971 | inherits(P224, MPrime); | ||
9972 | |||
9973 | function P192 () { | ||
9974 | MPrime.call( | ||
9975 | this, | ||
9976 | 'p192', | ||
9977 | 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff'); | ||
9978 | } | ||
9979 | inherits(P192, MPrime); | ||
9980 | |||
9981 | function P25519 () { | ||
9982 | // 2 ^ 255 - 19 | ||
9983 | MPrime.call( | ||
9984 | this, | ||
9985 | '25519', | ||
9986 | '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed'); | ||
9987 | } | ||
9988 | inherits(P25519, MPrime); | ||
9989 | |||
9990 | P25519.prototype.imulK = function imulK (num) { | ||
9991 | // K = 0x13 | ||
9992 | var carry = 0; | ||
9993 | for (var i = 0; i < num.length; i++) { | ||
9994 | var hi = (num.words[i] | 0) * 0x13 + carry; | ||
9995 | var lo = hi & 0x3ffffff; | ||
9996 | hi >>>= 26; | ||
9997 | |||
9998 | num.words[i] = lo; | ||
9999 | carry = hi; | ||
10000 | } | ||
10001 | if (carry !== 0) { | ||
10002 | num.words[num.length++] = carry; | ||
10003 | } | ||
10004 | return num; | ||
10005 | }; | ||
10006 | |||
10007 | // Exported mostly for testing purposes, use plain name instead | ||
10008 | BN._prime = function prime (name) { | ||
10009 | // Cached version of prime | ||
10010 | if (primes[name]) return primes[name]; | ||
10011 | |||
10012 | var prime; | ||
10013 | if (name === 'k256') { | ||
10014 | prime = new K256(); | ||
10015 | } else if (name === 'p224') { | ||
10016 | prime = new P224(); | ||
10017 | } else if (name === 'p192') { | ||
10018 | prime = new P192(); | ||
10019 | } else if (name === 'p25519') { | ||
10020 | prime = new P25519(); | ||
10021 | } else { | ||
10022 | throw new Error('Unknown prime ' + name); | ||
10023 | } | ||
10024 | primes[name] = prime; | ||
10025 | |||
10026 | return prime; | ||
10027 | }; | ||
10028 | |||
10029 | // | ||
10030 | // Base reduction engine | ||
10031 | // | ||
10032 | function Red (m) { | ||
10033 | if (typeof m === 'string') { | ||
10034 | var prime = BN._prime(m); | ||
10035 | this.m = prime.p; | ||
10036 | this.prime = prime; | ||
10037 | } else { | ||
10038 | assert(m.gtn(1), 'modulus must be greater than 1'); | ||
10039 | this.m = m; | ||
10040 | this.prime = null; | ||
10041 | } | ||
10042 | } | ||
10043 | |||
10044 | Red.prototype._verify1 = function _verify1 (a) { | ||
10045 | assert(a.negative === 0, 'red works only with positives'); | ||
10046 | assert(a.red, 'red works only with red numbers'); | ||
10047 | }; | ||
10048 | |||
10049 | Red.prototype._verify2 = function _verify2 (a, b) { | ||
10050 | assert((a.negative | b.negative) === 0, 'red works only with positives'); | ||
10051 | assert(a.red && a.red === b.red, | ||
10052 | 'red works only with red numbers'); | ||
10053 | }; | ||
10054 | |||
10055 | Red.prototype.imod = function imod (a) { | ||
10056 | if (this.prime) return this.prime.ireduce(a)._forceRed(this); | ||
10057 | return a.umod(this.m)._forceRed(this); | ||
10058 | }; | ||
10059 | |||
10060 | Red.prototype.neg = function neg (a) { | ||
10061 | if (a.isZero()) { | ||
10062 | return a.clone(); | ||
10063 | } | ||
10064 | |||
10065 | return this.m.sub(a)._forceRed(this); | ||
10066 | }; | ||
10067 | |||
10068 | Red.prototype.add = function add (a, b) { | ||
10069 | this._verify2(a, b); | ||
10070 | |||
10071 | var res = a.add(b); | ||
10072 | if (res.cmp(this.m) >= 0) { | ||
10073 | res.isub(this.m); | ||
10074 | } | ||
10075 | return res._forceRed(this); | ||
10076 | }; | ||
10077 | |||
10078 | Red.prototype.iadd = function iadd (a, b) { | ||
10079 | this._verify2(a, b); | ||
10080 | |||
10081 | var res = a.iadd(b); | ||
10082 | if (res.cmp(this.m) >= 0) { | ||
10083 | res.isub(this.m); | ||
10084 | } | ||
10085 | return res; | ||
10086 | }; | ||
10087 | |||
10088 | Red.prototype.sub = function sub (a, b) { | ||
10089 | this._verify2(a, b); | ||
10090 | |||
10091 | var res = a.sub(b); | ||
10092 | if (res.cmpn(0) < 0) { | ||
10093 | res.iadd(this.m); | ||
10094 | } | ||
10095 | return res._forceRed(this); | ||
10096 | }; | ||
10097 | |||
10098 | Red.prototype.isub = function isub (a, b) { | ||
10099 | this._verify2(a, b); | ||
10100 | |||
10101 | var res = a.isub(b); | ||
10102 | if (res.cmpn(0) < 0) { | ||
10103 | res.iadd(this.m); | ||
10104 | } | ||
10105 | return res; | ||
10106 | }; | ||
10107 | |||
10108 | Red.prototype.shl = function shl (a, num) { | ||
10109 | this._verify1(a); | ||
10110 | return this.imod(a.ushln(num)); | ||
10111 | }; | ||
10112 | |||
10113 | Red.prototype.imul = function imul (a, b) { | ||
10114 | this._verify2(a, b); | ||
10115 | return this.imod(a.imul(b)); | ||
10116 | }; | ||
10117 | |||
10118 | Red.prototype.mul = function mul (a, b) { | ||
10119 | this._verify2(a, b); | ||
10120 | return this.imod(a.mul(b)); | ||
10121 | }; | ||
10122 | |||
10123 | Red.prototype.isqr = function isqr (a) { | ||
10124 | return this.imul(a, a.clone()); | ||
10125 | }; | ||
10126 | |||
10127 | Red.prototype.sqr = function sqr (a) { | ||
10128 | return this.mul(a, a); | ||
10129 | }; | ||
10130 | |||
10131 | Red.prototype.sqrt = function sqrt (a) { | ||
10132 | if (a.isZero()) return a.clone(); | ||
10133 | |||
10134 | var mod3 = this.m.andln(3); | ||
10135 | assert(mod3 % 2 === 1); | ||
10136 | |||
10137 | // Fast case | ||
10138 | if (mod3 === 3) { | ||
10139 | var pow = this.m.add(new BN(1)).iushrn(2); | ||
10140 | return this.pow(a, pow); | ||
10141 | } | ||
10142 | |||
10143 | // Tonelli-Shanks algorithm (Totally unoptimized and slow) | ||
10144 | // | ||
10145 | // Find Q and S, that Q * 2 ^ S = (P - 1) | ||
10146 | var q = this.m.subn(1); | ||
10147 | var s = 0; | ||
10148 | while (!q.isZero() && q.andln(1) === 0) { | ||
10149 | s++; | ||
10150 | q.iushrn(1); | ||
10151 | } | ||
10152 | assert(!q.isZero()); | ||
10153 | |||
10154 | var one = new BN(1).toRed(this); | ||
10155 | var nOne = one.redNeg(); | ||
10156 | |||
10157 | // Find quadratic non-residue | ||
10158 | // NOTE: Max is such because of generalized Riemann hypothesis. | ||
10159 | var lpow = this.m.subn(1).iushrn(1); | ||
10160 | var z = this.m.bitLength(); | ||
10161 | z = new BN(2 * z * z).toRed(this); | ||
10162 | |||
10163 | while (this.pow(z, lpow).cmp(nOne) !== 0) { | ||
10164 | z.redIAdd(nOne); | ||
10165 | } | ||
10166 | |||
10167 | var c = this.pow(z, q); | ||
10168 | var r = this.pow(a, q.addn(1).iushrn(1)); | ||
10169 | var t = this.pow(a, q); | ||
10170 | var m = s; | ||
10171 | while (t.cmp(one) !== 0) { | ||
10172 | var tmp = t; | ||
10173 | for (var i = 0; tmp.cmp(one) !== 0; i++) { | ||
10174 | tmp = tmp.redSqr(); | ||
10175 | } | ||
10176 | assert(i < m); | ||
10177 | var b = this.pow(c, new BN(1).iushln(m - i - 1)); | ||
10178 | |||
10179 | r = r.redMul(b); | ||
10180 | c = b.redSqr(); | ||
10181 | t = t.redMul(c); | ||
10182 | m = i; | ||
10183 | } | ||
10184 | |||
10185 | return r; | ||
10186 | }; | ||
10187 | |||
10188 | Red.prototype.invm = function invm (a) { | ||
10189 | var inv = a._invmp(this.m); | ||
10190 | if (inv.negative !== 0) { | ||
10191 | inv.negative = 0; | ||
10192 | return this.imod(inv).redNeg(); | ||
10193 | } else { | ||
10194 | return this.imod(inv); | ||
10195 | } | ||
10196 | }; | ||
10197 | |||
10198 | Red.prototype.pow = function pow (a, num) { | ||
10199 | if (num.isZero()) return new BN(1); | ||
10200 | if (num.cmpn(1) === 0) return a.clone(); | ||
10201 | |||
10202 | var windowSize = 4; | ||
10203 | var wnd = new Array(1 << windowSize); | ||
10204 | wnd[0] = new BN(1).toRed(this); | ||
10205 | wnd[1] = a; | ||
10206 | for (var i = 2; i < wnd.length; i++) { | ||
10207 | wnd[i] = this.mul(wnd[i - 1], a); | ||
10208 | } | ||
10209 | |||
10210 | var res = wnd[0]; | ||
10211 | var current = 0; | ||
10212 | var currentLen = 0; | ||
10213 | var start = num.bitLength() % 26; | ||
10214 | if (start === 0) { | ||
10215 | start = 26; | ||
10216 | } | ||
10217 | |||
10218 | for (i = num.length - 1; i >= 0; i--) { | ||
10219 | var word = num.words[i]; | ||
10220 | for (var j = start - 1; j >= 0; j--) { | ||
10221 | var bit = (word >> j) & 1; | ||
10222 | if (res !== wnd[0]) { | ||
10223 | res = this.sqr(res); | ||
10224 | } | ||
10225 | |||
10226 | if (bit === 0 && current === 0) { | ||
10227 | currentLen = 0; | ||
10228 | continue; | ||
10229 | } | ||
10230 | |||
10231 | current <<= 1; | ||
10232 | current |= bit; | ||
10233 | currentLen++; | ||
10234 | if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; | ||
10235 | |||
10236 | res = this.mul(res, wnd[current]); | ||
10237 | currentLen = 0; | ||
10238 | current = 0; | ||
10239 | } | ||
10240 | start = 26; | ||
10241 | } | ||
10242 | |||
10243 | return res; | ||
10244 | }; | ||
10245 | |||
10246 | Red.prototype.convertTo = function convertTo (num) { | ||
10247 | var r = num.umod(this.m); | ||
10248 | |||
10249 | return r === num ? r.clone() : r; | ||
10250 | }; | ||
10251 | |||
10252 | Red.prototype.convertFrom = function convertFrom (num) { | ||
10253 | var res = num.clone(); | ||
10254 | res.red = null; | ||
10255 | return res; | ||
10256 | }; | ||
10257 | |||
10258 | // | ||
10259 | // Montgomery method engine | ||
10260 | // | ||
10261 | |||
10262 | BN.mont = function mont (num) { | ||
10263 | return new Mont(num); | ||
10264 | }; | ||
10265 | |||
10266 | function Mont (m) { | ||
10267 | Red.call(this, m); | ||
10268 | |||
10269 | this.shift = this.m.bitLength(); | ||
10270 | if (this.shift % 26 !== 0) { | ||
10271 | this.shift += 26 - (this.shift % 26); | ||
10272 | } | ||
10273 | |||
10274 | this.r = new BN(1).iushln(this.shift); | ||
10275 | this.r2 = this.imod(this.r.sqr()); | ||
10276 | this.rinv = this.r._invmp(this.m); | ||
10277 | |||
10278 | this.minv = this.rinv.mul(this.r).isubn(1).div(this.m); | ||
10279 | this.minv = this.minv.umod(this.r); | ||
10280 | this.minv = this.r.sub(this.minv); | ||
10281 | } | ||
10282 | inherits(Mont, Red); | ||
10283 | |||
10284 | Mont.prototype.convertTo = function convertTo (num) { | ||
10285 | return this.imod(num.ushln(this.shift)); | ||
10286 | }; | ||
10287 | |||
10288 | Mont.prototype.convertFrom = function convertFrom (num) { | ||
10289 | var r = this.imod(num.mul(this.rinv)); | ||
10290 | r.red = null; | ||
10291 | return r; | ||
10292 | }; | ||
10293 | |||
10294 | Mont.prototype.imul = function imul (a, b) { | ||
10295 | if (a.isZero() || b.isZero()) { | ||
10296 | a.words[0] = 0; | ||
10297 | a.length = 1; | ||
10298 | return a; | ||
10299 | } | ||
10300 | |||
10301 | var t = a.imul(b); | ||
10302 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); | ||
10303 | var u = t.isub(c).iushrn(this.shift); | ||
10304 | var res = u; | ||
10305 | |||
10306 | if (u.cmp(this.m) >= 0) { | ||
10307 | res = u.isub(this.m); | ||
10308 | } else if (u.cmpn(0) < 0) { | ||
10309 | res = u.iadd(this.m); | ||
10310 | } | ||
10311 | |||
10312 | return res._forceRed(this); | ||
10313 | }; | ||
10314 | |||
10315 | Mont.prototype.mul = function mul (a, b) { | ||
10316 | if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this); | ||
10317 | |||
10318 | var t = a.mul(b); | ||
10319 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); | ||
10320 | var u = t.isub(c).iushrn(this.shift); | ||
10321 | var res = u; | ||
10322 | if (u.cmp(this.m) >= 0) { | ||
10323 | res = u.isub(this.m); | ||
10324 | } else if (u.cmpn(0) < 0) { | ||
10325 | res = u.iadd(this.m); | ||
10326 | } | ||
10327 | |||
10328 | return res._forceRed(this); | ||
10329 | }; | ||
10330 | |||
10331 | Mont.prototype.invm = function invm (a) { | ||
10332 | // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R | ||
10333 | var res = this.imod(a._invmp(this.m).mul(this.r2)); | ||
10334 | return res._forceRed(this); | ||
10335 | }; | ||
10336 | })(typeof module === 'undefined' || module, this); | ||
10337 | |||
10338 | },{}],34:[function(require,module,exports){ | ||
10339 | var r; | ||
10340 | |||
10341 | module.exports = function rand(len) { | ||
10342 | if (!r) | ||
10343 | r = new Rand(null); | ||
10344 | |||
10345 | return r.generate(len); | ||
10346 | }; | ||
10347 | |||
10348 | function Rand(rand) { | ||
10349 | this.rand = rand; | ||
10350 | } | ||
10351 | module.exports.Rand = Rand; | ||
10352 | |||
10353 | Rand.prototype.generate = function generate(len) { | ||
10354 | return this._rand(len); | ||
10355 | }; | ||
10356 | |||
10357 | if (typeof self === 'object') { | ||
10358 | if (self.crypto && self.crypto.getRandomValues) { | ||
10359 | // Modern browsers | ||
10360 | Rand.prototype._rand = function _rand(n) { | ||
10361 | var arr = new Uint8Array(n); | ||
10362 | self.crypto.getRandomValues(arr); | ||
10363 | return arr; | ||
10364 | }; | ||
10365 | } else if (self.msCrypto && self.msCrypto.getRandomValues) { | ||
10366 | // IE | ||
10367 | Rand.prototype._rand = function _rand(n) { | ||
10368 | var arr = new Uint8Array(n); | ||
10369 | self.msCrypto.getRandomValues(arr); | ||
10370 | return arr; | ||
10371 | }; | ||
10372 | } else { | ||
10373 | // Old junk | ||
10374 | Rand.prototype._rand = function() { | ||
10375 | throw new Error('Not implemented yet'); | ||
10376 | }; | ||
10377 | } | ||
10378 | } else { | ||
10379 | // Node.js or Web worker with no crypto support | ||
10380 | try { | ||
10381 | var crypto = require('crypto'); | ||
10382 | |||
10383 | Rand.prototype._rand = function _rand(n) { | ||
10384 | return crypto.randomBytes(n); | ||
10385 | }; | ||
10386 | } catch (e) { | ||
10387 | // Emulate crypto API using randy | ||
10388 | Rand.prototype._rand = function _rand(n) { | ||
10389 | var res = new Uint8Array(n); | ||
10390 | for (var i = 0; i < res.length; i++) | ||
10391 | res[i] = this.rand.getByte(); | ||
10392 | return res; | ||
10393 | }; | ||
10394 | } | ||
10395 | } | ||
10396 | |||
10397 | },{"crypto":3}],35:[function(require,module,exports){ | ||
10398 | (function (Buffer){ | ||
10399 | var Transform = require('stream').Transform | ||
10400 | var inherits = require('inherits') | ||
10401 | var StringDecoder = require('string_decoder').StringDecoder | ||
10402 | module.exports = CipherBase | ||
10403 | inherits(CipherBase, Transform) | ||
10404 | function CipherBase (hashMode) { | ||
10405 | Transform.call(this) | ||
10406 | this.hashMode = typeof hashMode === 'string' | ||
10407 | if (this.hashMode) { | ||
10408 | this[hashMode] = this._finalOrDigest | ||
10409 | } else { | ||
10410 | this.final = this._finalOrDigest | ||
10411 | } | ||
10412 | this._decoder = null | ||
10413 | this._encoding = null | ||
10414 | } | ||
10415 | CipherBase.prototype.update = function (data, inputEnc, outputEnc) { | ||
10416 | if (typeof data === 'string') { | ||
10417 | data = new Buffer(data, inputEnc) | ||
10418 | } | ||
10419 | var outData = this._update(data) | ||
10420 | if (this.hashMode) { | ||
10421 | return this | ||
10422 | } | ||
10423 | if (outputEnc) { | ||
10424 | outData = this._toString(outData, outputEnc) | ||
10425 | } | ||
10426 | return outData | ||
10427 | } | ||
10428 | |||
10429 | CipherBase.prototype.setAutoPadding = function () {} | ||
10430 | |||
10431 | CipherBase.prototype.getAuthTag = function () { | ||
10432 | throw new Error('trying to get auth tag in unsupported state') | ||
10433 | } | ||
10434 | |||
10435 | CipherBase.prototype.setAuthTag = function () { | ||
10436 | throw new Error('trying to set auth tag in unsupported state') | ||
10437 | } | ||
10438 | |||
10439 | CipherBase.prototype.setAAD = function () { | ||
10440 | throw new Error('trying to set aad in unsupported state') | ||
10441 | } | ||
10442 | |||
10443 | CipherBase.prototype._transform = function (data, _, next) { | ||
10444 | var err | ||
10445 | try { | ||
10446 | if (this.hashMode) { | ||
10447 | this._update(data) | ||
10448 | } else { | ||
10449 | this.push(this._update(data)) | ||
10450 | } | ||
10451 | } catch (e) { | ||
10452 | err = e | ||
10453 | } finally { | ||
10454 | next(err) | ||
10455 | } | ||
10456 | } | ||
10457 | CipherBase.prototype._flush = function (done) { | ||
10458 | var err | ||
10459 | try { | ||
10460 | this.push(this._final()) | ||
10461 | } catch (e) { | ||
10462 | err = e | ||
10463 | } finally { | ||
10464 | done(err) | ||
10465 | } | ||
10466 | } | ||
10467 | CipherBase.prototype._finalOrDigest = function (outputEnc) { | ||
10468 | var outData = this._final() || new Buffer('') | ||
10469 | if (outputEnc) { | ||
10470 | outData = this._toString(outData, outputEnc, true) | ||
10471 | } | ||
10472 | return outData | ||
10473 | } | ||
10474 | |||
10475 | CipherBase.prototype._toString = function (value, enc, fin) { | ||
10476 | if (!this._decoder) { | ||
10477 | this._decoder = new StringDecoder(enc) | ||
10478 | this._encoding = enc | ||
10479 | } | ||
10480 | if (this._encoding !== enc) { | ||
10481 | throw new Error('can\'t switch encodings') | ||
10482 | } | ||
10483 | var out = this._decoder.write(value) | ||
10484 | if (fin) { | ||
10485 | out += this._decoder.end() | ||
10486 | } | ||
10487 | return out | ||
10488 | } | ||
10489 | |||
10490 | }).call(this,require("buffer").Buffer) | ||
10491 | },{"buffer":5,"inherits":63,"stream":25,"string_decoder":26}],36:[function(require,module,exports){ | ||
10492 | (function (Buffer){ | ||
10493 | 'use strict'; | ||
10494 | var inherits = require('inherits') | ||
10495 | var md5 = require('./md5') | ||
10496 | var rmd160 = require('ripemd160') | ||
10497 | var sha = require('sha.js') | ||
10498 | |||
10499 | var Base = require('cipher-base') | ||
10500 | |||
10501 | function HashNoConstructor(hash) { | ||
10502 | Base.call(this, 'digest') | ||
10503 | |||
10504 | this._hash = hash | ||
10505 | this.buffers = [] | ||
10506 | } | ||
10507 | |||
10508 | inherits(HashNoConstructor, Base) | ||
10509 | |||
10510 | HashNoConstructor.prototype._update = function (data) { | ||
10511 | this.buffers.push(data) | ||
10512 | } | ||
10513 | |||
10514 | HashNoConstructor.prototype._final = function () { | ||
10515 | var buf = Buffer.concat(this.buffers) | ||
10516 | var r = this._hash(buf) | ||
10517 | this.buffers = null | ||
10518 | |||
10519 | return r | ||
10520 | } | ||
10521 | |||
10522 | function Hash(hash) { | ||
10523 | Base.call(this, 'digest') | ||
10524 | |||
10525 | this._hash = hash | ||
10526 | } | ||
10527 | |||
10528 | inherits(Hash, Base) | ||
10529 | |||
10530 | Hash.prototype._update = function (data) { | ||
10531 | this._hash.update(data) | ||
10532 | } | ||
10533 | |||
10534 | Hash.prototype._final = function () { | ||
10535 | return this._hash.digest() | ||
10536 | } | ||
10537 | |||
10538 | module.exports = function createHash (alg) { | ||
10539 | alg = alg.toLowerCase() | ||
10540 | if ('md5' === alg) return new HashNoConstructor(md5) | ||
10541 | if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160) | ||
10542 | |||
10543 | return new Hash(sha(alg)) | ||
10544 | } | ||
10545 | |||
10546 | }).call(this,require("buffer").Buffer) | ||
10547 | },{"./md5":38,"buffer":5,"cipher-base":35,"inherits":63,"ripemd160":71,"sha.js":80}],37:[function(require,module,exports){ | ||
10548 | (function (Buffer){ | ||
10549 | 'use strict'; | ||
10550 | var intSize = 4; | ||
10551 | var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0); | ||
10552 | var chrsz = 8; | ||
10553 | |||
10554 | function toArray(buf, bigEndian) { | ||
10555 | if ((buf.length % intSize) !== 0) { | ||
10556 | var len = buf.length + (intSize - (buf.length % intSize)); | ||
10557 | buf = Buffer.concat([buf, zeroBuffer], len); | ||
10558 | } | ||
10559 | |||
10560 | var arr = []; | ||
10561 | var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE; | ||
10562 | for (var i = 0; i < buf.length; i += intSize) { | ||
10563 | arr.push(fn.call(buf, i)); | ||
10564 | } | ||
10565 | return arr; | ||
10566 | } | ||
10567 | |||
10568 | function toBuffer(arr, size, bigEndian) { | ||
10569 | var buf = new Buffer(size); | ||
10570 | var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE; | ||
10571 | for (var i = 0; i < arr.length; i++) { | ||
10572 | fn.call(buf, arr[i], i * 4, true); | ||
10573 | } | ||
10574 | return buf; | ||
10575 | } | ||
10576 | |||
10577 | function hash(buf, fn, hashSize, bigEndian) { | ||
10578 | if (!Buffer.isBuffer(buf)) buf = new Buffer(buf); | ||
10579 | var arr = fn(toArray(buf, bigEndian), buf.length * chrsz); | ||
10580 | return toBuffer(arr, hashSize, bigEndian); | ||
10581 | } | ||
10582 | exports.hash = hash; | ||
10583 | }).call(this,require("buffer").Buffer) | ||
10584 | },{"buffer":5}],38:[function(require,module,exports){ | ||
10585 | 'use strict'; | ||
10586 | /* | ||
10587 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message | ||
10588 | * Digest Algorithm, as defined in RFC 1321. | ||
10589 | * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. | ||
10590 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
10591 | * Distributed under the BSD License | ||
10592 | * See http://pajhome.org.uk/crypt/md5 for more info. | ||
10593 | */ | ||
10594 | |||
10595 | var helpers = require('./helpers'); | ||
10596 | |||
10597 | /* | ||
10598 | * Calculate the MD5 of an array of little-endian words, and a bit length | ||
10599 | */ | ||
10600 | function core_md5(x, len) | ||
10601 | { | ||
10602 | /* append padding */ | ||
10603 | x[len >> 5] |= 0x80 << ((len) % 32); | ||
10604 | x[(((len + 64) >>> 9) << 4) + 14] = len; | ||
10605 | |||
10606 | var a = 1732584193; | ||
10607 | var b = -271733879; | ||
10608 | var c = -1732584194; | ||
10609 | var d = 271733878; | ||
10610 | |||
10611 | for(var i = 0; i < x.length; i += 16) | ||
10612 | { | ||
10613 | var olda = a; | ||
10614 | var oldb = b; | ||
10615 | var oldc = c; | ||
10616 | var oldd = d; | ||
10617 | |||
10618 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); | ||
10619 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); | ||
10620 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); | ||
10621 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); | ||
10622 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); | ||
10623 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); | ||
10624 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); | ||
10625 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); | ||
10626 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); | ||
10627 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); | ||
10628 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063); | ||
10629 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); | ||
10630 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); | ||
10631 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); | ||
10632 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); | ||
10633 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); | ||
10634 | |||
10635 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); | ||
10636 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); | ||
10637 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); | ||
10638 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); | ||
10639 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); | ||
10640 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); | ||
10641 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); | ||
10642 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); | ||
10643 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); | ||
10644 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); | ||
10645 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); | ||
10646 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); | ||
10647 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); | ||
10648 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); | ||
10649 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); | ||
10650 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); | ||
10651 | |||
10652 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); | ||
10653 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); | ||
10654 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); | ||
10655 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); | ||
10656 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); | ||
10657 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); | ||
10658 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); | ||
10659 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); | ||
10660 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); | ||
10661 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); | ||
10662 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); | ||
10663 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); | ||
10664 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); | ||
10665 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); | ||
10666 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); | ||
10667 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); | ||
10668 | |||
10669 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); | ||
10670 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); | ||
10671 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); | ||
10672 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); | ||
10673 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); | ||
10674 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); | ||
10675 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); | ||
10676 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); | ||
10677 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); | ||
10678 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); | ||
10679 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); | ||
10680 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); | ||
10681 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); | ||
10682 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); | ||
10683 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); | ||
10684 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); | ||
10685 | |||
10686 | a = safe_add(a, olda); | ||
10687 | b = safe_add(b, oldb); | ||
10688 | c = safe_add(c, oldc); | ||
10689 | d = safe_add(d, oldd); | ||
10690 | } | ||
10691 | return Array(a, b, c, d); | ||
10692 | |||
10693 | } | ||
10694 | |||
10695 | /* | ||
10696 | * These functions implement the four basic operations the algorithm uses. | ||
10697 | */ | ||
10698 | function md5_cmn(q, a, b, x, s, t) | ||
10699 | { | ||
10700 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); | ||
10701 | } | ||
10702 | function md5_ff(a, b, c, d, x, s, t) | ||
10703 | { | ||
10704 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); | ||
10705 | } | ||
10706 | function md5_gg(a, b, c, d, x, s, t) | ||
10707 | { | ||
10708 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); | ||
10709 | } | ||
10710 | function md5_hh(a, b, c, d, x, s, t) | ||
10711 | { | ||
10712 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); | ||
10713 | } | ||
10714 | function md5_ii(a, b, c, d, x, s, t) | ||
10715 | { | ||
10716 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); | ||
10717 | } | ||
10718 | |||
10719 | /* | ||
10720 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally | ||
10721 | * to work around bugs in some JS interpreters. | ||
10722 | */ | ||
10723 | function safe_add(x, y) | ||
10724 | { | ||
10725 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); | ||
10726 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); | ||
10727 | return (msw << 16) | (lsw & 0xFFFF); | ||
10728 | } | ||
10729 | |||
10730 | /* | ||
10731 | * Bitwise rotate a 32-bit number to the left. | ||
10732 | */ | ||
10733 | function bit_rol(num, cnt) | ||
10734 | { | ||
10735 | return (num << cnt) | (num >>> (32 - cnt)); | ||
10736 | } | ||
10737 | |||
10738 | module.exports = function md5(buf) { | ||
10739 | return helpers.hash(buf, core_md5, 16); | ||
10740 | }; | ||
10741 | },{"./helpers":37}],39:[function(require,module,exports){ | ||
10742 | 'use strict'; | ||
10743 | |||
10744 | var elliptic = exports; | ||
10745 | |||
10746 | elliptic.version = require('../package.json').version; | ||
10747 | elliptic.utils = require('./elliptic/utils'); | ||
10748 | elliptic.rand = require('brorand'); | ||
10749 | elliptic.hmacDRBG = require('./elliptic/hmac-drbg'); | ||
10750 | elliptic.curve = require('./elliptic/curve'); | ||
10751 | elliptic.curves = require('./elliptic/curves'); | ||
10752 | |||
10753 | // Protocols | ||
10754 | elliptic.ec = require('./elliptic/ec'); | ||
10755 | elliptic.eddsa = require('./elliptic/eddsa'); | ||
10756 | |||
10757 | },{"../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){ | ||
10758 | 'use strict'; | ||
10759 | |||
10760 | var BN = require('bn.js'); | ||
10761 | var elliptic = require('../../elliptic'); | ||
10762 | var utils = elliptic.utils; | ||
10763 | var getNAF = utils.getNAF; | ||
10764 | var getJSF = utils.getJSF; | ||
10765 | var assert = utils.assert; | ||
10766 | |||
10767 | function BaseCurve(type, conf) { | ||
10768 | this.type = type; | ||
10769 | this.p = new BN(conf.p, 16); | ||
10770 | |||
10771 | // Use Montgomery, when there is no fast reduction for the prime | ||
10772 | this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); | ||
10773 | |||
10774 | // Useful for many curves | ||
10775 | this.zero = new BN(0).toRed(this.red); | ||
10776 | this.one = new BN(1).toRed(this.red); | ||
10777 | this.two = new BN(2).toRed(this.red); | ||
10778 | |||
10779 | // Curve configuration, optional | ||
10780 | this.n = conf.n && new BN(conf.n, 16); | ||
10781 | this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); | ||
10782 | |||
10783 | // Temporary arrays | ||
10784 | this._wnafT1 = new Array(4); | ||
10785 | this._wnafT2 = new Array(4); | ||
10786 | this._wnafT3 = new Array(4); | ||
10787 | this._wnafT4 = new Array(4); | ||
10788 | |||
10789 | // Generalized Greg Maxwell's trick | ||
10790 | var adjustCount = this.n && this.p.div(this.n); | ||
10791 | if (!adjustCount || adjustCount.cmpn(100) > 0) { | ||
10792 | this.redN = null; | ||
10793 | } else { | ||
10794 | this._maxwellTrick = true; | ||
10795 | this.redN = this.n.toRed(this.red); | ||
10796 | } | ||
10797 | } | ||
10798 | module.exports = BaseCurve; | ||
10799 | |||
10800 | BaseCurve.prototype.point = function point() { | ||
10801 | throw new Error('Not implemented'); | ||
10802 | }; | ||
10803 | |||
10804 | BaseCurve.prototype.validate = function validate() { | ||
10805 | throw new Error('Not implemented'); | ||
10806 | }; | ||
10807 | |||
10808 | BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) { | ||
10809 | assert(p.precomputed); | ||
10810 | var doubles = p._getDoubles(); | ||
10811 | |||
10812 | var naf = getNAF(k, 1); | ||
10813 | var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1); | ||
10814 | I /= 3; | ||
10815 | |||
10816 | // Translate into more windowed form | ||
10817 | var repr = []; | ||
10818 | for (var j = 0; j < naf.length; j += doubles.step) { | ||
10819 | var nafW = 0; | ||
10820 | for (var k = j + doubles.step - 1; k >= j; k--) | ||
10821 | nafW = (nafW << 1) + naf[k]; | ||
10822 | repr.push(nafW); | ||
10823 | } | ||
10824 | |||
10825 | var a = this.jpoint(null, null, null); | ||
10826 | var b = this.jpoint(null, null, null); | ||
10827 | for (var i = I; i > 0; i--) { | ||
10828 | for (var j = 0; j < repr.length; j++) { | ||
10829 | var nafW = repr[j]; | ||
10830 | if (nafW === i) | ||
10831 | b = b.mixedAdd(doubles.points[j]); | ||
10832 | else if (nafW === -i) | ||
10833 | b = b.mixedAdd(doubles.points[j].neg()); | ||
10834 | } | ||
10835 | a = a.add(b); | ||
10836 | } | ||
10837 | return a.toP(); | ||
10838 | }; | ||
10839 | |||
10840 | BaseCurve.prototype._wnafMul = function _wnafMul(p, k) { | ||
10841 | var w = 4; | ||
10842 | |||
10843 | // Precompute window | ||
10844 | var nafPoints = p._getNAFPoints(w); | ||
10845 | w = nafPoints.wnd; | ||
10846 | var wnd = nafPoints.points; | ||
10847 | |||
10848 | // Get NAF form | ||
10849 | var naf = getNAF(k, w); | ||
10850 | |||
10851 | // Add `this`*(N+1) for every w-NAF index | ||
10852 | var acc = this.jpoint(null, null, null); | ||
10853 | for (var i = naf.length - 1; i >= 0; i--) { | ||
10854 | // Count zeroes | ||
10855 | for (var k = 0; i >= 0 && naf[i] === 0; i--) | ||
10856 | k++; | ||
10857 | if (i >= 0) | ||
10858 | k++; | ||
10859 | acc = acc.dblp(k); | ||
10860 | |||
10861 | if (i < 0) | ||
10862 | break; | ||
10863 | var z = naf[i]; | ||
10864 | assert(z !== 0); | ||
10865 | if (p.type === 'affine') { | ||
10866 | // J +- P | ||
10867 | if (z > 0) | ||
10868 | acc = acc.mixedAdd(wnd[(z - 1) >> 1]); | ||
10869 | else | ||
10870 | acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg()); | ||
10871 | } else { | ||
10872 | // J +- J | ||
10873 | if (z > 0) | ||
10874 | acc = acc.add(wnd[(z - 1) >> 1]); | ||
10875 | else | ||
10876 | acc = acc.add(wnd[(-z - 1) >> 1].neg()); | ||
10877 | } | ||
10878 | } | ||
10879 | return p.type === 'affine' ? acc.toP() : acc; | ||
10880 | }; | ||
10881 | |||
10882 | BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, | ||
10883 | points, | ||
10884 | coeffs, | ||
10885 | len, | ||
10886 | jacobianResult) { | ||
10887 | var wndWidth = this._wnafT1; | ||
10888 | var wnd = this._wnafT2; | ||
10889 | var naf = this._wnafT3; | ||
10890 | |||
10891 | // Fill all arrays | ||
10892 | var max = 0; | ||
10893 | for (var i = 0; i < len; i++) { | ||
10894 | var p = points[i]; | ||
10895 | var nafPoints = p._getNAFPoints(defW); | ||
10896 | wndWidth[i] = nafPoints.wnd; | ||
10897 | wnd[i] = nafPoints.points; | ||
10898 | } | ||
10899 | |||
10900 | // Comb small window NAFs | ||
10901 | for (var i = len - 1; i >= 1; i -= 2) { | ||
10902 | var a = i - 1; | ||
10903 | var b = i; | ||
10904 | if (wndWidth[a] !== 1 || wndWidth[b] !== 1) { | ||
10905 | naf[a] = getNAF(coeffs[a], wndWidth[a]); | ||
10906 | naf[b] = getNAF(coeffs[b], wndWidth[b]); | ||
10907 | max = Math.max(naf[a].length, max); | ||
10908 | max = Math.max(naf[b].length, max); | ||
10909 | continue; | ||
10910 | } | ||
10911 | |||
10912 | var comb = [ | ||
10913 | points[a], /* 1 */ | ||
10914 | null, /* 3 */ | ||
10915 | null, /* 5 */ | ||
10916 | points[b] /* 7 */ | ||
10917 | ]; | ||
10918 | |||
10919 | // Try to avoid Projective points, if possible | ||
10920 | if (points[a].y.cmp(points[b].y) === 0) { | ||
10921 | comb[1] = points[a].add(points[b]); | ||
10922 | comb[2] = points[a].toJ().mixedAdd(points[b].neg()); | ||
10923 | } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) { | ||
10924 | comb[1] = points[a].toJ().mixedAdd(points[b]); | ||
10925 | comb[2] = points[a].add(points[b].neg()); | ||
10926 | } else { | ||
10927 | comb[1] = points[a].toJ().mixedAdd(points[b]); | ||
10928 | comb[2] = points[a].toJ().mixedAdd(points[b].neg()); | ||
10929 | } | ||
10930 | |||
10931 | var index = [ | ||
10932 | -3, /* -1 -1 */ | ||
10933 | -1, /* -1 0 */ | ||
10934 | -5, /* -1 1 */ | ||
10935 | -7, /* 0 -1 */ | ||
10936 | 0, /* 0 0 */ | ||
10937 | 7, /* 0 1 */ | ||
10938 | 5, /* 1 -1 */ | ||
10939 | 1, /* 1 0 */ | ||
10940 | 3 /* 1 1 */ | ||
10941 | ]; | ||
10942 | |||
10943 | var jsf = getJSF(coeffs[a], coeffs[b]); | ||
10944 | max = Math.max(jsf[0].length, max); | ||
10945 | naf[a] = new Array(max); | ||
10946 | naf[b] = new Array(max); | ||
10947 | for (var j = 0; j < max; j++) { | ||
10948 | var ja = jsf[0][j] | 0; | ||
10949 | var jb = jsf[1][j] | 0; | ||
10950 | |||
10951 | naf[a][j] = index[(ja + 1) * 3 + (jb + 1)]; | ||
10952 | naf[b][j] = 0; | ||
10953 | wnd[a] = comb; | ||
10954 | } | ||
10955 | } | ||
10956 | |||
10957 | var acc = this.jpoint(null, null, null); | ||
10958 | var tmp = this._wnafT4; | ||
10959 | for (var i = max; i >= 0; i--) { | ||
10960 | var k = 0; | ||
10961 | |||
10962 | while (i >= 0) { | ||
10963 | var zero = true; | ||
10964 | for (var j = 0; j < len; j++) { | ||
10965 | tmp[j] = naf[j][i] | 0; | ||
10966 | if (tmp[j] !== 0) | ||
10967 | zero = false; | ||
10968 | } | ||
10969 | if (!zero) | ||
10970 | break; | ||
10971 | k++; | ||
10972 | i--; | ||
10973 | } | ||
10974 | if (i >= 0) | ||
10975 | k++; | ||
10976 | acc = acc.dblp(k); | ||
10977 | if (i < 0) | ||
10978 | break; | ||
10979 | |||
10980 | for (var j = 0; j < len; j++) { | ||
10981 | var z = tmp[j]; | ||
10982 | var p; | ||
10983 | if (z === 0) | ||
10984 | continue; | ||
10985 | else if (z > 0) | ||
10986 | p = wnd[j][(z - 1) >> 1]; | ||
10987 | else if (z < 0) | ||
10988 | p = wnd[j][(-z - 1) >> 1].neg(); | ||
10989 | |||
10990 | if (p.type === 'affine') | ||
10991 | acc = acc.mixedAdd(p); | ||
10992 | else | ||
10993 | acc = acc.add(p); | ||
10994 | } | ||
10995 | } | ||
10996 | // Zeroify references | ||
10997 | for (var i = 0; i < len; i++) | ||
10998 | wnd[i] = null; | ||
10999 | |||
11000 | if (jacobianResult) | ||
11001 | return acc; | ||
11002 | else | ||
11003 | return acc.toP(); | ||
11004 | }; | ||
11005 | |||
11006 | function BasePoint(curve, type) { | ||
11007 | this.curve = curve; | ||
11008 | this.type = type; | ||
11009 | this.precomputed = null; | ||
11010 | } | ||
11011 | BaseCurve.BasePoint = BasePoint; | ||
11012 | |||
11013 | BasePoint.prototype.eq = function eq(/*other*/) { | ||
11014 | throw new Error('Not implemented'); | ||
11015 | }; | ||
11016 | |||
11017 | BasePoint.prototype.validate = function validate() { | ||
11018 | return this.curve.validate(this); | ||
11019 | }; | ||
11020 | |||
11021 | BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) { | ||
11022 | bytes = utils.toArray(bytes, enc); | ||
11023 | |||
11024 | var len = this.p.byteLength(); | ||
11025 | |||
11026 | // uncompressed, hybrid-odd, hybrid-even | ||
11027 | if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && | ||
11028 | bytes.length - 1 === 2 * len) { | ||
11029 | if (bytes[0] === 0x06) | ||
11030 | assert(bytes[bytes.length - 1] % 2 === 0); | ||
11031 | else if (bytes[0] === 0x07) | ||
11032 | assert(bytes[bytes.length - 1] % 2 === 1); | ||
11033 | |||
11034 | var res = this.point(bytes.slice(1, 1 + len), | ||
11035 | bytes.slice(1 + len, 1 + 2 * len)); | ||
11036 | |||
11037 | return res; | ||
11038 | } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && | ||
11039 | bytes.length - 1 === len) { | ||
11040 | return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03); | ||
11041 | } | ||
11042 | throw new Error('Unknown point format'); | ||
11043 | }; | ||
11044 | |||
11045 | BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) { | ||
11046 | return this.encode(enc, true); | ||
11047 | }; | ||
11048 | |||
11049 | BasePoint.prototype._encode = function _encode(compact) { | ||
11050 | var len = this.curve.p.byteLength(); | ||
11051 | var x = this.getX().toArray('be', len); | ||
11052 | |||
11053 | if (compact) | ||
11054 | return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x); | ||
11055 | |||
11056 | return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ; | ||
11057 | }; | ||
11058 | |||
11059 | BasePoint.prototype.encode = function encode(enc, compact) { | ||
11060 | return utils.encode(this._encode(compact), enc); | ||
11061 | }; | ||
11062 | |||
11063 | BasePoint.prototype.precompute = function precompute(power) { | ||
11064 | if (this.precomputed) | ||
11065 | return this; | ||
11066 | |||
11067 | var precomputed = { | ||
11068 | doubles: null, | ||
11069 | naf: null, | ||
11070 | beta: null | ||
11071 | }; | ||
11072 | precomputed.naf = this._getNAFPoints(8); | ||
11073 | precomputed.doubles = this._getDoubles(4, power); | ||
11074 | precomputed.beta = this._getBeta(); | ||
11075 | this.precomputed = precomputed; | ||
11076 | |||
11077 | return this; | ||
11078 | }; | ||
11079 | |||
11080 | BasePoint.prototype._hasDoubles = function _hasDoubles(k) { | ||
11081 | if (!this.precomputed) | ||
11082 | return false; | ||
11083 | |||
11084 | var doubles = this.precomputed.doubles; | ||
11085 | if (!doubles) | ||
11086 | return false; | ||
11087 | |||
11088 | return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step); | ||
11089 | }; | ||
11090 | |||
11091 | BasePoint.prototype._getDoubles = function _getDoubles(step, power) { | ||
11092 | if (this.precomputed && this.precomputed.doubles) | ||
11093 | return this.precomputed.doubles; | ||
11094 | |||
11095 | var doubles = [ this ]; | ||
11096 | var acc = this; | ||
11097 | for (var i = 0; i < power; i += step) { | ||
11098 | for (var j = 0; j < step; j++) | ||
11099 | acc = acc.dbl(); | ||
11100 | doubles.push(acc); | ||
11101 | } | ||
11102 | return { | ||
11103 | step: step, | ||
11104 | points: doubles | ||
11105 | }; | ||
11106 | }; | ||
11107 | |||
11108 | BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) { | ||
11109 | if (this.precomputed && this.precomputed.naf) | ||
11110 | return this.precomputed.naf; | ||
11111 | |||
11112 | var res = [ this ]; | ||
11113 | var max = (1 << wnd) - 1; | ||
11114 | var dbl = max === 1 ? null : this.dbl(); | ||
11115 | for (var i = 1; i < max; i++) | ||
11116 | res[i] = res[i - 1].add(dbl); | ||
11117 | return { | ||
11118 | wnd: wnd, | ||
11119 | points: res | ||
11120 | }; | ||
11121 | }; | ||
11122 | |||
11123 | BasePoint.prototype._getBeta = function _getBeta() { | ||
11124 | return null; | ||
11125 | }; | ||
11126 | |||
11127 | BasePoint.prototype.dblp = function dblp(k) { | ||
11128 | var r = this; | ||
11129 | for (var i = 0; i < k; i++) | ||
11130 | r = r.dbl(); | ||
11131 | return r; | ||
11132 | }; | ||
11133 | |||
11134 | },{"../../elliptic":39,"bn.js":33}],41:[function(require,module,exports){ | ||
11135 | 'use strict'; | ||
11136 | |||
11137 | var curve = require('../curve'); | ||
11138 | var elliptic = require('../../elliptic'); | ||
11139 | var BN = require('bn.js'); | ||
11140 | var inherits = require('inherits'); | ||
11141 | var Base = curve.base; | ||
11142 | |||
11143 | var assert = elliptic.utils.assert; | ||
11144 | |||
11145 | function EdwardsCurve(conf) { | ||
11146 | // NOTE: Important as we are creating point in Base.call() | ||
11147 | this.twisted = (conf.a | 0) !== 1; | ||
11148 | this.mOneA = this.twisted && (conf.a | 0) === -1; | ||
11149 | this.extended = this.mOneA; | ||
11150 | |||
11151 | Base.call(this, 'edwards', conf); | ||
11152 | |||
11153 | this.a = new BN(conf.a, 16).umod(this.red.m); | ||
11154 | this.a = this.a.toRed(this.red); | ||
11155 | this.c = new BN(conf.c, 16).toRed(this.red); | ||
11156 | this.c2 = this.c.redSqr(); | ||
11157 | this.d = new BN(conf.d, 16).toRed(this.red); | ||
11158 | this.dd = this.d.redAdd(this.d); | ||
11159 | |||
11160 | assert(!this.twisted || this.c.fromRed().cmpn(1) === 0); | ||
11161 | this.oneC = (conf.c | 0) === 1; | ||
11162 | } | ||
11163 | inherits(EdwardsCurve, Base); | ||
11164 | module.exports = EdwardsCurve; | ||
11165 | |||
11166 | EdwardsCurve.prototype._mulA = function _mulA(num) { | ||
11167 | if (this.mOneA) | ||
11168 | return num.redNeg(); | ||
11169 | else | ||
11170 | return this.a.redMul(num); | ||
11171 | }; | ||
11172 | |||
11173 | EdwardsCurve.prototype._mulC = function _mulC(num) { | ||
11174 | if (this.oneC) | ||
11175 | return num; | ||
11176 | else | ||
11177 | return this.c.redMul(num); | ||
11178 | }; | ||
11179 | |||
11180 | // Just for compatibility with Short curve | ||
11181 | EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) { | ||
11182 | return this.point(x, y, z, t); | ||
11183 | }; | ||
11184 | |||
11185 | EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
11186 | x = new BN(x, 16); | ||
11187 | if (!x.red) | ||
11188 | x = x.toRed(this.red); | ||
11189 | |||
11190 | var x2 = x.redSqr(); | ||
11191 | var rhs = this.c2.redSub(this.a.redMul(x2)); | ||
11192 | var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2)); | ||
11193 | |||
11194 | var y2 = rhs.redMul(lhs.redInvm()); | ||
11195 | var y = y2.redSqrt(); | ||
11196 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) | ||
11197 | throw new Error('invalid point'); | ||
11198 | |||
11199 | var isOdd = y.fromRed().isOdd(); | ||
11200 | if (odd && !isOdd || !odd && isOdd) | ||
11201 | y = y.redNeg(); | ||
11202 | |||
11203 | return this.point(x, y); | ||
11204 | }; | ||
11205 | |||
11206 | EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { | ||
11207 | y = new BN(y, 16); | ||
11208 | if (!y.red) | ||
11209 | y = y.toRed(this.red); | ||
11210 | |||
11211 | // x^2 = (y^2 - 1) / (d y^2 + 1) | ||
11212 | var y2 = y.redSqr(); | ||
11213 | var lhs = y2.redSub(this.one); | ||
11214 | var rhs = y2.redMul(this.d).redAdd(this.one); | ||
11215 | var x2 = lhs.redMul(rhs.redInvm()); | ||
11216 | |||
11217 | if (x2.cmp(this.zero) === 0) { | ||
11218 | if (odd) | ||
11219 | throw new Error('invalid point'); | ||
11220 | else | ||
11221 | return this.point(this.zero, y); | ||
11222 | } | ||
11223 | |||
11224 | var x = x2.redSqrt(); | ||
11225 | if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) | ||
11226 | throw new Error('invalid point'); | ||
11227 | |||
11228 | if (x.isOdd() !== odd) | ||
11229 | x = x.redNeg(); | ||
11230 | |||
11231 | return this.point(x, y); | ||
11232 | }; | ||
11233 | |||
11234 | EdwardsCurve.prototype.validate = function validate(point) { | ||
11235 | if (point.isInfinity()) | ||
11236 | return true; | ||
11237 | |||
11238 | // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2) | ||
11239 | point.normalize(); | ||
11240 | |||
11241 | var x2 = point.x.redSqr(); | ||
11242 | var y2 = point.y.redSqr(); | ||
11243 | var lhs = x2.redMul(this.a).redAdd(y2); | ||
11244 | var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2))); | ||
11245 | |||
11246 | return lhs.cmp(rhs) === 0; | ||
11247 | }; | ||
11248 | |||
11249 | function Point(curve, x, y, z, t) { | ||
11250 | Base.BasePoint.call(this, curve, 'projective'); | ||
11251 | if (x === null && y === null && z === null) { | ||
11252 | this.x = this.curve.zero; | ||
11253 | this.y = this.curve.one; | ||
11254 | this.z = this.curve.one; | ||
11255 | this.t = this.curve.zero; | ||
11256 | this.zOne = true; | ||
11257 | } else { | ||
11258 | this.x = new BN(x, 16); | ||
11259 | this.y = new BN(y, 16); | ||
11260 | this.z = z ? new BN(z, 16) : this.curve.one; | ||
11261 | this.t = t && new BN(t, 16); | ||
11262 | if (!this.x.red) | ||
11263 | this.x = this.x.toRed(this.curve.red); | ||
11264 | if (!this.y.red) | ||
11265 | this.y = this.y.toRed(this.curve.red); | ||
11266 | if (!this.z.red) | ||
11267 | this.z = this.z.toRed(this.curve.red); | ||
11268 | if (this.t && !this.t.red) | ||
11269 | this.t = this.t.toRed(this.curve.red); | ||
11270 | this.zOne = this.z === this.curve.one; | ||
11271 | |||
11272 | // Use extended coordinates | ||
11273 | if (this.curve.extended && !this.t) { | ||
11274 | this.t = this.x.redMul(this.y); | ||
11275 | if (!this.zOne) | ||
11276 | this.t = this.t.redMul(this.z.redInvm()); | ||
11277 | } | ||
11278 | } | ||
11279 | } | ||
11280 | inherits(Point, Base.BasePoint); | ||
11281 | |||
11282 | EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) { | ||
11283 | return Point.fromJSON(this, obj); | ||
11284 | }; | ||
11285 | |||
11286 | EdwardsCurve.prototype.point = function point(x, y, z, t) { | ||
11287 | return new Point(this, x, y, z, t); | ||
11288 | }; | ||
11289 | |||
11290 | Point.fromJSON = function fromJSON(curve, obj) { | ||
11291 | return new Point(curve, obj[0], obj[1], obj[2]); | ||
11292 | }; | ||
11293 | |||
11294 | Point.prototype.inspect = function inspect() { | ||
11295 | if (this.isInfinity()) | ||
11296 | return '<EC Point Infinity>'; | ||
11297 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
11298 | ' y: ' + this.y.fromRed().toString(16, 2) + | ||
11299 | ' z: ' + this.z.fromRed().toString(16, 2) + '>'; | ||
11300 | }; | ||
11301 | |||
11302 | Point.prototype.isInfinity = function isInfinity() { | ||
11303 | // XXX This code assumes that zero is always zero in red | ||
11304 | return this.x.cmpn(0) === 0 && | ||
11305 | this.y.cmp(this.z) === 0; | ||
11306 | }; | ||
11307 | |||
11308 | Point.prototype._extDbl = function _extDbl() { | ||
11309 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html | ||
11310 | // #doubling-dbl-2008-hwcd | ||
11311 | // 4M + 4S | ||
11312 | |||
11313 | // A = X1^2 | ||
11314 | var a = this.x.redSqr(); | ||
11315 | // B = Y1^2 | ||
11316 | var b = this.y.redSqr(); | ||
11317 | // C = 2 * Z1^2 | ||
11318 | var c = this.z.redSqr(); | ||
11319 | c = c.redIAdd(c); | ||
11320 | // D = a * A | ||
11321 | var d = this.curve._mulA(a); | ||
11322 | // E = (X1 + Y1)^2 - A - B | ||
11323 | var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); | ||
11324 | // G = D + B | ||
11325 | var g = d.redAdd(b); | ||
11326 | // F = G - C | ||
11327 | var f = g.redSub(c); | ||
11328 | // H = D - B | ||
11329 | var h = d.redSub(b); | ||
11330 | // X3 = E * F | ||
11331 | var nx = e.redMul(f); | ||
11332 | // Y3 = G * H | ||
11333 | var ny = g.redMul(h); | ||
11334 | // T3 = E * H | ||
11335 | var nt = e.redMul(h); | ||
11336 | // Z3 = F * G | ||
11337 | var nz = f.redMul(g); | ||
11338 | return this.curve.point(nx, ny, nz, nt); | ||
11339 | }; | ||
11340 | |||
11341 | Point.prototype._projDbl = function _projDbl() { | ||
11342 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html | ||
11343 | // #doubling-dbl-2008-bbjlp | ||
11344 | // #doubling-dbl-2007-bl | ||
11345 | // and others | ||
11346 | // Generally 3M + 4S or 2M + 4S | ||
11347 | |||
11348 | // B = (X1 + Y1)^2 | ||
11349 | var b = this.x.redAdd(this.y).redSqr(); | ||
11350 | // C = X1^2 | ||
11351 | var c = this.x.redSqr(); | ||
11352 | // D = Y1^2 | ||
11353 | var d = this.y.redSqr(); | ||
11354 | |||
11355 | var nx; | ||
11356 | var ny; | ||
11357 | var nz; | ||
11358 | if (this.curve.twisted) { | ||
11359 | // E = a * C | ||
11360 | var e = this.curve._mulA(c); | ||
11361 | // F = E + D | ||
11362 | var f = e.redAdd(d); | ||
11363 | if (this.zOne) { | ||
11364 | // X3 = (B - C - D) * (F - 2) | ||
11365 | nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); | ||
11366 | // Y3 = F * (E - D) | ||
11367 | ny = f.redMul(e.redSub(d)); | ||
11368 | // Z3 = F^2 - 2 * F | ||
11369 | nz = f.redSqr().redSub(f).redSub(f); | ||
11370 | } else { | ||
11371 | // H = Z1^2 | ||
11372 | var h = this.z.redSqr(); | ||
11373 | // J = F - 2 * H | ||
11374 | var j = f.redSub(h).redISub(h); | ||
11375 | // X3 = (B-C-D)*J | ||
11376 | nx = b.redSub(c).redISub(d).redMul(j); | ||
11377 | // Y3 = F * (E - D) | ||
11378 | ny = f.redMul(e.redSub(d)); | ||
11379 | // Z3 = F * J | ||
11380 | nz = f.redMul(j); | ||
11381 | } | ||
11382 | } else { | ||
11383 | // E = C + D | ||
11384 | var e = c.redAdd(d); | ||
11385 | // H = (c * Z1)^2 | ||
11386 | var h = this.curve._mulC(this.c.redMul(this.z)).redSqr(); | ||
11387 | // J = E - 2 * H | ||
11388 | var j = e.redSub(h).redSub(h); | ||
11389 | // X3 = c * (B - E) * J | ||
11390 | nx = this.curve._mulC(b.redISub(e)).redMul(j); | ||
11391 | // Y3 = c * E * (C - D) | ||
11392 | ny = this.curve._mulC(e).redMul(c.redISub(d)); | ||
11393 | // Z3 = E * J | ||
11394 | nz = e.redMul(j); | ||
11395 | } | ||
11396 | return this.curve.point(nx, ny, nz); | ||
11397 | }; | ||
11398 | |||
11399 | Point.prototype.dbl = function dbl() { | ||
11400 | if (this.isInfinity()) | ||
11401 | return this; | ||
11402 | |||
11403 | // Double in extended coordinates | ||
11404 | if (this.curve.extended) | ||
11405 | return this._extDbl(); | ||
11406 | else | ||
11407 | return this._projDbl(); | ||
11408 | }; | ||
11409 | |||
11410 | Point.prototype._extAdd = function _extAdd(p) { | ||
11411 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html | ||
11412 | // #addition-add-2008-hwcd-3 | ||
11413 | // 8M | ||
11414 | |||
11415 | // A = (Y1 - X1) * (Y2 - X2) | ||
11416 | var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); | ||
11417 | // B = (Y1 + X1) * (Y2 + X2) | ||
11418 | var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); | ||
11419 | // C = T1 * k * T2 | ||
11420 | var c = this.t.redMul(this.curve.dd).redMul(p.t); | ||
11421 | // D = Z1 * 2 * Z2 | ||
11422 | var d = this.z.redMul(p.z.redAdd(p.z)); | ||
11423 | // E = B - A | ||
11424 | var e = b.redSub(a); | ||
11425 | // F = D - C | ||
11426 | var f = d.redSub(c); | ||
11427 | // G = D + C | ||
11428 | var g = d.redAdd(c); | ||
11429 | // H = B + A | ||
11430 | var h = b.redAdd(a); | ||
11431 | // X3 = E * F | ||
11432 | var nx = e.redMul(f); | ||
11433 | // Y3 = G * H | ||
11434 | var ny = g.redMul(h); | ||
11435 | // T3 = E * H | ||
11436 | var nt = e.redMul(h); | ||
11437 | // Z3 = F * G | ||
11438 | var nz = f.redMul(g); | ||
11439 | return this.curve.point(nx, ny, nz, nt); | ||
11440 | }; | ||
11441 | |||
11442 | Point.prototype._projAdd = function _projAdd(p) { | ||
11443 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html | ||
11444 | // #addition-add-2008-bbjlp | ||
11445 | // #addition-add-2007-bl | ||
11446 | // 10M + 1S | ||
11447 | |||
11448 | // A = Z1 * Z2 | ||
11449 | var a = this.z.redMul(p.z); | ||
11450 | // B = A^2 | ||
11451 | var b = a.redSqr(); | ||
11452 | // C = X1 * X2 | ||
11453 | var c = this.x.redMul(p.x); | ||
11454 | // D = Y1 * Y2 | ||
11455 | var d = this.y.redMul(p.y); | ||
11456 | // E = d * C * D | ||
11457 | var e = this.curve.d.redMul(c).redMul(d); | ||
11458 | // F = B - E | ||
11459 | var f = b.redSub(e); | ||
11460 | // G = B + E | ||
11461 | var g = b.redAdd(e); | ||
11462 | // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D) | ||
11463 | var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d); | ||
11464 | var nx = a.redMul(f).redMul(tmp); | ||
11465 | var ny; | ||
11466 | var nz; | ||
11467 | if (this.curve.twisted) { | ||
11468 | // Y3 = A * G * (D - a * C) | ||
11469 | ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); | ||
11470 | // Z3 = F * G | ||
11471 | nz = f.redMul(g); | ||
11472 | } else { | ||
11473 | // Y3 = A * G * (D - C) | ||
11474 | ny = a.redMul(g).redMul(d.redSub(c)); | ||
11475 | // Z3 = c * F * G | ||
11476 | nz = this.curve._mulC(f).redMul(g); | ||
11477 | } | ||
11478 | return this.curve.point(nx, ny, nz); | ||
11479 | }; | ||
11480 | |||
11481 | Point.prototype.add = function add(p) { | ||
11482 | if (this.isInfinity()) | ||
11483 | return p; | ||
11484 | if (p.isInfinity()) | ||
11485 | return this; | ||
11486 | |||
11487 | if (this.curve.extended) | ||
11488 | return this._extAdd(p); | ||
11489 | else | ||
11490 | return this._projAdd(p); | ||
11491 | }; | ||
11492 | |||
11493 | Point.prototype.mul = function mul(k) { | ||
11494 | if (this._hasDoubles(k)) | ||
11495 | return this.curve._fixedNafMul(this, k); | ||
11496 | else | ||
11497 | return this.curve._wnafMul(this, k); | ||
11498 | }; | ||
11499 | |||
11500 | Point.prototype.mulAdd = function mulAdd(k1, p, k2) { | ||
11501 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false); | ||
11502 | }; | ||
11503 | |||
11504 | Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) { | ||
11505 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true); | ||
11506 | }; | ||
11507 | |||
11508 | Point.prototype.normalize = function normalize() { | ||
11509 | if (this.zOne) | ||
11510 | return this; | ||
11511 | |||
11512 | // Normalize coordinates | ||
11513 | var zi = this.z.redInvm(); | ||
11514 | this.x = this.x.redMul(zi); | ||
11515 | this.y = this.y.redMul(zi); | ||
11516 | if (this.t) | ||
11517 | this.t = this.t.redMul(zi); | ||
11518 | this.z = this.curve.one; | ||
11519 | this.zOne = true; | ||
11520 | return this; | ||
11521 | }; | ||
11522 | |||
11523 | Point.prototype.neg = function neg() { | ||
11524 | return this.curve.point(this.x.redNeg(), | ||
11525 | this.y, | ||
11526 | this.z, | ||
11527 | this.t && this.t.redNeg()); | ||
11528 | }; | ||
11529 | |||
11530 | Point.prototype.getX = function getX() { | ||
11531 | this.normalize(); | ||
11532 | return this.x.fromRed(); | ||
11533 | }; | ||
11534 | |||
11535 | Point.prototype.getY = function getY() { | ||
11536 | this.normalize(); | ||
11537 | return this.y.fromRed(); | ||
11538 | }; | ||
11539 | |||
11540 | Point.prototype.eq = function eq(other) { | ||
11541 | return this === other || | ||
11542 | this.getX().cmp(other.getX()) === 0 && | ||
11543 | this.getY().cmp(other.getY()) === 0; | ||
11544 | }; | ||
11545 | |||
11546 | Point.prototype.eqXToP = function eqXToP(x) { | ||
11547 | var rx = x.toRed(this.curve.red).redMul(this.z); | ||
11548 | if (this.x.cmp(rx) === 0) | ||
11549 | return true; | ||
11550 | |||
11551 | var xc = x.clone(); | ||
11552 | var t = this.curve.redN.redMul(this.z); | ||
11553 | for (;;) { | ||
11554 | xc.iadd(this.curve.n); | ||
11555 | if (xc.cmp(this.curve.p) >= 0) | ||
11556 | return false; | ||
11557 | |||
11558 | rx.redIAdd(t); | ||
11559 | if (this.x.cmp(rx) === 0) | ||
11560 | return true; | ||
11561 | } | ||
11562 | return false; | ||
11563 | }; | ||
11564 | |||
11565 | // Compatibility with BaseCurve | ||
11566 | Point.prototype.toP = Point.prototype.normalize; | ||
11567 | Point.prototype.mixedAdd = Point.prototype.add; | ||
11568 | |||
11569 | },{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],42:[function(require,module,exports){ | ||
11570 | 'use strict'; | ||
11571 | |||
11572 | var curve = exports; | ||
11573 | |||
11574 | curve.base = require('./base'); | ||
11575 | curve.short = require('./short'); | ||
11576 | curve.mont = require('./mont'); | ||
11577 | curve.edwards = require('./edwards'); | ||
11578 | |||
11579 | },{"./base":40,"./edwards":41,"./mont":43,"./short":44}],43:[function(require,module,exports){ | ||
11580 | 'use strict'; | ||
11581 | |||
11582 | var curve = require('../curve'); | ||
11583 | var BN = require('bn.js'); | ||
11584 | var inherits = require('inherits'); | ||
11585 | var Base = curve.base; | ||
11586 | |||
11587 | var elliptic = require('../../elliptic'); | ||
11588 | var utils = elliptic.utils; | ||
11589 | |||
11590 | function MontCurve(conf) { | ||
11591 | Base.call(this, 'mont', conf); | ||
11592 | |||
11593 | this.a = new BN(conf.a, 16).toRed(this.red); | ||
11594 | this.b = new BN(conf.b, 16).toRed(this.red); | ||
11595 | this.i4 = new BN(4).toRed(this.red).redInvm(); | ||
11596 | this.two = new BN(2).toRed(this.red); | ||
11597 | this.a24 = this.i4.redMul(this.a.redAdd(this.two)); | ||
11598 | } | ||
11599 | inherits(MontCurve, Base); | ||
11600 | module.exports = MontCurve; | ||
11601 | |||
11602 | MontCurve.prototype.validate = function validate(point) { | ||
11603 | var x = point.normalize().x; | ||
11604 | var x2 = x.redSqr(); | ||
11605 | var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x); | ||
11606 | var y = rhs.redSqrt(); | ||
11607 | |||
11608 | return y.redSqr().cmp(rhs) === 0; | ||
11609 | }; | ||
11610 | |||
11611 | function Point(curve, x, z) { | ||
11612 | Base.BasePoint.call(this, curve, 'projective'); | ||
11613 | if (x === null && z === null) { | ||
11614 | this.x = this.curve.one; | ||
11615 | this.z = this.curve.zero; | ||
11616 | } else { | ||
11617 | this.x = new BN(x, 16); | ||
11618 | this.z = new BN(z, 16); | ||
11619 | if (!this.x.red) | ||
11620 | this.x = this.x.toRed(this.curve.red); | ||
11621 | if (!this.z.red) | ||
11622 | this.z = this.z.toRed(this.curve.red); | ||
11623 | } | ||
11624 | } | ||
11625 | inherits(Point, Base.BasePoint); | ||
11626 | |||
11627 | MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) { | ||
11628 | return this.point(utils.toArray(bytes, enc), 1); | ||
11629 | }; | ||
11630 | |||
11631 | MontCurve.prototype.point = function point(x, z) { | ||
11632 | return new Point(this, x, z); | ||
11633 | }; | ||
11634 | |||
11635 | MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) { | ||
11636 | return Point.fromJSON(this, obj); | ||
11637 | }; | ||
11638 | |||
11639 | Point.prototype.precompute = function precompute() { | ||
11640 | // No-op | ||
11641 | }; | ||
11642 | |||
11643 | Point.prototype._encode = function _encode() { | ||
11644 | return this.getX().toArray('be', this.curve.p.byteLength()); | ||
11645 | }; | ||
11646 | |||
11647 | Point.fromJSON = function fromJSON(curve, obj) { | ||
11648 | return new Point(curve, obj[0], obj[1] || curve.one); | ||
11649 | }; | ||
11650 | |||
11651 | Point.prototype.inspect = function inspect() { | ||
11652 | if (this.isInfinity()) | ||
11653 | return '<EC Point Infinity>'; | ||
11654 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
11655 | ' z: ' + this.z.fromRed().toString(16, 2) + '>'; | ||
11656 | }; | ||
11657 | |||
11658 | Point.prototype.isInfinity = function isInfinity() { | ||
11659 | // XXX This code assumes that zero is always zero in red | ||
11660 | return this.z.cmpn(0) === 0; | ||
11661 | }; | ||
11662 | |||
11663 | Point.prototype.dbl = function dbl() { | ||
11664 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3 | ||
11665 | // 2M + 2S + 4A | ||
11666 | |||
11667 | // A = X1 + Z1 | ||
11668 | var a = this.x.redAdd(this.z); | ||
11669 | // AA = A^2 | ||
11670 | var aa = a.redSqr(); | ||
11671 | // B = X1 - Z1 | ||
11672 | var b = this.x.redSub(this.z); | ||
11673 | // BB = B^2 | ||
11674 | var bb = b.redSqr(); | ||
11675 | // C = AA - BB | ||
11676 | var c = aa.redSub(bb); | ||
11677 | // X3 = AA * BB | ||
11678 | var nx = aa.redMul(bb); | ||
11679 | // Z3 = C * (BB + A24 * C) | ||
11680 | var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c))); | ||
11681 | return this.curve.point(nx, nz); | ||
11682 | }; | ||
11683 | |||
11684 | Point.prototype.add = function add() { | ||
11685 | throw new Error('Not supported on Montgomery curve'); | ||
11686 | }; | ||
11687 | |||
11688 | Point.prototype.diffAdd = function diffAdd(p, diff) { | ||
11689 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3 | ||
11690 | // 4M + 2S + 6A | ||
11691 | |||
11692 | // A = X2 + Z2 | ||
11693 | var a = this.x.redAdd(this.z); | ||
11694 | // B = X2 - Z2 | ||
11695 | var b = this.x.redSub(this.z); | ||
11696 | // C = X3 + Z3 | ||
11697 | var c = p.x.redAdd(p.z); | ||
11698 | // D = X3 - Z3 | ||
11699 | var d = p.x.redSub(p.z); | ||
11700 | // DA = D * A | ||
11701 | var da = d.redMul(a); | ||
11702 | // CB = C * B | ||
11703 | var cb = c.redMul(b); | ||
11704 | // X5 = Z1 * (DA + CB)^2 | ||
11705 | var nx = diff.z.redMul(da.redAdd(cb).redSqr()); | ||
11706 | // Z5 = X1 * (DA - CB)^2 | ||
11707 | var nz = diff.x.redMul(da.redISub(cb).redSqr()); | ||
11708 | return this.curve.point(nx, nz); | ||
11709 | }; | ||
11710 | |||
11711 | Point.prototype.mul = function mul(k) { | ||
11712 | var t = k.clone(); | ||
11713 | var a = this; // (N / 2) * Q + Q | ||
11714 | var b = this.curve.point(null, null); // (N / 2) * Q | ||
11715 | var c = this; // Q | ||
11716 | |||
11717 | for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) | ||
11718 | bits.push(t.andln(1)); | ||
11719 | |||
11720 | for (var i = bits.length - 1; i >= 0; i--) { | ||
11721 | if (bits[i] === 0) { | ||
11722 | // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q | ||
11723 | a = a.diffAdd(b, c); | ||
11724 | // N * Q = 2 * ((N / 2) * Q + Q)) | ||
11725 | b = b.dbl(); | ||
11726 | } else { | ||
11727 | // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q) | ||
11728 | b = a.diffAdd(b, c); | ||
11729 | // N * Q + Q = 2 * ((N / 2) * Q + Q) | ||
11730 | a = a.dbl(); | ||
11731 | } | ||
11732 | } | ||
11733 | return b; | ||
11734 | }; | ||
11735 | |||
11736 | Point.prototype.mulAdd = function mulAdd() { | ||
11737 | throw new Error('Not supported on Montgomery curve'); | ||
11738 | }; | ||
11739 | |||
11740 | Point.prototype.jumlAdd = function jumlAdd() { | ||
11741 | throw new Error('Not supported on Montgomery curve'); | ||
11742 | }; | ||
11743 | |||
11744 | Point.prototype.eq = function eq(other) { | ||
11745 | return this.getX().cmp(other.getX()) === 0; | ||
11746 | }; | ||
11747 | |||
11748 | Point.prototype.normalize = function normalize() { | ||
11749 | this.x = this.x.redMul(this.z.redInvm()); | ||
11750 | this.z = this.curve.one; | ||
11751 | return this; | ||
11752 | }; | ||
11753 | |||
11754 | Point.prototype.getX = function getX() { | ||
11755 | // Normalize coordinates | ||
11756 | this.normalize(); | ||
11757 | |||
11758 | return this.x.fromRed(); | ||
11759 | }; | ||
11760 | |||
11761 | },{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],44:[function(require,module,exports){ | ||
11762 | 'use strict'; | ||
11763 | |||
11764 | var curve = require('../curve'); | ||
11765 | var elliptic = require('../../elliptic'); | ||
11766 | var BN = require('bn.js'); | ||
11767 | var inherits = require('inherits'); | ||
11768 | var Base = curve.base; | ||
11769 | |||
11770 | var assert = elliptic.utils.assert; | ||
11771 | |||
11772 | function ShortCurve(conf) { | ||
11773 | Base.call(this, 'short', conf); | ||
11774 | |||
11775 | this.a = new BN(conf.a, 16).toRed(this.red); | ||
11776 | this.b = new BN(conf.b, 16).toRed(this.red); | ||
11777 | this.tinv = this.two.redInvm(); | ||
11778 | |||
11779 | this.zeroA = this.a.fromRed().cmpn(0) === 0; | ||
11780 | this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; | ||
11781 | |||
11782 | // If the curve is endomorphic, precalculate beta and lambda | ||
11783 | this.endo = this._getEndomorphism(conf); | ||
11784 | this._endoWnafT1 = new Array(4); | ||
11785 | this._endoWnafT2 = new Array(4); | ||
11786 | } | ||
11787 | inherits(ShortCurve, Base); | ||
11788 | module.exports = ShortCurve; | ||
11789 | |||
11790 | ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) { | ||
11791 | // No efficient endomorphism | ||
11792 | if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) | ||
11793 | return; | ||
11794 | |||
11795 | // Compute beta and lambda, that lambda * P = (beta * Px; Py) | ||
11796 | var beta; | ||
11797 | var lambda; | ||
11798 | if (conf.beta) { | ||
11799 | beta = new BN(conf.beta, 16).toRed(this.red); | ||
11800 | } else { | ||
11801 | var betas = this._getEndoRoots(this.p); | ||
11802 | // Choose the smallest beta | ||
11803 | beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1]; | ||
11804 | beta = beta.toRed(this.red); | ||
11805 | } | ||
11806 | if (conf.lambda) { | ||
11807 | lambda = new BN(conf.lambda, 16); | ||
11808 | } else { | ||
11809 | // Choose the lambda that is matching selected beta | ||
11810 | var lambdas = this._getEndoRoots(this.n); | ||
11811 | if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) { | ||
11812 | lambda = lambdas[0]; | ||
11813 | } else { | ||
11814 | lambda = lambdas[1]; | ||
11815 | assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0); | ||
11816 | } | ||
11817 | } | ||
11818 | |||
11819 | // Get basis vectors, used for balanced length-two representation | ||
11820 | var basis; | ||
11821 | if (conf.basis) { | ||
11822 | basis = conf.basis.map(function(vec) { | ||
11823 | return { | ||
11824 | a: new BN(vec.a, 16), | ||
11825 | b: new BN(vec.b, 16) | ||
11826 | }; | ||
11827 | }); | ||
11828 | } else { | ||
11829 | basis = this._getEndoBasis(lambda); | ||
11830 | } | ||
11831 | |||
11832 | return { | ||
11833 | beta: beta, | ||
11834 | lambda: lambda, | ||
11835 | basis: basis | ||
11836 | }; | ||
11837 | }; | ||
11838 | |||
11839 | ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) { | ||
11840 | // Find roots of for x^2 + x + 1 in F | ||
11841 | // Root = (-1 +- Sqrt(-3)) / 2 | ||
11842 | // | ||
11843 | var red = num === this.p ? this.red : BN.mont(num); | ||
11844 | var tinv = new BN(2).toRed(red).redInvm(); | ||
11845 | var ntinv = tinv.redNeg(); | ||
11846 | |||
11847 | var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv); | ||
11848 | |||
11849 | var l1 = ntinv.redAdd(s).fromRed(); | ||
11850 | var l2 = ntinv.redSub(s).fromRed(); | ||
11851 | return [ l1, l2 ]; | ||
11852 | }; | ||
11853 | |||
11854 | ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) { | ||
11855 | // aprxSqrt >= sqrt(this.n) | ||
11856 | var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); | ||
11857 | |||
11858 | // 3.74 | ||
11859 | // Run EGCD, until r(L + 1) < aprxSqrt | ||
11860 | var u = lambda; | ||
11861 | var v = this.n.clone(); | ||
11862 | var x1 = new BN(1); | ||
11863 | var y1 = new BN(0); | ||
11864 | var x2 = new BN(0); | ||
11865 | var y2 = new BN(1); | ||
11866 | |||
11867 | // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) | ||
11868 | var a0; | ||
11869 | var b0; | ||
11870 | // First vector | ||
11871 | var a1; | ||
11872 | var b1; | ||
11873 | // Second vector | ||
11874 | var a2; | ||
11875 | var b2; | ||
11876 | |||
11877 | var prevR; | ||
11878 | var i = 0; | ||
11879 | var r; | ||
11880 | var x; | ||
11881 | while (u.cmpn(0) !== 0) { | ||
11882 | var q = v.div(u); | ||
11883 | r = v.sub(q.mul(u)); | ||
11884 | x = x2.sub(q.mul(x1)); | ||
11885 | var y = y2.sub(q.mul(y1)); | ||
11886 | |||
11887 | if (!a1 && r.cmp(aprxSqrt) < 0) { | ||
11888 | a0 = prevR.neg(); | ||
11889 | b0 = x1; | ||
11890 | a1 = r.neg(); | ||
11891 | b1 = x; | ||
11892 | } else if (a1 && ++i === 2) { | ||
11893 | break; | ||
11894 | } | ||
11895 | prevR = r; | ||
11896 | |||
11897 | v = u; | ||
11898 | u = r; | ||
11899 | x2 = x1; | ||
11900 | x1 = x; | ||
11901 | y2 = y1; | ||
11902 | y1 = y; | ||
11903 | } | ||
11904 | a2 = r.neg(); | ||
11905 | b2 = x; | ||
11906 | |||
11907 | var len1 = a1.sqr().add(b1.sqr()); | ||
11908 | var len2 = a2.sqr().add(b2.sqr()); | ||
11909 | if (len2.cmp(len1) >= 0) { | ||
11910 | a2 = a0; | ||
11911 | b2 = b0; | ||
11912 | } | ||
11913 | |||
11914 | // Normalize signs | ||
11915 | if (a1.negative) { | ||
11916 | a1 = a1.neg(); | ||
11917 | b1 = b1.neg(); | ||
11918 | } | ||
11919 | if (a2.negative) { | ||
11920 | a2 = a2.neg(); | ||
11921 | b2 = b2.neg(); | ||
11922 | } | ||
11923 | |||
11924 | return [ | ||
11925 | { a: a1, b: b1 }, | ||
11926 | { a: a2, b: b2 } | ||
11927 | ]; | ||
11928 | }; | ||
11929 | |||
11930 | ShortCurve.prototype._endoSplit = function _endoSplit(k) { | ||
11931 | var basis = this.endo.basis; | ||
11932 | var v1 = basis[0]; | ||
11933 | var v2 = basis[1]; | ||
11934 | |||
11935 | var c1 = v2.b.mul(k).divRound(this.n); | ||
11936 | var c2 = v1.b.neg().mul(k).divRound(this.n); | ||
11937 | |||
11938 | var p1 = c1.mul(v1.a); | ||
11939 | var p2 = c2.mul(v2.a); | ||
11940 | var q1 = c1.mul(v1.b); | ||
11941 | var q2 = c2.mul(v2.b); | ||
11942 | |||
11943 | // Calculate answer | ||
11944 | var k1 = k.sub(p1).sub(p2); | ||
11945 | var k2 = q1.add(q2).neg(); | ||
11946 | return { k1: k1, k2: k2 }; | ||
11947 | }; | ||
11948 | |||
11949 | ShortCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
11950 | x = new BN(x, 16); | ||
11951 | if (!x.red) | ||
11952 | x = x.toRed(this.red); | ||
11953 | |||
11954 | var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b); | ||
11955 | var y = y2.redSqrt(); | ||
11956 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) | ||
11957 | throw new Error('invalid point'); | ||
11958 | |||
11959 | // XXX Is there any way to tell if the number is odd without converting it | ||
11960 | // to non-red form? | ||
11961 | var isOdd = y.fromRed().isOdd(); | ||
11962 | if (odd && !isOdd || !odd && isOdd) | ||
11963 | y = y.redNeg(); | ||
11964 | |||
11965 | return this.point(x, y); | ||
11966 | }; | ||
11967 | |||
11968 | ShortCurve.prototype.validate = function validate(point) { | ||
11969 | if (point.inf) | ||
11970 | return true; | ||
11971 | |||
11972 | var x = point.x; | ||
11973 | var y = point.y; | ||
11974 | |||
11975 | var ax = this.a.redMul(x); | ||
11976 | var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b); | ||
11977 | return y.redSqr().redISub(rhs).cmpn(0) === 0; | ||
11978 | }; | ||
11979 | |||
11980 | ShortCurve.prototype._endoWnafMulAdd = | ||
11981 | function _endoWnafMulAdd(points, coeffs, jacobianResult) { | ||
11982 | var npoints = this._endoWnafT1; | ||
11983 | var ncoeffs = this._endoWnafT2; | ||
11984 | for (var i = 0; i < points.length; i++) { | ||
11985 | var split = this._endoSplit(coeffs[i]); | ||
11986 | var p = points[i]; | ||
11987 | var beta = p._getBeta(); | ||
11988 | |||
11989 | if (split.k1.negative) { | ||
11990 | split.k1.ineg(); | ||
11991 | p = p.neg(true); | ||
11992 | } | ||
11993 | if (split.k2.negative) { | ||
11994 | split.k2.ineg(); | ||
11995 | beta = beta.neg(true); | ||
11996 | } | ||
11997 | |||
11998 | npoints[i * 2] = p; | ||
11999 | npoints[i * 2 + 1] = beta; | ||
12000 | ncoeffs[i * 2] = split.k1; | ||
12001 | ncoeffs[i * 2 + 1] = split.k2; | ||
12002 | } | ||
12003 | var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); | ||
12004 | |||
12005 | // Clean-up references to points and coefficients | ||
12006 | for (var j = 0; j < i * 2; j++) { | ||
12007 | npoints[j] = null; | ||
12008 | ncoeffs[j] = null; | ||
12009 | } | ||
12010 | return res; | ||
12011 | }; | ||
12012 | |||
12013 | function Point(curve, x, y, isRed) { | ||
12014 | Base.BasePoint.call(this, curve, 'affine'); | ||
12015 | if (x === null && y === null) { | ||
12016 | this.x = null; | ||
12017 | this.y = null; | ||
12018 | this.inf = true; | ||
12019 | } else { | ||
12020 | this.x = new BN(x, 16); | ||
12021 | this.y = new BN(y, 16); | ||
12022 | // Force redgomery representation when loading from JSON | ||
12023 | if (isRed) { | ||
12024 | this.x.forceRed(this.curve.red); | ||
12025 | this.y.forceRed(this.curve.red); | ||
12026 | } | ||
12027 | if (!this.x.red) | ||
12028 | this.x = this.x.toRed(this.curve.red); | ||
12029 | if (!this.y.red) | ||
12030 | this.y = this.y.toRed(this.curve.red); | ||
12031 | this.inf = false; | ||
12032 | } | ||
12033 | } | ||
12034 | inherits(Point, Base.BasePoint); | ||
12035 | |||
12036 | ShortCurve.prototype.point = function point(x, y, isRed) { | ||
12037 | return new Point(this, x, y, isRed); | ||
12038 | }; | ||
12039 | |||
12040 | ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) { | ||
12041 | return Point.fromJSON(this, obj, red); | ||
12042 | }; | ||
12043 | |||
12044 | Point.prototype._getBeta = function _getBeta() { | ||
12045 | if (!this.curve.endo) | ||
12046 | return; | ||
12047 | |||
12048 | var pre = this.precomputed; | ||
12049 | if (pre && pre.beta) | ||
12050 | return pre.beta; | ||
12051 | |||
12052 | var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y); | ||
12053 | if (pre) { | ||
12054 | var curve = this.curve; | ||
12055 | var endoMul = function(p) { | ||
12056 | return curve.point(p.x.redMul(curve.endo.beta), p.y); | ||
12057 | }; | ||
12058 | pre.beta = beta; | ||
12059 | beta.precomputed = { | ||
12060 | beta: null, | ||
12061 | naf: pre.naf && { | ||
12062 | wnd: pre.naf.wnd, | ||
12063 | points: pre.naf.points.map(endoMul) | ||
12064 | }, | ||
12065 | doubles: pre.doubles && { | ||
12066 | step: pre.doubles.step, | ||
12067 | points: pre.doubles.points.map(endoMul) | ||
12068 | } | ||
12069 | }; | ||
12070 | } | ||
12071 | return beta; | ||
12072 | }; | ||
12073 | |||
12074 | Point.prototype.toJSON = function toJSON() { | ||
12075 | if (!this.precomputed) | ||
12076 | return [ this.x, this.y ]; | ||
12077 | |||
12078 | return [ this.x, this.y, this.precomputed && { | ||
12079 | doubles: this.precomputed.doubles && { | ||
12080 | step: this.precomputed.doubles.step, | ||
12081 | points: this.precomputed.doubles.points.slice(1) | ||
12082 | }, | ||
12083 | naf: this.precomputed.naf && { | ||
12084 | wnd: this.precomputed.naf.wnd, | ||
12085 | points: this.precomputed.naf.points.slice(1) | ||
12086 | } | ||
12087 | } ]; | ||
12088 | }; | ||
12089 | |||
12090 | Point.fromJSON = function fromJSON(curve, obj, red) { | ||
12091 | if (typeof obj === 'string') | ||
12092 | obj = JSON.parse(obj); | ||
12093 | var res = curve.point(obj[0], obj[1], red); | ||
12094 | if (!obj[2]) | ||
12095 | return res; | ||
12096 | |||
12097 | function obj2point(obj) { | ||
12098 | return curve.point(obj[0], obj[1], red); | ||
12099 | } | ||
12100 | |||
12101 | var pre = obj[2]; | ||
12102 | res.precomputed = { | ||
12103 | beta: null, | ||
12104 | doubles: pre.doubles && { | ||
12105 | step: pre.doubles.step, | ||
12106 | points: [ res ].concat(pre.doubles.points.map(obj2point)) | ||
12107 | }, | ||
12108 | naf: pre.naf && { | ||
12109 | wnd: pre.naf.wnd, | ||
12110 | points: [ res ].concat(pre.naf.points.map(obj2point)) | ||
12111 | } | ||
12112 | }; | ||
12113 | return res; | ||
12114 | }; | ||
12115 | |||
12116 | Point.prototype.inspect = function inspect() { | ||
12117 | if (this.isInfinity()) | ||
12118 | return '<EC Point Infinity>'; | ||
12119 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
12120 | ' y: ' + this.y.fromRed().toString(16, 2) + '>'; | ||
12121 | }; | ||
12122 | |||
12123 | Point.prototype.isInfinity = function isInfinity() { | ||
12124 | return this.inf; | ||
12125 | }; | ||
12126 | |||
12127 | Point.prototype.add = function add(p) { | ||
12128 | // O + P = P | ||
12129 | if (this.inf) | ||
12130 | return p; | ||
12131 | |||
12132 | // P + O = P | ||
12133 | if (p.inf) | ||
12134 | return this; | ||
12135 | |||
12136 | // P + P = 2P | ||
12137 | if (this.eq(p)) | ||
12138 | return this.dbl(); | ||
12139 | |||
12140 | // P + (-P) = O | ||
12141 | if (this.neg().eq(p)) | ||
12142 | return this.curve.point(null, null); | ||
12143 | |||
12144 | // P + Q = O | ||
12145 | if (this.x.cmp(p.x) === 0) | ||
12146 | return this.curve.point(null, null); | ||
12147 | |||
12148 | var c = this.y.redSub(p.y); | ||
12149 | if (c.cmpn(0) !== 0) | ||
12150 | c = c.redMul(this.x.redSub(p.x).redInvm()); | ||
12151 | var nx = c.redSqr().redISub(this.x).redISub(p.x); | ||
12152 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); | ||
12153 | return this.curve.point(nx, ny); | ||
12154 | }; | ||
12155 | |||
12156 | Point.prototype.dbl = function dbl() { | ||
12157 | if (this.inf) | ||
12158 | return this; | ||
12159 | |||
12160 | // 2P = O | ||
12161 | var ys1 = this.y.redAdd(this.y); | ||
12162 | if (ys1.cmpn(0) === 0) | ||
12163 | return this.curve.point(null, null); | ||
12164 | |||
12165 | var a = this.curve.a; | ||
12166 | |||
12167 | var x2 = this.x.redSqr(); | ||
12168 | var dyinv = ys1.redInvm(); | ||
12169 | var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv); | ||
12170 | |||
12171 | var nx = c.redSqr().redISub(this.x.redAdd(this.x)); | ||
12172 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); | ||
12173 | return this.curve.point(nx, ny); | ||
12174 | }; | ||
12175 | |||
12176 | Point.prototype.getX = function getX() { | ||
12177 | return this.x.fromRed(); | ||
12178 | }; | ||
12179 | |||
12180 | Point.prototype.getY = function getY() { | ||
12181 | return this.y.fromRed(); | ||
12182 | }; | ||
12183 | |||
12184 | Point.prototype.mul = function mul(k) { | ||
12185 | k = new BN(k, 16); | ||
12186 | |||
12187 | if (this._hasDoubles(k)) | ||
12188 | return this.curve._fixedNafMul(this, k); | ||
12189 | else if (this.curve.endo) | ||
12190 | return this.curve._endoWnafMulAdd([ this ], [ k ]); | ||
12191 | else | ||
12192 | return this.curve._wnafMul(this, k); | ||
12193 | }; | ||
12194 | |||
12195 | Point.prototype.mulAdd = function mulAdd(k1, p2, k2) { | ||
12196 | var points = [ this, p2 ]; | ||
12197 | var coeffs = [ k1, k2 ]; | ||
12198 | if (this.curve.endo) | ||
12199 | return this.curve._endoWnafMulAdd(points, coeffs); | ||
12200 | else | ||
12201 | return this.curve._wnafMulAdd(1, points, coeffs, 2); | ||
12202 | }; | ||
12203 | |||
12204 | Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) { | ||
12205 | var points = [ this, p2 ]; | ||
12206 | var coeffs = [ k1, k2 ]; | ||
12207 | if (this.curve.endo) | ||
12208 | return this.curve._endoWnafMulAdd(points, coeffs, true); | ||
12209 | else | ||
12210 | return this.curve._wnafMulAdd(1, points, coeffs, 2, true); | ||
12211 | }; | ||
12212 | |||
12213 | Point.prototype.eq = function eq(p) { | ||
12214 | return this === p || | ||
12215 | this.inf === p.inf && | ||
12216 | (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0); | ||
12217 | }; | ||
12218 | |||
12219 | Point.prototype.neg = function neg(_precompute) { | ||
12220 | if (this.inf) | ||
12221 | return this; | ||
12222 | |||
12223 | var res = this.curve.point(this.x, this.y.redNeg()); | ||
12224 | if (_precompute && this.precomputed) { | ||
12225 | var pre = this.precomputed; | ||
12226 | var negate = function(p) { | ||
12227 | return p.neg(); | ||
12228 | }; | ||
12229 | res.precomputed = { | ||
12230 | naf: pre.naf && { | ||
12231 | wnd: pre.naf.wnd, | ||
12232 | points: pre.naf.points.map(negate) | ||
12233 | }, | ||
12234 | doubles: pre.doubles && { | ||
12235 | step: pre.doubles.step, | ||
12236 | points: pre.doubles.points.map(negate) | ||
12237 | } | ||
12238 | }; | ||
12239 | } | ||
12240 | return res; | ||
12241 | }; | ||
12242 | |||
12243 | Point.prototype.toJ = function toJ() { | ||
12244 | if (this.inf) | ||
12245 | return this.curve.jpoint(null, null, null); | ||
12246 | |||
12247 | var res = this.curve.jpoint(this.x, this.y, this.curve.one); | ||
12248 | return res; | ||
12249 | }; | ||
12250 | |||
12251 | function JPoint(curve, x, y, z) { | ||
12252 | Base.BasePoint.call(this, curve, 'jacobian'); | ||
12253 | if (x === null && y === null && z === null) { | ||
12254 | this.x = this.curve.one; | ||
12255 | this.y = this.curve.one; | ||
12256 | this.z = new BN(0); | ||
12257 | } else { | ||
12258 | this.x = new BN(x, 16); | ||
12259 | this.y = new BN(y, 16); | ||
12260 | this.z = new BN(z, 16); | ||
12261 | } | ||
12262 | if (!this.x.red) | ||
12263 | this.x = this.x.toRed(this.curve.red); | ||
12264 | if (!this.y.red) | ||
12265 | this.y = this.y.toRed(this.curve.red); | ||
12266 | if (!this.z.red) | ||
12267 | this.z = this.z.toRed(this.curve.red); | ||
12268 | |||
12269 | this.zOne = this.z === this.curve.one; | ||
12270 | } | ||
12271 | inherits(JPoint, Base.BasePoint); | ||
12272 | |||
12273 | ShortCurve.prototype.jpoint = function jpoint(x, y, z) { | ||
12274 | return new JPoint(this, x, y, z); | ||
12275 | }; | ||
12276 | |||
12277 | JPoint.prototype.toP = function toP() { | ||
12278 | if (this.isInfinity()) | ||
12279 | return this.curve.point(null, null); | ||
12280 | |||
12281 | var zinv = this.z.redInvm(); | ||
12282 | var zinv2 = zinv.redSqr(); | ||
12283 | var ax = this.x.redMul(zinv2); | ||
12284 | var ay = this.y.redMul(zinv2).redMul(zinv); | ||
12285 | |||
12286 | return this.curve.point(ax, ay); | ||
12287 | }; | ||
12288 | |||
12289 | JPoint.prototype.neg = function neg() { | ||
12290 | return this.curve.jpoint(this.x, this.y.redNeg(), this.z); | ||
12291 | }; | ||
12292 | |||
12293 | JPoint.prototype.add = function add(p) { | ||
12294 | // O + P = P | ||
12295 | if (this.isInfinity()) | ||
12296 | return p; | ||
12297 | |||
12298 | // P + O = P | ||
12299 | if (p.isInfinity()) | ||
12300 | return this; | ||
12301 | |||
12302 | // 12M + 4S + 7A | ||
12303 | var pz2 = p.z.redSqr(); | ||
12304 | var z2 = this.z.redSqr(); | ||
12305 | var u1 = this.x.redMul(pz2); | ||
12306 | var u2 = p.x.redMul(z2); | ||
12307 | var s1 = this.y.redMul(pz2.redMul(p.z)); | ||
12308 | var s2 = p.y.redMul(z2.redMul(this.z)); | ||
12309 | |||
12310 | var h = u1.redSub(u2); | ||
12311 | var r = s1.redSub(s2); | ||
12312 | if (h.cmpn(0) === 0) { | ||
12313 | if (r.cmpn(0) !== 0) | ||
12314 | return this.curve.jpoint(null, null, null); | ||
12315 | else | ||
12316 | return this.dbl(); | ||
12317 | } | ||
12318 | |||
12319 | var h2 = h.redSqr(); | ||
12320 | var h3 = h2.redMul(h); | ||
12321 | var v = u1.redMul(h2); | ||
12322 | |||
12323 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); | ||
12324 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); | ||
12325 | var nz = this.z.redMul(p.z).redMul(h); | ||
12326 | |||
12327 | return this.curve.jpoint(nx, ny, nz); | ||
12328 | }; | ||
12329 | |||
12330 | JPoint.prototype.mixedAdd = function mixedAdd(p) { | ||
12331 | // O + P = P | ||
12332 | if (this.isInfinity()) | ||
12333 | return p.toJ(); | ||
12334 | |||
12335 | // P + O = P | ||
12336 | if (p.isInfinity()) | ||
12337 | return this; | ||
12338 | |||
12339 | // 8M + 3S + 7A | ||
12340 | var z2 = this.z.redSqr(); | ||
12341 | var u1 = this.x; | ||
12342 | var u2 = p.x.redMul(z2); | ||
12343 | var s1 = this.y; | ||
12344 | var s2 = p.y.redMul(z2).redMul(this.z); | ||
12345 | |||
12346 | var h = u1.redSub(u2); | ||
12347 | var r = s1.redSub(s2); | ||
12348 | if (h.cmpn(0) === 0) { | ||
12349 | if (r.cmpn(0) !== 0) | ||
12350 | return this.curve.jpoint(null, null, null); | ||
12351 | else | ||
12352 | return this.dbl(); | ||
12353 | } | ||
12354 | |||
12355 | var h2 = h.redSqr(); | ||
12356 | var h3 = h2.redMul(h); | ||
12357 | var v = u1.redMul(h2); | ||
12358 | |||
12359 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); | ||
12360 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); | ||
12361 | var nz = this.z.redMul(h); | ||
12362 | |||
12363 | return this.curve.jpoint(nx, ny, nz); | ||
12364 | }; | ||
12365 | |||
12366 | JPoint.prototype.dblp = function dblp(pow) { | ||
12367 | if (pow === 0) | ||
12368 | return this; | ||
12369 | if (this.isInfinity()) | ||
12370 | return this; | ||
12371 | if (!pow) | ||
12372 | return this.dbl(); | ||
12373 | |||
12374 | if (this.curve.zeroA || this.curve.threeA) { | ||
12375 | var r = this; | ||
12376 | for (var i = 0; i < pow; i++) | ||
12377 | r = r.dbl(); | ||
12378 | return r; | ||
12379 | } | ||
12380 | |||
12381 | // 1M + 2S + 1A + N * (4S + 5M + 8A) | ||
12382 | // N = 1 => 6M + 6S + 9A | ||
12383 | var a = this.curve.a; | ||
12384 | var tinv = this.curve.tinv; | ||
12385 | |||
12386 | var jx = this.x; | ||
12387 | var jy = this.y; | ||
12388 | var jz = this.z; | ||
12389 | var jz4 = jz.redSqr().redSqr(); | ||
12390 | |||
12391 | // Reuse results | ||
12392 | var jyd = jy.redAdd(jy); | ||
12393 | for (var i = 0; i < pow; i++) { | ||
12394 | var jx2 = jx.redSqr(); | ||
12395 | var jyd2 = jyd.redSqr(); | ||
12396 | var jyd4 = jyd2.redSqr(); | ||
12397 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); | ||
12398 | |||
12399 | var t1 = jx.redMul(jyd2); | ||
12400 | var nx = c.redSqr().redISub(t1.redAdd(t1)); | ||
12401 | var t2 = t1.redISub(nx); | ||
12402 | var dny = c.redMul(t2); | ||
12403 | dny = dny.redIAdd(dny).redISub(jyd4); | ||
12404 | var nz = jyd.redMul(jz); | ||
12405 | if (i + 1 < pow) | ||
12406 | jz4 = jz4.redMul(jyd4); | ||
12407 | |||
12408 | jx = nx; | ||
12409 | jz = nz; | ||
12410 | jyd = dny; | ||
12411 | } | ||
12412 | |||
12413 | return this.curve.jpoint(jx, jyd.redMul(tinv), jz); | ||
12414 | }; | ||
12415 | |||
12416 | JPoint.prototype.dbl = function dbl() { | ||
12417 | if (this.isInfinity()) | ||
12418 | return this; | ||
12419 | |||
12420 | if (this.curve.zeroA) | ||
12421 | return this._zeroDbl(); | ||
12422 | else if (this.curve.threeA) | ||
12423 | return this._threeDbl(); | ||
12424 | else | ||
12425 | return this._dbl(); | ||
12426 | }; | ||
12427 | |||
12428 | JPoint.prototype._zeroDbl = function _zeroDbl() { | ||
12429 | var nx; | ||
12430 | var ny; | ||
12431 | var nz; | ||
12432 | // Z = 1 | ||
12433 | if (this.zOne) { | ||
12434 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html | ||
12435 | // #doubling-mdbl-2007-bl | ||
12436 | // 1M + 5S + 14A | ||
12437 | |||
12438 | // XX = X1^2 | ||
12439 | var xx = this.x.redSqr(); | ||
12440 | // YY = Y1^2 | ||
12441 | var yy = this.y.redSqr(); | ||
12442 | // YYYY = YY^2 | ||
12443 | var yyyy = yy.redSqr(); | ||
12444 | // S = 2 * ((X1 + YY)^2 - XX - YYYY) | ||
12445 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
12446 | s = s.redIAdd(s); | ||
12447 | // M = 3 * XX + a; a = 0 | ||
12448 | var m = xx.redAdd(xx).redIAdd(xx); | ||
12449 | // T = M ^ 2 - 2*S | ||
12450 | var t = m.redSqr().redISub(s).redISub(s); | ||
12451 | |||
12452 | // 8 * YYYY | ||
12453 | var yyyy8 = yyyy.redIAdd(yyyy); | ||
12454 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
12455 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
12456 | |||
12457 | // X3 = T | ||
12458 | nx = t; | ||
12459 | // Y3 = M * (S - T) - 8 * YYYY | ||
12460 | ny = m.redMul(s.redISub(t)).redISub(yyyy8); | ||
12461 | // Z3 = 2*Y1 | ||
12462 | nz = this.y.redAdd(this.y); | ||
12463 | } else { | ||
12464 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html | ||
12465 | // #doubling-dbl-2009-l | ||
12466 | // 2M + 5S + 13A | ||
12467 | |||
12468 | // A = X1^2 | ||
12469 | var a = this.x.redSqr(); | ||
12470 | // B = Y1^2 | ||
12471 | var b = this.y.redSqr(); | ||
12472 | // C = B^2 | ||
12473 | var c = b.redSqr(); | ||
12474 | // D = 2 * ((X1 + B)^2 - A - C) | ||
12475 | var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c); | ||
12476 | d = d.redIAdd(d); | ||
12477 | // E = 3 * A | ||
12478 | var e = a.redAdd(a).redIAdd(a); | ||
12479 | // F = E^2 | ||
12480 | var f = e.redSqr(); | ||
12481 | |||
12482 | // 8 * C | ||
12483 | var c8 = c.redIAdd(c); | ||
12484 | c8 = c8.redIAdd(c8); | ||
12485 | c8 = c8.redIAdd(c8); | ||
12486 | |||
12487 | // X3 = F - 2 * D | ||
12488 | nx = f.redISub(d).redISub(d); | ||
12489 | // Y3 = E * (D - X3) - 8 * C | ||
12490 | ny = e.redMul(d.redISub(nx)).redISub(c8); | ||
12491 | // Z3 = 2 * Y1 * Z1 | ||
12492 | nz = this.y.redMul(this.z); | ||
12493 | nz = nz.redIAdd(nz); | ||
12494 | } | ||
12495 | |||
12496 | return this.curve.jpoint(nx, ny, nz); | ||
12497 | }; | ||
12498 | |||
12499 | JPoint.prototype._threeDbl = function _threeDbl() { | ||
12500 | var nx; | ||
12501 | var ny; | ||
12502 | var nz; | ||
12503 | // Z = 1 | ||
12504 | if (this.zOne) { | ||
12505 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html | ||
12506 | // #doubling-mdbl-2007-bl | ||
12507 | // 1M + 5S + 15A | ||
12508 | |||
12509 | // XX = X1^2 | ||
12510 | var xx = this.x.redSqr(); | ||
12511 | // YY = Y1^2 | ||
12512 | var yy = this.y.redSqr(); | ||
12513 | // YYYY = YY^2 | ||
12514 | var yyyy = yy.redSqr(); | ||
12515 | // S = 2 * ((X1 + YY)^2 - XX - YYYY) | ||
12516 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
12517 | s = s.redIAdd(s); | ||
12518 | // M = 3 * XX + a | ||
12519 | var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); | ||
12520 | // T = M^2 - 2 * S | ||
12521 | var t = m.redSqr().redISub(s).redISub(s); | ||
12522 | // X3 = T | ||
12523 | nx = t; | ||
12524 | // Y3 = M * (S - T) - 8 * YYYY | ||
12525 | var yyyy8 = yyyy.redIAdd(yyyy); | ||
12526 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
12527 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
12528 | ny = m.redMul(s.redISub(t)).redISub(yyyy8); | ||
12529 | // Z3 = 2 * Y1 | ||
12530 | nz = this.y.redAdd(this.y); | ||
12531 | } else { | ||
12532 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b | ||
12533 | // 3M + 5S | ||
12534 | |||
12535 | // delta = Z1^2 | ||
12536 | var delta = this.z.redSqr(); | ||
12537 | // gamma = Y1^2 | ||
12538 | var gamma = this.y.redSqr(); | ||
12539 | // beta = X1 * gamma | ||
12540 | var beta = this.x.redMul(gamma); | ||
12541 | // alpha = 3 * (X1 - delta) * (X1 + delta) | ||
12542 | var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta)); | ||
12543 | alpha = alpha.redAdd(alpha).redIAdd(alpha); | ||
12544 | // X3 = alpha^2 - 8 * beta | ||
12545 | var beta4 = beta.redIAdd(beta); | ||
12546 | beta4 = beta4.redIAdd(beta4); | ||
12547 | var beta8 = beta4.redAdd(beta4); | ||
12548 | nx = alpha.redSqr().redISub(beta8); | ||
12549 | // Z3 = (Y1 + Z1)^2 - gamma - delta | ||
12550 | nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); | ||
12551 | // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2 | ||
12552 | var ggamma8 = gamma.redSqr(); | ||
12553 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
12554 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
12555 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
12556 | ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8); | ||
12557 | } | ||
12558 | |||
12559 | return this.curve.jpoint(nx, ny, nz); | ||
12560 | }; | ||
12561 | |||
12562 | JPoint.prototype._dbl = function _dbl() { | ||
12563 | var a = this.curve.a; | ||
12564 | |||
12565 | // 4M + 6S + 10A | ||
12566 | var jx = this.x; | ||
12567 | var jy = this.y; | ||
12568 | var jz = this.z; | ||
12569 | var jz4 = jz.redSqr().redSqr(); | ||
12570 | |||
12571 | var jx2 = jx.redSqr(); | ||
12572 | var jy2 = jy.redSqr(); | ||
12573 | |||
12574 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); | ||
12575 | |||
12576 | var jxd4 = jx.redAdd(jx); | ||
12577 | jxd4 = jxd4.redIAdd(jxd4); | ||
12578 | var t1 = jxd4.redMul(jy2); | ||
12579 | var nx = c.redSqr().redISub(t1.redAdd(t1)); | ||
12580 | var t2 = t1.redISub(nx); | ||
12581 | |||
12582 | var jyd8 = jy2.redSqr(); | ||
12583 | jyd8 = jyd8.redIAdd(jyd8); | ||
12584 | jyd8 = jyd8.redIAdd(jyd8); | ||
12585 | jyd8 = jyd8.redIAdd(jyd8); | ||
12586 | var ny = c.redMul(t2).redISub(jyd8); | ||
12587 | var nz = jy.redAdd(jy).redMul(jz); | ||
12588 | |||
12589 | return this.curve.jpoint(nx, ny, nz); | ||
12590 | }; | ||
12591 | |||
12592 | JPoint.prototype.trpl = function trpl() { | ||
12593 | if (!this.curve.zeroA) | ||
12594 | return this.dbl().add(this); | ||
12595 | |||
12596 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl | ||
12597 | // 5M + 10S + ... | ||
12598 | |||
12599 | // XX = X1^2 | ||
12600 | var xx = this.x.redSqr(); | ||
12601 | // YY = Y1^2 | ||
12602 | var yy = this.y.redSqr(); | ||
12603 | // ZZ = Z1^2 | ||
12604 | var zz = this.z.redSqr(); | ||
12605 | // YYYY = YY^2 | ||
12606 | var yyyy = yy.redSqr(); | ||
12607 | // M = 3 * XX + a * ZZ2; a = 0 | ||
12608 | var m = xx.redAdd(xx).redIAdd(xx); | ||
12609 | // MM = M^2 | ||
12610 | var mm = m.redSqr(); | ||
12611 | // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM | ||
12612 | var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
12613 | e = e.redIAdd(e); | ||
12614 | e = e.redAdd(e).redIAdd(e); | ||
12615 | e = e.redISub(mm); | ||
12616 | // EE = E^2 | ||
12617 | var ee = e.redSqr(); | ||
12618 | // T = 16*YYYY | ||
12619 | var t = yyyy.redIAdd(yyyy); | ||
12620 | t = t.redIAdd(t); | ||
12621 | t = t.redIAdd(t); | ||
12622 | t = t.redIAdd(t); | ||
12623 | // U = (M + E)^2 - MM - EE - T | ||
12624 | var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); | ||
12625 | // X3 = 4 * (X1 * EE - 4 * YY * U) | ||
12626 | var yyu4 = yy.redMul(u); | ||
12627 | yyu4 = yyu4.redIAdd(yyu4); | ||
12628 | yyu4 = yyu4.redIAdd(yyu4); | ||
12629 | var nx = this.x.redMul(ee).redISub(yyu4); | ||
12630 | nx = nx.redIAdd(nx); | ||
12631 | nx = nx.redIAdd(nx); | ||
12632 | // Y3 = 8 * Y1 * (U * (T - U) - E * EE) | ||
12633 | var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee))); | ||
12634 | ny = ny.redIAdd(ny); | ||
12635 | ny = ny.redIAdd(ny); | ||
12636 | ny = ny.redIAdd(ny); | ||
12637 | // Z3 = (Z1 + E)^2 - ZZ - EE | ||
12638 | var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee); | ||
12639 | |||
12640 | return this.curve.jpoint(nx, ny, nz); | ||
12641 | }; | ||
12642 | |||
12643 | JPoint.prototype.mul = function mul(k, kbase) { | ||
12644 | k = new BN(k, kbase); | ||
12645 | |||
12646 | return this.curve._wnafMul(this, k); | ||
12647 | }; | ||
12648 | |||
12649 | JPoint.prototype.eq = function eq(p) { | ||
12650 | if (p.type === 'affine') | ||
12651 | return this.eq(p.toJ()); | ||
12652 | |||
12653 | if (this === p) | ||
12654 | return true; | ||
12655 | |||
12656 | // x1 * z2^2 == x2 * z1^2 | ||
12657 | var z2 = this.z.redSqr(); | ||
12658 | var pz2 = p.z.redSqr(); | ||
12659 | if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) | ||
12660 | return false; | ||
12661 | |||
12662 | // y1 * z2^3 == y2 * z1^3 | ||
12663 | var z3 = z2.redMul(this.z); | ||
12664 | var pz3 = pz2.redMul(p.z); | ||
12665 | return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0; | ||
12666 | }; | ||
12667 | |||
12668 | JPoint.prototype.eqXToP = function eqXToP(x) { | ||
12669 | var zs = this.z.redSqr(); | ||
12670 | var rx = x.toRed(this.curve.red).redMul(zs); | ||
12671 | if (this.x.cmp(rx) === 0) | ||
12672 | return true; | ||
12673 | |||
12674 | var xc = x.clone(); | ||
12675 | var t = this.curve.redN.redMul(zs); | ||
12676 | for (;;) { | ||
12677 | xc.iadd(this.curve.n); | ||
12678 | if (xc.cmp(this.curve.p) >= 0) | ||
12679 | return false; | ||
12680 | |||
12681 | rx.redIAdd(t); | ||
12682 | if (this.x.cmp(rx) === 0) | ||
12683 | return true; | ||
12684 | } | ||
12685 | return false; | ||
12686 | }; | ||
12687 | |||
12688 | JPoint.prototype.inspect = function inspect() { | ||
12689 | if (this.isInfinity()) | ||
12690 | return '<EC JPoint Infinity>'; | ||
12691 | return '<EC JPoint x: ' + this.x.toString(16, 2) + | ||
12692 | ' y: ' + this.y.toString(16, 2) + | ||
12693 | ' z: ' + this.z.toString(16, 2) + '>'; | ||
12694 | }; | ||
12695 | |||
12696 | JPoint.prototype.isInfinity = function isInfinity() { | ||
12697 | // XXX This code assumes that zero is always zero in red | ||
12698 | return this.z.cmpn(0) === 0; | ||
12699 | }; | ||
12700 | |||
12701 | },{"../../elliptic":39,"../curve":42,"bn.js":33,"inherits":63}],45:[function(require,module,exports){ | ||
12702 | 'use strict'; | ||
12703 | |||
12704 | var curves = exports; | ||
12705 | |||
12706 | var hash = require('hash.js'); | ||
12707 | var elliptic = require('../elliptic'); | ||
12708 | |||
12709 | var assert = elliptic.utils.assert; | ||
12710 | |||
12711 | function PresetCurve(options) { | ||
12712 | if (options.type === 'short') | ||
12713 | this.curve = new elliptic.curve.short(options); | ||
12714 | else if (options.type === 'edwards') | ||
12715 | this.curve = new elliptic.curve.edwards(options); | ||
12716 | else | ||
12717 | this.curve = new elliptic.curve.mont(options); | ||
12718 | this.g = this.curve.g; | ||
12719 | this.n = this.curve.n; | ||
12720 | this.hash = options.hash; | ||
12721 | |||
12722 | assert(this.g.validate(), 'Invalid curve'); | ||
12723 | assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O'); | ||
12724 | } | ||
12725 | curves.PresetCurve = PresetCurve; | ||
12726 | |||
12727 | function defineCurve(name, options) { | ||
12728 | Object.defineProperty(curves, name, { | ||
12729 | configurable: true, | ||
12730 | enumerable: true, | ||
12731 | get: function() { | ||
12732 | var curve = new PresetCurve(options); | ||
12733 | Object.defineProperty(curves, name, { | ||
12734 | configurable: true, | ||
12735 | enumerable: true, | ||
12736 | value: curve | ||
12737 | }); | ||
12738 | return curve; | ||
12739 | } | ||
12740 | }); | ||
12741 | } | ||
12742 | |||
12743 | defineCurve('p192', { | ||
12744 | type: 'short', | ||
12745 | prime: 'p192', | ||
12746 | p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff', | ||
12747 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc', | ||
12748 | b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1', | ||
12749 | n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831', | ||
12750 | hash: hash.sha256, | ||
12751 | gRed: false, | ||
12752 | g: [ | ||
12753 | '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', | ||
12754 | '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811' | ||
12755 | ] | ||
12756 | }); | ||
12757 | |||
12758 | defineCurve('p224', { | ||
12759 | type: 'short', | ||
12760 | prime: 'p224', | ||
12761 | p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001', | ||
12762 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe', | ||
12763 | b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4', | ||
12764 | n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d', | ||
12765 | hash: hash.sha256, | ||
12766 | gRed: false, | ||
12767 | g: [ | ||
12768 | 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', | ||
12769 | 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34' | ||
12770 | ] | ||
12771 | }); | ||
12772 | |||
12773 | defineCurve('p256', { | ||
12774 | type: 'short', | ||
12775 | prime: null, | ||
12776 | p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff', | ||
12777 | a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc', | ||
12778 | b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b', | ||
12779 | n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551', | ||
12780 | hash: hash.sha256, | ||
12781 | gRed: false, | ||
12782 | g: [ | ||
12783 | '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', | ||
12784 | '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5' | ||
12785 | ] | ||
12786 | }); | ||
12787 | |||
12788 | defineCurve('p384', { | ||
12789 | type: 'short', | ||
12790 | prime: null, | ||
12791 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12792 | 'fffffffe ffffffff 00000000 00000000 ffffffff', | ||
12793 | a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12794 | 'fffffffe ffffffff 00000000 00000000 fffffffc', | ||
12795 | b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + | ||
12796 | '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef', | ||
12797 | n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + | ||
12798 | 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973', | ||
12799 | hash: hash.sha384, | ||
12800 | gRed: false, | ||
12801 | g: [ | ||
12802 | 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' + | ||
12803 | '5502f25d bf55296c 3a545e38 72760ab7', | ||
12804 | '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' + | ||
12805 | '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f' | ||
12806 | ] | ||
12807 | }); | ||
12808 | |||
12809 | defineCurve('p521', { | ||
12810 | type: 'short', | ||
12811 | prime: null, | ||
12812 | p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12813 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12814 | 'ffffffff ffffffff ffffffff ffffffff ffffffff', | ||
12815 | a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12816 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12817 | 'ffffffff ffffffff ffffffff ffffffff fffffffc', | ||
12818 | b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + | ||
12819 | '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + | ||
12820 | '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00', | ||
12821 | n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
12822 | 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + | ||
12823 | 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409', | ||
12824 | hash: hash.sha512, | ||
12825 | gRed: false, | ||
12826 | g: [ | ||
12827 | '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' + | ||
12828 | '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' + | ||
12829 | 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66', | ||
12830 | '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' + | ||
12831 | '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' + | ||
12832 | '3fad0761 353c7086 a272c240 88be9476 9fd16650' | ||
12833 | ] | ||
12834 | }); | ||
12835 | |||
12836 | defineCurve('curve25519', { | ||
12837 | type: 'mont', | ||
12838 | prime: 'p25519', | ||
12839 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed', | ||
12840 | a: '76d06', | ||
12841 | b: '1', | ||
12842 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed', | ||
12843 | hash: hash.sha256, | ||
12844 | gRed: false, | ||
12845 | g: [ | ||
12846 | '9' | ||
12847 | ] | ||
12848 | }); | ||
12849 | |||
12850 | defineCurve('ed25519', { | ||
12851 | type: 'edwards', | ||
12852 | prime: 'p25519', | ||
12853 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed', | ||
12854 | a: '-1', | ||
12855 | c: '1', | ||
12856 | // -121665 * (121666^(-1)) (mod P) | ||
12857 | d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3', | ||
12858 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed', | ||
12859 | hash: hash.sha256, | ||
12860 | gRed: false, | ||
12861 | g: [ | ||
12862 | '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a', | ||
12863 | |||
12864 | // 4/5 | ||
12865 | '6666666666666666666666666666666666666666666666666666666666666658' | ||
12866 | ] | ||
12867 | }); | ||
12868 | |||
12869 | var pre; | ||
12870 | try { | ||
12871 | pre = require('./precomputed/secp256k1'); | ||
12872 | } catch (e) { | ||
12873 | pre = undefined; | ||
12874 | } | ||
12875 | |||
12876 | defineCurve('secp256k1', { | ||
12877 | type: 'short', | ||
12878 | prime: 'k256', | ||
12879 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f', | ||
12880 | a: '0', | ||
12881 | b: '7', | ||
12882 | n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141', | ||
12883 | h: '1', | ||
12884 | hash: hash.sha256, | ||
12885 | |||
12886 | // Precomputed endomorphism | ||
12887 | beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee', | ||
12888 | lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72', | ||
12889 | basis: [ | ||
12890 | { | ||
12891 | a: '3086d221a7d46bcde86c90e49284eb15', | ||
12892 | b: '-e4437ed6010e88286f547fa90abfe4c3' | ||
12893 | }, | ||
12894 | { | ||
12895 | a: '114ca50f7a8e2f3f657c1108d9d44cfd8', | ||
12896 | b: '3086d221a7d46bcde86c90e49284eb15' | ||
12897 | } | ||
12898 | ], | ||
12899 | |||
12900 | gRed: false, | ||
12901 | g: [ | ||
12902 | '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', | ||
12903 | '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', | ||
12904 | pre | ||
12905 | ] | ||
12906 | }); | ||
12907 | |||
12908 | },{"../elliptic":39,"./precomputed/secp256k1":53,"hash.js":57}],46:[function(require,module,exports){ | ||
12909 | 'use strict'; | ||
12910 | |||
12911 | var BN = require('bn.js'); | ||
12912 | var elliptic = require('../../elliptic'); | ||
12913 | var utils = elliptic.utils; | ||
12914 | var assert = utils.assert; | ||
12915 | |||
12916 | var KeyPair = require('./key'); | ||
12917 | var Signature = require('./signature'); | ||
12918 | |||
12919 | function EC(options) { | ||
12920 | if (!(this instanceof EC)) | ||
12921 | return new EC(options); | ||
12922 | |||
12923 | // Shortcut `elliptic.ec(curve-name)` | ||
12924 | if (typeof options === 'string') { | ||
12925 | assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options); | ||
12926 | |||
12927 | options = elliptic.curves[options]; | ||
12928 | } | ||
12929 | |||
12930 | // Shortcut for `elliptic.ec(elliptic.curves.curveName)` | ||
12931 | if (options instanceof elliptic.curves.PresetCurve) | ||
12932 | options = { curve: options }; | ||
12933 | |||
12934 | this.curve = options.curve.curve; | ||
12935 | this.n = this.curve.n; | ||
12936 | this.nh = this.n.ushrn(1); | ||
12937 | this.g = this.curve.g; | ||
12938 | |||
12939 | // Point on curve | ||
12940 | this.g = options.curve.g; | ||
12941 | this.g.precompute(options.curve.n.bitLength() + 1); | ||
12942 | |||
12943 | // Hash for function for DRBG | ||
12944 | this.hash = options.hash || options.curve.hash; | ||
12945 | } | ||
12946 | module.exports = EC; | ||
12947 | |||
12948 | EC.prototype.keyPair = function keyPair(options) { | ||
12949 | return new KeyPair(this, options); | ||
12950 | }; | ||
12951 | |||
12952 | EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) { | ||
12953 | return KeyPair.fromPrivate(this, priv, enc); | ||
12954 | }; | ||
12955 | |||
12956 | EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) { | ||
12957 | return KeyPair.fromPublic(this, pub, enc); | ||
12958 | }; | ||
12959 | |||
12960 | EC.prototype.genKeyPair = function genKeyPair(options) { | ||
12961 | if (!options) | ||
12962 | options = {}; | ||
12963 | |||
12964 | // Instantiate Hmac_DRBG | ||
12965 | var drbg = new elliptic.hmacDRBG({ | ||
12966 | hash: this.hash, | ||
12967 | pers: options.pers, | ||
12968 | entropy: options.entropy || elliptic.rand(this.hash.hmacStrength), | ||
12969 | nonce: this.n.toArray() | ||
12970 | }); | ||
12971 | |||
12972 | var bytes = this.n.byteLength(); | ||
12973 | var ns2 = this.n.sub(new BN(2)); | ||
12974 | do { | ||
12975 | var priv = new BN(drbg.generate(bytes)); | ||
12976 | if (priv.cmp(ns2) > 0) | ||
12977 | continue; | ||
12978 | |||
12979 | priv.iaddn(1); | ||
12980 | return this.keyFromPrivate(priv); | ||
12981 | } while (true); | ||
12982 | }; | ||
12983 | |||
12984 | EC.prototype._truncateToN = function truncateToN(msg, truncOnly) { | ||
12985 | var delta = msg.byteLength() * 8 - this.n.bitLength(); | ||
12986 | if (delta > 0) | ||
12987 | msg = msg.ushrn(delta); | ||
12988 | if (!truncOnly && msg.cmp(this.n) >= 0) | ||
12989 | return msg.sub(this.n); | ||
12990 | else | ||
12991 | return msg; | ||
12992 | }; | ||
12993 | |||
12994 | EC.prototype.sign = function sign(msg, key, enc, options) { | ||
12995 | if (typeof enc === 'object') { | ||
12996 | options = enc; | ||
12997 | enc = null; | ||
12998 | } | ||
12999 | if (!options) | ||
13000 | options = {}; | ||
13001 | |||
13002 | key = this.keyFromPrivate(key, enc); | ||
13003 | msg = this._truncateToN(new BN(msg, 16)); | ||
13004 | |||
13005 | // Zero-extend key to provide enough entropy | ||
13006 | var bytes = this.n.byteLength(); | ||
13007 | var bkey = key.getPrivate().toArray('be', bytes); | ||
13008 | |||
13009 | // Zero-extend nonce to have the same byte size as N | ||
13010 | var nonce = msg.toArray('be', bytes); | ||
13011 | |||
13012 | // Instantiate Hmac_DRBG | ||
13013 | var drbg = new elliptic.hmacDRBG({ | ||
13014 | hash: this.hash, | ||
13015 | entropy: bkey, | ||
13016 | nonce: nonce, | ||
13017 | pers: options.pers, | ||
13018 | persEnc: options.persEnc | ||
13019 | }); | ||
13020 | |||
13021 | // Number of bytes to generate | ||
13022 | var ns1 = this.n.sub(new BN(1)); | ||
13023 | |||
13024 | for (var iter = 0; true; iter++) { | ||
13025 | var k = options.k ? | ||
13026 | options.k(iter) : | ||
13027 | new BN(drbg.generate(this.n.byteLength())); | ||
13028 | k = this._truncateToN(k, true); | ||
13029 | if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) | ||
13030 | continue; | ||
13031 | |||
13032 | var kp = this.g.mul(k); | ||
13033 | if (kp.isInfinity()) | ||
13034 | continue; | ||
13035 | |||
13036 | var kpX = kp.getX(); | ||
13037 | var r = kpX.umod(this.n); | ||
13038 | if (r.cmpn(0) === 0) | ||
13039 | continue; | ||
13040 | |||
13041 | var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg)); | ||
13042 | s = s.umod(this.n); | ||
13043 | if (s.cmpn(0) === 0) | ||
13044 | continue; | ||
13045 | |||
13046 | var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | | ||
13047 | (kpX.cmp(r) !== 0 ? 2 : 0); | ||
13048 | |||
13049 | // Use complement of `s`, if it is > `n / 2` | ||
13050 | if (options.canonical && s.cmp(this.nh) > 0) { | ||
13051 | s = this.n.sub(s); | ||
13052 | recoveryParam ^= 1; | ||
13053 | } | ||
13054 | |||
13055 | return new Signature({ r: r, s: s, recoveryParam: recoveryParam }); | ||
13056 | } | ||
13057 | }; | ||
13058 | |||
13059 | EC.prototype.verify = function verify(msg, signature, key, enc) { | ||
13060 | msg = this._truncateToN(new BN(msg, 16)); | ||
13061 | key = this.keyFromPublic(key, enc); | ||
13062 | signature = new Signature(signature, 'hex'); | ||
13063 | |||
13064 | // Perform primitive values validation | ||
13065 | var r = signature.r; | ||
13066 | var s = signature.s; | ||
13067 | if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) | ||
13068 | return false; | ||
13069 | if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) | ||
13070 | return false; | ||
13071 | |||
13072 | // Validate signature | ||
13073 | var sinv = s.invm(this.n); | ||
13074 | var u1 = sinv.mul(msg).umod(this.n); | ||
13075 | var u2 = sinv.mul(r).umod(this.n); | ||
13076 | |||
13077 | if (!this.curve._maxwellTrick) { | ||
13078 | var p = this.g.mulAdd(u1, key.getPublic(), u2); | ||
13079 | if (p.isInfinity()) | ||
13080 | return false; | ||
13081 | |||
13082 | return p.getX().umod(this.n).cmp(r) === 0; | ||
13083 | } | ||
13084 | |||
13085 | // NOTE: Greg Maxwell's trick, inspired by: | ||
13086 | // https://git.io/vad3K | ||
13087 | |||
13088 | var p = this.g.jmulAdd(u1, key.getPublic(), u2); | ||
13089 | if (p.isInfinity()) | ||
13090 | return false; | ||
13091 | |||
13092 | // Compare `p.x` of Jacobian point with `r`, | ||
13093 | // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the | ||
13094 | // inverse of `p.z^2` | ||
13095 | return p.eqXToP(r); | ||
13096 | }; | ||
13097 | |||
13098 | EC.prototype.recoverPubKey = function(msg, signature, j, enc) { | ||
13099 | assert((3 & j) === j, 'The recovery param is more than two bits'); | ||
13100 | signature = new Signature(signature, enc); | ||
13101 | |||
13102 | var n = this.n; | ||
13103 | var e = new BN(msg); | ||
13104 | var r = signature.r; | ||
13105 | var s = signature.s; | ||
13106 | |||
13107 | // A set LSB signifies that the y-coordinate is odd | ||
13108 | var isYOdd = j & 1; | ||
13109 | var isSecondKey = j >> 1; | ||
13110 | if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) | ||
13111 | throw new Error('Unable to find sencond key candinate'); | ||
13112 | |||
13113 | // 1.1. Let x = r + jn. | ||
13114 | if (isSecondKey) | ||
13115 | r = this.curve.pointFromX(r.add(this.curve.n), isYOdd); | ||
13116 | else | ||
13117 | r = this.curve.pointFromX(r, isYOdd); | ||
13118 | |||
13119 | var rInv = signature.r.invm(n); | ||
13120 | var s1 = n.sub(e).mul(rInv).umod(n); | ||
13121 | var s2 = s.mul(rInv).umod(n); | ||
13122 | |||
13123 | // 1.6.1 Compute Q = r^-1 (sR - eG) | ||
13124 | // Q = r^-1 (sR + -eG) | ||
13125 | return this.g.mulAdd(s1, r, s2); | ||
13126 | }; | ||
13127 | |||
13128 | EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { | ||
13129 | signature = new Signature(signature, enc); | ||
13130 | if (signature.recoveryParam !== null) | ||
13131 | return signature.recoveryParam; | ||
13132 | |||
13133 | for (var i = 0; i < 4; i++) { | ||
13134 | var Qprime; | ||
13135 | try { | ||
13136 | Qprime = this.recoverPubKey(e, signature, i); | ||
13137 | } catch (e) { | ||
13138 | continue; | ||
13139 | } | ||
13140 | |||
13141 | if (Qprime.eq(Q)) | ||
13142 | return i; | ||
13143 | } | ||
13144 | throw new Error('Unable to find valid recovery factor'); | ||
13145 | }; | ||
13146 | |||
13147 | },{"../../elliptic":39,"./key":47,"./signature":48,"bn.js":33}],47:[function(require,module,exports){ | ||
13148 | 'use strict'; | ||
13149 | |||
13150 | var BN = require('bn.js'); | ||
13151 | var elliptic = require('../../elliptic'); | ||
13152 | var utils = elliptic.utils; | ||
13153 | var assert = utils.assert; | ||
13154 | |||
13155 | function KeyPair(ec, options) { | ||
13156 | this.ec = ec; | ||
13157 | this.priv = null; | ||
13158 | this.pub = null; | ||
13159 | |||
13160 | // KeyPair(ec, { priv: ..., pub: ... }) | ||
13161 | if (options.priv) | ||
13162 | this._importPrivate(options.priv, options.privEnc); | ||
13163 | if (options.pub) | ||
13164 | this._importPublic(options.pub, options.pubEnc); | ||
13165 | } | ||
13166 | module.exports = KeyPair; | ||
13167 | |||
13168 | KeyPair.fromPublic = function fromPublic(ec, pub, enc) { | ||
13169 | if (pub instanceof KeyPair) | ||
13170 | return pub; | ||
13171 | |||
13172 | return new KeyPair(ec, { | ||
13173 | pub: pub, | ||
13174 | pubEnc: enc | ||
13175 | }); | ||
13176 | }; | ||
13177 | |||
13178 | KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) { | ||
13179 | if (priv instanceof KeyPair) | ||
13180 | return priv; | ||
13181 | |||
13182 | return new KeyPair(ec, { | ||
13183 | priv: priv, | ||
13184 | privEnc: enc | ||
13185 | }); | ||
13186 | }; | ||
13187 | |||
13188 | KeyPair.prototype.validate = function validate() { | ||
13189 | var pub = this.getPublic(); | ||
13190 | |||
13191 | if (pub.isInfinity()) | ||
13192 | return { result: false, reason: 'Invalid public key' }; | ||
13193 | if (!pub.validate()) | ||
13194 | return { result: false, reason: 'Public key is not a point' }; | ||
13195 | if (!pub.mul(this.ec.curve.n).isInfinity()) | ||
13196 | return { result: false, reason: 'Public key * N != O' }; | ||
13197 | |||
13198 | return { result: true, reason: null }; | ||
13199 | }; | ||
13200 | |||
13201 | KeyPair.prototype.getPublic = function getPublic(compact, enc) { | ||
13202 | // compact is optional argument | ||
13203 | if (typeof compact === 'string') { | ||
13204 | enc = compact; | ||
13205 | compact = null; | ||
13206 | } | ||
13207 | |||
13208 | if (!this.pub) | ||
13209 | this.pub = this.ec.g.mul(this.priv); | ||
13210 | |||
13211 | if (!enc) | ||
13212 | return this.pub; | ||
13213 | |||
13214 | return this.pub.encode(enc, compact); | ||
13215 | }; | ||
13216 | |||
13217 | KeyPair.prototype.getPrivate = function getPrivate(enc) { | ||
13218 | if (enc === 'hex') | ||
13219 | return this.priv.toString(16, 2); | ||
13220 | else | ||
13221 | return this.priv; | ||
13222 | }; | ||
13223 | |||
13224 | KeyPair.prototype._importPrivate = function _importPrivate(key, enc) { | ||
13225 | this.priv = new BN(key, enc || 16); | ||
13226 | |||
13227 | // Ensure that the priv won't be bigger than n, otherwise we may fail | ||
13228 | // in fixed multiplication method | ||
13229 | this.priv = this.priv.umod(this.ec.curve.n); | ||
13230 | }; | ||
13231 | |||
13232 | KeyPair.prototype._importPublic = function _importPublic(key, enc) { | ||
13233 | if (key.x || key.y) { | ||
13234 | // Montgomery points only have an `x` coordinate. | ||
13235 | // Weierstrass/Edwards points on the other hand have both `x` and | ||
13236 | // `y` coordinates. | ||
13237 | if (this.ec.curve.type === 'mont') { | ||
13238 | assert(key.x, 'Need x coordinate'); | ||
13239 | } else if (this.ec.curve.type === 'short' || | ||
13240 | this.ec.curve.type === 'edwards') { | ||
13241 | assert(key.x && key.y, 'Need both x and y coordinate'); | ||
13242 | } | ||
13243 | this.pub = this.ec.curve.point(key.x, key.y); | ||
13244 | return; | ||
13245 | } | ||
13246 | this.pub = this.ec.curve.decodePoint(key, enc); | ||
13247 | }; | ||
13248 | |||
13249 | // ECDH | ||
13250 | KeyPair.prototype.derive = function derive(pub) { | ||
13251 | return pub.mul(this.priv).getX(); | ||
13252 | }; | ||
13253 | |||
13254 | // ECDSA | ||
13255 | KeyPair.prototype.sign = function sign(msg, enc, options) { | ||
13256 | return this.ec.sign(msg, this, enc, options); | ||
13257 | }; | ||
13258 | |||
13259 | KeyPair.prototype.verify = function verify(msg, signature) { | ||
13260 | return this.ec.verify(msg, signature, this); | ||
13261 | }; | ||
13262 | |||
13263 | KeyPair.prototype.inspect = function inspect() { | ||
13264 | return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + | ||
13265 | ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; | ||
13266 | }; | ||
13267 | |||
13268 | },{"../../elliptic":39,"bn.js":33}],48:[function(require,module,exports){ | ||
13269 | 'use strict'; | ||
13270 | |||
13271 | var BN = require('bn.js'); | ||
13272 | |||
13273 | var elliptic = require('../../elliptic'); | ||
13274 | var utils = elliptic.utils; | ||
13275 | var assert = utils.assert; | ||
13276 | |||
13277 | function Signature(options, enc) { | ||
13278 | if (options instanceof Signature) | ||
13279 | return options; | ||
13280 | |||
13281 | if (this._importDER(options, enc)) | ||
13282 | return; | ||
13283 | |||
13284 | assert(options.r && options.s, 'Signature without r or s'); | ||
13285 | this.r = new BN(options.r, 16); | ||
13286 | this.s = new BN(options.s, 16); | ||
13287 | if (options.recoveryParam === undefined) | ||
13288 | this.recoveryParam = null; | ||
13289 | else | ||
13290 | this.recoveryParam = options.recoveryParam; | ||
13291 | } | ||
13292 | module.exports = Signature; | ||
13293 | |||
13294 | function Position() { | ||
13295 | this.place = 0; | ||
13296 | } | ||
13297 | |||
13298 | function getLength(buf, p) { | ||
13299 | var initial = buf[p.place++]; | ||
13300 | if (!(initial & 0x80)) { | ||
13301 | return initial; | ||
13302 | } | ||
13303 | var octetLen = initial & 0xf; | ||
13304 | var val = 0; | ||
13305 | for (var i = 0, off = p.place; i < octetLen; i++, off++) { | ||
13306 | val <<= 8; | ||
13307 | val |= buf[off]; | ||
13308 | } | ||
13309 | p.place = off; | ||
13310 | return val; | ||
13311 | } | ||
13312 | |||
13313 | function rmPadding(buf) { | ||
13314 | var i = 0; | ||
13315 | var len = buf.length - 1; | ||
13316 | while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) { | ||
13317 | i++; | ||
13318 | } | ||
13319 | if (i === 0) { | ||
13320 | return buf; | ||
13321 | } | ||
13322 | return buf.slice(i); | ||
13323 | } | ||
13324 | |||
13325 | Signature.prototype._importDER = function _importDER(data, enc) { | ||
13326 | data = utils.toArray(data, enc); | ||
13327 | var p = new Position(); | ||
13328 | if (data[p.place++] !== 0x30) { | ||
13329 | return false; | ||
13330 | } | ||
13331 | var len = getLength(data, p); | ||
13332 | if ((len + p.place) !== data.length) { | ||
13333 | return false; | ||
13334 | } | ||
13335 | if (data[p.place++] !== 0x02) { | ||
13336 | return false; | ||
13337 | } | ||
13338 | var rlen = getLength(data, p); | ||
13339 | var r = data.slice(p.place, rlen + p.place); | ||
13340 | p.place += rlen; | ||
13341 | if (data[p.place++] !== 0x02) { | ||
13342 | return false; | ||
13343 | } | ||
13344 | var slen = getLength(data, p); | ||
13345 | if (data.length !== slen + p.place) { | ||
13346 | return false; | ||
13347 | } | ||
13348 | var s = data.slice(p.place, slen + p.place); | ||
13349 | if (r[0] === 0 && (r[1] & 0x80)) { | ||
13350 | r = r.slice(1); | ||
13351 | } | ||
13352 | if (s[0] === 0 && (s[1] & 0x80)) { | ||
13353 | s = s.slice(1); | ||
13354 | } | ||
13355 | |||
13356 | this.r = new BN(r); | ||
13357 | this.s = new BN(s); | ||
13358 | this.recoveryParam = null; | ||
13359 | |||
13360 | return true; | ||
13361 | }; | ||
13362 | |||
13363 | function constructLength(arr, len) { | ||
13364 | if (len < 0x80) { | ||
13365 | arr.push(len); | ||
13366 | return; | ||
13367 | } | ||
13368 | var octets = 1 + (Math.log(len) / Math.LN2 >>> 3); | ||
13369 | arr.push(octets | 0x80); | ||
13370 | while (--octets) { | ||
13371 | arr.push((len >>> (octets << 3)) & 0xff); | ||
13372 | } | ||
13373 | arr.push(len); | ||
13374 | } | ||
13375 | |||
13376 | Signature.prototype.toDER = function toDER(enc) { | ||
13377 | var r = this.r.toArray(); | ||
13378 | var s = this.s.toArray(); | ||
13379 | |||
13380 | // Pad values | ||
13381 | if (r[0] & 0x80) | ||
13382 | r = [ 0 ].concat(r); | ||
13383 | // Pad values | ||
13384 | if (s[0] & 0x80) | ||
13385 | s = [ 0 ].concat(s); | ||
13386 | |||
13387 | r = rmPadding(r); | ||
13388 | s = rmPadding(s); | ||
13389 | |||
13390 | while (!s[0] && !(s[1] & 0x80)) { | ||
13391 | s = s.slice(1); | ||
13392 | } | ||
13393 | var arr = [ 0x02 ]; | ||
13394 | constructLength(arr, r.length); | ||
13395 | arr = arr.concat(r); | ||
13396 | arr.push(0x02); | ||
13397 | constructLength(arr, s.length); | ||
13398 | var backHalf = arr.concat(s); | ||
13399 | var res = [ 0x30 ]; | ||
13400 | constructLength(res, backHalf.length); | ||
13401 | res = res.concat(backHalf); | ||
13402 | return utils.encode(res, enc); | ||
13403 | }; | ||
13404 | |||
13405 | },{"../../elliptic":39,"bn.js":33}],49:[function(require,module,exports){ | ||
13406 | 'use strict'; | ||
13407 | |||
13408 | var hash = require('hash.js'); | ||
13409 | var elliptic = require('../../elliptic'); | ||
13410 | var utils = elliptic.utils; | ||
13411 | var assert = utils.assert; | ||
13412 | var parseBytes = utils.parseBytes; | ||
13413 | var KeyPair = require('./key'); | ||
13414 | var Signature = require('./signature'); | ||
13415 | |||
13416 | function EDDSA(curve) { | ||
13417 | assert(curve === 'ed25519', 'only tested with ed25519 so far'); | ||
13418 | |||
13419 | if (!(this instanceof EDDSA)) | ||
13420 | return new EDDSA(curve); | ||
13421 | |||
13422 | var curve = elliptic.curves[curve].curve; | ||
13423 | this.curve = curve; | ||
13424 | this.g = curve.g; | ||
13425 | this.g.precompute(curve.n.bitLength() + 1); | ||
13426 | |||
13427 | this.pointClass = curve.point().constructor; | ||
13428 | this.encodingLength = Math.ceil(curve.n.bitLength() / 8); | ||
13429 | this.hash = hash.sha512; | ||
13430 | } | ||
13431 | |||
13432 | module.exports = EDDSA; | ||
13433 | |||
13434 | /** | ||
13435 | * @param {Array|String} message - message bytes | ||
13436 | * @param {Array|String|KeyPair} secret - secret bytes or a keypair | ||
13437 | * @returns {Signature} - signature | ||
13438 | */ | ||
13439 | EDDSA.prototype.sign = function sign(message, secret) { | ||
13440 | message = parseBytes(message); | ||
13441 | var key = this.keyFromSecret(secret); | ||
13442 | var r = this.hashInt(key.messagePrefix(), message); | ||
13443 | var R = this.g.mul(r); | ||
13444 | var Rencoded = this.encodePoint(R); | ||
13445 | var s_ = this.hashInt(Rencoded, key.pubBytes(), message) | ||
13446 | .mul(key.priv()); | ||
13447 | var S = r.add(s_).umod(this.curve.n); | ||
13448 | return this.makeSignature({ R: R, S: S, Rencoded: Rencoded }); | ||
13449 | }; | ||
13450 | |||
13451 | /** | ||
13452 | * @param {Array} message - message bytes | ||
13453 | * @param {Array|String|Signature} sig - sig bytes | ||
13454 | * @param {Array|String|Point|KeyPair} pub - public key | ||
13455 | * @returns {Boolean} - true if public key matches sig of message | ||
13456 | */ | ||
13457 | EDDSA.prototype.verify = function verify(message, sig, pub) { | ||
13458 | message = parseBytes(message); | ||
13459 | sig = this.makeSignature(sig); | ||
13460 | var key = this.keyFromPublic(pub); | ||
13461 | var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message); | ||
13462 | var SG = this.g.mul(sig.S()); | ||
13463 | var RplusAh = sig.R().add(key.pub().mul(h)); | ||
13464 | return RplusAh.eq(SG); | ||
13465 | }; | ||
13466 | |||
13467 | EDDSA.prototype.hashInt = function hashInt() { | ||
13468 | var hash = this.hash(); | ||
13469 | for (var i = 0; i < arguments.length; i++) | ||
13470 | hash.update(arguments[i]); | ||
13471 | return utils.intFromLE(hash.digest()).umod(this.curve.n); | ||
13472 | }; | ||
13473 | |||
13474 | EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) { | ||
13475 | return KeyPair.fromPublic(this, pub); | ||
13476 | }; | ||
13477 | |||
13478 | EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) { | ||
13479 | return KeyPair.fromSecret(this, secret); | ||
13480 | }; | ||
13481 | |||
13482 | EDDSA.prototype.makeSignature = function makeSignature(sig) { | ||
13483 | if (sig instanceof Signature) | ||
13484 | return sig; | ||
13485 | return new Signature(this, sig); | ||
13486 | }; | ||
13487 | |||
13488 | /** | ||
13489 | * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2 | ||
13490 | * | ||
13491 | * EDDSA defines methods for encoding and decoding points and integers. These are | ||
13492 | * helper convenience methods, that pass along to utility functions implied | ||
13493 | * parameters. | ||
13494 | * | ||
13495 | */ | ||
13496 | EDDSA.prototype.encodePoint = function encodePoint(point) { | ||
13497 | var enc = point.getY().toArray('le', this.encodingLength); | ||
13498 | enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0; | ||
13499 | return enc; | ||
13500 | }; | ||
13501 | |||
13502 | EDDSA.prototype.decodePoint = function decodePoint(bytes) { | ||
13503 | bytes = utils.parseBytes(bytes); | ||
13504 | |||
13505 | var lastIx = bytes.length - 1; | ||
13506 | var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80); | ||
13507 | var xIsOdd = (bytes[lastIx] & 0x80) !== 0; | ||
13508 | |||
13509 | var y = utils.intFromLE(normed); | ||
13510 | return this.curve.pointFromY(y, xIsOdd); | ||
13511 | }; | ||
13512 | |||
13513 | EDDSA.prototype.encodeInt = function encodeInt(num) { | ||
13514 | return num.toArray('le', this.encodingLength); | ||
13515 | }; | ||
13516 | |||
13517 | EDDSA.prototype.decodeInt = function decodeInt(bytes) { | ||
13518 | return utils.intFromLE(bytes); | ||
13519 | }; | ||
13520 | |||
13521 | EDDSA.prototype.isPoint = function isPoint(val) { | ||
13522 | return val instanceof this.pointClass; | ||
13523 | }; | ||
13524 | |||
13525 | },{"../../elliptic":39,"./key":50,"./signature":51,"hash.js":57}],50:[function(require,module,exports){ | ||
13526 | 'use strict'; | ||
13527 | |||
13528 | var elliptic = require('../../elliptic'); | ||
13529 | var utils = elliptic.utils; | ||
13530 | var assert = utils.assert; | ||
13531 | var parseBytes = utils.parseBytes; | ||
13532 | var cachedProperty = utils.cachedProperty; | ||
13533 | |||
13534 | /** | ||
13535 | * @param {EDDSA} eddsa - instance | ||
13536 | * @param {Object} params - public/private key parameters | ||
13537 | * | ||
13538 | * @param {Array<Byte>} [params.secret] - secret seed bytes | ||
13539 | * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms) | ||
13540 | * @param {Array<Byte>} [params.pub] - public key point encoded as bytes | ||
13541 | * | ||
13542 | */ | ||
13543 | function KeyPair(eddsa, params) { | ||
13544 | this.eddsa = eddsa; | ||
13545 | this._secret = parseBytes(params.secret); | ||
13546 | if (eddsa.isPoint(params.pub)) | ||
13547 | this._pub = params.pub; | ||
13548 | else | ||
13549 | this._pubBytes = parseBytes(params.pub); | ||
13550 | } | ||
13551 | |||
13552 | KeyPair.fromPublic = function fromPublic(eddsa, pub) { | ||
13553 | if (pub instanceof KeyPair) | ||
13554 | return pub; | ||
13555 | return new KeyPair(eddsa, { pub: pub }); | ||
13556 | }; | ||
13557 | |||
13558 | KeyPair.fromSecret = function fromSecret(eddsa, secret) { | ||
13559 | if (secret instanceof KeyPair) | ||
13560 | return secret; | ||
13561 | return new KeyPair(eddsa, { secret: secret }); | ||
13562 | }; | ||
13563 | |||
13564 | KeyPair.prototype.secret = function secret() { | ||
13565 | return this._secret; | ||
13566 | }; | ||
13567 | |||
13568 | cachedProperty(KeyPair, 'pubBytes', function pubBytes() { | ||
13569 | return this.eddsa.encodePoint(this.pub()); | ||
13570 | }); | ||
13571 | |||
13572 | cachedProperty(KeyPair, 'pub', function pub() { | ||
13573 | if (this._pubBytes) | ||
13574 | return this.eddsa.decodePoint(this._pubBytes); | ||
13575 | return this.eddsa.g.mul(this.priv()); | ||
13576 | }); | ||
13577 | |||
13578 | cachedProperty(KeyPair, 'privBytes', function privBytes() { | ||
13579 | var eddsa = this.eddsa; | ||
13580 | var hash = this.hash(); | ||
13581 | var lastIx = eddsa.encodingLength - 1; | ||
13582 | |||
13583 | var a = hash.slice(0, eddsa.encodingLength); | ||
13584 | a[0] &= 248; | ||
13585 | a[lastIx] &= 127; | ||
13586 | a[lastIx] |= 64; | ||
13587 | |||
13588 | return a; | ||
13589 | }); | ||
13590 | |||
13591 | cachedProperty(KeyPair, 'priv', function priv() { | ||
13592 | return this.eddsa.decodeInt(this.privBytes()); | ||
13593 | }); | ||
13594 | |||
13595 | cachedProperty(KeyPair, 'hash', function hash() { | ||
13596 | return this.eddsa.hash().update(this.secret()).digest(); | ||
13597 | }); | ||
13598 | |||
13599 | cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() { | ||
13600 | return this.hash().slice(this.eddsa.encodingLength); | ||
13601 | }); | ||
13602 | |||
13603 | KeyPair.prototype.sign = function sign(message) { | ||
13604 | assert(this._secret, 'KeyPair can only verify'); | ||
13605 | return this.eddsa.sign(message, this); | ||
13606 | }; | ||
13607 | |||
13608 | KeyPair.prototype.verify = function verify(message, sig) { | ||
13609 | return this.eddsa.verify(message, sig, this); | ||
13610 | }; | ||
13611 | |||
13612 | KeyPair.prototype.getSecret = function getSecret(enc) { | ||
13613 | assert(this._secret, 'KeyPair is public only'); | ||
13614 | return utils.encode(this.secret(), enc); | ||
13615 | }; | ||
13616 | |||
13617 | KeyPair.prototype.getPublic = function getPublic(enc) { | ||
13618 | return utils.encode(this.pubBytes(), enc); | ||
13619 | }; | ||
13620 | |||
13621 | module.exports = KeyPair; | ||
13622 | |||
13623 | },{"../../elliptic":39}],51:[function(require,module,exports){ | ||
13624 | 'use strict'; | ||
13625 | |||
13626 | var BN = require('bn.js'); | ||
13627 | var elliptic = require('../../elliptic'); | ||
13628 | var utils = elliptic.utils; | ||
13629 | var assert = utils.assert; | ||
13630 | var cachedProperty = utils.cachedProperty; | ||
13631 | var parseBytes = utils.parseBytes; | ||
13632 | |||
13633 | /** | ||
13634 | * @param {EDDSA} eddsa - eddsa instance | ||
13635 | * @param {Array<Bytes>|Object} sig - | ||
13636 | * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes | ||
13637 | * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes | ||
13638 | * @param {Array<Bytes>} [sig.Rencoded] - R point encoded | ||
13639 | * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded | ||
13640 | */ | ||
13641 | function Signature(eddsa, sig) { | ||
13642 | this.eddsa = eddsa; | ||
13643 | |||
13644 | if (typeof sig !== 'object') | ||
13645 | sig = parseBytes(sig); | ||
13646 | |||
13647 | if (Array.isArray(sig)) { | ||
13648 | sig = { | ||
13649 | R: sig.slice(0, eddsa.encodingLength), | ||
13650 | S: sig.slice(eddsa.encodingLength) | ||
13651 | }; | ||
13652 | } | ||
13653 | |||
13654 | assert(sig.R && sig.S, 'Signature without R or S'); | ||
13655 | |||
13656 | if (eddsa.isPoint(sig.R)) | ||
13657 | this._R = sig.R; | ||
13658 | if (sig.S instanceof BN) | ||
13659 | this._S = sig.S; | ||
13660 | |||
13661 | this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded; | ||
13662 | this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded; | ||
13663 | } | ||
13664 | |||
13665 | cachedProperty(Signature, 'S', function S() { | ||
13666 | return this.eddsa.decodeInt(this.Sencoded()); | ||
13667 | }); | ||
13668 | |||
13669 | cachedProperty(Signature, 'R', function R() { | ||
13670 | return this.eddsa.decodePoint(this.Rencoded()); | ||
13671 | }); | ||
13672 | |||
13673 | cachedProperty(Signature, 'Rencoded', function Rencoded() { | ||
13674 | return this.eddsa.encodePoint(this.R()); | ||
13675 | }); | ||
13676 | |||
13677 | cachedProperty(Signature, 'Sencoded', function Sencoded() { | ||
13678 | return this.eddsa.encodeInt(this.S()); | ||
13679 | }); | ||
13680 | |||
13681 | Signature.prototype.toBytes = function toBytes() { | ||
13682 | return this.Rencoded().concat(this.Sencoded()); | ||
13683 | }; | ||
13684 | |||
13685 | Signature.prototype.toHex = function toHex() { | ||
13686 | return utils.encode(this.toBytes(), 'hex').toUpperCase(); | ||
13687 | }; | ||
13688 | |||
13689 | module.exports = Signature; | ||
13690 | |||
13691 | },{"../../elliptic":39,"bn.js":33}],52:[function(require,module,exports){ | ||
13692 | 'use strict'; | ||
13693 | |||
13694 | var hash = require('hash.js'); | ||
13695 | var elliptic = require('../elliptic'); | ||
13696 | var utils = elliptic.utils; | ||
13697 | var assert = utils.assert; | ||
13698 | |||
13699 | function HmacDRBG(options) { | ||
13700 | if (!(this instanceof HmacDRBG)) | ||
13701 | return new HmacDRBG(options); | ||
13702 | this.hash = options.hash; | ||
13703 | this.predResist = !!options.predResist; | ||
13704 | |||
13705 | this.outLen = this.hash.outSize; | ||
13706 | this.minEntropy = options.minEntropy || this.hash.hmacStrength; | ||
13707 | |||
13708 | this.reseed = null; | ||
13709 | this.reseedInterval = null; | ||
13710 | this.K = null; | ||
13711 | this.V = null; | ||
13712 | |||
13713 | var entropy = utils.toArray(options.entropy, options.entropyEnc); | ||
13714 | var nonce = utils.toArray(options.nonce, options.nonceEnc); | ||
13715 | var pers = utils.toArray(options.pers, options.persEnc); | ||
13716 | assert(entropy.length >= (this.minEntropy / 8), | ||
13717 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); | ||
13718 | this._init(entropy, nonce, pers); | ||
13719 | } | ||
13720 | module.exports = HmacDRBG; | ||
13721 | |||
13722 | HmacDRBG.prototype._init = function init(entropy, nonce, pers) { | ||
13723 | var seed = entropy.concat(nonce).concat(pers); | ||
13724 | |||
13725 | this.K = new Array(this.outLen / 8); | ||
13726 | this.V = new Array(this.outLen / 8); | ||
13727 | for (var i = 0; i < this.V.length; i++) { | ||
13728 | this.K[i] = 0x00; | ||
13729 | this.V[i] = 0x01; | ||
13730 | } | ||
13731 | |||
13732 | this._update(seed); | ||
13733 | this.reseed = 1; | ||
13734 | this.reseedInterval = 0x1000000000000; // 2^48 | ||
13735 | }; | ||
13736 | |||
13737 | HmacDRBG.prototype._hmac = function hmac() { | ||
13738 | return new hash.hmac(this.hash, this.K); | ||
13739 | }; | ||
13740 | |||
13741 | HmacDRBG.prototype._update = function update(seed) { | ||
13742 | var kmac = this._hmac() | ||
13743 | .update(this.V) | ||
13744 | .update([ 0x00 ]); | ||
13745 | if (seed) | ||
13746 | kmac = kmac.update(seed); | ||
13747 | this.K = kmac.digest(); | ||
13748 | this.V = this._hmac().update(this.V).digest(); | ||
13749 | if (!seed) | ||
13750 | return; | ||
13751 | |||
13752 | this.K = this._hmac() | ||
13753 | .update(this.V) | ||
13754 | .update([ 0x01 ]) | ||
13755 | .update(seed) | ||
13756 | .digest(); | ||
13757 | this.V = this._hmac().update(this.V).digest(); | ||
13758 | }; | ||
13759 | |||
13760 | HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { | ||
13761 | // Optional entropy enc | ||
13762 | if (typeof entropyEnc !== 'string') { | ||
13763 | addEnc = add; | ||
13764 | add = entropyEnc; | ||
13765 | entropyEnc = null; | ||
13766 | } | ||
13767 | |||
13768 | entropy = utils.toBuffer(entropy, entropyEnc); | ||
13769 | add = utils.toBuffer(add, addEnc); | ||
13770 | |||
13771 | assert(entropy.length >= (this.minEntropy / 8), | ||
13772 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); | ||
13773 | |||
13774 | this._update(entropy.concat(add || [])); | ||
13775 | this.reseed = 1; | ||
13776 | }; | ||
13777 | |||
13778 | HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { | ||
13779 | if (this.reseed > this.reseedInterval) | ||
13780 | throw new Error('Reseed is required'); | ||
13781 | |||
13782 | // Optional encoding | ||
13783 | if (typeof enc !== 'string') { | ||
13784 | addEnc = add; | ||
13785 | add = enc; | ||
13786 | enc = null; | ||
13787 | } | ||
13788 | |||
13789 | // Optional additional data | ||
13790 | if (add) { | ||
13791 | add = utils.toArray(add, addEnc); | ||
13792 | this._update(add); | ||
13793 | } | ||
13794 | |||
13795 | var temp = []; | ||
13796 | while (temp.length < len) { | ||
13797 | this.V = this._hmac().update(this.V).digest(); | ||
13798 | temp = temp.concat(this.V); | ||
13799 | } | ||
13800 | |||
13801 | var res = temp.slice(0, len); | ||
13802 | this._update(add); | ||
13803 | this.reseed++; | ||
13804 | return utils.encode(res, enc); | ||
13805 | }; | ||
13806 | |||
13807 | },{"../elliptic":39,"hash.js":57}],53:[function(require,module,exports){ | ||
13808 | module.exports = { | ||
13809 | doubles: { | ||
13810 | step: 4, | ||
13811 | points: [ | ||
13812 | [ | ||
13813 | 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a', | ||
13814 | 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821' | ||
13815 | ], | ||
13816 | [ | ||
13817 | '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508', | ||
13818 | '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf' | ||
13819 | ], | ||
13820 | [ | ||
13821 | '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739', | ||
13822 | 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695' | ||
13823 | ], | ||
13824 | [ | ||
13825 | '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640', | ||
13826 | '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9' | ||
13827 | ], | ||
13828 | [ | ||
13829 | '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c', | ||
13830 | '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36' | ||
13831 | ], | ||
13832 | [ | ||
13833 | '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda', | ||
13834 | '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f' | ||
13835 | ], | ||
13836 | [ | ||
13837 | 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa', | ||
13838 | '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999' | ||
13839 | ], | ||
13840 | [ | ||
13841 | '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0', | ||
13842 | 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09' | ||
13843 | ], | ||
13844 | [ | ||
13845 | 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d', | ||
13846 | '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d' | ||
13847 | ], | ||
13848 | [ | ||
13849 | 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d', | ||
13850 | 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088' | ||
13851 | ], | ||
13852 | [ | ||
13853 | 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1', | ||
13854 | '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d' | ||
13855 | ], | ||
13856 | [ | ||
13857 | '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0', | ||
13858 | '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8' | ||
13859 | ], | ||
13860 | [ | ||
13861 | '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047', | ||
13862 | '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a' | ||
13863 | ], | ||
13864 | [ | ||
13865 | '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862', | ||
13866 | '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453' | ||
13867 | ], | ||
13868 | [ | ||
13869 | '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7', | ||
13870 | '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160' | ||
13871 | ], | ||
13872 | [ | ||
13873 | '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd', | ||
13874 | '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0' | ||
13875 | ], | ||
13876 | [ | ||
13877 | '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83', | ||
13878 | '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6' | ||
13879 | ], | ||
13880 | [ | ||
13881 | '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a', | ||
13882 | '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589' | ||
13883 | ], | ||
13884 | [ | ||
13885 | '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8', | ||
13886 | 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17' | ||
13887 | ], | ||
13888 | [ | ||
13889 | 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d', | ||
13890 | '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda' | ||
13891 | ], | ||
13892 | [ | ||
13893 | 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725', | ||
13894 | '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd' | ||
13895 | ], | ||
13896 | [ | ||
13897 | '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754', | ||
13898 | '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2' | ||
13899 | ], | ||
13900 | [ | ||
13901 | '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c', | ||
13902 | '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6' | ||
13903 | ], | ||
13904 | [ | ||
13905 | 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6', | ||
13906 | '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f' | ||
13907 | ], | ||
13908 | [ | ||
13909 | '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39', | ||
13910 | 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01' | ||
13911 | ], | ||
13912 | [ | ||
13913 | 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891', | ||
13914 | '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3' | ||
13915 | ], | ||
13916 | [ | ||
13917 | 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b', | ||
13918 | 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f' | ||
13919 | ], | ||
13920 | [ | ||
13921 | 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03', | ||
13922 | '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7' | ||
13923 | ], | ||
13924 | [ | ||
13925 | 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d', | ||
13926 | 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78' | ||
13927 | ], | ||
13928 | [ | ||
13929 | 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070', | ||
13930 | '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1' | ||
13931 | ], | ||
13932 | [ | ||
13933 | '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4', | ||
13934 | 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150' | ||
13935 | ], | ||
13936 | [ | ||
13937 | '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da', | ||
13938 | '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82' | ||
13939 | ], | ||
13940 | [ | ||
13941 | 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11', | ||
13942 | '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc' | ||
13943 | ], | ||
13944 | [ | ||
13945 | '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e', | ||
13946 | 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b' | ||
13947 | ], | ||
13948 | [ | ||
13949 | 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41', | ||
13950 | '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51' | ||
13951 | ], | ||
13952 | [ | ||
13953 | 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef', | ||
13954 | '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45' | ||
13955 | ], | ||
13956 | [ | ||
13957 | 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8', | ||
13958 | 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120' | ||
13959 | ], | ||
13960 | [ | ||
13961 | '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d', | ||
13962 | '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84' | ||
13963 | ], | ||
13964 | [ | ||
13965 | '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96', | ||
13966 | '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d' | ||
13967 | ], | ||
13968 | [ | ||
13969 | '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd', | ||
13970 | 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d' | ||
13971 | ], | ||
13972 | [ | ||
13973 | '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5', | ||
13974 | '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8' | ||
13975 | ], | ||
13976 | [ | ||
13977 | 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266', | ||
13978 | '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8' | ||
13979 | ], | ||
13980 | [ | ||
13981 | '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71', | ||
13982 | '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac' | ||
13983 | ], | ||
13984 | [ | ||
13985 | '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac', | ||
13986 | 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f' | ||
13987 | ], | ||
13988 | [ | ||
13989 | '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751', | ||
13990 | '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962' | ||
13991 | ], | ||
13992 | [ | ||
13993 | 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e', | ||
13994 | '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907' | ||
13995 | ], | ||
13996 | [ | ||
13997 | '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241', | ||
13998 | 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec' | ||
13999 | ], | ||
14000 | [ | ||
14001 | 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3', | ||
14002 | 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d' | ||
14003 | ], | ||
14004 | [ | ||
14005 | 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f', | ||
14006 | '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414' | ||
14007 | ], | ||
14008 | [ | ||
14009 | '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19', | ||
14010 | 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd' | ||
14011 | ], | ||
14012 | [ | ||
14013 | '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be', | ||
14014 | 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0' | ||
14015 | ], | ||
14016 | [ | ||
14017 | 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9', | ||
14018 | '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811' | ||
14019 | ], | ||
14020 | [ | ||
14021 | 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2', | ||
14022 | '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1' | ||
14023 | ], | ||
14024 | [ | ||
14025 | 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13', | ||
14026 | '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c' | ||
14027 | ], | ||
14028 | [ | ||
14029 | '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c', | ||
14030 | 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73' | ||
14031 | ], | ||
14032 | [ | ||
14033 | '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba', | ||
14034 | '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd' | ||
14035 | ], | ||
14036 | [ | ||
14037 | 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151', | ||
14038 | 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405' | ||
14039 | ], | ||
14040 | [ | ||
14041 | '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073', | ||
14042 | 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589' | ||
14043 | ], | ||
14044 | [ | ||
14045 | '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458', | ||
14046 | '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e' | ||
14047 | ], | ||
14048 | [ | ||
14049 | '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b', | ||
14050 | '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27' | ||
14051 | ], | ||
14052 | [ | ||
14053 | 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366', | ||
14054 | 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1' | ||
14055 | ], | ||
14056 | [ | ||
14057 | '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa', | ||
14058 | '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482' | ||
14059 | ], | ||
14060 | [ | ||
14061 | '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0', | ||
14062 | '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945' | ||
14063 | ], | ||
14064 | [ | ||
14065 | 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787', | ||
14066 | '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573' | ||
14067 | ], | ||
14068 | [ | ||
14069 | 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e', | ||
14070 | 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82' | ||
14071 | ] | ||
14072 | ] | ||
14073 | }, | ||
14074 | naf: { | ||
14075 | wnd: 7, | ||
14076 | points: [ | ||
14077 | [ | ||
14078 | 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9', | ||
14079 | '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672' | ||
14080 | ], | ||
14081 | [ | ||
14082 | '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4', | ||
14083 | 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6' | ||
14084 | ], | ||
14085 | [ | ||
14086 | '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc', | ||
14087 | '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da' | ||
14088 | ], | ||
14089 | [ | ||
14090 | 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe', | ||
14091 | 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37' | ||
14092 | ], | ||
14093 | [ | ||
14094 | '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb', | ||
14095 | 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b' | ||
14096 | ], | ||
14097 | [ | ||
14098 | 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8', | ||
14099 | 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81' | ||
14100 | ], | ||
14101 | [ | ||
14102 | 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e', | ||
14103 | '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58' | ||
14104 | ], | ||
14105 | [ | ||
14106 | 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34', | ||
14107 | '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77' | ||
14108 | ], | ||
14109 | [ | ||
14110 | '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c', | ||
14111 | '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a' | ||
14112 | ], | ||
14113 | [ | ||
14114 | '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5', | ||
14115 | '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c' | ||
14116 | ], | ||
14117 | [ | ||
14118 | '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f', | ||
14119 | '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67' | ||
14120 | ], | ||
14121 | [ | ||
14122 | '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714', | ||
14123 | '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402' | ||
14124 | ], | ||
14125 | [ | ||
14126 | 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729', | ||
14127 | 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55' | ||
14128 | ], | ||
14129 | [ | ||
14130 | 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db', | ||
14131 | '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482' | ||
14132 | ], | ||
14133 | [ | ||
14134 | '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4', | ||
14135 | 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82' | ||
14136 | ], | ||
14137 | [ | ||
14138 | '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5', | ||
14139 | 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396' | ||
14140 | ], | ||
14141 | [ | ||
14142 | '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479', | ||
14143 | '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49' | ||
14144 | ], | ||
14145 | [ | ||
14146 | '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d', | ||
14147 | '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf' | ||
14148 | ], | ||
14149 | [ | ||
14150 | '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f', | ||
14151 | '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a' | ||
14152 | ], | ||
14153 | [ | ||
14154 | '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb', | ||
14155 | 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7' | ||
14156 | ], | ||
14157 | [ | ||
14158 | 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9', | ||
14159 | 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933' | ||
14160 | ], | ||
14161 | [ | ||
14162 | '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963', | ||
14163 | '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a' | ||
14164 | ], | ||
14165 | [ | ||
14166 | '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74', | ||
14167 | '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6' | ||
14168 | ], | ||
14169 | [ | ||
14170 | 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530', | ||
14171 | 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37' | ||
14172 | ], | ||
14173 | [ | ||
14174 | '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b', | ||
14175 | '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e' | ||
14176 | ], | ||
14177 | [ | ||
14178 | 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247', | ||
14179 | 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6' | ||
14180 | ], | ||
14181 | [ | ||
14182 | 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1', | ||
14183 | 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476' | ||
14184 | ], | ||
14185 | [ | ||
14186 | '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120', | ||
14187 | '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40' | ||
14188 | ], | ||
14189 | [ | ||
14190 | '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435', | ||
14191 | '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61' | ||
14192 | ], | ||
14193 | [ | ||
14194 | '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18', | ||
14195 | '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683' | ||
14196 | ], | ||
14197 | [ | ||
14198 | 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8', | ||
14199 | '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5' | ||
14200 | ], | ||
14201 | [ | ||
14202 | '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb', | ||
14203 | '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b' | ||
14204 | ], | ||
14205 | [ | ||
14206 | 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f', | ||
14207 | '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417' | ||
14208 | ], | ||
14209 | [ | ||
14210 | '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143', | ||
14211 | 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868' | ||
14212 | ], | ||
14213 | [ | ||
14214 | '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba', | ||
14215 | 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a' | ||
14216 | ], | ||
14217 | [ | ||
14218 | 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45', | ||
14219 | 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6' | ||
14220 | ], | ||
14221 | [ | ||
14222 | '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a', | ||
14223 | '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996' | ||
14224 | ], | ||
14225 | [ | ||
14226 | '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e', | ||
14227 | 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e' | ||
14228 | ], | ||
14229 | [ | ||
14230 | 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8', | ||
14231 | 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d' | ||
14232 | ], | ||
14233 | [ | ||
14234 | '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c', | ||
14235 | '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2' | ||
14236 | ], | ||
14237 | [ | ||
14238 | '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519', | ||
14239 | 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e' | ||
14240 | ], | ||
14241 | [ | ||
14242 | '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab', | ||
14243 | '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437' | ||
14244 | ], | ||
14245 | [ | ||
14246 | '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca', | ||
14247 | 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311' | ||
14248 | ], | ||
14249 | [ | ||
14250 | 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf', | ||
14251 | '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4' | ||
14252 | ], | ||
14253 | [ | ||
14254 | '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610', | ||
14255 | '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575' | ||
14256 | ], | ||
14257 | [ | ||
14258 | '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4', | ||
14259 | 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d' | ||
14260 | ], | ||
14261 | [ | ||
14262 | '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c', | ||
14263 | 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d' | ||
14264 | ], | ||
14265 | [ | ||
14266 | 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940', | ||
14267 | 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629' | ||
14268 | ], | ||
14269 | [ | ||
14270 | 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980', | ||
14271 | 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06' | ||
14272 | ], | ||
14273 | [ | ||
14274 | '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3', | ||
14275 | '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374' | ||
14276 | ], | ||
14277 | [ | ||
14278 | '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf', | ||
14279 | '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee' | ||
14280 | ], | ||
14281 | [ | ||
14282 | 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63', | ||
14283 | '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1' | ||
14284 | ], | ||
14285 | [ | ||
14286 | 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448', | ||
14287 | 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b' | ||
14288 | ], | ||
14289 | [ | ||
14290 | '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf', | ||
14291 | '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661' | ||
14292 | ], | ||
14293 | [ | ||
14294 | '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5', | ||
14295 | '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6' | ||
14296 | ], | ||
14297 | [ | ||
14298 | 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6', | ||
14299 | '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e' | ||
14300 | ], | ||
14301 | [ | ||
14302 | '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5', | ||
14303 | '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d' | ||
14304 | ], | ||
14305 | [ | ||
14306 | 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99', | ||
14307 | 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc' | ||
14308 | ], | ||
14309 | [ | ||
14310 | '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51', | ||
14311 | 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4' | ||
14312 | ], | ||
14313 | [ | ||
14314 | '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5', | ||
14315 | '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c' | ||
14316 | ], | ||
14317 | [ | ||
14318 | 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5', | ||
14319 | '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b' | ||
14320 | ], | ||
14321 | [ | ||
14322 | 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997', | ||
14323 | '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913' | ||
14324 | ], | ||
14325 | [ | ||
14326 | '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881', | ||
14327 | '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154' | ||
14328 | ], | ||
14329 | [ | ||
14330 | '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5', | ||
14331 | '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865' | ||
14332 | ], | ||
14333 | [ | ||
14334 | '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66', | ||
14335 | 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc' | ||
14336 | ], | ||
14337 | [ | ||
14338 | '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726', | ||
14339 | 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224' | ||
14340 | ], | ||
14341 | [ | ||
14342 | '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede', | ||
14343 | '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e' | ||
14344 | ], | ||
14345 | [ | ||
14346 | '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94', | ||
14347 | '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6' | ||
14348 | ], | ||
14349 | [ | ||
14350 | '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31', | ||
14351 | '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511' | ||
14352 | ], | ||
14353 | [ | ||
14354 | '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51', | ||
14355 | 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b' | ||
14356 | ], | ||
14357 | [ | ||
14358 | 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252', | ||
14359 | 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2' | ||
14360 | ], | ||
14361 | [ | ||
14362 | '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5', | ||
14363 | 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c' | ||
14364 | ], | ||
14365 | [ | ||
14366 | 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b', | ||
14367 | '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3' | ||
14368 | ], | ||
14369 | [ | ||
14370 | 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4', | ||
14371 | '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d' | ||
14372 | ], | ||
14373 | [ | ||
14374 | 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f', | ||
14375 | '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700' | ||
14376 | ], | ||
14377 | [ | ||
14378 | 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889', | ||
14379 | '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4' | ||
14380 | ], | ||
14381 | [ | ||
14382 | '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246', | ||
14383 | 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196' | ||
14384 | ], | ||
14385 | [ | ||
14386 | '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984', | ||
14387 | '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4' | ||
14388 | ], | ||
14389 | [ | ||
14390 | '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a', | ||
14391 | 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257' | ||
14392 | ], | ||
14393 | [ | ||
14394 | 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030', | ||
14395 | 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13' | ||
14396 | ], | ||
14397 | [ | ||
14398 | 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197', | ||
14399 | '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096' | ||
14400 | ], | ||
14401 | [ | ||
14402 | 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593', | ||
14403 | 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38' | ||
14404 | ], | ||
14405 | [ | ||
14406 | 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef', | ||
14407 | '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f' | ||
14408 | ], | ||
14409 | [ | ||
14410 | '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38', | ||
14411 | '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448' | ||
14412 | ], | ||
14413 | [ | ||
14414 | 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a', | ||
14415 | '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a' | ||
14416 | ], | ||
14417 | [ | ||
14418 | 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111', | ||
14419 | '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4' | ||
14420 | ], | ||
14421 | [ | ||
14422 | '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502', | ||
14423 | '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437' | ||
14424 | ], | ||
14425 | [ | ||
14426 | '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea', | ||
14427 | 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7' | ||
14428 | ], | ||
14429 | [ | ||
14430 | 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26', | ||
14431 | '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d' | ||
14432 | ], | ||
14433 | [ | ||
14434 | 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986', | ||
14435 | '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a' | ||
14436 | ], | ||
14437 | [ | ||
14438 | 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e', | ||
14439 | '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54' | ||
14440 | ], | ||
14441 | [ | ||
14442 | '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4', | ||
14443 | '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77' | ||
14444 | ], | ||
14445 | [ | ||
14446 | 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda', | ||
14447 | 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517' | ||
14448 | ], | ||
14449 | [ | ||
14450 | '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859', | ||
14451 | 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10' | ||
14452 | ], | ||
14453 | [ | ||
14454 | 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f', | ||
14455 | 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125' | ||
14456 | ], | ||
14457 | [ | ||
14458 | 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c', | ||
14459 | '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e' | ||
14460 | ], | ||
14461 | [ | ||
14462 | '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942', | ||
14463 | 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1' | ||
14464 | ], | ||
14465 | [ | ||
14466 | 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a', | ||
14467 | '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2' | ||
14468 | ], | ||
14469 | [ | ||
14470 | 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80', | ||
14471 | '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423' | ||
14472 | ], | ||
14473 | [ | ||
14474 | 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d', | ||
14475 | '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8' | ||
14476 | ], | ||
14477 | [ | ||
14478 | '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1', | ||
14479 | 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758' | ||
14480 | ], | ||
14481 | [ | ||
14482 | '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63', | ||
14483 | 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375' | ||
14484 | ], | ||
14485 | [ | ||
14486 | 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352', | ||
14487 | '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d' | ||
14488 | ], | ||
14489 | [ | ||
14490 | '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193', | ||
14491 | 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec' | ||
14492 | ], | ||
14493 | [ | ||
14494 | '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00', | ||
14495 | '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0' | ||
14496 | ], | ||
14497 | [ | ||
14498 | '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58', | ||
14499 | 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c' | ||
14500 | ], | ||
14501 | [ | ||
14502 | 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7', | ||
14503 | 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4' | ||
14504 | ], | ||
14505 | [ | ||
14506 | '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8', | ||
14507 | 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f' | ||
14508 | ], | ||
14509 | [ | ||
14510 | '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e', | ||
14511 | '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649' | ||
14512 | ], | ||
14513 | [ | ||
14514 | '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d', | ||
14515 | 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826' | ||
14516 | ], | ||
14517 | [ | ||
14518 | '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b', | ||
14519 | '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5' | ||
14520 | ], | ||
14521 | [ | ||
14522 | 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f', | ||
14523 | 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87' | ||
14524 | ], | ||
14525 | [ | ||
14526 | '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6', | ||
14527 | '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b' | ||
14528 | ], | ||
14529 | [ | ||
14530 | 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297', | ||
14531 | '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc' | ||
14532 | ], | ||
14533 | [ | ||
14534 | '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a', | ||
14535 | '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c' | ||
14536 | ], | ||
14537 | [ | ||
14538 | 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c', | ||
14539 | 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f' | ||
14540 | ], | ||
14541 | [ | ||
14542 | 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52', | ||
14543 | '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a' | ||
14544 | ], | ||
14545 | [ | ||
14546 | 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb', | ||
14547 | 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46' | ||
14548 | ], | ||
14549 | [ | ||
14550 | '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065', | ||
14551 | 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f' | ||
14552 | ], | ||
14553 | [ | ||
14554 | '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917', | ||
14555 | '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03' | ||
14556 | ], | ||
14557 | [ | ||
14558 | '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9', | ||
14559 | 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08' | ||
14560 | ], | ||
14561 | [ | ||
14562 | '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3', | ||
14563 | '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8' | ||
14564 | ], | ||
14565 | [ | ||
14566 | '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57', | ||
14567 | '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373' | ||
14568 | ], | ||
14569 | [ | ||
14570 | '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66', | ||
14571 | 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3' | ||
14572 | ], | ||
14573 | [ | ||
14574 | '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8', | ||
14575 | '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8' | ||
14576 | ], | ||
14577 | [ | ||
14578 | '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721', | ||
14579 | '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1' | ||
14580 | ], | ||
14581 | [ | ||
14582 | '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180', | ||
14583 | '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9' | ||
14584 | ] | ||
14585 | ] | ||
14586 | } | ||
14587 | }; | ||
14588 | |||
14589 | },{}],54:[function(require,module,exports){ | ||
14590 | 'use strict'; | ||
14591 | |||
14592 | var utils = exports; | ||
14593 | var BN = require('bn.js'); | ||
14594 | |||
14595 | utils.assert = function assert(val, msg) { | ||
14596 | if (!val) | ||
14597 | throw new Error(msg || 'Assertion failed'); | ||
14598 | }; | ||
14599 | |||
14600 | function toArray(msg, enc) { | ||
14601 | if (Array.isArray(msg)) | ||
14602 | return msg.slice(); | ||
14603 | if (!msg) | ||
14604 | return []; | ||
14605 | var res = []; | ||
14606 | if (typeof msg !== 'string') { | ||
14607 | for (var i = 0; i < msg.length; i++) | ||
14608 | res[i] = msg[i] | 0; | ||
14609 | return res; | ||
14610 | } | ||
14611 | if (!enc) { | ||
14612 | for (var i = 0; i < msg.length; i++) { | ||
14613 | var c = msg.charCodeAt(i); | ||
14614 | var hi = c >> 8; | ||
14615 | var lo = c & 0xff; | ||
14616 | if (hi) | ||
14617 | res.push(hi, lo); | ||
14618 | else | ||
14619 | res.push(lo); | ||
14620 | } | ||
14621 | } else if (enc === 'hex') { | ||
14622 | msg = msg.replace(/[^a-z0-9]+/ig, ''); | ||
14623 | if (msg.length % 2 !== 0) | ||
14624 | msg = '0' + msg; | ||
14625 | for (var i = 0; i < msg.length; i += 2) | ||
14626 | res.push(parseInt(msg[i] + msg[i + 1], 16)); | ||
14627 | } | ||
14628 | return res; | ||
14629 | } | ||
14630 | utils.toArray = toArray; | ||
14631 | |||
14632 | function zero2(word) { | ||
14633 | if (word.length === 1) | ||
14634 | return '0' + word; | ||
14635 | else | ||
14636 | return word; | ||
14637 | } | ||
14638 | utils.zero2 = zero2; | ||
14639 | |||
14640 | function toHex(msg) { | ||
14641 | var res = ''; | ||
14642 | for (var i = 0; i < msg.length; i++) | ||
14643 | res += zero2(msg[i].toString(16)); | ||
14644 | return res; | ||
14645 | } | ||
14646 | utils.toHex = toHex; | ||
14647 | |||
14648 | utils.encode = function encode(arr, enc) { | ||
14649 | if (enc === 'hex') | ||
14650 | return toHex(arr); | ||
14651 | else | ||
14652 | return arr; | ||
14653 | }; | ||
14654 | |||
14655 | // Represent num in a w-NAF form | ||
14656 | function getNAF(num, w) { | ||
14657 | var naf = []; | ||
14658 | var ws = 1 << (w + 1); | ||
14659 | var k = num.clone(); | ||
14660 | while (k.cmpn(1) >= 0) { | ||
14661 | var z; | ||
14662 | if (k.isOdd()) { | ||
14663 | var mod = k.andln(ws - 1); | ||
14664 | if (mod > (ws >> 1) - 1) | ||
14665 | z = (ws >> 1) - mod; | ||
14666 | else | ||
14667 | z = mod; | ||
14668 | k.isubn(z); | ||
14669 | } else { | ||
14670 | z = 0; | ||
14671 | } | ||
14672 | naf.push(z); | ||
14673 | |||
14674 | // Optimization, shift by word if possible | ||
14675 | var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1; | ||
14676 | for (var i = 1; i < shift; i++) | ||
14677 | naf.push(0); | ||
14678 | k.iushrn(shift); | ||
14679 | } | ||
14680 | |||
14681 | return naf; | ||
14682 | } | ||
14683 | utils.getNAF = getNAF; | ||
14684 | |||
14685 | // Represent k1, k2 in a Joint Sparse Form | ||
14686 | function getJSF(k1, k2) { | ||
14687 | var jsf = [ | ||
14688 | [], | ||
14689 | [] | ||
14690 | ]; | ||
14691 | |||
14692 | k1 = k1.clone(); | ||
14693 | k2 = k2.clone(); | ||
14694 | var d1 = 0; | ||
14695 | var d2 = 0; | ||
14696 | while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { | ||
14697 | |||
14698 | // First phase | ||
14699 | var m14 = (k1.andln(3) + d1) & 3; | ||
14700 | var m24 = (k2.andln(3) + d2) & 3; | ||
14701 | if (m14 === 3) | ||
14702 | m14 = -1; | ||
14703 | if (m24 === 3) | ||
14704 | m24 = -1; | ||
14705 | var u1; | ||
14706 | if ((m14 & 1) === 0) { | ||
14707 | u1 = 0; | ||
14708 | } else { | ||
14709 | var m8 = (k1.andln(7) + d1) & 7; | ||
14710 | if ((m8 === 3 || m8 === 5) && m24 === 2) | ||
14711 | u1 = -m14; | ||
14712 | else | ||
14713 | u1 = m14; | ||
14714 | } | ||
14715 | jsf[0].push(u1); | ||
14716 | |||
14717 | var u2; | ||
14718 | if ((m24 & 1) === 0) { | ||
14719 | u2 = 0; | ||
14720 | } else { | ||
14721 | var m8 = (k2.andln(7) + d2) & 7; | ||
14722 | if ((m8 === 3 || m8 === 5) && m14 === 2) | ||
14723 | u2 = -m24; | ||
14724 | else | ||
14725 | u2 = m24; | ||
14726 | } | ||
14727 | jsf[1].push(u2); | ||
14728 | |||
14729 | // Second phase | ||
14730 | if (2 * d1 === u1 + 1) | ||
14731 | d1 = 1 - d1; | ||
14732 | if (2 * d2 === u2 + 1) | ||
14733 | d2 = 1 - d2; | ||
14734 | k1.iushrn(1); | ||
14735 | k2.iushrn(1); | ||
14736 | } | ||
14737 | |||
14738 | return jsf; | ||
14739 | } | ||
14740 | utils.getJSF = getJSF; | ||
14741 | |||
14742 | function cachedProperty(obj, name, computer) { | ||
14743 | var key = '_' + name; | ||
14744 | obj.prototype[name] = function cachedProperty() { | ||
14745 | return this[key] !== undefined ? this[key] : | ||
14746 | this[key] = computer.call(this); | ||
14747 | }; | ||
14748 | } | ||
14749 | utils.cachedProperty = cachedProperty; | ||
14750 | |||
14751 | function parseBytes(bytes) { | ||
14752 | return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : | ||
14753 | bytes; | ||
14754 | } | ||
14755 | utils.parseBytes = parseBytes; | ||
14756 | |||
14757 | function intFromLE(bytes) { | ||
14758 | return new BN(bytes, 'hex', 'le'); | ||
14759 | } | ||
14760 | utils.intFromLE = intFromLE; | ||
14761 | |||
14762 | |||
14763 | },{"bn.js":33}],55:[function(require,module,exports){ | ||
14764 | module.exports={ | ||
14765 | "_args": [ | ||
14766 | [ | ||
14767 | { | ||
14768 | "raw": "elliptic@^6.2.3", | ||
14769 | "scope": null, | ||
14770 | "escapedName": "elliptic", | ||
14771 | "name": "elliptic", | ||
14772 | "rawSpec": "^6.2.3", | ||
14773 | "spec": ">=6.2.3 <7.0.0", | ||
14774 | "type": "range" | ||
14775 | }, | ||
14776 | "/home/user/ethereum/ethereumjs-util/node_modules/secp256k1" | ||
14777 | ] | ||
14778 | ], | ||
14779 | "_from": "elliptic@>=6.2.3 <7.0.0", | ||
14780 | "_id": "elliptic@6.3.3", | ||
14781 | "_inCache": true, | ||
14782 | "_location": "/elliptic", | ||
14783 | "_nodeVersion": "7.0.0", | ||
14784 | "_npmOperationalInternal": { | ||
14785 | "host": "packages-18-east.internal.npmjs.com", | ||
14786 | "tmp": "tmp/elliptic-6.3.3.tgz_1486422837740_0.10658654430881143" | ||
14787 | }, | ||
14788 | "_npmUser": { | ||
14789 | "name": "indutny", | ||
14790 | "email": "fedor@indutny.com" | ||
14791 | }, | ||
14792 | "_npmVersion": "3.10.8", | ||
14793 | "_phantomChildren": {}, | ||
14794 | "_requested": { | ||
14795 | "raw": "elliptic@^6.2.3", | ||
14796 | "scope": null, | ||
14797 | "escapedName": "elliptic", | ||
14798 | "name": "elliptic", | ||
14799 | "rawSpec": "^6.2.3", | ||
14800 | "spec": ">=6.2.3 <7.0.0", | ||
14801 | "type": "range" | ||
14802 | }, | ||
14803 | "_requiredBy": [ | ||
14804 | "/browserify-sign", | ||
14805 | "/create-ecdh", | ||
14806 | "/secp256k1" | ||
14807 | ], | ||
14808 | "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.3.3.tgz", | ||
14809 | "_shasum": "5482d9646d54bcb89fd7d994fc9e2e9568876e3f", | ||
14810 | "_shrinkwrap": null, | ||
14811 | "_spec": "elliptic@^6.2.3", | ||
14812 | "_where": "/home/user/ethereum/ethereumjs-util/node_modules/secp256k1", | ||
14813 | "author": { | ||
14814 | "name": "Fedor Indutny", | ||
14815 | "email": "fedor@indutny.com" | ||
14816 | }, | ||
14817 | "bugs": { | ||
14818 | "url": "https://github.com/indutny/elliptic/issues" | ||
14819 | }, | ||
14820 | "dependencies": { | ||
14821 | "bn.js": "^4.4.0", | ||
14822 | "brorand": "^1.0.1", | ||
14823 | "hash.js": "^1.0.0", | ||
14824 | "inherits": "^2.0.1" | ||
14825 | }, | ||
14826 | "description": "EC cryptography", | ||
14827 | "devDependencies": { | ||
14828 | "brfs": "^1.4.3", | ||
14829 | "coveralls": "^2.11.3", | ||
14830 | "grunt": "^0.4.5", | ||
14831 | "grunt-browserify": "^5.0.0", | ||
14832 | "grunt-cli": "^1.2.0", | ||
14833 | "grunt-contrib-connect": "^1.0.0", | ||
14834 | "grunt-contrib-copy": "^1.0.0", | ||
14835 | "grunt-contrib-uglify": "^1.0.1", | ||
14836 | "grunt-mocha-istanbul": "^3.0.1", | ||
14837 | "grunt-saucelabs": "^8.6.2", | ||
14838 | "istanbul": "^0.4.2", | ||
14839 | "jscs": "^2.9.0", | ||
14840 | "jshint": "^2.6.0", | ||
14841 | "mocha": "^2.1.0" | ||
14842 | }, | ||
14843 | "directories": {}, | ||
14844 | "dist": { | ||
14845 | "shasum": "5482d9646d54bcb89fd7d994fc9e2e9568876e3f", | ||
14846 | "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.3.3.tgz" | ||
14847 | }, | ||
14848 | "files": [ | ||
14849 | "lib" | ||
14850 | ], | ||
14851 | "gitHead": "63aee8d697e9b7fac37ece24222029117a890a7e", | ||
14852 | "homepage": "https://github.com/indutny/elliptic", | ||
14853 | "keywords": [ | ||
14854 | "EC", | ||
14855 | "Elliptic", | ||
14856 | "curve", | ||
14857 | "Cryptography" | ||
14858 | ], | ||
14859 | "license": "MIT", | ||
14860 | "main": "lib/elliptic.js", | ||
14861 | "maintainers": [ | ||
14862 | { | ||
14863 | "name": "indutny", | ||
14864 | "email": "fedor@indutny.com" | ||
14865 | } | ||
14866 | ], | ||
14867 | "name": "elliptic", | ||
14868 | "optionalDependencies": {}, | ||
14869 | "readme": "ERROR: No README data found!", | ||
14870 | "repository": { | ||
14871 | "type": "git", | ||
14872 | "url": "git+ssh://git@github.com/indutny/elliptic.git" | ||
14873 | }, | ||
14874 | "scripts": { | ||
14875 | "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js", | ||
14876 | "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js", | ||
14877 | "lint": "npm run jscs && npm run jshint", | ||
14878 | "test": "npm run lint && npm run unit", | ||
14879 | "unit": "istanbul test _mocha --reporter=spec test/index.js", | ||
14880 | "version": "grunt dist && git add dist/" | ||
14881 | }, | ||
14882 | "version": "6.3.3" | ||
14883 | } | ||
14884 | |||
14885 | },{}],56:[function(require,module,exports){ | ||
14886 | (function (Buffer){ | ||
14887 | 'use strict'; | ||
14888 | |||
14889 | var isHexPrefixed = require('is-hex-prefixed'); | ||
14890 | var stripHexPrefix = require('strip-hex-prefix'); | ||
14891 | |||
14892 | /** | ||
14893 | * Pads a `String` to have an even length | ||
14894 | * @param {String} value | ||
14895 | * @return {String} output | ||
14896 | */ | ||
14897 | function padToEven(value) { | ||
14898 | var a = value; // eslint-disable-line | ||
14899 | |||
14900 | if (typeof a !== 'string') { | ||
14901 | throw new Error('[ethjs-util] while padding to even, value must be string, is currently ' + typeof a + ', while padToEven.'); | ||
14902 | } | ||
14903 | |||
14904 | if (a.length % 2) { | ||
14905 | a = '0' + a; | ||
14906 | } | ||
14907 | |||
14908 | return a; | ||
14909 | } | ||
14910 | |||
14911 | /** | ||
14912 | * Converts a `Number` into a hex `String` | ||
14913 | * @param {Number} i | ||
14914 | * @return {String} | ||
14915 | */ | ||
14916 | function intToHex(i) { | ||
14917 | var hex = i.toString(16); // eslint-disable-line | ||
14918 | |||
14919 | return '0x' + padToEven(hex); | ||
14920 | } | ||
14921 | |||
14922 | /** | ||
14923 | * Converts an `Number` to a `Buffer` | ||
14924 | * @param {Number} i | ||
14925 | * @return {Buffer} | ||
14926 | */ | ||
14927 | function intToBuffer(i) { | ||
14928 | var hex = intToHex(i); | ||
14929 | |||
14930 | return new Buffer(hex.slice(2), 'hex'); | ||
14931 | } | ||
14932 | |||
14933 | /** | ||
14934 | * Get the binary size of a string | ||
14935 | * @param {String} str | ||
14936 | * @return {Number} | ||
14937 | */ | ||
14938 | function getBinarySize(str) { | ||
14939 | if (typeof str !== 'string') { | ||
14940 | throw new Error('[ethjs-util] while getting binary size, method getBinarySize requires input \'str\' to be type String, got \'' + typeof str + '\'.'); | ||
14941 | } | ||
14942 | |||
14943 | return Buffer.byteLength(str, 'utf8'); | ||
14944 | } | ||
14945 | |||
14946 | /** | ||
14947 | * Returns TRUE if the first specified array contains all elements | ||
14948 | * from the second one. FALSE otherwise. | ||
14949 | * | ||
14950 | * @param {array} superset | ||
14951 | * @param {array} subset | ||
14952 | * | ||
14953 | * @returns {boolean} | ||
14954 | */ | ||
14955 | function arrayContainsArray(superset, subset, some) { | ||
14956 | if (Array.isArray(superset) !== true) { | ||
14957 | throw new Error('[ethjs-util] method arrayContainsArray requires input \'superset\' to be an array got type \'' + typeof superset + '\''); | ||
14958 | } | ||
14959 | if (Array.isArray(subset) !== true) { | ||
14960 | throw new Error('[ethjs-util] method arrayContainsArray requires input \'subset\' to be an array got type \'' + typeof subset + '\''); | ||
14961 | } | ||
14962 | |||
14963 | return subset[Boolean(some) && 'some' || 'every'](function (value) { | ||
14964 | return superset.indexOf(value) >= 0; | ||
14965 | }); | ||
14966 | } | ||
14967 | |||
14968 | /** | ||
14969 | * Should be called to get utf8 from it's hex representation | ||
14970 | * | ||
14971 | * @method toUtf8 | ||
14972 | * @param {String} string in hex | ||
14973 | * @returns {String} ascii string representation of hex value | ||
14974 | */ | ||
14975 | function toUtf8(hex) { | ||
14976 | var bufferValue = new Buffer(padToEven(stripHexPrefix(hex).replace(/^0+|0+$/g, '')), 'hex'); | ||
14977 | |||
14978 | return bufferValue.toString('utf8'); | ||
14979 | } | ||
14980 | |||
14981 | /** | ||
14982 | * Should be called to get ascii from it's hex representation | ||
14983 | * | ||
14984 | * @method toAscii | ||
14985 | * @param {String} string in hex | ||
14986 | * @returns {String} ascii string representation of hex value | ||
14987 | */ | ||
14988 | function toAscii(hex) { | ||
14989 | var str = ''; // eslint-disable-line | ||
14990 | var i = 0, | ||
14991 | l = hex.length; // eslint-disable-line | ||
14992 | |||
14993 | if (hex.substring(0, 2) === '0x') { | ||
14994 | i = 2; | ||
14995 | } | ||
14996 | |||
14997 | for (; i < l; i += 2) { | ||
14998 | var code = parseInt(hex.substr(i, 2), 16); | ||
14999 | str += String.fromCharCode(code); | ||
15000 | } | ||
15001 | |||
15002 | return str; | ||
15003 | } | ||
15004 | |||
15005 | /** | ||
15006 | * Should be called to get hex representation (prefixed by 0x) of utf8 string | ||
15007 | * | ||
15008 | * @method fromUtf8 | ||
15009 | * @param {String} string | ||
15010 | * @param {Number} optional padding | ||
15011 | * @returns {String} hex representation of input string | ||
15012 | */ | ||
15013 | function fromUtf8(stringValue) { | ||
15014 | var str = new Buffer(stringValue, 'utf8'); | ||
15015 | |||
15016 | return '0x' + padToEven(str.toString('hex')).replace(/^0+|0+$/g, ''); | ||
15017 | } | ||
15018 | |||
15019 | /** | ||
15020 | * Should be called to get hex representation (prefixed by 0x) of ascii string | ||
15021 | * | ||
15022 | * @method fromAscii | ||
15023 | * @param {String} string | ||
15024 | * @param {Number} optional padding | ||
15025 | * @returns {String} hex representation of input string | ||
15026 | */ | ||
15027 | function fromAscii(stringValue) { | ||
15028 | var hex = ''; // eslint-disable-line | ||
15029 | for (var i = 0; i < stringValue.length; i++) { | ||
15030 | // eslint-disable-line | ||
15031 | var code = stringValue.charCodeAt(i); | ||
15032 | var n = code.toString(16); | ||
15033 | hex += n.length < 2 ? '0' + n : n; | ||
15034 | } | ||
15035 | |||
15036 | return '0x' + hex; | ||
15037 | } | ||
15038 | |||
15039 | /** | ||
15040 | * getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3] | ||
15041 | * | ||
15042 | * @method getKeys get specific key from inner object array of objects | ||
15043 | * @param {String} params | ||
15044 | * @param {String} key | ||
15045 | * @param {Boolean} allowEmpty | ||
15046 | * @returns {Array} output just a simple array of output keys | ||
15047 | */ | ||
15048 | function getKeys(params, key, allowEmpty) { | ||
15049 | if (!Array.isArray(params)) { | ||
15050 | throw new Error('[ethjs-util] method getKeys expecting type Array as \'params\' input, got \'' + typeof params + '\''); | ||
15051 | } | ||
15052 | if (typeof key !== 'string') { | ||
15053 | throw new Error('[ethjs-util] method getKeys expecting type String for input \'key\' got \'' + typeof key + '\'.'); | ||
15054 | } | ||
15055 | |||
15056 | var result = []; // eslint-disable-line | ||
15057 | |||
15058 | for (var i = 0; i < params.length; i++) { | ||
15059 | // eslint-disable-line | ||
15060 | var value = params[i][key]; // eslint-disable-line | ||
15061 | if (allowEmpty && !value) { | ||
15062 | value = ''; | ||
15063 | } else if (typeof value !== 'string') { | ||
15064 | throw new Error('invalid abi'); | ||
15065 | } | ||
15066 | result.push(value); | ||
15067 | } | ||
15068 | |||
15069 | return result; | ||
15070 | } | ||
15071 | |||
15072 | /** | ||
15073 | * Is the string a hex string. | ||
15074 | * | ||
15075 | * @method check if string is hex string of specific length | ||
15076 | * @param {String} value | ||
15077 | * @param {Number} length | ||
15078 | * @returns {Boolean} output the string is a hex string | ||
15079 | */ | ||
15080 | function isHexString(value, length) { | ||
15081 | if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) { | ||
15082 | return false; | ||
15083 | } | ||
15084 | |||
15085 | if (length && value.length !== 2 + 2 * length) { | ||
15086 | return false; | ||
15087 | } | ||
15088 | |||
15089 | return true; | ||
15090 | } | ||
15091 | |||
15092 | module.exports = { | ||
15093 | arrayContainsArray: arrayContainsArray, | ||
15094 | intToBuffer: intToBuffer, | ||
15095 | getBinarySize: getBinarySize, | ||
15096 | isHexPrefixed: isHexPrefixed, | ||
15097 | stripHexPrefix: stripHexPrefix, | ||
15098 | padToEven: padToEven, | ||
15099 | intToHex: intToHex, | ||
15100 | fromAscii: fromAscii, | ||
15101 | fromUtf8: fromUtf8, | ||
15102 | toAscii: toAscii, | ||
15103 | toUtf8: toUtf8, | ||
15104 | getKeys: getKeys, | ||
15105 | isHexString: isHexString | ||
15106 | }; | ||
15107 | }).call(this,require("buffer").Buffer) | ||
15108 | },{"buffer":5,"is-hex-prefixed":64,"strip-hex-prefix":87}],57:[function(require,module,exports){ | ||
15109 | var hash = exports; | ||
15110 | |||
15111 | hash.utils = require('./hash/utils'); | ||
15112 | hash.common = require('./hash/common'); | ||
15113 | hash.sha = require('./hash/sha'); | ||
15114 | hash.ripemd = require('./hash/ripemd'); | ||
15115 | hash.hmac = require('./hash/hmac'); | ||
15116 | |||
15117 | // Proxy hash functions to the main object | ||
15118 | hash.sha1 = hash.sha.sha1; | ||
15119 | hash.sha256 = hash.sha.sha256; | ||
15120 | hash.sha224 = hash.sha.sha224; | ||
15121 | hash.sha384 = hash.sha.sha384; | ||
15122 | hash.sha512 = hash.sha.sha512; | ||
15123 | hash.ripemd160 = hash.ripemd.ripemd160; | ||
15124 | |||
15125 | },{"./hash/common":58,"./hash/hmac":59,"./hash/ripemd":60,"./hash/sha":61,"./hash/utils":62}],58:[function(require,module,exports){ | ||
15126 | var hash = require('../hash'); | ||
15127 | var utils = hash.utils; | ||
15128 | var assert = utils.assert; | ||
15129 | |||
15130 | function BlockHash() { | ||
15131 | this.pending = null; | ||
15132 | this.pendingTotal = 0; | ||
15133 | this.blockSize = this.constructor.blockSize; | ||
15134 | this.outSize = this.constructor.outSize; | ||
15135 | this.hmacStrength = this.constructor.hmacStrength; | ||
15136 | this.padLength = this.constructor.padLength / 8; | ||
15137 | this.endian = 'big'; | ||
15138 | |||
15139 | this._delta8 = this.blockSize / 8; | ||
15140 | this._delta32 = this.blockSize / 32; | ||
15141 | } | ||
15142 | exports.BlockHash = BlockHash; | ||
15143 | |||
15144 | BlockHash.prototype.update = function update(msg, enc) { | ||
15145 | // Convert message to array, pad it, and join into 32bit blocks | ||
15146 | msg = utils.toArray(msg, enc); | ||
15147 | if (!this.pending) | ||
15148 | this.pending = msg; | ||
15149 | else | ||
15150 | this.pending = this.pending.concat(msg); | ||
15151 | this.pendingTotal += msg.length; | ||
15152 | |||
15153 | // Enough data, try updating | ||
15154 | if (this.pending.length >= this._delta8) { | ||
15155 | msg = this.pending; | ||
15156 | |||
15157 | // Process pending data in blocks | ||
15158 | var r = msg.length % this._delta8; | ||
15159 | this.pending = msg.slice(msg.length - r, msg.length); | ||
15160 | if (this.pending.length === 0) | ||
15161 | this.pending = null; | ||
15162 | |||
15163 | msg = utils.join32(msg, 0, msg.length - r, this.endian); | ||
15164 | for (var i = 0; i < msg.length; i += this._delta32) | ||
15165 | this._update(msg, i, i + this._delta32); | ||
15166 | } | ||
15167 | |||
15168 | return this; | ||
15169 | }; | ||
15170 | |||
15171 | BlockHash.prototype.digest = function digest(enc) { | ||
15172 | this.update(this._pad()); | ||
15173 | assert(this.pending === null); | ||
15174 | |||
15175 | return this._digest(enc); | ||
15176 | }; | ||
15177 | |||
15178 | BlockHash.prototype._pad = function pad() { | ||
15179 | var len = this.pendingTotal; | ||
15180 | var bytes = this._delta8; | ||
15181 | var k = bytes - ((len + this.padLength) % bytes); | ||
15182 | var res = new Array(k + this.padLength); | ||
15183 | res[0] = 0x80; | ||
15184 | for (var i = 1; i < k; i++) | ||
15185 | res[i] = 0; | ||
15186 | |||
15187 | // Append length | ||
15188 | len <<= 3; | ||
15189 | if (this.endian === 'big') { | ||
15190 | for (var t = 8; t < this.padLength; t++) | ||
15191 | res[i++] = 0; | ||
15192 | |||
15193 | res[i++] = 0; | ||
15194 | res[i++] = 0; | ||
15195 | res[i++] = 0; | ||
15196 | res[i++] = 0; | ||
15197 | res[i++] = (len >>> 24) & 0xff; | ||
15198 | res[i++] = (len >>> 16) & 0xff; | ||
15199 | res[i++] = (len >>> 8) & 0xff; | ||
15200 | res[i++] = len & 0xff; | ||
15201 | } else { | ||
15202 | res[i++] = len & 0xff; | ||
15203 | res[i++] = (len >>> 8) & 0xff; | ||
15204 | res[i++] = (len >>> 16) & 0xff; | ||
15205 | res[i++] = (len >>> 24) & 0xff; | ||
15206 | res[i++] = 0; | ||
15207 | res[i++] = 0; | ||
15208 | res[i++] = 0; | ||
15209 | res[i++] = 0; | ||
15210 | |||
15211 | for (var t = 8; t < this.padLength; t++) | ||
15212 | res[i++] = 0; | ||
15213 | } | ||
15214 | |||
15215 | return res; | ||
15216 | }; | ||
15217 | |||
15218 | },{"../hash":57}],59:[function(require,module,exports){ | ||
15219 | var hmac = exports; | ||
15220 | |||
15221 | var hash = require('../hash'); | ||
15222 | var utils = hash.utils; | ||
15223 | var assert = utils.assert; | ||
15224 | |||
15225 | function Hmac(hash, key, enc) { | ||
15226 | if (!(this instanceof Hmac)) | ||
15227 | return new Hmac(hash, key, enc); | ||
15228 | this.Hash = hash; | ||
15229 | this.blockSize = hash.blockSize / 8; | ||
15230 | this.outSize = hash.outSize / 8; | ||
15231 | this.inner = null; | ||
15232 | this.outer = null; | ||
15233 | |||
15234 | this._init(utils.toArray(key, enc)); | ||
15235 | } | ||
15236 | module.exports = Hmac; | ||
15237 | |||
15238 | Hmac.prototype._init = function init(key) { | ||
15239 | // Shorten key, if needed | ||
15240 | if (key.length > this.blockSize) | ||
15241 | key = new this.Hash().update(key).digest(); | ||
15242 | assert(key.length <= this.blockSize); | ||
15243 | |||
15244 | // Add padding to key | ||
15245 | for (var i = key.length; i < this.blockSize; i++) | ||
15246 | key.push(0); | ||
15247 | |||
15248 | for (var i = 0; i < key.length; i++) | ||
15249 | key[i] ^= 0x36; | ||
15250 | this.inner = new this.Hash().update(key); | ||
15251 | |||
15252 | // 0x36 ^ 0x5c = 0x6a | ||
15253 | for (var i = 0; i < key.length; i++) | ||
15254 | key[i] ^= 0x6a; | ||
15255 | this.outer = new this.Hash().update(key); | ||
15256 | }; | ||
15257 | |||
15258 | Hmac.prototype.update = function update(msg, enc) { | ||
15259 | this.inner.update(msg, enc); | ||
15260 | return this; | ||
15261 | }; | ||
15262 | |||
15263 | Hmac.prototype.digest = function digest(enc) { | ||
15264 | this.outer.update(this.inner.digest()); | ||
15265 | return this.outer.digest(enc); | ||
15266 | }; | ||
15267 | |||
15268 | },{"../hash":57}],60:[function(require,module,exports){ | ||
15269 | var hash = require('../hash'); | ||
15270 | var utils = hash.utils; | ||
15271 | |||
15272 | var rotl32 = utils.rotl32; | ||
15273 | var sum32 = utils.sum32; | ||
15274 | var sum32_3 = utils.sum32_3; | ||
15275 | var sum32_4 = utils.sum32_4; | ||
15276 | var BlockHash = hash.common.BlockHash; | ||
15277 | |||
15278 | function RIPEMD160() { | ||
15279 | if (!(this instanceof RIPEMD160)) | ||
15280 | return new RIPEMD160(); | ||
15281 | |||
15282 | BlockHash.call(this); | ||
15283 | |||
15284 | this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ]; | ||
15285 | this.endian = 'little'; | ||
15286 | } | ||
15287 | utils.inherits(RIPEMD160, BlockHash); | ||
15288 | exports.ripemd160 = RIPEMD160; | ||
15289 | |||
15290 | RIPEMD160.blockSize = 512; | ||
15291 | RIPEMD160.outSize = 160; | ||
15292 | RIPEMD160.hmacStrength = 192; | ||
15293 | RIPEMD160.padLength = 64; | ||
15294 | |||
15295 | RIPEMD160.prototype._update = function update(msg, start) { | ||
15296 | var A = this.h[0]; | ||
15297 | var B = this.h[1]; | ||
15298 | var C = this.h[2]; | ||
15299 | var D = this.h[3]; | ||
15300 | var E = this.h[4]; | ||
15301 | var Ah = A; | ||
15302 | var Bh = B; | ||
15303 | var Ch = C; | ||
15304 | var Dh = D; | ||
15305 | var Eh = E; | ||
15306 | for (var j = 0; j < 80; j++) { | ||
15307 | var T = sum32( | ||
15308 | rotl32( | ||
15309 | sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), | ||
15310 | s[j]), | ||
15311 | E); | ||
15312 | A = E; | ||
15313 | E = D; | ||
15314 | D = rotl32(C, 10); | ||
15315 | C = B; | ||
15316 | B = T; | ||
15317 | T = sum32( | ||
15318 | rotl32( | ||
15319 | sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), | ||
15320 | sh[j]), | ||
15321 | Eh); | ||
15322 | Ah = Eh; | ||
15323 | Eh = Dh; | ||
15324 | Dh = rotl32(Ch, 10); | ||
15325 | Ch = Bh; | ||
15326 | Bh = T; | ||
15327 | } | ||
15328 | T = sum32_3(this.h[1], C, Dh); | ||
15329 | this.h[1] = sum32_3(this.h[2], D, Eh); | ||
15330 | this.h[2] = sum32_3(this.h[3], E, Ah); | ||
15331 | this.h[3] = sum32_3(this.h[4], A, Bh); | ||
15332 | this.h[4] = sum32_3(this.h[0], B, Ch); | ||
15333 | this.h[0] = T; | ||
15334 | }; | ||
15335 | |||
15336 | RIPEMD160.prototype._digest = function digest(enc) { | ||
15337 | if (enc === 'hex') | ||
15338 | return utils.toHex32(this.h, 'little'); | ||
15339 | else | ||
15340 | return utils.split32(this.h, 'little'); | ||
15341 | }; | ||
15342 | |||
15343 | function f(j, x, y, z) { | ||
15344 | if (j <= 15) | ||
15345 | return x ^ y ^ z; | ||
15346 | else if (j <= 31) | ||
15347 | return (x & y) | ((~x) & z); | ||
15348 | else if (j <= 47) | ||
15349 | return (x | (~y)) ^ z; | ||
15350 | else if (j <= 63) | ||
15351 | return (x & z) | (y & (~z)); | ||
15352 | else | ||
15353 | return x ^ (y | (~z)); | ||
15354 | } | ||
15355 | |||
15356 | function K(j) { | ||
15357 | if (j <= 15) | ||
15358 | return 0x00000000; | ||
15359 | else if (j <= 31) | ||
15360 | return 0x5a827999; | ||
15361 | else if (j <= 47) | ||
15362 | return 0x6ed9eba1; | ||
15363 | else if (j <= 63) | ||
15364 | return 0x8f1bbcdc; | ||
15365 | else | ||
15366 | return 0xa953fd4e; | ||
15367 | } | ||
15368 | |||
15369 | function Kh(j) { | ||
15370 | if (j <= 15) | ||
15371 | return 0x50a28be6; | ||
15372 | else if (j <= 31) | ||
15373 | return 0x5c4dd124; | ||
15374 | else if (j <= 47) | ||
15375 | return 0x6d703ef3; | ||
15376 | else if (j <= 63) | ||
15377 | return 0x7a6d76e9; | ||
15378 | else | ||
15379 | return 0x00000000; | ||
15380 | } | ||
15381 | |||
15382 | var r = [ | ||
15383 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, | ||
15384 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, | ||
15385 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, | ||
15386 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, | ||
15387 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 | ||
15388 | ]; | ||
15389 | |||
15390 | var rh = [ | ||
15391 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, | ||
15392 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, | ||
15393 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, | ||
15394 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, | ||
15395 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 | ||
15396 | ]; | ||
15397 | |||
15398 | var s = [ | ||
15399 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, | ||
15400 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, | ||
15401 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, | ||
15402 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, | ||
15403 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 | ||
15404 | ]; | ||
15405 | |||
15406 | var sh = [ | ||
15407 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, | ||
15408 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, | ||
15409 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, | ||
15410 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, | ||
15411 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 | ||
15412 | ]; | ||
15413 | |||
15414 | },{"../hash":57}],61:[function(require,module,exports){ | ||
15415 | var hash = require('../hash'); | ||
15416 | var utils = hash.utils; | ||
15417 | var assert = utils.assert; | ||
15418 | |||
15419 | var rotr32 = utils.rotr32; | ||
15420 | var rotl32 = utils.rotl32; | ||
15421 | var sum32 = utils.sum32; | ||
15422 | var sum32_4 = utils.sum32_4; | ||
15423 | var sum32_5 = utils.sum32_5; | ||
15424 | var rotr64_hi = utils.rotr64_hi; | ||
15425 | var rotr64_lo = utils.rotr64_lo; | ||
15426 | var shr64_hi = utils.shr64_hi; | ||
15427 | var shr64_lo = utils.shr64_lo; | ||
15428 | var sum64 = utils.sum64; | ||
15429 | var sum64_hi = utils.sum64_hi; | ||
15430 | var sum64_lo = utils.sum64_lo; | ||
15431 | var sum64_4_hi = utils.sum64_4_hi; | ||
15432 | var sum64_4_lo = utils.sum64_4_lo; | ||
15433 | var sum64_5_hi = utils.sum64_5_hi; | ||
15434 | var sum64_5_lo = utils.sum64_5_lo; | ||
15435 | var BlockHash = hash.common.BlockHash; | ||
15436 | |||
15437 | var sha256_K = [ | ||
15438 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, | ||
15439 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | ||
15440 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, | ||
15441 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, | ||
15442 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, | ||
15443 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, | ||
15444 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, | ||
15445 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, | ||
15446 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, | ||
15447 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, | ||
15448 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, | ||
15449 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, | ||
15450 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, | ||
15451 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, | ||
15452 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, | ||
15453 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 | ||
15454 | ]; | ||
15455 | |||
15456 | var sha512_K = [ | ||
15457 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, | ||
15458 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, | ||
15459 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, | ||
15460 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, | ||
15461 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, | ||
15462 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, | ||
15463 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, | ||
15464 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, | ||
15465 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, | ||
15466 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, | ||
15467 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, | ||
15468 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, | ||
15469 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, | ||
15470 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, | ||
15471 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, | ||
15472 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, | ||
15473 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, | ||
15474 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, | ||
15475 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, | ||
15476 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, | ||
15477 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, | ||
15478 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, | ||
15479 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, | ||
15480 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, | ||
15481 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, | ||
15482 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, | ||
15483 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, | ||
15484 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, | ||
15485 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, | ||
15486 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, | ||
15487 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, | ||
15488 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, | ||
15489 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, | ||
15490 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, | ||
15491 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, | ||
15492 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, | ||
15493 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, | ||
15494 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, | ||
15495 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, | ||
15496 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 | ||
15497 | ]; | ||
15498 | |||
15499 | var sha1_K = [ | ||
15500 | 0x5A827999, 0x6ED9EBA1, | ||
15501 | 0x8F1BBCDC, 0xCA62C1D6 | ||
15502 | ]; | ||
15503 | |||
15504 | function SHA256() { | ||
15505 | if (!(this instanceof SHA256)) | ||
15506 | return new SHA256(); | ||
15507 | |||
15508 | BlockHash.call(this); | ||
15509 | this.h = [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, | ||
15510 | 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ]; | ||
15511 | this.k = sha256_K; | ||
15512 | this.W = new Array(64); | ||
15513 | } | ||
15514 | utils.inherits(SHA256, BlockHash); | ||
15515 | exports.sha256 = SHA256; | ||
15516 | |||
15517 | SHA256.blockSize = 512; | ||
15518 | SHA256.outSize = 256; | ||
15519 | SHA256.hmacStrength = 192; | ||
15520 | SHA256.padLength = 64; | ||
15521 | |||
15522 | SHA256.prototype._update = function _update(msg, start) { | ||
15523 | var W = this.W; | ||
15524 | |||
15525 | for (var i = 0; i < 16; i++) | ||
15526 | W[i] = msg[start + i]; | ||
15527 | for (; i < W.length; i++) | ||
15528 | W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]); | ||
15529 | |||
15530 | var a = this.h[0]; | ||
15531 | var b = this.h[1]; | ||
15532 | var c = this.h[2]; | ||
15533 | var d = this.h[3]; | ||
15534 | var e = this.h[4]; | ||
15535 | var f = this.h[5]; | ||
15536 | var g = this.h[6]; | ||
15537 | var h = this.h[7]; | ||
15538 | |||
15539 | assert(this.k.length === W.length); | ||
15540 | for (var i = 0; i < W.length; i++) { | ||
15541 | var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]); | ||
15542 | var T2 = sum32(s0_256(a), maj32(a, b, c)); | ||
15543 | h = g; | ||
15544 | g = f; | ||
15545 | f = e; | ||
15546 | e = sum32(d, T1); | ||
15547 | d = c; | ||
15548 | c = b; | ||
15549 | b = a; | ||
15550 | a = sum32(T1, T2); | ||
15551 | } | ||
15552 | |||
15553 | this.h[0] = sum32(this.h[0], a); | ||
15554 | this.h[1] = sum32(this.h[1], b); | ||
15555 | this.h[2] = sum32(this.h[2], c); | ||
15556 | this.h[3] = sum32(this.h[3], d); | ||
15557 | this.h[4] = sum32(this.h[4], e); | ||
15558 | this.h[5] = sum32(this.h[5], f); | ||
15559 | this.h[6] = sum32(this.h[6], g); | ||
15560 | this.h[7] = sum32(this.h[7], h); | ||
15561 | }; | ||
15562 | |||
15563 | SHA256.prototype._digest = function digest(enc) { | ||
15564 | if (enc === 'hex') | ||
15565 | return utils.toHex32(this.h, 'big'); | ||
15566 | else | ||
15567 | return utils.split32(this.h, 'big'); | ||
15568 | }; | ||
15569 | |||
15570 | function SHA224() { | ||
15571 | if (!(this instanceof SHA224)) | ||
15572 | return new SHA224(); | ||
15573 | |||
15574 | SHA256.call(this); | ||
15575 | this.h = [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, | ||
15576 | 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ]; | ||
15577 | } | ||
15578 | utils.inherits(SHA224, SHA256); | ||
15579 | exports.sha224 = SHA224; | ||
15580 | |||
15581 | SHA224.blockSize = 512; | ||
15582 | SHA224.outSize = 224; | ||
15583 | SHA224.hmacStrength = 192; | ||
15584 | SHA224.padLength = 64; | ||
15585 | |||
15586 | SHA224.prototype._digest = function digest(enc) { | ||
15587 | // Just truncate output | ||
15588 | if (enc === 'hex') | ||
15589 | return utils.toHex32(this.h.slice(0, 7), 'big'); | ||
15590 | else | ||
15591 | return utils.split32(this.h.slice(0, 7), 'big'); | ||
15592 | }; | ||
15593 | |||
15594 | function SHA512() { | ||
15595 | if (!(this instanceof SHA512)) | ||
15596 | return new SHA512(); | ||
15597 | |||
15598 | BlockHash.call(this); | ||
15599 | this.h = [ 0x6a09e667, 0xf3bcc908, | ||
15600 | 0xbb67ae85, 0x84caa73b, | ||
15601 | 0x3c6ef372, 0xfe94f82b, | ||
15602 | 0xa54ff53a, 0x5f1d36f1, | ||
15603 | 0x510e527f, 0xade682d1, | ||
15604 | 0x9b05688c, 0x2b3e6c1f, | ||
15605 | 0x1f83d9ab, 0xfb41bd6b, | ||
15606 | 0x5be0cd19, 0x137e2179 ]; | ||
15607 | this.k = sha512_K; | ||
15608 | this.W = new Array(160); | ||
15609 | } | ||
15610 | utils.inherits(SHA512, BlockHash); | ||
15611 | exports.sha512 = SHA512; | ||
15612 | |||
15613 | SHA512.blockSize = 1024; | ||
15614 | SHA512.outSize = 512; | ||
15615 | SHA512.hmacStrength = 192; | ||
15616 | SHA512.padLength = 128; | ||
15617 | |||
15618 | SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) { | ||
15619 | var W = this.W; | ||
15620 | |||
15621 | // 32 x 32bit words | ||
15622 | for (var i = 0; i < 32; i++) | ||
15623 | W[i] = msg[start + i]; | ||
15624 | for (; i < W.length; i += 2) { | ||
15625 | var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2 | ||
15626 | var c0_lo = g1_512_lo(W[i - 4], W[i - 3]); | ||
15627 | var c1_hi = W[i - 14]; // i - 7 | ||
15628 | var c1_lo = W[i - 13]; | ||
15629 | var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15 | ||
15630 | var c2_lo = g0_512_lo(W[i - 30], W[i - 29]); | ||
15631 | var c3_hi = W[i - 32]; // i - 16 | ||
15632 | var c3_lo = W[i - 31]; | ||
15633 | |||
15634 | W[i] = sum64_4_hi(c0_hi, c0_lo, | ||
15635 | c1_hi, c1_lo, | ||
15636 | c2_hi, c2_lo, | ||
15637 | c3_hi, c3_lo); | ||
15638 | W[i + 1] = sum64_4_lo(c0_hi, c0_lo, | ||
15639 | c1_hi, c1_lo, | ||
15640 | c2_hi, c2_lo, | ||
15641 | c3_hi, c3_lo); | ||
15642 | } | ||
15643 | }; | ||
15644 | |||
15645 | SHA512.prototype._update = function _update(msg, start) { | ||
15646 | this._prepareBlock(msg, start); | ||
15647 | |||
15648 | var W = this.W; | ||
15649 | |||
15650 | var ah = this.h[0]; | ||
15651 | var al = this.h[1]; | ||
15652 | var bh = this.h[2]; | ||
15653 | var bl = this.h[3]; | ||
15654 | var ch = this.h[4]; | ||
15655 | var cl = this.h[5]; | ||
15656 | var dh = this.h[6]; | ||
15657 | var dl = this.h[7]; | ||
15658 | var eh = this.h[8]; | ||
15659 | var el = this.h[9]; | ||
15660 | var fh = this.h[10]; | ||
15661 | var fl = this.h[11]; | ||
15662 | var gh = this.h[12]; | ||
15663 | var gl = this.h[13]; | ||
15664 | var hh = this.h[14]; | ||
15665 | var hl = this.h[15]; | ||
15666 | |||
15667 | assert(this.k.length === W.length); | ||
15668 | for (var i = 0; i < W.length; i += 2) { | ||
15669 | var c0_hi = hh; | ||
15670 | var c0_lo = hl; | ||
15671 | var c1_hi = s1_512_hi(eh, el); | ||
15672 | var c1_lo = s1_512_lo(eh, el); | ||
15673 | var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl); | ||
15674 | var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl); | ||
15675 | var c3_hi = this.k[i]; | ||
15676 | var c3_lo = this.k[i + 1]; | ||
15677 | var c4_hi = W[i]; | ||
15678 | var c4_lo = W[i + 1]; | ||
15679 | |||
15680 | var T1_hi = sum64_5_hi(c0_hi, c0_lo, | ||
15681 | c1_hi, c1_lo, | ||
15682 | c2_hi, c2_lo, | ||
15683 | c3_hi, c3_lo, | ||
15684 | c4_hi, c4_lo); | ||
15685 | var T1_lo = sum64_5_lo(c0_hi, c0_lo, | ||
15686 | c1_hi, c1_lo, | ||
15687 | c2_hi, c2_lo, | ||
15688 | c3_hi, c3_lo, | ||
15689 | c4_hi, c4_lo); | ||
15690 | |||
15691 | var c0_hi = s0_512_hi(ah, al); | ||
15692 | var c0_lo = s0_512_lo(ah, al); | ||
15693 | var c1_hi = maj64_hi(ah, al, bh, bl, ch, cl); | ||
15694 | var c1_lo = maj64_lo(ah, al, bh, bl, ch, cl); | ||
15695 | |||
15696 | var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo); | ||
15697 | var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo); | ||
15698 | |||
15699 | hh = gh; | ||
15700 | hl = gl; | ||
15701 | |||
15702 | gh = fh; | ||
15703 | gl = fl; | ||
15704 | |||
15705 | fh = eh; | ||
15706 | fl = el; | ||
15707 | |||
15708 | eh = sum64_hi(dh, dl, T1_hi, T1_lo); | ||
15709 | el = sum64_lo(dl, dl, T1_hi, T1_lo); | ||
15710 | |||
15711 | dh = ch; | ||
15712 | dl = cl; | ||
15713 | |||
15714 | ch = bh; | ||
15715 | cl = bl; | ||
15716 | |||
15717 | bh = ah; | ||
15718 | bl = al; | ||
15719 | |||
15720 | ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo); | ||
15721 | al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo); | ||
15722 | } | ||
15723 | |||
15724 | sum64(this.h, 0, ah, al); | ||
15725 | sum64(this.h, 2, bh, bl); | ||
15726 | sum64(this.h, 4, ch, cl); | ||
15727 | sum64(this.h, 6, dh, dl); | ||
15728 | sum64(this.h, 8, eh, el); | ||
15729 | sum64(this.h, 10, fh, fl); | ||
15730 | sum64(this.h, 12, gh, gl); | ||
15731 | sum64(this.h, 14, hh, hl); | ||
15732 | }; | ||
15733 | |||
15734 | SHA512.prototype._digest = function digest(enc) { | ||
15735 | if (enc === 'hex') | ||
15736 | return utils.toHex32(this.h, 'big'); | ||
15737 | else | ||
15738 | return utils.split32(this.h, 'big'); | ||
15739 | }; | ||
15740 | |||
15741 | function SHA384() { | ||
15742 | if (!(this instanceof SHA384)) | ||
15743 | return new SHA384(); | ||
15744 | |||
15745 | SHA512.call(this); | ||
15746 | this.h = [ 0xcbbb9d5d, 0xc1059ed8, | ||
15747 | 0x629a292a, 0x367cd507, | ||
15748 | 0x9159015a, 0x3070dd17, | ||
15749 | 0x152fecd8, 0xf70e5939, | ||
15750 | 0x67332667, 0xffc00b31, | ||
15751 | 0x8eb44a87, 0x68581511, | ||
15752 | 0xdb0c2e0d, 0x64f98fa7, | ||
15753 | 0x47b5481d, 0xbefa4fa4 ]; | ||
15754 | } | ||
15755 | utils.inherits(SHA384, SHA512); | ||
15756 | exports.sha384 = SHA384; | ||
15757 | |||
15758 | SHA384.blockSize = 1024; | ||
15759 | SHA384.outSize = 384; | ||
15760 | SHA384.hmacStrength = 192; | ||
15761 | SHA384.padLength = 128; | ||
15762 | |||
15763 | SHA384.prototype._digest = function digest(enc) { | ||
15764 | if (enc === 'hex') | ||
15765 | return utils.toHex32(this.h.slice(0, 12), 'big'); | ||
15766 | else | ||
15767 | return utils.split32(this.h.slice(0, 12), 'big'); | ||
15768 | }; | ||
15769 | |||
15770 | function SHA1() { | ||
15771 | if (!(this instanceof SHA1)) | ||
15772 | return new SHA1(); | ||
15773 | |||
15774 | BlockHash.call(this); | ||
15775 | this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, | ||
15776 | 0x10325476, 0xc3d2e1f0 ]; | ||
15777 | this.W = new Array(80); | ||
15778 | } | ||
15779 | |||
15780 | utils.inherits(SHA1, BlockHash); | ||
15781 | exports.sha1 = SHA1; | ||
15782 | |||
15783 | SHA1.blockSize = 512; | ||
15784 | SHA1.outSize = 160; | ||
15785 | SHA1.hmacStrength = 80; | ||
15786 | SHA1.padLength = 64; | ||
15787 | |||
15788 | SHA1.prototype._update = function _update(msg, start) { | ||
15789 | var W = this.W; | ||
15790 | |||
15791 | for (var i = 0; i < 16; i++) | ||
15792 | W[i] = msg[start + i]; | ||
15793 | |||
15794 | for(; i < W.length; i++) | ||
15795 | W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); | ||
15796 | |||
15797 | var a = this.h[0]; | ||
15798 | var b = this.h[1]; | ||
15799 | var c = this.h[2]; | ||
15800 | var d = this.h[3]; | ||
15801 | var e = this.h[4]; | ||
15802 | |||
15803 | for (var i = 0; i < W.length; i++) { | ||
15804 | var s = ~~(i / 20); | ||
15805 | var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]); | ||
15806 | e = d; | ||
15807 | d = c; | ||
15808 | c = rotl32(b, 30); | ||
15809 | b = a; | ||
15810 | a = t; | ||
15811 | } | ||
15812 | |||
15813 | this.h[0] = sum32(this.h[0], a); | ||
15814 | this.h[1] = sum32(this.h[1], b); | ||
15815 | this.h[2] = sum32(this.h[2], c); | ||
15816 | this.h[3] = sum32(this.h[3], d); | ||
15817 | this.h[4] = sum32(this.h[4], e); | ||
15818 | }; | ||
15819 | |||
15820 | SHA1.prototype._digest = function digest(enc) { | ||
15821 | if (enc === 'hex') | ||
15822 | return utils.toHex32(this.h, 'big'); | ||
15823 | else | ||
15824 | return utils.split32(this.h, 'big'); | ||
15825 | }; | ||
15826 | |||
15827 | function ch32(x, y, z) { | ||
15828 | return (x & y) ^ ((~x) & z); | ||
15829 | } | ||
15830 | |||
15831 | function maj32(x, y, z) { | ||
15832 | return (x & y) ^ (x & z) ^ (y & z); | ||
15833 | } | ||
15834 | |||
15835 | function p32(x, y, z) { | ||
15836 | return x ^ y ^ z; | ||
15837 | } | ||
15838 | |||
15839 | function s0_256(x) { | ||
15840 | return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); | ||
15841 | } | ||
15842 | |||
15843 | function s1_256(x) { | ||
15844 | return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); | ||
15845 | } | ||
15846 | |||
15847 | function g0_256(x) { | ||
15848 | return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3); | ||
15849 | } | ||
15850 | |||
15851 | function g1_256(x) { | ||
15852 | return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10); | ||
15853 | } | ||
15854 | |||
15855 | function ft_1(s, x, y, z) { | ||
15856 | if (s === 0) | ||
15857 | return ch32(x, y, z); | ||
15858 | if (s === 1 || s === 3) | ||
15859 | return p32(x, y, z); | ||
15860 | if (s === 2) | ||
15861 | return maj32(x, y, z); | ||
15862 | } | ||
15863 | |||
15864 | function ch64_hi(xh, xl, yh, yl, zh, zl) { | ||
15865 | var r = (xh & yh) ^ ((~xh) & zh); | ||
15866 | if (r < 0) | ||
15867 | r += 0x100000000; | ||
15868 | return r; | ||
15869 | } | ||
15870 | |||
15871 | function ch64_lo(xh, xl, yh, yl, zh, zl) { | ||
15872 | var r = (xl & yl) ^ ((~xl) & zl); | ||
15873 | if (r < 0) | ||
15874 | r += 0x100000000; | ||
15875 | return r; | ||
15876 | } | ||
15877 | |||
15878 | function maj64_hi(xh, xl, yh, yl, zh, zl) { | ||
15879 | var r = (xh & yh) ^ (xh & zh) ^ (yh & zh); | ||
15880 | if (r < 0) | ||
15881 | r += 0x100000000; | ||
15882 | return r; | ||
15883 | } | ||
15884 | |||
15885 | function maj64_lo(xh, xl, yh, yl, zh, zl) { | ||
15886 | var r = (xl & yl) ^ (xl & zl) ^ (yl & zl); | ||
15887 | if (r < 0) | ||
15888 | r += 0x100000000; | ||
15889 | return r; | ||
15890 | } | ||
15891 | |||
15892 | function s0_512_hi(xh, xl) { | ||
15893 | var c0_hi = rotr64_hi(xh, xl, 28); | ||
15894 | var c1_hi = rotr64_hi(xl, xh, 2); // 34 | ||
15895 | var c2_hi = rotr64_hi(xl, xh, 7); // 39 | ||
15896 | |||
15897 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
15898 | if (r < 0) | ||
15899 | r += 0x100000000; | ||
15900 | return r; | ||
15901 | } | ||
15902 | |||
15903 | function s0_512_lo(xh, xl) { | ||
15904 | var c0_lo = rotr64_lo(xh, xl, 28); | ||
15905 | var c1_lo = rotr64_lo(xl, xh, 2); // 34 | ||
15906 | var c2_lo = rotr64_lo(xl, xh, 7); // 39 | ||
15907 | |||
15908 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
15909 | if (r < 0) | ||
15910 | r += 0x100000000; | ||
15911 | return r; | ||
15912 | } | ||
15913 | |||
15914 | function s1_512_hi(xh, xl) { | ||
15915 | var c0_hi = rotr64_hi(xh, xl, 14); | ||
15916 | var c1_hi = rotr64_hi(xh, xl, 18); | ||
15917 | var c2_hi = rotr64_hi(xl, xh, 9); // 41 | ||
15918 | |||
15919 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
15920 | if (r < 0) | ||
15921 | r += 0x100000000; | ||
15922 | return r; | ||
15923 | } | ||
15924 | |||
15925 | function s1_512_lo(xh, xl) { | ||
15926 | var c0_lo = rotr64_lo(xh, xl, 14); | ||
15927 | var c1_lo = rotr64_lo(xh, xl, 18); | ||
15928 | var c2_lo = rotr64_lo(xl, xh, 9); // 41 | ||
15929 | |||
15930 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
15931 | if (r < 0) | ||
15932 | r += 0x100000000; | ||
15933 | return r; | ||
15934 | } | ||
15935 | |||
15936 | function g0_512_hi(xh, xl) { | ||
15937 | var c0_hi = rotr64_hi(xh, xl, 1); | ||
15938 | var c1_hi = rotr64_hi(xh, xl, 8); | ||
15939 | var c2_hi = shr64_hi(xh, xl, 7); | ||
15940 | |||
15941 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
15942 | if (r < 0) | ||
15943 | r += 0x100000000; | ||
15944 | return r; | ||
15945 | } | ||
15946 | |||
15947 | function g0_512_lo(xh, xl) { | ||
15948 | var c0_lo = rotr64_lo(xh, xl, 1); | ||
15949 | var c1_lo = rotr64_lo(xh, xl, 8); | ||
15950 | var c2_lo = shr64_lo(xh, xl, 7); | ||
15951 | |||
15952 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
15953 | if (r < 0) | ||
15954 | r += 0x100000000; | ||
15955 | return r; | ||
15956 | } | ||
15957 | |||
15958 | function g1_512_hi(xh, xl) { | ||
15959 | var c0_hi = rotr64_hi(xh, xl, 19); | ||
15960 | var c1_hi = rotr64_hi(xl, xh, 29); // 61 | ||
15961 | var c2_hi = shr64_hi(xh, xl, 6); | ||
15962 | |||
15963 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
15964 | if (r < 0) | ||
15965 | r += 0x100000000; | ||
15966 | return r; | ||
15967 | } | ||
15968 | |||
15969 | function g1_512_lo(xh, xl) { | ||
15970 | var c0_lo = rotr64_lo(xh, xl, 19); | ||
15971 | var c1_lo = rotr64_lo(xl, xh, 29); // 61 | ||
15972 | var c2_lo = shr64_lo(xh, xl, 6); | ||
15973 | |||
15974 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
15975 | if (r < 0) | ||
15976 | r += 0x100000000; | ||
15977 | return r; | ||
15978 | } | ||
15979 | |||
15980 | },{"../hash":57}],62:[function(require,module,exports){ | ||
15981 | var utils = exports; | ||
15982 | var inherits = require('inherits'); | ||
15983 | |||
15984 | function toArray(msg, enc) { | ||
15985 | if (Array.isArray(msg)) | ||
15986 | return msg.slice(); | ||
15987 | if (!msg) | ||
15988 | return []; | ||
15989 | var res = []; | ||
15990 | if (typeof msg === 'string') { | ||
15991 | if (!enc) { | ||
15992 | for (var i = 0; i < msg.length; i++) { | ||
15993 | var c = msg.charCodeAt(i); | ||
15994 | var hi = c >> 8; | ||
15995 | var lo = c & 0xff; | ||
15996 | if (hi) | ||
15997 | res.push(hi, lo); | ||
15998 | else | ||
15999 | res.push(lo); | ||
16000 | } | ||
16001 | } else if (enc === 'hex') { | ||
16002 | msg = msg.replace(/[^a-z0-9]+/ig, ''); | ||
16003 | if (msg.length % 2 !== 0) | ||
16004 | msg = '0' + msg; | ||
16005 | for (var i = 0; i < msg.length; i += 2) | ||
16006 | res.push(parseInt(msg[i] + msg[i + 1], 16)); | ||
16007 | } | ||
16008 | } else { | ||
16009 | for (var i = 0; i < msg.length; i++) | ||
16010 | res[i] = msg[i] | 0; | ||
16011 | } | ||
16012 | return res; | ||
16013 | } | ||
16014 | utils.toArray = toArray; | ||
16015 | |||
16016 | function toHex(msg) { | ||
16017 | var res = ''; | ||
16018 | for (var i = 0; i < msg.length; i++) | ||
16019 | res += zero2(msg[i].toString(16)); | ||
16020 | return res; | ||
16021 | } | ||
16022 | utils.toHex = toHex; | ||
16023 | |||
16024 | function htonl(w) { | ||
16025 | var res = (w >>> 24) | | ||
16026 | ((w >>> 8) & 0xff00) | | ||
16027 | ((w << 8) & 0xff0000) | | ||
16028 | ((w & 0xff) << 24); | ||
16029 | return res >>> 0; | ||
16030 | } | ||
16031 | utils.htonl = htonl; | ||
16032 | |||
16033 | function toHex32(msg, endian) { | ||
16034 | var res = ''; | ||
16035 | for (var i = 0; i < msg.length; i++) { | ||
16036 | var w = msg[i]; | ||
16037 | if (endian === 'little') | ||
16038 | w = htonl(w); | ||
16039 | res += zero8(w.toString(16)); | ||
16040 | } | ||
16041 | return res; | ||
16042 | } | ||
16043 | utils.toHex32 = toHex32; | ||
16044 | |||
16045 | function zero2(word) { | ||
16046 | if (word.length === 1) | ||
16047 | return '0' + word; | ||
16048 | else | ||
16049 | return word; | ||
16050 | } | ||
16051 | utils.zero2 = zero2; | ||
16052 | |||
16053 | function zero8(word) { | ||
16054 | if (word.length === 7) | ||
16055 | return '0' + word; | ||
16056 | else if (word.length === 6) | ||
16057 | return '00' + word; | ||
16058 | else if (word.length === 5) | ||
16059 | return '000' + word; | ||
16060 | else if (word.length === 4) | ||
16061 | return '0000' + word; | ||
16062 | else if (word.length === 3) | ||
16063 | return '00000' + word; | ||
16064 | else if (word.length === 2) | ||
16065 | return '000000' + word; | ||
16066 | else if (word.length === 1) | ||
16067 | return '0000000' + word; | ||
16068 | else | ||
16069 | return word; | ||
16070 | } | ||
16071 | utils.zero8 = zero8; | ||
16072 | |||
16073 | function join32(msg, start, end, endian) { | ||
16074 | var len = end - start; | ||
16075 | assert(len % 4 === 0); | ||
16076 | var res = new Array(len / 4); | ||
16077 | for (var i = 0, k = start; i < res.length; i++, k += 4) { | ||
16078 | var w; | ||
16079 | if (endian === 'big') | ||
16080 | w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3]; | ||
16081 | else | ||
16082 | w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k]; | ||
16083 | res[i] = w >>> 0; | ||
16084 | } | ||
16085 | return res; | ||
16086 | } | ||
16087 | utils.join32 = join32; | ||
16088 | |||
16089 | function split32(msg, endian) { | ||
16090 | var res = new Array(msg.length * 4); | ||
16091 | for (var i = 0, k = 0; i < msg.length; i++, k += 4) { | ||
16092 | var m = msg[i]; | ||
16093 | if (endian === 'big') { | ||
16094 | res[k] = m >>> 24; | ||
16095 | res[k + 1] = (m >>> 16) & 0xff; | ||
16096 | res[k + 2] = (m >>> 8) & 0xff; | ||
16097 | res[k + 3] = m & 0xff; | ||
16098 | } else { | ||
16099 | res[k + 3] = m >>> 24; | ||
16100 | res[k + 2] = (m >>> 16) & 0xff; | ||
16101 | res[k + 1] = (m >>> 8) & 0xff; | ||
16102 | res[k] = m & 0xff; | ||
16103 | } | ||
16104 | } | ||
16105 | return res; | ||
16106 | } | ||
16107 | utils.split32 = split32; | ||
16108 | |||
16109 | function rotr32(w, b) { | ||
16110 | return (w >>> b) | (w << (32 - b)); | ||
16111 | } | ||
16112 | utils.rotr32 = rotr32; | ||
16113 | |||
16114 | function rotl32(w, b) { | ||
16115 | return (w << b) | (w >>> (32 - b)); | ||
16116 | } | ||
16117 | utils.rotl32 = rotl32; | ||
16118 | |||
16119 | function sum32(a, b) { | ||
16120 | return (a + b) >>> 0; | ||
16121 | } | ||
16122 | utils.sum32 = sum32; | ||
16123 | |||
16124 | function sum32_3(a, b, c) { | ||
16125 | return (a + b + c) >>> 0; | ||
16126 | } | ||
16127 | utils.sum32_3 = sum32_3; | ||
16128 | |||
16129 | function sum32_4(a, b, c, d) { | ||
16130 | return (a + b + c + d) >>> 0; | ||
16131 | } | ||
16132 | utils.sum32_4 = sum32_4; | ||
16133 | |||
16134 | function sum32_5(a, b, c, d, e) { | ||
16135 | return (a + b + c + d + e) >>> 0; | ||
16136 | } | ||
16137 | utils.sum32_5 = sum32_5; | ||
16138 | |||
16139 | function assert(cond, msg) { | ||
16140 | if (!cond) | ||
16141 | throw new Error(msg || 'Assertion failed'); | ||
16142 | } | ||
16143 | utils.assert = assert; | ||
16144 | |||
16145 | utils.inherits = inherits; | ||
16146 | |||
16147 | function sum64(buf, pos, ah, al) { | ||
16148 | var bh = buf[pos]; | ||
16149 | var bl = buf[pos + 1]; | ||
16150 | |||
16151 | var lo = (al + bl) >>> 0; | ||
16152 | var hi = (lo < al ? 1 : 0) + ah + bh; | ||
16153 | buf[pos] = hi >>> 0; | ||
16154 | buf[pos + 1] = lo; | ||
16155 | } | ||
16156 | exports.sum64 = sum64; | ||
16157 | |||
16158 | function sum64_hi(ah, al, bh, bl) { | ||
16159 | var lo = (al + bl) >>> 0; | ||
16160 | var hi = (lo < al ? 1 : 0) + ah + bh; | ||
16161 | return hi >>> 0; | ||
16162 | }; | ||
16163 | exports.sum64_hi = sum64_hi; | ||
16164 | |||
16165 | function sum64_lo(ah, al, bh, bl) { | ||
16166 | var lo = al + bl; | ||
16167 | return lo >>> 0; | ||
16168 | }; | ||
16169 | exports.sum64_lo = sum64_lo; | ||
16170 | |||
16171 | function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { | ||
16172 | var carry = 0; | ||
16173 | var lo = al; | ||
16174 | lo = (lo + bl) >>> 0; | ||
16175 | carry += lo < al ? 1 : 0; | ||
16176 | lo = (lo + cl) >>> 0; | ||
16177 | carry += lo < cl ? 1 : 0; | ||
16178 | lo = (lo + dl) >>> 0; | ||
16179 | carry += lo < dl ? 1 : 0; | ||
16180 | |||
16181 | var hi = ah + bh + ch + dh + carry; | ||
16182 | return hi >>> 0; | ||
16183 | }; | ||
16184 | exports.sum64_4_hi = sum64_4_hi; | ||
16185 | |||
16186 | function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { | ||
16187 | var lo = al + bl + cl + dl; | ||
16188 | return lo >>> 0; | ||
16189 | }; | ||
16190 | exports.sum64_4_lo = sum64_4_lo; | ||
16191 | |||
16192 | function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { | ||
16193 | var carry = 0; | ||
16194 | var lo = al; | ||
16195 | lo = (lo + bl) >>> 0; | ||
16196 | carry += lo < al ? 1 : 0; | ||
16197 | lo = (lo + cl) >>> 0; | ||
16198 | carry += lo < cl ? 1 : 0; | ||
16199 | lo = (lo + dl) >>> 0; | ||
16200 | carry += lo < dl ? 1 : 0; | ||
16201 | lo = (lo + el) >>> 0; | ||
16202 | carry += lo < el ? 1 : 0; | ||
16203 | |||
16204 | var hi = ah + bh + ch + dh + eh + carry; | ||
16205 | return hi >>> 0; | ||
16206 | }; | ||
16207 | exports.sum64_5_hi = sum64_5_hi; | ||
16208 | |||
16209 | function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { | ||
16210 | var lo = al + bl + cl + dl + el; | ||
16211 | |||
16212 | return lo >>> 0; | ||
16213 | }; | ||
16214 | exports.sum64_5_lo = sum64_5_lo; | ||
16215 | |||
16216 | function rotr64_hi(ah, al, num) { | ||
16217 | var r = (al << (32 - num)) | (ah >>> num); | ||
16218 | return r >>> 0; | ||
16219 | }; | ||
16220 | exports.rotr64_hi = rotr64_hi; | ||
16221 | |||
16222 | function rotr64_lo(ah, al, num) { | ||
16223 | var r = (ah << (32 - num)) | (al >>> num); | ||
16224 | return r >>> 0; | ||
16225 | }; | ||
16226 | exports.rotr64_lo = rotr64_lo; | ||
16227 | |||
16228 | function shr64_hi(ah, al, num) { | ||
16229 | return ah >>> num; | ||
16230 | }; | ||
16231 | exports.shr64_hi = shr64_hi; | ||
16232 | |||
16233 | function shr64_lo(ah, al, num) { | ||
16234 | var r = (ah << (32 - num)) | (al >>> num); | ||
16235 | return r >>> 0; | ||
16236 | }; | ||
16237 | exports.shr64_lo = shr64_lo; | ||
16238 | |||
16239 | },{"inherits":63}],63:[function(require,module,exports){ | ||
16240 | arguments[4][9][0].apply(exports,arguments) | ||
16241 | },{"dup":9}],64:[function(require,module,exports){ | ||
16242 | /** | ||
16243 | * Returns a `Boolean` on whether or not the a `String` starts with '0x' | ||
16244 | * @param {String} str the string input value | ||
16245 | * @return {Boolean} a boolean if it is or is not hex prefixed | ||
16246 | * @throws if the str input is not a string | ||
16247 | */ | ||
16248 | module.exports = function isHexPrefixed(str) { | ||
16249 | if (typeof str !== 'string') { | ||
16250 | throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed."); | ||
16251 | } | ||
16252 | |||
16253 | return str.slice(0, 2) === '0x'; | ||
16254 | } | ||
16255 | |||
16256 | },{}],65:[function(require,module,exports){ | ||
16257 | 'use strict' | ||
16258 | module.exports = require('./lib/api')(require('./lib/keccak')) | ||
16259 | |||
16260 | },{"./lib/api":66,"./lib/keccak":70}],66:[function(require,module,exports){ | ||
16261 | 'use strict' | ||
16262 | var createKeccak = require('./keccak') | ||
16263 | var createShake = require('./shake') | ||
16264 | |||
16265 | module.exports = function (KeccakState) { | ||
16266 | var Keccak = createKeccak(KeccakState) | ||
16267 | var Shake = createShake(KeccakState) | ||
16268 | |||
16269 | return function (algorithm, options) { | ||
16270 | var hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm | ||
16271 | switch (hash) { | ||
16272 | case 'keccak224': return new Keccak(1152, 448, null, 224, options) | ||
16273 | case 'keccak256': return new Keccak(1088, 512, null, 256, options) | ||
16274 | case 'keccak384': return new Keccak(832, 768, null, 384, options) | ||
16275 | case 'keccak512': return new Keccak(576, 1024, null, 512, options) | ||
16276 | |||
16277 | case 'sha3-224': return new Keccak(1152, 448, 0x06, 224, options) | ||
16278 | case 'sha3-256': return new Keccak(1088, 512, 0x06, 256, options) | ||
16279 | case 'sha3-384': return new Keccak(832, 768, 0x06, 384, options) | ||
16280 | case 'sha3-512': return new Keccak(576, 1024, 0x06, 512, options) | ||
16281 | |||
16282 | case 'shake128': return new Shake(1344, 256, 0x1f, options) | ||
16283 | case 'shake256': return new Shake(1088, 512, 0x1f, options) | ||
16284 | |||
16285 | default: throw new Error('Invald algorithm: ' + algorithm) | ||
16286 | } | ||
16287 | } | ||
16288 | } | ||
16289 | |||
16290 | },{"./keccak":67,"./shake":68}],67:[function(require,module,exports){ | ||
16291 | (function (Buffer){ | ||
16292 | 'use strict' | ||
16293 | var Transform = require('stream').Transform | ||
16294 | var inherits = require('inherits') | ||
16295 | |||
16296 | module.exports = function (KeccakState) { | ||
16297 | function Keccak (rate, capacity, delimitedSuffix, hashBitLength, options) { | ||
16298 | Transform.call(this, options) | ||
16299 | |||
16300 | this._rate = rate | ||
16301 | this._capacity = capacity | ||
16302 | this._delimitedSuffix = delimitedSuffix | ||
16303 | this._hashBitLength = hashBitLength | ||
16304 | this._options = options | ||
16305 | |||
16306 | this._state = new KeccakState() | ||
16307 | this._state.initialize(rate, capacity) | ||
16308 | this._finalized = false | ||
16309 | } | ||
16310 | |||
16311 | inherits(Keccak, Transform) | ||
16312 | |||
16313 | Keccak.prototype._transform = function (chunk, encoding, callback) { | ||
16314 | var error = null | ||
16315 | try { | ||
16316 | this.update(chunk, encoding) | ||
16317 | } catch (err) { | ||
16318 | error = err | ||
16319 | } | ||
16320 | |||
16321 | callback(error) | ||
16322 | } | ||
16323 | |||
16324 | Keccak.prototype._flush = function (callback) { | ||
16325 | var error = null | ||
16326 | try { | ||
16327 | this.push(this.digest()) | ||
16328 | } catch (err) { | ||
16329 | error = err | ||
16330 | } | ||
16331 | |||
16332 | callback(error) | ||
16333 | } | ||
16334 | |||
16335 | Keccak.prototype.update = function (data, encoding) { | ||
16336 | if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer') | ||
16337 | if (this._finalized) throw new Error('Digest already called') | ||
16338 | if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding) | ||
16339 | |||
16340 | this._state.absorb(data) | ||
16341 | |||
16342 | return this | ||
16343 | } | ||
16344 | |||
16345 | Keccak.prototype.digest = function (encoding) { | ||
16346 | if (this._finalized) throw new Error('Digest already called') | ||
16347 | this._finalized = true | ||
16348 | |||
16349 | if (this._delimitedSuffix) this._state.absorbLastFewBits(this._delimitedSuffix) | ||
16350 | var digest = this._state.squeeze(this._hashBitLength / 8) | ||
16351 | if (encoding !== undefined) digest = digest.toString(encoding) | ||
16352 | |||
16353 | this._resetState() | ||
16354 | |||
16355 | return digest | ||
16356 | } | ||
16357 | |||
16358 | // remove result from memory | ||
16359 | Keccak.prototype._resetState = function () { | ||
16360 | this._state.initialize(this._rate, this._capacity) | ||
16361 | return this | ||
16362 | } | ||
16363 | |||
16364 | // because sometimes we need hash right now and little later | ||
16365 | Keccak.prototype._clone = function () { | ||
16366 | var clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options) | ||
16367 | this._state.copy(clone._state) | ||
16368 | clone._finalized = this._finalized | ||
16369 | |||
16370 | return clone | ||
16371 | } | ||
16372 | |||
16373 | return Keccak | ||
16374 | } | ||
16375 | |||
16376 | }).call(this,require("buffer").Buffer) | ||
16377 | },{"buffer":5,"inherits":63,"stream":25}],68:[function(require,module,exports){ | ||
16378 | (function (Buffer){ | ||
16379 | 'use strict' | ||
16380 | var Transform = require('stream').Transform | ||
16381 | var inherits = require('inherits') | ||
16382 | |||
16383 | module.exports = function (KeccakState) { | ||
16384 | function Shake (rate, capacity, delimitedSuffix, options) { | ||
16385 | Transform.call(this, options) | ||
16386 | |||
16387 | this._rate = rate | ||
16388 | this._capacity = capacity | ||
16389 | this._delimitedSuffix = delimitedSuffix | ||
16390 | this._options = options | ||
16391 | |||
16392 | this._state = new KeccakState() | ||
16393 | this._state.initialize(rate, capacity) | ||
16394 | this._finalized = false | ||
16395 | } | ||
16396 | |||
16397 | inherits(Shake, Transform) | ||
16398 | |||
16399 | Shake.prototype._transform = function (chunk, encoding, callback) { | ||
16400 | var error = null | ||
16401 | try { | ||
16402 | this.update(chunk, encoding) | ||
16403 | } catch (err) { | ||
16404 | error = err | ||
16405 | } | ||
16406 | |||
16407 | callback(error) | ||
16408 | } | ||
16409 | |||
16410 | Shake.prototype._flush = function () {} | ||
16411 | |||
16412 | Shake.prototype._read = function (size) { | ||
16413 | this.push(this.squeeze(size)) | ||
16414 | } | ||
16415 | |||
16416 | Shake.prototype.update = function (data, encoding) { | ||
16417 | if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer') | ||
16418 | if (this._finalized) throw new Error('Squeeze already called') | ||
16419 | if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding) | ||
16420 | |||
16421 | this._state.absorb(data) | ||
16422 | |||
16423 | return this | ||
16424 | } | ||
16425 | |||
16426 | Shake.prototype.squeeze = function (dataByteLength, encoding) { | ||
16427 | if (!this._finalized) { | ||
16428 | this._finalized = true | ||
16429 | this._state.absorbLastFewBits(this._delimitedSuffix) | ||
16430 | } | ||
16431 | |||
16432 | var data = this._state.squeeze(dataByteLength) | ||
16433 | if (encoding !== undefined) data = data.toString(encoding) | ||
16434 | |||
16435 | return data | ||
16436 | } | ||
16437 | |||
16438 | Shake.prototype._resetState = function () { | ||
16439 | this._state.initialize(this._rate, this._capacity) | ||
16440 | return this | ||
16441 | } | ||
16442 | |||
16443 | Shake.prototype._clone = function () { | ||
16444 | var clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options) | ||
16445 | this._state.copy(clone._state) | ||
16446 | clone._finalized = this._finalized | ||
16447 | |||
16448 | return clone | ||
16449 | } | ||
16450 | |||
16451 | return Shake | ||
16452 | } | ||
16453 | |||
16454 | }).call(this,require("buffer").Buffer) | ||
16455 | },{"buffer":5,"inherits":63,"stream":25}],69:[function(require,module,exports){ | ||
16456 | 'use strict' | ||
16457 | var 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] | ||
16458 | |||
16459 | exports.p1600 = function (s) { | ||
16460 | for (var round = 0; round < 24; ++round) { | ||
16461 | // theta | ||
16462 | var lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40] | ||
16463 | var hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41] | ||
16464 | var lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42] | ||
16465 | var hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43] | ||
16466 | var lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44] | ||
16467 | var hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45] | ||
16468 | var lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46] | ||
16469 | var hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47] | ||
16470 | var lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48] | ||
16471 | var hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49] | ||
16472 | |||
16473 | var lo = lo4 ^ (lo1 << 1 | hi1 >>> 31) | ||
16474 | var hi = hi4 ^ (hi1 << 1 | lo1 >>> 31) | ||
16475 | var t1slo0 = s[0] ^ lo | ||
16476 | var t1shi0 = s[1] ^ hi | ||
16477 | var t1slo5 = s[10] ^ lo | ||
16478 | var t1shi5 = s[11] ^ hi | ||
16479 | var t1slo10 = s[20] ^ lo | ||
16480 | var t1shi10 = s[21] ^ hi | ||
16481 | var t1slo15 = s[30] ^ lo | ||
16482 | var t1shi15 = s[31] ^ hi | ||
16483 | var t1slo20 = s[40] ^ lo | ||
16484 | var t1shi20 = s[41] ^ hi | ||
16485 | lo = lo0 ^ (lo2 << 1 | hi2 >>> 31) | ||
16486 | hi = hi0 ^ (hi2 << 1 | lo2 >>> 31) | ||
16487 | var t1slo1 = s[2] ^ lo | ||
16488 | var t1shi1 = s[3] ^ hi | ||
16489 | var t1slo6 = s[12] ^ lo | ||
16490 | var t1shi6 = s[13] ^ hi | ||
16491 | var t1slo11 = s[22] ^ lo | ||
16492 | var t1shi11 = s[23] ^ hi | ||
16493 | var t1slo16 = s[32] ^ lo | ||
16494 | var t1shi16 = s[33] ^ hi | ||
16495 | var t1slo21 = s[42] ^ lo | ||
16496 | var t1shi21 = s[43] ^ hi | ||
16497 | lo = lo1 ^ (lo3 << 1 | hi3 >>> 31) | ||
16498 | hi = hi1 ^ (hi3 << 1 | lo3 >>> 31) | ||
16499 | var t1slo2 = s[4] ^ lo | ||
16500 | var t1shi2 = s[5] ^ hi | ||
16501 | var t1slo7 = s[14] ^ lo | ||
16502 | var t1shi7 = s[15] ^ hi | ||
16503 | var t1slo12 = s[24] ^ lo | ||
16504 | var t1shi12 = s[25] ^ hi | ||
16505 | var t1slo17 = s[34] ^ lo | ||
16506 | var t1shi17 = s[35] ^ hi | ||
16507 | var t1slo22 = s[44] ^ lo | ||
16508 | var t1shi22 = s[45] ^ hi | ||
16509 | lo = lo2 ^ (lo4 << 1 | hi4 >>> 31) | ||
16510 | hi = hi2 ^ (hi4 << 1 | lo4 >>> 31) | ||
16511 | var t1slo3 = s[6] ^ lo | ||
16512 | var t1shi3 = s[7] ^ hi | ||
16513 | var t1slo8 = s[16] ^ lo | ||
16514 | var t1shi8 = s[17] ^ hi | ||
16515 | var t1slo13 = s[26] ^ lo | ||
16516 | var t1shi13 = s[27] ^ hi | ||
16517 | var t1slo18 = s[36] ^ lo | ||
16518 | var t1shi18 = s[37] ^ hi | ||
16519 | var t1slo23 = s[46] ^ lo | ||
16520 | var t1shi23 = s[47] ^ hi | ||
16521 | lo = lo3 ^ (lo0 << 1 | hi0 >>> 31) | ||
16522 | hi = hi3 ^ (hi0 << 1 | lo0 >>> 31) | ||
16523 | var t1slo4 = s[8] ^ lo | ||
16524 | var t1shi4 = s[9] ^ hi | ||
16525 | var t1slo9 = s[18] ^ lo | ||
16526 | var t1shi9 = s[19] ^ hi | ||
16527 | var t1slo14 = s[28] ^ lo | ||
16528 | var t1shi14 = s[29] ^ hi | ||
16529 | var t1slo19 = s[38] ^ lo | ||
16530 | var t1shi19 = s[39] ^ hi | ||
16531 | var t1slo24 = s[48] ^ lo | ||
16532 | var t1shi24 = s[49] ^ hi | ||
16533 | |||
16534 | // rho & pi | ||
16535 | var t2slo0 = t1slo0 | ||
16536 | var t2shi0 = t1shi0 | ||
16537 | var t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28) | ||
16538 | var t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28) | ||
16539 | var t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29) | ||
16540 | var t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29) | ||
16541 | var t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23) | ||
16542 | var t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23) | ||
16543 | var t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14) | ||
16544 | var t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14) | ||
16545 | var t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31) | ||
16546 | var t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31) | ||
16547 | var t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20) | ||
16548 | var t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20) | ||
16549 | var t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22) | ||
16550 | var t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22) | ||
16551 | var t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19) | ||
16552 | var t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19) | ||
16553 | var t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30) | ||
16554 | var t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30) | ||
16555 | var t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2) | ||
16556 | var t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2) | ||
16557 | var t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26) | ||
16558 | var t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26) | ||
16559 | var t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21) | ||
16560 | var t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21) | ||
16561 | var t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17) | ||
16562 | var t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17) | ||
16563 | var t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3) | ||
16564 | var t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3) | ||
16565 | var t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4) | ||
16566 | var t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4) | ||
16567 | var t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9) | ||
16568 | var t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9) | ||
16569 | var t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7) | ||
16570 | var t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7) | ||
16571 | var t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11) | ||
16572 | var t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11) | ||
16573 | var t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8) | ||
16574 | var t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8) | ||
16575 | var t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5) | ||
16576 | var t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5) | ||
16577 | var t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12) | ||
16578 | var t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12) | ||
16579 | var t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25) | ||
16580 | var t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25) | ||
16581 | var t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24) | ||
16582 | var t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24) | ||
16583 | var t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18) | ||
16584 | var t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18) | ||
16585 | |||
16586 | // chi | ||
16587 | s[0] = t2slo0 ^ (~t2slo1 & t2slo2) | ||
16588 | s[1] = t2shi0 ^ (~t2shi1 & t2shi2) | ||
16589 | s[10] = t2slo5 ^ (~t2slo6 & t2slo7) | ||
16590 | s[11] = t2shi5 ^ (~t2shi6 & t2shi7) | ||
16591 | s[20] = t2slo10 ^ (~t2slo11 & t2slo12) | ||
16592 | s[21] = t2shi10 ^ (~t2shi11 & t2shi12) | ||
16593 | s[30] = t2slo15 ^ (~t2slo16 & t2slo17) | ||
16594 | s[31] = t2shi15 ^ (~t2shi16 & t2shi17) | ||
16595 | s[40] = t2slo20 ^ (~t2slo21 & t2slo22) | ||
16596 | s[41] = t2shi20 ^ (~t2shi21 & t2shi22) | ||
16597 | s[2] = t2slo1 ^ (~t2slo2 & t2slo3) | ||
16598 | s[3] = t2shi1 ^ (~t2shi2 & t2shi3) | ||
16599 | s[12] = t2slo6 ^ (~t2slo7 & t2slo8) | ||
16600 | s[13] = t2shi6 ^ (~t2shi7 & t2shi8) | ||
16601 | s[22] = t2slo11 ^ (~t2slo12 & t2slo13) | ||
16602 | s[23] = t2shi11 ^ (~t2shi12 & t2shi13) | ||
16603 | s[32] = t2slo16 ^ (~t2slo17 & t2slo18) | ||
16604 | s[33] = t2shi16 ^ (~t2shi17 & t2shi18) | ||
16605 | s[42] = t2slo21 ^ (~t2slo22 & t2slo23) | ||
16606 | s[43] = t2shi21 ^ (~t2shi22 & t2shi23) | ||
16607 | s[4] = t2slo2 ^ (~t2slo3 & t2slo4) | ||
16608 | s[5] = t2shi2 ^ (~t2shi3 & t2shi4) | ||
16609 | s[14] = t2slo7 ^ (~t2slo8 & t2slo9) | ||
16610 | s[15] = t2shi7 ^ (~t2shi8 & t2shi9) | ||
16611 | s[24] = t2slo12 ^ (~t2slo13 & t2slo14) | ||
16612 | s[25] = t2shi12 ^ (~t2shi13 & t2shi14) | ||
16613 | s[34] = t2slo17 ^ (~t2slo18 & t2slo19) | ||
16614 | s[35] = t2shi17 ^ (~t2shi18 & t2shi19) | ||
16615 | s[44] = t2slo22 ^ (~t2slo23 & t2slo24) | ||
16616 | s[45] = t2shi22 ^ (~t2shi23 & t2shi24) | ||
16617 | s[6] = t2slo3 ^ (~t2slo4 & t2slo0) | ||
16618 | s[7] = t2shi3 ^ (~t2shi4 & t2shi0) | ||
16619 | s[16] = t2slo8 ^ (~t2slo9 & t2slo5) | ||
16620 | s[17] = t2shi8 ^ (~t2shi9 & t2shi5) | ||
16621 | s[26] = t2slo13 ^ (~t2slo14 & t2slo10) | ||
16622 | s[27] = t2shi13 ^ (~t2shi14 & t2shi10) | ||
16623 | s[36] = t2slo18 ^ (~t2slo19 & t2slo15) | ||
16624 | s[37] = t2shi18 ^ (~t2shi19 & t2shi15) | ||
16625 | s[46] = t2slo23 ^ (~t2slo24 & t2slo20) | ||
16626 | s[47] = t2shi23 ^ (~t2shi24 & t2shi20) | ||
16627 | s[8] = t2slo4 ^ (~t2slo0 & t2slo1) | ||
16628 | s[9] = t2shi4 ^ (~t2shi0 & t2shi1) | ||
16629 | s[18] = t2slo9 ^ (~t2slo5 & t2slo6) | ||
16630 | s[19] = t2shi9 ^ (~t2shi5 & t2shi6) | ||
16631 | s[28] = t2slo14 ^ (~t2slo10 & t2slo11) | ||
16632 | s[29] = t2shi14 ^ (~t2shi10 & t2shi11) | ||
16633 | s[38] = t2slo19 ^ (~t2slo15 & t2slo16) | ||
16634 | s[39] = t2shi19 ^ (~t2shi15 & t2shi16) | ||
16635 | s[48] = t2slo24 ^ (~t2slo20 & t2slo21) | ||
16636 | s[49] = t2shi24 ^ (~t2shi20 & t2shi21) | ||
16637 | |||
16638 | // iota | ||
16639 | s[0] ^= P1600_ROUND_CONSTANTS[round * 2] | ||
16640 | s[1] ^= P1600_ROUND_CONSTANTS[round * 2 + 1] | ||
16641 | } | ||
16642 | } | ||
16643 | |||
16644 | },{}],70:[function(require,module,exports){ | ||
16645 | (function (Buffer){ | ||
16646 | 'use strict' | ||
16647 | var keccakState = require('./keccak-state-unroll') | ||
16648 | |||
16649 | function Keccak () { | ||
16650 | // much faster than `new Array(50)` | ||
16651 | this.state = [ | ||
16652 | 0, 0, 0, 0, 0, | ||
16653 | 0, 0, 0, 0, 0, | ||
16654 | 0, 0, 0, 0, 0, | ||
16655 | 0, 0, 0, 0, 0, | ||
16656 | 0, 0, 0, 0, 0 | ||
16657 | ] | ||
16658 | |||
16659 | this.blockSize = null | ||
16660 | this.count = 0 | ||
16661 | this.squeezing = false | ||
16662 | } | ||
16663 | |||
16664 | Keccak.prototype.initialize = function (rate, capacity) { | ||
16665 | for (var i = 0; i < 50; ++i) this.state[i] = 0 | ||
16666 | this.blockSize = rate / 8 | ||
16667 | this.count = 0 | ||
16668 | this.squeezing = false | ||
16669 | } | ||
16670 | |||
16671 | Keccak.prototype.absorb = function (data) { | ||
16672 | for (var i = 0; i < data.length; ++i) { | ||
16673 | this.state[~~(this.count / 4)] ^= data[i] << (8 * (this.count % 4)) | ||
16674 | this.count += 1 | ||
16675 | if (this.count === this.blockSize) { | ||
16676 | keccakState.p1600(this.state) | ||
16677 | this.count = 0 | ||
16678 | } | ||
16679 | } | ||
16680 | } | ||
16681 | |||
16682 | Keccak.prototype.absorbLastFewBits = function (bits) { | ||
16683 | this.state[~~(this.count / 4)] ^= bits << (8 * (this.count % 4)) | ||
16684 | if ((bits & 0x80) !== 0 && this.count === (this.blockSize - 1)) keccakState.p1600(this.state) | ||
16685 | this.state[~~((this.blockSize - 1) / 4)] ^= 0x80 << (8 * ((this.blockSize - 1) % 4)) | ||
16686 | keccakState.p1600(this.state) | ||
16687 | this.count = 0 | ||
16688 | this.squeezing = true | ||
16689 | } | ||
16690 | |||
16691 | Keccak.prototype.squeeze = function (length) { | ||
16692 | if (!this.squeezing) this.absorbLastFewBits(0x01) | ||
16693 | |||
16694 | var output = Buffer.allocUnsafe(length) | ||
16695 | for (var i = 0; i < length; ++i) { | ||
16696 | output[i] = (this.state[~~(this.count / 4)] >>> (8 * (this.count % 4))) & 0xff | ||
16697 | this.count += 1 | ||
16698 | if (this.count === this.blockSize) { | ||
16699 | keccakState.p1600(this.state) | ||
16700 | this.count = 0 | ||
16701 | } | ||
16702 | } | ||
16703 | |||
16704 | return output | ||
16705 | } | ||
16706 | |||
16707 | Keccak.prototype.copy = function (dest) { | ||
16708 | for (var i = 0; i < 50; ++i) dest.state[i] = this.state[i] | ||
16709 | dest.blockSize = this.blockSize | ||
16710 | dest.count = this.count | ||
16711 | dest.squeezing = this.squeezing | ||
16712 | } | ||
16713 | |||
16714 | module.exports = Keccak | ||
16715 | |||
16716 | }).call(this,require("buffer").Buffer) | ||
16717 | },{"./keccak-state-unroll":69,"buffer":5}],71:[function(require,module,exports){ | ||
16718 | (function (Buffer){ | ||
16719 | /* | ||
16720 | CryptoJS v3.1.2 | ||
16721 | code.google.com/p/crypto-js | ||
16722 | (c) 2009-2013 by Jeff Mott. All rights reserved. | ||
16723 | code.google.com/p/crypto-js/wiki/License | ||
16724 | */ | ||
16725 | /** @preserve | ||
16726 | (c) 2012 by Cédric Mesnil. All rights reserved. | ||
16727 | |||
16728 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
16729 | |||
16730 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
16731 | - 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. | ||
16732 | |||
16733 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
16734 | */ | ||
16735 | |||
16736 | // constants table | ||
16737 | var zl = [ | ||
16738 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, | ||
16739 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, | ||
16740 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, | ||
16741 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, | ||
16742 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 | ||
16743 | ] | ||
16744 | |||
16745 | var zr = [ | ||
16746 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, | ||
16747 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, | ||
16748 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, | ||
16749 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, | ||
16750 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 | ||
16751 | ] | ||
16752 | |||
16753 | var sl = [ | ||
16754 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, | ||
16755 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, | ||
16756 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, | ||
16757 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, | ||
16758 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 | ||
16759 | ] | ||
16760 | |||
16761 | var sr = [ | ||
16762 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, | ||
16763 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, | ||
16764 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, | ||
16765 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, | ||
16766 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 | ||
16767 | ] | ||
16768 | |||
16769 | var hl = [0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E] | ||
16770 | var hr = [0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000] | ||
16771 | |||
16772 | function bytesToWords (bytes) { | ||
16773 | var words = [] | ||
16774 | for (var i = 0, b = 0; i < bytes.length; i++, b += 8) { | ||
16775 | words[b >>> 5] |= bytes[i] << (24 - b % 32) | ||
16776 | } | ||
16777 | return words | ||
16778 | } | ||
16779 | |||
16780 | function wordsToBytes (words) { | ||
16781 | var bytes = [] | ||
16782 | for (var b = 0; b < words.length * 32; b += 8) { | ||
16783 | bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF) | ||
16784 | } | ||
16785 | return bytes | ||
16786 | } | ||
16787 | |||
16788 | function processBlock (H, M, offset) { | ||
16789 | // swap endian | ||
16790 | for (var i = 0; i < 16; i++) { | ||
16791 | var offset_i = offset + i | ||
16792 | var M_offset_i = M[offset_i] | ||
16793 | |||
16794 | // Swap | ||
16795 | M[offset_i] = ( | ||
16796 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | | ||
16797 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) | ||
16798 | ) | ||
16799 | } | ||
16800 | |||
16801 | // Working variables | ||
16802 | var al, bl, cl, dl, el | ||
16803 | var ar, br, cr, dr, er | ||
16804 | |||
16805 | ar = al = H[0] | ||
16806 | br = bl = H[1] | ||
16807 | cr = cl = H[2] | ||
16808 | dr = dl = H[3] | ||
16809 | er = el = H[4] | ||
16810 | |||
16811 | // computation | ||
16812 | var t | ||
16813 | for (i = 0; i < 80; i += 1) { | ||
16814 | t = (al + M[offset + zl[i]]) | 0 | ||
16815 | if (i < 16) { | ||
16816 | t += f1(bl, cl, dl) + hl[0] | ||
16817 | } else if (i < 32) { | ||
16818 | t += f2(bl, cl, dl) + hl[1] | ||
16819 | } else if (i < 48) { | ||
16820 | t += f3(bl, cl, dl) + hl[2] | ||
16821 | } else if (i < 64) { | ||
16822 | t += f4(bl, cl, dl) + hl[3] | ||
16823 | } else {// if (i<80) { | ||
16824 | t += f5(bl, cl, dl) + hl[4] | ||
16825 | } | ||
16826 | t = t | 0 | ||
16827 | t = rotl(t, sl[i]) | ||
16828 | t = (t + el) | 0 | ||
16829 | al = el | ||
16830 | el = dl | ||
16831 | dl = rotl(cl, 10) | ||
16832 | cl = bl | ||
16833 | bl = t | ||
16834 | |||
16835 | t = (ar + M[offset + zr[i]]) | 0 | ||
16836 | if (i < 16) { | ||
16837 | t += f5(br, cr, dr) + hr[0] | ||
16838 | } else if (i < 32) { | ||
16839 | t += f4(br, cr, dr) + hr[1] | ||
16840 | } else if (i < 48) { | ||
16841 | t += f3(br, cr, dr) + hr[2] | ||
16842 | } else if (i < 64) { | ||
16843 | t += f2(br, cr, dr) + hr[3] | ||
16844 | } else {// if (i<80) { | ||
16845 | t += f1(br, cr, dr) + hr[4] | ||
16846 | } | ||
16847 | |||
16848 | t = t | 0 | ||
16849 | t = rotl(t, sr[i]) | ||
16850 | t = (t + er) | 0 | ||
16851 | ar = er | ||
16852 | er = dr | ||
16853 | dr = rotl(cr, 10) | ||
16854 | cr = br | ||
16855 | br = t | ||
16856 | } | ||
16857 | |||
16858 | // intermediate hash value | ||
16859 | t = (H[1] + cl + dr) | 0 | ||
16860 | H[1] = (H[2] + dl + er) | 0 | ||
16861 | H[2] = (H[3] + el + ar) | 0 | ||
16862 | H[3] = (H[4] + al + br) | 0 | ||
16863 | H[4] = (H[0] + bl + cr) | 0 | ||
16864 | H[0] = t | ||
16865 | } | ||
16866 | |||
16867 | function f1 (x, y, z) { | ||
16868 | return ((x) ^ (y) ^ (z)) | ||
16869 | } | ||
16870 | |||
16871 | function f2 (x, y, z) { | ||
16872 | return (((x) & (y)) | ((~x) & (z))) | ||
16873 | } | ||
16874 | |||
16875 | function f3 (x, y, z) { | ||
16876 | return (((x) | (~(y))) ^ (z)) | ||
16877 | } | ||
16878 | |||
16879 | function f4 (x, y, z) { | ||
16880 | return (((x) & (z)) | ((y) & (~(z)))) | ||
16881 | } | ||
16882 | |||
16883 | function f5 (x, y, z) { | ||
16884 | return ((x) ^ ((y) | (~(z)))) | ||
16885 | } | ||
16886 | |||
16887 | function rotl (x, n) { | ||
16888 | return (x << n) | (x >>> (32 - n)) | ||
16889 | } | ||
16890 | |||
16891 | function ripemd160 (message) { | ||
16892 | var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0] | ||
16893 | |||
16894 | if (typeof message === 'string') { | ||
16895 | message = new Buffer(message, 'utf8') | ||
16896 | } | ||
16897 | |||
16898 | var m = bytesToWords(message) | ||
16899 | |||
16900 | var nBitsLeft = message.length * 8 | ||
16901 | var nBitsTotal = message.length * 8 | ||
16902 | |||
16903 | // Add padding | ||
16904 | m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32) | ||
16905 | m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( | ||
16906 | (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | | ||
16907 | (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) | ||
16908 | ) | ||
16909 | |||
16910 | for (var i = 0; i < m.length; i += 16) { | ||
16911 | processBlock(H, m, i) | ||
16912 | } | ||
16913 | |||
16914 | // swap endian | ||
16915 | for (i = 0; i < 5; i++) { | ||
16916 | // shortcut | ||
16917 | var H_i = H[i] | ||
16918 | |||
16919 | // Swap | ||
16920 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | | ||
16921 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00) | ||
16922 | } | ||
16923 | |||
16924 | var digestbytes = wordsToBytes(H) | ||
16925 | return new Buffer(digestbytes) | ||
16926 | } | ||
16927 | |||
16928 | module.exports = ripemd160 | ||
16929 | |||
16930 | }).call(this,require("buffer").Buffer) | ||
16931 | },{"buffer":5}],72:[function(require,module,exports){ | ||
16932 | (function (Buffer){ | ||
16933 | const assert = require('assert') | ||
16934 | /** | ||
16935 | * RLP Encoding based on: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP | ||
16936 | * This function takes in a data, convert it to buffer if not, and a length for recursion | ||
16937 | * | ||
16938 | * @param {Buffer,String,Integer,Array} data - will be converted to buffer | ||
16939 | * @returns {Buffer} - returns buffer of encoded data | ||
16940 | **/ | ||
16941 | exports.encode = function (input) { | ||
16942 | if (input instanceof Array) { | ||
16943 | var output = [] | ||
16944 | for (var i = 0; i < input.length; i++) { | ||
16945 | output.push(exports.encode(input[i])) | ||
16946 | } | ||
16947 | var buf = Buffer.concat(output) | ||
16948 | return Buffer.concat([encodeLength(buf.length, 192), buf]) | ||
16949 | } else { | ||
16950 | input = toBuffer(input) | ||
16951 | if (input.length === 1 && input[0] < 128) { | ||
16952 | return input | ||
16953 | } else { | ||
16954 | return Buffer.concat([encodeLength(input.length, 128), input]) | ||
16955 | } | ||
16956 | } | ||
16957 | } | ||
16958 | |||
16959 | function safeParseInt (v, base) { | ||
16960 | if (v.slice(0, 2) === '00') { | ||
16961 | throw (new Error('invalid RLP: extra zeros')) | ||
16962 | } | ||
16963 | |||
16964 | return parseInt(v, base) | ||
16965 | } | ||
16966 | |||
16967 | function encodeLength (len, offset) { | ||
16968 | if (len < 56) { | ||
16969 | return new Buffer([len + offset]) | ||
16970 | } else { | ||
16971 | var hexLength = intToHex(len) | ||
16972 | var lLength = hexLength.length / 2 | ||
16973 | var firstByte = intToHex(offset + 55 + lLength) | ||
16974 | return new Buffer(firstByte + hexLength, 'hex') | ||
16975 | } | ||
16976 | } | ||
16977 | |||
16978 | /** | ||
16979 | * RLP Decoding based on: {@link https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP|RLP} | ||
16980 | * @param {Buffer,String,Integer,Array} data - will be converted to buffer | ||
16981 | * @returns {Array} - returns decode Array of Buffers containg the original message | ||
16982 | **/ | ||
16983 | exports.decode = function (input, stream) { | ||
16984 | if (!input || input.length === 0) { | ||
16985 | return new Buffer([]) | ||
16986 | } | ||
16987 | |||
16988 | input = toBuffer(input) | ||
16989 | var decoded = _decode(input) | ||
16990 | |||
16991 | if (stream) { | ||
16992 | return decoded | ||
16993 | } | ||
16994 | |||
16995 | assert.equal(decoded.remainder.length, 0, 'invalid remainder') | ||
16996 | return decoded.data | ||
16997 | } | ||
16998 | |||
16999 | exports.getLength = function (input) { | ||
17000 | if (!input || input.length === 0) { | ||
17001 | return new Buffer([]) | ||
17002 | } | ||
17003 | |||
17004 | input = toBuffer(input) | ||
17005 | var firstByte = input[0] | ||
17006 | if (firstByte <= 0x7f) { | ||
17007 | return input.length | ||
17008 | } else if (firstByte <= 0xb7) { | ||
17009 | return firstByte - 0x7f | ||
17010 | } else if (firstByte <= 0xbf) { | ||
17011 | return firstByte - 0xb6 | ||
17012 | } else if (firstByte <= 0xf7) { | ||
17013 | // a list between 0-55 bytes long | ||
17014 | return firstByte - 0xbf | ||
17015 | } else { | ||
17016 | // a list over 55 bytes long | ||
17017 | var llength = firstByte - 0xf6 | ||
17018 | var length = safeParseInt(input.slice(1, llength).toString('hex'), 16) | ||
17019 | return llength + length | ||
17020 | } | ||
17021 | } | ||
17022 | |||
17023 | function _decode (input) { | ||
17024 | var length, llength, data, innerRemainder, d | ||
17025 | var decoded = [] | ||
17026 | var firstByte = input[0] | ||
17027 | |||
17028 | if (firstByte <= 0x7f) { | ||
17029 | // a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding. | ||
17030 | return { | ||
17031 | data: input.slice(0, 1), | ||
17032 | remainder: input.slice(1) | ||
17033 | } | ||
17034 | } else if (firstByte <= 0xb7) { | ||
17035 | // string is 0-55 bytes long. A single byte with value 0x80 plus the length of the string followed by the string | ||
17036 | // The range of the first byte is [0x80, 0xb7] | ||
17037 | length = firstByte - 0x7f | ||
17038 | |||
17039 | // set 0x80 null to 0 | ||
17040 | if (firstByte === 0x80) { | ||
17041 | data = new Buffer([]) | ||
17042 | } else { | ||
17043 | data = input.slice(1, length) | ||
17044 | } | ||
17045 | |||
17046 | if (length === 2 && data[0] < 0x80) { | ||
17047 | throw new Error('invalid rlp encoding: byte must be less 0x80') | ||
17048 | } | ||
17049 | |||
17050 | return { | ||
17051 | data: data, | ||
17052 | remainder: input.slice(length) | ||
17053 | } | ||
17054 | } else if (firstByte <= 0xbf) { | ||
17055 | llength = firstByte - 0xb6 | ||
17056 | length = safeParseInt(input.slice(1, llength).toString('hex'), 16) | ||
17057 | data = input.slice(llength, length + llength) | ||
17058 | if (data.length < length) { | ||
17059 | throw (new Error('invalid RLP')) | ||
17060 | } | ||
17061 | |||
17062 | return { | ||
17063 | data: data, | ||
17064 | remainder: input.slice(length + llength) | ||
17065 | } | ||
17066 | } else if (firstByte <= 0xf7) { | ||
17067 | // a list between 0-55 bytes long | ||
17068 | length = firstByte - 0xbf | ||
17069 | innerRemainder = input.slice(1, length) | ||
17070 | while (innerRemainder.length) { | ||
17071 | d = _decode(innerRemainder) | ||
17072 | decoded.push(d.data) | ||
17073 | innerRemainder = d.remainder | ||
17074 | } | ||
17075 | |||
17076 | return { | ||
17077 | data: decoded, | ||
17078 | remainder: input.slice(length) | ||
17079 | } | ||
17080 | } else { | ||
17081 | // a list over 55 bytes long | ||
17082 | llength = firstByte - 0xf6 | ||
17083 | length = safeParseInt(input.slice(1, llength).toString('hex'), 16) | ||
17084 | var totalLength = llength + length | ||
17085 | if (totalLength > input.length) { | ||
17086 | throw new Error('invalid rlp: total length is larger than the data') | ||
17087 | } | ||
17088 | |||
17089 | innerRemainder = input.slice(llength, totalLength) | ||
17090 | if (innerRemainder.length === 0) { | ||
17091 | throw new Error('invalid rlp, List has a invalid length') | ||
17092 | } | ||
17093 | |||
17094 | while (innerRemainder.length) { | ||
17095 | d = _decode(innerRemainder) | ||
17096 | decoded.push(d.data) | ||
17097 | innerRemainder = d.remainder | ||
17098 | } | ||
17099 | return { | ||
17100 | data: decoded, | ||
17101 | remainder: input.slice(totalLength) | ||
17102 | } | ||
17103 | } | ||
17104 | } | ||
17105 | |||
17106 | function isHexPrefixed (str) { | ||
17107 | return str.slice(0, 2) === '0x' | ||
17108 | } | ||
17109 | |||
17110 | // Removes 0x from a given String | ||
17111 | function stripHexPrefix (str) { | ||
17112 | if (typeof str !== 'string') { | ||
17113 | return str | ||
17114 | } | ||
17115 | return isHexPrefixed(str) ? str.slice(2) : str | ||
17116 | } | ||
17117 | |||
17118 | function intToHex (i) { | ||
17119 | var hex = i.toString(16) | ||
17120 | if (hex.length % 2) { | ||
17121 | hex = '0' + hex | ||
17122 | } | ||
17123 | |||
17124 | return hex | ||
17125 | } | ||
17126 | |||
17127 | function padToEven (a) { | ||
17128 | if (a.length % 2) a = '0' + a | ||
17129 | return a | ||
17130 | } | ||
17131 | |||
17132 | function intToBuffer (i) { | ||
17133 | var hex = intToHex(i) | ||
17134 | return new Buffer(hex, 'hex') | ||
17135 | } | ||
17136 | |||
17137 | function toBuffer (v) { | ||
17138 | if (!Buffer.isBuffer(v)) { | ||
17139 | if (typeof v === 'string') { | ||
17140 | if (isHexPrefixed(v)) { | ||
17141 | v = new Buffer(padToEven(stripHexPrefix(v)), 'hex') | ||
17142 | } else { | ||
17143 | v = new Buffer(v) | ||
17144 | } | ||
17145 | } else if (typeof v === 'number') { | ||
17146 | if (!v) { | ||
17147 | v = new Buffer([]) | ||
17148 | } else { | ||
17149 | v = intToBuffer(v) | ||
17150 | } | ||
17151 | } else if (v === null || v === undefined) { | ||
17152 | v = new Buffer([]) | ||
17153 | } else if (v.toArray) { | ||
17154 | // converts a BN to a Buffer | ||
17155 | v = new Buffer(v.toArray()) | ||
17156 | } else { | ||
17157 | throw new Error('invalid type') | ||
17158 | } | ||
17159 | } | ||
17160 | return v | ||
17161 | } | ||
17162 | |||
17163 | }).call(this,require("buffer").Buffer) | ||
17164 | },{"assert":1,"buffer":5}],73:[function(require,module,exports){ | ||
17165 | 'use strict' | ||
17166 | module.exports = require('./lib')(require('./lib/elliptic')) | ||
17167 | |||
17168 | },{"./lib":77,"./lib/elliptic":76}],74:[function(require,module,exports){ | ||
17169 | (function (Buffer){ | ||
17170 | 'use strict' | ||
17171 | var toString = Object.prototype.toString | ||
17172 | |||
17173 | // TypeError | ||
17174 | exports.isArray = function (value, message) { | ||
17175 | if (!Array.isArray(value)) throw TypeError(message) | ||
17176 | } | ||
17177 | |||
17178 | exports.isBoolean = function (value, message) { | ||
17179 | if (toString.call(value) !== '[object Boolean]') throw TypeError(message) | ||
17180 | } | ||
17181 | |||
17182 | exports.isBuffer = function (value, message) { | ||
17183 | if (!Buffer.isBuffer(value)) throw TypeError(message) | ||
17184 | } | ||
17185 | |||
17186 | exports.isFunction = function (value, message) { | ||
17187 | if (toString.call(value) !== '[object Function]') throw TypeError(message) | ||
17188 | } | ||
17189 | |||
17190 | exports.isNumber = function (value, message) { | ||
17191 | if (toString.call(value) !== '[object Number]') throw TypeError(message) | ||
17192 | } | ||
17193 | |||
17194 | exports.isObject = function (value, message) { | ||
17195 | if (toString.call(value) !== '[object Object]') throw TypeError(message) | ||
17196 | } | ||
17197 | |||
17198 | // RangeError | ||
17199 | exports.isBufferLength = function (buffer, length, message) { | ||
17200 | if (buffer.length !== length) throw RangeError(message) | ||
17201 | } | ||
17202 | |||
17203 | exports.isBufferLength2 = function (buffer, length1, length2, message) { | ||
17204 | if (buffer.length !== length1 && buffer.length !== length2) throw RangeError(message) | ||
17205 | } | ||
17206 | |||
17207 | exports.isLengthGTZero = function (value, message) { | ||
17208 | if (value.length === 0) throw RangeError(message) | ||
17209 | } | ||
17210 | |||
17211 | exports.isNumberInInterval = function (number, x, y, message) { | ||
17212 | if (number <= x || number >= y) throw RangeError(message) | ||
17213 | } | ||
17214 | |||
17215 | }).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v7.5.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) | ||
17216 | },{"../../../../../.nvm/versions/node/v7.5.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10}],75:[function(require,module,exports){ | ||
17217 | (function (Buffer){ | ||
17218 | 'use strict' | ||
17219 | var bip66 = require('bip66') | ||
17220 | |||
17221 | var EC_PRIVKEY_EXPORT_DER_COMPRESSED = new Buffer([ | ||
17222 | // begin | ||
17223 | 0x30, 0x81, 0xd3, 0x02, 0x01, 0x01, 0x04, 0x20, | ||
17224 | // private key | ||
17225 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17226 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17227 | // middle | ||
17228 | 0xa0, 0x81, 0x85, 0x30, 0x81, 0x82, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, | ||
17229 | 0xcE, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17230 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17231 | 0xff, 0xff, 0xfE, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, | ||
17232 | 0x21, 0x02, 0x79, 0xbE, 0x66, 0x7E, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xcE, 0x87, | ||
17233 | 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xcE, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, | ||
17234 | 0x17, 0x98, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17235 | 0xff, 0xff, 0xff, 0xff, 0xfE, 0xba, 0xaE, 0xdc, 0xE6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5E, | ||
17236 | 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0xa1, 0x24, 0x03, 0x22, 0x00, | ||
17237 | // public key | ||
17238 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17239 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17240 | 0x00 | ||
17241 | ]) | ||
17242 | |||
17243 | var EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED = new Buffer([ | ||
17244 | // begin | ||
17245 | 0x30, 0x82, 0x01, 0x13, 0x02, 0x01, 0x01, 0x04, 0x20, | ||
17246 | // private key | ||
17247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17249 | // middle | ||
17250 | 0xa0, 0x81, 0xa5, 0x30, 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, | ||
17251 | 0xcE, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17252 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17253 | 0xff, 0xff, 0xfE, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, | ||
17254 | 0x41, 0x04, 0x79, 0xbE, 0x66, 0x7E, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xcE, 0x87, | ||
17255 | 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xcE, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, | ||
17256 | 0x17, 0x98, 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0E, 0x11, | ||
17257 | 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, | ||
17258 | 0xd4, 0xb8, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
17259 | 0xff, 0xff, 0xff, 0xff, 0xfE, 0xba, 0xaE, 0xdc, 0xE6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5E, | ||
17260 | 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0xa1, 0x44, 0x03, 0x42, 0x00, | ||
17261 | // public key | ||
17262 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17263 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17264 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17265 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17266 | 0x00 | ||
17267 | ]) | ||
17268 | |||
17269 | var ZERO_BUFFER_32 = new Buffer([ | ||
17270 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
17271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
17272 | ]) | ||
17273 | |||
17274 | exports.privateKeyExport = function (privateKey, publicKey, compressed) { | ||
17275 | var result = new Buffer(compressed ? EC_PRIVKEY_EXPORT_DER_COMPRESSED : EC_PRIVKEY_EXPORT_DER_UNCOMPRESSED) | ||
17276 | privateKey.copy(result, compressed ? 8 : 9) | ||
17277 | publicKey.copy(result, compressed ? 181 : 214) | ||
17278 | return result | ||
17279 | } | ||
17280 | |||
17281 | exports.privateKeyImport = function (privateKey) { | ||
17282 | var length = privateKey.length | ||
17283 | |||
17284 | // sequence header | ||
17285 | var index = 0 | ||
17286 | if (length < index + 1 || privateKey[index] !== 0x30) return | ||
17287 | index += 1 | ||
17288 | |||
17289 | // sequence length constructor | ||
17290 | if (length < index + 1 || !(privateKey[index] & 0x80)) return | ||
17291 | |||
17292 | var lenb = privateKey[index] & 0x7f | ||
17293 | index += 1 | ||
17294 | if (lenb < 1 || lenb > 2) return | ||
17295 | if (length < index + lenb) return | ||
17296 | |||
17297 | // sequence length | ||
17298 | var len = privateKey[index + lenb - 1] | (lenb > 1 ? privateKey[index + lenb - 2] << 8 : 0) | ||
17299 | index += lenb | ||
17300 | if (length < index + len) return | ||
17301 | |||
17302 | // sequence element 0: version number (=1) | ||
17303 | if (length < index + 3 || | ||
17304 | privateKey[index] !== 0x02 || | ||
17305 | privateKey[index + 1] !== 0x01 || | ||
17306 | privateKey[index + 2] !== 0x01) { | ||
17307 | return | ||
17308 | } | ||
17309 | index += 3 | ||
17310 | |||
17311 | // sequence element 1: octet string, up to 32 bytes | ||
17312 | if (length < index + 2 || | ||
17313 | privateKey[index] !== 0x04 || | ||
17314 | privateKey[index + 1] > 0x20 || | ||
17315 | length < index + 2 + privateKey[index + 1]) { | ||
17316 | return | ||
17317 | } | ||
17318 | |||
17319 | return privateKey.slice(index + 2, index + 2 + privateKey[index + 1]) | ||
17320 | } | ||
17321 | |||
17322 | exports.signatureExport = function (sigObj) { | ||
17323 | var r = Buffer.concat([new Buffer([0]), sigObj.r]) | ||
17324 | for (var lenR = 33, posR = 0; lenR > 1 && r[posR] === 0x00 && !(r[posR + 1] & 0x80); --lenR, ++posR); | ||
17325 | |||
17326 | var s = Buffer.concat([new Buffer([0]), sigObj.s]) | ||
17327 | for (var lenS = 33, posS = 0; lenS > 1 && s[posS] === 0x00 && !(s[posS + 1] & 0x80); --lenS, ++posS); | ||
17328 | |||
17329 | return bip66.encode(r.slice(posR), s.slice(posS)) | ||
17330 | } | ||
17331 | |||
17332 | exports.signatureImport = function (sig) { | ||
17333 | var r = new Buffer(ZERO_BUFFER_32) | ||
17334 | var s = new Buffer(ZERO_BUFFER_32) | ||
17335 | |||
17336 | try { | ||
17337 | var sigObj = bip66.decode(sig) | ||
17338 | if (sigObj.r.length === 33 && sigObj.r[0] === 0x00) sigObj.r = sigObj.r.slice(1) | ||
17339 | if (sigObj.r.length > 32) throw new Error('R length is too long') | ||
17340 | if (sigObj.s.length === 33 && sigObj.s[0] === 0x00) sigObj.s = sigObj.s.slice(1) | ||
17341 | if (sigObj.s.length > 32) throw new Error('S length is too long') | ||
17342 | } catch (err) { | ||
17343 | return | ||
17344 | } | ||
17345 | |||
17346 | sigObj.r.copy(r, 32 - sigObj.r.length) | ||
17347 | sigObj.s.copy(s, 32 - sigObj.s.length) | ||
17348 | |||
17349 | return { r: r, s: s } | ||
17350 | } | ||
17351 | |||
17352 | exports.signatureImportLax = function (sig) { | ||
17353 | var r = new Buffer(ZERO_BUFFER_32) | ||
17354 | var s = new Buffer(ZERO_BUFFER_32) | ||
17355 | |||
17356 | var length = sig.length | ||
17357 | var index = 0 | ||
17358 | |||
17359 | // sequence tag byte | ||
17360 | if (sig[index++] !== 0x30) return | ||
17361 | |||
17362 | // sequence length byte | ||
17363 | var lenbyte = sig[index++] | ||
17364 | if (lenbyte & 0x80) { | ||
17365 | index += lenbyte - 0x80 | ||
17366 | if (index > length) return | ||
17367 | } | ||
17368 | |||
17369 | // sequence tag byte for r | ||
17370 | if (sig[index++] !== 0x02) return | ||
17371 | |||
17372 | // length for r | ||
17373 | var rlen = sig[index++] | ||
17374 | if (rlen & 0x80) { | ||
17375 | lenbyte = rlen - 0x80 | ||
17376 | if (index + lenbyte > length) return | ||
17377 | for (; lenbyte > 0 && sig[index] === 0x00; index += 1, lenbyte -= 1); | ||
17378 | for (rlen = 0; lenbyte > 0; index += 1, lenbyte -= 1) rlen = (rlen << 8) + sig[index] | ||
17379 | } | ||
17380 | if (rlen > length - index) return | ||
17381 | var rindex = index | ||
17382 | index += rlen | ||
17383 | |||
17384 | // sequence tag byte for s | ||
17385 | if (sig[index++] !== 0x02) return | ||
17386 | |||
17387 | // length for s | ||
17388 | var slen = sig[index++] | ||
17389 | if (slen & 0x80) { | ||
17390 | lenbyte = slen - 0x80 | ||
17391 | if (index + lenbyte > length) return | ||
17392 | for (; lenbyte > 0 && sig[index] === 0x00; index += 1, lenbyte -= 1); | ||
17393 | for (slen = 0; lenbyte > 0; index += 1, lenbyte -= 1) slen = (slen << 8) + sig[index] | ||
17394 | } | ||
17395 | if (slen > length - index) return | ||
17396 | var sindex = index | ||
17397 | index += slen | ||
17398 | |||
17399 | // ignore leading zeros in r | ||
17400 | for (; rlen > 0 && sig[rindex] === 0x00; rlen -= 1, rindex += 1); | ||
17401 | // copy r value | ||
17402 | if (rlen > 32) return | ||
17403 | var rvalue = sig.slice(rindex, rindex + rlen) | ||
17404 | rvalue.copy(r, 32 - rvalue.length) | ||
17405 | |||
17406 | // ignore leading zeros in s | ||
17407 | for (; slen > 0 && sig[sindex] === 0x00; slen -= 1, sindex += 1); | ||
17408 | // copy s value | ||
17409 | if (slen > 32) return | ||
17410 | var svalue = sig.slice(sindex, sindex + slen) | ||
17411 | svalue.copy(s, 32 - svalue.length) | ||
17412 | |||
17413 | return { r: r, s: s } | ||
17414 | } | ||
17415 | |||
17416 | }).call(this,require("buffer").Buffer) | ||
17417 | },{"bip66":32,"buffer":5}],76:[function(require,module,exports){ | ||
17418 | (function (Buffer){ | ||
17419 | 'use strict' | ||
17420 | var createHash = require('create-hash') | ||
17421 | var BN = require('bn.js') | ||
17422 | var EC = require('elliptic').ec | ||
17423 | |||
17424 | var messages = require('../messages.json') | ||
17425 | |||
17426 | var ec = new EC('secp256k1') | ||
17427 | var ecparams = ec.curve | ||
17428 | |||
17429 | function loadCompressedPublicKey (first, xBuffer) { | ||
17430 | var x = new BN(xBuffer) | ||
17431 | |||
17432 | // overflow | ||
17433 | if (x.cmp(ecparams.p) >= 0) return null | ||
17434 | x = x.toRed(ecparams.red) | ||
17435 | |||
17436 | // compute corresponding Y | ||
17437 | var y = x.redSqr().redIMul(x).redIAdd(ecparams.b).redSqrt() | ||
17438 | if ((first === 0x03) !== y.isOdd()) y = y.redNeg() | ||
17439 | |||
17440 | return ec.keyPair({ pub: { x: x, y: y } }) | ||
17441 | } | ||
17442 | |||
17443 | function loadUncompressedPublicKey (first, xBuffer, yBuffer) { | ||
17444 | var x = new BN(xBuffer) | ||
17445 | var y = new BN(yBuffer) | ||
17446 | |||
17447 | // overflow | ||
17448 | if (x.cmp(ecparams.p) >= 0 || y.cmp(ecparams.p) >= 0) return null | ||
17449 | |||
17450 | x = x.toRed(ecparams.red) | ||
17451 | y = y.toRed(ecparams.red) | ||
17452 | |||
17453 | // is odd flag | ||
17454 | if ((first === 0x06 || first === 0x07) && y.isOdd() !== (first === 0x07)) return null | ||
17455 | |||
17456 | // x*x*x + b = y*y | ||
17457 | var x3 = x.redSqr().redIMul(x) | ||
17458 | if (!y.redSqr().redISub(x3.redIAdd(ecparams.b)).isZero()) return null | ||
17459 | |||
17460 | return ec.keyPair({ pub: { x: x, y: y } }) | ||
17461 | } | ||
17462 | |||
17463 | function loadPublicKey (publicKey) { | ||
17464 | var first = publicKey[0] | ||
17465 | switch (first) { | ||
17466 | case 0x02: | ||
17467 | case 0x03: | ||
17468 | if (publicKey.length !== 33) return null | ||
17469 | return loadCompressedPublicKey(first, publicKey.slice(1, 33)) | ||
17470 | case 0x04: | ||
17471 | case 0x06: | ||
17472 | case 0x07: | ||
17473 | if (publicKey.length !== 65) return null | ||
17474 | return loadUncompressedPublicKey(first, publicKey.slice(1, 33), publicKey.slice(33, 65)) | ||
17475 | default: | ||
17476 | return null | ||
17477 | } | ||
17478 | } | ||
17479 | |||
17480 | exports.privateKeyVerify = function (privateKey) { | ||
17481 | var bn = new BN(privateKey) | ||
17482 | return bn.cmp(ecparams.n) < 0 && !bn.isZero() | ||
17483 | } | ||
17484 | |||
17485 | exports.privateKeyExport = function (privateKey, compressed) { | ||
17486 | var d = new BN(privateKey) | ||
17487 | if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.EC_PRIVATE_KEY_EXPORT_DER_FAIL) | ||
17488 | |||
17489 | return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true)) | ||
17490 | } | ||
17491 | |||
17492 | exports.privateKeyTweakAdd = function (privateKey, tweak) { | ||
17493 | var bn = new BN(tweak) | ||
17494 | if (bn.cmp(ecparams.n) >= 0) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_ADD_FAIL) | ||
17495 | |||
17496 | bn.iadd(new BN(privateKey)) | ||
17497 | if (bn.cmp(ecparams.n) >= 0) bn.isub(ecparams.n) | ||
17498 | if (bn.isZero()) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_ADD_FAIL) | ||
17499 | |||
17500 | return bn.toArrayLike(Buffer, 'be', 32) | ||
17501 | } | ||
17502 | |||
17503 | exports.privateKeyTweakMul = function (privateKey, tweak) { | ||
17504 | var bn = new BN(tweak) | ||
17505 | if (bn.cmp(ecparams.n) >= 0 || bn.isZero()) throw new Error(messages.EC_PRIVATE_KEY_TWEAK_MUL_FAIL) | ||
17506 | |||
17507 | bn.imul(new BN(privateKey)) | ||
17508 | if (bn.cmp(ecparams.n)) bn = bn.umod(ecparams.n) | ||
17509 | |||
17510 | return bn.toArrayLike(Buffer, 'be', 32) | ||
17511 | } | ||
17512 | |||
17513 | exports.publicKeyCreate = function (privateKey, compressed) { | ||
17514 | var d = new BN(privateKey) | ||
17515 | if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.EC_PUBLIC_KEY_CREATE_FAIL) | ||
17516 | |||
17517 | return new Buffer(ec.keyFromPrivate(privateKey).getPublic(compressed, true)) | ||
17518 | } | ||
17519 | |||
17520 | exports.publicKeyConvert = function (publicKey, compressed) { | ||
17521 | var pair = loadPublicKey(publicKey) | ||
17522 | if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17523 | |||
17524 | return new Buffer(pair.getPublic(compressed, true)) | ||
17525 | } | ||
17526 | |||
17527 | exports.publicKeyVerify = function (publicKey) { | ||
17528 | return loadPublicKey(publicKey) !== null | ||
17529 | } | ||
17530 | |||
17531 | exports.publicKeyTweakAdd = function (publicKey, tweak, compressed) { | ||
17532 | var pair = loadPublicKey(publicKey) | ||
17533 | if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17534 | |||
17535 | tweak = new BN(tweak) | ||
17536 | if (tweak.cmp(ecparams.n) >= 0) throw new Error(messages.EC_PUBLIC_KEY_TWEAK_ADD_FAIL) | ||
17537 | |||
17538 | return new Buffer(ecparams.g.mul(tweak).add(pair.pub).encode(true, compressed)) | ||
17539 | } | ||
17540 | |||
17541 | exports.publicKeyTweakMul = function (publicKey, tweak, compressed) { | ||
17542 | var pair = loadPublicKey(publicKey) | ||
17543 | if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17544 | |||
17545 | tweak = new BN(tweak) | ||
17546 | if (tweak.cmp(ecparams.n) >= 0 || tweak.isZero()) throw new Error(messages.EC_PUBLIC_KEY_TWEAK_MUL_FAIL) | ||
17547 | |||
17548 | return new Buffer(pair.pub.mul(tweak).encode(true, compressed)) | ||
17549 | } | ||
17550 | |||
17551 | exports.publicKeyCombine = function (publicKeys, compressed) { | ||
17552 | var pairs = new Array(publicKeys.length) | ||
17553 | for (var i = 0; i < publicKeys.length; ++i) { | ||
17554 | pairs[i] = loadPublicKey(publicKeys[i]) | ||
17555 | if (pairs[i] === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17556 | } | ||
17557 | |||
17558 | var point = pairs[0].pub | ||
17559 | for (var j = 1; j < pairs.length; ++j) point = point.add(pairs[j].pub) | ||
17560 | if (point.isInfinity()) throw new Error(messages.EC_PUBLIC_KEY_COMBINE_FAIL) | ||
17561 | |||
17562 | return new Buffer(point.encode(true, compressed)) | ||
17563 | } | ||
17564 | |||
17565 | exports.signatureNormalize = function (signature) { | ||
17566 | var r = new BN(signature.slice(0, 32)) | ||
17567 | var s = new BN(signature.slice(32, 64)) | ||
17568 | if (r.cmp(ecparams.n) >= 0 || s.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL) | ||
17569 | |||
17570 | var result = new Buffer(signature) | ||
17571 | if (s.cmp(ec.nh) === 1) ecparams.n.sub(s).toArrayLike(Buffer, 'be', 32).copy(result, 32) | ||
17572 | |||
17573 | return result | ||
17574 | } | ||
17575 | |||
17576 | exports.signatureExport = function (signature) { | ||
17577 | var r = signature.slice(0, 32) | ||
17578 | var s = signature.slice(32, 64) | ||
17579 | if (new BN(r).cmp(ecparams.n) >= 0 || new BN(s).cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL) | ||
17580 | |||
17581 | return { r: r, s: s } | ||
17582 | } | ||
17583 | |||
17584 | exports.signatureImport = function (sigObj) { | ||
17585 | var r = new BN(sigObj.r) | ||
17586 | if (r.cmp(ecparams.n) >= 0) r = new BN(0) | ||
17587 | |||
17588 | var s = new BN(sigObj.s) | ||
17589 | if (s.cmp(ecparams.n) >= 0) s = new BN(0) | ||
17590 | |||
17591 | return Buffer.concat([ | ||
17592 | r.toArrayLike(Buffer, 'be', 32), | ||
17593 | s.toArrayLike(Buffer, 'be', 32) | ||
17594 | ]) | ||
17595 | } | ||
17596 | |||
17597 | exports.sign = function (message, privateKey, noncefn, data) { | ||
17598 | if (typeof noncefn === 'function') { | ||
17599 | var getNonce = noncefn | ||
17600 | noncefn = function (counter) { | ||
17601 | var nonce = getNonce(message, privateKey, null, data, counter) | ||
17602 | if (!Buffer.isBuffer(nonce) || nonce.length !== 32) throw new Error(messages.ECDSA_SIGN_FAIL) | ||
17603 | |||
17604 | return new BN(nonce) | ||
17605 | } | ||
17606 | } | ||
17607 | |||
17608 | var d = new BN(privateKey) | ||
17609 | if (d.cmp(ecparams.n) >= 0 || d.isZero()) throw new Error(messages.ECDSA_SIGN_FAIL) | ||
17610 | |||
17611 | var result = ec.sign(message, privateKey, { canonical: true, k: noncefn, pers: data }) | ||
17612 | return { | ||
17613 | signature: Buffer.concat([ | ||
17614 | result.r.toArrayLike(Buffer, 'be', 32), | ||
17615 | result.s.toArrayLike(Buffer, 'be', 32) | ||
17616 | ]), | ||
17617 | recovery: result.recoveryParam | ||
17618 | } | ||
17619 | } | ||
17620 | |||
17621 | exports.verify = function (message, signature, publicKey) { | ||
17622 | var sigObj = {r: signature.slice(0, 32), s: signature.slice(32, 64)} | ||
17623 | |||
17624 | var sigr = new BN(sigObj.r) | ||
17625 | var sigs = new BN(sigObj.s) | ||
17626 | if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL) | ||
17627 | if (sigs.cmp(ec.nh) === 1 || sigr.isZero() || sigs.isZero()) return false | ||
17628 | |||
17629 | var pair = loadPublicKey(publicKey) | ||
17630 | if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17631 | |||
17632 | return ec.verify(message, sigObj, {x: pair.pub.x, y: pair.pub.y}) | ||
17633 | } | ||
17634 | |||
17635 | exports.recover = function (message, signature, recovery, compressed) { | ||
17636 | var sigObj = {r: signature.slice(0, 32), s: signature.slice(32, 64)} | ||
17637 | |||
17638 | var sigr = new BN(sigObj.r) | ||
17639 | var sigs = new BN(sigObj.s) | ||
17640 | if (sigr.cmp(ecparams.n) >= 0 || sigs.cmp(ecparams.n) >= 0) throw new Error(messages.ECDSA_SIGNATURE_PARSE_FAIL) | ||
17641 | |||
17642 | try { | ||
17643 | if (sigr.isZero() || sigs.isZero()) throw new Error() | ||
17644 | |||
17645 | var point = ec.recoverPubKey(message, sigObj, recovery) | ||
17646 | return new Buffer(point.encode(true, compressed)) | ||
17647 | } catch (err) { | ||
17648 | throw new Error(messages.ECDSA_RECOVER_FAIL) | ||
17649 | } | ||
17650 | } | ||
17651 | |||
17652 | exports.ecdh = function (publicKey, privateKey) { | ||
17653 | var shared = exports.ecdhUnsafe(publicKey, privateKey, true) | ||
17654 | return createHash('sha256').update(shared).digest() | ||
17655 | } | ||
17656 | |||
17657 | exports.ecdhUnsafe = function (publicKey, privateKey, compressed) { | ||
17658 | var pair = loadPublicKey(publicKey) | ||
17659 | if (pair === null) throw new Error(messages.EC_PUBLIC_KEY_PARSE_FAIL) | ||
17660 | |||
17661 | var scalar = new BN(privateKey) | ||
17662 | if (scalar.cmp(ecparams.n) >= 0 || scalar.isZero()) throw new Error(messages.ECDH_FAIL) | ||
17663 | |||
17664 | return new Buffer(pair.pub.mul(scalar).encode(true, compressed)) | ||
17665 | } | ||
17666 | |||
17667 | }).call(this,require("buffer").Buffer) | ||
17668 | },{"../messages.json":78,"bn.js":33,"buffer":5,"create-hash":36,"elliptic":39}],77:[function(require,module,exports){ | ||
17669 | 'use strict' | ||
17670 | var assert = require('./assert') | ||
17671 | var der = require('./der') | ||
17672 | var messages = require('./messages.json') | ||
17673 | |||
17674 | function initCompressedValue (value, defaultValue) { | ||
17675 | if (value === undefined) return defaultValue | ||
17676 | |||
17677 | assert.isBoolean(value, messages.COMPRESSED_TYPE_INVALID) | ||
17678 | return value | ||
17679 | } | ||
17680 | |||
17681 | module.exports = function (secp256k1) { | ||
17682 | return { | ||
17683 | privateKeyVerify: function (privateKey) { | ||
17684 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17685 | return privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey) | ||
17686 | }, | ||
17687 | |||
17688 | privateKeyExport: function (privateKey, compressed) { | ||
17689 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17690 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17691 | |||
17692 | compressed = initCompressedValue(compressed, true) | ||
17693 | var publicKey = secp256k1.privateKeyExport(privateKey, compressed) | ||
17694 | |||
17695 | return der.privateKeyExport(privateKey, publicKey, compressed) | ||
17696 | }, | ||
17697 | |||
17698 | privateKeyImport: function (privateKey) { | ||
17699 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17700 | |||
17701 | privateKey = der.privateKeyImport(privateKey) | ||
17702 | if (privateKey && privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)) return privateKey | ||
17703 | |||
17704 | throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL) | ||
17705 | }, | ||
17706 | |||
17707 | privateKeyTweakAdd: function (privateKey, tweak) { | ||
17708 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17709 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17710 | |||
17711 | assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID) | ||
17712 | assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID) | ||
17713 | |||
17714 | return secp256k1.privateKeyTweakAdd(privateKey, tweak) | ||
17715 | }, | ||
17716 | |||
17717 | privateKeyTweakMul: function (privateKey, tweak) { | ||
17718 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17719 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17720 | |||
17721 | assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID) | ||
17722 | assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID) | ||
17723 | |||
17724 | return secp256k1.privateKeyTweakMul(privateKey, tweak) | ||
17725 | }, | ||
17726 | |||
17727 | publicKeyCreate: function (privateKey, compressed) { | ||
17728 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17729 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17730 | |||
17731 | compressed = initCompressedValue(compressed, true) | ||
17732 | |||
17733 | return secp256k1.publicKeyCreate(privateKey, compressed) | ||
17734 | }, | ||
17735 | |||
17736 | publicKeyConvert: function (publicKey, compressed) { | ||
17737 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17738 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17739 | |||
17740 | compressed = initCompressedValue(compressed, true) | ||
17741 | |||
17742 | return secp256k1.publicKeyConvert(publicKey, compressed) | ||
17743 | }, | ||
17744 | |||
17745 | publicKeyVerify: function (publicKey) { | ||
17746 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17747 | return secp256k1.publicKeyVerify(publicKey) | ||
17748 | }, | ||
17749 | |||
17750 | publicKeyTweakAdd: function (publicKey, tweak, compressed) { | ||
17751 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17752 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17753 | |||
17754 | assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID) | ||
17755 | assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID) | ||
17756 | |||
17757 | compressed = initCompressedValue(compressed, true) | ||
17758 | |||
17759 | return secp256k1.publicKeyTweakAdd(publicKey, tweak, compressed) | ||
17760 | }, | ||
17761 | |||
17762 | publicKeyTweakMul: function (publicKey, tweak, compressed) { | ||
17763 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17764 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17765 | |||
17766 | assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID) | ||
17767 | assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID) | ||
17768 | |||
17769 | compressed = initCompressedValue(compressed, true) | ||
17770 | |||
17771 | return secp256k1.publicKeyTweakMul(publicKey, tweak, compressed) | ||
17772 | }, | ||
17773 | |||
17774 | publicKeyCombine: function (publicKeys, compressed) { | ||
17775 | assert.isArray(publicKeys, messages.EC_PUBLIC_KEYS_TYPE_INVALID) | ||
17776 | assert.isLengthGTZero(publicKeys, messages.EC_PUBLIC_KEYS_LENGTH_INVALID) | ||
17777 | for (var i = 0; i < publicKeys.length; ++i) { | ||
17778 | assert.isBuffer(publicKeys[i], messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17779 | assert.isBufferLength2(publicKeys[i], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17780 | } | ||
17781 | |||
17782 | compressed = initCompressedValue(compressed, true) | ||
17783 | |||
17784 | return secp256k1.publicKeyCombine(publicKeys, compressed) | ||
17785 | }, | ||
17786 | |||
17787 | signatureNormalize: function (signature) { | ||
17788 | assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17789 | assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17790 | |||
17791 | return secp256k1.signatureNormalize(signature) | ||
17792 | }, | ||
17793 | |||
17794 | signatureExport: function (signature) { | ||
17795 | assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17796 | assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17797 | |||
17798 | var sigObj = secp256k1.signatureExport(signature) | ||
17799 | return der.signatureExport(sigObj) | ||
17800 | }, | ||
17801 | |||
17802 | signatureImport: function (sig) { | ||
17803 | assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17804 | assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17805 | |||
17806 | var sigObj = der.signatureImport(sig) | ||
17807 | if (sigObj) return secp256k1.signatureImport(sigObj) | ||
17808 | |||
17809 | throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL) | ||
17810 | }, | ||
17811 | |||
17812 | signatureImportLax: function (sig) { | ||
17813 | assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17814 | assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17815 | |||
17816 | var sigObj = der.signatureImportLax(sig) | ||
17817 | if (sigObj) return secp256k1.signatureImport(sigObj) | ||
17818 | |||
17819 | throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL) | ||
17820 | }, | ||
17821 | |||
17822 | sign: function (message, privateKey, options) { | ||
17823 | assert.isBuffer(message, messages.MSG32_TYPE_INVALID) | ||
17824 | assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID) | ||
17825 | |||
17826 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17827 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17828 | |||
17829 | var data = null | ||
17830 | var noncefn = null | ||
17831 | if (options !== undefined) { | ||
17832 | assert.isObject(options, messages.OPTIONS_TYPE_INVALID) | ||
17833 | |||
17834 | if (options.data !== undefined) { | ||
17835 | assert.isBuffer(options.data, messages.OPTIONS_DATA_TYPE_INVALID) | ||
17836 | assert.isBufferLength(options.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID) | ||
17837 | data = options.data | ||
17838 | } | ||
17839 | |||
17840 | if (options.noncefn !== undefined) { | ||
17841 | assert.isFunction(options.noncefn, messages.OPTIONS_NONCEFN_TYPE_INVALID) | ||
17842 | noncefn = options.noncefn | ||
17843 | } | ||
17844 | } | ||
17845 | |||
17846 | return secp256k1.sign(message, privateKey, noncefn, data) | ||
17847 | }, | ||
17848 | |||
17849 | verify: function (message, signature, publicKey) { | ||
17850 | assert.isBuffer(message, messages.MSG32_TYPE_INVALID) | ||
17851 | assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID) | ||
17852 | |||
17853 | assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17854 | assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17855 | |||
17856 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17857 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17858 | |||
17859 | return secp256k1.verify(message, signature, publicKey) | ||
17860 | }, | ||
17861 | |||
17862 | recover: function (message, signature, recovery, compressed) { | ||
17863 | assert.isBuffer(message, messages.MSG32_TYPE_INVALID) | ||
17864 | assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID) | ||
17865 | |||
17866 | assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID) | ||
17867 | assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID) | ||
17868 | |||
17869 | assert.isNumber(recovery, messages.RECOVERY_ID_TYPE_INVALID) | ||
17870 | assert.isNumberInInterval(recovery, -1, 4, messages.RECOVERY_ID_VALUE_INVALID) | ||
17871 | |||
17872 | compressed = initCompressedValue(compressed, true) | ||
17873 | |||
17874 | return secp256k1.recover(message, signature, recovery, compressed) | ||
17875 | }, | ||
17876 | |||
17877 | ecdh: function (publicKey, privateKey) { | ||
17878 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17879 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17880 | |||
17881 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17882 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17883 | |||
17884 | return secp256k1.ecdh(publicKey, privateKey) | ||
17885 | }, | ||
17886 | |||
17887 | ecdhUnsafe: function (publicKey, privateKey, compressed) { | ||
17888 | assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID) | ||
17889 | assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID) | ||
17890 | |||
17891 | assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID) | ||
17892 | assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID) | ||
17893 | |||
17894 | compressed = initCompressedValue(compressed, true) | ||
17895 | |||
17896 | return secp256k1.ecdhUnsafe(publicKey, privateKey, compressed) | ||
17897 | } | ||
17898 | } | ||
17899 | } | ||
17900 | |||
17901 | },{"./assert":74,"./der":75,"./messages.json":78}],78:[function(require,module,exports){ | ||
17902 | module.exports={ | ||
17903 | "COMPRESSED_TYPE_INVALID": "compressed should be a boolean", | ||
17904 | "EC_PRIVATE_KEY_TYPE_INVALID": "private key should be a Buffer", | ||
17905 | "EC_PRIVATE_KEY_LENGTH_INVALID": "private key length is invalid", | ||
17906 | "EC_PRIVATE_KEY_TWEAK_ADD_FAIL": "tweak out of range or resulting private key is invalid", | ||
17907 | "EC_PRIVATE_KEY_TWEAK_MUL_FAIL": "tweak out of range", | ||
17908 | "EC_PRIVATE_KEY_EXPORT_DER_FAIL": "couldn't export to DER format", | ||
17909 | "EC_PRIVATE_KEY_IMPORT_DER_FAIL": "couldn't import from DER format", | ||
17910 | "EC_PUBLIC_KEYS_TYPE_INVALID": "public keys should be an Array", | ||
17911 | "EC_PUBLIC_KEYS_LENGTH_INVALID": "public keys Array should have at least 1 element", | ||
17912 | "EC_PUBLIC_KEY_TYPE_INVALID": "public key should be a Buffer", | ||
17913 | "EC_PUBLIC_KEY_LENGTH_INVALID": "public key length is invalid", | ||
17914 | "EC_PUBLIC_KEY_PARSE_FAIL": "the public key could not be parsed or is invalid", | ||
17915 | "EC_PUBLIC_KEY_CREATE_FAIL": "private was invalid, try again", | ||
17916 | "EC_PUBLIC_KEY_TWEAK_ADD_FAIL": "tweak out of range or resulting public key is invalid", | ||
17917 | "EC_PUBLIC_KEY_TWEAK_MUL_FAIL": "tweak out of range", | ||
17918 | "EC_PUBLIC_KEY_COMBINE_FAIL": "the sum of the public keys is not valid", | ||
17919 | "ECDH_FAIL": "scalar was invalid (zero or overflow)", | ||
17920 | "ECDSA_SIGNATURE_TYPE_INVALID": "signature should be a Buffer", | ||
17921 | "ECDSA_SIGNATURE_LENGTH_INVALID": "signature length is invalid", | ||
17922 | "ECDSA_SIGNATURE_PARSE_FAIL": "couldn't parse signature", | ||
17923 | "ECDSA_SIGNATURE_PARSE_DER_FAIL": "couldn't parse DER signature", | ||
17924 | "ECDSA_SIGNATURE_SERIALIZE_DER_FAIL": "couldn't serialize signature to DER format", | ||
17925 | "ECDSA_SIGN_FAIL": "nonce generation function failed or private key is invalid", | ||
17926 | "ECDSA_RECOVER_FAIL": "couldn't recover public key from signature", | ||
17927 | "MSG32_TYPE_INVALID": "message should be a Buffer", | ||
17928 | "MSG32_LENGTH_INVALID": "message length is invalid", | ||
17929 | "OPTIONS_TYPE_INVALID": "options should be an Object", | ||
17930 | "OPTIONS_DATA_TYPE_INVALID": "options.data should be a Buffer", | ||
17931 | "OPTIONS_DATA_LENGTH_INVALID": "options.data length is invalid", | ||
17932 | "OPTIONS_NONCEFN_TYPE_INVALID": "options.noncefn should be a Function", | ||
17933 | "RECOVERY_ID_TYPE_INVALID": "recovery should be a Number", | ||
17934 | "RECOVERY_ID_VALUE_INVALID": "recovery should have value between -1 and 4", | ||
17935 | "TWEAK_TYPE_INVALID": "tweak should be a Buffer", | ||
17936 | "TWEAK_LENGTH_INVALID": "tweak length is invalid" | ||
17937 | } | ||
17938 | |||
17939 | },{}],79:[function(require,module,exports){ | ||
17940 | (function (Buffer){ | ||
17941 | // prototype class for hash functions | ||
17942 | function Hash (blockSize, finalSize) { | ||
17943 | this._block = new Buffer(blockSize) | ||
17944 | this._finalSize = finalSize | ||
17945 | this._blockSize = blockSize | ||
17946 | this._len = 0 | ||
17947 | this._s = 0 | ||
17948 | } | ||
17949 | |||
17950 | Hash.prototype.update = function (data, enc) { | ||
17951 | if (typeof data === 'string') { | ||
17952 | enc = enc || 'utf8' | ||
17953 | data = new Buffer(data, enc) | ||
17954 | } | ||
17955 | |||
17956 | var l = this._len += data.length | ||
17957 | var s = this._s || 0 | ||
17958 | var f = 0 | ||
17959 | var buffer = this._block | ||
17960 | |||
17961 | while (s < l) { | ||
17962 | var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize)) | ||
17963 | var ch = (t - f) | ||
17964 | |||
17965 | for (var i = 0; i < ch; i++) { | ||
17966 | buffer[(s % this._blockSize) + i] = data[i + f] | ||
17967 | } | ||
17968 | |||
17969 | s += ch | ||
17970 | f += ch | ||
17971 | |||
17972 | if ((s % this._blockSize) === 0) { | ||
17973 | this._update(buffer) | ||
17974 | } | ||
17975 | } | ||
17976 | this._s = s | ||
17977 | |||
17978 | return this | ||
17979 | } | ||
17980 | |||
17981 | Hash.prototype.digest = function (enc) { | ||
17982 | // Suppose the length of the message M, in bits, is l | ||
17983 | var l = this._len * 8 | ||
17984 | |||
17985 | // Append the bit 1 to the end of the message | ||
17986 | this._block[this._len % this._blockSize] = 0x80 | ||
17987 | |||
17988 | // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize | ||
17989 | this._block.fill(0, this._len % this._blockSize + 1) | ||
17990 | |||
17991 | if (l % (this._blockSize * 8) >= this._finalSize * 8) { | ||
17992 | this._update(this._block) | ||
17993 | this._block.fill(0) | ||
17994 | } | ||
17995 | |||
17996 | // to this append the block which is equal to the number l written in binary | ||
17997 | // TODO: handle case where l is > Math.pow(2, 29) | ||
17998 | this._block.writeInt32BE(l, this._blockSize - 4) | ||
17999 | |||
18000 | var hash = this._update(this._block) || this._hash() | ||
18001 | |||
18002 | return enc ? hash.toString(enc) : hash | ||
18003 | } | ||
18004 | |||
18005 | Hash.prototype._update = function () { | ||
18006 | throw new Error('_update must be implemented by subclass') | ||
18007 | } | ||
18008 | |||
18009 | module.exports = Hash | ||
18010 | |||
18011 | }).call(this,require("buffer").Buffer) | ||
18012 | },{"buffer":5}],80:[function(require,module,exports){ | ||
18013 | var exports = module.exports = function SHA (algorithm) { | ||
18014 | algorithm = algorithm.toLowerCase() | ||
18015 | |||
18016 | var Algorithm = exports[algorithm] | ||
18017 | if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)') | ||
18018 | |||
18019 | return new Algorithm() | ||
18020 | } | ||
18021 | |||
18022 | exports.sha = require('./sha') | ||
18023 | exports.sha1 = require('./sha1') | ||
18024 | exports.sha224 = require('./sha224') | ||
18025 | exports.sha256 = require('./sha256') | ||
18026 | exports.sha384 = require('./sha384') | ||
18027 | exports.sha512 = require('./sha512') | ||
18028 | |||
18029 | },{"./sha":81,"./sha1":82,"./sha224":83,"./sha256":84,"./sha384":85,"./sha512":86}],81:[function(require,module,exports){ | ||
18030 | (function (Buffer){ | ||
18031 | /* | ||
18032 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined | ||
18033 | * in FIPS PUB 180-1 | ||
18034 | * This source code is derived from sha1.js of the same repository. | ||
18035 | * The difference between SHA-0 and SHA-1 is just a bitwise rotate left | ||
18036 | * operation was added. | ||
18037 | */ | ||
18038 | |||
18039 | var inherits = require('inherits') | ||
18040 | var Hash = require('./hash') | ||
18041 | |||
18042 | var K = [ | ||
18043 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | ||
18044 | ] | ||
18045 | |||
18046 | var W = new Array(80) | ||
18047 | |||
18048 | function Sha () { | ||
18049 | this.init() | ||
18050 | this._w = W | ||
18051 | |||
18052 | Hash.call(this, 64, 56) | ||
18053 | } | ||
18054 | |||
18055 | inherits(Sha, Hash) | ||
18056 | |||
18057 | Sha.prototype.init = function () { | ||
18058 | this._a = 0x67452301 | ||
18059 | this._b = 0xefcdab89 | ||
18060 | this._c = 0x98badcfe | ||
18061 | this._d = 0x10325476 | ||
18062 | this._e = 0xc3d2e1f0 | ||
18063 | |||
18064 | return this | ||
18065 | } | ||
18066 | |||
18067 | function rotl5 (num) { | ||
18068 | return (num << 5) | (num >>> 27) | ||
18069 | } | ||
18070 | |||
18071 | function rotl30 (num) { | ||
18072 | return (num << 30) | (num >>> 2) | ||
18073 | } | ||
18074 | |||
18075 | function ft (s, b, c, d) { | ||
18076 | if (s === 0) return (b & c) | ((~b) & d) | ||
18077 | if (s === 2) return (b & c) | (b & d) | (c & d) | ||
18078 | return b ^ c ^ d | ||
18079 | } | ||
18080 | |||
18081 | Sha.prototype._update = function (M) { | ||
18082 | var W = this._w | ||
18083 | |||
18084 | var a = this._a | 0 | ||
18085 | var b = this._b | 0 | ||
18086 | var c = this._c | 0 | ||
18087 | var d = this._d | 0 | ||
18088 | var e = this._e | 0 | ||
18089 | |||
18090 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
18091 | for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16] | ||
18092 | |||
18093 | for (var j = 0; j < 80; ++j) { | ||
18094 | var s = ~~(j / 20) | ||
18095 | var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 | ||
18096 | |||
18097 | e = d | ||
18098 | d = c | ||
18099 | c = rotl30(b) | ||
18100 | b = a | ||
18101 | a = t | ||
18102 | } | ||
18103 | |||
18104 | this._a = (a + this._a) | 0 | ||
18105 | this._b = (b + this._b) | 0 | ||
18106 | this._c = (c + this._c) | 0 | ||
18107 | this._d = (d + this._d) | 0 | ||
18108 | this._e = (e + this._e) | 0 | ||
18109 | } | ||
18110 | |||
18111 | Sha.prototype._hash = function () { | ||
18112 | var H = new Buffer(20) | ||
18113 | |||
18114 | H.writeInt32BE(this._a | 0, 0) | ||
18115 | H.writeInt32BE(this._b | 0, 4) | ||
18116 | H.writeInt32BE(this._c | 0, 8) | ||
18117 | H.writeInt32BE(this._d | 0, 12) | ||
18118 | H.writeInt32BE(this._e | 0, 16) | ||
18119 | |||
18120 | return H | ||
18121 | } | ||
18122 | |||
18123 | module.exports = Sha | ||
18124 | |||
18125 | }).call(this,require("buffer").Buffer) | ||
18126 | },{"./hash":79,"buffer":5,"inherits":63}],82:[function(require,module,exports){ | ||
18127 | (function (Buffer){ | ||
18128 | /* | ||
18129 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined | ||
18130 | * in FIPS PUB 180-1 | ||
18131 | * Version 2.1a Copyright Paul Johnston 2000 - 2002. | ||
18132 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
18133 | * Distributed under the BSD License | ||
18134 | * See http://pajhome.org.uk/crypt/md5 for details. | ||
18135 | */ | ||
18136 | |||
18137 | var inherits = require('inherits') | ||
18138 | var Hash = require('./hash') | ||
18139 | |||
18140 | var K = [ | ||
18141 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | ||
18142 | ] | ||
18143 | |||
18144 | var W = new Array(80) | ||
18145 | |||
18146 | function Sha1 () { | ||
18147 | this.init() | ||
18148 | this._w = W | ||
18149 | |||
18150 | Hash.call(this, 64, 56) | ||
18151 | } | ||
18152 | |||
18153 | inherits(Sha1, Hash) | ||
18154 | |||
18155 | Sha1.prototype.init = function () { | ||
18156 | this._a = 0x67452301 | ||
18157 | this._b = 0xefcdab89 | ||
18158 | this._c = 0x98badcfe | ||
18159 | this._d = 0x10325476 | ||
18160 | this._e = 0xc3d2e1f0 | ||
18161 | |||
18162 | return this | ||
18163 | } | ||
18164 | |||
18165 | function rotl1 (num) { | ||
18166 | return (num << 1) | (num >>> 31) | ||
18167 | } | ||
18168 | |||
18169 | function rotl5 (num) { | ||
18170 | return (num << 5) | (num >>> 27) | ||
18171 | } | ||
18172 | |||
18173 | function rotl30 (num) { | ||
18174 | return (num << 30) | (num >>> 2) | ||
18175 | } | ||
18176 | |||
18177 | function ft (s, b, c, d) { | ||
18178 | if (s === 0) return (b & c) | ((~b) & d) | ||
18179 | if (s === 2) return (b & c) | (b & d) | (c & d) | ||
18180 | return b ^ c ^ d | ||
18181 | } | ||
18182 | |||
18183 | Sha1.prototype._update = function (M) { | ||
18184 | var W = this._w | ||
18185 | |||
18186 | var a = this._a | 0 | ||
18187 | var b = this._b | 0 | ||
18188 | var c = this._c | 0 | ||
18189 | var d = this._d | 0 | ||
18190 | var e = this._e | 0 | ||
18191 | |||
18192 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
18193 | for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]) | ||
18194 | |||
18195 | for (var j = 0; j < 80; ++j) { | ||
18196 | var s = ~~(j / 20) | ||
18197 | var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 | ||
18198 | |||
18199 | e = d | ||
18200 | d = c | ||
18201 | c = rotl30(b) | ||
18202 | b = a | ||
18203 | a = t | ||
18204 | } | ||
18205 | |||
18206 | this._a = (a + this._a) | 0 | ||
18207 | this._b = (b + this._b) | 0 | ||
18208 | this._c = (c + this._c) | 0 | ||
18209 | this._d = (d + this._d) | 0 | ||
18210 | this._e = (e + this._e) | 0 | ||
18211 | } | ||
18212 | |||
18213 | Sha1.prototype._hash = function () { | ||
18214 | var H = new Buffer(20) | ||
18215 | |||
18216 | H.writeInt32BE(this._a | 0, 0) | ||
18217 | H.writeInt32BE(this._b | 0, 4) | ||
18218 | H.writeInt32BE(this._c | 0, 8) | ||
18219 | H.writeInt32BE(this._d | 0, 12) | ||
18220 | H.writeInt32BE(this._e | 0, 16) | ||
18221 | |||
18222 | return H | ||
18223 | } | ||
18224 | |||
18225 | module.exports = Sha1 | ||
18226 | |||
18227 | }).call(this,require("buffer").Buffer) | ||
18228 | },{"./hash":79,"buffer":5,"inherits":63}],83:[function(require,module,exports){ | ||
18229 | (function (Buffer){ | ||
18230 | /** | ||
18231 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | ||
18232 | * in FIPS 180-2 | ||
18233 | * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. | ||
18234 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
18235 | * | ||
18236 | */ | ||
18237 | |||
18238 | var inherits = require('inherits') | ||
18239 | var Sha256 = require('./sha256') | ||
18240 | var Hash = require('./hash') | ||
18241 | |||
18242 | var W = new Array(64) | ||
18243 | |||
18244 | function Sha224 () { | ||
18245 | this.init() | ||
18246 | |||
18247 | this._w = W // new Array(64) | ||
18248 | |||
18249 | Hash.call(this, 64, 56) | ||
18250 | } | ||
18251 | |||
18252 | inherits(Sha224, Sha256) | ||
18253 | |||
18254 | Sha224.prototype.init = function () { | ||
18255 | this._a = 0xc1059ed8 | ||
18256 | this._b = 0x367cd507 | ||
18257 | this._c = 0x3070dd17 | ||
18258 | this._d = 0xf70e5939 | ||
18259 | this._e = 0xffc00b31 | ||
18260 | this._f = 0x68581511 | ||
18261 | this._g = 0x64f98fa7 | ||
18262 | this._h = 0xbefa4fa4 | ||
18263 | |||
18264 | return this | ||
18265 | } | ||
18266 | |||
18267 | Sha224.prototype._hash = function () { | ||
18268 | var H = new Buffer(28) | ||
18269 | |||
18270 | H.writeInt32BE(this._a, 0) | ||
18271 | H.writeInt32BE(this._b, 4) | ||
18272 | H.writeInt32BE(this._c, 8) | ||
18273 | H.writeInt32BE(this._d, 12) | ||
18274 | H.writeInt32BE(this._e, 16) | ||
18275 | H.writeInt32BE(this._f, 20) | ||
18276 | H.writeInt32BE(this._g, 24) | ||
18277 | |||
18278 | return H | ||
18279 | } | ||
18280 | |||
18281 | module.exports = Sha224 | ||
18282 | |||
18283 | }).call(this,require("buffer").Buffer) | ||
18284 | },{"./hash":79,"./sha256":84,"buffer":5,"inherits":63}],84:[function(require,module,exports){ | ||
18285 | (function (Buffer){ | ||
18286 | /** | ||
18287 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | ||
18288 | * in FIPS 180-2 | ||
18289 | * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. | ||
18290 | * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | ||
18291 | * | ||
18292 | */ | ||
18293 | |||
18294 | var inherits = require('inherits') | ||
18295 | var Hash = require('./hash') | ||
18296 | |||
18297 | var K = [ | ||
18298 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, | ||
18299 | 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, | ||
18300 | 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, | ||
18301 | 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, | ||
18302 | 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, | ||
18303 | 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, | ||
18304 | 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, | ||
18305 | 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, | ||
18306 | 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, | ||
18307 | 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, | ||
18308 | 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, | ||
18309 | 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, | ||
18310 | 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, | ||
18311 | 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, | ||
18312 | 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, | ||
18313 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 | ||
18314 | ] | ||
18315 | |||
18316 | var W = new Array(64) | ||
18317 | |||
18318 | function Sha256 () { | ||
18319 | this.init() | ||
18320 | |||
18321 | this._w = W // new Array(64) | ||
18322 | |||
18323 | Hash.call(this, 64, 56) | ||
18324 | } | ||
18325 | |||
18326 | inherits(Sha256, Hash) | ||
18327 | |||
18328 | Sha256.prototype.init = function () { | ||
18329 | this._a = 0x6a09e667 | ||
18330 | this._b = 0xbb67ae85 | ||
18331 | this._c = 0x3c6ef372 | ||
18332 | this._d = 0xa54ff53a | ||
18333 | this._e = 0x510e527f | ||
18334 | this._f = 0x9b05688c | ||
18335 | this._g = 0x1f83d9ab | ||
18336 | this._h = 0x5be0cd19 | ||
18337 | |||
18338 | return this | ||
18339 | } | ||
18340 | |||
18341 | function ch (x, y, z) { | ||
18342 | return z ^ (x & (y ^ z)) | ||
18343 | } | ||
18344 | |||
18345 | function maj (x, y, z) { | ||
18346 | return (x & y) | (z & (x | y)) | ||
18347 | } | ||
18348 | |||
18349 | function sigma0 (x) { | ||
18350 | return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10) | ||
18351 | } | ||
18352 | |||
18353 | function sigma1 (x) { | ||
18354 | return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7) | ||
18355 | } | ||
18356 | |||
18357 | function gamma0 (x) { | ||
18358 | return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3) | ||
18359 | } | ||
18360 | |||
18361 | function gamma1 (x) { | ||
18362 | return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10) | ||
18363 | } | ||
18364 | |||
18365 | Sha256.prototype._update = function (M) { | ||
18366 | var W = this._w | ||
18367 | |||
18368 | var a = this._a | 0 | ||
18369 | var b = this._b | 0 | ||
18370 | var c = this._c | 0 | ||
18371 | var d = this._d | 0 | ||
18372 | var e = this._e | 0 | ||
18373 | var f = this._f | 0 | ||
18374 | var g = this._g | 0 | ||
18375 | var h = this._h | 0 | ||
18376 | |||
18377 | for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) | ||
18378 | for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0 | ||
18379 | |||
18380 | for (var j = 0; j < 64; ++j) { | ||
18381 | var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0 | ||
18382 | var T2 = (sigma0(a) + maj(a, b, c)) | 0 | ||
18383 | |||
18384 | h = g | ||
18385 | g = f | ||
18386 | f = e | ||
18387 | e = (d + T1) | 0 | ||
18388 | d = c | ||
18389 | c = b | ||
18390 | b = a | ||
18391 | a = (T1 + T2) | 0 | ||
18392 | } | ||
18393 | |||
18394 | this._a = (a + this._a) | 0 | ||
18395 | this._b = (b + this._b) | 0 | ||
18396 | this._c = (c + this._c) | 0 | ||
18397 | this._d = (d + this._d) | 0 | ||
18398 | this._e = (e + this._e) | 0 | ||
18399 | this._f = (f + this._f) | 0 | ||
18400 | this._g = (g + this._g) | 0 | ||
18401 | this._h = (h + this._h) | 0 | ||
18402 | } | ||
18403 | |||
18404 | Sha256.prototype._hash = function () { | ||
18405 | var H = new Buffer(32) | ||
18406 | |||
18407 | H.writeInt32BE(this._a, 0) | ||
18408 | H.writeInt32BE(this._b, 4) | ||
18409 | H.writeInt32BE(this._c, 8) | ||
18410 | H.writeInt32BE(this._d, 12) | ||
18411 | H.writeInt32BE(this._e, 16) | ||
18412 | H.writeInt32BE(this._f, 20) | ||
18413 | H.writeInt32BE(this._g, 24) | ||
18414 | H.writeInt32BE(this._h, 28) | ||
18415 | |||
18416 | return H | ||
18417 | } | ||
18418 | |||
18419 | module.exports = Sha256 | ||
18420 | |||
18421 | }).call(this,require("buffer").Buffer) | ||
18422 | },{"./hash":79,"buffer":5,"inherits":63}],85:[function(require,module,exports){ | ||
18423 | (function (Buffer){ | ||
18424 | var inherits = require('inherits') | ||
18425 | var SHA512 = require('./sha512') | ||
18426 | var Hash = require('./hash') | ||
18427 | |||
18428 | var W = new Array(160) | ||
18429 | |||
18430 | function Sha384 () { | ||
18431 | this.init() | ||
18432 | this._w = W | ||
18433 | |||
18434 | Hash.call(this, 128, 112) | ||
18435 | } | ||
18436 | |||
18437 | inherits(Sha384, SHA512) | ||
18438 | |||
18439 | Sha384.prototype.init = function () { | ||
18440 | this._ah = 0xcbbb9d5d | ||
18441 | this._bh = 0x629a292a | ||
18442 | this._ch = 0x9159015a | ||
18443 | this._dh = 0x152fecd8 | ||
18444 | this._eh = 0x67332667 | ||
18445 | this._fh = 0x8eb44a87 | ||
18446 | this._gh = 0xdb0c2e0d | ||
18447 | this._hh = 0x47b5481d | ||
18448 | |||
18449 | this._al = 0xc1059ed8 | ||
18450 | this._bl = 0x367cd507 | ||
18451 | this._cl = 0x3070dd17 | ||
18452 | this._dl = 0xf70e5939 | ||
18453 | this._el = 0xffc00b31 | ||
18454 | this._fl = 0x68581511 | ||
18455 | this._gl = 0x64f98fa7 | ||
18456 | this._hl = 0xbefa4fa4 | ||
18457 | |||
18458 | return this | ||
18459 | } | ||
18460 | |||
18461 | Sha384.prototype._hash = function () { | ||
18462 | var H = new Buffer(48) | ||
18463 | |||
18464 | function writeInt64BE (h, l, offset) { | ||
18465 | H.writeInt32BE(h, offset) | ||
18466 | H.writeInt32BE(l, offset + 4) | ||
18467 | } | ||
18468 | |||
18469 | writeInt64BE(this._ah, this._al, 0) | ||
18470 | writeInt64BE(this._bh, this._bl, 8) | ||
18471 | writeInt64BE(this._ch, this._cl, 16) | ||
18472 | writeInt64BE(this._dh, this._dl, 24) | ||
18473 | writeInt64BE(this._eh, this._el, 32) | ||
18474 | writeInt64BE(this._fh, this._fl, 40) | ||
18475 | |||
18476 | return H | ||
18477 | } | ||
18478 | |||
18479 | module.exports = Sha384 | ||
18480 | |||
18481 | }).call(this,require("buffer").Buffer) | ||
18482 | },{"./hash":79,"./sha512":86,"buffer":5,"inherits":63}],86:[function(require,module,exports){ | ||
18483 | (function (Buffer){ | ||
18484 | var inherits = require('inherits') | ||
18485 | var Hash = require('./hash') | ||
18486 | |||
18487 | var K = [ | ||
18488 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, | ||
18489 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, | ||
18490 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, | ||
18491 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, | ||
18492 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, | ||
18493 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, | ||
18494 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, | ||
18495 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, | ||
18496 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, | ||
18497 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, | ||
18498 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, | ||
18499 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, | ||
18500 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, | ||
18501 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, | ||
18502 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, | ||
18503 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, | ||
18504 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, | ||
18505 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, | ||
18506 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, | ||
18507 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, | ||
18508 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, | ||
18509 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, | ||
18510 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, | ||
18511 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, | ||
18512 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, | ||
18513 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, | ||
18514 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, | ||
18515 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, | ||
18516 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, | ||
18517 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, | ||
18518 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, | ||
18519 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, | ||
18520 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, | ||
18521 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, | ||
18522 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, | ||
18523 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, | ||
18524 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, | ||
18525 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, | ||
18526 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, | ||
18527 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 | ||
18528 | ] | ||
18529 | |||
18530 | var W = new Array(160) | ||
18531 | |||
18532 | function Sha512 () { | ||
18533 | this.init() | ||
18534 | this._w = W | ||
18535 | |||
18536 | Hash.call(this, 128, 112) | ||
18537 | } | ||
18538 | |||
18539 | inherits(Sha512, Hash) | ||
18540 | |||
18541 | Sha512.prototype.init = function () { | ||
18542 | this._ah = 0x6a09e667 | ||
18543 | this._bh = 0xbb67ae85 | ||
18544 | this._ch = 0x3c6ef372 | ||
18545 | this._dh = 0xa54ff53a | ||
18546 | this._eh = 0x510e527f | ||
18547 | this._fh = 0x9b05688c | ||
18548 | this._gh = 0x1f83d9ab | ||
18549 | this._hh = 0x5be0cd19 | ||
18550 | |||
18551 | this._al = 0xf3bcc908 | ||
18552 | this._bl = 0x84caa73b | ||
18553 | this._cl = 0xfe94f82b | ||
18554 | this._dl = 0x5f1d36f1 | ||
18555 | this._el = 0xade682d1 | ||
18556 | this._fl = 0x2b3e6c1f | ||
18557 | this._gl = 0xfb41bd6b | ||
18558 | this._hl = 0x137e2179 | ||
18559 | |||
18560 | return this | ||
18561 | } | ||
18562 | |||
18563 | function Ch (x, y, z) { | ||
18564 | return z ^ (x & (y ^ z)) | ||
18565 | } | ||
18566 | |||
18567 | function maj (x, y, z) { | ||
18568 | return (x & y) | (z & (x | y)) | ||
18569 | } | ||
18570 | |||
18571 | function sigma0 (x, xl) { | ||
18572 | return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25) | ||
18573 | } | ||
18574 | |||
18575 | function sigma1 (x, xl) { | ||
18576 | return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23) | ||
18577 | } | ||
18578 | |||
18579 | function Gamma0 (x, xl) { | ||
18580 | return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7) | ||
18581 | } | ||
18582 | |||
18583 | function Gamma0l (x, xl) { | ||
18584 | return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25) | ||
18585 | } | ||
18586 | |||
18587 | function Gamma1 (x, xl) { | ||
18588 | return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6) | ||
18589 | } | ||
18590 | |||
18591 | function Gamma1l (x, xl) { | ||
18592 | return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26) | ||
18593 | } | ||
18594 | |||
18595 | function getCarry (a, b) { | ||
18596 | return (a >>> 0) < (b >>> 0) ? 1 : 0 | ||
18597 | } | ||
18598 | |||
18599 | Sha512.prototype._update = function (M) { | ||
18600 | var W = this._w | ||
18601 | |||
18602 | var ah = this._ah | 0 | ||
18603 | var bh = this._bh | 0 | ||
18604 | var ch = this._ch | 0 | ||
18605 | var dh = this._dh | 0 | ||
18606 | var eh = this._eh | 0 | ||
18607 | var fh = this._fh | 0 | ||
18608 | var gh = this._gh | 0 | ||
18609 | var hh = this._hh | 0 | ||
18610 | |||
18611 | var al = this._al | 0 | ||
18612 | var bl = this._bl | 0 | ||
18613 | var cl = this._cl | 0 | ||
18614 | var dl = this._dl | 0 | ||
18615 | var el = this._el | 0 | ||
18616 | var fl = this._fl | 0 | ||
18617 | var gl = this._gl | 0 | ||
18618 | var hl = this._hl | 0 | ||
18619 | |||
18620 | for (var i = 0; i < 32; i += 2) { | ||
18621 | W[i] = M.readInt32BE(i * 4) | ||
18622 | W[i + 1] = M.readInt32BE(i * 4 + 4) | ||
18623 | } | ||
18624 | for (; i < 160; i += 2) { | ||
18625 | var xh = W[i - 15 * 2] | ||
18626 | var xl = W[i - 15 * 2 + 1] | ||
18627 | var gamma0 = Gamma0(xh, xl) | ||
18628 | var gamma0l = Gamma0l(xl, xh) | ||
18629 | |||
18630 | xh = W[i - 2 * 2] | ||
18631 | xl = W[i - 2 * 2 + 1] | ||
18632 | var gamma1 = Gamma1(xh, xl) | ||
18633 | var gamma1l = Gamma1l(xl, xh) | ||
18634 | |||
18635 | // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] | ||
18636 | var Wi7h = W[i - 7 * 2] | ||
18637 | var Wi7l = W[i - 7 * 2 + 1] | ||
18638 | |||
18639 | var Wi16h = W[i - 16 * 2] | ||
18640 | var Wi16l = W[i - 16 * 2 + 1] | ||
18641 | |||
18642 | var Wil = (gamma0l + Wi7l) | 0 | ||
18643 | var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0 | ||
18644 | Wil = (Wil + gamma1l) | 0 | ||
18645 | Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0 | ||
18646 | Wil = (Wil + Wi16l) | 0 | ||
18647 | Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0 | ||
18648 | |||
18649 | W[i] = Wih | ||
18650 | W[i + 1] = Wil | ||
18651 | } | ||
18652 | |||
18653 | for (var j = 0; j < 160; j += 2) { | ||
18654 | Wih = W[j] | ||
18655 | Wil = W[j + 1] | ||
18656 | |||
18657 | var majh = maj(ah, bh, ch) | ||
18658 | var majl = maj(al, bl, cl) | ||
18659 | |||
18660 | var sigma0h = sigma0(ah, al) | ||
18661 | var sigma0l = sigma0(al, ah) | ||
18662 | var sigma1h = sigma1(eh, el) | ||
18663 | var sigma1l = sigma1(el, eh) | ||
18664 | |||
18665 | // t1 = h + sigma1 + ch + K[j] + W[j] | ||
18666 | var Kih = K[j] | ||
18667 | var Kil = K[j + 1] | ||
18668 | |||
18669 | var chh = Ch(eh, fh, gh) | ||
18670 | var chl = Ch(el, fl, gl) | ||
18671 | |||
18672 | var t1l = (hl + sigma1l) | 0 | ||
18673 | var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0 | ||
18674 | t1l = (t1l + chl) | 0 | ||
18675 | t1h = (t1h + chh + getCarry(t1l, chl)) | 0 | ||
18676 | t1l = (t1l + Kil) | 0 | ||
18677 | t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0 | ||
18678 | t1l = (t1l + Wil) | 0 | ||
18679 | t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0 | ||
18680 | |||
18681 | // t2 = sigma0 + maj | ||
18682 | var t2l = (sigma0l + majl) | 0 | ||
18683 | var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0 | ||
18684 | |||
18685 | hh = gh | ||
18686 | hl = gl | ||
18687 | gh = fh | ||
18688 | gl = fl | ||
18689 | fh = eh | ||
18690 | fl = el | ||
18691 | el = (dl + t1l) | 0 | ||
18692 | eh = (dh + t1h + getCarry(el, dl)) | 0 | ||
18693 | dh = ch | ||
18694 | dl = cl | ||
18695 | ch = bh | ||
18696 | cl = bl | ||
18697 | bh = ah | ||
18698 | bl = al | ||
18699 | al = (t1l + t2l) | 0 | ||
18700 | ah = (t1h + t2h + getCarry(al, t1l)) | 0 | ||
18701 | } | ||
18702 | |||
18703 | this._al = (this._al + al) | 0 | ||
18704 | this._bl = (this._bl + bl) | 0 | ||
18705 | this._cl = (this._cl + cl) | 0 | ||
18706 | this._dl = (this._dl + dl) | 0 | ||
18707 | this._el = (this._el + el) | 0 | ||
18708 | this._fl = (this._fl + fl) | 0 | ||
18709 | this._gl = (this._gl + gl) | 0 | ||
18710 | this._hl = (this._hl + hl) | 0 | ||
18711 | |||
18712 | this._ah = (this._ah + ah + getCarry(this._al, al)) | 0 | ||
18713 | this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0 | ||
18714 | this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0 | ||
18715 | this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0 | ||
18716 | this._eh = (this._eh + eh + getCarry(this._el, el)) | 0 | ||
18717 | this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0 | ||
18718 | this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0 | ||
18719 | this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0 | ||
18720 | } | ||
18721 | |||
18722 | Sha512.prototype._hash = function () { | ||
18723 | var H = new Buffer(64) | ||
18724 | |||
18725 | function writeInt64BE (h, l, offset) { | ||
18726 | H.writeInt32BE(h, offset) | ||
18727 | H.writeInt32BE(l, offset + 4) | ||
18728 | } | ||
18729 | |||
18730 | writeInt64BE(this._ah, this._al, 0) | ||
18731 | writeInt64BE(this._bh, this._bl, 8) | ||
18732 | writeInt64BE(this._ch, this._cl, 16) | ||
18733 | writeInt64BE(this._dh, this._dl, 24) | ||
18734 | writeInt64BE(this._eh, this._el, 32) | ||
18735 | writeInt64BE(this._fh, this._fl, 40) | ||
18736 | writeInt64BE(this._gh, this._gl, 48) | ||
18737 | writeInt64BE(this._hh, this._hl, 56) | ||
18738 | |||
18739 | return H | ||
18740 | } | ||
18741 | |||
18742 | module.exports = Sha512 | ||
18743 | |||
18744 | }).call(this,require("buffer").Buffer) | ||
18745 | },{"./hash":79,"buffer":5,"inherits":63}],87:[function(require,module,exports){ | ||
18746 | var isHexPrefixed = require('is-hex-prefixed'); | ||
18747 | |||
18748 | /** | ||
18749 | * Removes '0x' from a given `String` is present | ||
18750 | * @param {String} str the string value | ||
18751 | * @return {String|Optional} a string by pass if necessary | ||
18752 | */ | ||
18753 | module.exports = function stripHexPrefix(str) { | ||
18754 | if (typeof str !== 'string') { | ||
18755 | return str; | ||
18756 | } | ||
18757 | |||
18758 | return isHexPrefixed(str) ? str.slice(2) : str; | ||
18759 | } | ||
18760 | |||
18761 | },{"is-hex-prefixed":64}]},{},[31])(31) | ||
18762 | }); \ No newline at end of file | ||
diff --git a/src/js/index.js b/src/js/index.js index c3c0a4a..c4d99af 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | var DOM = {}; | 24 | var DOM = {}; |
25 | DOM.network = $(".network"); | 25 | DOM.network = $(".network"); |
26 | DOM.bip32Client = $("#bip32-client"); | ||
26 | DOM.phraseNetwork = $("#network-phrase"); | 27 | DOM.phraseNetwork = $("#network-phrase"); |
27 | DOM.useEntropy = $(".use-entropy"); | 28 | DOM.useEntropy = $(".use-entropy"); |
28 | DOM.entropyContainer = $(".entropy-container"); | 29 | DOM.entropyContainer = $(".entropy-container"); |
@@ -77,6 +78,7 @@ | |||
77 | function init() { | 78 | function init() { |
78 | // Events | 79 | // Events |
79 | DOM.network.on("change", networkChanged); | 80 | DOM.network.on("change", networkChanged); |
81 | DOM.bip32Client.on("change", bip32ClientChanged); | ||
80 | DOM.useEntropy.on("change", setEntropyVisibility); | 82 | DOM.useEntropy.on("change", setEntropyVisibility); |
81 | DOM.entropy.on("input", delayedEntropyChanged); | 83 | DOM.entropy.on("input", delayedEntropyChanged); |
82 | DOM.entropyMnemonicLength.on("change", entropyChanged); | 84 | DOM.entropyMnemonicLength.on("change", entropyChanged); |
@@ -102,6 +104,7 @@ | |||
102 | hidePending(); | 104 | hidePending(); |
103 | hideValidationError(); | 105 | hideValidationError(); |
104 | populateNetworkSelect(); | 106 | populateNetworkSelect(); |
107 | populateClientSelect(); | ||
105 | } | 108 | } |
106 | 109 | ||
107 | // Event handlers | 110 | // Event handlers |
@@ -117,6 +120,23 @@ | |||
117 | } | 120 | } |
118 | } | 121 | } |
119 | 122 | ||
123 | function bip32ClientChanged(e) { | ||
124 | var clientIndex = DOM.bip32Client.val(); | ||
125 | if (clientIndex == "custom") { | ||
126 | DOM.bip32path.prop("readonly", false); | ||
127 | } | ||
128 | else { | ||
129 | DOM.bip32path.prop("readonly", true); | ||
130 | clients[clientIndex].onSelect(); | ||
131 | if (seed != null) { | ||
132 | phraseChanged(); | ||
133 | } | ||
134 | else { | ||
135 | rootKeyChanged(); | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
120 | function setEntropyVisibility() { | 140 | function setEntropyVisibility() { |
121 | if (isUsingOwnEntropy()) { | 141 | if (isUsingOwnEntropy()) { |
122 | DOM.entropyContainer.removeClass("hidden"); | 142 | DOM.entropyContainer.removeClass("hidden"); |
@@ -564,6 +584,20 @@ | |||
564 | if (useHardenedAddresses) { | 584 | if (useHardenedAddresses) { |
565 | indexText = indexText + "'"; | 585 | indexText = indexText + "'"; |
566 | } | 586 | } |
587 | // Ethereum values are different | ||
588 | if (networks[DOM.network.val()].name == "Ethereum") { | ||
589 | var privKeyBuffer = key.privKey.d.toBuffer(); | ||
590 | privkey = privKeyBuffer.toString('hex'); | ||
591 | var addressBuffer = ethUtil.privateToAddress(privKeyBuffer); | ||
592 | var hexAddress = addressBuffer.toString('hex'); | ||
593 | var checksumAddress = ethUtil.toChecksumAddress(hexAddress); | ||
594 | address = ethUtil.addHexPrefix(checksumAddress); | ||
595 | } | ||
596 | // Ripple values are different | ||
597 | if (networks[DOM.network.val()].name == "Ripple") { | ||
598 | privkey = convertRipplePriv(privkey); | ||
599 | address = convertRippleAdrr(address); | ||
600 | } | ||
567 | addAddressToList(indexText, address, pubkey, privkey); | 601 | addAddressToList(indexText, address, pubkey, privkey); |
568 | }, 50) | 602 | }, 50) |
569 | } | 603 | } |
@@ -702,6 +736,16 @@ | |||
702 | } | 736 | } |
703 | } | 737 | } |
704 | 738 | ||
739 | function populateClientSelect() { | ||
740 | for (var i=0; i<clients.length; i++) { | ||
741 | var client = clients[i]; | ||
742 | var option = $("<option>"); | ||
743 | option.attr("value", i); | ||
744 | option.text(client.name); | ||
745 | DOM.bip32Client.append(option); | ||
746 | } | ||
747 | } | ||
748 | |||
705 | function getLanguage() { | 749 | function getLanguage() { |
706 | var defaultLanguage = "english"; | 750 | var defaultLanguage = "english"; |
707 | // Try to get from existing phrase | 751 | // Try to get from existing phrase |
@@ -1047,10 +1091,10 @@ | |||
1047 | }, | 1091 | }, |
1048 | }, | 1092 | }, |
1049 | { | 1093 | { |
1050 | name: "Litecoin", | 1094 | name: "CLAM", |
1051 | onSelect: function() { | 1095 | onSelect: function() { |
1052 | network = bitcoin.networks.litecoin; | 1096 | network = bitcoin.networks.clam; |
1053 | DOM.bip44coin.val(2); | 1097 | DOM.bip44coin.val(23); |
1054 | }, | 1098 | }, |
1055 | }, | 1099 | }, |
1056 | { | 1100 | { |
@@ -1061,6 +1105,62 @@ | |||
1061 | }, | 1105 | }, |
1062 | }, | 1106 | }, |
1063 | { | 1107 | { |
1108 | name: "DASH", | ||
1109 | onSelect: function() { | ||
1110 | network = bitcoin.networks.dash; | ||
1111 | DOM.bip44coin.val(5); | ||
1112 | }, | ||
1113 | }, | ||
1114 | { | ||
1115 | name: "Ethereum", | ||
1116 | onSelect: function() { | ||
1117 | network = bitcoin.networks.bitcoin; | ||
1118 | DOM.bip44coin.val(60); | ||
1119 | }, | ||
1120 | }, | ||
1121 | { | ||
1122 | name: "GAME", | ||
1123 | onSelect: function() { | ||
1124 | network = bitcoin.networks.game; | ||
1125 | DOM.bip44coin.val(101); | ||
1126 | }, | ||
1127 | }, | ||
1128 | { | ||
1129 | name: "Jumbucks", | ||
1130 | onSelect: function() { | ||
1131 | network = bitcoin.networks.jumbucks; | ||
1132 | DOM.bip44coin.val(26); | ||
1133 | }, | ||
1134 | }, | ||
1135 | { | ||
1136 | name: "Litecoin", | ||
1137 | onSelect: function() { | ||
1138 | network = bitcoin.networks.litecoin; | ||
1139 | DOM.bip44coin.val(2); | ||
1140 | }, | ||
1141 | }, | ||
1142 | { | ||
1143 | name: "Namecoin", | ||
1144 | onSelect: function() { | ||
1145 | network = bitcoin.networks.namecoin; | ||
1146 | DOM.bip44coin.val(7); | ||
1147 | }, | ||
1148 | }, | ||
1149 | { | ||
1150 | name: "Peercoin", | ||
1151 | onSelect: function() { | ||
1152 | network = bitcoin.networks.peercoin; | ||
1153 | DOM.bip44coin.val(6); | ||
1154 | }, | ||
1155 | }, | ||
1156 | { | ||
1157 | name: "Ripple", | ||
1158 | onSelect: function() { | ||
1159 | network = bitcoin.networks.bitcoin; | ||
1160 | DOM.bip44coin.val(144); | ||
1161 | }, | ||
1162 | }, | ||
1163 | { | ||
1064 | name: "ShadowCash", | 1164 | name: "ShadowCash", |
1065 | onSelect: function() { | 1165 | onSelect: function() { |
1066 | network = bitcoin.networks.shadow; | 1166 | network = bitcoin.networks.shadow; |
@@ -1088,41 +1188,30 @@ | |||
1088 | DOM.bip44coin.val(1); | 1188 | DOM.bip44coin.val(1); |
1089 | }, | 1189 | }, |
1090 | }, | 1190 | }, |
1191 | ] | ||
1192 | |||
1193 | var clients = [ | ||
1091 | { | 1194 | { |
1092 | name: "Jumbucks", | 1195 | name: "Bitcoin Core", |
1093 | onSelect: function() { | ||
1094 | network = bitcoin.networks.jumbucks; | ||
1095 | DOM.bip44coin.val(26); | ||
1096 | }, | ||
1097 | }, | ||
1098 | { | ||
1099 | name: "CLAM", | ||
1100 | onSelect: function() { | ||
1101 | network = bitcoin.networks.clam; | ||
1102 | DOM.bip44coin.val(23); | ||
1103 | }, | ||
1104 | }, | ||
1105 | { | ||
1106 | name: "DASH", | ||
1107 | onSelect: function() { | 1196 | onSelect: function() { |
1108 | network = bitcoin.networks.dash; | 1197 | DOM.bip32path.val("m/0'/0'"); |
1109 | DOM.bip44coin.val(5); | 1198 | DOM.hardenedAddresses.prop('checked', true); |
1110 | }, | 1199 | }, |
1111 | }, | 1200 | }, |
1112 | { | 1201 | { |
1113 | name: "Namecoin", | 1202 | name: "blockchain.info", |
1114 | onSelect: function() { | 1203 | onSelect: function() { |
1115 | network = bitcoin.networks.namecoin; | 1204 | DOM.bip32path.val("m/44'/0'/0'"); |
1116 | DOM.bip44coin.val(7); | 1205 | DOM.hardenedAddresses.prop('checked', false); |
1117 | }, | 1206 | }, |
1118 | }, | 1207 | }, |
1119 | { | 1208 | { |
1120 | name: "Peercoin", | 1209 | name: "MultiBit HD", |
1121 | onSelect: function() { | 1210 | onSelect: function() { |
1122 | network = bitcoin.networks.peercoin; | 1211 | DOM.bip32path.val("m/0'/0"); |
1123 | DOM.bip44coin.val(6); | 1212 | DOM.hardenedAddresses.prop('checked', false); |
1124 | }, | 1213 | }, |
1125 | }, | 1214 | } |
1126 | ] | 1215 | ] |
1127 | 1216 | ||
1128 | init(); | 1217 | init(); |
diff --git a/src/js/jsbip39.js b/src/js/jsbip39.js index 67ba5a7..025f625 100644 --- a/src/js/jsbip39.js +++ b/src/js/jsbip39.js | |||
@@ -130,10 +130,11 @@ var Mnemonic = function(language) { | |||
130 | 130 | ||
131 | self.toSeed = function(mnemonic, passphrase) { | 131 | self.toSeed = function(mnemonic, passphrase) { |
132 | passphrase = passphrase || ''; | 132 | passphrase = passphrase || ''; |
133 | mnemonic = self.joinWords(self.splitWords(self.normalizeString(mnemonic))); // removes blanks | 133 | mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks |
134 | var mnemonicNormalized = self.normalizeString(mnemonic); | ||
134 | passphrase = self.normalizeString(passphrase) | 135 | passphrase = self.normalizeString(passphrase) |
135 | passphrase = "mnemonic" + passphrase; | 136 | passphrase = "mnemonic" + passphrase; |
136 | var mnemonicBits = sjcl.codec.utf8String.toBits(mnemonic); | 137 | var mnemonicBits = sjcl.codec.utf8String.toBits(mnemonicNormalized); |
137 | var passphraseBits = sjcl.codec.utf8String.toBits(passphrase); | 138 | var passphraseBits = sjcl.codec.utf8String.toBits(passphrase); |
138 | var result = sjcl.misc.pbkdf2(mnemonicBits, passphraseBits, PBKDF2_ROUNDS, 512, hmacSHA512); | 139 | var result = sjcl.misc.pbkdf2(mnemonicBits, passphraseBits, PBKDF2_ROUNDS, 512, hmacSHA512); |
139 | var hashHex = sjcl.codec.hex.fromBits(result); | 140 | var hashHex = sjcl.codec.hex.fromBits(result); |
diff --git a/src/js/polyfill.es6.js b/src/js/polyfill.es6.js new file mode 100644 index 0000000..be05249 --- /dev/null +++ b/src/js/polyfill.es6.js | |||
@@ -0,0 +1,3793 @@ | |||
1 | // From | ||
2 | // https://raw.githubusercontent.com/inexorabletash/polyfill/a6bc6ced78160c994f76a909b6ff6bbbab3d43de/es6.js | ||
3 | // Required for ethereumjs-utils.js when run in phantomjs-2.1.1 | ||
4 | // but is not required in any modern browsers. | ||
5 | // For more information, see | ||
6 | // https://www.bountysource.com/issues/38485709-error-rendering-plot-with-phantomjs | ||
7 | |||
8 | //---------------------------------------------------------------------- | ||
9 | // | ||
10 | // ECMAScript 2015 Polyfills | ||
11 | // | ||
12 | //---------------------------------------------------------------------- | ||
13 | |||
14 | (function (global) { | ||
15 | "use strict"; | ||
16 | |||
17 | // Set this to always override native implementations, for testing | ||
18 | // the polyfill in browsers with partial/full ES2015 support. | ||
19 | var OVERRIDE_NATIVE_FOR_TESTING = false; | ||
20 | |||
21 | var undefined = (void 0); // Paranoia | ||
22 | |||
23 | // Helpers | ||
24 | |||
25 | function strict(o) { | ||
26 | return o === global ? undefined : o; | ||
27 | } | ||
28 | |||
29 | function hook(o, p, f) { | ||
30 | var op = o[p]; | ||
31 | console.assert(typeof op === 'function', 'Hooking a non-function'); | ||
32 | o[p] = function() { | ||
33 | var o = strict(this); | ||
34 | var r = f.apply(o, arguments); | ||
35 | return r !== undefined ? r : op.apply(o, arguments); | ||
36 | }; | ||
37 | } | ||
38 | |||
39 | function isSymbol(s) { | ||
40 | return (typeof s === 'symbol') || ('Symbol' in global && s instanceof global.Symbol); | ||
41 | } | ||
42 | |||
43 | function getPropertyDescriptor(target, name) { | ||
44 | var desc = Object.getOwnPropertyDescriptor(target, name); | ||
45 | var proto = Object.getPrototypeOf(target); | ||
46 | while (!desc && proto) { | ||
47 | desc = Object.getOwnPropertyDescriptor(proto, name); | ||
48 | proto = Object.getPrototypeOf(proto); | ||
49 | } | ||
50 | return desc; | ||
51 | } | ||
52 | |||
53 | var enqueue = (function(nativePromise, nativeSetImmediate) { | ||
54 | if (nativePromise) | ||
55 | return function(job) { nativePromise.resolve().then(function() { job(); }); }; | ||
56 | if (nativeSetImmediate) | ||
57 | return function(job) { nativeSetImmediate(job); }; | ||
58 | return function(job) { setTimeout(job, 0); }; | ||
59 | }(global['Promise'], global['setImmediate'])); | ||
60 | |||
61 | function define(o, p, v, override) { | ||
62 | if (p in o && !override && !OVERRIDE_NATIVE_FOR_TESTING) | ||
63 | return; | ||
64 | |||
65 | if (typeof v === 'function') { | ||
66 | // Sanity check that functions are appropriately named (where possible) | ||
67 | console.assert(isSymbol(p) || !('name' in v) || v.name === p || v.name === p + '_', 'Expected function name "' + p.toString() + '", was "' + v.name + '"'); | ||
68 | Object.defineProperty(o, p, { | ||
69 | value: v, | ||
70 | configurable: true, | ||
71 | enumerable: false, | ||
72 | writable: true | ||
73 | }); | ||
74 | } else { | ||
75 | Object.defineProperty(o, p, { | ||
76 | value: v, | ||
77 | configurable: false, | ||
78 | enumerable: false, | ||
79 | writable: false | ||
80 | }); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | function set_internal(o, p, v) { | ||
85 | Object.defineProperty(o, p, { | ||
86 | value: v, | ||
87 | configurable: false, | ||
88 | enumerable: false, | ||
89 | writable: true | ||
90 | }); | ||
91 | } | ||
92 | |||
93 | // Snapshot intrinsic functions | ||
94 | var $isNaN = global.isNaN, | ||
95 | $parseInt = global.parseInt, | ||
96 | $parseFloat = global.parseFloat; | ||
97 | |||
98 | var E = Math.E, | ||
99 | LOG10E = Math.LOG10E, | ||
100 | LOG2E = Math.LOG2E, | ||
101 | abs = Math.abs, | ||
102 | ceil = Math.ceil, | ||
103 | exp = Math.exp, | ||
104 | floor = Math.floor, | ||
105 | log = Math.log, | ||
106 | max = Math.max, | ||
107 | min = Math.min, | ||
108 | pow = Math.pow, | ||
109 | random = Math.random, | ||
110 | sqrt = Math.sqrt; | ||
111 | |||
112 | var orig_match = String.prototype.match, | ||
113 | orig_replace = String.prototype.replace, | ||
114 | orig_search = String.prototype.search, | ||
115 | orig_split = String.prototype.split; | ||
116 | |||
117 | // These are used for implementing the polyfills, but not exported. | ||
118 | |||
119 | // Inspired by https://gist.github.com/1638059 | ||
120 | /** @constructor */ | ||
121 | function EphemeronTable() { | ||
122 | var secretKey = ObjectCreate(null); | ||
123 | |||
124 | function conceal(o) { | ||
125 | var oValueOf = o.valueOf, secrets = ObjectCreate(null); | ||
126 | Object.defineProperty(o, 'valueOf', { | ||
127 | value: (function(secretKey) { | ||
128 | return function (k) { | ||
129 | return (k === secretKey) ? secrets : oValueOf.apply(o, arguments); | ||
130 | }; | ||
131 | }(secretKey)), | ||
132 | configurable: true, | ||
133 | writeable: true, | ||
134 | enumerable: false | ||
135 | }); | ||
136 | return secrets; | ||
137 | } | ||
138 | |||
139 | function reveal(o) { | ||
140 | var v = typeof o.valueOf === 'function' && o.valueOf(secretKey); | ||
141 | return v === o ? null : v; | ||
142 | } | ||
143 | |||
144 | return { | ||
145 | clear: function() { | ||
146 | secretKey = ObjectCreate(null); | ||
147 | }, | ||
148 | remove: function(key) { | ||
149 | var secrets = reveal(key); | ||
150 | if (secrets && HasOwnProperty(secrets, 'value')) { | ||
151 | delete secrets.value; | ||
152 | return true; | ||
153 | } | ||
154 | return false; | ||
155 | }, | ||
156 | get: function(key, defaultValue) { | ||
157 | var secrets = reveal(key); | ||
158 | return (secrets && HasOwnProperty(secrets, 'value')) ? secrets.value : defaultValue; | ||
159 | }, | ||
160 | has: function(key) { | ||
161 | var secrets = reveal(key); | ||
162 | return Boolean(secrets && HasOwnProperty(secrets, 'value')); | ||
163 | }, | ||
164 | set: function(key, value) { | ||
165 | var secrets = reveal(key) || conceal(key); | ||
166 | secrets.value = value; | ||
167 | } | ||
168 | }; | ||
169 | } | ||
170 | |||
171 | var empty = Object.create(null); | ||
172 | |||
173 | //---------------------------------------------------------------------- | ||
174 | // | ||
175 | // ECMAScript 2015 | ||
176 | // http://www.ecma-international.org/ecma-262/6.0/ | ||
177 | // | ||
178 | //---------------------------------------------------------------------- | ||
179 | |||
180 | // --------------------------------------- | ||
181 | // 19.4 Symbol Objects | ||
182 | // --------------------------------------- | ||
183 | |||
184 | // NOTE: Symbols are defined here - out of spec order - since we need the | ||
185 | // properties and prototype to be populated for other polyfills. | ||
186 | |||
187 | // NOTE: Not secure, nor is obj[$$symbol] hidden from Object.keys() | ||
188 | |||
189 | var symbolForKey; | ||
190 | (function() { | ||
191 | var secret = Object.create(null); | ||
192 | var symbolMap = {}; | ||
193 | symbolForKey = function(k) { | ||
194 | return symbolMap[k]; | ||
195 | }; | ||
196 | |||
197 | var GlobalSymbolRegistry = []; | ||
198 | |||
199 | function unique(bits) { | ||
200 | return Array(bits + 1).join('x').replace(/x/g, function() { | ||
201 | return random() < 0.5 ? '\u200C' : '\u200D'; // JWNJ / ZWJ | ||
202 | }); | ||
203 | } | ||
204 | |||
205 | // 19.4.1 The Symbol Constructor | ||
206 | // 19.4.1.1 Symbol ( description=undefined ) | ||
207 | function Symbol(description) { | ||
208 | if (!(this instanceof Symbol)) return new Symbol(description, secret); | ||
209 | if (this instanceof Symbol && arguments[1] !== secret) throw TypeError(); | ||
210 | |||
211 | var descString = description === undefined ? undefined : String(description); | ||
212 | |||
213 | set_internal(this, '[[SymbolData]]', unique(128)); | ||
214 | set_internal(this, '[[Description]]', descString); | ||
215 | |||
216 | symbolMap[this] = this; | ||
217 | return this; | ||
218 | } | ||
219 | |||
220 | if (!('Symbol' in global) || OVERRIDE_NATIVE_FOR_TESTING) | ||
221 | global.Symbol = Symbol; | ||
222 | |||
223 | // 19.4.2 Properties of the Symbol Constructor | ||
224 | |||
225 | // 19.4.2.1 Symbol.for (key) | ||
226 | define(Symbol, 'for', function for_(key) { | ||
227 | var stringKey = String(key); | ||
228 | for (var i = 0; i < GlobalSymbolRegistry.length; ++i) { | ||
229 | var e = GlobalSymbolRegistry[i]; | ||
230 | if (SameValue(e['[[key]]'], stringKey)) return e['[[symbol]]']; | ||
231 | } | ||
232 | var newSymbol = Symbol(key); | ||
233 | GlobalSymbolRegistry.push({'[[key]]': stringKey, '[[symbol]]': newSymbol}); | ||
234 | return newSymbol; | ||
235 | }); | ||
236 | |||
237 | // 19.4.2.2 Symbol.hasInstance | ||
238 | // 19.4.2.3 Symbol.isConcatSpreadable | ||
239 | |||
240 | // 19.4.2.4 Symbol.iterator | ||
241 | define(global.Symbol, 'iterator', global.Symbol('Symbol.iterator')); | ||
242 | |||
243 | // 19.4.2.5 Symbol.keyFor (sym) | ||
244 | define(Symbol, 'keyFor', function keyFor(sym) { | ||
245 | if (!(sym instanceof Symbol)) throw TypeError(); | ||
246 | for (var i = 0; i < GlobalSymbolRegistry.length; ++i) { | ||
247 | var e = GlobalSymbolRegistry[i]; | ||
248 | if (SameValue(e['[[symbol]]'], sym)) return e['[[key]]']; | ||
249 | } | ||
250 | return undefined; | ||
251 | }); | ||
252 | |||
253 | // 19.4.2.6 Symbol.match | ||
254 | define(global.Symbol, 'match', global.Symbol('Symbol.match')); | ||
255 | |||
256 | // 19.4.2.7 Symbol.prototype | ||
257 | |||
258 | // 19.4.2.8 Symbol.replace | ||
259 | define(global.Symbol, 'replace', global.Symbol('Symbol.replace')); | ||
260 | |||
261 | // 19.4.2.9 Symbol.search | ||
262 | define(global.Symbol, 'search', global.Symbol('Symbol.search')); | ||
263 | |||
264 | // 19.4.2.10 Symbol.species | ||
265 | |||
266 | // 19.4.2.11 Symbol.search | ||
267 | define(global.Symbol, 'split', global.Symbol('Symbol.split')); | ||
268 | |||
269 | // 19.4.2.12 Symbol.toPrimitive | ||
270 | |||
271 | // 19.4.2.13 Symbol.toStringTag | ||
272 | define(global.Symbol, 'toStringTag', global.Symbol('Symbol.toStringTag')); | ||
273 | |||
274 | // 19.4.2.14 Symbol.unscopables | ||
275 | |||
276 | // 19.4.3 Properties of the Symbol Prototype Object | ||
277 | // 19.4.3.1 Symbol.prototype.constructor | ||
278 | |||
279 | // 19.4.3.2 Symbol.prototype.toString ( ) | ||
280 | Object.defineProperty(Symbol.prototype, 'toString', { | ||
281 | value: function toString() { | ||
282 | var s = strict(this); | ||
283 | var desc = s['[[Description]]']; | ||
284 | return 'Symbol(' + (desc === undefined ? '' : desc) + s['[[SymbolData]]'] + ')'; | ||
285 | }, | ||
286 | configurable: true, writeable: true, enumerable: false }); | ||
287 | |||
288 | // 19.4.3.3 Symbol.prototype.valueOf ( ) | ||
289 | Object.defineProperty(Symbol.prototype, 'valueOf', { | ||
290 | value: function valueOf() { | ||
291 | // To prevent automatic string conversion: | ||
292 | throw TypeError(); | ||
293 | |||
294 | // Spec has approximately the following: | ||
295 | //var s = strict(this); | ||
296 | //if (Type(s) === 'symbol') return s; | ||
297 | //if (Type(s) !== 'object') throw TypeError(); | ||
298 | //if (!('[[SymbolData]]' in s)) throw TypeError(); | ||
299 | //return s['[[SymbolData]]']; | ||
300 | }, | ||
301 | configurable: true, writeable: true, enumerable: false }); | ||
302 | |||
303 | // 19.4.3.4 Symbol.prototype [ @@toStringTag ] | ||
304 | // (Done later to polyfill partial implementations) | ||
305 | |||
306 | // 19.4.4 Properties of Symbol Instances | ||
307 | }()); | ||
308 | |||
309 | console.assert(typeof global.Symbol() === 'symbol' || symbolForKey(String(global.Symbol('x')))); | ||
310 | |||
311 | // Defined here so that other prototypes can reference it | ||
312 | // 25.1.2 The %IteratorPrototype% Object | ||
313 | var $IteratorPrototype$ = {}; | ||
314 | |||
315 | //---------------------------------------- | ||
316 | // 6 ECMAScript Data Types and Values | ||
317 | //---------------------------------------- | ||
318 | |||
319 | // 6.1 ECMAScript Language Types | ||
320 | |||
321 | // "Type(x)" is used as shorthand for "the type of x"... | ||
322 | function Type(v) { | ||
323 | switch (typeof v) { | ||
324 | case 'undefined': return 'undefined'; | ||
325 | case 'boolean': return 'boolean'; | ||
326 | case 'number': return 'number'; | ||
327 | case 'string': return 'string'; | ||
328 | case 'symbol': return 'symbol'; | ||
329 | default: | ||
330 | if (v === null) return 'null'; | ||
331 | if (v instanceof global.Symbol) return 'symbol'; | ||
332 | return 'object'; | ||
333 | } | ||
334 | } | ||
335 | |||
336 | // 6.1.5.1 Well-Known Symbols | ||
337 | var $$iterator = global.Symbol.iterator, | ||
338 | $$match = global.Symbol.match, | ||
339 | $$replace = global.Symbol.replace, | ||
340 | $$search = global.Symbol.search, | ||
341 | $$split = global.Symbol.split, | ||
342 | $$toStringTag = global.Symbol.toStringTag; | ||
343 | |||
344 | //---------------------------------------- | ||
345 | // 7 Abstract Operations | ||
346 | //---------------------------------------- | ||
347 | |||
348 | //---------------------------------------- | ||
349 | // 7.1 Type Conversion | ||
350 | //---------------------------------------- | ||
351 | |||
352 | // 7.1.1 ToPrimitive ( input [, PreferredType] ) | ||
353 | // just use valueOf() | ||
354 | |||
355 | // 7.1.2 ToBoolean ( argument ) | ||
356 | // just use Boolean() | ||
357 | |||
358 | // 7.1.3 ToNumber ( argument ) | ||
359 | // just use Number() | ||
360 | |||
361 | // 7.1.4 ToInteger ( argument ) | ||
362 | function ToInteger(n) { | ||
363 | n = Number(n); | ||
364 | if ($isNaN(n)) return 0; | ||
365 | if (n === 0 || n === Infinity || n === -Infinity) return n; | ||
366 | return ((n < 0) ? -1 : 1) * floor(abs(n)); | ||
367 | } | ||
368 | |||
369 | // 7.1.5 ToInt32 ( argument ) | ||
370 | function ToInt32(v) { return v >> 0; } | ||
371 | |||
372 | // 7.1.6 ToUint32 ( argument ) | ||
373 | function ToUint32(v) { return v >>> 0; } | ||
374 | |||
375 | // 7.1.7 ToInt16 ( argument ) | ||
376 | function ToInt16(v) { return (v << 16) >> 16; } | ||
377 | |||
378 | // 7.1.8 ToUint16 ( argument ) | ||
379 | function ToUint16(v) { return v & 0xFFFF; } | ||
380 | |||
381 | // 7.1.9 ToInt8 ( argument ) | ||
382 | function ToInt8(v) { return (v << 24) >> 24; } | ||
383 | |||
384 | // 7.1.10 ToUint8 ( argument ) | ||
385 | function ToUint8(v) { return v & 0xFF; } | ||
386 | |||
387 | // 7.1.11 ToUint8Clamp ( argument ) | ||
388 | function ToUint8Clamp(argument) { | ||
389 | var number = Number(argument); | ||
390 | if ($isNaN(number)) return 0; | ||
391 | if (number <= 0) return 0; | ||
392 | if (number >= 255) return 255; | ||
393 | var f = floor(number); | ||
394 | if ((f + 0.5) < number) return f + 1; | ||
395 | if (number < (f + 0.5)) return f; | ||
396 | if (f % 2) return f + 1; | ||
397 | return f; | ||
398 | } | ||
399 | |||
400 | // 7.1.12 ToString ( argument ) | ||
401 | // just use String() | ||
402 | |||
403 | // 7.1.13 ToObject ( argument ) | ||
404 | function ToObject(v) { | ||
405 | if (v === null || v === undefined) throw TypeError(); | ||
406 | return Object(v); | ||
407 | } | ||
408 | |||
409 | // 7.1.14 ToPropertyKey ( argument ) | ||
410 | function ToPropertyKey(v) { | ||
411 | return String(v); | ||
412 | } | ||
413 | |||
414 | // 7.1.15 ToLength ( argument ) | ||
415 | function ToLength(v) { | ||
416 | var len = ToInteger(v); | ||
417 | if (len <= 0) return 0; | ||
418 | if (len === Infinity) return 0x20000000000000 - 1; // 2^53-1 | ||
419 | return min(len, 0x20000000000000 - 1); // 2^53-1 | ||
420 | } | ||
421 | |||
422 | // 7.1.16 CanonicalNumericIndexString ( argument ) | ||
423 | |||
424 | //---------------------------------------- | ||
425 | // 7.2 Testing and Comparison Operations | ||
426 | //---------------------------------------- | ||
427 | |||
428 | // 7.2.1 RequireObjectCoercible ( argument ) | ||
429 | // 7.2.2 IsArray ( argument ) | ||
430 | |||
431 | // 7.2.3 IsCallable ( argument ) | ||
432 | function IsCallable(o) { return typeof o === 'function'; } | ||
433 | |||
434 | // 7.2.4 IsConstructor ( argument ) | ||
435 | function IsConstructor(o) { | ||
436 | // Hacks for Safari 7 TypedArray XXXConstructor objects | ||
437 | if (/Constructor/.test(Object.prototype.toString.call(o))) return true; | ||
438 | if (/Function/.test(Object.prototype.toString.call(o))) return true; | ||
439 | // TODO: Can this be improved on? | ||
440 | return typeof o === 'function'; | ||
441 | } | ||
442 | |||
443 | // 7.2.5 IsExtensible (O) | ||
444 | // 7.2.6 IsInteger ( argument ) | ||
445 | |||
446 | // 7.2.7 IsPropertyKey ( argument ) | ||
447 | function IsPropertyKey(argument) { | ||
448 | if (Type(argument) === 'string') return true; | ||
449 | if (Type(argument) === 'symbol') return true; | ||
450 | return false; | ||
451 | } | ||
452 | |||
453 | // 7.2.8 IsRegExp ( argument ) | ||
454 | // 7.2.5 IsConstructor ( argument ) | ||
455 | |||
456 | // 7.2.9 SameValue(x, y) | ||
457 | function SameValue(x, y) { | ||
458 | if (typeof x !== typeof y) return false; | ||
459 | switch (typeof x) { | ||
460 | case 'undefined': | ||
461 | return true; | ||
462 | case 'number': | ||
463 | if (x !== x && y !== y) return true; | ||
464 | if (x === 0 && y === 0) return 1/x === 1/y; | ||
465 | return x === y; | ||
466 | case 'boolean': | ||
467 | case 'string': | ||
468 | case 'object': | ||
469 | default: | ||
470 | return x === y; | ||
471 | } | ||
472 | } | ||
473 | |||
474 | // 7.2.10 SameValueZero(x, y) | ||
475 | function SameValueZero(x, y) { | ||
476 | if (typeof x !== typeof y) return false; | ||
477 | switch (typeof x) { | ||
478 | case 'undefined': | ||
479 | return true; | ||
480 | case 'number': | ||
481 | if (x !== x && y !== y) return true; | ||
482 | return x === y; | ||
483 | case 'boolean': | ||
484 | case 'string': | ||
485 | case 'object': | ||
486 | default: | ||
487 | return x === y; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | //---------------------------------------- | ||
492 | // 7.3 Operations on Objects | ||
493 | //---------------------------------------- | ||
494 | |||
495 | // 7.3.1 Get (O, P) | ||
496 | // - just use o.p or o[p] | ||
497 | |||
498 | // 7.3.2 GetV (V, P) | ||
499 | function GetV(v, p) { | ||
500 | var o = ToObject(v); | ||
501 | return o[p]; | ||
502 | } | ||
503 | |||
504 | // 7.3.3 Set (O, P, V, Throw) | ||
505 | // - just use o.p = v or o[p] = v | ||
506 | |||
507 | |||
508 | |||
509 | |||
510 | // 7.3.9 GetMethod (O, P) | ||
511 | function GetMethod(o, p) { | ||
512 | var func = GetV(o, p); | ||
513 | if (func === undefined || func === null) return undefined; | ||
514 | if (!IsCallable(func)) throw TypeError(); | ||
515 | return func; | ||
516 | } | ||
517 | |||
518 | // 7.3.10 HasProperty (O, P) | ||
519 | function HasProperty(o, p) { | ||
520 | while (o) { | ||
521 | if (Object.prototype.hasOwnProperty.call(o, p)) return true; | ||
522 | if (Type(o) !== 'object') return false; | ||
523 | o = Object.getPrototypeOf(o); | ||
524 | } | ||
525 | return false; | ||
526 | } | ||
527 | |||
528 | // 7.3.11 HasOwnProperty (O, P) | ||
529 | function HasOwnProperty(o, p) { | ||
530 | return Object.prototype.hasOwnProperty.call(o, p); | ||
531 | } | ||
532 | |||
533 | //---------------------------------------- | ||
534 | // 7.4 Operations on Iterator Objects | ||
535 | //---------------------------------------- | ||
536 | |||
537 | // 7.4.1 GetIterator ( obj, method ) | ||
538 | function GetIterator(obj, method) { | ||
539 | if (arguments.length < 2) | ||
540 | method = GetMethod(obj, $$iterator); | ||
541 | var iterator = method.call(obj); | ||
542 | if (Type(iterator) !== 'object') throw TypeError(); | ||
543 | return iterator; | ||
544 | } | ||
545 | |||
546 | // 7.4.2 IteratorNext ( iterator, value ) | ||
547 | function IteratorNext(iterator, value) { | ||
548 | if (arguments.length < 2) | ||
549 | var result = iterator.next(); | ||
550 | else | ||
551 | result = iterator.next(value); | ||
552 | if (Type(result) !== 'object') throw TypeError(); | ||
553 | return result; | ||
554 | } | ||
555 | |||
556 | // 7.4.3 IteratorComplete ( iterResult ) | ||
557 | function IteratorComplete(iterResult) { | ||
558 | console.assert(Type(iterResult) === 'object'); | ||
559 | return Boolean(iterResult.done); | ||
560 | } | ||
561 | |||
562 | // 7.4.4 IteratorValue ( iterResult ) | ||
563 | function IteratorValue(iterResult) { | ||
564 | console.assert(Type(iterResult) === 'object'); | ||
565 | return iterResult.value; | ||
566 | } | ||
567 | |||
568 | // 7.4.5 IteratorStep ( iterator ) | ||
569 | function IteratorStep( iterator, value ) { | ||
570 | var result = IteratorNext(iterator, value); | ||
571 | var done = result['done']; | ||
572 | if (Boolean(done) === true) return false; | ||
573 | return result; | ||
574 | } | ||
575 | |||
576 | // 7.4.6 IteratorClose( iterator, completion ) | ||
577 | function IteratorClose( iterator, completion ) { | ||
578 | console.assert(Type(iterator) === 'object'); | ||
579 | var _return = GetMethod(iterator, 'return'); | ||
580 | if (_return === undefined) return completion; | ||
581 | try { | ||
582 | var innerResult = _return[iterator](); | ||
583 | } catch (result) { | ||
584 | // TODO: If completion.[[type]] is throw, return completion | ||
585 | return result; | ||
586 | } | ||
587 | if (Type(innerResult) !== 'object') throw TypeError(); | ||
588 | return completion; | ||
589 | } | ||
590 | |||
591 | // 7.4.7 CreateIterResultObject (value, done) | ||
592 | function CreateIterResultObject(value, done) { | ||
593 | console.assert(Type(done) === 'boolean'); | ||
594 | var obj = {}; | ||
595 | obj["value"] = value; | ||
596 | obj["done"] = done; | ||
597 | return obj; | ||
598 | } | ||
599 | |||
600 | // 7.4.8 CreateListIterator (list) | ||
601 | // 7.4.8.1 ListIterator next( ) | ||
602 | // 7.4.9 CreateCompoundIterator ( iterator1, iterator2 ) | ||
603 | // 7.4.9.1 CompoundIterator next( ) | ||
604 | |||
605 | //---------------------------------------- | ||
606 | // 8 Executable Code and Execution Contexts | ||
607 | //---------------------------------------- | ||
608 | |||
609 | //---------------------------------------- | ||
610 | // 8.4 Jobs and Job Queues | ||
611 | //---------------------------------------- | ||
612 | |||
613 | // 8.4.1 EnqueueJob ( queueName, job, arguments) | ||
614 | function EnqueueJob(queueName, job, args) { | ||
615 | var fn = function() { job.apply(undefined, args); }; | ||
616 | enqueue(fn); | ||
617 | } | ||
618 | |||
619 | // 8.4.2 NextJob result | ||
620 | function NextJob(result) { | ||
621 | // no-op | ||
622 | } | ||
623 | |||
624 | //---------------------------------------- | ||
625 | // 9 Ordinary and Exotic Objects Behaviors | ||
626 | //---------------------------------------- | ||
627 | |||
628 | // 9.1.11 [[Enumerate]] () | ||
629 | function Enumerate(obj) { | ||
630 | var e = []; | ||
631 | if (Object(obj) !== obj) return e; | ||
632 | var visited = new Set; | ||
633 | while (obj !== null) { | ||
634 | Object.getOwnPropertyNames(obj).forEach(function(name) { | ||
635 | if (!visited.has(name)) { | ||
636 | var desc = Object.getOwnPropertyDescriptor(obj, name); | ||
637 | if (desc) { | ||
638 | visited.add(name); | ||
639 | if (desc.enumerable) e.push(name); | ||
640 | } | ||
641 | } | ||
642 | }); | ||
643 | obj = Object.getPrototypeOf(obj); | ||
644 | } | ||
645 | return e[$$iterator](); | ||
646 | } | ||
647 | |||
648 | // 9.1.12 [[OwnPropertyKeys]] ( ) | ||
649 | function OwnPropertyKeys(o) { | ||
650 | return Object.getOwnPropertyNames(o); | ||
651 | } | ||
652 | |||
653 | // 9.1.13 ObjectCreate(proto, internalSlotsList) | ||
654 | function ObjectCreate(proto, internalSlotsList) { | ||
655 | return Object.create(proto, internalSlotsList); | ||
656 | } | ||
657 | |||
658 | // --------------------------------------- | ||
659 | // 19 Fundamental Objects | ||
660 | // --------------------------------------- | ||
661 | |||
662 | // --------------------------------------- | ||
663 | // 19.1 Object Objects | ||
664 | // --------------------------------------- | ||
665 | |||
666 | // 19.1.1 The Object Constructor | ||
667 | // 19.1.1.1 Object ( [ value ] ) | ||
668 | // 19.1.2 Properties of the Object Constructor | ||
669 | // 19.1.2.1 Object.assign ( target, ...sources ) | ||
670 | define( | ||
671 | Object, 'assign', | ||
672 | function assign(target, /*...*/sources) { | ||
673 | var to = ToObject(target); | ||
674 | if (arguments.length < 2) return to; | ||
675 | |||
676 | var sourcesIndex = 1; | ||
677 | while (sourcesIndex < arguments.length) { | ||
678 | var nextSource = arguments[sourcesIndex++]; | ||
679 | if (nextSource === undefined || nextSource === null) { | ||
680 | var keys = []; | ||
681 | } else { | ||
682 | var from = ToObject(nextSource); | ||
683 | keys = OwnPropertyKeys(from); | ||
684 | } | ||
685 | for (var keysIndex = 0; keysIndex < keys.length; ++keysIndex) { | ||
686 | var nextKey = keys[keysIndex]; | ||
687 | var desc = Object.getOwnPropertyDescriptor(from, nextKey); | ||
688 | if (desc !== undefined && desc.enumerable) { | ||
689 | var propValue = from[nextKey]; | ||
690 | to[nextKey] = propValue; | ||
691 | } | ||
692 | } | ||
693 | } | ||
694 | return to; | ||
695 | }); | ||
696 | |||
697 | // 19.1.2.2 Object.create ( O [ , Properties ] ) | ||
698 | // 19.1.2.3 Object.defineProperties ( O, Properties ) | ||
699 | // 19.1.2.4 Object.defineProperty ( O, P, Attributes ) | ||
700 | // 19.1.2.5 Object.freeze ( O ) | ||
701 | // 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) | ||
702 | |||
703 | (function() { | ||
704 | var nativeSymbols = (typeof global.Symbol() === 'symbol'), | ||
705 | $getOwnPropertyNames = Object.getOwnPropertyNames, | ||
706 | $keys = Object.keys, | ||
707 | $window_names = (typeof window === 'object' ? $getOwnPropertyNames(window) : []); | ||
708 | |||
709 | function isStringKey(k) { return !symbolForKey(k); } | ||
710 | |||
711 | // 19.1.2.7 Object.getOwnPropertyNames ( O ) | ||
712 | define( | ||
713 | Object, 'getOwnPropertyNames', | ||
714 | function getOwnPropertyNames(o) { | ||
715 | if (Object.prototype.toString.call(o) === '[object Window]') { | ||
716 | // Workaround for cross-realm calling by IE itself. | ||
717 | // https://github.com/inexorabletash/polyfill/issues/96 | ||
718 | try { | ||
719 | return $getOwnPropertyNames(o).filter(isStringKey); | ||
720 | } catch (_) { | ||
721 | return $window_names.slice(); | ||
722 | } | ||
723 | } | ||
724 | return $getOwnPropertyNames(o).filter(isStringKey); | ||
725 | }, !nativeSymbols); | ||
726 | |||
727 | // 19.1.2.8 Object.getOwnPropertySymbols ( O ) | ||
728 | define( | ||
729 | Object, 'getOwnPropertySymbols', | ||
730 | function getOwnPropertySymbols(o) { | ||
731 | return $getOwnPropertyNames(o).filter(symbolForKey).map(symbolForKey); | ||
732 | }, !nativeSymbols); | ||
733 | |||
734 | // 19.1.2.14 Object.keys ( O ) | ||
735 | define( | ||
736 | Object, 'keys', | ||
737 | function keys(o) { | ||
738 | return $keys(o).filter(isStringKey); | ||
739 | }, !nativeSymbols); | ||
740 | }()); | ||
741 | |||
742 | // 19.1.2.9 Object.getPrototypeOf ( O ) | ||
743 | // 19.1.2.10 Object.is ( value1, value2 ) | ||
744 | define( | ||
745 | Object, 'is', | ||
746 | function is(value1, value2) { | ||
747 | return SameValue(value1, value2); | ||
748 | }); | ||
749 | |||
750 | // 19.1.2.11 Object.isExtensible ( O ) | ||
751 | // 19.1.2.12 Object.isFrozen ( O ) | ||
752 | // 19.1.2.13 Object.isSealed ( O ) | ||
753 | |||
754 | // 19.1.2.14 Object.keys ( O ) | ||
755 | // see above | ||
756 | |||
757 | // 19.1.2.15 Object.preventExtensions ( O ) | ||
758 | // 19.1.2.16 Object.prototype | ||
759 | // 19.1.2.17 Object.seal ( O ) | ||
760 | |||
761 | // 19.1.2.18 Object.setPrototypeOf ( O, proto ) | ||
762 | define( | ||
763 | Object, 'setPrototypeOf', | ||
764 | function setPrototypeOf(o, proto) { | ||
765 | if (Type(o) !== 'object') throw TypeError(); | ||
766 | if (Type(proto) !== 'object' && Type(proto) !== 'null') throw TypeError(); | ||
767 | o.__proto__ = proto; | ||
768 | return o; | ||
769 | } | ||
770 | ); | ||
771 | |||
772 | // 19.1.3 Properties of the Object Prototype Object | ||
773 | // 19.1.3.1 Object.prototype.constructor | ||
774 | // 19.1.3.2 Object.prototype.hasOwnProperty ( V ) | ||
775 | // 19.1.3.3 Object.prototype.isPrototypeOf ( V ) | ||
776 | // 19.1.3.4 Object.prototype.propertyIsEnumerable ( V ) | ||
777 | // 19.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) | ||
778 | // 19.1.3.6 Object.prototype.toString ( ) | ||
779 | hook(Object.prototype, 'toString', | ||
780 | function() { | ||
781 | var o = strict(this); | ||
782 | if (o === Object(o) && $$toStringTag in o) { | ||
783 | return '[object ' + o[$$toStringTag] + ']'; | ||
784 | } | ||
785 | return undefined; | ||
786 | }); | ||
787 | |||
788 | // 19.1.3.7 Object.prototype.valueOf ( ) | ||
789 | // 19.1.4 Properties of Object Instances | ||
790 | |||
791 | // --------------------------------------- | ||
792 | // 19.2 Function Objects | ||
793 | // --------------------------------------- | ||
794 | |||
795 | // 19.2.1 The Function Constructor | ||
796 | // 19.2.1.1 Function ( p1, p2, … , pn, body ) | ||
797 | // 19.2.2 Properties of the Function Constructor | ||
798 | // 19.2.2.1 Function.length | ||
799 | // 19.2.2.2 Function.prototype | ||
800 | // 19.2.3 Properties of the Function Prototype Object | ||
801 | // 19.2.3.1 Function.prototype.apply ( thisArg, argArray ) | ||
802 | // 19.2.3.2 Function.prototype.bind ( thisArg , ...args) | ||
803 | // 19.2.3.3 Function.prototype.call (thisArg , ...args) | ||
804 | // 19.2.3.4 Function.prototype.constructor | ||
805 | // 19.2.3.5 Function.prototype.toString ( ) | ||
806 | // 19.2.3.6 Function.prototype[@@hasInstance] ( V ) | ||
807 | // 19.2.4 Function Instances | ||
808 | // 19.2.4.1 length | ||
809 | // 19.2.4.2 name | ||
810 | // 19.2.4.3 prototype | ||
811 | |||
812 | // (No polyfillable changes from ES5) | ||
813 | |||
814 | // --------------------------------------- | ||
815 | // 19.3 Boolean Objects | ||
816 | // --------------------------------------- | ||
817 | |||
818 | // 19.3.1 The Boolean Constructor | ||
819 | // 19.3.1.1 Boolean ( value ) | ||
820 | // 19.3.2 Properties of the Boolean Constructor | ||
821 | // 19.3.2.1 Boolean.prototype | ||
822 | // 19.3.3 Properties of the Boolean Prototype Object | ||
823 | // 19.3.3.1 Boolean.prototype.constructor | ||
824 | // 19.3.3.2 Boolean.prototype.toString ( ) | ||
825 | // 19.3.3.3 Boolean.prototype.valueOf ( ) | ||
826 | // 19.3.4 Properties of Boolean Instances | ||
827 | |||
828 | // (No polyfillable changes from ES5) | ||
829 | |||
830 | // --------------------------------------- | ||
831 | // 19.4 Symbol Objects | ||
832 | // --------------------------------------- | ||
833 | |||
834 | // Moved earlier in this script, so that other polyfills can depend on them. | ||
835 | |||
836 | // 19.4.3.4 Symbol.prototype [ @@toStringTag ] | ||
837 | define(global.Symbol.prototype, global.Symbol.toStringTag, 'Symbol'); | ||
838 | |||
839 | // --------------------------------------- | ||
840 | // 19.5 Error Objects | ||
841 | // --------------------------------------- | ||
842 | |||
843 | // 19.5.1 The Error Constructor | ||
844 | // 19.5.1.1 Error ( message ) | ||
845 | // 19.5.1.2 new Error( ...argumentsList ) | ||
846 | // 19.5.2 Properties of the Error Constructor | ||
847 | // 19.5.2.1 Error.prototype | ||
848 | // 19.5.3 Properties of the Error Prototype Object | ||
849 | // 19.5.3.1 Error.prototype.constructor | ||
850 | // 19.5.3.2 Error.prototype.message | ||
851 | // 19.5.3.3 Error.prototype.name | ||
852 | // 19.5.3.4 Error.prototype.toString ( ) | ||
853 | // 19.5.4 Properties of Error Instances | ||
854 | // 19.5.5 Native Error Types Used in This Standard | ||
855 | // 19.5.5.1 EvalError | ||
856 | // 19.5.5.2 RangeError | ||
857 | // 19.5.5.3 ReferenceError | ||
858 | // 19.5.5.4 SyntaxError | ||
859 | // 19.5.5.5 TypeError | ||
860 | // 19.5.5.6 URIError | ||
861 | // 19.5.6 NativeError Object Structure | ||
862 | // 19.5.6.1 NativeError Constructors | ||
863 | // 19.5.6.1.1 NativeError ( message ) | ||
864 | // 19.5.6.1.2 new NativeError ( ...argumentsList ) | ||
865 | // 19.5.6.2 Properties of the NativeError Constructors | ||
866 | // 19.5.6.2.1 NativeError.prototype | ||
867 | // 19.5.6.3 Properties of the NativeError Prototype Objects | ||
868 | // 19.5.6.4 Properties of NativeError Instances | ||
869 | |||
870 | // (No polyfillable changes from ES5) | ||
871 | |||
872 | // --------------------------------------- | ||
873 | // 20 Numbers and Dates | ||
874 | // --------------------------------------- | ||
875 | |||
876 | // --------------------------------------- | ||
877 | // 20.1 Number Objects | ||
878 | // --------------------------------------- | ||
879 | |||
880 | // 20.1.1 The Number Constructor | ||
881 | // 20.1.1.1 Number ( [ value ] ) | ||
882 | // 20.1.1.2 new Number ( ...argumentsList ) | ||
883 | // 20.1.2 Properties of the Number Constructor | ||
884 | |||
885 | // 20.1.2.1 Number.EPSILON | ||
886 | define( | ||
887 | Number, 'EPSILON', | ||
888 | (function () { | ||
889 | var next, result; | ||
890 | for (next = 1; 1 + next !== 1; next = next / 2) | ||
891 | result = next; | ||
892 | return result; | ||
893 | }())); | ||
894 | |||
895 | // 20.1.2.2 Number.isFinite ( number ) | ||
896 | define( | ||
897 | Number, 'isFinite', | ||
898 | function isFinite(number) { | ||
899 | if (Type(number) !== 'number') return false; | ||
900 | if (number !== number || number === +Infinity || number === -Infinity) return false; | ||
901 | return true; | ||
902 | }); | ||
903 | |||
904 | // 20.1.2.3 Number.isInteger ( number ) | ||
905 | define( | ||
906 | Number, 'isInteger', | ||
907 | function isInteger(number) { | ||
908 | if (Type(number) !== 'number') return false; | ||
909 | if (number !== number || number === +Infinity || number === -Infinity) return false; | ||
910 | var integer = ToInteger(number); | ||
911 | if (integer !== number) return false; | ||
912 | return true; | ||
913 | }); | ||
914 | |||
915 | // 20.1.2.4 Number.isNaN ( number ) | ||
916 | define( | ||
917 | Number, 'isNaN', | ||
918 | function isNaN(number) { | ||
919 | if (Type(number) !== 'number') return false; | ||
920 | if (number !== number) return true; | ||
921 | return false; | ||
922 | }); | ||
923 | |||
924 | // 20.1.2.5 Number.isSafeInteger ( number ) | ||
925 | define( | ||
926 | Number, 'isSafeInteger', | ||
927 | function isSafeInteger(number) { | ||
928 | if (Type(number) !== 'number') return false; | ||
929 | if (number !== number || number === +Infinity || number === -Infinity) return false; | ||
930 | var integer = ToInteger(number); | ||
931 | if (integer !== number) return false; | ||
932 | if (abs(integer) <= (0x20000000000000 - 1)) // 2^53-1 | ||
933 | return true; | ||
934 | return false; | ||
935 | }); | ||
936 | |||
937 | // 20.1.2.6 Number.MAX_SAFE_INTEGER | ||
938 | define( | ||
939 | Number, 'MAX_SAFE_INTEGER', | ||
940 | 9007199254740991); // 2^53-1 | ||
941 | |||
942 | // 20.1.2.7 Number.MAX_VALUE | ||
943 | |||
944 | // 20.1.2.8 Number.MIN_SAFE_INTEGER | ||
945 | define( | ||
946 | Number, 'MIN_SAFE_INTEGER', | ||
947 | -9007199254740991); // -2^53+1 | ||
948 | |||
949 | // 20.1.2.9 Number.MIN_VALUE | ||
950 | // 20.1.2.10 Number.NaN | ||
951 | // 20.1.2.11 Number.NEGATIVE_INFINITY | ||
952 | |||
953 | // 20.1.2.12 Number.parseFloat ( string ) | ||
954 | define(Number, 'parseFloat', $parseFloat); | ||
955 | |||
956 | // 20.1.2.13 Number.parseInt ( string, radix ) | ||
957 | define(Number, 'parseInt', $parseInt); | ||
958 | |||
959 | // 20.1.2.14 Number.POSITIVE_INFINITY | ||
960 | // 20.1.2.15 Number.prototype | ||
961 | |||
962 | // 20.1.3 Properties of the Number Prototype Object | ||
963 | // 20.1.3.1 Number.prototype.constructor | ||
964 | // 20.1.3.2 Number.prototype.toExponential ( fractionDigits ) | ||
965 | // 20.1.3.3 Number.prototype.toFixed ( fractionDigits ) | ||
966 | // 20.1.3.4 Number.prototype.toLocaleString( [ reserved1 [ , reserved2 ] ]) | ||
967 | // 20.1.3.5 Number.prototype.toPrecision ( precision ) | ||
968 | // 20.1.3.6 Number.prototype.toString ( [ radix ] ) | ||
969 | // 20.1.3.7 Number.prototype.valueOf ( ) | ||
970 | // 20.1.4 Properties of Number Instances | ||
971 | |||
972 | // --------------------------------------- | ||
973 | // 20.2 The Math Object | ||
974 | // --------------------------------------- | ||
975 | |||
976 | // 20.2.1 Value Properties of the Math Object | ||
977 | // 20.2.1.1 Math.E | ||
978 | // 20.2.1.2 Math.LN10 | ||
979 | // 20.2.1.3 Math.LN2 | ||
980 | // 20.2.1.4 Math.LOG10E | ||
981 | // 20.2.1.5 Math.LOG2E | ||
982 | // 20.2.1.6 Math.PI | ||
983 | // 20.2.1.7 Math.SQRT1_2 | ||
984 | // 20.2.1.8 Math.SQRT2 | ||
985 | |||
986 | // 20.2.1.9 Math [ @@toStringTag ] | ||
987 | define(Math, $$toStringTag, 'Math'); | ||
988 | |||
989 | // 20.2.2 Function Properties of the Math Object | ||
990 | // 20.2.2.1 Math.abs ( x ) | ||
991 | // 20.2.2.2 Math.acos ( x ) | ||
992 | |||
993 | // 20.2.2.3 Math.acosh(x) | ||
994 | define( | ||
995 | Math, 'acosh', | ||
996 | function acosh(x) { | ||
997 | x = Number(x); | ||
998 | return log(x + sqrt(x * x - 1)); | ||
999 | }); | ||
1000 | |||
1001 | // 20.2.2.4 Math.asin ( x ) | ||
1002 | |||
1003 | // 20.2.2.5 Math.asinh( x ) | ||
1004 | define( | ||
1005 | Math, 'asinh', | ||
1006 | function asinh(x) { | ||
1007 | x = Number(x); | ||
1008 | if (SameValue(x, -0)) { | ||
1009 | return x; | ||
1010 | } | ||
1011 | var s = sqrt(x * x + 1); | ||
1012 | return (s === -x) ? log(0) : log(x + s); | ||
1013 | }); | ||
1014 | |||
1015 | // 20.2.2.6 Math.atan ( x ) | ||
1016 | |||
1017 | // 20.2.2.7 Math.atanh( x ) | ||
1018 | define( | ||
1019 | Math, 'atanh', | ||
1020 | function atanh(x) { | ||
1021 | x = Number(x); | ||
1022 | return (x === 0) ? x : log((1 + x) / (1 - x)) / 2; | ||
1023 | }); | ||
1024 | |||
1025 | // 20.2.2.8 Math.atan2 ( y, x ) | ||
1026 | |||
1027 | // 20.2.2.9 Math.cbrt ( x ) | ||
1028 | define( | ||
1029 | Math, 'cbrt', | ||
1030 | function cbrt(x) { | ||
1031 | x = Number(x); | ||
1032 | if ($isNaN(x/x)) { | ||
1033 | return x; | ||
1034 | } | ||
1035 | var r = pow(abs(x), 1/3); | ||
1036 | var t = x/r/r; | ||
1037 | return r + (r * (t-r) / (2*r + t)); | ||
1038 | }); | ||
1039 | |||
1040 | // 20.2.2.10 Math.ceil ( x ) | ||
1041 | |||
1042 | // 20.2.2.11 Math.clz32 ( x ) | ||
1043 | define( | ||
1044 | Math, 'clz32', | ||
1045 | function clz32(x) { | ||
1046 | function clz8(x) { | ||
1047 | return (x & 0xf0) ? (x & 0x80 ? 0 : x & 0x40 ? 1 : x & 0x20 ? 2 : 3) : | ||
1048 | (x & 0x08 ? 4 : x & 0x04 ? 5 : x & 0x02 ? 6 : x & 0x01 ? 7 : 8); | ||
1049 | } | ||
1050 | x = ToUint32(x); | ||
1051 | return x & 0xff000000 ? clz8(x >> 24) : | ||
1052 | x & 0xff0000 ? clz8(x >> 16) + 8 : | ||
1053 | x & 0xff00 ? clz8(x >> 8) + 16 : clz8(x) + 24; | ||
1054 | }); | ||
1055 | |||
1056 | |||
1057 | |||
1058 | // 20.2.2.12 Math.cos ( x ) | ||
1059 | |||
1060 | // 20.2.2.13 Math.cosh ( x ) | ||
1061 | define( | ||
1062 | Math, 'cosh', | ||
1063 | function cosh(x) { | ||
1064 | x = Number(x); | ||
1065 | return (pow(E, x) + pow(E, -x)) / 2; | ||
1066 | }); | ||
1067 | |||
1068 | // 20.2.2.14 Math.exp ( x ) | ||
1069 | |||
1070 | // 20.2.2.15 Math.expm1 ( x ) | ||
1071 | define( | ||
1072 | Math, 'expm1', | ||
1073 | function expm1(x) { | ||
1074 | x = Number(x); | ||
1075 | // from: http://www.johndcook.com/cpp_log1p.html | ||
1076 | if (SameValue(x, -0)) { | ||
1077 | return -0; | ||
1078 | } else if (abs(x) < 1e-5) { | ||
1079 | return x + 0.5 * x * x; // two terms of Taylor expansion | ||
1080 | } else { | ||
1081 | return exp(x) - 1; | ||
1082 | } | ||
1083 | }); | ||
1084 | |||
1085 | // 20.2.2.16 Math.floor ( x ) | ||
1086 | |||
1087 | // 20.2.2.17 Math.fround ( x ) | ||
1088 | define( | ||
1089 | Math, 'fround', | ||
1090 | function fround(x) { | ||
1091 | if ($isNaN(x)) { | ||
1092 | return NaN; | ||
1093 | } | ||
1094 | if (1/x === +Infinity || 1/x === -Infinity || x === +Infinity || x === -Infinity) { | ||
1095 | return x; | ||
1096 | } | ||
1097 | return (new Float32Array([x]))[0]; | ||
1098 | }); | ||
1099 | |||
1100 | // 20.2.2.18 Math.hypot ( value1 [, value2 [ ... ] ] ) | ||
1101 | define( | ||
1102 | Math, 'hypot', | ||
1103 | function hypot() { | ||
1104 | var values = []; | ||
1105 | var m = 0, sawNaN = false; | ||
1106 | for (var i = 0; i < arguments.length; ++i) { | ||
1107 | var n = abs(Number(arguments[i])); | ||
1108 | if (n === Infinity) return n; | ||
1109 | if (n !== n) sawNaN = true; | ||
1110 | if (n > m) m = n; | ||
1111 | values[i] = n; | ||
1112 | } | ||
1113 | if (sawNaN) return NaN; | ||
1114 | if (m === 0) return +0; | ||
1115 | var sum = +0; | ||
1116 | for (i = 0; i < values.length; ++i) { | ||
1117 | var r = values[i] / m; | ||
1118 | sum = sum + r * r; | ||
1119 | } | ||
1120 | return m * sqrt(sum); | ||
1121 | }); | ||
1122 | |||
1123 | // 20.2.2.19 Math.imul ( x, y ) | ||
1124 | define( | ||
1125 | Math, 'imul', | ||
1126 | function imul(x, y) { | ||
1127 | var a = ToUint32(x); | ||
1128 | var b = ToUint32(y); | ||
1129 | // (slow but accurate) | ||
1130 | var ah = (a >>> 16) & 0xffff; | ||
1131 | var al = a & 0xffff; | ||
1132 | var bh = (b >>> 16) & 0xffff; | ||
1133 | var bl = b & 0xffff; | ||
1134 | return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0); | ||
1135 | }, ('imul' in Math && Math.imul(1, 0x80000000) === 0) // Safari 7 bug | ||
1136 | ); | ||
1137 | |||
1138 | // 20.2.2.20 Math.log ( x ) | ||
1139 | |||
1140 | // 20.2.2.21 Math.log1p ( x ) | ||
1141 | define( | ||
1142 | Math, 'log1p', | ||
1143 | function log1p(x) { | ||
1144 | x = Number(x); | ||
1145 | // from: http://www.johndcook.com/cpp_expm1.html | ||
1146 | if (x < -1) { | ||
1147 | return NaN; | ||
1148 | } else if (SameValue(x, -0)) { | ||
1149 | return -0; | ||
1150 | } else if (abs(x) > 1e-4) { | ||
1151 | return log(1 + x); | ||
1152 | } else { | ||
1153 | return (-0.5 * x + 1) * x; | ||
1154 | } | ||
1155 | }); | ||
1156 | |||
1157 | // 20.2.2.22 Math.log10 ( x ) | ||
1158 | define( | ||
1159 | Math, 'log10', | ||
1160 | function log10(x) { | ||
1161 | x = Number(x); | ||
1162 | return log(x) * LOG10E; | ||
1163 | }); | ||
1164 | |||
1165 | // 20.2.2.23 Math.log2 ( x ) | ||
1166 | define( | ||
1167 | Math, 'log2', | ||
1168 | function log2(x) { | ||
1169 | x = Number(x); | ||
1170 | return log(x) * LOG2E; | ||
1171 | }); | ||
1172 | |||
1173 | // 20.2.2.24 Math.max ( value1, value2 , ...values ) | ||
1174 | // 20.2.2.25 Math.min ( value1, value2 , ...values ) | ||
1175 | // 20.2.2.26 Math.pow ( x, y ) | ||
1176 | // 20.2.2.27 Math.random ( ) | ||
1177 | // 20.2.2.28 Math.round ( x ) | ||
1178 | |||
1179 | // 20.2.2.29 Math.sign(x) | ||
1180 | define( | ||
1181 | Math, 'sign', | ||
1182 | function sign(x) { | ||
1183 | x = Number(x); | ||
1184 | return x < 0 ? -1 : x > 0 ? 1 : x; | ||
1185 | }); | ||
1186 | |||
1187 | // 20.2.2.30 Math.sin ( x ) | ||
1188 | |||
1189 | // 20.2.2.31 Math.sinh( x ) | ||
1190 | define( | ||
1191 | Math, 'sinh', | ||
1192 | function sinh(x) { | ||
1193 | x = Number(x); | ||
1194 | return SameValue(x, -0) ? x : (pow(E, x) - pow(E, -x)) / 2; | ||
1195 | }); | ||
1196 | |||
1197 | // 20.2.2.32 Math.sqrt ( x ) | ||
1198 | // 20.2.2.33 Math.tan ( x ) | ||
1199 | |||
1200 | // 20.2.2.34 Math.tanh ( x ) | ||
1201 | define( | ||
1202 | Math, 'tanh', | ||
1203 | function tanh(x) { | ||
1204 | x = Number(x); | ||
1205 | var n = pow(E, 2 * x) - 1, | ||
1206 | d = pow(E, 2 * x) + 1; | ||
1207 | if (SameValue(x, -0)) | ||
1208 | return x; | ||
1209 | return (n === d) ? 1 : n / d; // Handle Infinity/Infinity | ||
1210 | }); | ||
1211 | |||
1212 | // 20.2.2.35 Math.trunc ( x ) | ||
1213 | define( | ||
1214 | Math, 'trunc', | ||
1215 | function trunc(x) { | ||
1216 | x = Number(x); | ||
1217 | return $isNaN(x) ? NaN : | ||
1218 | x < 0 ? ceil(x) : floor(x); | ||
1219 | }); | ||
1220 | |||
1221 | // --------------------------------------- | ||
1222 | // 20.3 Date Objects | ||
1223 | // --------------------------------------- | ||
1224 | |||
1225 | // 20.3.1 Overview of Date Objects and Definitions of Abstract Operations | ||
1226 | // 20.3.1.1 Time Values and Time Range | ||
1227 | // 20.3.1.2 Day Number and Time within Day | ||
1228 | // 20.3.1.3 Year Number | ||
1229 | // 20.3.1.4 Month Number | ||
1230 | // 20.3.1.5 Date Number | ||
1231 | // 20.3.1.6 Week Day | ||
1232 | // 20.3.1.7 Local Time Zone Adjustment | ||
1233 | // 20.3.1.8 Daylight Saving Time Adjustment | ||
1234 | // 20.3.1.9 Local Time | ||
1235 | // 20.3.1.10 Hours, Minutes, Second, and Milliseconds | ||
1236 | // 20.3.1.11 MakeTime (hour, min, sec, ms) | ||
1237 | // 20.3.1.12 MakeDay (year, month, date) | ||
1238 | // 20.3.1.13 MakeDate (day, time) | ||
1239 | // 20.3.1.14 TimeClip (time) | ||
1240 | // 20.3.1.15 Date Time String Format | ||
1241 | // 20.3.1.15.1 Extended years | ||
1242 | // 20.3.2 The Date Constructor | ||
1243 | // 20.3.2.1 Date ( year, month [, date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ) | ||
1244 | // 20.3.2.2 Date ( value ) | ||
1245 | // 20.3.2.3 Date ( ) | ||
1246 | // 20.3.3 Properties of the Date Constructor | ||
1247 | // 20.3.3.1 Date.now ( ) | ||
1248 | // 20.3.3.2 Date.parse (string) | ||
1249 | // 20.3.3.3 Date.prototype | ||
1250 | // 20.3.3.4 Date.UTC ( year, month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ) | ||
1251 | // 20.3.4 Properties of the Date Prototype Object | ||
1252 | // 20.3.4.1 Date.prototype.constructor | ||
1253 | // 20.3.4.2 Date.prototype.getDate ( ) | ||
1254 | // 20.3.4.3 Date.prototype.getDay ( ) | ||
1255 | // 20.3.4.4 Date.prototype.getFullYear ( ) | ||
1256 | // 20.3.4.5 Date.prototype.getHours ( ) | ||
1257 | // 20.3.4.6 Date.prototype.getMilliseconds ( ) | ||
1258 | // 20.3.4.7 Date.prototype.getMinutes ( ) | ||
1259 | // 20.3.4.8 Date.prototype.getMonth ( ) | ||
1260 | // 20.3.4.9 Date.prototype.getSeconds ( ) | ||
1261 | // 20.3.4.10 Date.prototype.getTime ( ) | ||
1262 | // 20.3.4.11 Date.prototype.getTimezoneOffset ( ) | ||
1263 | // 20.3.4.12 Date.prototype.getUTCDate ( ) | ||
1264 | // 20.3.4.13 Date.prototype.getUTCDay ( ) | ||
1265 | // 20.3.4.14 Date.prototype.getUTCFullYear ( ) | ||
1266 | // 20.3.4.15 Date.prototype.getUTCHours ( ) | ||
1267 | // 20.3.4.16 Date.prototype.getUTCMilliseconds ( ) | ||
1268 | // 20.3.4.17 Date.prototype.getUTCMinutes ( ) | ||
1269 | // 20.3.4.18 Date.prototype.getUTCMonth ( ) | ||
1270 | // 20.3.4.19 Date.prototype.getUTCSeconds ( ) | ||
1271 | // 20.3.4.20 Date.prototype.setDate ( date ) | ||
1272 | // 20.3.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ) | ||
1273 | // 20.3.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ) | ||
1274 | // 20.3.4.23 Date.prototype.setMilliseconds ( ms ) | ||
1275 | // 20.3.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ) | ||
1276 | // 20.3.4.25 Date.prototype.setMonth ( month [ , date ] ) | ||
1277 | // 20.3.4.26 Date.prototype.setSeconds ( sec [ , ms ] ) | ||
1278 | // 20.3.4.27 Date.prototype.setTime ( time ) | ||
1279 | // 20.3.4.28 Date.prototype.setUTCDate ( date ) | ||
1280 | // 20.3.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] ) | ||
1281 | // 20.3.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] ) | ||
1282 | // 20.3.4.31 Date.prototype.setUTCMilliseconds ( ms ) | ||
1283 | // 20.3.4.32 Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] ) | ||
1284 | // 20.3.4.33 Date.prototype.setUTCMonth ( month [ , date ] ) | ||
1285 | // 20.3.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] ) | ||
1286 | // 20.3.4.35 Date.prototype.toDateString ( ) | ||
1287 | // 20.3.4.36 Date.prototype.toISOString ( ) | ||
1288 | // 20.3.4.37 Date.prototype.toJSON ( key ) | ||
1289 | // 20.3.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ) | ||
1290 | // 20.3.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) | ||
1291 | // 20.3.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ) | ||
1292 | // 20.3.4.41 Date.prototype.toString ( ) | ||
1293 | // 20.3.4.42 Date.prototype.toTimeString ( ) | ||
1294 | // 20.3.4.43 Date.prototype.toUTCString ( ) | ||
1295 | // 20.3.4.44 Date.prototype.valueOf ( ) | ||
1296 | // 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint ) | ||
1297 | // 20.3.5 Properties of Date Instances | ||
1298 | |||
1299 | // (No polyfillable changes from ES5) | ||
1300 | |||
1301 | // --------------------------------------- | ||
1302 | // 21 Text Processing | ||
1303 | // --------------------------------------- | ||
1304 | |||
1305 | var string_regexp_dispatch = (function() { | ||
1306 | var faux = {}, secret = Symbol(); | ||
1307 | faux[Symbol.match] = function() { return secret; }; | ||
1308 | return ("").match(faux) === secret; | ||
1309 | }()); | ||
1310 | |||
1311 | // 21.1 String Objects | ||
1312 | // 21.1.1 The String Constructor | ||
1313 | // 21.1.1.1 String ( value ) | ||
1314 | // 21.1.2 Properties of the String Constructor | ||
1315 | // 21.1.2.1 String.fromCharCode ( ...codeUnits ) | ||
1316 | |||
1317 | // 21.1.2.2 String.fromCodePoint ( ...codePoints ) | ||
1318 | define( | ||
1319 | String, 'fromCodePoint', | ||
1320 | function fromCodePoint(/*...codePoints*/) { | ||
1321 | var codePoints = arguments, | ||
1322 | length = codePoints.length, | ||
1323 | elements = [], | ||
1324 | nextIndex = 0; | ||
1325 | while (nextIndex < length) { | ||
1326 | var next = codePoints[nextIndex]; | ||
1327 | var nextCP = Number(next); | ||
1328 | if (!SameValue(nextCP, ToInteger(nextCP)) || | ||
1329 | nextCP < 0 || nextCP > 0x10FFFF) { | ||
1330 | throw RangeError('Invalid code point ' + nextCP); | ||
1331 | } | ||
1332 | if (nextCP < 0x10000) { | ||
1333 | elements.push(String.fromCharCode(nextCP)); | ||
1334 | } else { | ||
1335 | nextCP -= 0x10000; | ||
1336 | elements.push(String.fromCharCode((nextCP >> 10) + 0xD800)); | ||
1337 | elements.push(String.fromCharCode((nextCP % 0x400) + 0xDC00)); | ||
1338 | } | ||
1339 | nextIndex += 1; | ||
1340 | } | ||
1341 | return elements.join(''); | ||
1342 | }); | ||
1343 | |||
1344 | // 21.1.2.3 String.prototype | ||
1345 | |||
1346 | // 21.1.2.4 String.raw ( template , ...substitutions ) | ||
1347 | define( | ||
1348 | String, 'raw', | ||
1349 | function raw(template /*, ...substitutions*/) { | ||
1350 | var substitutions = [].slice.call(arguments, 1); | ||
1351 | |||
1352 | var cooked = Object(template); | ||
1353 | var rawValue = cooked['raw']; | ||
1354 | var raw = Object(rawValue); | ||
1355 | var len = raw['length']; | ||
1356 | var literalSegments = ToLength(len); | ||
1357 | if (literalSegments <= 0) return ''; | ||
1358 | var stringElements = []; | ||
1359 | var nextIndex = 0; | ||
1360 | while (true) { | ||
1361 | var next = raw[nextIndex]; | ||
1362 | var nextSeg = String(next); | ||
1363 | stringElements.push(nextSeg); | ||
1364 | if (nextIndex + 1 === literalSegments) | ||
1365 | return stringElements.join(''); | ||
1366 | next = substitutions[nextIndex]; | ||
1367 | var nextSub = String(next); | ||
1368 | stringElements.push(nextSub); | ||
1369 | nextIndex = nextIndex + 1; | ||
1370 | } | ||
1371 | }); | ||
1372 | |||
1373 | // See https://githib.com/inexorabletash/uate for a more useful version. | ||
1374 | |||
1375 | // 21.1.3 Properties of the String Prototype Object | ||
1376 | // 21.1.3.1 String.prototype.charAt ( pos ) | ||
1377 | // 21.1.3.2 String.prototype.charCodeAt ( pos ) | ||
1378 | |||
1379 | // 21.1.3.3 String.prototype.codePointAt ( pos ) | ||
1380 | define( | ||
1381 | String.prototype, 'codePointAt', | ||
1382 | function codePointAt(pos) { | ||
1383 | var o = strict(this); | ||
1384 | var s = String(o); | ||
1385 | var position = ToInteger(pos); | ||
1386 | var size = s.length; | ||
1387 | if (position < 0 || position >= size) return undefined; | ||
1388 | var first = s.charCodeAt(position); | ||
1389 | if (first < 0xD800 || first > 0xDBFF || position + 1 === size) return first; | ||
1390 | var second = s.charCodeAt(position + 1); | ||
1391 | if (second < 0xDC00 || second > 0xDFFF) return first; | ||
1392 | return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000; | ||
1393 | }); | ||
1394 | |||
1395 | // 21.1.3.4 String.prototype.concat ( ...args ) | ||
1396 | // 21.1.3.5 String.prototype.constructor | ||
1397 | |||
1398 | // 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) | ||
1399 | define( | ||
1400 | String.prototype, 'endsWith', | ||
1401 | function endsWith(searchString) { | ||
1402 | var endPosition = arguments[1]; | ||
1403 | |||
1404 | var o = strict(this); | ||
1405 | var s = String(o); | ||
1406 | var searchStr = String(searchString); | ||
1407 | var len = s.length; | ||
1408 | var pos = (endPosition === undefined) ? len : ToInteger(endPosition); | ||
1409 | var end = min(max(pos, 0), len); | ||
1410 | var searchLength = searchStr.length; | ||
1411 | var start = end - searchLength; | ||
1412 | if (start < 0) return false; | ||
1413 | if (s.substring(start, start + searchLength) === searchStr) return true; | ||
1414 | return false; | ||
1415 | }); | ||
1416 | |||
1417 | // 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) | ||
1418 | define( | ||
1419 | String.prototype, 'includes', | ||
1420 | function includes(searchString) { | ||
1421 | var position = arguments[1]; | ||
1422 | |||
1423 | var o = strict(this); | ||
1424 | var s = String(o); | ||
1425 | var searchStr = String(searchString); | ||
1426 | var pos = ToInteger(position); | ||
1427 | var len = s.length; | ||
1428 | var start = min(max(pos, 0), len); | ||
1429 | return s.indexOf(searchStr, start) !== -1; | ||
1430 | }); | ||
1431 | |||
1432 | // 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) | ||
1433 | // 21.1.3.9 String.prototype.lastIndexOf ( searchString [ , position ] ) | ||
1434 | // 21.1.3.10 String.prototype.localeCompare ( that [, reserved1 [ , reserved2 ] ] ) | ||
1435 | // 21.1.3.11 String.prototype.match ( regexp ) | ||
1436 | define( | ||
1437 | String.prototype, 'match', | ||
1438 | function match(regexp) { | ||
1439 | var o = strict(this); | ||
1440 | var s = String(o); | ||
1441 | if (HasProperty(regexp, $$match)) var rx = regexp; | ||
1442 | else rx = new RegExp(regexp); | ||
1443 | return rx[$$match](s); | ||
1444 | }, !string_regexp_dispatch); | ||
1445 | |||
1446 | // 21.1.3.12 String.prototype.normalize ( [ form ] ) | ||
1447 | |||
1448 | // Not practical due to table sizes; if needed, pull in: | ||
1449 | // https://github.com/walling/unorm/ | ||
1450 | |||
1451 | // 21.1.3.13 String.prototype.repeat ( count ) | ||
1452 | define( | ||
1453 | String.prototype, 'repeat', | ||
1454 | function repeat(count) { | ||
1455 | var o = strict(this); | ||
1456 | var s = String(o); | ||
1457 | var n = ToInteger(count); | ||
1458 | if (n < 0) throw RangeError(); | ||
1459 | if (n === Infinity) throw RangeError(); | ||
1460 | var t = new Array(n + 1).join(s); | ||
1461 | return t; | ||
1462 | }); | ||
1463 | |||
1464 | // 21.1.3.14 String.prototype.replace (searchValue, replaceValue ) | ||
1465 | define( | ||
1466 | String.prototype, 'replace', | ||
1467 | function replace(searchValue, replaceValue) { | ||
1468 | var o = strict(this); | ||
1469 | if (HasProperty(searchValue, $$replace)) | ||
1470 | return searchValue[$$replace](o, replaceValue); | ||
1471 | return orig_replace.call(o, searchValue, replaceValue); | ||
1472 | }, !string_regexp_dispatch); | ||
1473 | |||
1474 | // 21.1.3.15 String.prototype.search ( regexp ) | ||
1475 | define( | ||
1476 | String.prototype, 'search', | ||
1477 | function search(regexp) { | ||
1478 | var o = strict(this); | ||
1479 | var string = String(o); | ||
1480 | if (HasProperty(regexp, $$search)) var rx = regexp; | ||
1481 | else rx = new RegExp(regexp); | ||
1482 | return rx[$$search](string); | ||
1483 | }, !string_regexp_dispatch); | ||
1484 | |||
1485 | // 21.1.3.16 String.prototype.slice ( start, end ) | ||
1486 | // 21.1.3.17 String.prototype.split ( separator, limit ) | ||
1487 | define( | ||
1488 | String.prototype, 'split', | ||
1489 | function split(separator, limit) { | ||
1490 | var o = strict(this); | ||
1491 | if (HasProperty(separator, $$split)) | ||
1492 | return separator[$$split](o, limit); | ||
1493 | return orig_split.call(o, separator, limit); | ||
1494 | }, !string_regexp_dispatch); | ||
1495 | |||
1496 | // 21.1.3.18 String.prototype.startsWith ( searchString [, position ] ) | ||
1497 | define( | ||
1498 | String.prototype, 'startsWith', | ||
1499 | function startsWith(searchString) { | ||
1500 | var position = arguments[1]; | ||
1501 | |||
1502 | var o = strict(this); | ||
1503 | var s = String(o); | ||
1504 | var searchStr = String(searchString); | ||
1505 | var pos = ToInteger(position); | ||
1506 | var len = s.length; | ||
1507 | var start = min(max(pos, 0), len); | ||
1508 | var searchLength = searchStr.length; | ||
1509 | if (searchLength + start > len) return false; | ||
1510 | if (s.substring(start, start + searchLength) === searchStr) return true; | ||
1511 | return false; | ||
1512 | }); | ||
1513 | |||
1514 | // 21.1.3.19 String.prototype.substring ( start, end ) | ||
1515 | // 21.1.3.20 String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] ) | ||
1516 | // 21.1.3.21 String.prototype.toLocaleUpperCase ([ reserved1 [ , reserved2 ] ] ) | ||
1517 | // 21.1.3.22 String.prototype.toLowerCase ( ) | ||
1518 | // 21.1.3.23 String.prototype.toString ( ) | ||
1519 | // 21.1.3.24 String.prototype.toUpperCase ( ) | ||
1520 | // 21.1.3.25 String.prototype.trim ( ) | ||
1521 | // 21.1.3.26 String.prototype.valueOf ( ) | ||
1522 | |||
1523 | // 21.1.3.27 String.prototype [ @@iterator ]( ) | ||
1524 | define( | ||
1525 | String.prototype, $$iterator, | ||
1526 | function entries() { | ||
1527 | return CreateStringIterator(this, 'value'); | ||
1528 | }); | ||
1529 | |||
1530 | // 21.1.4 Properties of String Instances | ||
1531 | // 21.1.4.1 length | ||
1532 | |||
1533 | // 21.1.5 String Iterator Objects | ||
1534 | /** @constructor */ | ||
1535 | function StringIterator() {} | ||
1536 | |||
1537 | // 21.1.5.1 CreateStringIterator Abstract Operation | ||
1538 | function CreateStringIterator(string, kind) { | ||
1539 | var s = String(string); | ||
1540 | var iterator = new StringIterator; | ||
1541 | set_internal(iterator, '[[IteratedString]]', s); | ||
1542 | set_internal(iterator, '[[StringIteratorNextIndex]]', 0); | ||
1543 | set_internal(iterator, '[[StringIterationKind]]', kind); | ||
1544 | return iterator; | ||
1545 | } | ||
1546 | |||
1547 | // 21.1.5.2 The %StringIteratorPrototype% Object | ||
1548 | var $StringIteratorPrototype$ = Object.create($IteratorPrototype$); | ||
1549 | StringIterator.prototype = $StringIteratorPrototype$; | ||
1550 | |||
1551 | // 21.1.5.2.1 %StringIteratorPrototype%.next ( ) | ||
1552 | define( | ||
1553 | $StringIteratorPrototype$, 'next', | ||
1554 | function next() { | ||
1555 | var o = ToObject(this); | ||
1556 | var s = String(o['[[IteratedString]]']), | ||
1557 | index = o['[[StringIteratorNextIndex]]'], | ||
1558 | len = s.length; | ||
1559 | if (index >= len) { | ||
1560 | set_internal(o, '[[StringIteratorNextIndex]]', Infinity); | ||
1561 | return CreateIterResultObject(undefined, true); | ||
1562 | } | ||
1563 | var cp = s.codePointAt(index); | ||
1564 | set_internal(o, '[[StringIteratorNextIndex]]', index + (cp > 0xFFFF ? 2 : 1)); | ||
1565 | return CreateIterResultObject(String.fromCodePoint(cp), false); | ||
1566 | }); | ||
1567 | |||
1568 | // 21.1.5.2.2 %StringIteratorPrototype% [ @@toStringTag ] | ||
1569 | define($StringIteratorPrototype$, $$toStringTag, 'String Iterator'); | ||
1570 | |||
1571 | // 21.1.5.3 Properties of String Iterator Instances | ||
1572 | |||
1573 | // --------------------------------------- | ||
1574 | // 21.2 RegExp (Regular Expression) Objects | ||
1575 | // --------------------------------------- | ||
1576 | |||
1577 | // 21.2.1 Patterns | ||
1578 | // 21.2.2 Pattern Semantics | ||
1579 | // 21.2.2.1 Notation | ||
1580 | // 21.2.2.2 Pattern | ||
1581 | // 21.2.2.3 Disjunction | ||
1582 | // 21.2.2.4 Alternative | ||
1583 | // 21.2.2.5 Term | ||
1584 | // 21.2.2.6 Assertion | ||
1585 | // 21.2.2.7 Quantifier | ||
1586 | // 21.2.2.8 Atom | ||
1587 | // 21.2.2.9 AtomEscape | ||
1588 | // 21.2.2.10 CharacterEscape | ||
1589 | // 21.2.2.11 DecimalEscape | ||
1590 | // 21.2.2.12 CharacterClassEscape | ||
1591 | // 21.2.2.13 CharacterClass | ||
1592 | // 21.2.2.14 ClassRanges | ||
1593 | // 21.2.2.15 NonemptyClassRanges | ||
1594 | // 21.2.2.16 NonemptyClassRangesNoDash | ||
1595 | // 21.2.2.17 ClassAtom | ||
1596 | // 21.2.2.18 ClassAtomNoDash | ||
1597 | // 21.2.2.19 ClassEscape | ||
1598 | // 21.2.3 The RegExp Constructor | ||
1599 | // 21.2.3.1 RegExp ( pattern, flags ) | ||
1600 | // 21.2.3.2 new RegExp( ...argumentsList ) | ||
1601 | // 21.2.3.3 Abstract Operations for the RegExp Constructor | ||
1602 | // 21.2.4 Properties of the RegExp Constructor | ||
1603 | // 21.2.4.1 RegExp.prototype | ||
1604 | // 21.2.5 Properties of the RegExp Prototype Object | ||
1605 | // 21.2.5.1 RegExp.prototype.constructor | ||
1606 | // 21.2.5.2 RegExp.prototype.exec ( string ) | ||
1607 | |||
1608 | // 21.2.5.3 get RegExp.prototype.flags | ||
1609 | if (!('flags' in RegExp.prototype)) { | ||
1610 | Object.defineProperty( | ||
1611 | RegExp.prototype, 'flags', { | ||
1612 | get: function() { | ||
1613 | var s = String(this); | ||
1614 | return s.substring(s.lastIndexOf('/') + 1); | ||
1615 | } | ||
1616 | }); | ||
1617 | } | ||
1618 | |||
1619 | // 21.2.5.4 get RegExp.prototype.global | ||
1620 | // 21.2.5.5 get RegExp.prototype.ignoreCase | ||
1621 | |||
1622 | // 21.2.5.6 RegExp.prototype [ @@match ] ( string ) | ||
1623 | define(RegExp.prototype, $$match, function(string) { | ||
1624 | var o = strict(this); | ||
1625 | return orig_match.call(string, o); | ||
1626 | }); | ||
1627 | |||
1628 | // 21.2.5.7 get RegExp.prototype.multiline | ||
1629 | |||
1630 | // 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) | ||
1631 | define(RegExp.prototype, $$replace, function(string, replaceValue) { | ||
1632 | var o = strict(this); | ||
1633 | return orig_replace.call(string, o, replaceValue); | ||
1634 | }); | ||
1635 | |||
1636 | // 21.2.5.9 RegExp.prototype [ @@search ] ( string ) | ||
1637 | define(RegExp.prototype, $$search, function(string) { | ||
1638 | var o = strict(this); | ||
1639 | return orig_search.call(string, o); | ||
1640 | }); | ||
1641 | |||
1642 | // 21.2.5.10 get RegExp.prototype.source | ||
1643 | |||
1644 | // 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) | ||
1645 | define(RegExp.prototype, $$split, function(string, limit) { | ||
1646 | var o = strict(this); | ||
1647 | return orig_split.call(string, o, limit); | ||
1648 | }); | ||
1649 | |||
1650 | // 21.2.5.12 get RegExp.prototype.sticky | ||
1651 | // 21.2.5.13 RegExp.prototype.test( S ) | ||
1652 | // 21.2.5.14 RegExp.prototype.toString ( ) | ||
1653 | // 21.2.5.15 get RegExp.prototype.unicode | ||
1654 | |||
1655 | // 21.2.6 Properties of RegExp Instances | ||
1656 | // 21.2.6.1 lastIndex | ||
1657 | |||
1658 | // (No polyfillable changes from ES5) | ||
1659 | |||
1660 | // --------------------------------------- | ||
1661 | // 22 Indexed Collections | ||
1662 | // --------------------------------------- | ||
1663 | |||
1664 | // --------------------------------------- | ||
1665 | // 22.1 Array Objects | ||
1666 | // --------------------------------------- | ||
1667 | |||
1668 | // 22.1.1 The Array Constructor | ||
1669 | // 22.1.1.1 Array ( ) | ||
1670 | // 22.1.1.2 Array (len) | ||
1671 | // 22.1.1.3 Array (...items ) | ||
1672 | |||
1673 | // 22.1.2 Properties of the Array Constructor | ||
1674 | |||
1675 | // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) | ||
1676 | define( | ||
1677 | Array, 'from', | ||
1678 | function from(items) { | ||
1679 | var mapfn = arguments[1]; | ||
1680 | var thisArg = arguments[2]; | ||
1681 | |||
1682 | var c = strict(this); | ||
1683 | if (mapfn === undefined) { | ||
1684 | var mapping = false; | ||
1685 | } else { | ||
1686 | if (!IsCallable(mapfn)) throw TypeError(); | ||
1687 | var t = thisArg; | ||
1688 | mapping = true; | ||
1689 | } | ||
1690 | var usingIterator = GetMethod(items, $$iterator); | ||
1691 | if (usingIterator !== undefined) { | ||
1692 | if (IsConstructor(c)) { | ||
1693 | var a = new c(); | ||
1694 | } else { | ||
1695 | a = new Array(0); | ||
1696 | } | ||
1697 | var iterator = GetIterator(items, usingIterator); | ||
1698 | var k = 0; | ||
1699 | while (true) { | ||
1700 | var next = IteratorStep(iterator); | ||
1701 | if (next === false) { | ||
1702 | a.length = k; | ||
1703 | return a; | ||
1704 | } | ||
1705 | var nextValue = IteratorValue(next); | ||
1706 | if (mapping) | ||
1707 | var mappedValue = mapfn.call(t, nextValue); | ||
1708 | else | ||
1709 | mappedValue = nextValue; | ||
1710 | a[k] = mappedValue; | ||
1711 | k += 1; | ||
1712 | } | ||
1713 | } | ||
1714 | var arrayLike = ToObject(items); | ||
1715 | var lenValue = arrayLike.length; | ||
1716 | var len = ToLength(lenValue); | ||
1717 | if (IsConstructor(c)) { | ||
1718 | a = new c(len); | ||
1719 | } else { | ||
1720 | a = new Array(len); | ||
1721 | } | ||
1722 | k = 0; | ||
1723 | while (k < len) { | ||
1724 | var kValue = arrayLike[k]; | ||
1725 | if (mapping) | ||
1726 | mappedValue = mapfn.call(t, kValue, k); | ||
1727 | else | ||
1728 | mappedValue = kValue; | ||
1729 | a[k] = mappedValue; | ||
1730 | k += 1; | ||
1731 | } | ||
1732 | a.length = len; | ||
1733 | return a; | ||
1734 | }); | ||
1735 | |||
1736 | // 22.1.2.2 Array.isArray ( arg ) | ||
1737 | |||
1738 | // 22.1.2.3 Array.of ( ...items ) | ||
1739 | define( | ||
1740 | Array, 'of', | ||
1741 | function of() { | ||
1742 | var items = arguments; | ||
1743 | |||
1744 | var lenValue = items.length; | ||
1745 | var len = ToUint32(lenValue); | ||
1746 | var c = strict(this), a; | ||
1747 | if (IsConstructor(c)) { | ||
1748 | a = new c(len); | ||
1749 | a = ToObject(a); | ||
1750 | } else { | ||
1751 | a = new Array(len); | ||
1752 | } | ||
1753 | var k = 0; | ||
1754 | while (k < len) { | ||
1755 | a[k] = items[k]; | ||
1756 | k += 1; | ||
1757 | } | ||
1758 | a.length = len; | ||
1759 | return a; | ||
1760 | }); | ||
1761 | |||
1762 | // 22.1.2.4 Array.prototype | ||
1763 | // 22.1.2.5 get Array [ @@species ] | ||
1764 | // 22.1.3 Properties of the Array Prototype Object | ||
1765 | // 22.1.3.1 Array.prototype.concat ( ...arguments ) | ||
1766 | // 22.1.3.1.1 Runtime Semantics: IsConcatSpreadable ( O ) | ||
1767 | // 22.1.3.2 Array.prototype.constructor | ||
1768 | // 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) | ||
1769 | define( | ||
1770 | Array.prototype, 'copyWithin', | ||
1771 | function copyWithin(target, start/*, end*/) { | ||
1772 | var end = arguments[2]; | ||
1773 | |||
1774 | var o = ToObject(this); | ||
1775 | var lenVal = o.length; | ||
1776 | var len = ToLength(lenVal); | ||
1777 | len = max(len, 0); | ||
1778 | var relativeTarget = ToInteger(target); | ||
1779 | var to; | ||
1780 | if (relativeTarget < 0) | ||
1781 | to = max(len + relativeTarget, 0); | ||
1782 | else | ||
1783 | to = min(relativeTarget, len); | ||
1784 | var relativeStart = ToInteger(start); | ||
1785 | var from; | ||
1786 | if (relativeStart < 0) | ||
1787 | from = max(len + relativeStart, 0); | ||
1788 | else | ||
1789 | from = min(relativeStart, len); | ||
1790 | var relativeEnd; | ||
1791 | if (end === undefined) | ||
1792 | relativeEnd = len; | ||
1793 | else | ||
1794 | relativeEnd = ToInteger(end); | ||
1795 | var final; | ||
1796 | if (relativeEnd < 0) | ||
1797 | final = max(len + relativeEnd, 0); | ||
1798 | else | ||
1799 | final = min(relativeEnd, len); | ||
1800 | var count = min(final - from, len - to); | ||
1801 | var direction; | ||
1802 | if (from < to && to < from + count) { | ||
1803 | direction = -1; | ||
1804 | from = from + count - 1; | ||
1805 | to = to + count - 1; | ||
1806 | } else { | ||
1807 | direction = 1; | ||
1808 | } | ||
1809 | while (count > 0) { | ||
1810 | var fromKey = String(from); | ||
1811 | var toKey = String(to); | ||
1812 | var fromPresent = HasProperty(o, fromKey); | ||
1813 | if (fromPresent) { | ||
1814 | var fromVal = o[fromKey]; | ||
1815 | o[toKey] = fromVal; | ||
1816 | } else { | ||
1817 | delete o[toKey]; | ||
1818 | } | ||
1819 | from = from + direction; | ||
1820 | to = to + direction; | ||
1821 | count = count - 1; | ||
1822 | } | ||
1823 | return o; | ||
1824 | }); | ||
1825 | |||
1826 | // 22.1.3.4 Array.prototype.entries ( ) | ||
1827 | var nativeArrayIteratorMethods = | ||
1828 | ('entries' in Array.prototype && 'next' in [].entries()); | ||
1829 | |||
1830 | define( | ||
1831 | Array.prototype, 'entries', | ||
1832 | function entries() { | ||
1833 | return CreateArrayIterator(this, 'key+value'); | ||
1834 | }, !nativeArrayIteratorMethods); | ||
1835 | |||
1836 | // 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg] ) | ||
1837 | |||
1838 | // 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) | ||
1839 | define( | ||
1840 | Array.prototype, 'fill', | ||
1841 | function fill(value/*, start, end*/) { | ||
1842 | var start = arguments[1], | ||
1843 | end = arguments[2]; | ||
1844 | |||
1845 | var o = ToObject(this); | ||
1846 | var lenVal = o.length; | ||
1847 | var len = ToLength(lenVal); | ||
1848 | len = max(len, 0); | ||
1849 | var relativeStart = ToInteger(start); | ||
1850 | var k; | ||
1851 | if (relativeStart < 0) | ||
1852 | k = max((len + relativeStart), 0); | ||
1853 | else | ||
1854 | k = min(relativeStart, len); | ||
1855 | var relativeEnd; | ||
1856 | if (end === undefined) | ||
1857 | relativeEnd = len; | ||
1858 | else | ||
1859 | relativeEnd = ToInteger(end); | ||
1860 | var final; | ||
1861 | if (relativeEnd < 0) | ||
1862 | final = max((len + relativeEnd), 0); | ||
1863 | else | ||
1864 | final = min(relativeEnd, len); | ||
1865 | while (k < final) { | ||
1866 | var pk = String(k); | ||
1867 | o[pk] = value; | ||
1868 | k += 1; | ||
1869 | } | ||
1870 | return o; | ||
1871 | }); | ||
1872 | |||
1873 | // 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ) | ||
1874 | |||
1875 | // 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) | ||
1876 | define( | ||
1877 | Array.prototype, 'find', | ||
1878 | function find(predicate) { | ||
1879 | var o = ToObject(this); | ||
1880 | var lenValue = o.length; | ||
1881 | var len = ToInteger(lenValue); | ||
1882 | if (!IsCallable(predicate)) throw TypeError(); | ||
1883 | var t = arguments.length > 1 ? arguments[1] : undefined; | ||
1884 | var k = 0; | ||
1885 | while (k < len) { | ||
1886 | var pk = String(k); | ||
1887 | var kPresent = HasProperty(o, pk); | ||
1888 | if (kPresent) { | ||
1889 | var kValue = o[pk]; | ||
1890 | var testResult = predicate.call(t, kValue, k, o); | ||
1891 | if (Boolean(testResult)) { | ||
1892 | return kValue; | ||
1893 | } | ||
1894 | } | ||
1895 | ++k; | ||
1896 | } | ||
1897 | return undefined; | ||
1898 | }); | ||
1899 | |||
1900 | // 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] ) | ||
1901 | define( | ||
1902 | Array.prototype, 'findIndex', | ||
1903 | function findIndex(predicate) { | ||
1904 | var o = ToObject(this); | ||
1905 | var lenValue = o.length; | ||
1906 | var len = ToLength(lenValue); | ||
1907 | if (!IsCallable(predicate)) throw TypeError(); | ||
1908 | var t = arguments.length > 1 ? arguments[1] : undefined; | ||
1909 | var k = 0; | ||
1910 | while (k < len) { | ||
1911 | var pk = String(k); | ||
1912 | var kPresent = HasProperty(o, pk); | ||
1913 | if (kPresent) { | ||
1914 | var kValue = o[pk]; | ||
1915 | var testResult = predicate.call(t, kValue, k, o); | ||
1916 | if (Boolean(testResult)) { | ||
1917 | return k; | ||
1918 | } | ||
1919 | } | ||
1920 | ++k; | ||
1921 | } | ||
1922 | return -1; | ||
1923 | }); | ||
1924 | |||
1925 | // 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) | ||
1926 | // 22.1.3.11 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) | ||
1927 | // 22.1.3.12 Array.prototype.join (separator) | ||
1928 | |||
1929 | // 22.1.3.13 Array.prototype.keys ( ) | ||
1930 | define( | ||
1931 | Array.prototype, 'keys', | ||
1932 | function keys() { | ||
1933 | return CreateArrayIterator(this, 'key'); | ||
1934 | }, !nativeArrayIteratorMethods); | ||
1935 | |||
1936 | // 22.1.3.14 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) | ||
1937 | // 22.1.3.15 Array.prototype.map ( callbackfn [ , thisArg ] ) | ||
1938 | // 22.1.3.16 Array.prototype.pop ( ) | ||
1939 | // 22.1.3.17 Array.prototype.push ( ...items ) | ||
1940 | // 22.1.3.18 Array.prototype.reduce ( callbackfn [ , initialValue ] ) | ||
1941 | // 22.1.3.19 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) | ||
1942 | // 22.1.3.20 Array.prototype.reverse ( ) | ||
1943 | // 22.1.3.21 Array.prototype.shift ( ) | ||
1944 | // 22.1.3.22 Array.prototype.slice (start, end) | ||
1945 | // 22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] ) | ||
1946 | // 22.1.3.24 Array.prototype.sort (comparefn) | ||
1947 | // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) | ||
1948 | // 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) | ||
1949 | // 22.1.3.27 Array.prototype.toString ( ) | ||
1950 | // 22.1.3.28 Array.prototype.unshift ( ...items ) | ||
1951 | |||
1952 | // 22.1.3.29 Array.prototype.values ( ) | ||
1953 | define( | ||
1954 | Array.prototype, 'values', | ||
1955 | function values() { | ||
1956 | return CreateArrayIterator(this, 'value'); | ||
1957 | }, !nativeArrayIteratorMethods); | ||
1958 | |||
1959 | // 22.1.3.30 Array.prototype [ @@iterator ] ( ) | ||
1960 | define( | ||
1961 | Array.prototype, $$iterator, | ||
1962 | Array.prototype.values | ||
1963 | ); | ||
1964 | |||
1965 | // 22.1.3.31 Array.prototype [ @@unscopables ] | ||
1966 | // 22.1.4 Properties of Array Instances | ||
1967 | // 22.1.4.1 length | ||
1968 | |||
1969 | // 22.1.5 Array Iterator Objects | ||
1970 | function ArrayIterator() {} | ||
1971 | |||
1972 | // 22.1.5.1 CreateArrayIterator Abstract Operation | ||
1973 | function CreateArrayIterator(array, kind) { | ||
1974 | var o = ToObject(array); | ||
1975 | var iterator = new ArrayIterator; | ||
1976 | set_internal(iterator, '[[IteratedObject]]', o); | ||
1977 | set_internal(iterator, '[[ArrayIteratorNextIndex]]', 0); | ||
1978 | set_internal(iterator, '[[ArrayIterationKind]]', kind); | ||
1979 | return iterator; | ||
1980 | } | ||
1981 | |||
1982 | // 22.1.5.2 The %ArrayIteratorPrototype% Object | ||
1983 | var $ArrayIteratorPrototype$ = Object.create($IteratorPrototype$); | ||
1984 | ArrayIterator.prototype = $ArrayIteratorPrototype$; | ||
1985 | |||
1986 | // 22.1.5.2.1 %ArrayIteratorPrototype%. next( ) | ||
1987 | define( | ||
1988 | $ArrayIteratorPrototype$, 'next', | ||
1989 | function next() { | ||
1990 | var o = strict(this); | ||
1991 | if (Type(o) !== 'object') throw TypeError(); | ||
1992 | var a = o['[[IteratedObject]]'], | ||
1993 | index = o['[[ArrayIteratorNextIndex]]'], | ||
1994 | itemKind = o['[[ArrayIterationKind]]'], | ||
1995 | lenValue = a.length, | ||
1996 | len = ToUint32(lenValue), | ||
1997 | elementKey, | ||
1998 | elementValue; | ||
1999 | if (itemKind.indexOf('sparse') !== -1) { | ||
2000 | var found = false; | ||
2001 | while (!found && index < len) { | ||
2002 | elementKey = String(index); | ||
2003 | found = HasProperty(a, elementKey); | ||
2004 | if (!found) { | ||
2005 | index += 1; | ||
2006 | } | ||
2007 | } | ||
2008 | } | ||
2009 | if (index >= len) { | ||
2010 | set_internal(o, '[[ArrayIteratorNextIndex]]', Infinity); | ||
2011 | return CreateIterResultObject(undefined, true); | ||
2012 | } | ||
2013 | elementKey = index; | ||
2014 | set_internal(o, '[[ArrayIteratorNextIndex]]', index + 1); | ||
2015 | if (itemKind.indexOf('value') !== -1) | ||
2016 | elementValue = a[elementKey]; | ||
2017 | if (itemKind.indexOf('key+value') !== -1) | ||
2018 | return CreateIterResultObject([elementKey, elementValue], false); | ||
2019 | if (itemKind.indexOf('key') !== -1) | ||
2020 | return CreateIterResultObject(elementKey, false); | ||
2021 | if (itemKind === 'value') | ||
2022 | return CreateIterResultObject(elementValue, false); | ||
2023 | throw Error('Internal error'); | ||
2024 | }); | ||
2025 | |||
2026 | // 22.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ] | ||
2027 | define($ArrayIteratorPrototype$, $$toStringTag, 'Array Iterator'); | ||
2028 | |||
2029 | // 22.1.5.3 Properties of Array Iterator Instances | ||
2030 | |||
2031 | |||
2032 | // --------------------------------------- | ||
2033 | // 22.2 TypedArray Objects | ||
2034 | // --------------------------------------- | ||
2035 | |||
2036 | // See typedarray.js for TypedArray polyfill | ||
2037 | |||
2038 | ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', | ||
2039 | 'Int16Array', 'Uint16Array', | ||
2040 | 'Int32Array', 'Uint32Array', | ||
2041 | 'Float32Array', 'Float64Array'].forEach(function ($TypedArrayName$) { | ||
2042 | if (!($TypedArrayName$ in global)) | ||
2043 | return; | ||
2044 | var $TypedArray$ = global[$TypedArrayName$]; | ||
2045 | |||
2046 | // 22.2.1 The %TypedArray% Intrinsic Object | ||
2047 | // 22.2.1.1 %TypedArray% ( length ) | ||
2048 | // 22.2.1.2 %TypedArray% ( typedArray ) | ||
2049 | // 22.2.1.3 %TypedArray% ( object ) | ||
2050 | // 22.2.1.4 %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) | ||
2051 | // 22.2.1.5 %TypedArray% ( all other argument combinations ) | ||
2052 | // 22.2.2 Properties of the %TypedArray% Intrinsic Object | ||
2053 | |||
2054 | // 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) | ||
2055 | define( | ||
2056 | $TypedArray$, 'from', | ||
2057 | function from(source) { | ||
2058 | var mapfn = arguments[1]; | ||
2059 | var thisArg = arguments[2]; | ||
2060 | |||
2061 | var c = strict(this); | ||
2062 | if (!IsConstructor(c)) throw TypeError(); | ||
2063 | if (mapfn === undefined) { | ||
2064 | var mapping = false; | ||
2065 | } else { | ||
2066 | if (IsCallable(mapfn)) throw TypeError(); | ||
2067 | var t = thisArg; | ||
2068 | mapping = true; | ||
2069 | } | ||
2070 | var usingIterator = GetMethod(source, $$iterator); | ||
2071 | if (usingIterator !== undefined) { | ||
2072 | var iterator = GetIterator(source, usingIterator); | ||
2073 | var values = []; | ||
2074 | var next = true; | ||
2075 | while (next !== false) { | ||
2076 | next = IteratorStep(iterator); | ||
2077 | if (next !== false) { | ||
2078 | var nextValue = IteratorValue(next); | ||
2079 | values.push(nextValue); | ||
2080 | } | ||
2081 | } | ||
2082 | var len = values.length; | ||
2083 | var newObj = new c(len); | ||
2084 | var k = 0; | ||
2085 | while (k < len) { | ||
2086 | var kValue = values.shift(); | ||
2087 | if (mapping) { | ||
2088 | var mappedValue = mapfn.call(t, kValue); | ||
2089 | } else { | ||
2090 | mappedValue = kValue; | ||
2091 | } | ||
2092 | newObj[k] = mappedValue; | ||
2093 | ++k; | ||
2094 | } | ||
2095 | console.assert(values.length === 0); | ||
2096 | return newObj; | ||
2097 | } | ||
2098 | var arrayLike = ToObject(source); | ||
2099 | var lenValue = arrayLike.length; | ||
2100 | len = ToLength(lenValue); | ||
2101 | newObj = new c(len); | ||
2102 | k = 0; | ||
2103 | while (k < len) { | ||
2104 | kValue = arrayLike[k]; | ||
2105 | if (mapping) { | ||
2106 | mappedValue = mapfn.call(t, kValue, k); | ||
2107 | } else { | ||
2108 | mappedValue = kValue; | ||
2109 | } | ||
2110 | newObj[k] = mappedValue; | ||
2111 | ++k; | ||
2112 | } | ||
2113 | return newObj; | ||
2114 | }); | ||
2115 | |||
2116 | // 22.2.2.2 %TypedArray%.of ( ...items ) | ||
2117 | define( | ||
2118 | $TypedArray$, 'of', | ||
2119 | function of() { | ||
2120 | var items = arguments; | ||
2121 | |||
2122 | var len = items.length; | ||
2123 | var c = strict(this); | ||
2124 | var newObj = new c(len); | ||
2125 | var k = 0; | ||
2126 | while (k < len) { | ||
2127 | newObj[k] = items[k]; | ||
2128 | ++k; | ||
2129 | } | ||
2130 | return newObj; | ||
2131 | }); | ||
2132 | |||
2133 | // 22.2.2.3 %TypedArray%.prototype | ||
2134 | // 22.2.2.4 get %TypedArray% [ @@species ] | ||
2135 | // 22.2.3 Properties of the %TypedArrayPrototype% Object | ||
2136 | // 22.2.3.1 get %TypedArray%.prototype.buffer | ||
2137 | // 22.2.3.2 get %TypedArray%.prototype.byteLength | ||
2138 | // 22.2.3.3 get %TypedArray%.prototype.byteOffset | ||
2139 | // 22.2.3.4 %TypedArray%.prototype.constructor | ||
2140 | |||
2141 | // 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] ) | ||
2142 | define($TypedArray$.prototype, 'copyWithin', Array.prototype.copyWithin); | ||
2143 | |||
2144 | // 22.2.3.6 %TypedArray%.prototype.entries ( ) | ||
2145 | define($TypedArray$.prototype, 'entries', Array.prototype.entries); | ||
2146 | |||
2147 | // 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) | ||
2148 | define($TypedArray$.prototype, 'every', Array.prototype.every); | ||
2149 | |||
2150 | // 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) | ||
2151 | define( | ||
2152 | $TypedArray$.prototype, 'fill', | ||
2153 | //Array.prototype.fill // Doesn't work in Safari 7 | ||
2154 | function fill(value/*, start, end*/) { | ||
2155 | var start = arguments[1], | ||
2156 | end = arguments[2]; | ||
2157 | |||
2158 | var o = ToObject(this); | ||
2159 | var lenVal = o.length; | ||
2160 | var len = ToLength(lenVal); | ||
2161 | len = max(len, 0); | ||
2162 | var relativeStart = ToInteger(start); | ||
2163 | var k; | ||
2164 | if (relativeStart < 0) k = max((len + relativeStart), 0); | ||
2165 | else k = min(relativeStart, len); | ||
2166 | var relativeEnd; | ||
2167 | if (end === undefined) relativeEnd = len; | ||
2168 | else relativeEnd = ToInteger(end); | ||
2169 | var final; | ||
2170 | if (relativeEnd < 0) final = max((len + relativeEnd), 0); | ||
2171 | else final = min(relativeEnd, len); | ||
2172 | while (k < final) { | ||
2173 | var pk = String(k); | ||
2174 | o[pk] = value; | ||
2175 | k += 1; | ||
2176 | } | ||
2177 | return o; | ||
2178 | }); | ||
2179 | |||
2180 | // 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) | ||
2181 | define( | ||
2182 | $TypedArray$.prototype, 'filter', | ||
2183 | function filter(callbackfn) { | ||
2184 | var thisArg = arguments[1]; | ||
2185 | |||
2186 | var o = ToObject(this); | ||
2187 | var lenVal = o.length; | ||
2188 | var len = ToLength(lenVal); | ||
2189 | if (!IsCallable(callbackfn)) throw TypeError(); | ||
2190 | var t = thisArg; | ||
2191 | var c = o.constructor; | ||
2192 | var kept = []; | ||
2193 | var k = 0; | ||
2194 | var captured = 0; | ||
2195 | while (k < len) { | ||
2196 | var kValue = o[k]; | ||
2197 | var selected = callbackfn.call(t, kValue, k, o); | ||
2198 | if (selected) { | ||
2199 | kept.push(kValue); | ||
2200 | ++captured; | ||
2201 | } | ||
2202 | ++k; | ||
2203 | } | ||
2204 | var a = new c(captured); | ||
2205 | var n = 0; | ||
2206 | for (var i = 0; i < kept.length; ++i) { | ||
2207 | var e = kept[i]; | ||
2208 | a[n] = e; | ||
2209 | ++n; | ||
2210 | } | ||
2211 | return a; | ||
2212 | }); | ||
2213 | |||
2214 | // 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) | ||
2215 | define($TypedArray$.prototype, 'find', Array.prototype.find); | ||
2216 | |||
2217 | // 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) | ||
2218 | define($TypedArray$.prototype, 'findIndex', Array.prototype.findIndex); | ||
2219 | |||
2220 | // 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) | ||
2221 | define($TypedArray$.prototype, 'forEach', Array.prototype.forEach); | ||
2222 | |||
2223 | // 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) | ||
2224 | define($TypedArray$.prototype, 'indexOf', Array.prototype.indexOf); | ||
2225 | |||
2226 | // 22.2.3.14 %TypedArray%.prototype.join ( separator ) | ||
2227 | define($TypedArray$.prototype, 'join', Array.prototype.join); | ||
2228 | |||
2229 | // 22.2.3.15 %TypedArray%.prototype.keys ( ) | ||
2230 | define($TypedArray$.prototype, 'keys', Array.prototype.keys); | ||
2231 | |||
2232 | // 22.2.3.16 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) | ||
2233 | define($TypedArray$.prototype, 'lastIndexOf', Array.prototype.lastIndexOf); | ||
2234 | |||
2235 | // 22.2.3.17 get %TypedArray%.prototype.length | ||
2236 | |||
2237 | // 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) | ||
2238 | define( | ||
2239 | $TypedArray$.prototype, 'map', | ||
2240 | function map(callbackfn) { | ||
2241 | var thisArg = arguments[1]; | ||
2242 | |||
2243 | var o = ToObject(this); | ||
2244 | var lenValue = o.length; | ||
2245 | var len = ToLength(lenValue); | ||
2246 | if (!IsCallable(callbackfn)) throw TypeError(); | ||
2247 | var t = thisArg; | ||
2248 | var a = undefined; | ||
2249 | var c = o.constructor; | ||
2250 | if (IsConstructor(c)) | ||
2251 | a = new c(len); | ||
2252 | if (a === undefined) | ||
2253 | a = new Array(len); | ||
2254 | var k = 0; | ||
2255 | while (k < len) { | ||
2256 | var kPresent = HasProperty(o, k); | ||
2257 | if (kPresent) { | ||
2258 | var kValue = o[k]; | ||
2259 | var mappedValue = callbackfn.call(t, kValue, k, o); | ||
2260 | a[k] = mappedValue; | ||
2261 | } | ||
2262 | ++k; | ||
2263 | } | ||
2264 | return a; | ||
2265 | }); | ||
2266 | |||
2267 | // 22.2.3.19 %TypedArray%.prototype.reduce ( callbackfn [, initialValue] ) | ||
2268 | define($TypedArray$.prototype, 'reduce', Array.prototype.reduce); | ||
2269 | |||
2270 | // 22.2.3.20 %TypedArray%.prototype.reduceRight ( callbackfn [, initialValue] ) | ||
2271 | define($TypedArray$.prototype, 'reduceRight', Array.prototype.reduceRight); | ||
2272 | |||
2273 | // 22.2.3.21 %TypedArray%.prototype.reverse ( ) | ||
2274 | define($TypedArray$.prototype, 'reverse', Array.prototype.reverse); | ||
2275 | |||
2276 | // 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ]) | ||
2277 | // 22.2.3.22.1 %TypedArray%.prototype.set (array [ , offset ] ) | ||
2278 | // 22.2.3.22.2 %TypedArray%.prototype.set(typedArray [, offset ] ) | ||
2279 | |||
2280 | // 22.2.3.23 %TypedArray%.prototype.slice ( start, end ) | ||
2281 | define( | ||
2282 | $TypedArray$.prototype, 'slice', | ||
2283 | function slice(start, end) { | ||
2284 | var o = ToObject(this); | ||
2285 | var lenVal = o.length; | ||
2286 | var len = ToLength(lenVal); | ||
2287 | var relativeStart = ToInteger(start); | ||
2288 | var k = (relativeStart < 0) ? max(len + relativeStart, 0) : min(relativeStart, len); | ||
2289 | var relativeEnd = (end === undefined) ? len : ToInteger(end); | ||
2290 | var final = (relativeEnd < 0) ? max(len + relativeEnd, 0) : min(relativeEnd, len); | ||
2291 | var count = final - k; | ||
2292 | var c = o.constructor; | ||
2293 | if (IsConstructor(c)) { | ||
2294 | var a = new c(count); | ||
2295 | } else { | ||
2296 | throw TypeError(); | ||
2297 | } | ||
2298 | var n = 0; | ||
2299 | while (k < final) { | ||
2300 | var kValue = o[k]; | ||
2301 | a[n] = kValue; | ||
2302 | ++k; | ||
2303 | ++n; | ||
2304 | } | ||
2305 | return a; | ||
2306 | }); | ||
2307 | |||
2308 | // 22.2.3.24 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) | ||
2309 | define($TypedArray$.prototype, 'some', Array.prototype.some); | ||
2310 | |||
2311 | // 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) | ||
2312 | define( | ||
2313 | $TypedArray$.prototype, 'sort', | ||
2314 | function sort() { | ||
2315 | var comparefn = arguments[0]; | ||
2316 | |||
2317 | function sortCompare(x, y) { | ||
2318 | console.assert(Type(x) === 'number' && Type(y) === 'number'); | ||
2319 | if (x !== x && y !== y) return +0; | ||
2320 | if (x !== x) return 1; | ||
2321 | if (y !== y) return -1; | ||
2322 | if (comparefn !== undefined) { | ||
2323 | return comparefn(x, y); | ||
2324 | } | ||
2325 | if (x < y) return -1; | ||
2326 | if (x > y) return 1; | ||
2327 | return +0; | ||
2328 | } | ||
2329 | return Array.prototype.sort.call(this, sortCompare); | ||
2330 | }); | ||
2331 | |||
2332 | // 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) | ||
2333 | // 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) | ||
2334 | // 22.2.3.28 %TypedArray%.prototype.toString ( ) | ||
2335 | |||
2336 | // 22.2.3.29 %TypedArray%.prototype.values ( ) | ||
2337 | define($TypedArray$.prototype, 'values', Array.prototype.values); | ||
2338 | |||
2339 | // 22.2.3.30 %TypedArray%.prototype [ @@iterator ] ( ) | ||
2340 | define( | ||
2341 | $TypedArray$.prototype, $$iterator, | ||
2342 | $TypedArray$.prototype.values | ||
2343 | ); | ||
2344 | |||
2345 | // 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ] | ||
2346 | define($TypedArray$.prototype, $$toStringTag, $TypedArrayName$); | ||
2347 | |||
2348 | // 22.2.4 The TypedArray Constructors | ||
2349 | // 22.2.4.1TypedArray( ... argumentsList) | ||
2350 | // 22.2.5 Properties of the TypedArray Constructors | ||
2351 | // 22.2.5.1 TypedArray.BYTES_PER_ELEMENT | ||
2352 | // 22.2.5.2 TypedArray.prototype | ||
2353 | // 22.2.6 Properties of TypedArray Prototype Objects | ||
2354 | // 22.2.6.1 TypedArray.prototype.BYTES_PER_ELEMENT | ||
2355 | // 22.2.6.2 TypedArray.prototype.constructor | ||
2356 | // 22.2.7 Properties of TypedArray Instances | ||
2357 | }); | ||
2358 | |||
2359 | // --------------------------------------- | ||
2360 | // 23 Keyed Collection | ||
2361 | // --------------------------------------- | ||
2362 | |||
2363 | // --------------------------------------- | ||
2364 | // 23.1 Map Objects | ||
2365 | // --------------------------------------- | ||
2366 | |||
2367 | (function() { | ||
2368 | // 23.1.1 The Map Constructor | ||
2369 | |||
2370 | // 23.1.1.1 Map ( [ iterable ] ) | ||
2371 | /** @constructor */ | ||
2372 | function Map(/*iterable*/) { | ||
2373 | var map = strict(this); | ||
2374 | var iterable = arguments[0]; | ||
2375 | |||
2376 | if (Type(map) !== 'object') throw TypeError(); | ||
2377 | if ('[[MapData]]' in map) throw TypeError(); | ||
2378 | |||
2379 | if (iterable !== undefined) { | ||
2380 | var adder = map['set']; | ||
2381 | if (!IsCallable(adder)) throw TypeError(); | ||
2382 | var iter = GetIterator(ToObject(iterable)); | ||
2383 | } | ||
2384 | set_internal(map, '[[MapData]]', { keys: [], values: [] }); | ||
2385 | if (iter === undefined) return map; | ||
2386 | while (true) { | ||
2387 | var next = IteratorStep(iter); | ||
2388 | if (next === false) | ||
2389 | return map; | ||
2390 | var nextItem = IteratorValue(next); | ||
2391 | if (Type(nextItem) !== 'object') throw TypeError(); | ||
2392 | var k = nextItem[0]; | ||
2393 | var v = nextItem[1]; | ||
2394 | adder.call(map, k, v); | ||
2395 | } | ||
2396 | |||
2397 | return map; | ||
2398 | } | ||
2399 | |||
2400 | if (!('Map' in global) || OVERRIDE_NATIVE_FOR_TESTING || | ||
2401 | (function() { try { new global.Map([]); return false; } catch (_) { return true; } }()) || | ||
2402 | (function() { try { return !new global.Map().entries().next; } catch (_) { return true; } }()) || | ||
2403 | (new global.Map([['a', 1]]).size !== 1)) | ||
2404 | global.Map = Map; | ||
2405 | |||
2406 | |||
2407 | function MapDataIndexOf(mapData, key) { | ||
2408 | var i; | ||
2409 | if (key === key) return mapData.keys.indexOf(key); | ||
2410 | // Slow case for NaN | ||
2411 | for (i = 0; i < mapData.keys.length; i += 1) | ||
2412 | if (SameValueZero(mapData.keys[i], key)) return i; | ||
2413 | return -1; | ||
2414 | } | ||
2415 | |||
2416 | // 23.1.1.2 new Map ( ... argumentsList ) | ||
2417 | // 23.1.2 Properties of the Map Constructor | ||
2418 | // 23.1.2.1 Map.prototype | ||
2419 | var $MapPrototype$ = {}; | ||
2420 | Map.prototype = $MapPrototype$; | ||
2421 | |||
2422 | // 23.1.2.2 get Map [ @@species ] | ||
2423 | |||
2424 | // 23.1.3 Properties of the Map Prototype Object | ||
2425 | // 23.1.3.1 Map.prototype.clear () | ||
2426 | define( | ||
2427 | Map.prototype, 'clear', | ||
2428 | function clear() { | ||
2429 | var m = strict(this); | ||
2430 | if (Type(m) !== 'object') throw TypeError(); | ||
2431 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2432 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2433 | var entries = m['[[MapData]]']; | ||
2434 | entries.keys.length = 0; | ||
2435 | entries.values.length = 0; | ||
2436 | return undefined; | ||
2437 | }); | ||
2438 | |||
2439 | // 23.1.3.2 Map.prototype.constructor | ||
2440 | |||
2441 | // 23.1.3.3 Map.prototype.delete ( key ) | ||
2442 | define( | ||
2443 | Map.prototype, 'delete', | ||
2444 | function delete_(key) { | ||
2445 | var m = strict(this); | ||
2446 | if (Type(m) !== 'object') throw TypeError(); | ||
2447 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2448 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2449 | var entries = m['[[MapData]]']; | ||
2450 | var i = MapDataIndexOf(entries, key); | ||
2451 | if (i < 0) return false; | ||
2452 | entries.keys[i] = empty; | ||
2453 | entries.values[i] = empty; | ||
2454 | return true; | ||
2455 | }); | ||
2456 | |||
2457 | // 23.1.3.4 Map.prototype.entries ( ) | ||
2458 | define( | ||
2459 | Map.prototype, 'entries', | ||
2460 | function entries() { | ||
2461 | var m = strict(this); | ||
2462 | if (Type(m) !== 'object') throw TypeError(); | ||
2463 | return CreateMapIterator(m, 'key+value'); | ||
2464 | }); | ||
2465 | |||
2466 | // 23.1.3.5 Map.prototype.forEach ( callbackfn [ , thisArg ] ) | ||
2467 | define( | ||
2468 | Map.prototype, 'forEach', | ||
2469 | function forEach(callbackfn /*, thisArg*/) { | ||
2470 | var thisArg = arguments[1]; | ||
2471 | |||
2472 | var m = strict(this); | ||
2473 | if (Type(m) !== 'object') throw TypeError(); | ||
2474 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2475 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2476 | var entries = m['[[MapData]]']; | ||
2477 | |||
2478 | if (!IsCallable(callbackfn)) { | ||
2479 | throw TypeError('First argument to forEach is not callable.'); | ||
2480 | } | ||
2481 | for (var i = 0; i < entries.keys.length; ++i) { | ||
2482 | if (entries.keys[i] !== empty) { | ||
2483 | callbackfn.call(thisArg, entries.values[i], entries.keys[i], m); | ||
2484 | } | ||
2485 | } | ||
2486 | return undefined; | ||
2487 | }); | ||
2488 | |||
2489 | // 23.1.3.6 Map.prototype.get ( key ) | ||
2490 | define( | ||
2491 | Map.prototype, 'get', | ||
2492 | function get(key) { | ||
2493 | var m = strict(this); | ||
2494 | if (Type(m) !== 'object') throw TypeError(); | ||
2495 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2496 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2497 | var entries = m['[[MapData]]']; | ||
2498 | var i = MapDataIndexOf(entries, key); | ||
2499 | if (i >= 0) return entries.values[i]; | ||
2500 | return undefined; | ||
2501 | }); | ||
2502 | |||
2503 | // 23.1.3.7 Map.prototype.has ( key ) | ||
2504 | define( | ||
2505 | Map.prototype, 'has', | ||
2506 | function has(key) { | ||
2507 | var m = strict(this); | ||
2508 | if (Type(m) !== 'object') throw TypeError(); | ||
2509 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2510 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2511 | var entries = m['[[MapData]]']; | ||
2512 | if (MapDataIndexOf(entries, key) >= 0) return true; | ||
2513 | return false; | ||
2514 | }); | ||
2515 | |||
2516 | // 23.1.3.8 Map.prototype.keys ( ) | ||
2517 | define( | ||
2518 | Map.prototype, 'keys', | ||
2519 | function keys() { | ||
2520 | var m = strict(this); | ||
2521 | if (Type(m) !== 'object') throw TypeError(); | ||
2522 | return CreateMapIterator(m, 'key'); | ||
2523 | }); | ||
2524 | |||
2525 | // 23.1.3.9 Map.prototype.set ( key , value ) | ||
2526 | define( | ||
2527 | Map.prototype, 'set', | ||
2528 | function set(key, value) { | ||
2529 | var m = strict(this); | ||
2530 | if (Type(m) !== 'object') throw TypeError(); | ||
2531 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2532 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2533 | var entries = m['[[MapData]]']; | ||
2534 | var i = MapDataIndexOf(entries, key); | ||
2535 | if (i < 0) i = entries.keys.length; | ||
2536 | if (SameValue(key, -0)) key = 0; | ||
2537 | entries.keys[i] = key; | ||
2538 | entries.values[i] = value; | ||
2539 | return m; | ||
2540 | }); | ||
2541 | |||
2542 | // 23.1.3.10 get Map.prototype.size | ||
2543 | Object.defineProperty( | ||
2544 | Map.prototype, 'size', { | ||
2545 | get: function() { | ||
2546 | var m = strict(this); | ||
2547 | if (Type(m) !== 'object') throw TypeError(); | ||
2548 | if (!('[[MapData]]' in m)) throw TypeError(); | ||
2549 | if (m['[[MapData]]'] === undefined) throw TypeError(); | ||
2550 | var entries = m['[[MapData]]']; | ||
2551 | var count = 0; | ||
2552 | for (var i = 0; i < entries.keys.length; ++i) { | ||
2553 | if (entries.keys[i] !== empty) | ||
2554 | count = count + 1; | ||
2555 | } | ||
2556 | return count; | ||
2557 | } | ||
2558 | }); | ||
2559 | |||
2560 | // 23.1.3.11 Map.prototype.values ( ) | ||
2561 | define( | ||
2562 | Map.prototype, 'values', | ||
2563 | function values() { | ||
2564 | var m = strict(this); | ||
2565 | if (Type(m) !== 'object') throw TypeError(); | ||
2566 | return CreateMapIterator(m, 'value'); | ||
2567 | }); | ||
2568 | |||
2569 | // 23.1.3.12 Map.prototype [ @@iterator ]( ) | ||
2570 | define( | ||
2571 | Map.prototype, $$iterator, | ||
2572 | function() { | ||
2573 | var m = strict(this); | ||
2574 | if (Type(m) !== 'object') throw TypeError(); | ||
2575 | return CreateMapIterator(m, 'key+value'); | ||
2576 | }); | ||
2577 | |||
2578 | // 23.1.3.13 Map.prototype [ @@toStringTag ] | ||
2579 | define(global.Map.prototype, $$toStringTag, 'Map'); | ||
2580 | |||
2581 | // 23.1.4 Properties of Map Instances | ||
2582 | // 23.1.5 Map Iterator Objects | ||
2583 | |||
2584 | /** @constructor */ | ||
2585 | function MapIterator() {} | ||
2586 | |||
2587 | // 23.1.5.1 CreateMapIterator Abstract Operation | ||
2588 | function CreateMapIterator(map, kind) { | ||
2589 | if (Type(map) !== 'object') throw TypeError(); | ||
2590 | if (!('[[MapData]]' in map)) throw TypeError(); | ||
2591 | if (map['[[MapData]]'] === undefined) throw TypeError(); | ||
2592 | var iterator = new MapIterator; | ||
2593 | set_internal(iterator, '[[Map]]', map); | ||
2594 | set_internal(iterator, '[[MapNextIndex]]', 0); | ||
2595 | set_internal(iterator, '[[MapIterationKind]]', kind); | ||
2596 | return iterator; | ||
2597 | } | ||
2598 | |||
2599 | // 23.1.5.2 The %MapIteratorPrototype% Object | ||
2600 | var $MapIteratorPrototype$ = Object.create($IteratorPrototype$); | ||
2601 | MapIterator.prototype = $MapIteratorPrototype$; | ||
2602 | |||
2603 | // 23.1.5.2.1 %MapIteratorPrototype%.next ( ) | ||
2604 | define( | ||
2605 | $MapIteratorPrototype$, 'next', | ||
2606 | function next() { | ||
2607 | var o = strict(this); | ||
2608 | if (Type(o) !== 'object') throw TypeError(); | ||
2609 | var m = o['[[Map]]'], | ||
2610 | index = o['[[MapNextIndex]]'], | ||
2611 | itemKind = o['[[MapIterationKind]]'], | ||
2612 | entries = m['[[MapData]]']; | ||
2613 | while (index < entries.keys.length) { | ||
2614 | var e = {key: entries.keys[index], value: entries.values[index]}; | ||
2615 | index = index += 1; | ||
2616 | set_internal(o, '[[MapNextIndex]]', index); | ||
2617 | if (e.key !== empty) { | ||
2618 | if (itemKind === 'key') { | ||
2619 | return CreateIterResultObject(e.key, false); | ||
2620 | } else if (itemKind === 'value') { | ||
2621 | return CreateIterResultObject(e.value, false); | ||
2622 | } else { | ||
2623 | return CreateIterResultObject([e.key, e.value], false); | ||
2624 | } | ||
2625 | } | ||
2626 | } | ||
2627 | return CreateIterResultObject(undefined, true); | ||
2628 | }); | ||
2629 | |||
2630 | // 23.1.5.2.2 %MapIteratorPrototype% [ @@toStringTag ] | ||
2631 | define($MapIteratorPrototype$, $$toStringTag, 'Map Iterator'); | ||
2632 | |||
2633 | // 23.1.5.3 Properties of Map Iterator Instances | ||
2634 | }()); | ||
2635 | |||
2636 | // --------------------------------------- | ||
2637 | // 23.2 Set Objects | ||
2638 | // --------------------------------------- | ||
2639 | |||
2640 | (function() { | ||
2641 | // 23.2.1 The Set Constructor | ||
2642 | // 23.2.1.1 Set ( [ iterable ] ) | ||
2643 | |||
2644 | /** @constructor */ | ||
2645 | function Set(/*iterable*/) { | ||
2646 | var set = strict(this); | ||
2647 | var iterable = arguments[0]; | ||
2648 | |||
2649 | if (Type(set) !== 'object') throw TypeError(); | ||
2650 | if ('[[SetData]]' in set) throw TypeError(); | ||
2651 | |||
2652 | if (iterable !== undefined) { | ||
2653 | var adder = set['add']; | ||
2654 | if (!IsCallable(adder)) throw TypeError(); | ||
2655 | var iter = GetIterator(ToObject(iterable)); | ||
2656 | } | ||
2657 | set_internal(set, '[[SetData]]', []); | ||
2658 | if (iter === undefined) return set; | ||
2659 | while (true) { | ||
2660 | var next = IteratorStep(iter); | ||
2661 | if (next === false) | ||
2662 | return set; | ||
2663 | var nextValue = IteratorValue(next); | ||
2664 | adder.call(set, nextValue); | ||
2665 | } | ||
2666 | |||
2667 | return set; | ||
2668 | } | ||
2669 | |||
2670 | if (!('Set' in global) || OVERRIDE_NATIVE_FOR_TESTING || | ||
2671 | (function() { try { return !new global.Set().entries().next; } catch (_) { return true; } }()) || | ||
2672 | (new global.Set([1]).size !== 1)) | ||
2673 | global.Set = Set; | ||
2674 | |||
2675 | function SetDataIndexOf(setData, key) { | ||
2676 | var i; | ||
2677 | if (key === key) | ||
2678 | return setData.indexOf(key); | ||
2679 | // Slow case for NaN | ||
2680 | for (i = 0; i < setData.length; i += 1) | ||
2681 | if (SameValueZero(setData[i], key)) return i; | ||
2682 | return -1; | ||
2683 | } | ||
2684 | |||
2685 | // 23.2.1.2 new Set ( ...argumentsList ) | ||
2686 | // 23.2.2 Properties of the Set Constructor | ||
2687 | |||
2688 | // 23.2.2.1 Set.prototype | ||
2689 | var $SetPrototype$ = {}; | ||
2690 | Set.prototype = $SetPrototype$; | ||
2691 | |||
2692 | // 23.2.2.2 get Set [ @@species ] | ||
2693 | // 23.2.3 Properties of the Set Prototype Object | ||
2694 | |||
2695 | // 23.2.3.1 Set.prototype.add (value ) | ||
2696 | define( | ||
2697 | Set.prototype, 'add', | ||
2698 | function add(value) { | ||
2699 | var s = strict(this); | ||
2700 | if (Type(s) !== 'object') throw TypeError(); | ||
2701 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2702 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2703 | if (SameValue(value, -0)) value = 0; | ||
2704 | var entries = s['[[SetData]]']; | ||
2705 | var i = SetDataIndexOf(entries, value); | ||
2706 | if (i < 0) i = s['[[SetData]]'].length; | ||
2707 | s['[[SetData]]'][i] = value; | ||
2708 | |||
2709 | return s; | ||
2710 | }); | ||
2711 | |||
2712 | // 23.2.3.2 Set.prototype.clear () | ||
2713 | define( | ||
2714 | Set.prototype, 'clear', | ||
2715 | function clear() { | ||
2716 | var s = strict(this); | ||
2717 | if (Type(s) !== 'object') throw TypeError(); | ||
2718 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2719 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2720 | var entries = s['[[SetData]]']; | ||
2721 | entries.length = 0; | ||
2722 | return undefined; | ||
2723 | }); | ||
2724 | |||
2725 | // 23.2.3.3 Set.prototype.constructor | ||
2726 | // 23.2.3.4 Set.prototype.delete ( value ) | ||
2727 | define( | ||
2728 | Set.prototype, 'delete', | ||
2729 | function delete_(value) { | ||
2730 | var s = strict(this); | ||
2731 | if (Type(s) !== 'object') throw TypeError(); | ||
2732 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2733 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2734 | var entries = s['[[SetData]]']; | ||
2735 | var i = SetDataIndexOf(entries, value); | ||
2736 | if (i < 0) return false; | ||
2737 | entries[i] = empty; | ||
2738 | return true; | ||
2739 | }); | ||
2740 | |||
2741 | // 23.2.3.5 Set.prototype.entries ( ) | ||
2742 | define( | ||
2743 | Set.prototype, 'entries', | ||
2744 | function entries() { | ||
2745 | var s = strict(this); | ||
2746 | if (Type(s) !== 'object') throw TypeError(); | ||
2747 | return CreateSetIterator(s, 'key+value'); | ||
2748 | }); | ||
2749 | |||
2750 | // 23.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] ) | ||
2751 | define( | ||
2752 | Set.prototype, 'forEach', | ||
2753 | function forEach(callbackfn/*, thisArg*/) { | ||
2754 | var thisArg = arguments[1]; | ||
2755 | |||
2756 | var s = strict(this); | ||
2757 | if (Type(s) !== 'object') throw TypeError(); | ||
2758 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2759 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2760 | var entries = s['[[SetData]]']; | ||
2761 | |||
2762 | if (!IsCallable(callbackfn)) { | ||
2763 | throw TypeError('First argument to forEach is not callable.'); | ||
2764 | } | ||
2765 | for (var i = 0; i < entries.length; ++i) { | ||
2766 | if (entries[i] !== empty) { | ||
2767 | callbackfn.call(thisArg, entries[i], entries[i], s); | ||
2768 | } | ||
2769 | } | ||
2770 | }); | ||
2771 | |||
2772 | // 23.2.3.7 Set.prototype.has ( value ) | ||
2773 | define( | ||
2774 | Set.prototype, 'has', | ||
2775 | function has(key) { | ||
2776 | var s = strict(this); | ||
2777 | if (Type(s) !== 'object') throw TypeError(); | ||
2778 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2779 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2780 | var entries = s['[[SetData]]']; | ||
2781 | return SetDataIndexOf(entries, key) !== -1; | ||
2782 | }); | ||
2783 | |||
2784 | // 23.2.3.8 Set.prototype.keys ( ) | ||
2785 | // See Set.prototype.values | ||
2786 | |||
2787 | // 23.2.3.9 get Set.prototype.size | ||
2788 | Object.defineProperty( | ||
2789 | Set.prototype, 'size', { | ||
2790 | get: function() { | ||
2791 | var s = strict(this); | ||
2792 | if (Type(s) !== 'object') throw TypeError(); | ||
2793 | if (!('[[SetData]]' in s)) throw TypeError(); | ||
2794 | if (s['[[SetData]]'] === undefined) throw TypeError(); | ||
2795 | var entries = s['[[SetData]]']; | ||
2796 | var count = 0; | ||
2797 | for (var i = 0; i < entries.length; ++i) { | ||
2798 | if (entries[i] !== empty) | ||
2799 | count = count + 1; | ||
2800 | } | ||
2801 | return count; | ||
2802 | } | ||
2803 | }); | ||
2804 | |||
2805 | // 23.2.3.10 Set.prototype.values ( ) | ||
2806 | define( | ||
2807 | Set.prototype, 'values', | ||
2808 | function values() { | ||
2809 | var s = strict(this); | ||
2810 | if (Type(s) !== 'object') throw TypeError(); | ||
2811 | return CreateSetIterator(s, 'value'); | ||
2812 | }); | ||
2813 | // NOTE: function name is still 'values': | ||
2814 | Set.prototype.keys = Set.prototype.values; | ||
2815 | |||
2816 | // 23.2.3.11 Set.prototype [@@iterator ] ( ) | ||
2817 | define( | ||
2818 | Set.prototype, $$iterator, | ||
2819 | function() { | ||
2820 | var s = strict(this); | ||
2821 | if (Type(s) !== 'object') throw TypeError(); | ||
2822 | return CreateSetIterator(s); | ||
2823 | }); | ||
2824 | |||
2825 | // 23.2.3.12 Set.prototype [ @@toStringTag ] | ||
2826 | define(global.Set.prototype, $$toStringTag, 'Set'); | ||
2827 | |||
2828 | // 23.2.4 Properties of Set Instances | ||
2829 | // 23.2.5 Set Iterator Objects | ||
2830 | /** @constructor */ | ||
2831 | function SetIterator() {} | ||
2832 | |||
2833 | // 23.2.5.1 CreateSetIterator Abstract Operation | ||
2834 | function CreateSetIterator(set, kind) { | ||
2835 | if (Type(set) !== 'object') throw TypeError(); | ||
2836 | if (!('[[SetData]]' in set)) throw TypeError(); | ||
2837 | if (set['[[SetData]]'] === undefined) throw TypeError(); | ||
2838 | var iterator = new SetIterator; | ||
2839 | set_internal(iterator, '[[IteratedSet]]', set); | ||
2840 | set_internal(iterator, '[[SetNextIndex]]', 0); | ||
2841 | set_internal(iterator, '[[SetIterationKind]]', kind); | ||
2842 | return iterator; | ||
2843 | } | ||
2844 | |||
2845 | // 23.2.5.2 The %SetIteratorPrototype% Object | ||
2846 | var $SetIteratorPrototype$ = Object.create($IteratorPrototype$); | ||
2847 | SetIterator.prototype = $SetIteratorPrototype$; | ||
2848 | |||
2849 | // 23.2.5.2.1 %SetIteratorPrototype%.next( ) | ||
2850 | define( | ||
2851 | $SetIteratorPrototype$, 'next', | ||
2852 | function next() { | ||
2853 | var o = strict(this); | ||
2854 | if (Type(o) !== 'object') throw TypeError(); | ||
2855 | var s = o['[[IteratedSet]]'], | ||
2856 | index = o['[[SetNextIndex]]'], | ||
2857 | itemKind = o['[[SetIterationKind]]'], | ||
2858 | entries = s['[[SetData]]']; | ||
2859 | while (index < entries.length) { | ||
2860 | var e = entries[index]; | ||
2861 | index = index += 1; | ||
2862 | set_internal(o, '[[SetNextIndex]]', index); | ||
2863 | if (e !== empty) { | ||
2864 | if (itemKind === 'key+value') | ||
2865 | return CreateIterResultObject([e, e], false); | ||
2866 | return CreateIterResultObject(e, false); | ||
2867 | } | ||
2868 | } | ||
2869 | return CreateIterResultObject(undefined, true); | ||
2870 | }); | ||
2871 | |||
2872 | // 23.2.5.2.2 %SetIteratorPrototype% [ @@toStringTag ] | ||
2873 | define($SetIteratorPrototype$, $$toStringTag, 'Set Iterator'); | ||
2874 | |||
2875 | // 23.2.5.3 Properties of Set Iterator Instances | ||
2876 | |||
2877 | }()); | ||
2878 | |||
2879 | // --------------------------------------- | ||
2880 | // 23.3 WeakMap Objects | ||
2881 | // --------------------------------------- | ||
2882 | |||
2883 | (function() { | ||
2884 | // 23.3.1 The WeakMap Constructor | ||
2885 | // 23.3.1.1 WeakMap ( [ iterable ] ) | ||
2886 | /** @constructor */ | ||
2887 | function WeakMap(/*iterable*/) { | ||
2888 | var map = strict(this); | ||
2889 | var iterable = arguments[0]; | ||
2890 | |||
2891 | if (Type(map) !== 'object') throw TypeError(); | ||
2892 | if ('[[WeakMapData]]' in map) throw TypeError(); | ||
2893 | |||
2894 | if (iterable !== undefined) { | ||
2895 | var adder = map['set']; | ||
2896 | if (!IsCallable(adder)) throw TypeError(); | ||
2897 | var iter = GetIterator(ToObject(iterable)); | ||
2898 | } | ||
2899 | set_internal(map, '[[WeakMapData]]', new EphemeronTable); | ||
2900 | if (iter === undefined) return map; | ||
2901 | while (true) { | ||
2902 | var next = IteratorStep(iter); | ||
2903 | if (next === false) | ||
2904 | return map; | ||
2905 | var nextValue = IteratorValue(next); | ||
2906 | if (Type(nextValue) !== 'object') throw TypeError(); | ||
2907 | var k = nextValue[0]; | ||
2908 | var v = nextValue[1]; | ||
2909 | adder.call(map, k, v); | ||
2910 | } | ||
2911 | |||
2912 | return map; | ||
2913 | } | ||
2914 | |||
2915 | if (!('WeakMap' in global) || OVERRIDE_NATIVE_FOR_TESTING) | ||
2916 | global.WeakMap = WeakMap; | ||
2917 | |||
2918 | // 23.3.2 Properties of the WeakMap Constructor | ||
2919 | // 23.3.2.1 WeakMap.prototype | ||
2920 | var $WeakMapPrototype$ = {}; | ||
2921 | WeakMap.prototype = $WeakMapPrototype$; | ||
2922 | |||
2923 | |||
2924 | |||
2925 | // 23.3.2.2 WeakMap[ @@create ] ( ) | ||
2926 | // 23.3.3 Properties of the WeakMap Prototype Object | ||
2927 | |||
2928 | // 23.3.3.1 WeakMap.prototype.constructor | ||
2929 | |||
2930 | // 23.3.3.2 WeakMap.prototype.delete ( key ) | ||
2931 | define( | ||
2932 | WeakMap.prototype, 'delete', | ||
2933 | function delete_(key) { | ||
2934 | var M = strict(this); | ||
2935 | if (Type(M) !== 'object') throw TypeError(); | ||
2936 | if (M['[[WeakMapData]]'] === undefined) throw TypeError(); | ||
2937 | if (Type(key) !== 'object') throw TypeError('Expected object'); | ||
2938 | return M['[[WeakMapData]]'].remove(key); | ||
2939 | }); | ||
2940 | |||
2941 | // 23.3.3.3 WeakMap.prototype.get ( key ) | ||
2942 | define( | ||
2943 | WeakMap.prototype, 'get', | ||
2944 | function get(key, defaultValue) { | ||
2945 | var M = strict(this); | ||
2946 | if (Type(M) !== 'object') throw TypeError(); | ||
2947 | if (M['[[WeakMapData]]'] === undefined) throw TypeError(); | ||
2948 | if (Type(key) !== 'object') throw TypeError('Expected object'); | ||
2949 | return M['[[WeakMapData]]'].get(key, defaultValue); | ||
2950 | }); | ||
2951 | |||
2952 | // 23.3.3.4 WeakMap.prototype.has ( key ) | ||
2953 | define( | ||
2954 | WeakMap.prototype, 'has', | ||
2955 | function has(key) { | ||
2956 | var M = strict(this); | ||
2957 | if (Type(M) !== 'object') throw TypeError(); | ||
2958 | if (M['[[WeakMapData]]'] === undefined) throw TypeError(); | ||
2959 | if (Type(key) !== 'object') throw TypeError('Expected object'); | ||
2960 | return M['[[WeakMapData]]'].has(key); | ||
2961 | }); | ||
2962 | |||
2963 | // 23.3.3.5 WeakMap.prototype.set ( key , value ) | ||
2964 | define( | ||
2965 | WeakMap.prototype, 'set', | ||
2966 | function set(key, value) { | ||
2967 | var M = strict(this); | ||
2968 | if (Type(M) !== 'object') throw TypeError(); | ||
2969 | if (M['[[WeakMapData]]'] === undefined) throw TypeError(); | ||
2970 | if (Type(key) !== 'object') throw TypeError('Expected object'); | ||
2971 | M['[[WeakMapData]]'].set(key, value); | ||
2972 | return M; | ||
2973 | }); | ||
2974 | |||
2975 | // 23.3.3.6 WeakMap.prototype [ @@toStringTag ] | ||
2976 | define(global.WeakMap.prototype, $$toStringTag, 'WeakMap'); | ||
2977 | |||
2978 | // 23.3.4 Properties of WeakMap Instances | ||
2979 | |||
2980 | // Polyfills for incomplete native implementations: | ||
2981 | (function() { | ||
2982 | var wm = new global.WeakMap(); | ||
2983 | var orig = global.WeakMap.prototype.set; | ||
2984 | define(global.WeakMap.prototype, 'set', function set() { | ||
2985 | orig.apply(this, arguments); | ||
2986 | return this; | ||
2987 | }, wm.set({}, 0) !== wm); | ||
2988 | }()); | ||
2989 | }()); | ||
2990 | |||
2991 | // --------------------------------------- | ||
2992 | // 23.4 WeakSet Objects | ||
2993 | // --------------------------------------- | ||
2994 | |||
2995 | (function() { | ||
2996 | // 23.4.1 The WeakSet Constructor | ||
2997 | // 23.4.1.1 WeakSet ( [ iterable ] ) | ||
2998 | /** @constructor */ | ||
2999 | function WeakSet(/*iterable*/) { | ||
3000 | var set = strict(this); | ||
3001 | var iterable = arguments[0]; | ||
3002 | |||
3003 | if (Type(set) !== 'object') throw TypeError(); | ||
3004 | if ('[[WeakSetData]]' in set) throw TypeError(); | ||
3005 | |||
3006 | if (iterable !== undefined) { | ||
3007 | var adder = set['add']; | ||
3008 | if (!IsCallable(adder)) throw TypeError(); | ||
3009 | var iter = GetIterator(ToObject(iterable)); | ||
3010 | } | ||
3011 | set_internal(set, '[[WeakSetData]]', new EphemeronTable); | ||
3012 | if (iter === undefined) return set; | ||
3013 | while (true) { | ||
3014 | var next = IteratorStep(iter); | ||
3015 | if (next === false) | ||
3016 | return set; | ||
3017 | var nextValue = IteratorValue(next); | ||
3018 | adder.call(set, nextValue); | ||
3019 | } | ||
3020 | |||
3021 | return set; | ||
3022 | } | ||
3023 | |||
3024 | if (!('WeakSet' in global) || OVERRIDE_NATIVE_FOR_TESTING) | ||
3025 | global.WeakSet = WeakSet; | ||
3026 | |||
3027 | // 23.4.2 Properties of the WeakSet Constructor | ||
3028 | // 23.4.2.1 WeakSet.prototype | ||
3029 | var $WeakSetPrototype$ = {}; | ||
3030 | WeakSet.prototype = $WeakSetPrototype$; | ||
3031 | |||
3032 | // 23.4.3 Properties of the WeakSet Prototype Object | ||
3033 | // 23.4.3.1 WeakSet.prototype.add (value ) | ||
3034 | define( | ||
3035 | WeakSet.prototype, 'add', | ||
3036 | function add(value) { | ||
3037 | var S = strict(this); | ||
3038 | if (Type(S) !== 'object') throw TypeError(); | ||
3039 | if (S['[[WeakSetData]]'] === undefined) throw TypeError(); | ||
3040 | if (Type(value) !== 'object') throw TypeError('Expected object'); | ||
3041 | S['[[WeakSetData]]'].set(value, true); | ||
3042 | return S; | ||
3043 | }); | ||
3044 | |||
3045 | // 23.4.3.2 WeakSet.prototype.constructor | ||
3046 | // 23.4.3.3 WeakSet.prototype.delete ( value ) | ||
3047 | define( | ||
3048 | WeakSet.prototype, 'delete', | ||
3049 | function delete_(value) { | ||
3050 | var S = strict(this); | ||
3051 | if (Type(S) !== 'object') throw TypeError(); | ||
3052 | if (S['[[WeakSetData]]'] === undefined) throw TypeError(); | ||
3053 | if (Type(value) !== 'object') throw TypeError('Expected object'); | ||
3054 | return S['[[WeakSetData]]'].remove(value); | ||
3055 | }); | ||
3056 | |||
3057 | // 23.4.3.4 WeakSet.prototype.has ( value ) | ||
3058 | define( | ||
3059 | WeakSet.prototype, 'has', | ||
3060 | function has(key) { | ||
3061 | var S = strict(this); | ||
3062 | if (Type(S) !== 'object') throw TypeError(); | ||
3063 | if (S['[[WeakSetData]]'] === undefined) throw TypeError(); | ||
3064 | if (Type(key) !== 'object') throw TypeError('Expected object'); | ||
3065 | return S['[[WeakSetData]]'].has(key); | ||
3066 | }); | ||
3067 | |||
3068 | // 23.4.3.5 WeakSet.prototype [ @@toStringTag ] | ||
3069 | define(global.WeakSet.prototype, $$toStringTag, 'WeakSet'); | ||
3070 | |||
3071 | // 23.4.4 Properties of WeakSet Instances | ||
3072 | |||
3073 | // Polyfills for incomplete native implementations: | ||
3074 | (function() { | ||
3075 | var ws = new global.WeakSet(); | ||
3076 | var orig = global.WeakSet.prototype.add; | ||
3077 | define(global.WeakSet.prototype, 'add', function add() { | ||
3078 | orig.apply(this, arguments); | ||
3079 | return this; | ||
3080 | }, ws.add({}) !== ws); | ||
3081 | }()); | ||
3082 | }()); | ||
3083 | |||
3084 | // --------------------------------------- | ||
3085 | // 24 Structured Data | ||
3086 | // --------------------------------------- | ||
3087 | |||
3088 | // --------------------------------------- | ||
3089 | // 24.1 ArrayBuffer Objects | ||
3090 | // --------------------------------------- | ||
3091 | |||
3092 | // See typedarray.js for TypedArray polyfill | ||
3093 | |||
3094 | (function() { | ||
3095 | if (!('ArrayBuffer' in global)) | ||
3096 | return; | ||
3097 | |||
3098 | // 24.1.1 Abstract Operations For ArrayBuffer Objects | ||
3099 | // 24.1.1.1 AllocateArrayBuffer( constructor, byteLength ) | ||
3100 | // 24.1.1.2 IsDetachedBuffer( arrayBuffer ) | ||
3101 | // 24.1.1.3 DetachArrayBuffer( arrayBuffer ) | ||
3102 | // 24.1.1.4 CloneArrayBuffer( srcBuffer, srcByteOffset [, cloneConstructor] ) | ||
3103 | // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian ) | ||
3104 | // 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isLittleEndian ) | ||
3105 | // 24.1.2 The ArrayBuffer Constructor | ||
3106 | // 24.1.2.1 ArrayBuffer( length ) | ||
3107 | // 24.1.3 Properties of the ArrayBuffer Constructor | ||
3108 | |||
3109 | // 24.1.3.1 ArrayBuffer.isView ( arg ) | ||
3110 | define( | ||
3111 | ArrayBuffer, 'isView', | ||
3112 | function isView(arg) { | ||
3113 | if (Type(arg) !== 'object') return false; | ||
3114 | if ('buffer' in arg && arg.buffer instanceof ArrayBuffer) return true; | ||
3115 | return false; | ||
3116 | }); | ||
3117 | |||
3118 | // 24.1.3.2 ArrayBuffer.prototype | ||
3119 | // 24.1.3.3 get ArrayBuffer [ @@species ] | ||
3120 | // 24.1.4 Properties of the ArrayBuffer Prototype Object | ||
3121 | // 24.1.4.1 get ArrayBuffer.prototype.byteLength | ||
3122 | // 24.1.4.2 ArrayBuffer.prototype.constructor | ||
3123 | // 24.1.4.3 ArrayBuffer.prototype.slice ( start , end) | ||
3124 | |||
3125 | // 24.1.4.4 ArrayBuffer.prototype [ @@toStringTag ] | ||
3126 | define(ArrayBuffer.prototype, $$toStringTag, 'ArrayBuffer'); | ||
3127 | |||
3128 | // 24.1.5 Properties of the ArrayBuffer Instances | ||
3129 | }()); | ||
3130 | |||
3131 | // --------------------------------------- | ||
3132 | // 24.2 DataView Objects | ||
3133 | // --------------------------------------- | ||
3134 | |||
3135 | // See typedarray.js for TypedArray polyfill | ||
3136 | |||
3137 | (function() { | ||
3138 | if (!('DataView' in global)) | ||
3139 | return; | ||
3140 | |||
3141 | // 24.2.1 Abstract Operations For DataView Objects | ||
3142 | // 24.2.1.1 GetViewValue(view, requestIndex, isLittleEndian, type) | ||
3143 | // 24.2.1.2 SetViewValue(view, requestIndex, isLittleEndian, type, value) | ||
3144 | // 24.2.2 The DataView Constructor | ||
3145 | // 24.2.2.1 DataView (buffer [ , byteOffset [ , byteLength ] ] ) | ||
3146 | // 24.2.3 Properties of the DataView Constructor | ||
3147 | // 24.2.3.1 DataView.prototype | ||
3148 | // 24.2.4 Properties of the DataView Prototype Object | ||
3149 | // 24.2.4.1 get DataView.prototype.buffer | ||
3150 | // 24.2.4.2 get DataView.prototype.byteLength | ||
3151 | // 24.2.4.3 get DataView.prototype.byteOffset | ||
3152 | // 24.2.4.4 DataView.prototype.constructor | ||
3153 | // 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) | ||
3154 | // 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) | ||
3155 | // 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) | ||
3156 | // 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) | ||
3157 | // 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) | ||
3158 | // 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) | ||
3159 | // 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) | ||
3160 | // 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) | ||
3161 | // 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) | ||
3162 | // 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) | ||
3163 | // 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) | ||
3164 | // 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) | ||
3165 | // 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) | ||
3166 | // 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) | ||
3167 | // 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) | ||
3168 | // 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) | ||
3169 | |||
3170 | // 24.2.4.21 DataView.prototype[ @@toStringTag ] | ||
3171 | define(DataView.prototype, $$toStringTag, 'DataView'); | ||
3172 | |||
3173 | // 24.2.5 Properties of DataView Instances | ||
3174 | }()); | ||
3175 | |||
3176 | // --------------------------------------- | ||
3177 | // 24.3 The JSON Object | ||
3178 | // --------------------------------------- | ||
3179 | |||
3180 | // 24.3.1 JSON.parse ( text [ , reviver ] ) | ||
3181 | // 24.3.2 JSON.stringify ( value [ , replacer [ , space ] ] ) | ||
3182 | // 24.3.3 JSON [ @@toStringTag ] | ||
3183 | define(JSON, $$toStringTag, 'JSON'); | ||
3184 | |||
3185 | // --------------------------------------- | ||
3186 | // 25.1 Iteration | ||
3187 | // --------------------------------------- | ||
3188 | |||
3189 | // 25.1.1 Common Iteration Interfaces | ||
3190 | // 25.1.1.1 The Iterable Interface | ||
3191 | // 25.1.1.2 The Iterator Interface | ||
3192 | // 25.1.1.3 The IteratorResult Interface | ||
3193 | |||
3194 | // 25.1.2 The %IteratorPrototype% Object | ||
3195 | // Defined earlier, so other prototypes can reference it. | ||
3196 | // 25.1.2.1 %IteratorPrototype% [ @@iterator ] ( ) | ||
3197 | define($IteratorPrototype$, $$iterator, function() { | ||
3198 | return this; | ||
3199 | }); | ||
3200 | |||
3201 | |||
3202 | // --------------------------------------- | ||
3203 | // 25.4 Promise Objects | ||
3204 | // --------------------------------------- | ||
3205 | |||
3206 | (function() { | ||
3207 | // 25.4 Promise Objects | ||
3208 | |||
3209 | // 25.4.1 Promise Abstract Operations | ||
3210 | |||
3211 | // 25.4.1.1 PromiseCapability Records | ||
3212 | // 25.4.1.1.1 IfAbruptRejectPromise ( value, capability ) | ||
3213 | |||
3214 | function IfAbruptRejectPromise(value, capability) { | ||
3215 | var rejectResult = capability['[[Reject]]'].call(undefined, value); | ||
3216 | return capability['[[Promise]]']; | ||
3217 | } | ||
3218 | |||
3219 | // 25.4.1.2 PromiseReaction Records | ||
3220 | |||
3221 | // 25.4.1.3 CreateResolvingFunctions ( promise ) | ||
3222 | |||
3223 | function CreateResolvingFunctions(promise) { | ||
3224 | var alreadyResolved = {'[[value]]': false}; | ||
3225 | var resolve = PromiseResolveFunction(); | ||
3226 | set_internal(resolve, '[[Promise]]', promise); | ||
3227 | set_internal(resolve, '[[AlreadyResolved]]', alreadyResolved); | ||
3228 | var reject = PromiseRejectFunction(); | ||
3229 | set_internal(reject, '[[Promise]]', promise); | ||
3230 | set_internal(reject, '[[AlreadyResolved]]', alreadyResolved); | ||
3231 | return { '[[Resolve]]': resolve, '[[Reject]]': reject}; | ||
3232 | } | ||
3233 | |||
3234 | // 25.4.1.3.1 Promise Reject Functions | ||
3235 | |||
3236 | function PromiseRejectFunction() { | ||
3237 | var F = function(reason) { | ||
3238 | console.assert(Type(F['[[Promise]]']) === 'object'); | ||
3239 | var promise = F['[[Promise]]']; | ||
3240 | var alreadyResolved = F['[[AlreadyResolved]]']; | ||
3241 | if (alreadyResolved['[[value]]']) return undefined; | ||
3242 | set_internal(alreadyResolved, '[[value]]', true); | ||
3243 | return RejectPromise(promise, reason); | ||
3244 | }; | ||
3245 | return F; | ||
3246 | } | ||
3247 | |||
3248 | // 25.4.1.3.2 Promise Resolve Functions | ||
3249 | |||
3250 | function PromiseResolveFunction() { | ||
3251 | var F = function(resolution) { | ||
3252 | console.assert(Type(F['[[Promise]]']) === 'object'); | ||
3253 | var promise = F['[[Promise]]']; | ||
3254 | var alreadyResolved = F['[[AlreadyResolved]]']; | ||
3255 | if (alreadyResolved['[[value]]']) return undefined; | ||
3256 | set_internal(alreadyResolved, '[[value]]', true); | ||
3257 | |||
3258 | if (SameValue(resolution, promise)) { | ||
3259 | var selfResolutionError = TypeError(); | ||
3260 | return RejectPromise(promise, selfResolutionError); | ||
3261 | } | ||
3262 | if (Type(resolution) !== 'object') | ||
3263 | return FulfillPromise(promise, resolution); | ||
3264 | try { | ||
3265 | var then = resolution['then']; | ||
3266 | } catch(then) { | ||
3267 | return RejectPromise(promise, then); | ||
3268 | } | ||
3269 | if (!IsCallable(then)) | ||
3270 | return FulfillPromise(promise, resolution); | ||
3271 | EnqueueJob('PromiseJobs', PromiseResolveThenableJob, [promise, resolution, then]); | ||
3272 | return undefined; | ||
3273 | }; | ||
3274 | return F; | ||
3275 | } | ||
3276 | |||
3277 | // 25.4.1.4 FulfillPromise ( promise, value ) | ||
3278 | |||
3279 | function FulfillPromise(promise, value) { | ||
3280 | console.assert(promise['[[PromiseState]]'] === 'pending'); | ||
3281 | var reactions = promise['[[PromiseFulfillReactions]]']; | ||
3282 | set_internal(promise, '[[PromiseResult]]', value); | ||
3283 | set_internal(promise, '[[PromiseFulfillReactions]]', undefined); | ||
3284 | set_internal(promise, '[[PromiseRejectReactions]]', undefined); | ||
3285 | set_internal(promise, '[[PromiseState]]', 'fulfilled'); | ||
3286 | return TriggerPromiseReactions(reactions, value); | ||
3287 | } | ||
3288 | |||
3289 | // 25.4.1.5 NewPromiseCapability ( C ) | ||
3290 | |||
3291 | function NewPromiseCapability(c) { | ||
3292 | // To keep Promise hermetic, this doesn't look much like the spec. | ||
3293 | return CreatePromiseCapabilityRecord(undefined, c); | ||
3294 | } | ||
3295 | |||
3296 | // 25.4.1.5.1 CreatePromiseCapabilityRecord ( promise, constructor ) | ||
3297 | |||
3298 | function CreatePromiseCapabilityRecord(promise, constructor) { | ||
3299 | // To keep Promise hermetic, this doesn't look much like the spec. | ||
3300 | console.assert(IsConstructor(constructor)); | ||
3301 | var promiseCapability = {}; | ||
3302 | set_internal(promiseCapability, '[[Promise]]', promise); | ||
3303 | set_internal(promiseCapability, '[[Resolve]]', undefined); | ||
3304 | set_internal(promiseCapability, '[[Reject]]', undefined); | ||
3305 | var executor = GetCapabilitiesExecutor(); | ||
3306 | set_internal(executor, '[[Capability]]', promiseCapability); | ||
3307 | |||
3308 | // NOTE: Differs from spec; object is constructed here | ||
3309 | var constructorResult = promise = new constructor(executor); | ||
3310 | set_internal(promiseCapability, '[[Promise]]', promise); | ||
3311 | |||
3312 | if (!IsCallable(promiseCapability['[[Resolve]]'])) throw TypeError(); | ||
3313 | if (!IsCallable(promiseCapability['[[Reject]]'])) throw TypeError(); | ||
3314 | if (Type(constructorResult) === 'object' && !SameValue(promise, constructorResult)) throw TypeError(); | ||
3315 | return promiseCapability; | ||
3316 | } | ||
3317 | |||
3318 | // 25.4.1.5.2 GetCapabilitiesExecutor Functions | ||
3319 | |||
3320 | function GetCapabilitiesExecutor() { | ||
3321 | var F = function(resolve, reject) { | ||
3322 | console.assert(F['[[Capability]]']); | ||
3323 | var promiseCapability = F['[[Capability]]']; | ||
3324 | if (promiseCapability['[[Resolve]]'] !== undefined) throw TypeError(); | ||
3325 | if (promiseCapability['[[Reject]]'] !== undefined) throw TypeError(); | ||
3326 | set_internal(promiseCapability, '[[Resolve]]', resolve); | ||
3327 | set_internal(promiseCapability, '[[Reject]]', reject); | ||
3328 | return undefined; | ||
3329 | }; | ||
3330 | return F; | ||
3331 | } | ||
3332 | |||
3333 | // 25.4.1.6 IsPromise ( x ) | ||
3334 | |||
3335 | function IsPromise(x) { | ||
3336 | if (Type(x) !== 'object') return false; | ||
3337 | if (!('[[PromiseState]]' in x)) return false; | ||
3338 | if (x['[[PromiseState]]'] === undefined) return false; | ||
3339 | return true; | ||
3340 | } | ||
3341 | |||
3342 | // 25.4.1.7 RejectPromise ( promise, reason ) | ||
3343 | |||
3344 | function RejectPromise(promise, reason) { | ||
3345 | console.assert(promise['[[PromiseState]]'] === 'pending'); | ||
3346 | var reactions = promise['[[PromiseRejectReactions]]']; | ||
3347 | set_internal(promise, '[[PromiseResult]]', reason); | ||
3348 | set_internal(promise, '[[PromiseFulfillReactions]]', undefined); | ||
3349 | set_internal(promise, '[[PromiseRejectReactions]]', undefined); | ||
3350 | set_internal(promise, '[[PromiseState]]', 'rejected'); | ||
3351 | return TriggerPromiseReactions(reactions, reason); | ||
3352 | } | ||
3353 | |||
3354 | // 25.4.1.8 TriggerPromiseReactions ( reactions, argument ) | ||
3355 | |||
3356 | function TriggerPromiseReactions(reactions, argument) { | ||
3357 | for (var i = 0, len = reactions.length; i < len; ++i) | ||
3358 | EnqueueJob('PromiseJobs', PromiseReactionJob, [reactions[i], argument]); | ||
3359 | return undefined; | ||
3360 | } | ||
3361 | |||
3362 | // 25.4.2 Promise Jobs | ||
3363 | |||
3364 | // 25.4.2.1 PromiseReactionJob ( reaction, argument ) | ||
3365 | |||
3366 | function PromiseReactionJob(reaction, argument) { | ||
3367 | var promiseCapability = reaction['[[Capabilities]]']; | ||
3368 | var handler = reaction['[[Handler]]']; | ||
3369 | var handlerResult, status; | ||
3370 | try { | ||
3371 | if (handler === 'Identity') handlerResult = argument; | ||
3372 | else if (handler === 'Thrower') throw argument; | ||
3373 | else handlerResult = handler.call(undefined, argument); | ||
3374 | } catch (handlerResult) { | ||
3375 | status = promiseCapability['[[Reject]]'].call(undefined, handlerResult); | ||
3376 | NextJob(status); return; | ||
3377 | } | ||
3378 | status = promiseCapability['[[Resolve]]'].call(undefined, handlerResult); | ||
3379 | NextJob(status); | ||
3380 | } | ||
3381 | |||
3382 | // 25.4.2.2 PromiseResolveThenableJob ( promiseToResolve, thenable, then) | ||
3383 | |||
3384 | function PromiseResolveThenableJob(promiseToResolve, thenable, then) { | ||
3385 | // SPEC BUG: promise vs. promiseToResolve | ||
3386 | var resolvingFunctions = CreateResolvingFunctions(promiseToResolve); | ||
3387 | try { | ||
3388 | var thenCallResult = then.call(thenable, resolvingFunctions['[[Resolve]]'], | ||
3389 | resolvingFunctions['[[Reject]]']); | ||
3390 | } catch (thenCallResult) { | ||
3391 | var status = resolvingFunctions['[[Reject]]'].call(undefined, thenCallResult); | ||
3392 | NextJob(status); return; | ||
3393 | } | ||
3394 | NextJob(thenCallResult); | ||
3395 | } | ||
3396 | |||
3397 | // 25.4.3 The Promise Constructor | ||
3398 | |||
3399 | // 25.4.3.1 Promise ( executor ) | ||
3400 | |||
3401 | function Promise(executor) { | ||
3402 | var config = { configurable: false, enumerable: false, writable: true, value: undefined }; | ||
3403 | Object.defineProperty(this, '[[PromiseState]]', config); | ||
3404 | Object.defineProperty(this, '[[PromiseConstructor]]', config); | ||
3405 | Object.defineProperty(this, '[[PromiseResult]]', config); | ||
3406 | Object.defineProperty(this, '[[PromiseFulfillReactions]]', config); | ||
3407 | Object.defineProperty(this, '[[PromiseRejectReactions]]', config); | ||
3408 | |||
3409 | var promise = this; | ||
3410 | if (Type(promise) !== 'object') throw new TypeError(); | ||
3411 | if (!('[[PromiseState]]' in promise)) throw TypeError(); | ||
3412 | if (promise['[[PromiseState]]'] !== undefined) throw TypeError(); | ||
3413 | if (!IsCallable(executor)) throw TypeError(); | ||
3414 | |||
3415 | set_internal(promise, '[[PromiseConstructor]]', Promise); | ||
3416 | |||
3417 | return InitializePromise(promise, executor); | ||
3418 | } | ||
3419 | |||
3420 | // 25.4.3.1.1 InitializePromise ( promise, executor ) | ||
3421 | |||
3422 | function InitializePromise(promise, executor) { | ||
3423 | console.assert('[[PromiseState]]' in promise); | ||
3424 | console.assert(IsCallable(executor)); | ||
3425 | set_internal(promise, '[[PromiseState]]', 'pending'); | ||
3426 | set_internal(promise, '[[PromiseFulfillReactions]]', []); | ||
3427 | set_internal(promise, '[[PromiseRejectReactions]]', []); | ||
3428 | var resolvingFunctions = CreateResolvingFunctions(promise); | ||
3429 | try { | ||
3430 | var completion = executor.call(undefined, resolvingFunctions['[[Resolve]]'], | ||
3431 | resolvingFunctions['[[Reject]]']); | ||
3432 | } catch (completion) { | ||
3433 | var status = resolvingFunctions['[[Reject]]'].call(undefined, completion); | ||
3434 | } | ||
3435 | return promise; | ||
3436 | } | ||
3437 | |||
3438 | // 25.4.4 Properties of the Promise Constructor | ||
3439 | // 25.4.4.1 Promise.all ( iterable ) | ||
3440 | |||
3441 | define(Promise, 'all', function all(iterable) { | ||
3442 | var c = strict(this); | ||
3443 | var promiseCapability = NewPromiseCapability(c); | ||
3444 | try { | ||
3445 | var iterator = GetIterator(iterable); | ||
3446 | } catch (value) { | ||
3447 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3448 | return promiseCapability['[[Promise]]']; | ||
3449 | } | ||
3450 | var values = []; | ||
3451 | var remainingElementsCount = { value: 1 }; | ||
3452 | var index = 0; | ||
3453 | while (true) { | ||
3454 | try { | ||
3455 | var next = IteratorStep(iterator); | ||
3456 | } catch (value) { | ||
3457 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3458 | return promiseCapability['[[Promise]]']; | ||
3459 | } | ||
3460 | if (!next) { | ||
3461 | remainingElementsCount.value -= 1; | ||
3462 | if (remainingElementsCount.value === 0) { | ||
3463 | var resolveResult = promiseCapability['[[Resolve]]'].apply(undefined, values); | ||
3464 | |||
3465 | |||
3466 | } | ||
3467 | return promiseCapability['[[Promise]]']; | ||
3468 | } | ||
3469 | try { | ||
3470 | var nextValue = IteratorValue(next); | ||
3471 | } catch (value) { | ||
3472 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3473 | return promiseCapability['[[Promise]]']; | ||
3474 | } | ||
3475 | try { | ||
3476 | var nextPromise = c.resolve(nextValue); | ||
3477 | } catch (value) { | ||
3478 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3479 | return promiseCapability['[[Promise]]']; | ||
3480 | } | ||
3481 | var resolveElement = PromiseAllResolveElementFunction(); | ||
3482 | set_internal(resolveElement, '[[AlreadyCalled]]', { value: false }); | ||
3483 | set_internal(resolveElement, '[[Index]]', index); | ||
3484 | set_internal(resolveElement, '[[Values]]', values); | ||
3485 | set_internal(resolveElement, '[[Capabilities]]', promiseCapability); | ||
3486 | set_internal(resolveElement, '[[RemainingElements]]', remainingElementsCount); | ||
3487 | remainingElementsCount.value += 1; | ||
3488 | try { | ||
3489 | var result = nextPromise.then(resolveElement, promiseCapability['[[Reject]]']); | ||
3490 | } catch (value) { | ||
3491 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3492 | return promiseCapability['[[Promise]]']; | ||
3493 | } | ||
3494 | index += 1; | ||
3495 | } | ||
3496 | }); | ||
3497 | |||
3498 | // 25.4.4.1.1 Promise.all Resolve Element Functions | ||
3499 | |||
3500 | function PromiseAllResolveElementFunction() { | ||
3501 | var F = function(x) { | ||
3502 | var alreadyCalled = F['[[AlreadyCalled]]']; | ||
3503 | if (alreadyCalled.value) return undefined; | ||
3504 | alreadyCalled.value = true; | ||
3505 | var index = F['[[Index]]']; | ||
3506 | var values = F['[[Values]]']; | ||
3507 | var promiseCapability = F['[[Capabilities]]']; | ||
3508 | var remainingElementsCount = F['[[RemainingElements]]']; | ||
3509 | try { | ||
3510 | values[index] = x; | ||
3511 | } catch (result) { | ||
3512 | promiseCapability['[[Reject]]'].call(undefined, result); | ||
3513 | return promiseCapability['[[Promise]]']; | ||
3514 | } | ||
3515 | remainingElementsCount.value -= 1; | ||
3516 | if (remainingElementsCount.value === 0) | ||
3517 | return promiseCapability['[[Resolve]]'].call(undefined, values); | ||
3518 | return undefined; | ||
3519 | }; | ||
3520 | return F; | ||
3521 | } | ||
3522 | |||
3523 | // 25.4.4.2 Promise.prototype | ||
3524 | |||
3525 | Promise.prototype = {}; | ||
3526 | |||
3527 | // 25.4.4.3 Promise.race ( iterable ) | ||
3528 | |||
3529 | define(Promise, 'race', function race(iterable) { | ||
3530 | var c = strict(this); | ||
3531 | var promiseCapability = NewPromiseCapability(c); | ||
3532 | try { | ||
3533 | var iterator = GetIterator(iterable); | ||
3534 | } catch (value) { | ||
3535 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3536 | return promiseCapability['[[Promise]]']; | ||
3537 | } | ||
3538 | while (true) { | ||
3539 | try { | ||
3540 | var next = IteratorStep(iterator); | ||
3541 | } catch (value) { | ||
3542 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3543 | return promiseCapability['[[Promise]]']; | ||
3544 | } | ||
3545 | if (!next) return promiseCapability['[[Promise]]']; | ||
3546 | try { | ||
3547 | var nextValue = IteratorValue(next); | ||
3548 | } catch (value) { | ||
3549 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3550 | return promiseCapability['[[Promise]]']; | ||
3551 | } | ||
3552 | try { | ||
3553 | var nextPromise = c.resolve(nextValue); | ||
3554 | } catch (value) { | ||
3555 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3556 | return promiseCapability['[[Promise]]']; | ||
3557 | } | ||
3558 | try { | ||
3559 | nextPromise.then(promiseCapability['[[Resolve]]'], promiseCapability['[[Reject]]']); | ||
3560 | } catch (value) { | ||
3561 | promiseCapability['[[Reject]]'].call(undefined, value); | ||
3562 | return promiseCapability['[[Promise]]']; | ||
3563 | } | ||
3564 | } | ||
3565 | }); | ||
3566 | |||
3567 | // 25.4.4.4 Promise.reject ( r ) | ||
3568 | |||
3569 | define(Promise, 'reject', function reject(r) { | ||
3570 | var c = strict(this); | ||
3571 | var promiseCapability = NewPromiseCapability(c); | ||
3572 | var rejectResult = promiseCapability['[[Reject]]'].call(undefined, r); | ||
3573 | return promiseCapability['[[Promise]]']; | ||
3574 | }); | ||
3575 | |||
3576 | // 25.4.4.5 Promise.resolve ( x ) | ||
3577 | |||
3578 | define(Promise, 'resolve', function resolve(x) { | ||
3579 | var c = strict(this); | ||
3580 | if (IsPromise(x)) { | ||
3581 | var constructor = x['[[PromiseConstructor]]']; | ||
3582 | if (SameValue(constructor, c)) return x; | ||
3583 | } | ||
3584 | var promiseCapability = NewPromiseCapability(c); | ||
3585 | var resolveResult = promiseCapability['[[Resolve]]'].call(undefined, x); | ||
3586 | return promiseCapability['[[Promise]]']; | ||
3587 | }); | ||
3588 | |||
3589 | // 25.4.4.6 Promise [ @@create ] ( ) | ||
3590 | // 25.4.4.6.1 AllocatePromise ( constructor ) | ||
3591 | // 25.4.5 Properties of the Promise Prototype Object | ||
3592 | // 25.4.5.1 Promise.prototype.catch ( onRejected ) | ||
3593 | |||
3594 | define(Promise.prototype, 'catch', function catch_(onRejected) { | ||
3595 | var promise = this; | ||
3596 | return promise.then(undefined, onRejected); | ||
3597 | }); | ||
3598 | |||
3599 | // 25.4.5.2 Promise.prototype.constructor | ||
3600 | |||
3601 | Promise.prototype.constructor = Promise; | ||
3602 | |||
3603 | // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) | ||
3604 | |||
3605 | define(Promise.prototype, 'then', function then(onFulfilled, onRejected) { | ||
3606 | var promise = this; | ||
3607 | if (!IsPromise(promise)) throw TypeError(); | ||
3608 | if (!IsCallable(onFulfilled)) onFulfilled = 'Identity'; | ||
3609 | if (!IsCallable(onRejected)) onRejected = 'Thrower'; | ||
3610 | var c = promise.constructor; | ||
3611 | var promiseCapability = NewPromiseCapability(c); | ||
3612 | var fulfillReaction = { '[[Capabilities]]': promiseCapability, | ||
3613 | '[[Handler]]': onFulfilled }; | ||
3614 | var rejectReaction = { '[[Capabilities]]': promiseCapability, | ||
3615 | '[[Handler]]': onRejected }; | ||
3616 | if (promise['[[PromiseState]]'] === 'pending') { | ||
3617 | promise['[[PromiseFulfillReactions]]'].push(fulfillReaction); | ||
3618 | promise['[[PromiseRejectReactions]]'].push(rejectReaction); | ||
3619 | } else if (promise['[[PromiseState]]'] === 'fulfilled') { | ||
3620 | var value = promise['[[PromiseResult]]']; | ||
3621 | EnqueueJob('PromiseJobs', PromiseReactionJob, [fulfillReaction, value]); | ||
3622 | } else if (promise['[[PromiseState]]'] === 'rejected') { | ||
3623 | var reason = promise['[[PromiseResult]]']; | ||
3624 | EnqueueJob('PromiseJobs', PromiseReactionJob, [rejectReaction, reason]); | ||
3625 | } | ||
3626 | return promiseCapability['[[Promise]]']; | ||
3627 | }); | ||
3628 | |||
3629 | // 25.4.6 Properties of Promise Instances | ||
3630 | |||
3631 | if (!('Promise' in global) || OVERRIDE_NATIVE_FOR_TESTING) | ||
3632 | global.Promise = Promise; | ||
3633 | |||
3634 | // Patch early Promise.cast vs. Promise.resolve implementations | ||
3635 | if ('cast' in global.Promise) global.Promise.resolve = global.Promise.cast; | ||
3636 | }()); | ||
3637 | |||
3638 | // 25.4.5.1 Promise.prototype [ @@toStringTag ] | ||
3639 | define(Promise.prototype, $$toStringTag, 'Promise'); | ||
3640 | |||
3641 | // --------------------------------------- | ||
3642 | // 26 Reflection | ||
3643 | // --------------------------------------- | ||
3644 | |||
3645 | (function() { | ||
3646 | // 26.1 The Reflect Object | ||
3647 | if (!('Reflect' in global) || OVERRIDE_NATIVE_FOR_TESTING) | ||
3648 | global.Reflect = {}; | ||
3649 | |||
3650 | // 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) | ||
3651 | define( | ||
3652 | Reflect, 'apply', | ||
3653 | function apply(target, thisArgument, argumentsList) { | ||
3654 | if (!IsCallable(target)) throw TypeError(); | ||
3655 | return Function.prototype.apply.call(target, thisArgument, argumentsList); | ||
3656 | }); | ||
3657 | |||
3658 | // 26.1.2 Reflect.construct ( target, argumentsList [, newTarget] ) | ||
3659 | define( | ||
3660 | Reflect, 'construct', | ||
3661 | function construct(target, argumentsList) { | ||
3662 | return __cons(target, argumentsList); | ||
3663 | }); | ||
3664 | |||
3665 | // 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) | ||
3666 | define( | ||
3667 | Reflect, 'defineProperty', | ||
3668 | function defineProperty(target, propertyKey, attributes) { | ||
3669 | try { | ||
3670 | Object.defineProperty(target, propertyKey, attributes); | ||
3671 | return true; | ||
3672 | } catch (_) { | ||
3673 | return false; | ||
3674 | } | ||
3675 | }); | ||
3676 | |||
3677 | // 26.1.4 Reflect.deleteProperty ( target, propertyKey ) | ||
3678 | define( | ||
3679 | Reflect, 'deleteProperty', | ||
3680 | function deleteProperty(target,name) { | ||
3681 | try { | ||
3682 | delete target[name]; | ||
3683 | return !HasOwnProperty(target, name); | ||
3684 | } catch (_) { | ||
3685 | return false; | ||
3686 | } | ||
3687 | }); | ||
3688 | |||
3689 | // 26.1.5 Reflect.enumerate ( target ) | ||
3690 | define( | ||
3691 | Reflect, 'enumerate', | ||
3692 | function enumerate(target) { | ||
3693 | target = ToObject(target); | ||
3694 | var iterator = Enumerate(target); | ||
3695 | return iterator; | ||
3696 | }); | ||
3697 | |||
3698 | // 26.1.6 Reflect.get ( target, propertyKey [ , receiver ]) | ||
3699 | define( | ||
3700 | Reflect, 'get', | ||
3701 | function get(target, name, receiver) { | ||
3702 | target = ToObject(target); | ||
3703 | name = String(name); | ||
3704 | receiver = (receiver === undefined) ? target : ToObject(receiver); | ||
3705 | var desc = getPropertyDescriptor(target, name); | ||
3706 | if (desc && 'get' in desc) | ||
3707 | return Function.prototype.call.call(desc['get'], receiver); | ||
3708 | return target[name]; | ||
3709 | }); | ||
3710 | |||
3711 | // 26.1.7 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) | ||
3712 | define( | ||
3713 | Reflect, 'getOwnPropertyDescriptor', | ||
3714 | Object.getOwnPropertyDescriptor); | ||
3715 | |||
3716 | // 26.1.8 Reflect.getPrototypeOf ( target ) | ||
3717 | define( | ||
3718 | Reflect, 'getPrototypeOf', | ||
3719 | Object.getPrototypeOf); | ||
3720 | |||
3721 | // 26.1.9 Reflect.has ( target, propertyKey ) | ||
3722 | define( | ||
3723 | Reflect, 'has', | ||
3724 | function has(target,name) { | ||
3725 | return String(name) in ToObject(target); | ||
3726 | }); | ||
3727 | |||
3728 | // 26.1.10 Reflect.isExtensible (target) | ||
3729 | define( | ||
3730 | Reflect, 'isExtensible', | ||
3731 | Object.isExtensible); | ||
3732 | |||
3733 | // 26.1.11 Reflect.ownKeys ( target ) | ||
3734 | define( | ||
3735 | Reflect, 'ownKeys', | ||
3736 | function ownKeys(target) { | ||
3737 | var obj = ToObject(target); | ||
3738 | return Object.getOwnPropertyNames(obj); | ||
3739 | }); | ||
3740 | |||
3741 | // 26.1.12 Reflect.preventExtensions ( target ) | ||
3742 | define( | ||
3743 | Reflect, 'preventExtensions', | ||
3744 | function preventExtensions(target) { | ||
3745 | try { Object.preventExtensions(target); return true; } catch (_) { return false; } | ||
3746 | }); | ||
3747 | |||
3748 | // 26.1.13 Reflect.set ( target, propertyKey, V [ , receiver ] ) | ||
3749 | define( | ||
3750 | Reflect, 'set', | ||
3751 | function set(target, name, value, receiver) { | ||
3752 | target = ToObject(target); | ||
3753 | name = String(name); | ||
3754 | receiver = (receiver === undefined) ? target : ToObject(receiver); | ||
3755 | var desc = getPropertyDescriptor(target, name); | ||
3756 | try { | ||
3757 | if (desc && 'set' in desc) | ||
3758 | Function.prototype.call.call(desc['set'], receiver, value); | ||
3759 | else | ||
3760 | target[name] = value; | ||
3761 | return true; | ||
3762 | } catch (_) { | ||
3763 | return false; | ||
3764 | } | ||
3765 | }); | ||
3766 | |||
3767 | // 26.1.14 Reflect.setPrototypeOf ( target, proto ) | ||
3768 | define( | ||
3769 | Reflect, 'setPrototypeOf', | ||
3770 | function setPrototypeOf(target, proto) { | ||
3771 | try { | ||
3772 | target.__proto__ = proto; | ||
3773 | return Reflect.getPrototypeOf(target) === proto; | ||
3774 | } catch(_) { | ||
3775 | return false; | ||
3776 | } | ||
3777 | }); | ||
3778 | |||
3779 | }()); | ||
3780 | |||
3781 | // --------------------------------------- | ||
3782 | // 26.2 Proxy Objects | ||
3783 | // --------------------------------------- | ||
3784 | |||
3785 | // Not polyfillable. | ||
3786 | |||
3787 | }(self)); | ||
3788 | |||
3789 | // This helper is defined outside the main scope so that the use of | ||
3790 | // 'eval' does not taint the scope for minifiers. | ||
3791 | function __cons(t, a) { | ||
3792 | return eval('new t(' + a.map(function(_, i) { return 'a[' + i + ']'; }).join(',') + ')'); | ||
3793 | } | ||
diff --git a/src/js/ripple-util.js b/src/js/ripple-util.js new file mode 100644 index 0000000..8b287fb --- /dev/null +++ b/src/js/ripple-util.js | |||
@@ -0,0 +1,10 @@ | |||
1 | function convertRippleAdrr(address) { | ||
2 | return window.basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode( | ||
3 | window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(address) | ||
4 | ) | ||
5 | } | ||
6 | |||
7 | function convertRipplePriv(priv) { | ||
8 | return window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(priv).toString("hex").slice(2) | ||
9 | } | ||
10 | |||
diff --git a/src/js/unorm.js b/src/js/unorm.js new file mode 100644 index 0000000..92d3699 --- /dev/null +++ b/src/js/unorm.js | |||
@@ -0,0 +1,442 @@ | |||
1 | (function (root) { | ||
2 | "use strict"; | ||
3 | |||
4 | /***** unorm.js *****/ | ||
5 | |||
6 | /* | ||
7 | * UnicodeNormalizer 1.0.0 | ||
8 | * Copyright (c) 2008 Matsuza | ||
9 | * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. | ||
10 | * $Date: 2008-06-05 16:44:17 +0200 (Thu, 05 Jun 2008) $ | ||
11 | * $Rev: 13309 $ | ||
12 | */ | ||
13 | |||
14 | var DEFAULT_FEATURE = [null, 0, {}]; | ||
15 | var CACHE_THRESHOLD = 10; | ||
16 | var SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7, LCount = 19, VCount = 21, TCount = 28; | ||
17 | var NCount = VCount * TCount; // 588 | ||
18 | var SCount = LCount * NCount; // 11172 | ||
19 | |||
20 | var UChar = function(cp, feature){ | ||
21 | this.codepoint = cp; | ||
22 | this.feature = feature; | ||
23 | }; | ||
24 | |||
25 | // Strategies | ||
26 | var cache = {}; | ||
27 | var cacheCounter = []; | ||
28 | for (var i = 0; i <= 0xFF; ++i){ | ||
29 | cacheCounter[i] = 0; | ||
30 | } | ||
31 | |||
32 | function fromCache(next, cp, needFeature){ | ||
33 | var ret = cache[cp]; | ||
34 | if(!ret){ | ||
35 | ret = next(cp, needFeature); | ||
36 | if(!!ret.feature && ++cacheCounter[(cp >> 8) & 0xFF] > CACHE_THRESHOLD){ | ||
37 | cache[cp] = ret; | ||
38 | } | ||
39 | } | ||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | function fromData(next, cp, needFeature){ | ||
44 | var hash = cp & 0xFF00; | ||
45 | var dunit = UChar.udata[hash] || {}; | ||
46 | var f = dunit[cp]; | ||
47 | return f ? new UChar(cp, f) : new UChar(cp, DEFAULT_FEATURE); | ||
48 | } | ||
49 | function fromCpOnly(next, cp, needFeature){ | ||
50 | return !!needFeature ? next(cp, needFeature) : new UChar(cp, null); | ||
51 | } | ||
52 | function fromRuleBasedJamo(next, cp, needFeature){ | ||
53 | var j; | ||
54 | if(cp < LBase || (LBase + LCount <= cp && cp < SBase) || (SBase + SCount < cp)){ | ||
55 | return next(cp, needFeature); | ||
56 | } | ||
57 | if(LBase <= cp && cp < LBase + LCount){ | ||
58 | var c = {}; | ||
59 | var base = (cp - LBase) * VCount; | ||
60 | for (j = 0; j < VCount; ++j){ | ||
61 | c[VBase + j] = SBase + TCount * (j + base); | ||
62 | } | ||
63 | return new UChar(cp, [,,c]); | ||
64 | } | ||
65 | |||
66 | var SIndex = cp - SBase; | ||
67 | var TIndex = SIndex % TCount; | ||
68 | var feature = []; | ||
69 | if(TIndex !== 0){ | ||
70 | feature[0] = [SBase + SIndex - TIndex, TBase + TIndex]; | ||
71 | } else { | ||
72 | feature[0] = [LBase + Math.floor(SIndex / NCount), VBase + Math.floor((SIndex % NCount) / TCount)]; | ||
73 | feature[2] = {}; | ||
74 | for (j = 1; j < TCount; ++j){ | ||
75 | feature[2][TBase + j] = cp + j; | ||
76 | } | ||
77 | } | ||
78 | return new UChar(cp, feature); | ||
79 | } | ||
80 | function fromCpFilter(next, cp, needFeature){ | ||
81 | return cp < 60 || 13311 < cp && cp < 42607 ? new UChar(cp, DEFAULT_FEATURE) : next(cp, needFeature); | ||
82 | } | ||
83 | |||
84 | var strategies = [fromCpFilter, fromCache, fromCpOnly, fromRuleBasedJamo, fromData]; | ||
85 | |||
86 | UChar.fromCharCode = strategies.reduceRight(function (next, strategy) { | ||
87 | return function (cp, needFeature) { | ||
88 | return strategy(next, cp, needFeature); | ||
89 | }; | ||
90 | }, null); | ||
91 | |||
92 | UChar.isHighSurrogate = function(cp){ | ||
93 | return cp >= 0xD800 && cp <= 0xDBFF; | ||
94 | }; | ||
95 | UChar.isLowSurrogate = function(cp){ | ||
96 | return cp >= 0xDC00 && cp <= 0xDFFF; | ||
97 | }; | ||
98 | |||
99 | UChar.prototype.prepFeature = function(){ | ||
100 | if(!this.feature){ | ||
101 | this.feature = UChar.fromCharCode(this.codepoint, true).feature; | ||
102 | } | ||
103 | }; | ||
104 | |||
105 | UChar.prototype.toString = function(){ | ||
106 | if(this.codepoint < 0x10000){ | ||
107 | return String.fromCharCode(this.codepoint); | ||
108 | } else { | ||
109 | var x = this.codepoint - 0x10000; | ||
110 | return String.fromCharCode(Math.floor(x / 0x400) + 0xD800, x % 0x400 + 0xDC00); | ||
111 | } | ||
112 | }; | ||
113 | |||
114 | UChar.prototype.getDecomp = function(){ | ||
115 | this.prepFeature(); | ||
116 | return this.feature[0] || null; | ||
117 | }; | ||
118 | |||
119 | UChar.prototype.isCompatibility = function(){ | ||
120 | this.prepFeature(); | ||
121 | return !!this.feature[1] && (this.feature[1] & (1 << 8)); | ||
122 | }; | ||
123 | UChar.prototype.isExclude = function(){ | ||
124 | this.prepFeature(); | ||
125 | return !!this.feature[1] && (this.feature[1] & (1 << 9)); | ||
126 | }; | ||
127 | UChar.prototype.getCanonicalClass = function(){ | ||
128 | this.prepFeature(); | ||
129 | return !!this.feature[1] ? (this.feature[1] & 0xff) : 0; | ||
130 | }; | ||
131 | UChar.prototype.getComposite = function(following){ | ||
132 | this.prepFeature(); | ||
133 | if(!this.feature[2]){ | ||
134 | return null; | ||
135 | } | ||
136 | var cp = this.feature[2][following.codepoint]; | ||
137 | return cp ? UChar.fromCharCode(cp) : null; | ||
138 | }; | ||
139 | |||
140 | var UCharIterator = function(str){ | ||
141 | this.str = str; | ||
142 | this.cursor = 0; | ||
143 | }; | ||
144 | UCharIterator.prototype.next = function(){ | ||
145 | if(!!this.str && this.cursor < this.str.length){ | ||
146 | var cp = this.str.charCodeAt(this.cursor++); | ||
147 | var d; | ||
148 | if(UChar.isHighSurrogate(cp) && this.cursor < this.str.length && UChar.isLowSurrogate((d = this.str.charCodeAt(this.cursor)))){ | ||
149 | cp = (cp - 0xD800) * 0x400 + (d -0xDC00) + 0x10000; | ||
150 | ++this.cursor; | ||
151 | } | ||
152 | return UChar.fromCharCode(cp); | ||
153 | } else { | ||
154 | this.str = null; | ||
155 | return null; | ||
156 | } | ||
157 | }; | ||
158 | |||
159 | var RecursDecompIterator = function(it, cano){ | ||
160 | this.it = it; | ||
161 | this.canonical = cano; | ||
162 | this.resBuf = []; | ||
163 | }; | ||
164 | |||
165 | RecursDecompIterator.prototype.next = function(){ | ||
166 | function recursiveDecomp(cano, uchar){ | ||
167 | var decomp = uchar.getDecomp(); | ||
168 | if(!!decomp && !(cano && uchar.isCompatibility())){ | ||
169 | var ret = []; | ||
170 | for(var i = 0; i < decomp.length; ++i){ | ||
171 | var a = recursiveDecomp(cano, UChar.fromCharCode(decomp[i])); | ||
172 | ret = ret.concat(a); | ||
173 | } | ||
174 | return ret; | ||
175 | } else { | ||
176 | return [uchar]; | ||
177 | } | ||
178 | } | ||
179 | if(this.resBuf.length === 0){ | ||
180 | var uchar = this.it.next(); | ||
181 | if(!uchar){ | ||
182 | return null; | ||
183 | } | ||
184 | this.resBuf = recursiveDecomp(this.canonical, uchar); | ||
185 | } | ||
186 | return this.resBuf.shift(); | ||
187 | }; | ||
188 | |||
189 | var DecompIterator = function(it){ | ||
190 | this.it = it; | ||
191 | this.resBuf = []; | ||
192 | }; | ||
193 | |||
194 | DecompIterator.prototype.next = function(){ | ||
195 | var cc; | ||
196 | if(this.resBuf.length === 0){ | ||
197 | do{ | ||
198 | var uchar = this.it.next(); | ||
199 | if(!uchar){ | ||
200 | break; | ||
201 | } | ||
202 | cc = uchar.getCanonicalClass(); | ||
203 | var inspt = this.resBuf.length; | ||
204 | if(cc !== 0){ | ||
205 | for(; inspt > 0; --inspt){ | ||
206 | var uchar2 = this.resBuf[inspt - 1]; | ||
207 | var cc2 = uchar2.getCanonicalClass(); | ||
208 | if(cc2 <= cc){ | ||
209 | break; | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | this.resBuf.splice(inspt, 0, uchar); | ||
214 | } while(cc !== 0); | ||
215 | } | ||
216 | return this.resBuf.shift(); | ||
217 | }; | ||
218 | |||
219 | var CompIterator = function(it){ | ||
220 | this.it = it; | ||
221 | this.procBuf = []; | ||
222 | this.resBuf = []; | ||
223 | this.lastClass = null; | ||
224 | }; | ||
225 | |||
226 | CompIterator.prototype.next = function(){ | ||
227 | while(this.resBuf.length === 0){ | ||
228 | var uchar = this.it.next(); | ||
229 | if(!uchar){ | ||
230 | this.resBuf = this.procBuf; | ||
231 | this.procBuf = []; | ||
232 | break; | ||
233 | } | ||
234 | if(this.procBuf.length === 0){ | ||
235 | this.lastClass = uchar.getCanonicalClass(); | ||
236 | this.procBuf.push(uchar); | ||
237 | } else { | ||
238 | var starter = this.procBuf[0]; | ||
239 | var composite = starter.getComposite(uchar); | ||
240 | var cc = uchar.getCanonicalClass(); | ||
241 | if(!!composite && (this.lastClass < cc || this.lastClass === 0)){ | ||
242 | this.procBuf[0] = composite; | ||
243 | } else { | ||
244 | if(cc === 0){ | ||
245 | this.resBuf = this.procBuf; | ||
246 | this.procBuf = []; | ||
247 | } | ||
248 | this.lastClass = cc; | ||
249 | this.procBuf.push(uchar); | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | return this.resBuf.shift(); | ||
254 | }; | ||
255 | |||
256 | var createIterator = function(mode, str){ | ||
257 | switch(mode){ | ||
258 | case "NFD": | ||
259 | return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true)); | ||
260 | case "NFKD": | ||
261 | return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false)); | ||
262 | case "NFC": | ||
263 | return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true))); | ||
264 | case "NFKC": | ||
265 | return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false))); | ||
266 | } | ||
267 | throw mode + " is invalid"; | ||
268 | }; | ||
269 | var normalize = function(mode, str){ | ||
270 | var it = createIterator(mode, str); | ||
271 | var ret = ""; | ||
272 | var uchar; | ||
273 | while(!!(uchar = it.next())){ | ||
274 | ret += uchar.toString(); | ||
275 | } | ||
276 | return ret; | ||
277 | }; | ||
278 | |||
279 | /* API functions */ | ||
280 | function nfd(str){ | ||
281 | return normalize("NFD", str); | ||
282 | } | ||
283 | |||
284 | function nfkd(str){ | ||
285 | return normalize("NFKD", str); | ||
286 | } | ||
287 | |||
288 | function nfc(str){ | ||
289 | return normalize("NFC", str); | ||
290 | } | ||
291 | |||
292 | function nfkc(str){ | ||
293 | return normalize("NFKC", str); | ||
294 | } | ||
295 | |||
296 | /* Unicode data */ | ||
297 | UChar.udata={ | ||
298 | 0:{60:[,,{824:8814}],61:[,,{824:8800}],62:[,,{824:8815}],65:[,,{768:192,769:193,770:194,771:195,772:256,774:258,775:550,776:196,777:7842,778:197,780:461,783:512,785:514,803:7840,805:7680,808:260}],66:[,,{775:7682,803:7684,817:7686}],67:[,,{769:262,770:264,775:266,780:268,807:199}],68:[,,{775:7690,780:270,803:7692,807:7696,813:7698,817:7694}],69:[,,{768:200,769:201,770:202,771:7868,772:274,774:276,775:278,776:203,777:7866,780:282,783:516,785:518,803:7864,807:552,808:280,813:7704,816:7706}],70:[,,{775:7710}],71:[,,{769:500,770:284,772:7712,774:286,775:288,780:486,807:290}],72:[,,{770:292,775:7714,776:7718,780:542,803:7716,807:7720,814:7722}],73:[,,{768:204,769:205,770:206,771:296,772:298,774:300,775:304,776:207,777:7880,780:463,783:520,785:522,803:7882,808:302,816:7724}],74:[,,{770:308}],75:[,,{769:7728,780:488,803:7730,807:310,817:7732}],76:[,,{769:313,780:317,803:7734,807:315,813:7740,817:7738}],77:[,,{769:7742,775:7744,803:7746}],78:[,,{768:504,769:323,771:209,775:7748,780:327,803:7750,807:325,813:7754,817:7752}],79:[,,{768:210,769:211,770:212,771:213,772:332,774:334,775:558,776:214,777:7886,779:336,780:465,783:524,785:526,795:416,803:7884,808:490}],80:[,,{769:7764,775:7766}],82:[,,{769:340,775:7768,780:344,783:528,785:530,803:7770,807:342,817:7774}],83:[,,{769:346,770:348,775:7776,780:352,803:7778,806:536,807:350}],84:[,,{775:7786,780:356,803:7788,806:538,807:354,813:7792,817:7790}],85:[,,{768:217,769:218,770:219,771:360,772:362,774:364,776:220,777:7910,778:366,779:368,780:467,783:532,785:534,795:431,803:7908,804:7794,808:370,813:7798,816:7796}],86:[,,{771:7804,803:7806}],87:[,,{768:7808,769:7810,770:372,775:7814,776:7812,803:7816}],88:[,,{775:7818,776:7820}],89:[,,{768:7922,769:221,770:374,771:7928,772:562,775:7822,776:376,777:7926,803:7924}],90:[,,{769:377,770:7824,775:379,780:381,803:7826,817:7828}],97:[,,{768:224,769:225,770:226,771:227,772:257,774:259,775:551,776:228,777:7843,778:229,780:462,783:513,785:515,803:7841,805:7681,808:261}],98:[,,{775:7683,803:7685,817:7687}],99:[,,{769:263,770:265,775:267,780:269,807:231}],100:[,,{775:7691,780:271,803:7693,807:7697,813:7699,817:7695}],101:[,,{768:232,769:233,770:234,771:7869,772:275,774:277,775:279,776:235,777:7867,780:283,783:517,785:519,803:7865,807:553,808:281,813:7705,816:7707}],102:[,,{775:7711}],103:[,,{769:501,770:285,772:7713,774:287,775:289,780:487,807:291}],104:[,,{770:293,775:7715,776:7719,780:543,803:7717,807:7721,814:7723,817:7830}],105:[,,{768:236,769:237,770:238,771:297,772:299,774:301,776:239,777:7881,780:464,783:521,785:523,803:7883,808:303,816:7725}],106:[,,{770:309,780:496}],107:[,,{769:7729,780:489,803:7731,807:311,817:7733}],108:[,,{769:314,780:318,803:7735,807:316,813:7741,817:7739}],109:[,,{769:7743,775:7745,803:7747}],110:[,,{768:505,769:324,771:241,775:7749,780:328,803:7751,807:326,813:7755,817:7753}],111:[,,{768:242,769:243,770:244,771:245,772:333,774:335,775:559,776:246,777:7887,779:337,780:466,783:525,785:527,795:417,803:7885,808:491}],112:[,,{769:7765,775:7767}],114:[,,{769:341,775:7769,780:345,783:529,785:531,803:7771,807:343,817:7775}],115:[,,{769:347,770:349,775:7777,780:353,803:7779,806:537,807:351}],116:[,,{775:7787,776:7831,780:357,803:7789,806:539,807:355,813:7793,817:7791}],117:[,,{768:249,769:250,770:251,771:361,772:363,774:365,776:252,777:7911,778:367,779:369,780:468,783:533,785:535,795:432,803:7909,804:7795,808:371,813:7799,816:7797}],118:[,,{771:7805,803:7807}],119:[,,{768:7809,769:7811,770:373,775:7815,776:7813,778:7832,803:7817}],120:[,,{775:7819,776:7821}],121:[,,{768:7923,769:253,770:375,771:7929,772:563,775:7823,776:255,777:7927,778:7833,803:7925}],122:[,,{769:378,770:7825,775:380,780:382,803:7827,817:7829}],160:[[32],256],168:[[32,776],256,{768:8173,769:901,834:8129}],170:[[97],256],175:[[32,772],256],178:[[50],256],179:[[51],256],180:[[32,769],256],181:[[956],256],184:[[32,807],256],185:[[49],256],186:[[111],256],188:[[49,8260,52],256],189:[[49,8260,50],256],190:[[51,8260,52],256],192:[[65,768]],193:[[65,769]],194:[[65,770],,{768:7846,769:7844,771:7850,777:7848}],195:[[65,771]],196:[[65,776],,{772:478}],197:[[65,778],,{769:506}],198:[,,{769:508,772:482}],199:[[67,807],,{769:7688}],200:[[69,768]],201:[[69,769]],202:[[69,770],,{768:7872,769:7870,771:7876,777:7874}],203:[[69,776]],204:[[73,768]],205:[[73,769]],206:[[73,770]],207:[[73,776],,{769:7726}],209:[[78,771]],210:[[79,768]],211:[[79,769]],212:[[79,770],,{768:7890,769:7888,771:7894,777:7892}],213:[[79,771],,{769:7756,772:556,776:7758}],214:[[79,776],,{772:554}],216:[,,{769:510}],217:[[85,768]],218:[[85,769]],219:[[85,770]],220:[[85,776],,{768:475,769:471,772:469,780:473}],221:[[89,769]],224:[[97,768]],225:[[97,769]],226:[[97,770],,{768:7847,769:7845,771:7851,777:7849}],227:[[97,771]],228:[[97,776],,{772:479}],229:[[97,778],,{769:507}],230:[,,{769:509,772:483}],231:[[99,807],,{769:7689}],232:[[101,768]],233:[[101,769]],234:[[101,770],,{768:7873,769:7871,771:7877,777:7875}],235:[[101,776]],236:[[105,768]],237:[[105,769]],238:[[105,770]],239:[[105,776],,{769:7727}],241:[[110,771]],242:[[111,768]],243:[[111,769]],244:[[111,770],,{768:7891,769:7889,771:7895,777:7893}],245:[[111,771],,{769:7757,772:557,776:7759}],246:[[111,776],,{772:555}],248:[,,{769:511}],249:[[117,768]],250:[[117,769]],251:[[117,770]],252:[[117,776],,{768:476,769:472,772:470,780:474}],253:[[121,769]],255:[[121,776]]}, | ||
299 | 256:{256:[[65,772]],257:[[97,772]],258:[[65,774],,{768:7856,769:7854,771:7860,777:7858}],259:[[97,774],,{768:7857,769:7855,771:7861,777:7859}],260:[[65,808]],261:[[97,808]],262:[[67,769]],263:[[99,769]],264:[[67,770]],265:[[99,770]],266:[[67,775]],267:[[99,775]],268:[[67,780]],269:[[99,780]],270:[[68,780]],271:[[100,780]],274:[[69,772],,{768:7700,769:7702}],275:[[101,772],,{768:7701,769:7703}],276:[[69,774]],277:[[101,774]],278:[[69,775]],279:[[101,775]],280:[[69,808]],281:[[101,808]],282:[[69,780]],283:[[101,780]],284:[[71,770]],285:[[103,770]],286:[[71,774]],287:[[103,774]],288:[[71,775]],289:[[103,775]],290:[[71,807]],291:[[103,807]],292:[[72,770]],293:[[104,770]],296:[[73,771]],297:[[105,771]],298:[[73,772]],299:[[105,772]],300:[[73,774]],301:[[105,774]],302:[[73,808]],303:[[105,808]],304:[[73,775]],306:[[73,74],256],307:[[105,106],256],308:[[74,770]],309:[[106,770]],310:[[75,807]],311:[[107,807]],313:[[76,769]],314:[[108,769]],315:[[76,807]],316:[[108,807]],317:[[76,780]],318:[[108,780]],319:[[76,183],256],320:[[108,183],256],323:[[78,769]],324:[[110,769]],325:[[78,807]],326:[[110,807]],327:[[78,780]],328:[[110,780]],329:[[700,110],256],332:[[79,772],,{768:7760,769:7762}],333:[[111,772],,{768:7761,769:7763}],334:[[79,774]],335:[[111,774]],336:[[79,779]],337:[[111,779]],340:[[82,769]],341:[[114,769]],342:[[82,807]],343:[[114,807]],344:[[82,780]],345:[[114,780]],346:[[83,769],,{775:7780}],347:[[115,769],,{775:7781}],348:[[83,770]],349:[[115,770]],350:[[83,807]],351:[[115,807]],352:[[83,780],,{775:7782}],353:[[115,780],,{775:7783}],354:[[84,807]],355:[[116,807]],356:[[84,780]],357:[[116,780]],360:[[85,771],,{769:7800}],361:[[117,771],,{769:7801}],362:[[85,772],,{776:7802}],363:[[117,772],,{776:7803}],364:[[85,774]],365:[[117,774]],366:[[85,778]],367:[[117,778]],368:[[85,779]],369:[[117,779]],370:[[85,808]],371:[[117,808]],372:[[87,770]],373:[[119,770]],374:[[89,770]],375:[[121,770]],376:[[89,776]],377:[[90,769]],378:[[122,769]],379:[[90,775]],380:[[122,775]],381:[[90,780]],382:[[122,780]],383:[[115],256,{775:7835}],416:[[79,795],,{768:7900,769:7898,771:7904,777:7902,803:7906}],417:[[111,795],,{768:7901,769:7899,771:7905,777:7903,803:7907}],431:[[85,795],,{768:7914,769:7912,771:7918,777:7916,803:7920}],432:[[117,795],,{768:7915,769:7913,771:7919,777:7917,803:7921}],439:[,,{780:494}],452:[[68,381],256],453:[[68,382],256],454:[[100,382],256],455:[[76,74],256],456:[[76,106],256],457:[[108,106],256],458:[[78,74],256],459:[[78,106],256],460:[[110,106],256],461:[[65,780]],462:[[97,780]],463:[[73,780]],464:[[105,780]],465:[[79,780]],466:[[111,780]],467:[[85,780]],468:[[117,780]],469:[[220,772]],470:[[252,772]],471:[[220,769]],472:[[252,769]],473:[[220,780]],474:[[252,780]],475:[[220,768]],476:[[252,768]],478:[[196,772]],479:[[228,772]],480:[[550,772]],481:[[551,772]],482:[[198,772]],483:[[230,772]],486:[[71,780]],487:[[103,780]],488:[[75,780]],489:[[107,780]],490:[[79,808],,{772:492}],491:[[111,808],,{772:493}],492:[[490,772]],493:[[491,772]],494:[[439,780]],495:[[658,780]],496:[[106,780]],497:[[68,90],256],498:[[68,122],256],499:[[100,122],256],500:[[71,769]],501:[[103,769]],504:[[78,768]],505:[[110,768]],506:[[197,769]],507:[[229,769]],508:[[198,769]],509:[[230,769]],510:[[216,769]],511:[[248,769]],66045:[,220]}, | ||
300 | 512:{512:[[65,783]],513:[[97,783]],514:[[65,785]],515:[[97,785]],516:[[69,783]],517:[[101,783]],518:[[69,785]],519:[[101,785]],520:[[73,783]],521:[[105,783]],522:[[73,785]],523:[[105,785]],524:[[79,783]],525:[[111,783]],526:[[79,785]],527:[[111,785]],528:[[82,783]],529:[[114,783]],530:[[82,785]],531:[[114,785]],532:[[85,783]],533:[[117,783]],534:[[85,785]],535:[[117,785]],536:[[83,806]],537:[[115,806]],538:[[84,806]],539:[[116,806]],542:[[72,780]],543:[[104,780]],550:[[65,775],,{772:480}],551:[[97,775],,{772:481}],552:[[69,807],,{774:7708}],553:[[101,807],,{774:7709}],554:[[214,772]],555:[[246,772]],556:[[213,772]],557:[[245,772]],558:[[79,775],,{772:560}],559:[[111,775],,{772:561}],560:[[558,772]],561:[[559,772]],562:[[89,772]],563:[[121,772]],658:[,,{780:495}],688:[[104],256],689:[[614],256],690:[[106],256],691:[[114],256],692:[[633],256],693:[[635],256],694:[[641],256],695:[[119],256],696:[[121],256],728:[[32,774],256],729:[[32,775],256],730:[[32,778],256],731:[[32,808],256],732:[[32,771],256],733:[[32,779],256],736:[[611],256],737:[[108],256],738:[[115],256],739:[[120],256],740:[[661],256],66272:[,220]}, | ||
301 | 768:{768:[,230],769:[,230],770:[,230],771:[,230],772:[,230],773:[,230],774:[,230],775:[,230],776:[,230,{769:836}],777:[,230],778:[,230],779:[,230],780:[,230],781:[,230],782:[,230],783:[,230],784:[,230],785:[,230],786:[,230],787:[,230],788:[,230],789:[,232],790:[,220],791:[,220],792:[,220],793:[,220],794:[,232],795:[,216],796:[,220],797:[,220],798:[,220],799:[,220],800:[,220],801:[,202],802:[,202],803:[,220],804:[,220],805:[,220],806:[,220],807:[,202],808:[,202],809:[,220],810:[,220],811:[,220],812:[,220],813:[,220],814:[,220],815:[,220],816:[,220],817:[,220],818:[,220],819:[,220],820:[,1],821:[,1],822:[,1],823:[,1],824:[,1],825:[,220],826:[,220],827:[,220],828:[,220],829:[,230],830:[,230],831:[,230],832:[[768],230],833:[[769],230],834:[,230],835:[[787],230],836:[[776,769],230],837:[,240],838:[,230],839:[,220],840:[,220],841:[,220],842:[,230],843:[,230],844:[,230],845:[,220],846:[,220],848:[,230],849:[,230],850:[,230],851:[,220],852:[,220],853:[,220],854:[,220],855:[,230],856:[,232],857:[,220],858:[,220],859:[,230],860:[,233],861:[,234],862:[,234],863:[,233],864:[,234],865:[,234],866:[,233],867:[,230],868:[,230],869:[,230],870:[,230],871:[,230],872:[,230],873:[,230],874:[,230],875:[,230],876:[,230],877:[,230],878:[,230],879:[,230],884:[[697]],890:[[32,837],256],894:[[59]],900:[[32,769],256],901:[[168,769]],902:[[913,769]],903:[[183]],904:[[917,769]],905:[[919,769]],906:[[921,769]],908:[[927,769]],910:[[933,769]],911:[[937,769]],912:[[970,769]],913:[,,{768:8122,769:902,772:8121,774:8120,787:7944,788:7945,837:8124}],917:[,,{768:8136,769:904,787:7960,788:7961}],919:[,,{768:8138,769:905,787:7976,788:7977,837:8140}],921:[,,{768:8154,769:906,772:8153,774:8152,776:938,787:7992,788:7993}],927:[,,{768:8184,769:908,787:8008,788:8009}],929:[,,{788:8172}],933:[,,{768:8170,769:910,772:8169,774:8168,776:939,788:8025}],937:[,,{768:8186,769:911,787:8040,788:8041,837:8188}],938:[[921,776]],939:[[933,776]],940:[[945,769],,{837:8116}],941:[[949,769]],942:[[951,769],,{837:8132}],943:[[953,769]],944:[[971,769]],945:[,,{768:8048,769:940,772:8113,774:8112,787:7936,788:7937,834:8118,837:8115}],949:[,,{768:8050,769:941,787:7952,788:7953}],951:[,,{768:8052,769:942,787:7968,788:7969,834:8134,837:8131}],953:[,,{768:8054,769:943,772:8145,774:8144,776:970,787:7984,788:7985,834:8150}],959:[,,{768:8056,769:972,787:8000,788:8001}],961:[,,{787:8164,788:8165}],965:[,,{768:8058,769:973,772:8161,774:8160,776:971,787:8016,788:8017,834:8166}],969:[,,{768:8060,769:974,787:8032,788:8033,834:8182,837:8179}],970:[[953,776],,{768:8146,769:912,834:8151}],971:[[965,776],,{768:8162,769:944,834:8167}],972:[[959,769]],973:[[965,769]],974:[[969,769],,{837:8180}],976:[[946],256],977:[[952],256],978:[[933],256,{769:979,776:980}],979:[[978,769]],980:[[978,776]],981:[[966],256],982:[[960],256],1008:[[954],256],1009:[[961],256],1010:[[962],256],1012:[[920],256],1013:[[949],256],1017:[[931],256],66422:[,230],66423:[,230],66424:[,230],66425:[,230],66426:[,230]}, | ||
302 | 1024:{1024:[[1045,768]],1025:[[1045,776]],1027:[[1043,769]],1030:[,,{776:1031}],1031:[[1030,776]],1036:[[1050,769]],1037:[[1048,768]],1038:[[1059,774]],1040:[,,{774:1232,776:1234}],1043:[,,{769:1027}],1045:[,,{768:1024,774:1238,776:1025}],1046:[,,{774:1217,776:1244}],1047:[,,{776:1246}],1048:[,,{768:1037,772:1250,774:1049,776:1252}],1049:[[1048,774]],1050:[,,{769:1036}],1054:[,,{776:1254}],1059:[,,{772:1262,774:1038,776:1264,779:1266}],1063:[,,{776:1268}],1067:[,,{776:1272}],1069:[,,{776:1260}],1072:[,,{774:1233,776:1235}],1075:[,,{769:1107}],1077:[,,{768:1104,774:1239,776:1105}],1078:[,,{774:1218,776:1245}],1079:[,,{776:1247}],1080:[,,{768:1117,772:1251,774:1081,776:1253}],1081:[[1080,774]],1082:[,,{769:1116}],1086:[,,{776:1255}],1091:[,,{772:1263,774:1118,776:1265,779:1267}],1095:[,,{776:1269}],1099:[,,{776:1273}],1101:[,,{776:1261}],1104:[[1077,768]],1105:[[1077,776]],1107:[[1075,769]],1110:[,,{776:1111}],1111:[[1110,776]],1116:[[1082,769]],1117:[[1080,768]],1118:[[1091,774]],1140:[,,{783:1142}],1141:[,,{783:1143}],1142:[[1140,783]],1143:[[1141,783]],1155:[,230],1156:[,230],1157:[,230],1158:[,230],1159:[,230],1217:[[1046,774]],1218:[[1078,774]],1232:[[1040,774]],1233:[[1072,774]],1234:[[1040,776]],1235:[[1072,776]],1238:[[1045,774]],1239:[[1077,774]],1240:[,,{776:1242}],1241:[,,{776:1243}],1242:[[1240,776]],1243:[[1241,776]],1244:[[1046,776]],1245:[[1078,776]],1246:[[1047,776]],1247:[[1079,776]],1250:[[1048,772]],1251:[[1080,772]],1252:[[1048,776]],1253:[[1080,776]],1254:[[1054,776]],1255:[[1086,776]],1256:[,,{776:1258}],1257:[,,{776:1259}],1258:[[1256,776]],1259:[[1257,776]],1260:[[1069,776]],1261:[[1101,776]],1262:[[1059,772]],1263:[[1091,772]],1264:[[1059,776]],1265:[[1091,776]],1266:[[1059,779]],1267:[[1091,779]],1268:[[1063,776]],1269:[[1095,776]],1272:[[1067,776]],1273:[[1099,776]]}, | ||
303 | 1280:{1415:[[1381,1410],256],1425:[,220],1426:[,230],1427:[,230],1428:[,230],1429:[,230],1430:[,220],1431:[,230],1432:[,230],1433:[,230],1434:[,222],1435:[,220],1436:[,230],1437:[,230],1438:[,230],1439:[,230],1440:[,230],1441:[,230],1442:[,220],1443:[,220],1444:[,220],1445:[,220],1446:[,220],1447:[,220],1448:[,230],1449:[,230],1450:[,220],1451:[,230],1452:[,230],1453:[,222],1454:[,228],1455:[,230],1456:[,10],1457:[,11],1458:[,12],1459:[,13],1460:[,14],1461:[,15],1462:[,16],1463:[,17],1464:[,18],1465:[,19],1466:[,19],1467:[,20],1468:[,21],1469:[,22],1471:[,23],1473:[,24],1474:[,25],1476:[,230],1477:[,220],1479:[,18]}, | ||
304 | 1536:{1552:[,230],1553:[,230],1554:[,230],1555:[,230],1556:[,230],1557:[,230],1558:[,230],1559:[,230],1560:[,30],1561:[,31],1562:[,32],1570:[[1575,1619]],1571:[[1575,1620]],1572:[[1608,1620]],1573:[[1575,1621]],1574:[[1610,1620]],1575:[,,{1619:1570,1620:1571,1621:1573}],1608:[,,{1620:1572}],1610:[,,{1620:1574}],1611:[,27],1612:[,28],1613:[,29],1614:[,30],1615:[,31],1616:[,32],1617:[,33],1618:[,34],1619:[,230],1620:[,230],1621:[,220],1622:[,220],1623:[,230],1624:[,230],1625:[,230],1626:[,230],1627:[,230],1628:[,220],1629:[,230],1630:[,230],1631:[,220],1648:[,35],1653:[[1575,1652],256],1654:[[1608,1652],256],1655:[[1735,1652],256],1656:[[1610,1652],256],1728:[[1749,1620]],1729:[,,{1620:1730}],1730:[[1729,1620]],1746:[,,{1620:1747}],1747:[[1746,1620]],1749:[,,{1620:1728}],1750:[,230],1751:[,230],1752:[,230],1753:[,230],1754:[,230],1755:[,230],1756:[,230],1759:[,230],1760:[,230],1761:[,230],1762:[,230],1763:[,220],1764:[,230],1767:[,230],1768:[,230],1770:[,220],1771:[,230],1772:[,230],1773:[,220]}, | ||
305 | 1792:{1809:[,36],1840:[,230],1841:[,220],1842:[,230],1843:[,230],1844:[,220],1845:[,230],1846:[,230],1847:[,220],1848:[,220],1849:[,220],1850:[,230],1851:[,220],1852:[,220],1853:[,230],1854:[,220],1855:[,230],1856:[,230],1857:[,230],1858:[,220],1859:[,230],1860:[,220],1861:[,230],1862:[,220],1863:[,230],1864:[,220],1865:[,230],1866:[,230],2027:[,230],2028:[,230],2029:[,230],2030:[,230],2031:[,230],2032:[,230],2033:[,230],2034:[,220],2035:[,230]}, | ||
306 | 2048:{2070:[,230],2071:[,230],2072:[,230],2073:[,230],2075:[,230],2076:[,230],2077:[,230],2078:[,230],2079:[,230],2080:[,230],2081:[,230],2082:[,230],2083:[,230],2085:[,230],2086:[,230],2087:[,230],2089:[,230],2090:[,230],2091:[,230],2092:[,230],2093:[,230],2137:[,220],2138:[,220],2139:[,220],2276:[,230],2277:[,230],2278:[,220],2279:[,230],2280:[,230],2281:[,220],2282:[,230],2283:[,230],2284:[,230],2285:[,220],2286:[,220],2287:[,220],2288:[,27],2289:[,28],2290:[,29],2291:[,230],2292:[,230],2293:[,230],2294:[,220],2295:[,230],2296:[,230],2297:[,220],2298:[,220],2299:[,230],2300:[,230],2301:[,230],2302:[,230],2303:[,230]}, | ||
307 | 2304:{2344:[,,{2364:2345}],2345:[[2344,2364]],2352:[,,{2364:2353}],2353:[[2352,2364]],2355:[,,{2364:2356}],2356:[[2355,2364]],2364:[,7],2381:[,9],2385:[,230],2386:[,220],2387:[,230],2388:[,230],2392:[[2325,2364],512],2393:[[2326,2364],512],2394:[[2327,2364],512],2395:[[2332,2364],512],2396:[[2337,2364],512],2397:[[2338,2364],512],2398:[[2347,2364],512],2399:[[2351,2364],512],2492:[,7],2503:[,,{2494:2507,2519:2508}],2507:[[2503,2494]],2508:[[2503,2519]],2509:[,9],2524:[[2465,2492],512],2525:[[2466,2492],512],2527:[[2479,2492],512]}, | ||
308 | 2560:{2611:[[2610,2620],512],2614:[[2616,2620],512],2620:[,7],2637:[,9],2649:[[2582,2620],512],2650:[[2583,2620],512],2651:[[2588,2620],512],2654:[[2603,2620],512],2748:[,7],2765:[,9],68109:[,220],68111:[,230],68152:[,230],68153:[,1],68154:[,220],68159:[,9],68325:[,230],68326:[,220]}, | ||
309 | 2816:{2876:[,7],2887:[,,{2878:2891,2902:2888,2903:2892}],2888:[[2887,2902]],2891:[[2887,2878]],2892:[[2887,2903]],2893:[,9],2908:[[2849,2876],512],2909:[[2850,2876],512],2962:[,,{3031:2964}],2964:[[2962,3031]],3014:[,,{3006:3018,3031:3020}],3015:[,,{3006:3019}],3018:[[3014,3006]],3019:[[3015,3006]],3020:[[3014,3031]],3021:[,9]}, | ||
310 | 3072:{3142:[,,{3158:3144}],3144:[[3142,3158]],3149:[,9],3157:[,84],3158:[,91],3260:[,7],3263:[,,{3285:3264}],3264:[[3263,3285]],3270:[,,{3266:3274,3285:3271,3286:3272}],3271:[[3270,3285]],3272:[[3270,3286]],3274:[[3270,3266],,{3285:3275}],3275:[[3274,3285]],3277:[,9]}, | ||
311 | 3328:{3398:[,,{3390:3402,3415:3404}],3399:[,,{3390:3403}],3402:[[3398,3390]],3403:[[3399,3390]],3404:[[3398,3415]],3405:[,9],3530:[,9],3545:[,,{3530:3546,3535:3548,3551:3550}],3546:[[3545,3530]],3548:[[3545,3535],,{3530:3549}],3549:[[3548,3530]],3550:[[3545,3551]]}, | ||
312 | 3584:{3635:[[3661,3634],256],3640:[,103],3641:[,103],3642:[,9],3656:[,107],3657:[,107],3658:[,107],3659:[,107],3763:[[3789,3762],256],3768:[,118],3769:[,118],3784:[,122],3785:[,122],3786:[,122],3787:[,122],3804:[[3755,3737],256],3805:[[3755,3745],256]}, | ||
313 | 3840:{3852:[[3851],256],3864:[,220],3865:[,220],3893:[,220],3895:[,220],3897:[,216],3907:[[3906,4023],512],3917:[[3916,4023],512],3922:[[3921,4023],512],3927:[[3926,4023],512],3932:[[3931,4023],512],3945:[[3904,4021],512],3953:[,129],3954:[,130],3955:[[3953,3954],512],3956:[,132],3957:[[3953,3956],512],3958:[[4018,3968],512],3959:[[4018,3969],256],3960:[[4019,3968],512],3961:[[4019,3969],256],3962:[,130],3963:[,130],3964:[,130],3965:[,130],3968:[,130],3969:[[3953,3968],512],3970:[,230],3971:[,230],3972:[,9],3974:[,230],3975:[,230],3987:[[3986,4023],512],3997:[[3996,4023],512],4002:[[4001,4023],512],4007:[[4006,4023],512],4012:[[4011,4023],512],4025:[[3984,4021],512],4038:[,220]}, | ||
314 | 4096:{4133:[,,{4142:4134}],4134:[[4133,4142]],4151:[,7],4153:[,9],4154:[,9],4237:[,220],4348:[[4316],256],69702:[,9],69759:[,9],69785:[,,{69818:69786}],69786:[[69785,69818]],69787:[,,{69818:69788}],69788:[[69787,69818]],69797:[,,{69818:69803}],69803:[[69797,69818]],69817:[,9],69818:[,7]}, | ||
315 | 4352:{69888:[,230],69889:[,230],69890:[,230],69934:[[69937,69927]],69935:[[69938,69927]],69937:[,,{69927:69934}],69938:[,,{69927:69935}],69939:[,9],69940:[,9],70003:[,7],70080:[,9]}, | ||
316 | 4608:{70197:[,9],70198:[,7],70377:[,7],70378:[,9]}, | ||
317 | 4864:{4957:[,230],4958:[,230],4959:[,230],70460:[,7],70471:[,,{70462:70475,70487:70476}],70475:[[70471,70462]],70476:[[70471,70487]],70477:[,9],70502:[,230],70503:[,230],70504:[,230],70505:[,230],70506:[,230],70507:[,230],70508:[,230],70512:[,230],70513:[,230],70514:[,230],70515:[,230],70516:[,230]}, | ||
318 | 5120:{70841:[,,{70832:70844,70842:70843,70845:70846}],70843:[[70841,70842]],70844:[[70841,70832]],70846:[[70841,70845]],70850:[,9],70851:[,7]}, | ||
319 | 5376:{71096:[,,{71087:71098}],71097:[,,{71087:71099}],71098:[[71096,71087]],71099:[[71097,71087]],71103:[,9],71104:[,7]}, | ||
320 | 5632:{71231:[,9],71350:[,9],71351:[,7]}, | ||
321 | 5888:{5908:[,9],5940:[,9],6098:[,9],6109:[,230]}, | ||
322 | 6144:{6313:[,228]}, | ||
323 | 6400:{6457:[,222],6458:[,230],6459:[,220]}, | ||
324 | 6656:{6679:[,230],6680:[,220],6752:[,9],6773:[,230],6774:[,230],6775:[,230],6776:[,230],6777:[,230],6778:[,230],6779:[,230],6780:[,230],6783:[,220],6832:[,230],6833:[,230],6834:[,230],6835:[,230],6836:[,230],6837:[,220],6838:[,220],6839:[,220],6840:[,220],6841:[,220],6842:[,220],6843:[,230],6844:[,230],6845:[,220]}, | ||
325 | 6912:{6917:[,,{6965:6918}],6918:[[6917,6965]],6919:[,,{6965:6920}],6920:[[6919,6965]],6921:[,,{6965:6922}],6922:[[6921,6965]],6923:[,,{6965:6924}],6924:[[6923,6965]],6925:[,,{6965:6926}],6926:[[6925,6965]],6929:[,,{6965:6930}],6930:[[6929,6965]],6964:[,7],6970:[,,{6965:6971}],6971:[[6970,6965]],6972:[,,{6965:6973}],6973:[[6972,6965]],6974:[,,{6965:6976}],6975:[,,{6965:6977}],6976:[[6974,6965]],6977:[[6975,6965]],6978:[,,{6965:6979}],6979:[[6978,6965]],6980:[,9],7019:[,230],7020:[,220],7021:[,230],7022:[,230],7023:[,230],7024:[,230],7025:[,230],7026:[,230],7027:[,230],7082:[,9],7083:[,9],7142:[,7],7154:[,9],7155:[,9]}, | ||
326 | 7168:{7223:[,7],7376:[,230],7377:[,230],7378:[,230],7380:[,1],7381:[,220],7382:[,220],7383:[,220],7384:[,220],7385:[,220],7386:[,230],7387:[,230],7388:[,220],7389:[,220],7390:[,220],7391:[,220],7392:[,230],7394:[,1],7395:[,1],7396:[,1],7397:[,1],7398:[,1],7399:[,1],7400:[,1],7405:[,220],7412:[,230],7416:[,230],7417:[,230]}, | ||
327 | 7424:{7468:[[65],256],7469:[[198],256],7470:[[66],256],7472:[[68],256],7473:[[69],256],7474:[[398],256],7475:[[71],256],7476:[[72],256],7477:[[73],256],7478:[[74],256],7479:[[75],256],7480:[[76],256],7481:[[77],256],7482:[[78],256],7484:[[79],256],7485:[[546],256],7486:[[80],256],7487:[[82],256],7488:[[84],256],7489:[[85],256],7490:[[87],256],7491:[[97],256],7492:[[592],256],7493:[[593],256],7494:[[7426],256],7495:[[98],256],7496:[[100],256],7497:[[101],256],7498:[[601],256],7499:[[603],256],7500:[[604],256],7501:[[103],256],7503:[[107],256],7504:[[109],256],7505:[[331],256],7506:[[111],256],7507:[[596],256],7508:[[7446],256],7509:[[7447],256],7510:[[112],256],7511:[[116],256],7512:[[117],256],7513:[[7453],256],7514:[[623],256],7515:[[118],256],7516:[[7461],256],7517:[[946],256],7518:[[947],256],7519:[[948],256],7520:[[966],256],7521:[[967],256],7522:[[105],256],7523:[[114],256],7524:[[117],256],7525:[[118],256],7526:[[946],256],7527:[[947],256],7528:[[961],256],7529:[[966],256],7530:[[967],256],7544:[[1085],256],7579:[[594],256],7580:[[99],256],7581:[[597],256],7582:[[240],256],7583:[[604],256],7584:[[102],256],7585:[[607],256],7586:[[609],256],7587:[[613],256],7588:[[616],256],7589:[[617],256],7590:[[618],256],7591:[[7547],256],7592:[[669],256],7593:[[621],256],7594:[[7557],256],7595:[[671],256],7596:[[625],256],7597:[[624],256],7598:[[626],256],7599:[[627],256],7600:[[628],256],7601:[[629],256],7602:[[632],256],7603:[[642],256],7604:[[643],256],7605:[[427],256],7606:[[649],256],7607:[[650],256],7608:[[7452],256],7609:[[651],256],7610:[[652],256],7611:[[122],256],7612:[[656],256],7613:[[657],256],7614:[[658],256],7615:[[952],256],7616:[,230],7617:[,230],7618:[,220],7619:[,230],7620:[,230],7621:[,230],7622:[,230],7623:[,230],7624:[,230],7625:[,230],7626:[,220],7627:[,230],7628:[,230],7629:[,234],7630:[,214],7631:[,220],7632:[,202],7633:[,230],7634:[,230],7635:[,230],7636:[,230],7637:[,230],7638:[,230],7639:[,230],7640:[,230],7641:[,230],7642:[,230],7643:[,230],7644:[,230],7645:[,230],7646:[,230],7647:[,230],7648:[,230],7649:[,230],7650:[,230],7651:[,230],7652:[,230],7653:[,230],7654:[,230],7655:[,230],7656:[,230],7657:[,230],7658:[,230],7659:[,230],7660:[,230],7661:[,230],7662:[,230],7663:[,230],7664:[,230],7665:[,230],7666:[,230],7667:[,230],7668:[,230],7669:[,230],7676:[,233],7677:[,220],7678:[,230],7679:[,220]}, | ||
328 | 7680:{7680:[[65,805]],7681:[[97,805]],7682:[[66,775]],7683:[[98,775]],7684:[[66,803]],7685:[[98,803]],7686:[[66,817]],7687:[[98,817]],7688:[[199,769]],7689:[[231,769]],7690:[[68,775]],7691:[[100,775]],7692:[[68,803]],7693:[[100,803]],7694:[[68,817]],7695:[[100,817]],7696:[[68,807]],7697:[[100,807]],7698:[[68,813]],7699:[[100,813]],7700:[[274,768]],7701:[[275,768]],7702:[[274,769]],7703:[[275,769]],7704:[[69,813]],7705:[[101,813]],7706:[[69,816]],7707:[[101,816]],7708:[[552,774]],7709:[[553,774]],7710:[[70,775]],7711:[[102,775]],7712:[[71,772]],7713:[[103,772]],7714:[[72,775]],7715:[[104,775]],7716:[[72,803]],7717:[[104,803]],7718:[[72,776]],7719:[[104,776]],7720:[[72,807]],7721:[[104,807]],7722:[[72,814]],7723:[[104,814]],7724:[[73,816]],7725:[[105,816]],7726:[[207,769]],7727:[[239,769]],7728:[[75,769]],7729:[[107,769]],7730:[[75,803]],7731:[[107,803]],7732:[[75,817]],7733:[[107,817]],7734:[[76,803],,{772:7736}],7735:[[108,803],,{772:7737}],7736:[[7734,772]],7737:[[7735,772]],7738:[[76,817]],7739:[[108,817]],7740:[[76,813]],7741:[[108,813]],7742:[[77,769]],7743:[[109,769]],7744:[[77,775]],7745:[[109,775]],7746:[[77,803]],7747:[[109,803]],7748:[[78,775]],7749:[[110,775]],7750:[[78,803]],7751:[[110,803]],7752:[[78,817]],7753:[[110,817]],7754:[[78,813]],7755:[[110,813]],7756:[[213,769]],7757:[[245,769]],7758:[[213,776]],7759:[[245,776]],7760:[[332,768]],7761:[[333,768]],7762:[[332,769]],7763:[[333,769]],7764:[[80,769]],7765:[[112,769]],7766:[[80,775]],7767:[[112,775]],7768:[[82,775]],7769:[[114,775]],7770:[[82,803],,{772:7772}],7771:[[114,803],,{772:7773}],7772:[[7770,772]],7773:[[7771,772]],7774:[[82,817]],7775:[[114,817]],7776:[[83,775]],7777:[[115,775]],7778:[[83,803],,{775:7784}],7779:[[115,803],,{775:7785}],7780:[[346,775]],7781:[[347,775]],7782:[[352,775]],7783:[[353,775]],7784:[[7778,775]],7785:[[7779,775]],7786:[[84,775]],7787:[[116,775]],7788:[[84,803]],7789:[[116,803]],7790:[[84,817]],7791:[[116,817]],7792:[[84,813]],7793:[[116,813]],7794:[[85,804]],7795:[[117,804]],7796:[[85,816]],7797:[[117,816]],7798:[[85,813]],7799:[[117,813]],7800:[[360,769]],7801:[[361,769]],7802:[[362,776]],7803:[[363,776]],7804:[[86,771]],7805:[[118,771]],7806:[[86,803]],7807:[[118,803]],7808:[[87,768]],7809:[[119,768]],7810:[[87,769]],7811:[[119,769]],7812:[[87,776]],7813:[[119,776]],7814:[[87,775]],7815:[[119,775]],7816:[[87,803]],7817:[[119,803]],7818:[[88,775]],7819:[[120,775]],7820:[[88,776]],7821:[[120,776]],7822:[[89,775]],7823:[[121,775]],7824:[[90,770]],7825:[[122,770]],7826:[[90,803]],7827:[[122,803]],7828:[[90,817]],7829:[[122,817]],7830:[[104,817]],7831:[[116,776]],7832:[[119,778]],7833:[[121,778]],7834:[[97,702],256],7835:[[383,775]],7840:[[65,803],,{770:7852,774:7862}],7841:[[97,803],,{770:7853,774:7863}],7842:[[65,777]],7843:[[97,777]],7844:[[194,769]],7845:[[226,769]],7846:[[194,768]],7847:[[226,768]],7848:[[194,777]],7849:[[226,777]],7850:[[194,771]],7851:[[226,771]],7852:[[7840,770]],7853:[[7841,770]],7854:[[258,769]],7855:[[259,769]],7856:[[258,768]],7857:[[259,768]],7858:[[258,777]],7859:[[259,777]],7860:[[258,771]],7861:[[259,771]],7862:[[7840,774]],7863:[[7841,774]],7864:[[69,803],,{770:7878}],7865:[[101,803],,{770:7879}],7866:[[69,777]],7867:[[101,777]],7868:[[69,771]],7869:[[101,771]],7870:[[202,769]],7871:[[234,769]],7872:[[202,768]],7873:[[234,768]],7874:[[202,777]],7875:[[234,777]],7876:[[202,771]],7877:[[234,771]],7878:[[7864,770]],7879:[[7865,770]],7880:[[73,777]],7881:[[105,777]],7882:[[73,803]],7883:[[105,803]],7884:[[79,803],,{770:7896}],7885:[[111,803],,{770:7897}],7886:[[79,777]],7887:[[111,777]],7888:[[212,769]],7889:[[244,769]],7890:[[212,768]],7891:[[244,768]],7892:[[212,777]],7893:[[244,777]],7894:[[212,771]],7895:[[244,771]],7896:[[7884,770]],7897:[[7885,770]],7898:[[416,769]],7899:[[417,769]],7900:[[416,768]],7901:[[417,768]],7902:[[416,777]],7903:[[417,777]],7904:[[416,771]],7905:[[417,771]],7906:[[416,803]],7907:[[417,803]],7908:[[85,803]],7909:[[117,803]],7910:[[85,777]],7911:[[117,777]],7912:[[431,769]],7913:[[432,769]],7914:[[431,768]],7915:[[432,768]],7916:[[431,777]],7917:[[432,777]],7918:[[431,771]],7919:[[432,771]],7920:[[431,803]],7921:[[432,803]],7922:[[89,768]],7923:[[121,768]],7924:[[89,803]],7925:[[121,803]],7926:[[89,777]],7927:[[121,777]],7928:[[89,771]],7929:[[121,771]]}, | ||
329 | 7936:{7936:[[945,787],,{768:7938,769:7940,834:7942,837:8064}],7937:[[945,788],,{768:7939,769:7941,834:7943,837:8065}],7938:[[7936,768],,{837:8066}],7939:[[7937,768],,{837:8067}],7940:[[7936,769],,{837:8068}],7941:[[7937,769],,{837:8069}],7942:[[7936,834],,{837:8070}],7943:[[7937,834],,{837:8071}],7944:[[913,787],,{768:7946,769:7948,834:7950,837:8072}],7945:[[913,788],,{768:7947,769:7949,834:7951,837:8073}],7946:[[7944,768],,{837:8074}],7947:[[7945,768],,{837:8075}],7948:[[7944,769],,{837:8076}],7949:[[7945,769],,{837:8077}],7950:[[7944,834],,{837:8078}],7951:[[7945,834],,{837:8079}],7952:[[949,787],,{768:7954,769:7956}],7953:[[949,788],,{768:7955,769:7957}],7954:[[7952,768]],7955:[[7953,768]],7956:[[7952,769]],7957:[[7953,769]],7960:[[917,787],,{768:7962,769:7964}],7961:[[917,788],,{768:7963,769:7965}],7962:[[7960,768]],7963:[[7961,768]],7964:[[7960,769]],7965:[[7961,769]],7968:[[951,787],,{768:7970,769:7972,834:7974,837:8080}],7969:[[951,788],,{768:7971,769:7973,834:7975,837:8081}],7970:[[7968,768],,{837:8082}],7971:[[7969,768],,{837:8083}],7972:[[7968,769],,{837:8084}],7973:[[7969,769],,{837:8085}],7974:[[7968,834],,{837:8086}],7975:[[7969,834],,{837:8087}],7976:[[919,787],,{768:7978,769:7980,834:7982,837:8088}],7977:[[919,788],,{768:7979,769:7981,834:7983,837:8089}],7978:[[7976,768],,{837:8090}],7979:[[7977,768],,{837:8091}],7980:[[7976,769],,{837:8092}],7981:[[7977,769],,{837:8093}],7982:[[7976,834],,{837:8094}],7983:[[7977,834],,{837:8095}],7984:[[953,787],,{768:7986,769:7988,834:7990}],7985:[[953,788],,{768:7987,769:7989,834:7991}],7986:[[7984,768]],7987:[[7985,768]],7988:[[7984,769]],7989:[[7985,769]],7990:[[7984,834]],7991:[[7985,834]],7992:[[921,787],,{768:7994,769:7996,834:7998}],7993:[[921,788],,{768:7995,769:7997,834:7999}],7994:[[7992,768]],7995:[[7993,768]],7996:[[7992,769]],7997:[[7993,769]],7998:[[7992,834]],7999:[[7993,834]],8000:[[959,787],,{768:8002,769:8004}],8001:[[959,788],,{768:8003,769:8005}],8002:[[8000,768]],8003:[[8001,768]],8004:[[8000,769]],8005:[[8001,769]],8008:[[927,787],,{768:8010,769:8012}],8009:[[927,788],,{768:8011,769:8013}],8010:[[8008,768]],8011:[[8009,768]],8012:[[8008,769]],8013:[[8009,769]],8016:[[965,787],,{768:8018,769:8020,834:8022}],8017:[[965,788],,{768:8019,769:8021,834:8023}],8018:[[8016,768]],8019:[[8017,768]],8020:[[8016,769]],8021:[[8017,769]],8022:[[8016,834]],8023:[[8017,834]],8025:[[933,788],,{768:8027,769:8029,834:8031}],8027:[[8025,768]],8029:[[8025,769]],8031:[[8025,834]],8032:[[969,787],,{768:8034,769:8036,834:8038,837:8096}],8033:[[969,788],,{768:8035,769:8037,834:8039,837:8097}],8034:[[8032,768],,{837:8098}],8035:[[8033,768],,{837:8099}],8036:[[8032,769],,{837:8100}],8037:[[8033,769],,{837:8101}],8038:[[8032,834],,{837:8102}],8039:[[8033,834],,{837:8103}],8040:[[937,787],,{768:8042,769:8044,834:8046,837:8104}],8041:[[937,788],,{768:8043,769:8045,834:8047,837:8105}],8042:[[8040,768],,{837:8106}],8043:[[8041,768],,{837:8107}],8044:[[8040,769],,{837:8108}],8045:[[8041,769],,{837:8109}],8046:[[8040,834],,{837:8110}],8047:[[8041,834],,{837:8111}],8048:[[945,768],,{837:8114}],8049:[[940]],8050:[[949,768]],8051:[[941]],8052:[[951,768],,{837:8130}],8053:[[942]],8054:[[953,768]],8055:[[943]],8056:[[959,768]],8057:[[972]],8058:[[965,768]],8059:[[973]],8060:[[969,768],,{837:8178}],8061:[[974]],8064:[[7936,837]],8065:[[7937,837]],8066:[[7938,837]],8067:[[7939,837]],8068:[[7940,837]],8069:[[7941,837]],8070:[[7942,837]],8071:[[7943,837]],8072:[[7944,837]],8073:[[7945,837]],8074:[[7946,837]],8075:[[7947,837]],8076:[[7948,837]],8077:[[7949,837]],8078:[[7950,837]],8079:[[7951,837]],8080:[[7968,837]],8081:[[7969,837]],8082:[[7970,837]],8083:[[7971,837]],8084:[[7972,837]],8085:[[7973,837]],8086:[[7974,837]],8087:[[7975,837]],8088:[[7976,837]],8089:[[7977,837]],8090:[[7978,837]],8091:[[7979,837]],8092:[[7980,837]],8093:[[7981,837]],8094:[[7982,837]],8095:[[7983,837]],8096:[[8032,837]],8097:[[8033,837]],8098:[[8034,837]],8099:[[8035,837]],8100:[[8036,837]],8101:[[8037,837]],8102:[[8038,837]],8103:[[8039,837]],8104:[[8040,837]],8105:[[8041,837]],8106:[[8042,837]],8107:[[8043,837]],8108:[[8044,837]],8109:[[8045,837]],8110:[[8046,837]],8111:[[8047,837]],8112:[[945,774]],8113:[[945,772]],8114:[[8048,837]],8115:[[945,837]],8116:[[940,837]],8118:[[945,834],,{837:8119}],8119:[[8118,837]],8120:[[913,774]],8121:[[913,772]],8122:[[913,768]],8123:[[902]],8124:[[913,837]],8125:[[32,787],256],8126:[[953]],8127:[[32,787],256,{768:8141,769:8142,834:8143}],8128:[[32,834],256],8129:[[168,834]],8130:[[8052,837]],8131:[[951,837]],8132:[[942,837]],8134:[[951,834],,{837:8135}],8135:[[8134,837]],8136:[[917,768]],8137:[[904]],8138:[[919,768]],8139:[[905]],8140:[[919,837]],8141:[[8127,768]],8142:[[8127,769]],8143:[[8127,834]],8144:[[953,774]],8145:[[953,772]],8146:[[970,768]],8147:[[912]],8150:[[953,834]],8151:[[970,834]],8152:[[921,774]],8153:[[921,772]],8154:[[921,768]],8155:[[906]],8157:[[8190,768]],8158:[[8190,769]],8159:[[8190,834]],8160:[[965,774]],8161:[[965,772]],8162:[[971,768]],8163:[[944]],8164:[[961,787]],8165:[[961,788]],8166:[[965,834]],8167:[[971,834]],8168:[[933,774]],8169:[[933,772]],8170:[[933,768]],8171:[[910]],8172:[[929,788]],8173:[[168,768]],8174:[[901]],8175:[[96]],8178:[[8060,837]],8179:[[969,837]],8180:[[974,837]],8182:[[969,834],,{837:8183}],8183:[[8182,837]],8184:[[927,768]],8185:[[908]],8186:[[937,768]],8187:[[911]],8188:[[937,837]],8189:[[180]],8190:[[32,788],256,{768:8157,769:8158,834:8159}]}, | ||
330 | 8192:{8192:[[8194]],8193:[[8195]],8194:[[32],256],8195:[[32],256],8196:[[32],256],8197:[[32],256],8198:[[32],256],8199:[[32],256],8200:[[32],256],8201:[[32],256],8202:[[32],256],8209:[[8208],256],8215:[[32,819],256],8228:[[46],256],8229:[[46,46],256],8230:[[46,46,46],256],8239:[[32],256],8243:[[8242,8242],256],8244:[[8242,8242,8242],256],8246:[[8245,8245],256],8247:[[8245,8245,8245],256],8252:[[33,33],256],8254:[[32,773],256],8263:[[63,63],256],8264:[[63,33],256],8265:[[33,63],256],8279:[[8242,8242,8242,8242],256],8287:[[32],256],8304:[[48],256],8305:[[105],256],8308:[[52],256],8309:[[53],256],8310:[[54],256],8311:[[55],256],8312:[[56],256],8313:[[57],256],8314:[[43],256],8315:[[8722],256],8316:[[61],256],8317:[[40],256],8318:[[41],256],8319:[[110],256],8320:[[48],256],8321:[[49],256],8322:[[50],256],8323:[[51],256],8324:[[52],256],8325:[[53],256],8326:[[54],256],8327:[[55],256],8328:[[56],256],8329:[[57],256],8330:[[43],256],8331:[[8722],256],8332:[[61],256],8333:[[40],256],8334:[[41],256],8336:[[97],256],8337:[[101],256],8338:[[111],256],8339:[[120],256],8340:[[601],256],8341:[[104],256],8342:[[107],256],8343:[[108],256],8344:[[109],256],8345:[[110],256],8346:[[112],256],8347:[[115],256],8348:[[116],256],8360:[[82,115],256],8400:[,230],8401:[,230],8402:[,1],8403:[,1],8404:[,230],8405:[,230],8406:[,230],8407:[,230],8408:[,1],8409:[,1],8410:[,1],8411:[,230],8412:[,230],8417:[,230],8421:[,1],8422:[,1],8423:[,230],8424:[,220],8425:[,230],8426:[,1],8427:[,1],8428:[,220],8429:[,220],8430:[,220],8431:[,220],8432:[,230]}, | ||
331 | 8448:{8448:[[97,47,99],256],8449:[[97,47,115],256],8450:[[67],256],8451:[[176,67],256],8453:[[99,47,111],256],8454:[[99,47,117],256],8455:[[400],256],8457:[[176,70],256],8458:[[103],256],8459:[[72],256],8460:[[72],256],8461:[[72],256],8462:[[104],256],8463:[[295],256],8464:[[73],256],8465:[[73],256],8466:[[76],256],8467:[[108],256],8469:[[78],256],8470:[[78,111],256],8473:[[80],256],8474:[[81],256],8475:[[82],256],8476:[[82],256],8477:[[82],256],8480:[[83,77],256],8481:[[84,69,76],256],8482:[[84,77],256],8484:[[90],256],8486:[[937]],8488:[[90],256],8490:[[75]],8491:[[197]],8492:[[66],256],8493:[[67],256],8495:[[101],256],8496:[[69],256],8497:[[70],256],8499:[[77],256],8500:[[111],256],8501:[[1488],256],8502:[[1489],256],8503:[[1490],256],8504:[[1491],256],8505:[[105],256],8507:[[70,65,88],256],8508:[[960],256],8509:[[947],256],8510:[[915],256],8511:[[928],256],8512:[[8721],256],8517:[[68],256],8518:[[100],256],8519:[[101],256],8520:[[105],256],8521:[[106],256],8528:[[49,8260,55],256],8529:[[49,8260,57],256],8530:[[49,8260,49,48],256],8531:[[49,8260,51],256],8532:[[50,8260,51],256],8533:[[49,8260,53],256],8534:[[50,8260,53],256],8535:[[51,8260,53],256],8536:[[52,8260,53],256],8537:[[49,8260,54],256],8538:[[53,8260,54],256],8539:[[49,8260,56],256],8540:[[51,8260,56],256],8541:[[53,8260,56],256],8542:[[55,8260,56],256],8543:[[49,8260],256],8544:[[73],256],8545:[[73,73],256],8546:[[73,73,73],256],8547:[[73,86],256],8548:[[86],256],8549:[[86,73],256],8550:[[86,73,73],256],8551:[[86,73,73,73],256],8552:[[73,88],256],8553:[[88],256],8554:[[88,73],256],8555:[[88,73,73],256],8556:[[76],256],8557:[[67],256],8558:[[68],256],8559:[[77],256],8560:[[105],256],8561:[[105,105],256],8562:[[105,105,105],256],8563:[[105,118],256],8564:[[118],256],8565:[[118,105],256],8566:[[118,105,105],256],8567:[[118,105,105,105],256],8568:[[105,120],256],8569:[[120],256],8570:[[120,105],256],8571:[[120,105,105],256],8572:[[108],256],8573:[[99],256],8574:[[100],256],8575:[[109],256],8585:[[48,8260,51],256],8592:[,,{824:8602}],8594:[,,{824:8603}],8596:[,,{824:8622}],8602:[[8592,824]],8603:[[8594,824]],8622:[[8596,824]],8653:[[8656,824]],8654:[[8660,824]],8655:[[8658,824]],8656:[,,{824:8653}],8658:[,,{824:8655}],8660:[,,{824:8654}]}, | ||
332 | 8704:{8707:[,,{824:8708}],8708:[[8707,824]],8712:[,,{824:8713}],8713:[[8712,824]],8715:[,,{824:8716}],8716:[[8715,824]],8739:[,,{824:8740}],8740:[[8739,824]],8741:[,,{824:8742}],8742:[[8741,824]],8748:[[8747,8747],256],8749:[[8747,8747,8747],256],8751:[[8750,8750],256],8752:[[8750,8750,8750],256],8764:[,,{824:8769}],8769:[[8764,824]],8771:[,,{824:8772}],8772:[[8771,824]],8773:[,,{824:8775}],8775:[[8773,824]],8776:[,,{824:8777}],8777:[[8776,824]],8781:[,,{824:8813}],8800:[[61,824]],8801:[,,{824:8802}],8802:[[8801,824]],8804:[,,{824:8816}],8805:[,,{824:8817}],8813:[[8781,824]],8814:[[60,824]],8815:[[62,824]],8816:[[8804,824]],8817:[[8805,824]],8818:[,,{824:8820}],8819:[,,{824:8821}],8820:[[8818,824]],8821:[[8819,824]],8822:[,,{824:8824}],8823:[,,{824:8825}],8824:[[8822,824]],8825:[[8823,824]],8826:[,,{824:8832}],8827:[,,{824:8833}],8828:[,,{824:8928}],8829:[,,{824:8929}],8832:[[8826,824]],8833:[[8827,824]],8834:[,,{824:8836}],8835:[,,{824:8837}],8836:[[8834,824]],8837:[[8835,824]],8838:[,,{824:8840}],8839:[,,{824:8841}],8840:[[8838,824]],8841:[[8839,824]],8849:[,,{824:8930}],8850:[,,{824:8931}],8866:[,,{824:8876}],8872:[,,{824:8877}],8873:[,,{824:8878}],8875:[,,{824:8879}],8876:[[8866,824]],8877:[[8872,824]],8878:[[8873,824]],8879:[[8875,824]],8882:[,,{824:8938}],8883:[,,{824:8939}],8884:[,,{824:8940}],8885:[,,{824:8941}],8928:[[8828,824]],8929:[[8829,824]],8930:[[8849,824]],8931:[[8850,824]],8938:[[8882,824]],8939:[[8883,824]],8940:[[8884,824]],8941:[[8885,824]]}, | ||
333 | 8960:{9001:[[12296]],9002:[[12297]]}, | ||
334 | 9216:{9312:[[49],256],9313:[[50],256],9314:[[51],256],9315:[[52],256],9316:[[53],256],9317:[[54],256],9318:[[55],256],9319:[[56],256],9320:[[57],256],9321:[[49,48],256],9322:[[49,49],256],9323:[[49,50],256],9324:[[49,51],256],9325:[[49,52],256],9326:[[49,53],256],9327:[[49,54],256],9328:[[49,55],256],9329:[[49,56],256],9330:[[49,57],256],9331:[[50,48],256],9332:[[40,49,41],256],9333:[[40,50,41],256],9334:[[40,51,41],256],9335:[[40,52,41],256],9336:[[40,53,41],256],9337:[[40,54,41],256],9338:[[40,55,41],256],9339:[[40,56,41],256],9340:[[40,57,41],256],9341:[[40,49,48,41],256],9342:[[40,49,49,41],256],9343:[[40,49,50,41],256],9344:[[40,49,51,41],256],9345:[[40,49,52,41],256],9346:[[40,49,53,41],256],9347:[[40,49,54,41],256],9348:[[40,49,55,41],256],9349:[[40,49,56,41],256],9350:[[40,49,57,41],256],9351:[[40,50,48,41],256],9352:[[49,46],256],9353:[[50,46],256],9354:[[51,46],256],9355:[[52,46],256],9356:[[53,46],256],9357:[[54,46],256],9358:[[55,46],256],9359:[[56,46],256],9360:[[57,46],256],9361:[[49,48,46],256],9362:[[49,49,46],256],9363:[[49,50,46],256],9364:[[49,51,46],256],9365:[[49,52,46],256],9366:[[49,53,46],256],9367:[[49,54,46],256],9368:[[49,55,46],256],9369:[[49,56,46],256],9370:[[49,57,46],256],9371:[[50,48,46],256],9372:[[40,97,41],256],9373:[[40,98,41],256],9374:[[40,99,41],256],9375:[[40,100,41],256],9376:[[40,101,41],256],9377:[[40,102,41],256],9378:[[40,103,41],256],9379:[[40,104,41],256],9380:[[40,105,41],256],9381:[[40,106,41],256],9382:[[40,107,41],256],9383:[[40,108,41],256],9384:[[40,109,41],256],9385:[[40,110,41],256],9386:[[40,111,41],256],9387:[[40,112,41],256],9388:[[40,113,41],256],9389:[[40,114,41],256],9390:[[40,115,41],256],9391:[[40,116,41],256],9392:[[40,117,41],256],9393:[[40,118,41],256],9394:[[40,119,41],256],9395:[[40,120,41],256],9396:[[40,121,41],256],9397:[[40,122,41],256],9398:[[65],256],9399:[[66],256],9400:[[67],256],9401:[[68],256],9402:[[69],256],9403:[[70],256],9404:[[71],256],9405:[[72],256],9406:[[73],256],9407:[[74],256],9408:[[75],256],9409:[[76],256],9410:[[77],256],9411:[[78],256],9412:[[79],256],9413:[[80],256],9414:[[81],256],9415:[[82],256],9416:[[83],256],9417:[[84],256],9418:[[85],256],9419:[[86],256],9420:[[87],256],9421:[[88],256],9422:[[89],256],9423:[[90],256],9424:[[97],256],9425:[[98],256],9426:[[99],256],9427:[[100],256],9428:[[101],256],9429:[[102],256],9430:[[103],256],9431:[[104],256],9432:[[105],256],9433:[[106],256],9434:[[107],256],9435:[[108],256],9436:[[109],256],9437:[[110],256],9438:[[111],256],9439:[[112],256],9440:[[113],256],9441:[[114],256],9442:[[115],256],9443:[[116],256],9444:[[117],256],9445:[[118],256],9446:[[119],256],9447:[[120],256],9448:[[121],256],9449:[[122],256],9450:[[48],256]}, | ||
335 | 10752:{10764:[[8747,8747,8747,8747],256],10868:[[58,58,61],256],10869:[[61,61],256],10870:[[61,61,61],256],10972:[[10973,824],512]}, | ||
336 | 11264:{11388:[[106],256],11389:[[86],256],11503:[,230],11504:[,230],11505:[,230]}, | ||
337 | 11520:{11631:[[11617],256],11647:[,9],11744:[,230],11745:[,230],11746:[,230],11747:[,230],11748:[,230],11749:[,230],11750:[,230],11751:[,230],11752:[,230],11753:[,230],11754:[,230],11755:[,230],11756:[,230],11757:[,230],11758:[,230],11759:[,230],11760:[,230],11761:[,230],11762:[,230],11763:[,230],11764:[,230],11765:[,230],11766:[,230],11767:[,230],11768:[,230],11769:[,230],11770:[,230],11771:[,230],11772:[,230],11773:[,230],11774:[,230],11775:[,230]}, | ||
338 | 11776:{11935:[[27597],256],12019:[[40863],256]}, | ||
339 | 12032:{12032:[[19968],256],12033:[[20008],256],12034:[[20022],256],12035:[[20031],256],12036:[[20057],256],12037:[[20101],256],12038:[[20108],256],12039:[[20128],256],12040:[[20154],256],12041:[[20799],256],12042:[[20837],256],12043:[[20843],256],12044:[[20866],256],12045:[[20886],256],12046:[[20907],256],12047:[[20960],256],12048:[[20981],256],12049:[[20992],256],12050:[[21147],256],12051:[[21241],256],12052:[[21269],256],12053:[[21274],256],12054:[[21304],256],12055:[[21313],256],12056:[[21340],256],12057:[[21353],256],12058:[[21378],256],12059:[[21430],256],12060:[[21448],256],12061:[[21475],256],12062:[[22231],256],12063:[[22303],256],12064:[[22763],256],12065:[[22786],256],12066:[[22794],256],12067:[[22805],256],12068:[[22823],256],12069:[[22899],256],12070:[[23376],256],12071:[[23424],256],12072:[[23544],256],12073:[[23567],256],12074:[[23586],256],12075:[[23608],256],12076:[[23662],256],12077:[[23665],256],12078:[[24027],256],12079:[[24037],256],12080:[[24049],256],12081:[[24062],256],12082:[[24178],256],12083:[[24186],256],12084:[[24191],256],12085:[[24308],256],12086:[[24318],256],12087:[[24331],256],12088:[[24339],256],12089:[[24400],256],12090:[[24417],256],12091:[[24435],256],12092:[[24515],256],12093:[[25096],256],12094:[[25142],256],12095:[[25163],256],12096:[[25903],256],12097:[[25908],256],12098:[[25991],256],12099:[[26007],256],12100:[[26020],256],12101:[[26041],256],12102:[[26080],256],12103:[[26085],256],12104:[[26352],256],12105:[[26376],256],12106:[[26408],256],12107:[[27424],256],12108:[[27490],256],12109:[[27513],256],12110:[[27571],256],12111:[[27595],256],12112:[[27604],256],12113:[[27611],256],12114:[[27663],256],12115:[[27668],256],12116:[[27700],256],12117:[[28779],256],12118:[[29226],256],12119:[[29238],256],12120:[[29243],256],12121:[[29247],256],12122:[[29255],256],12123:[[29273],256],12124:[[29275],256],12125:[[29356],256],12126:[[29572],256],12127:[[29577],256],12128:[[29916],256],12129:[[29926],256],12130:[[29976],256],12131:[[29983],256],12132:[[29992],256],12133:[[30000],256],12134:[[30091],256],12135:[[30098],256],12136:[[30326],256],12137:[[30333],256],12138:[[30382],256],12139:[[30399],256],12140:[[30446],256],12141:[[30683],256],12142:[[30690],256],12143:[[30707],256],12144:[[31034],256],12145:[[31160],256],12146:[[31166],256],12147:[[31348],256],12148:[[31435],256],12149:[[31481],256],12150:[[31859],256],12151:[[31992],256],12152:[[32566],256],12153:[[32593],256],12154:[[32650],256],12155:[[32701],256],12156:[[32769],256],12157:[[32780],256],12158:[[32786],256],12159:[[32819],256],12160:[[32895],256],12161:[[32905],256],12162:[[33251],256],12163:[[33258],256],12164:[[33267],256],12165:[[33276],256],12166:[[33292],256],12167:[[33307],256],12168:[[33311],256],12169:[[33390],256],12170:[[33394],256],12171:[[33400],256],12172:[[34381],256],12173:[[34411],256],12174:[[34880],256],12175:[[34892],256],12176:[[34915],256],12177:[[35198],256],12178:[[35211],256],12179:[[35282],256],12180:[[35328],256],12181:[[35895],256],12182:[[35910],256],12183:[[35925],256],12184:[[35960],256],12185:[[35997],256],12186:[[36196],256],12187:[[36208],256],12188:[[36275],256],12189:[[36523],256],12190:[[36554],256],12191:[[36763],256],12192:[[36784],256],12193:[[36789],256],12194:[[37009],256],12195:[[37193],256],12196:[[37318],256],12197:[[37324],256],12198:[[37329],256],12199:[[38263],256],12200:[[38272],256],12201:[[38428],256],12202:[[38582],256],12203:[[38585],256],12204:[[38632],256],12205:[[38737],256],12206:[[38750],256],12207:[[38754],256],12208:[[38761],256],12209:[[38859],256],12210:[[38893],256],12211:[[38899],256],12212:[[38913],256],12213:[[39080],256],12214:[[39131],256],12215:[[39135],256],12216:[[39318],256],12217:[[39321],256],12218:[[39340],256],12219:[[39592],256],12220:[[39640],256],12221:[[39647],256],12222:[[39717],256],12223:[[39727],256],12224:[[39730],256],12225:[[39740],256],12226:[[39770],256],12227:[[40165],256],12228:[[40565],256],12229:[[40575],256],12230:[[40613],256],12231:[[40635],256],12232:[[40643],256],12233:[[40653],256],12234:[[40657],256],12235:[[40697],256],12236:[[40701],256],12237:[[40718],256],12238:[[40723],256],12239:[[40736],256],12240:[[40763],256],12241:[[40778],256],12242:[[40786],256],12243:[[40845],256],12244:[[40860],256],12245:[[40864],256]}, | ||
340 | 12288:{12288:[[32],256],12330:[,218],12331:[,228],12332:[,232],12333:[,222],12334:[,224],12335:[,224],12342:[[12306],256],12344:[[21313],256],12345:[[21316],256],12346:[[21317],256],12358:[,,{12441:12436}],12363:[,,{12441:12364}],12364:[[12363,12441]],12365:[,,{12441:12366}],12366:[[12365,12441]],12367:[,,{12441:12368}],12368:[[12367,12441]],12369:[,,{12441:12370}],12370:[[12369,12441]],12371:[,,{12441:12372}],12372:[[12371,12441]],12373:[,,{12441:12374}],12374:[[12373,12441]],12375:[,,{12441:12376}],12376:[[12375,12441]],12377:[,,{12441:12378}],12378:[[12377,12441]],12379:[,,{12441:12380}],12380:[[12379,12441]],12381:[,,{12441:12382}],12382:[[12381,12441]],12383:[,,{12441:12384}],12384:[[12383,12441]],12385:[,,{12441:12386}],12386:[[12385,12441]],12388:[,,{12441:12389}],12389:[[12388,12441]],12390:[,,{12441:12391}],12391:[[12390,12441]],12392:[,,{12441:12393}],12393:[[12392,12441]],12399:[,,{12441:12400,12442:12401}],12400:[[12399,12441]],12401:[[12399,12442]],12402:[,,{12441:12403,12442:12404}],12403:[[12402,12441]],12404:[[12402,12442]],12405:[,,{12441:12406,12442:12407}],12406:[[12405,12441]],12407:[[12405,12442]],12408:[,,{12441:12409,12442:12410}],12409:[[12408,12441]],12410:[[12408,12442]],12411:[,,{12441:12412,12442:12413}],12412:[[12411,12441]],12413:[[12411,12442]],12436:[[12358,12441]],12441:[,8],12442:[,8],12443:[[32,12441],256],12444:[[32,12442],256],12445:[,,{12441:12446}],12446:[[12445,12441]],12447:[[12424,12426],256],12454:[,,{12441:12532}],12459:[,,{12441:12460}],12460:[[12459,12441]],12461:[,,{12441:12462}],12462:[[12461,12441]],12463:[,,{12441:12464}],12464:[[12463,12441]],12465:[,,{12441:12466}],12466:[[12465,12441]],12467:[,,{12441:12468}],12468:[[12467,12441]],12469:[,,{12441:12470}],12470:[[12469,12441]],12471:[,,{12441:12472}],12472:[[12471,12441]],12473:[,,{12441:12474}],12474:[[12473,12441]],12475:[,,{12441:12476}],12476:[[12475,12441]],12477:[,,{12441:12478}],12478:[[12477,12441]],12479:[,,{12441:12480}],12480:[[12479,12441]],12481:[,,{12441:12482}],12482:[[12481,12441]],12484:[,,{12441:12485}],12485:[[12484,12441]],12486:[,,{12441:12487}],12487:[[12486,12441]],12488:[,,{12441:12489}],12489:[[12488,12441]],12495:[,,{12441:12496,12442:12497}],12496:[[12495,12441]],12497:[[12495,12442]],12498:[,,{12441:12499,12442:12500}],12499:[[12498,12441]],12500:[[12498,12442]],12501:[,,{12441:12502,12442:12503}],12502:[[12501,12441]],12503:[[12501,12442]],12504:[,,{12441:12505,12442:12506}],12505:[[12504,12441]],12506:[[12504,12442]],12507:[,,{12441:12508,12442:12509}],12508:[[12507,12441]],12509:[[12507,12442]],12527:[,,{12441:12535}],12528:[,,{12441:12536}],12529:[,,{12441:12537}],12530:[,,{12441:12538}],12532:[[12454,12441]],12535:[[12527,12441]],12536:[[12528,12441]],12537:[[12529,12441]],12538:[[12530,12441]],12541:[,,{12441:12542}],12542:[[12541,12441]],12543:[[12467,12488],256]}, | ||
341 | 12544:{12593:[[4352],256],12594:[[4353],256],12595:[[4522],256],12596:[[4354],256],12597:[[4524],256],12598:[[4525],256],12599:[[4355],256],12600:[[4356],256],12601:[[4357],256],12602:[[4528],256],12603:[[4529],256],12604:[[4530],256],12605:[[4531],256],12606:[[4532],256],12607:[[4533],256],12608:[[4378],256],12609:[[4358],256],12610:[[4359],256],12611:[[4360],256],12612:[[4385],256],12613:[[4361],256],12614:[[4362],256],12615:[[4363],256],12616:[[4364],256],12617:[[4365],256],12618:[[4366],256],12619:[[4367],256],12620:[[4368],256],12621:[[4369],256],12622:[[4370],256],12623:[[4449],256],12624:[[4450],256],12625:[[4451],256],12626:[[4452],256],12627:[[4453],256],12628:[[4454],256],12629:[[4455],256],12630:[[4456],256],12631:[[4457],256],12632:[[4458],256],12633:[[4459],256],12634:[[4460],256],12635:[[4461],256],12636:[[4462],256],12637:[[4463],256],12638:[[4464],256],12639:[[4465],256],12640:[[4466],256],12641:[[4467],256],12642:[[4468],256],12643:[[4469],256],12644:[[4448],256],12645:[[4372],256],12646:[[4373],256],12647:[[4551],256],12648:[[4552],256],12649:[[4556],256],12650:[[4558],256],12651:[[4563],256],12652:[[4567],256],12653:[[4569],256],12654:[[4380],256],12655:[[4573],256],12656:[[4575],256],12657:[[4381],256],12658:[[4382],256],12659:[[4384],256],12660:[[4386],256],12661:[[4387],256],12662:[[4391],256],12663:[[4393],256],12664:[[4395],256],12665:[[4396],256],12666:[[4397],256],12667:[[4398],256],12668:[[4399],256],12669:[[4402],256],12670:[[4406],256],12671:[[4416],256],12672:[[4423],256],12673:[[4428],256],12674:[[4593],256],12675:[[4594],256],12676:[[4439],256],12677:[[4440],256],12678:[[4441],256],12679:[[4484],256],12680:[[4485],256],12681:[[4488],256],12682:[[4497],256],12683:[[4498],256],12684:[[4500],256],12685:[[4510],256],12686:[[4513],256],12690:[[19968],256],12691:[[20108],256],12692:[[19977],256],12693:[[22235],256],12694:[[19978],256],12695:[[20013],256],12696:[[19979],256],12697:[[30002],256],12698:[[20057],256],12699:[[19993],256],12700:[[19969],256],12701:[[22825],256],12702:[[22320],256],12703:[[20154],256]}, | ||
342 | 12800:{12800:[[40,4352,41],256],12801:[[40,4354,41],256],12802:[[40,4355,41],256],12803:[[40,4357,41],256],12804:[[40,4358,41],256],12805:[[40,4359,41],256],12806:[[40,4361,41],256],12807:[[40,4363,41],256],12808:[[40,4364,41],256],12809:[[40,4366,41],256],12810:[[40,4367,41],256],12811:[[40,4368,41],256],12812:[[40,4369,41],256],12813:[[40,4370,41],256],12814:[[40,4352,4449,41],256],12815:[[40,4354,4449,41],256],12816:[[40,4355,4449,41],256],12817:[[40,4357,4449,41],256],12818:[[40,4358,4449,41],256],12819:[[40,4359,4449,41],256],12820:[[40,4361,4449,41],256],12821:[[40,4363,4449,41],256],12822:[[40,4364,4449,41],256],12823:[[40,4366,4449,41],256],12824:[[40,4367,4449,41],256],12825:[[40,4368,4449,41],256],12826:[[40,4369,4449,41],256],12827:[[40,4370,4449,41],256],12828:[[40,4364,4462,41],256],12829:[[40,4363,4457,4364,4453,4523,41],256],12830:[[40,4363,4457,4370,4462,41],256],12832:[[40,19968,41],256],12833:[[40,20108,41],256],12834:[[40,19977,41],256],12835:[[40,22235,41],256],12836:[[40,20116,41],256],12837:[[40,20845,41],256],12838:[[40,19971,41],256],12839:[[40,20843,41],256],12840:[[40,20061,41],256],12841:[[40,21313,41],256],12842:[[40,26376,41],256],12843:[[40,28779,41],256],12844:[[40,27700,41],256],12845:[[40,26408,41],256],12846:[[40,37329,41],256],12847:[[40,22303,41],256],12848:[[40,26085,41],256],12849:[[40,26666,41],256],12850:[[40,26377,41],256],12851:[[40,31038,41],256],12852:[[40,21517,41],256],12853:[[40,29305,41],256],12854:[[40,36001,41],256],12855:[[40,31069,41],256],12856:[[40,21172,41],256],12857:[[40,20195,41],256],12858:[[40,21628,41],256],12859:[[40,23398,41],256],12860:[[40,30435,41],256],12861:[[40,20225,41],256],12862:[[40,36039,41],256],12863:[[40,21332,41],256],12864:[[40,31085,41],256],12865:[[40,20241,41],256],12866:[[40,33258,41],256],12867:[[40,33267,41],256],12868:[[21839],256],12869:[[24188],256],12870:[[25991],256],12871:[[31631],256],12880:[[80,84,69],256],12881:[[50,49],256],12882:[[50,50],256],12883:[[50,51],256],12884:[[50,52],256],12885:[[50,53],256],12886:[[50,54],256],12887:[[50,55],256],12888:[[50,56],256],12889:[[50,57],256],12890:[[51,48],256],12891:[[51,49],256],12892:[[51,50],256],12893:[[51,51],256],12894:[[51,52],256],12895:[[51,53],256],12896:[[4352],256],12897:[[4354],256],12898:[[4355],256],12899:[[4357],256],12900:[[4358],256],12901:[[4359],256],12902:[[4361],256],12903:[[4363],256],12904:[[4364],256],12905:[[4366],256],12906:[[4367],256],12907:[[4368],256],12908:[[4369],256],12909:[[4370],256],12910:[[4352,4449],256],12911:[[4354,4449],256],12912:[[4355,4449],256],12913:[[4357,4449],256],12914:[[4358,4449],256],12915:[[4359,4449],256],12916:[[4361,4449],256],12917:[[4363,4449],256],12918:[[4364,4449],256],12919:[[4366,4449],256],12920:[[4367,4449],256],12921:[[4368,4449],256],12922:[[4369,4449],256],12923:[[4370,4449],256],12924:[[4366,4449,4535,4352,4457],256],12925:[[4364,4462,4363,4468],256],12926:[[4363,4462],256],12928:[[19968],256],12929:[[20108],256],12930:[[19977],256],12931:[[22235],256],12932:[[20116],256],12933:[[20845],256],12934:[[19971],256],12935:[[20843],256],12936:[[20061],256],12937:[[21313],256],12938:[[26376],256],12939:[[28779],256],12940:[[27700],256],12941:[[26408],256],12942:[[37329],256],12943:[[22303],256],12944:[[26085],256],12945:[[26666],256],12946:[[26377],256],12947:[[31038],256],12948:[[21517],256],12949:[[29305],256],12950:[[36001],256],12951:[[31069],256],12952:[[21172],256],12953:[[31192],256],12954:[[30007],256],12955:[[22899],256],12956:[[36969],256],12957:[[20778],256],12958:[[21360],256],12959:[[27880],256],12960:[[38917],256],12961:[[20241],256],12962:[[20889],256],12963:[[27491],256],12964:[[19978],256],12965:[[20013],256],12966:[[19979],256],12967:[[24038],256],12968:[[21491],256],12969:[[21307],256],12970:[[23447],256],12971:[[23398],256],12972:[[30435],256],12973:[[20225],256],12974:[[36039],256],12975:[[21332],256],12976:[[22812],256],12977:[[51,54],256],12978:[[51,55],256],12979:[[51,56],256],12980:[[51,57],256],12981:[[52,48],256],12982:[[52,49],256],12983:[[52,50],256],12984:[[52,51],256],12985:[[52,52],256],12986:[[52,53],256],12987:[[52,54],256],12988:[[52,55],256],12989:[[52,56],256],12990:[[52,57],256],12991:[[53,48],256],12992:[[49,26376],256],12993:[[50,26376],256],12994:[[51,26376],256],12995:[[52,26376],256],12996:[[53,26376],256],12997:[[54,26376],256],12998:[[55,26376],256],12999:[[56,26376],256],13000:[[57,26376],256],13001:[[49,48,26376],256],13002:[[49,49,26376],256],13003:[[49,50,26376],256],13004:[[72,103],256],13005:[[101,114,103],256],13006:[[101,86],256],13007:[[76,84,68],256],13008:[[12450],256],13009:[[12452],256],13010:[[12454],256],13011:[[12456],256],13012:[[12458],256],13013:[[12459],256],13014:[[12461],256],13015:[[12463],256],13016:[[12465],256],13017:[[12467],256],13018:[[12469],256],13019:[[12471],256],13020:[[12473],256],13021:[[12475],256],13022:[[12477],256],13023:[[12479],256],13024:[[12481],256],13025:[[12484],256],13026:[[12486],256],13027:[[12488],256],13028:[[12490],256],13029:[[12491],256],13030:[[12492],256],13031:[[12493],256],13032:[[12494],256],13033:[[12495],256],13034:[[12498],256],13035:[[12501],256],13036:[[12504],256],13037:[[12507],256],13038:[[12510],256],13039:[[12511],256],13040:[[12512],256],13041:[[12513],256],13042:[[12514],256],13043:[[12516],256],13044:[[12518],256],13045:[[12520],256],13046:[[12521],256],13047:[[12522],256],13048:[[12523],256],13049:[[12524],256],13050:[[12525],256],13051:[[12527],256],13052:[[12528],256],13053:[[12529],256],13054:[[12530],256]}, | ||
343 | 13056:{13056:[[12450,12497,12540,12488],256],13057:[[12450,12523,12501,12449],256],13058:[[12450,12531,12506,12450],256],13059:[[12450,12540,12523],256],13060:[[12452,12491,12531,12464],256],13061:[[12452,12531,12481],256],13062:[[12454,12457,12531],256],13063:[[12456,12473,12463,12540,12489],256],13064:[[12456,12540,12459,12540],256],13065:[[12458,12531,12473],256],13066:[[12458,12540,12512],256],13067:[[12459,12452,12522],256],13068:[[12459,12521,12483,12488],256],13069:[[12459,12525,12522,12540],256],13070:[[12460,12525,12531],256],13071:[[12460,12531,12510],256],13072:[[12462,12460],256],13073:[[12462,12491,12540],256],13074:[[12461,12517,12522,12540],256],13075:[[12462,12523,12480,12540],256],13076:[[12461,12525],256],13077:[[12461,12525,12464,12521,12512],256],13078:[[12461,12525,12513,12540,12488,12523],256],13079:[[12461,12525,12527,12483,12488],256],13080:[[12464,12521,12512],256],13081:[[12464,12521,12512,12488,12531],256],13082:[[12463,12523,12476,12452,12525],256],13083:[[12463,12525,12540,12493],256],13084:[[12465,12540,12473],256],13085:[[12467,12523,12490],256],13086:[[12467,12540,12509],256],13087:[[12469,12452,12463,12523],256],13088:[[12469,12531,12481,12540,12512],256],13089:[[12471,12522,12531,12464],256],13090:[[12475,12531,12481],256],13091:[[12475,12531,12488],256],13092:[[12480,12540,12473],256],13093:[[12487,12471],256],13094:[[12489,12523],256],13095:[[12488,12531],256],13096:[[12490,12494],256],13097:[[12494,12483,12488],256],13098:[[12495,12452,12484],256],13099:[[12497,12540,12475,12531,12488],256],13100:[[12497,12540,12484],256],13101:[[12496,12540,12524,12523],256],13102:[[12500,12450,12473,12488,12523],256],13103:[[12500,12463,12523],256],13104:[[12500,12467],256],13105:[[12499,12523],256],13106:[[12501,12449,12521,12483,12489],256],13107:[[12501,12451,12540,12488],256],13108:[[12502,12483,12471,12455,12523],256],13109:[[12501,12521,12531],256],13110:[[12504,12463,12479,12540,12523],256],13111:[[12506,12477],256],13112:[[12506,12491,12498],256],13113:[[12504,12523,12484],256],13114:[[12506,12531,12473],256],13115:[[12506,12540,12472],256],13116:[[12505,12540,12479],256],13117:[[12509,12452,12531,12488],256],13118:[[12508,12523,12488],256],13119:[[12507,12531],256],13120:[[12509,12531,12489],256],13121:[[12507,12540,12523],256],13122:[[12507,12540,12531],256],13123:[[12510,12452,12463,12525],256],13124:[[12510,12452,12523],256],13125:[[12510,12483,12495],256],13126:[[12510,12523,12463],256],13127:[[12510,12531,12471,12519,12531],256],13128:[[12511,12463,12525,12531],256],13129:[[12511,12522],256],13130:[[12511,12522,12496,12540,12523],256],13131:[[12513,12460],256],13132:[[12513,12460,12488,12531],256],13133:[[12513,12540,12488,12523],256],13134:[[12516,12540,12489],256],13135:[[12516,12540,12523],256],13136:[[12518,12450,12531],256],13137:[[12522,12483,12488,12523],256],13138:[[12522,12521],256],13139:[[12523,12500,12540],256],13140:[[12523,12540,12502,12523],256],13141:[[12524,12512],256],13142:[[12524,12531,12488,12466,12531],256],13143:[[12527,12483,12488],256],13144:[[48,28857],256],13145:[[49,28857],256],13146:[[50,28857],256],13147:[[51,28857],256],13148:[[52,28857],256],13149:[[53,28857],256],13150:[[54,28857],256],13151:[[55,28857],256],13152:[[56,28857],256],13153:[[57,28857],256],13154:[[49,48,28857],256],13155:[[49,49,28857],256],13156:[[49,50,28857],256],13157:[[49,51,28857],256],13158:[[49,52,28857],256],13159:[[49,53,28857],256],13160:[[49,54,28857],256],13161:[[49,55,28857],256],13162:[[49,56,28857],256],13163:[[49,57,28857],256],13164:[[50,48,28857],256],13165:[[50,49,28857],256],13166:[[50,50,28857],256],13167:[[50,51,28857],256],13168:[[50,52,28857],256],13169:[[104,80,97],256],13170:[[100,97],256],13171:[[65,85],256],13172:[[98,97,114],256],13173:[[111,86],256],13174:[[112,99],256],13175:[[100,109],256],13176:[[100,109,178],256],13177:[[100,109,179],256],13178:[[73,85],256],13179:[[24179,25104],256],13180:[[26157,21644],256],13181:[[22823,27491],256],13182:[[26126,27835],256],13183:[[26666,24335,20250,31038],256],13184:[[112,65],256],13185:[[110,65],256],13186:[[956,65],256],13187:[[109,65],256],13188:[[107,65],256],13189:[[75,66],256],13190:[[77,66],256],13191:[[71,66],256],13192:[[99,97,108],256],13193:[[107,99,97,108],256],13194:[[112,70],256],13195:[[110,70],256],13196:[[956,70],256],13197:[[956,103],256],13198:[[109,103],256],13199:[[107,103],256],13200:[[72,122],256],13201:[[107,72,122],256],13202:[[77,72,122],256],13203:[[71,72,122],256],13204:[[84,72,122],256],13205:[[956,8467],256],13206:[[109,8467],256],13207:[[100,8467],256],13208:[[107,8467],256],13209:[[102,109],256],13210:[[110,109],256],13211:[[956,109],256],13212:[[109,109],256],13213:[[99,109],256],13214:[[107,109],256],13215:[[109,109,178],256],13216:[[99,109,178],256],13217:[[109,178],256],13218:[[107,109,178],256],13219:[[109,109,179],256],13220:[[99,109,179],256],13221:[[109,179],256],13222:[[107,109,179],256],13223:[[109,8725,115],256],13224:[[109,8725,115,178],256],13225:[[80,97],256],13226:[[107,80,97],256],13227:[[77,80,97],256],13228:[[71,80,97],256],13229:[[114,97,100],256],13230:[[114,97,100,8725,115],256],13231:[[114,97,100,8725,115,178],256],13232:[[112,115],256],13233:[[110,115],256],13234:[[956,115],256],13235:[[109,115],256],13236:[[112,86],256],13237:[[110,86],256],13238:[[956,86],256],13239:[[109,86],256],13240:[[107,86],256],13241:[[77,86],256],13242:[[112,87],256],13243:[[110,87],256],13244:[[956,87],256],13245:[[109,87],256],13246:[[107,87],256],13247:[[77,87],256],13248:[[107,937],256],13249:[[77,937],256],13250:[[97,46,109,46],256],13251:[[66,113],256],13252:[[99,99],256],13253:[[99,100],256],13254:[[67,8725,107,103],256],13255:[[67,111,46],256],13256:[[100,66],256],13257:[[71,121],256],13258:[[104,97],256],13259:[[72,80],256],13260:[[105,110],256],13261:[[75,75],256],13262:[[75,77],256],13263:[[107,116],256],13264:[[108,109],256],13265:[[108,110],256],13266:[[108,111,103],256],13267:[[108,120],256],13268:[[109,98],256],13269:[[109,105,108],256],13270:[[109,111,108],256],13271:[[80,72],256],13272:[[112,46,109,46],256],13273:[[80,80,77],256],13274:[[80,82],256],13275:[[115,114],256],13276:[[83,118],256],13277:[[87,98],256],13278:[[86,8725,109],256],13279:[[65,8725,109],256],13280:[[49,26085],256],13281:[[50,26085],256],13282:[[51,26085],256],13283:[[52,26085],256],13284:[[53,26085],256],13285:[[54,26085],256],13286:[[55,26085],256],13287:[[56,26085],256],13288:[[57,26085],256],13289:[[49,48,26085],256],13290:[[49,49,26085],256],13291:[[49,50,26085],256],13292:[[49,51,26085],256],13293:[[49,52,26085],256],13294:[[49,53,26085],256],13295:[[49,54,26085],256],13296:[[49,55,26085],256],13297:[[49,56,26085],256],13298:[[49,57,26085],256],13299:[[50,48,26085],256],13300:[[50,49,26085],256],13301:[[50,50,26085],256],13302:[[50,51,26085],256],13303:[[50,52,26085],256],13304:[[50,53,26085],256],13305:[[50,54,26085],256],13306:[[50,55,26085],256],13307:[[50,56,26085],256],13308:[[50,57,26085],256],13309:[[51,48,26085],256],13310:[[51,49,26085],256],13311:[[103,97,108],256]}, | ||
344 | 27136:{92912:[,1],92913:[,1],92914:[,1],92915:[,1],92916:[,1]}, | ||
345 | 27392:{92976:[,230],92977:[,230],92978:[,230],92979:[,230],92980:[,230],92981:[,230],92982:[,230]}, | ||
346 | 42496:{42607:[,230],42612:[,230],42613:[,230],42614:[,230],42615:[,230],42616:[,230],42617:[,230],42618:[,230],42619:[,230],42620:[,230],42621:[,230],42652:[[1098],256],42653:[[1100],256],42655:[,230],42736:[,230],42737:[,230]}, | ||
347 | 42752:{42864:[[42863],256],43000:[[294],256],43001:[[339],256]}, | ||
348 | 43008:{43014:[,9],43204:[,9],43232:[,230],43233:[,230],43234:[,230],43235:[,230],43236:[,230],43237:[,230],43238:[,230],43239:[,230],43240:[,230],43241:[,230],43242:[,230],43243:[,230],43244:[,230],43245:[,230],43246:[,230],43247:[,230],43248:[,230],43249:[,230]}, | ||
349 | 43264:{43307:[,220],43308:[,220],43309:[,220],43347:[,9],43443:[,7],43456:[,9]}, | ||
350 | 43520:{43696:[,230],43698:[,230],43699:[,230],43700:[,220],43703:[,230],43704:[,230],43710:[,230],43711:[,230],43713:[,230],43766:[,9]}, | ||
351 | 43776:{43868:[[42791],256],43869:[[43831],256],43870:[[619],256],43871:[[43858],256],44013:[,9]}, | ||
352 | 48128:{113822:[,1]}, | ||
353 | 53504:{119134:[[119127,119141],512],119135:[[119128,119141],512],119136:[[119135,119150],512],119137:[[119135,119151],512],119138:[[119135,119152],512],119139:[[119135,119153],512],119140:[[119135,119154],512],119141:[,216],119142:[,216],119143:[,1],119144:[,1],119145:[,1],119149:[,226],119150:[,216],119151:[,216],119152:[,216],119153:[,216],119154:[,216],119163:[,220],119164:[,220],119165:[,220],119166:[,220],119167:[,220],119168:[,220],119169:[,220],119170:[,220],119173:[,230],119174:[,230],119175:[,230],119176:[,230],119177:[,230],119178:[,220],119179:[,220],119210:[,230],119211:[,230],119212:[,230],119213:[,230],119227:[[119225,119141],512],119228:[[119226,119141],512],119229:[[119227,119150],512],119230:[[119228,119150],512],119231:[[119227,119151],512],119232:[[119228,119151],512]}, | ||
354 | 53760:{119362:[,230],119363:[,230],119364:[,230]}, | ||
355 | 54272:{119808:[[65],256],119809:[[66],256],119810:[[67],256],119811:[[68],256],119812:[[69],256],119813:[[70],256],119814:[[71],256],119815:[[72],256],119816:[[73],256],119817:[[74],256],119818:[[75],256],119819:[[76],256],119820:[[77],256],119821:[[78],256],119822:[[79],256],119823:[[80],256],119824:[[81],256],119825:[[82],256],119826:[[83],256],119827:[[84],256],119828:[[85],256],119829:[[86],256],119830:[[87],256],119831:[[88],256],119832:[[89],256],119833:[[90],256],119834:[[97],256],119835:[[98],256],119836:[[99],256],119837:[[100],256],119838:[[101],256],119839:[[102],256],119840:[[103],256],119841:[[104],256],119842:[[105],256],119843:[[106],256],119844:[[107],256],119845:[[108],256],119846:[[109],256],119847:[[110],256],119848:[[111],256],119849:[[112],256],119850:[[113],256],119851:[[114],256],119852:[[115],256],119853:[[116],256],119854:[[117],256],119855:[[118],256],119856:[[119],256],119857:[[120],256],119858:[[121],256],119859:[[122],256],119860:[[65],256],119861:[[66],256],119862:[[67],256],119863:[[68],256],119864:[[69],256],119865:[[70],256],119866:[[71],256],119867:[[72],256],119868:[[73],256],119869:[[74],256],119870:[[75],256],119871:[[76],256],119872:[[77],256],119873:[[78],256],119874:[[79],256],119875:[[80],256],119876:[[81],256],119877:[[82],256],119878:[[83],256],119879:[[84],256],119880:[[85],256],119881:[[86],256],119882:[[87],256],119883:[[88],256],119884:[[89],256],119885:[[90],256],119886:[[97],256],119887:[[98],256],119888:[[99],256],119889:[[100],256],119890:[[101],256],119891:[[102],256],119892:[[103],256],119894:[[105],256],119895:[[106],256],119896:[[107],256],119897:[[108],256],119898:[[109],256],119899:[[110],256],119900:[[111],256],119901:[[112],256],119902:[[113],256],119903:[[114],256],119904:[[115],256],119905:[[116],256],119906:[[117],256],119907:[[118],256],119908:[[119],256],119909:[[120],256],119910:[[121],256],119911:[[122],256],119912:[[65],256],119913:[[66],256],119914:[[67],256],119915:[[68],256],119916:[[69],256],119917:[[70],256],119918:[[71],256],119919:[[72],256],119920:[[73],256],119921:[[74],256],119922:[[75],256],119923:[[76],256],119924:[[77],256],119925:[[78],256],119926:[[79],256],119927:[[80],256],119928:[[81],256],119929:[[82],256],119930:[[83],256],119931:[[84],256],119932:[[85],256],119933:[[86],256],119934:[[87],256],119935:[[88],256],119936:[[89],256],119937:[[90],256],119938:[[97],256],119939:[[98],256],119940:[[99],256],119941:[[100],256],119942:[[101],256],119943:[[102],256],119944:[[103],256],119945:[[104],256],119946:[[105],256],119947:[[106],256],119948:[[107],256],119949:[[108],256],119950:[[109],256],119951:[[110],256],119952:[[111],256],119953:[[112],256],119954:[[113],256],119955:[[114],256],119956:[[115],256],119957:[[116],256],119958:[[117],256],119959:[[118],256],119960:[[119],256],119961:[[120],256],119962:[[121],256],119963:[[122],256],119964:[[65],256],119966:[[67],256],119967:[[68],256],119970:[[71],256],119973:[[74],256],119974:[[75],256],119977:[[78],256],119978:[[79],256],119979:[[80],256],119980:[[81],256],119982:[[83],256],119983:[[84],256],119984:[[85],256],119985:[[86],256],119986:[[87],256],119987:[[88],256],119988:[[89],256],119989:[[90],256],119990:[[97],256],119991:[[98],256],119992:[[99],256],119993:[[100],256],119995:[[102],256],119997:[[104],256],119998:[[105],256],119999:[[106],256],120000:[[107],256],120001:[[108],256],120002:[[109],256],120003:[[110],256],120005:[[112],256],120006:[[113],256],120007:[[114],256],120008:[[115],256],120009:[[116],256],120010:[[117],256],120011:[[118],256],120012:[[119],256],120013:[[120],256],120014:[[121],256],120015:[[122],256],120016:[[65],256],120017:[[66],256],120018:[[67],256],120019:[[68],256],120020:[[69],256],120021:[[70],256],120022:[[71],256],120023:[[72],256],120024:[[73],256],120025:[[74],256],120026:[[75],256],120027:[[76],256],120028:[[77],256],120029:[[78],256],120030:[[79],256],120031:[[80],256],120032:[[81],256],120033:[[82],256],120034:[[83],256],120035:[[84],256],120036:[[85],256],120037:[[86],256],120038:[[87],256],120039:[[88],256],120040:[[89],256],120041:[[90],256],120042:[[97],256],120043:[[98],256],120044:[[99],256],120045:[[100],256],120046:[[101],256],120047:[[102],256],120048:[[103],256],120049:[[104],256],120050:[[105],256],120051:[[106],256],120052:[[107],256],120053:[[108],256],120054:[[109],256],120055:[[110],256],120056:[[111],256],120057:[[112],256],120058:[[113],256],120059:[[114],256],120060:[[115],256],120061:[[116],256],120062:[[117],256],120063:[[118],256]}, | ||
356 | 54528:{120064:[[119],256],120065:[[120],256],120066:[[121],256],120067:[[122],256],120068:[[65],256],120069:[[66],256],120071:[[68],256],120072:[[69],256],120073:[[70],256],120074:[[71],256],120077:[[74],256],120078:[[75],256],120079:[[76],256],120080:[[77],256],120081:[[78],256],120082:[[79],256],120083:[[80],256],120084:[[81],256],120086:[[83],256],120087:[[84],256],120088:[[85],256],120089:[[86],256],120090:[[87],256],120091:[[88],256],120092:[[89],256],120094:[[97],256],120095:[[98],256],120096:[[99],256],120097:[[100],256],120098:[[101],256],120099:[[102],256],120100:[[103],256],120101:[[104],256],120102:[[105],256],120103:[[106],256],120104:[[107],256],120105:[[108],256],120106:[[109],256],120107:[[110],256],120108:[[111],256],120109:[[112],256],120110:[[113],256],120111:[[114],256],120112:[[115],256],120113:[[116],256],120114:[[117],256],120115:[[118],256],120116:[[119],256],120117:[[120],256],120118:[[121],256],120119:[[122],256],120120:[[65],256],120121:[[66],256],120123:[[68],256],120124:[[69],256],120125:[[70],256],120126:[[71],256],120128:[[73],256],120129:[[74],256],120130:[[75],256],120131:[[76],256],120132:[[77],256],120134:[[79],256],120138:[[83],256],120139:[[84],256],120140:[[85],256],120141:[[86],256],120142:[[87],256],120143:[[88],256],120144:[[89],256],120146:[[97],256],120147:[[98],256],120148:[[99],256],120149:[[100],256],120150:[[101],256],120151:[[102],256],120152:[[103],256],120153:[[104],256],120154:[[105],256],120155:[[106],256],120156:[[107],256],120157:[[108],256],120158:[[109],256],120159:[[110],256],120160:[[111],256],120161:[[112],256],120162:[[113],256],120163:[[114],256],120164:[[115],256],120165:[[116],256],120166:[[117],256],120167:[[118],256],120168:[[119],256],120169:[[120],256],120170:[[121],256],120171:[[122],256],120172:[[65],256],120173:[[66],256],120174:[[67],256],120175:[[68],256],120176:[[69],256],120177:[[70],256],120178:[[71],256],120179:[[72],256],120180:[[73],256],120181:[[74],256],120182:[[75],256],120183:[[76],256],120184:[[77],256],120185:[[78],256],120186:[[79],256],120187:[[80],256],120188:[[81],256],120189:[[82],256],120190:[[83],256],120191:[[84],256],120192:[[85],256],120193:[[86],256],120194:[[87],256],120195:[[88],256],120196:[[89],256],120197:[[90],256],120198:[[97],256],120199:[[98],256],120200:[[99],256],120201:[[100],256],120202:[[101],256],120203:[[102],256],120204:[[103],256],120205:[[104],256],120206:[[105],256],120207:[[106],256],120208:[[107],256],120209:[[108],256],120210:[[109],256],120211:[[110],256],120212:[[111],256],120213:[[112],256],120214:[[113],256],120215:[[114],256],120216:[[115],256],120217:[[116],256],120218:[[117],256],120219:[[118],256],120220:[[119],256],120221:[[120],256],120222:[[121],256],120223:[[122],256],120224:[[65],256],120225:[[66],256],120226:[[67],256],120227:[[68],256],120228:[[69],256],120229:[[70],256],120230:[[71],256],120231:[[72],256],120232:[[73],256],120233:[[74],256],120234:[[75],256],120235:[[76],256],120236:[[77],256],120237:[[78],256],120238:[[79],256],120239:[[80],256],120240:[[81],256],120241:[[82],256],120242:[[83],256],120243:[[84],256],120244:[[85],256],120245:[[86],256],120246:[[87],256],120247:[[88],256],120248:[[89],256],120249:[[90],256],120250:[[97],256],120251:[[98],256],120252:[[99],256],120253:[[100],256],120254:[[101],256],120255:[[102],256],120256:[[103],256],120257:[[104],256],120258:[[105],256],120259:[[106],256],120260:[[107],256],120261:[[108],256],120262:[[109],256],120263:[[110],256],120264:[[111],256],120265:[[112],256],120266:[[113],256],120267:[[114],256],120268:[[115],256],120269:[[116],256],120270:[[117],256],120271:[[118],256],120272:[[119],256],120273:[[120],256],120274:[[121],256],120275:[[122],256],120276:[[65],256],120277:[[66],256],120278:[[67],256],120279:[[68],256],120280:[[69],256],120281:[[70],256],120282:[[71],256],120283:[[72],256],120284:[[73],256],120285:[[74],256],120286:[[75],256],120287:[[76],256],120288:[[77],256],120289:[[78],256],120290:[[79],256],120291:[[80],256],120292:[[81],256],120293:[[82],256],120294:[[83],256],120295:[[84],256],120296:[[85],256],120297:[[86],256],120298:[[87],256],120299:[[88],256],120300:[[89],256],120301:[[90],256],120302:[[97],256],120303:[[98],256],120304:[[99],256],120305:[[100],256],120306:[[101],256],120307:[[102],256],120308:[[103],256],120309:[[104],256],120310:[[105],256],120311:[[106],256],120312:[[107],256],120313:[[108],256],120314:[[109],256],120315:[[110],256],120316:[[111],256],120317:[[112],256],120318:[[113],256],120319:[[114],256]}, | ||
357 | 54784:{120320:[[115],256],120321:[[116],256],120322:[[117],256],120323:[[118],256],120324:[[119],256],120325:[[120],256],120326:[[121],256],120327:[[122],256],120328:[[65],256],120329:[[66],256],120330:[[67],256],120331:[[68],256],120332:[[69],256],120333:[[70],256],120334:[[71],256],120335:[[72],256],120336:[[73],256],120337:[[74],256],120338:[[75],256],120339:[[76],256],120340:[[77],256],120341:[[78],256],120342:[[79],256],120343:[[80],256],120344:[[81],256],120345:[[82],256],120346:[[83],256],120347:[[84],256],120348:[[85],256],120349:[[86],256],120350:[[87],256],120351:[[88],256],120352:[[89],256],120353:[[90],256],120354:[[97],256],120355:[[98],256],120356:[[99],256],120357:[[100],256],120358:[[101],256],120359:[[102],256],120360:[[103],256],120361:[[104],256],120362:[[105],256],120363:[[106],256],120364:[[107],256],120365:[[108],256],120366:[[109],256],120367:[[110],256],120368:[[111],256],120369:[[112],256],120370:[[113],256],120371:[[114],256],120372:[[115],256],120373:[[116],256],120374:[[117],256],120375:[[118],256],120376:[[119],256],120377:[[120],256],120378:[[121],256],120379:[[122],256],120380:[[65],256],120381:[[66],256],120382:[[67],256],120383:[[68],256],120384:[[69],256],120385:[[70],256],120386:[[71],256],120387:[[72],256],120388:[[73],256],120389:[[74],256],120390:[[75],256],120391:[[76],256],120392:[[77],256],120393:[[78],256],120394:[[79],256],120395:[[80],256],120396:[[81],256],120397:[[82],256],120398:[[83],256],120399:[[84],256],120400:[[85],256],120401:[[86],256],120402:[[87],256],120403:[[88],256],120404:[[89],256],120405:[[90],256],120406:[[97],256],120407:[[98],256],120408:[[99],256],120409:[[100],256],120410:[[101],256],120411:[[102],256],120412:[[103],256],120413:[[104],256],120414:[[105],256],120415:[[106],256],120416:[[107],256],120417:[[108],256],120418:[[109],256],120419:[[110],256],120420:[[111],256],120421:[[112],256],120422:[[113],256],120423:[[114],256],120424:[[115],256],120425:[[116],256],120426:[[117],256],120427:[[118],256],120428:[[119],256],120429:[[120],256],120430:[[121],256],120431:[[122],256],120432:[[65],256],120433:[[66],256],120434:[[67],256],120435:[[68],256],120436:[[69],256],120437:[[70],256],120438:[[71],256],120439:[[72],256],120440:[[73],256],120441:[[74],256],120442:[[75],256],120443:[[76],256],120444:[[77],256],120445:[[78],256],120446:[[79],256],120447:[[80],256],120448:[[81],256],120449:[[82],256],120450:[[83],256],120451:[[84],256],120452:[[85],256],120453:[[86],256],120454:[[87],256],120455:[[88],256],120456:[[89],256],120457:[[90],256],120458:[[97],256],120459:[[98],256],120460:[[99],256],120461:[[100],256],120462:[[101],256],120463:[[102],256],120464:[[103],256],120465:[[104],256],120466:[[105],256],120467:[[106],256],120468:[[107],256],120469:[[108],256],120470:[[109],256],120471:[[110],256],120472:[[111],256],120473:[[112],256],120474:[[113],256],120475:[[114],256],120476:[[115],256],120477:[[116],256],120478:[[117],256],120479:[[118],256],120480:[[119],256],120481:[[120],256],120482:[[121],256],120483:[[122],256],120484:[[305],256],120485:[[567],256],120488:[[913],256],120489:[[914],256],120490:[[915],256],120491:[[916],256],120492:[[917],256],120493:[[918],256],120494:[[919],256],120495:[[920],256],120496:[[921],256],120497:[[922],256],120498:[[923],256],120499:[[924],256],120500:[[925],256],120501:[[926],256],120502:[[927],256],120503:[[928],256],120504:[[929],256],120505:[[1012],256],120506:[[931],256],120507:[[932],256],120508:[[933],256],120509:[[934],256],120510:[[935],256],120511:[[936],256],120512:[[937],256],120513:[[8711],256],120514:[[945],256],120515:[[946],256],120516:[[947],256],120517:[[948],256],120518:[[949],256],120519:[[950],256],120520:[[951],256],120521:[[952],256],120522:[[953],256],120523:[[954],256],120524:[[955],256],120525:[[956],256],120526:[[957],256],120527:[[958],256],120528:[[959],256],120529:[[960],256],120530:[[961],256],120531:[[962],256],120532:[[963],256],120533:[[964],256],120534:[[965],256],120535:[[966],256],120536:[[967],256],120537:[[968],256],120538:[[969],256],120539:[[8706],256],120540:[[1013],256],120541:[[977],256],120542:[[1008],256],120543:[[981],256],120544:[[1009],256],120545:[[982],256],120546:[[913],256],120547:[[914],256],120548:[[915],256],120549:[[916],256],120550:[[917],256],120551:[[918],256],120552:[[919],256],120553:[[920],256],120554:[[921],256],120555:[[922],256],120556:[[923],256],120557:[[924],256],120558:[[925],256],120559:[[926],256],120560:[[927],256],120561:[[928],256],120562:[[929],256],120563:[[1012],256],120564:[[931],256],120565:[[932],256],120566:[[933],256],120567:[[934],256],120568:[[935],256],120569:[[936],256],120570:[[937],256],120571:[[8711],256],120572:[[945],256],120573:[[946],256],120574:[[947],256],120575:[[948],256]}, | ||
358 | 55040:{120576:[[949],256],120577:[[950],256],120578:[[951],256],120579:[[952],256],120580:[[953],256],120581:[[954],256],120582:[[955],256],120583:[[956],256],120584:[[957],256],120585:[[958],256],120586:[[959],256],120587:[[960],256],120588:[[961],256],120589:[[962],256],120590:[[963],256],120591:[[964],256],120592:[[965],256],120593:[[966],256],120594:[[967],256],120595:[[968],256],120596:[[969],256],120597:[[8706],256],120598:[[1013],256],120599:[[977],256],120600:[[1008],256],120601:[[981],256],120602:[[1009],256],120603:[[982],256],120604:[[913],256],120605:[[914],256],120606:[[915],256],120607:[[916],256],120608:[[917],256],120609:[[918],256],120610:[[919],256],120611:[[920],256],120612:[[921],256],120613:[[922],256],120614:[[923],256],120615:[[924],256],120616:[[925],256],120617:[[926],256],120618:[[927],256],120619:[[928],256],120620:[[929],256],120621:[[1012],256],120622:[[931],256],120623:[[932],256],120624:[[933],256],120625:[[934],256],120626:[[935],256],120627:[[936],256],120628:[[937],256],120629:[[8711],256],120630:[[945],256],120631:[[946],256],120632:[[947],256],120633:[[948],256],120634:[[949],256],120635:[[950],256],120636:[[951],256],120637:[[952],256],120638:[[953],256],120639:[[954],256],120640:[[955],256],120641:[[956],256],120642:[[957],256],120643:[[958],256],120644:[[959],256],120645:[[960],256],120646:[[961],256],120647:[[962],256],120648:[[963],256],120649:[[964],256],120650:[[965],256],120651:[[966],256],120652:[[967],256],120653:[[968],256],120654:[[969],256],120655:[[8706],256],120656:[[1013],256],120657:[[977],256],120658:[[1008],256],120659:[[981],256],120660:[[1009],256],120661:[[982],256],120662:[[913],256],120663:[[914],256],120664:[[915],256],120665:[[916],256],120666:[[917],256],120667:[[918],256],120668:[[919],256],120669:[[920],256],120670:[[921],256],120671:[[922],256],120672:[[923],256],120673:[[924],256],120674:[[925],256],120675:[[926],256],120676:[[927],256],120677:[[928],256],120678:[[929],256],120679:[[1012],256],120680:[[931],256],120681:[[932],256],120682:[[933],256],120683:[[934],256],120684:[[935],256],120685:[[936],256],120686:[[937],256],120687:[[8711],256],120688:[[945],256],120689:[[946],256],120690:[[947],256],120691:[[948],256],120692:[[949],256],120693:[[950],256],120694:[[951],256],120695:[[952],256],120696:[[953],256],120697:[[954],256],120698:[[955],256],120699:[[956],256],120700:[[957],256],120701:[[958],256],120702:[[959],256],120703:[[960],256],120704:[[961],256],120705:[[962],256],120706:[[963],256],120707:[[964],256],120708:[[965],256],120709:[[966],256],120710:[[967],256],120711:[[968],256],120712:[[969],256],120713:[[8706],256],120714:[[1013],256],120715:[[977],256],120716:[[1008],256],120717:[[981],256],120718:[[1009],256],120719:[[982],256],120720:[[913],256],120721:[[914],256],120722:[[915],256],120723:[[916],256],120724:[[917],256],120725:[[918],256],120726:[[919],256],120727:[[920],256],120728:[[921],256],120729:[[922],256],120730:[[923],256],120731:[[924],256],120732:[[925],256],120733:[[926],256],120734:[[927],256],120735:[[928],256],120736:[[929],256],120737:[[1012],256],120738:[[931],256],120739:[[932],256],120740:[[933],256],120741:[[934],256],120742:[[935],256],120743:[[936],256],120744:[[937],256],120745:[[8711],256],120746:[[945],256],120747:[[946],256],120748:[[947],256],120749:[[948],256],120750:[[949],256],120751:[[950],256],120752:[[951],256],120753:[[952],256],120754:[[953],256],120755:[[954],256],120756:[[955],256],120757:[[956],256],120758:[[957],256],120759:[[958],256],120760:[[959],256],120761:[[960],256],120762:[[961],256],120763:[[962],256],120764:[[963],256],120765:[[964],256],120766:[[965],256],120767:[[966],256],120768:[[967],256],120769:[[968],256],120770:[[969],256],120771:[[8706],256],120772:[[1013],256],120773:[[977],256],120774:[[1008],256],120775:[[981],256],120776:[[1009],256],120777:[[982],256],120778:[[988],256],120779:[[989],256],120782:[[48],256],120783:[[49],256],120784:[[50],256],120785:[[51],256],120786:[[52],256],120787:[[53],256],120788:[[54],256],120789:[[55],256],120790:[[56],256],120791:[[57],256],120792:[[48],256],120793:[[49],256],120794:[[50],256],120795:[[51],256],120796:[[52],256],120797:[[53],256],120798:[[54],256],120799:[[55],256],120800:[[56],256],120801:[[57],256],120802:[[48],256],120803:[[49],256],120804:[[50],256],120805:[[51],256],120806:[[52],256],120807:[[53],256],120808:[[54],256],120809:[[55],256],120810:[[56],256],120811:[[57],256],120812:[[48],256],120813:[[49],256],120814:[[50],256],120815:[[51],256],120816:[[52],256],120817:[[53],256],120818:[[54],256],120819:[[55],256],120820:[[56],256],120821:[[57],256],120822:[[48],256],120823:[[49],256],120824:[[50],256],120825:[[51],256],120826:[[52],256],120827:[[53],256],120828:[[54],256],120829:[[55],256],120830:[[56],256],120831:[[57],256]}, | ||
359 | 59392:{125136:[,220],125137:[,220],125138:[,220],125139:[,220],125140:[,220],125141:[,220],125142:[,220]}, | ||
360 | 60928:{126464:[[1575],256],126465:[[1576],256],126466:[[1580],256],126467:[[1583],256],126469:[[1608],256],126470:[[1586],256],126471:[[1581],256],126472:[[1591],256],126473:[[1610],256],126474:[[1603],256],126475:[[1604],256],126476:[[1605],256],126477:[[1606],256],126478:[[1587],256],126479:[[1593],256],126480:[[1601],256],126481:[[1589],256],126482:[[1602],256],126483:[[1585],256],126484:[[1588],256],126485:[[1578],256],126486:[[1579],256],126487:[[1582],256],126488:[[1584],256],126489:[[1590],256],126490:[[1592],256],126491:[[1594],256],126492:[[1646],256],126493:[[1722],256],126494:[[1697],256],126495:[[1647],256],126497:[[1576],256],126498:[[1580],256],126500:[[1607],256],126503:[[1581],256],126505:[[1610],256],126506:[[1603],256],126507:[[1604],256],126508:[[1605],256],126509:[[1606],256],126510:[[1587],256],126511:[[1593],256],126512:[[1601],256],126513:[[1589],256],126514:[[1602],256],126516:[[1588],256],126517:[[1578],256],126518:[[1579],256],126519:[[1582],256],126521:[[1590],256],126523:[[1594],256],126530:[[1580],256],126535:[[1581],256],126537:[[1610],256],126539:[[1604],256],126541:[[1606],256],126542:[[1587],256],126543:[[1593],256],126545:[[1589],256],126546:[[1602],256],126548:[[1588],256],126551:[[1582],256],126553:[[1590],256],126555:[[1594],256],126557:[[1722],256],126559:[[1647],256],126561:[[1576],256],126562:[[1580],256],126564:[[1607],256],126567:[[1581],256],126568:[[1591],256],126569:[[1610],256],126570:[[1603],256],126572:[[1605],256],126573:[[1606],256],126574:[[1587],256],126575:[[1593],256],126576:[[1601],256],126577:[[1589],256],126578:[[1602],256],126580:[[1588],256],126581:[[1578],256],126582:[[1579],256],126583:[[1582],256],126585:[[1590],256],126586:[[1592],256],126587:[[1594],256],126588:[[1646],256],126590:[[1697],256],126592:[[1575],256],126593:[[1576],256],126594:[[1580],256],126595:[[1583],256],126596:[[1607],256],126597:[[1608],256],126598:[[1586],256],126599:[[1581],256],126600:[[1591],256],126601:[[1610],256],126603:[[1604],256],126604:[[1605],256],126605:[[1606],256],126606:[[1587],256],126607:[[1593],256],126608:[[1601],256],126609:[[1589],256],126610:[[1602],256],126611:[[1585],256],126612:[[1588],256],126613:[[1578],256],126614:[[1579],256],126615:[[1582],256],126616:[[1584],256],126617:[[1590],256],126618:[[1592],256],126619:[[1594],256],126625:[[1576],256],126626:[[1580],256],126627:[[1583],256],126629:[[1608],256],126630:[[1586],256],126631:[[1581],256],126632:[[1591],256],126633:[[1610],256],126635:[[1604],256],126636:[[1605],256],126637:[[1606],256],126638:[[1587],256],126639:[[1593],256],126640:[[1601],256],126641:[[1589],256],126642:[[1602],256],126643:[[1585],256],126644:[[1588],256],126645:[[1578],256],126646:[[1579],256],126647:[[1582],256],126648:[[1584],256],126649:[[1590],256],126650:[[1592],256],126651:[[1594],256]}, | ||
361 | 61696:{127232:[[48,46],256],127233:[[48,44],256],127234:[[49,44],256],127235:[[50,44],256],127236:[[51,44],256],127237:[[52,44],256],127238:[[53,44],256],127239:[[54,44],256],127240:[[55,44],256],127241:[[56,44],256],127242:[[57,44],256],127248:[[40,65,41],256],127249:[[40,66,41],256],127250:[[40,67,41],256],127251:[[40,68,41],256],127252:[[40,69,41],256],127253:[[40,70,41],256],127254:[[40,71,41],256],127255:[[40,72,41],256],127256:[[40,73,41],256],127257:[[40,74,41],256],127258:[[40,75,41],256],127259:[[40,76,41],256],127260:[[40,77,41],256],127261:[[40,78,41],256],127262:[[40,79,41],256],127263:[[40,80,41],256],127264:[[40,81,41],256],127265:[[40,82,41],256],127266:[[40,83,41],256],127267:[[40,84,41],256],127268:[[40,85,41],256],127269:[[40,86,41],256],127270:[[40,87,41],256],127271:[[40,88,41],256],127272:[[40,89,41],256],127273:[[40,90,41],256],127274:[[12308,83,12309],256],127275:[[67],256],127276:[[82],256],127277:[[67,68],256],127278:[[87,90],256],127280:[[65],256],127281:[[66],256],127282:[[67],256],127283:[[68],256],127284:[[69],256],127285:[[70],256],127286:[[71],256],127287:[[72],256],127288:[[73],256],127289:[[74],256],127290:[[75],256],127291:[[76],256],127292:[[77],256],127293:[[78],256],127294:[[79],256],127295:[[80],256],127296:[[81],256],127297:[[82],256],127298:[[83],256],127299:[[84],256],127300:[[85],256],127301:[[86],256],127302:[[87],256],127303:[[88],256],127304:[[89],256],127305:[[90],256],127306:[[72,86],256],127307:[[77,86],256],127308:[[83,68],256],127309:[[83,83],256],127310:[[80,80,86],256],127311:[[87,67],256],127338:[[77,67],256],127339:[[77,68],256],127376:[[68,74],256]}, | ||
362 | 61952:{127488:[[12411,12363],256],127489:[[12467,12467],256],127490:[[12469],256],127504:[[25163],256],127505:[[23383],256],127506:[[21452],256],127507:[[12487],256],127508:[[20108],256],127509:[[22810],256],127510:[[35299],256],127511:[[22825],256],127512:[[20132],256],127513:[[26144],256],127514:[[28961],256],127515:[[26009],256],127516:[[21069],256],127517:[[24460],256],127518:[[20877],256],127519:[[26032],256],127520:[[21021],256],127521:[[32066],256],127522:[[29983],256],127523:[[36009],256],127524:[[22768],256],127525:[[21561],256],127526:[[28436],256],127527:[[25237],256],127528:[[25429],256],127529:[[19968],256],127530:[[19977],256],127531:[[36938],256],127532:[[24038],256],127533:[[20013],256],127534:[[21491],256],127535:[[25351],256],127536:[[36208],256],127537:[[25171],256],127538:[[31105],256],127539:[[31354],256],127540:[[21512],256],127541:[[28288],256],127542:[[26377],256],127543:[[26376],256],127544:[[30003],256],127545:[[21106],256],127546:[[21942],256],127552:[[12308,26412,12309],256],127553:[[12308,19977,12309],256],127554:[[12308,20108,12309],256],127555:[[12308,23433,12309],256],127556:[[12308,28857,12309],256],127557:[[12308,25171,12309],256],127558:[[12308,30423,12309],256],127559:[[12308,21213,12309],256],127560:[[12308,25943,12309],256],127568:[[24471],256],127569:[[21487],256]}, | ||
363 | 63488:{194560:[[20029]],194561:[[20024]],194562:[[20033]],194563:[[131362]],194564:[[20320]],194565:[[20398]],194566:[[20411]],194567:[[20482]],194568:[[20602]],194569:[[20633]],194570:[[20711]],194571:[[20687]],194572:[[13470]],194573:[[132666]],194574:[[20813]],194575:[[20820]],194576:[[20836]],194577:[[20855]],194578:[[132380]],194579:[[13497]],194580:[[20839]],194581:[[20877]],194582:[[132427]],194583:[[20887]],194584:[[20900]],194585:[[20172]],194586:[[20908]],194587:[[20917]],194588:[[168415]],194589:[[20981]],194590:[[20995]],194591:[[13535]],194592:[[21051]],194593:[[21062]],194594:[[21106]],194595:[[21111]],194596:[[13589]],194597:[[21191]],194598:[[21193]],194599:[[21220]],194600:[[21242]],194601:[[21253]],194602:[[21254]],194603:[[21271]],194604:[[21321]],194605:[[21329]],194606:[[21338]],194607:[[21363]],194608:[[21373]],194609:[[21375]],194610:[[21375]],194611:[[21375]],194612:[[133676]],194613:[[28784]],194614:[[21450]],194615:[[21471]],194616:[[133987]],194617:[[21483]],194618:[[21489]],194619:[[21510]],194620:[[21662]],194621:[[21560]],194622:[[21576]],194623:[[21608]],194624:[[21666]],194625:[[21750]],194626:[[21776]],194627:[[21843]],194628:[[21859]],194629:[[21892]],194630:[[21892]],194631:[[21913]],194632:[[21931]],194633:[[21939]],194634:[[21954]],194635:[[22294]],194636:[[22022]],194637:[[22295]],194638:[[22097]],194639:[[22132]],194640:[[20999]],194641:[[22766]],194642:[[22478]],194643:[[22516]],194644:[[22541]],194645:[[22411]],194646:[[22578]],194647:[[22577]],194648:[[22700]],194649:[[136420]],194650:[[22770]],194651:[[22775]],194652:[[22790]],194653:[[22810]],194654:[[22818]],194655:[[22882]],194656:[[136872]],194657:[[136938]],194658:[[23020]],194659:[[23067]],194660:[[23079]],194661:[[23000]],194662:[[23142]],194663:[[14062]],194664:[[14076]],194665:[[23304]],194666:[[23358]],194667:[[23358]],194668:[[137672]],194669:[[23491]],194670:[[23512]],194671:[[23527]],194672:[[23539]],194673:[[138008]],194674:[[23551]],194675:[[23558]],194676:[[24403]],194677:[[23586]],194678:[[14209]],194679:[[23648]],194680:[[23662]],194681:[[23744]],194682:[[23693]],194683:[[138724]],194684:[[23875]],194685:[[138726]],194686:[[23918]],194687:[[23915]],194688:[[23932]],194689:[[24033]],194690:[[24034]],194691:[[14383]],194692:[[24061]],194693:[[24104]],194694:[[24125]],194695:[[24169]],194696:[[14434]],194697:[[139651]],194698:[[14460]],194699:[[24240]],194700:[[24243]],194701:[[24246]],194702:[[24266]],194703:[[172946]],194704:[[24318]],194705:[[140081]],194706:[[140081]],194707:[[33281]],194708:[[24354]],194709:[[24354]],194710:[[14535]],194711:[[144056]],194712:[[156122]],194713:[[24418]],194714:[[24427]],194715:[[14563]],194716:[[24474]],194717:[[24525]],194718:[[24535]],194719:[[24569]],194720:[[24705]],194721:[[14650]],194722:[[14620]],194723:[[24724]],194724:[[141012]],194725:[[24775]],194726:[[24904]],194727:[[24908]],194728:[[24910]],194729:[[24908]],194730:[[24954]],194731:[[24974]],194732:[[25010]],194733:[[24996]],194734:[[25007]],194735:[[25054]],194736:[[25074]],194737:[[25078]],194738:[[25104]],194739:[[25115]],194740:[[25181]],194741:[[25265]],194742:[[25300]],194743:[[25424]],194744:[[142092]],194745:[[25405]],194746:[[25340]],194747:[[25448]],194748:[[25475]],194749:[[25572]],194750:[[142321]],194751:[[25634]],194752:[[25541]],194753:[[25513]],194754:[[14894]],194755:[[25705]],194756:[[25726]],194757:[[25757]],194758:[[25719]],194759:[[14956]],194760:[[25935]],194761:[[25964]],194762:[[143370]],194763:[[26083]],194764:[[26360]],194765:[[26185]],194766:[[15129]],194767:[[26257]],194768:[[15112]],194769:[[15076]],194770:[[20882]],194771:[[20885]],194772:[[26368]],194773:[[26268]],194774:[[32941]],194775:[[17369]],194776:[[26391]],194777:[[26395]],194778:[[26401]],194779:[[26462]],194780:[[26451]],194781:[[144323]],194782:[[15177]],194783:[[26618]],194784:[[26501]],194785:[[26706]],194786:[[26757]],194787:[[144493]],194788:[[26766]],194789:[[26655]],194790:[[26900]],194791:[[15261]],194792:[[26946]],194793:[[27043]],194794:[[27114]],194795:[[27304]],194796:[[145059]],194797:[[27355]],194798:[[15384]],194799:[[27425]],194800:[[145575]],194801:[[27476]],194802:[[15438]],194803:[[27506]],194804:[[27551]],194805:[[27578]],194806:[[27579]],194807:[[146061]],194808:[[138507]],194809:[[146170]],194810:[[27726]],194811:[[146620]],194812:[[27839]],194813:[[27853]],194814:[[27751]],194815:[[27926]]}, | ||
364 | 63744:{63744:[[35912]],63745:[[26356]],63746:[[36554]],63747:[[36040]],63748:[[28369]],63749:[[20018]],63750:[[21477]],63751:[[40860]],63752:[[40860]],63753:[[22865]],63754:[[37329]],63755:[[21895]],63756:[[22856]],63757:[[25078]],63758:[[30313]],63759:[[32645]],63760:[[34367]],63761:[[34746]],63762:[[35064]],63763:[[37007]],63764:[[27138]],63765:[[27931]],63766:[[28889]],63767:[[29662]],63768:[[33853]],63769:[[37226]],63770:[[39409]],63771:[[20098]],63772:[[21365]],63773:[[27396]],63774:[[29211]],63775:[[34349]],63776:[[40478]],63777:[[23888]],63778:[[28651]],63779:[[34253]],63780:[[35172]],63781:[[25289]],63782:[[33240]],63783:[[34847]],63784:[[24266]],63785:[[26391]],63786:[[28010]],63787:[[29436]],63788:[[37070]],63789:[[20358]],63790:[[20919]],63791:[[21214]],63792:[[25796]],63793:[[27347]],63794:[[29200]],63795:[[30439]],63796:[[32769]],63797:[[34310]],63798:[[34396]],63799:[[36335]],63800:[[38706]],63801:[[39791]],63802:[[40442]],63803:[[30860]],63804:[[31103]],63805:[[32160]],63806:[[33737]],63807:[[37636]],63808:[[40575]],63809:[[35542]],63810:[[22751]],63811:[[24324]],63812:[[31840]],63813:[[32894]],63814:[[29282]],63815:[[30922]],63816:[[36034]],63817:[[38647]],63818:[[22744]],63819:[[23650]],63820:[[27155]],63821:[[28122]],63822:[[28431]],63823:[[32047]],63824:[[32311]],63825:[[38475]],63826:[[21202]],63827:[[32907]],63828:[[20956]],63829:[[20940]],63830:[[31260]],63831:[[32190]],63832:[[33777]],63833:[[38517]],63834:[[35712]],63835:[[25295]],63836:[[27138]],63837:[[35582]],63838:[[20025]],63839:[[23527]],63840:[[24594]],63841:[[29575]],63842:[[30064]],63843:[[21271]],63844:[[30971]],63845:[[20415]],63846:[[24489]],63847:[[19981]],63848:[[27852]],63849:[[25976]],63850:[[32034]],63851:[[21443]],63852:[[22622]],63853:[[30465]],63854:[[33865]],63855:[[35498]],63856:[[27578]],63857:[[36784]],63858:[[27784]],63859:[[25342]],63860:[[33509]],63861:[[25504]],63862:[[30053]],63863:[[20142]],63864:[[20841]],63865:[[20937]],63866:[[26753]],63867:[[31975]],63868:[[33391]],63869:[[35538]],63870:[[37327]],63871:[[21237]],63872:[[21570]],63873:[[22899]],63874:[[24300]],63875:[[26053]],63876:[[28670]],63877:[[31018]],63878:[[38317]],63879:[[39530]],63880:[[40599]],63881:[[40654]],63882:[[21147]],63883:[[26310]],63884:[[27511]],63885:[[36706]],63886:[[24180]],63887:[[24976]],63888:[[25088]],63889:[[25754]],63890:[[28451]],63891:[[29001]],63892:[[29833]],63893:[[31178]],63894:[[32244]],63895:[[32879]],63896:[[36646]],63897:[[34030]],63898:[[36899]],63899:[[37706]],63900:[[21015]],63901:[[21155]],63902:[[21693]],63903:[[28872]],63904:[[35010]],63905:[[35498]],63906:[[24265]],63907:[[24565]],63908:[[25467]],63909:[[27566]],63910:[[31806]],63911:[[29557]],63912:[[20196]],63913:[[22265]],63914:[[23527]],63915:[[23994]],63916:[[24604]],63917:[[29618]],63918:[[29801]],63919:[[32666]],63920:[[32838]],63921:[[37428]],63922:[[38646]],63923:[[38728]],63924:[[38936]],63925:[[20363]],63926:[[31150]],63927:[[37300]],63928:[[38584]],63929:[[24801]],63930:[[20102]],63931:[[20698]],63932:[[23534]],63933:[[23615]],63934:[[26009]],63935:[[27138]],63936:[[29134]],63937:[[30274]],63938:[[34044]],63939:[[36988]],63940:[[40845]],63941:[[26248]],63942:[[38446]],63943:[[21129]],63944:[[26491]],63945:[[26611]],63946:[[27969]],63947:[[28316]],63948:[[29705]],63949:[[30041]],63950:[[30827]],63951:[[32016]],63952:[[39006]],63953:[[20845]],63954:[[25134]],63955:[[38520]],63956:[[20523]],63957:[[23833]],63958:[[28138]],63959:[[36650]],63960:[[24459]],63961:[[24900]],63962:[[26647]],63963:[[29575]],63964:[[38534]],63965:[[21033]],63966:[[21519]],63967:[[23653]],63968:[[26131]],63969:[[26446]],63970:[[26792]],63971:[[27877]],63972:[[29702]],63973:[[30178]],63974:[[32633]],63975:[[35023]],63976:[[35041]],63977:[[37324]],63978:[[38626]],63979:[[21311]],63980:[[28346]],63981:[[21533]],63982:[[29136]],63983:[[29848]],63984:[[34298]],63985:[[38563]],63986:[[40023]],63987:[[40607]],63988:[[26519]],63989:[[28107]],63990:[[33256]],63991:[[31435]],63992:[[31520]],63993:[[31890]],63994:[[29376]],63995:[[28825]],63996:[[35672]],63997:[[20160]],63998:[[33590]],63999:[[21050]],194816:[[27966]],194817:[[28023]],194818:[[27969]],194819:[[28009]],194820:[[28024]],194821:[[28037]],194822:[[146718]],194823:[[27956]],194824:[[28207]],194825:[[28270]],194826:[[15667]],194827:[[28363]],194828:[[28359]],194829:[[147153]],194830:[[28153]],194831:[[28526]],194832:[[147294]],194833:[[147342]],194834:[[28614]],194835:[[28729]],194836:[[28702]],194837:[[28699]],194838:[[15766]],194839:[[28746]],194840:[[28797]],194841:[[28791]],194842:[[28845]],194843:[[132389]],194844:[[28997]],194845:[[148067]],194846:[[29084]],194847:[[148395]],194848:[[29224]],194849:[[29237]],194850:[[29264]],194851:[[149000]],194852:[[29312]],194853:[[29333]],194854:[[149301]],194855:[[149524]],194856:[[29562]],194857:[[29579]],194858:[[16044]],194859:[[29605]],194860:[[16056]],194861:[[16056]],194862:[[29767]],194863:[[29788]],194864:[[29809]],194865:[[29829]],194866:[[29898]],194867:[[16155]],194868:[[29988]],194869:[[150582]],194870:[[30014]],194871:[[150674]],194872:[[30064]],194873:[[139679]],194874:[[30224]],194875:[[151457]],194876:[[151480]],194877:[[151620]],194878:[[16380]],194879:[[16392]],194880:[[30452]],194881:[[151795]],194882:[[151794]],194883:[[151833]],194884:[[151859]],194885:[[30494]],194886:[[30495]],194887:[[30495]],194888:[[30538]],194889:[[16441]],194890:[[30603]],194891:[[16454]],194892:[[16534]],194893:[[152605]],194894:[[30798]],194895:[[30860]],194896:[[30924]],194897:[[16611]],194898:[[153126]],194899:[[31062]],194900:[[153242]],194901:[[153285]],194902:[[31119]],194903:[[31211]],194904:[[16687]],194905:[[31296]],194906:[[31306]],194907:[[31311]],194908:[[153980]],194909:[[154279]],194910:[[154279]],194911:[[31470]],194912:[[16898]],194913:[[154539]],194914:[[31686]],194915:[[31689]],194916:[[16935]],194917:[[154752]],194918:[[31954]],194919:[[17056]],194920:[[31976]],194921:[[31971]],194922:[[32000]],194923:[[155526]],194924:[[32099]],194925:[[17153]],194926:[[32199]],194927:[[32258]],194928:[[32325]],194929:[[17204]],194930:[[156200]],194931:[[156231]],194932:[[17241]],194933:[[156377]],194934:[[32634]],194935:[[156478]],194936:[[32661]],194937:[[32762]],194938:[[32773]],194939:[[156890]],194940:[[156963]],194941:[[32864]],194942:[[157096]],194943:[[32880]],194944:[[144223]],194945:[[17365]],194946:[[32946]],194947:[[33027]],194948:[[17419]],194949:[[33086]],194950:[[23221]],194951:[[157607]],194952:[[157621]],194953:[[144275]],194954:[[144284]],194955:[[33281]],194956:[[33284]],194957:[[36766]],194958:[[17515]],194959:[[33425]],194960:[[33419]],194961:[[33437]],194962:[[21171]],194963:[[33457]],194964:[[33459]],194965:[[33469]],194966:[[33510]],194967:[[158524]],194968:[[33509]],194969:[[33565]],194970:[[33635]],194971:[[33709]],194972:[[33571]],194973:[[33725]],194974:[[33767]],194975:[[33879]],194976:[[33619]],194977:[[33738]],194978:[[33740]],194979:[[33756]],194980:[[158774]],194981:[[159083]],194982:[[158933]],194983:[[17707]],194984:[[34033]],194985:[[34035]],194986:[[34070]],194987:[[160714]],194988:[[34148]],194989:[[159532]],194990:[[17757]],194991:[[17761]],194992:[[159665]],194993:[[159954]],194994:[[17771]],194995:[[34384]],194996:[[34396]],194997:[[34407]],194998:[[34409]],194999:[[34473]],195000:[[34440]],195001:[[34574]],195002:[[34530]],195003:[[34681]],195004:[[34600]],195005:[[34667]],195006:[[34694]],195007:[[17879]],195008:[[34785]],195009:[[34817]],195010:[[17913]],195011:[[34912]],195012:[[34915]],195013:[[161383]],195014:[[35031]],195015:[[35038]],195016:[[17973]],195017:[[35066]],195018:[[13499]],195019:[[161966]],195020:[[162150]],195021:[[18110]],195022:[[18119]],195023:[[35488]],195024:[[35565]],195025:[[35722]],195026:[[35925]],195027:[[162984]],195028:[[36011]],195029:[[36033]],195030:[[36123]],195031:[[36215]],195032:[[163631]],195033:[[133124]],195034:[[36299]],195035:[[36284]],195036:[[36336]],195037:[[133342]],195038:[[36564]],195039:[[36664]],195040:[[165330]],195041:[[165357]],195042:[[37012]],195043:[[37105]],195044:[[37137]],195045:[[165678]],195046:[[37147]],195047:[[37432]],195048:[[37591]],195049:[[37592]],195050:[[37500]],195051:[[37881]],195052:[[37909]],195053:[[166906]],195054:[[38283]],195055:[[18837]],195056:[[38327]],195057:[[167287]],195058:[[18918]],195059:[[38595]],195060:[[23986]],195061:[[38691]],195062:[[168261]],195063:[[168474]],195064:[[19054]],195065:[[19062]],195066:[[38880]],195067:[[168970]],195068:[[19122]],195069:[[169110]],195070:[[38923]],195071:[[38923]]}, | ||
365 | 64000:{64000:[[20999]],64001:[[24230]],64002:[[25299]],64003:[[31958]],64004:[[23429]],64005:[[27934]],64006:[[26292]],64007:[[36667]],64008:[[34892]],64009:[[38477]],64010:[[35211]],64011:[[24275]],64012:[[20800]],64013:[[21952]],64016:[[22618]],64018:[[26228]],64021:[[20958]],64022:[[29482]],64023:[[30410]],64024:[[31036]],64025:[[31070]],64026:[[31077]],64027:[[31119]],64028:[[38742]],64029:[[31934]],64030:[[32701]],64032:[[34322]],64034:[[35576]],64037:[[36920]],64038:[[37117]],64042:[[39151]],64043:[[39164]],64044:[[39208]],64045:[[40372]],64046:[[37086]],64047:[[38583]],64048:[[20398]],64049:[[20711]],64050:[[20813]],64051:[[21193]],64052:[[21220]],64053:[[21329]],64054:[[21917]],64055:[[22022]],64056:[[22120]],64057:[[22592]],64058:[[22696]],64059:[[23652]],64060:[[23662]],64061:[[24724]],64062:[[24936]],64063:[[24974]],64064:[[25074]],64065:[[25935]],64066:[[26082]],64067:[[26257]],64068:[[26757]],64069:[[28023]],64070:[[28186]],64071:[[28450]],64072:[[29038]],64073:[[29227]],64074:[[29730]],64075:[[30865]],64076:[[31038]],64077:[[31049]],64078:[[31048]],64079:[[31056]],64080:[[31062]],64081:[[31069]],64082:[[31117]],64083:[[31118]],64084:[[31296]],64085:[[31361]],64086:[[31680]],64087:[[32244]],64088:[[32265]],64089:[[32321]],64090:[[32626]],64091:[[32773]],64092:[[33261]],64093:[[33401]],64094:[[33401]],64095:[[33879]],64096:[[35088]],64097:[[35222]],64098:[[35585]],64099:[[35641]],64100:[[36051]],64101:[[36104]],64102:[[36790]],64103:[[36920]],64104:[[38627]],64105:[[38911]],64106:[[38971]],64107:[[24693]],64108:[[148206]],64109:[[33304]],64112:[[20006]],64113:[[20917]],64114:[[20840]],64115:[[20352]],64116:[[20805]],64117:[[20864]],64118:[[21191]],64119:[[21242]],64120:[[21917]],64121:[[21845]],64122:[[21913]],64123:[[21986]],64124:[[22618]],64125:[[22707]],64126:[[22852]],64127:[[22868]],64128:[[23138]],64129:[[23336]],64130:[[24274]],64131:[[24281]],64132:[[24425]],64133:[[24493]],64134:[[24792]],64135:[[24910]],64136:[[24840]],64137:[[24974]],64138:[[24928]],64139:[[25074]],64140:[[25140]],64141:[[25540]],64142:[[25628]],64143:[[25682]],64144:[[25942]],64145:[[26228]],64146:[[26391]],64147:[[26395]],64148:[[26454]],64149:[[27513]],64150:[[27578]],64151:[[27969]],64152:[[28379]],64153:[[28363]],64154:[[28450]],64155:[[28702]],64156:[[29038]],64157:[[30631]],64158:[[29237]],64159:[[29359]],64160:[[29482]],64161:[[29809]],64162:[[29958]],64163:[[30011]],64164:[[30237]],64165:[[30239]],64166:[[30410]],64167:[[30427]],64168:[[30452]],64169:[[30538]],64170:[[30528]],64171:[[30924]],64172:[[31409]],64173:[[31680]],64174:[[31867]],64175:[[32091]],64176:[[32244]],64177:[[32574]],64178:[[32773]],64179:[[33618]],64180:[[33775]],64181:[[34681]],64182:[[35137]],64183:[[35206]],64184:[[35222]],64185:[[35519]],64186:[[35576]],64187:[[35531]],64188:[[35585]],64189:[[35582]],64190:[[35565]],64191:[[35641]],64192:[[35722]],64193:[[36104]],64194:[[36664]],64195:[[36978]],64196:[[37273]],64197:[[37494]],64198:[[38524]],64199:[[38627]],64200:[[38742]],64201:[[38875]],64202:[[38911]],64203:[[38923]],64204:[[38971]],64205:[[39698]],64206:[[40860]],64207:[[141386]],64208:[[141380]],64209:[[144341]],64210:[[15261]],64211:[[16408]],64212:[[16441]],64213:[[152137]],64214:[[154832]],64215:[[163539]],64216:[[40771]],64217:[[40846]],195072:[[38953]],195073:[[169398]],195074:[[39138]],195075:[[19251]],195076:[[39209]],195077:[[39335]],195078:[[39362]],195079:[[39422]],195080:[[19406]],195081:[[170800]],195082:[[39698]],195083:[[40000]],195084:[[40189]],195085:[[19662]],195086:[[19693]],195087:[[40295]],195088:[[172238]],195089:[[19704]],195090:[[172293]],195091:[[172558]],195092:[[172689]],195093:[[40635]],195094:[[19798]],195095:[[40697]],195096:[[40702]],195097:[[40709]],195098:[[40719]],195099:[[40726]],195100:[[40763]],195101:[[173568]]}, | ||
366 | 64256:{64256:[[102,102],256],64257:[[102,105],256],64258:[[102,108],256],64259:[[102,102,105],256],64260:[[102,102,108],256],64261:[[383,116],256],64262:[[115,116],256],64275:[[1396,1398],256],64276:[[1396,1381],256],64277:[[1396,1387],256],64278:[[1406,1398],256],64279:[[1396,1389],256],64285:[[1497,1460],512],64286:[,26],64287:[[1522,1463],512],64288:[[1506],256],64289:[[1488],256],64290:[[1491],256],64291:[[1492],256],64292:[[1499],256],64293:[[1500],256],64294:[[1501],256],64295:[[1512],256],64296:[[1514],256],64297:[[43],256],64298:[[1513,1473],512],64299:[[1513,1474],512],64300:[[64329,1473],512],64301:[[64329,1474],512],64302:[[1488,1463],512],64303:[[1488,1464],512],64304:[[1488,1468],512],64305:[[1489,1468],512],64306:[[1490,1468],512],64307:[[1491,1468],512],64308:[[1492,1468],512],64309:[[1493,1468],512],64310:[[1494,1468],512],64312:[[1496,1468],512],64313:[[1497,1468],512],64314:[[1498,1468],512],64315:[[1499,1468],512],64316:[[1500,1468],512],64318:[[1502,1468],512],64320:[[1504,1468],512],64321:[[1505,1468],512],64323:[[1507,1468],512],64324:[[1508,1468],512],64326:[[1510,1468],512],64327:[[1511,1468],512],64328:[[1512,1468],512],64329:[[1513,1468],512],64330:[[1514,1468],512],64331:[[1493,1465],512],64332:[[1489,1471],512],64333:[[1499,1471],512],64334:[[1508,1471],512],64335:[[1488,1500],256],64336:[[1649],256],64337:[[1649],256],64338:[[1659],256],64339:[[1659],256],64340:[[1659],256],64341:[[1659],256],64342:[[1662],256],64343:[[1662],256],64344:[[1662],256],64345:[[1662],256],64346:[[1664],256],64347:[[1664],256],64348:[[1664],256],64349:[[1664],256],64350:[[1658],256],64351:[[1658],256],64352:[[1658],256],64353:[[1658],256],64354:[[1663],256],64355:[[1663],256],64356:[[1663],256],64357:[[1663],256],64358:[[1657],256],64359:[[1657],256],64360:[[1657],256],64361:[[1657],256],64362:[[1700],256],64363:[[1700],256],64364:[[1700],256],64365:[[1700],256],64366:[[1702],256],64367:[[1702],256],64368:[[1702],256],64369:[[1702],256],64370:[[1668],256],64371:[[1668],256],64372:[[1668],256],64373:[[1668],256],64374:[[1667],256],64375:[[1667],256],64376:[[1667],256],64377:[[1667],256],64378:[[1670],256],64379:[[1670],256],64380:[[1670],256],64381:[[1670],256],64382:[[1671],256],64383:[[1671],256],64384:[[1671],256],64385:[[1671],256],64386:[[1677],256],64387:[[1677],256],64388:[[1676],256],64389:[[1676],256],64390:[[1678],256],64391:[[1678],256],64392:[[1672],256],64393:[[1672],256],64394:[[1688],256],64395:[[1688],256],64396:[[1681],256],64397:[[1681],256],64398:[[1705],256],64399:[[1705],256],64400:[[1705],256],64401:[[1705],256],64402:[[1711],256],64403:[[1711],256],64404:[[1711],256],64405:[[1711],256],64406:[[1715],256],64407:[[1715],256],64408:[[1715],256],64409:[[1715],256],64410:[[1713],256],64411:[[1713],256],64412:[[1713],256],64413:[[1713],256],64414:[[1722],256],64415:[[1722],256],64416:[[1723],256],64417:[[1723],256],64418:[[1723],256],64419:[[1723],256],64420:[[1728],256],64421:[[1728],256],64422:[[1729],256],64423:[[1729],256],64424:[[1729],256],64425:[[1729],256],64426:[[1726],256],64427:[[1726],256],64428:[[1726],256],64429:[[1726],256],64430:[[1746],256],64431:[[1746],256],64432:[[1747],256],64433:[[1747],256],64467:[[1709],256],64468:[[1709],256],64469:[[1709],256],64470:[[1709],256],64471:[[1735],256],64472:[[1735],256],64473:[[1734],256],64474:[[1734],256],64475:[[1736],256],64476:[[1736],256],64477:[[1655],256],64478:[[1739],256],64479:[[1739],256],64480:[[1733],256],64481:[[1733],256],64482:[[1737],256],64483:[[1737],256],64484:[[1744],256],64485:[[1744],256],64486:[[1744],256],64487:[[1744],256],64488:[[1609],256],64489:[[1609],256],64490:[[1574,1575],256],64491:[[1574,1575],256],64492:[[1574,1749],256],64493:[[1574,1749],256],64494:[[1574,1608],256],64495:[[1574,1608],256],64496:[[1574,1735],256],64497:[[1574,1735],256],64498:[[1574,1734],256],64499:[[1574,1734],256],64500:[[1574,1736],256],64501:[[1574,1736],256],64502:[[1574,1744],256],64503:[[1574,1744],256],64504:[[1574,1744],256],64505:[[1574,1609],256],64506:[[1574,1609],256],64507:[[1574,1609],256],64508:[[1740],256],64509:[[1740],256],64510:[[1740],256],64511:[[1740],256]}, | ||
367 | 64512:{64512:[[1574,1580],256],64513:[[1574,1581],256],64514:[[1574,1605],256],64515:[[1574,1609],256],64516:[[1574,1610],256],64517:[[1576,1580],256],64518:[[1576,1581],256],64519:[[1576,1582],256],64520:[[1576,1605],256],64521:[[1576,1609],256],64522:[[1576,1610],256],64523:[[1578,1580],256],64524:[[1578,1581],256],64525:[[1578,1582],256],64526:[[1578,1605],256],64527:[[1578,1609],256],64528:[[1578,1610],256],64529:[[1579,1580],256],64530:[[1579,1605],256],64531:[[1579,1609],256],64532:[[1579,1610],256],64533:[[1580,1581],256],64534:[[1580,1605],256],64535:[[1581,1580],256],64536:[[1581,1605],256],64537:[[1582,1580],256],64538:[[1582,1581],256],64539:[[1582,1605],256],64540:[[1587,1580],256],64541:[[1587,1581],256],64542:[[1587,1582],256],64543:[[1587,1605],256],64544:[[1589,1581],256],64545:[[1589,1605],256],64546:[[1590,1580],256],64547:[[1590,1581],256],64548:[[1590,1582],256],64549:[[1590,1605],256],64550:[[1591,1581],256],64551:[[1591,1605],256],64552:[[1592,1605],256],64553:[[1593,1580],256],64554:[[1593,1605],256],64555:[[1594,1580],256],64556:[[1594,1605],256],64557:[[1601,1580],256],64558:[[1601,1581],256],64559:[[1601,1582],256],64560:[[1601,1605],256],64561:[[1601,1609],256],64562:[[1601,1610],256],64563:[[1602,1581],256],64564:[[1602,1605],256],64565:[[1602,1609],256],64566:[[1602,1610],256],64567:[[1603,1575],256],64568:[[1603,1580],256],64569:[[1603,1581],256],64570:[[1603,1582],256],64571:[[1603,1604],256],64572:[[1603,1605],256],64573:[[1603,1609],256],64574:[[1603,1610],256],64575:[[1604,1580],256],64576:[[1604,1581],256],64577:[[1604,1582],256],64578:[[1604,1605],256],64579:[[1604,1609],256],64580:[[1604,1610],256],64581:[[1605,1580],256],64582:[[1605,1581],256],64583:[[1605,1582],256],64584:[[1605,1605],256],64585:[[1605,1609],256],64586:[[1605,1610],256],64587:[[1606,1580],256],64588:[[1606,1581],256],64589:[[1606,1582],256],64590:[[1606,1605],256],64591:[[1606,1609],256],64592:[[1606,1610],256],64593:[[1607,1580],256],64594:[[1607,1605],256],64595:[[1607,1609],256],64596:[[1607,1610],256],64597:[[1610,1580],256],64598:[[1610,1581],256],64599:[[1610,1582],256],64600:[[1610,1605],256],64601:[[1610,1609],256],64602:[[1610,1610],256],64603:[[1584,1648],256],64604:[[1585,1648],256],64605:[[1609,1648],256],64606:[[32,1612,1617],256],64607:[[32,1613,1617],256],64608:[[32,1614,1617],256],64609:[[32,1615,1617],256],64610:[[32,1616,1617],256],64611:[[32,1617,1648],256],64612:[[1574,1585],256],64613:[[1574,1586],256],64614:[[1574,1605],256],64615:[[1574,1606],256],64616:[[1574,1609],256],64617:[[1574,1610],256],64618:[[1576,1585],256],64619:[[1576,1586],256],64620:[[1576,1605],256],64621:[[1576,1606],256],64622:[[1576,1609],256],64623:[[1576,1610],256],64624:[[1578,1585],256],64625:[[1578,1586],256],64626:[[1578,1605],256],64627:[[1578,1606],256],64628:[[1578,1609],256],64629:[[1578,1610],256],64630:[[1579,1585],256],64631:[[1579,1586],256],64632:[[1579,1605],256],64633:[[1579,1606],256],64634:[[1579,1609],256],64635:[[1579,1610],256],64636:[[1601,1609],256],64637:[[1601,1610],256],64638:[[1602,1609],256],64639:[[1602,1610],256],64640:[[1603,1575],256],64641:[[1603,1604],256],64642:[[1603,1605],256],64643:[[1603,1609],256],64644:[[1603,1610],256],64645:[[1604,1605],256],64646:[[1604,1609],256],64647:[[1604,1610],256],64648:[[1605,1575],256],64649:[[1605,1605],256],64650:[[1606,1585],256],64651:[[1606,1586],256],64652:[[1606,1605],256],64653:[[1606,1606],256],64654:[[1606,1609],256],64655:[[1606,1610],256],64656:[[1609,1648],256],64657:[[1610,1585],256],64658:[[1610,1586],256],64659:[[1610,1605],256],64660:[[1610,1606],256],64661:[[1610,1609],256],64662:[[1610,1610],256],64663:[[1574,1580],256],64664:[[1574,1581],256],64665:[[1574,1582],256],64666:[[1574,1605],256],64667:[[1574,1607],256],64668:[[1576,1580],256],64669:[[1576,1581],256],64670:[[1576,1582],256],64671:[[1576,1605],256],64672:[[1576,1607],256],64673:[[1578,1580],256],64674:[[1578,1581],256],64675:[[1578,1582],256],64676:[[1578,1605],256],64677:[[1578,1607],256],64678:[[1579,1605],256],64679:[[1580,1581],256],64680:[[1580,1605],256],64681:[[1581,1580],256],64682:[[1581,1605],256],64683:[[1582,1580],256],64684:[[1582,1605],256],64685:[[1587,1580],256],64686:[[1587,1581],256],64687:[[1587,1582],256],64688:[[1587,1605],256],64689:[[1589,1581],256],64690:[[1589,1582],256],64691:[[1589,1605],256],64692:[[1590,1580],256],64693:[[1590,1581],256],64694:[[1590,1582],256],64695:[[1590,1605],256],64696:[[1591,1581],256],64697:[[1592,1605],256],64698:[[1593,1580],256],64699:[[1593,1605],256],64700:[[1594,1580],256],64701:[[1594,1605],256],64702:[[1601,1580],256],64703:[[1601,1581],256],64704:[[1601,1582],256],64705:[[1601,1605],256],64706:[[1602,1581],256],64707:[[1602,1605],256],64708:[[1603,1580],256],64709:[[1603,1581],256],64710:[[1603,1582],256],64711:[[1603,1604],256],64712:[[1603,1605],256],64713:[[1604,1580],256],64714:[[1604,1581],256],64715:[[1604,1582],256],64716:[[1604,1605],256],64717:[[1604,1607],256],64718:[[1605,1580],256],64719:[[1605,1581],256],64720:[[1605,1582],256],64721:[[1605,1605],256],64722:[[1606,1580],256],64723:[[1606,1581],256],64724:[[1606,1582],256],64725:[[1606,1605],256],64726:[[1606,1607],256],64727:[[1607,1580],256],64728:[[1607,1605],256],64729:[[1607,1648],256],64730:[[1610,1580],256],64731:[[1610,1581],256],64732:[[1610,1582],256],64733:[[1610,1605],256],64734:[[1610,1607],256],64735:[[1574,1605],256],64736:[[1574,1607],256],64737:[[1576,1605],256],64738:[[1576,1607],256],64739:[[1578,1605],256],64740:[[1578,1607],256],64741:[[1579,1605],256],64742:[[1579,1607],256],64743:[[1587,1605],256],64744:[[1587,1607],256],64745:[[1588,1605],256],64746:[[1588,1607],256],64747:[[1603,1604],256],64748:[[1603,1605],256],64749:[[1604,1605],256],64750:[[1606,1605],256],64751:[[1606,1607],256],64752:[[1610,1605],256],64753:[[1610,1607],256],64754:[[1600,1614,1617],256],64755:[[1600,1615,1617],256],64756:[[1600,1616,1617],256],64757:[[1591,1609],256],64758:[[1591,1610],256],64759:[[1593,1609],256],64760:[[1593,1610],256],64761:[[1594,1609],256],64762:[[1594,1610],256],64763:[[1587,1609],256],64764:[[1587,1610],256],64765:[[1588,1609],256],64766:[[1588,1610],256],64767:[[1581,1609],256]}, | ||
368 | 64768:{64768:[[1581,1610],256],64769:[[1580,1609],256],64770:[[1580,1610],256],64771:[[1582,1609],256],64772:[[1582,1610],256],64773:[[1589,1609],256],64774:[[1589,1610],256],64775:[[1590,1609],256],64776:[[1590,1610],256],64777:[[1588,1580],256],64778:[[1588,1581],256],64779:[[1588,1582],256],64780:[[1588,1605],256],64781:[[1588,1585],256],64782:[[1587,1585],256],64783:[[1589,1585],256],64784:[[1590,1585],256],64785:[[1591,1609],256],64786:[[1591,1610],256],64787:[[1593,1609],256],64788:[[1593,1610],256],64789:[[1594,1609],256],64790:[[1594,1610],256],64791:[[1587,1609],256],64792:[[1587,1610],256],64793:[[1588,1609],256],64794:[[1588,1610],256],64795:[[1581,1609],256],64796:[[1581,1610],256],64797:[[1580,1609],256],64798:[[1580,1610],256],64799:[[1582,1609],256],64800:[[1582,1610],256],64801:[[1589,1609],256],64802:[[1589,1610],256],64803:[[1590,1609],256],64804:[[1590,1610],256],64805:[[1588,1580],256],64806:[[1588,1581],256],64807:[[1588,1582],256],64808:[[1588,1605],256],64809:[[1588,1585],256],64810:[[1587,1585],256],64811:[[1589,1585],256],64812:[[1590,1585],256],64813:[[1588,1580],256],64814:[[1588,1581],256],64815:[[1588,1582],256],64816:[[1588,1605],256],64817:[[1587,1607],256],64818:[[1588,1607],256],64819:[[1591,1605],256],64820:[[1587,1580],256],64821:[[1587,1581],256],64822:[[1587,1582],256],64823:[[1588,1580],256],64824:[[1588,1581],256],64825:[[1588,1582],256],64826:[[1591,1605],256],64827:[[1592,1605],256],64828:[[1575,1611],256],64829:[[1575,1611],256],64848:[[1578,1580,1605],256],64849:[[1578,1581,1580],256],64850:[[1578,1581,1580],256],64851:[[1578,1581,1605],256],64852:[[1578,1582,1605],256],64853:[[1578,1605,1580],256],64854:[[1578,1605,1581],256],64855:[[1578,1605,1582],256],64856:[[1580,1605,1581],256],64857:[[1580,1605,1581],256],64858:[[1581,1605,1610],256],64859:[[1581,1605,1609],256],64860:[[1587,1581,1580],256],64861:[[1587,1580,1581],256],64862:[[1587,1580,1609],256],64863:[[1587,1605,1581],256],64864:[[1587,1605,1581],256],64865:[[1587,1605,1580],256],64866:[[1587,1605,1605],256],64867:[[1587,1605,1605],256],64868:[[1589,1581,1581],256],64869:[[1589,1581,1581],256],64870:[[1589,1605,1605],256],64871:[[1588,1581,1605],256],64872:[[1588,1581,1605],256],64873:[[1588,1580,1610],256],64874:[[1588,1605,1582],256],64875:[[1588,1605,1582],256],64876:[[1588,1605,1605],256],64877:[[1588,1605,1605],256],64878:[[1590,1581,1609],256],64879:[[1590,1582,1605],256],64880:[[1590,1582,1605],256],64881:[[1591,1605,1581],256],64882:[[1591,1605,1581],256],64883:[[1591,1605,1605],256],64884:[[1591,1605,1610],256],64885:[[1593,1580,1605],256],64886:[[1593,1605,1605],256],64887:[[1593,1605,1605],256],64888:[[1593,1605,1609],256],64889:[[1594,1605,1605],256],64890:[[1594,1605,1610],256],64891:[[1594,1605,1609],256],64892:[[1601,1582,1605],256],64893:[[1601,1582,1605],256],64894:[[1602,1605,1581],256],64895:[[1602,1605,1605],256],64896:[[1604,1581,1605],256],64897:[[1604,1581,1610],256],64898:[[1604,1581,1609],256],64899:[[1604,1580,1580],256],64900:[[1604,1580,1580],256],64901:[[1604,1582,1605],256],64902:[[1604,1582,1605],256],64903:[[1604,1605,1581],256],64904:[[1604,1605,1581],256],64905:[[1605,1581,1580],256],64906:[[1605,1581,1605],256],64907:[[1605,1581,1610],256],64908:[[1605,1580,1581],256],64909:[[1605,1580,1605],256],64910:[[1605,1582,1580],256],64911:[[1605,1582,1605],256],64914:[[1605,1580,1582],256],64915:[[1607,1605,1580],256],64916:[[1607,1605,1605],256],64917:[[1606,1581,1605],256],64918:[[1606,1581,1609],256],64919:[[1606,1580,1605],256],64920:[[1606,1580,1605],256],64921:[[1606,1580,1609],256],64922:[[1606,1605,1610],256],64923:[[1606,1605,1609],256],64924:[[1610,1605,1605],256],64925:[[1610,1605,1605],256],64926:[[1576,1582,1610],256],64927:[[1578,1580,1610],256],64928:[[1578,1580,1609],256],64929:[[1578,1582,1610],256],64930:[[1578,1582,1609],256],64931:[[1578,1605,1610],256],64932:[[1578,1605,1609],256],64933:[[1580,1605,1610],256],64934:[[1580,1581,1609],256],64935:[[1580,1605,1609],256],64936:[[1587,1582,1609],256],64937:[[1589,1581,1610],256],64938:[[1588,1581,1610],256],64939:[[1590,1581,1610],256],64940:[[1604,1580,1610],256],64941:[[1604,1605,1610],256],64942:[[1610,1581,1610],256],64943:[[1610,1580,1610],256],64944:[[1610,1605,1610],256],64945:[[1605,1605,1610],256],64946:[[1602,1605,1610],256],64947:[[1606,1581,1610],256],64948:[[1602,1605,1581],256],64949:[[1604,1581,1605],256],64950:[[1593,1605,1610],256],64951:[[1603,1605,1610],256],64952:[[1606,1580,1581],256],64953:[[1605,1582,1610],256],64954:[[1604,1580,1605],256],64955:[[1603,1605,1605],256],64956:[[1604,1580,1605],256],64957:[[1606,1580,1581],256],64958:[[1580,1581,1610],256],64959:[[1581,1580,1610],256],64960:[[1605,1580,1610],256],64961:[[1601,1605,1610],256],64962:[[1576,1581,1610],256],64963:[[1603,1605,1605],256],64964:[[1593,1580,1605],256],64965:[[1589,1605,1605],256],64966:[[1587,1582,1610],256],64967:[[1606,1580,1610],256],65008:[[1589,1604,1746],256],65009:[[1602,1604,1746],256],65010:[[1575,1604,1604,1607],256],65011:[[1575,1603,1576,1585],256],65012:[[1605,1581,1605,1583],256],65013:[[1589,1604,1593,1605],256],65014:[[1585,1587,1608,1604],256],65015:[[1593,1604,1610,1607],256],65016:[[1608,1587,1604,1605],256],65017:[[1589,1604,1609],256],65018:[[1589,1604,1609,32,1575,1604,1604,1607,32,1593,1604,1610,1607,32,1608,1587,1604,1605],256],65019:[[1580,1604,32,1580,1604,1575,1604,1607],256],65020:[[1585,1740,1575,1604],256]}, | ||
369 | 65024:{65040:[[44],256],65041:[[12289],256],65042:[[12290],256],65043:[[58],256],65044:[[59],256],65045:[[33],256],65046:[[63],256],65047:[[12310],256],65048:[[12311],256],65049:[[8230],256],65056:[,230],65057:[,230],65058:[,230],65059:[,230],65060:[,230],65061:[,230],65062:[,230],65063:[,220],65064:[,220],65065:[,220],65066:[,220],65067:[,220],65068:[,220],65069:[,220],65072:[[8229],256],65073:[[8212],256],65074:[[8211],256],65075:[[95],256],65076:[[95],256],65077:[[40],256],65078:[[41],256],65079:[[123],256],65080:[[125],256],65081:[[12308],256],65082:[[12309],256],65083:[[12304],256],65084:[[12305],256],65085:[[12298],256],65086:[[12299],256],65087:[[12296],256],65088:[[12297],256],65089:[[12300],256],65090:[[12301],256],65091:[[12302],256],65092:[[12303],256],65095:[[91],256],65096:[[93],256],65097:[[8254],256],65098:[[8254],256],65099:[[8254],256],65100:[[8254],256],65101:[[95],256],65102:[[95],256],65103:[[95],256],65104:[[44],256],65105:[[12289],256],65106:[[46],256],65108:[[59],256],65109:[[58],256],65110:[[63],256],65111:[[33],256],65112:[[8212],256],65113:[[40],256],65114:[[41],256],65115:[[123],256],65116:[[125],256],65117:[[12308],256],65118:[[12309],256],65119:[[35],256],65120:[[38],256],65121:[[42],256],65122:[[43],256],65123:[[45],256],65124:[[60],256],65125:[[62],256],65126:[[61],256],65128:[[92],256],65129:[[36],256],65130:[[37],256],65131:[[64],256],65136:[[32,1611],256],65137:[[1600,1611],256],65138:[[32,1612],256],65140:[[32,1613],256],65142:[[32,1614],256],65143:[[1600,1614],256],65144:[[32,1615],256],65145:[[1600,1615],256],65146:[[32,1616],256],65147:[[1600,1616],256],65148:[[32,1617],256],65149:[[1600,1617],256],65150:[[32,1618],256],65151:[[1600,1618],256],65152:[[1569],256],65153:[[1570],256],65154:[[1570],256],65155:[[1571],256],65156:[[1571],256],65157:[[1572],256],65158:[[1572],256],65159:[[1573],256],65160:[[1573],256],65161:[[1574],256],65162:[[1574],256],65163:[[1574],256],65164:[[1574],256],65165:[[1575],256],65166:[[1575],256],65167:[[1576],256],65168:[[1576],256],65169:[[1576],256],65170:[[1576],256],65171:[[1577],256],65172:[[1577],256],65173:[[1578],256],65174:[[1578],256],65175:[[1578],256],65176:[[1578],256],65177:[[1579],256],65178:[[1579],256],65179:[[1579],256],65180:[[1579],256],65181:[[1580],256],65182:[[1580],256],65183:[[1580],256],65184:[[1580],256],65185:[[1581],256],65186:[[1581],256],65187:[[1581],256],65188:[[1581],256],65189:[[1582],256],65190:[[1582],256],65191:[[1582],256],65192:[[1582],256],65193:[[1583],256],65194:[[1583],256],65195:[[1584],256],65196:[[1584],256],65197:[[1585],256],65198:[[1585],256],65199:[[1586],256],65200:[[1586],256],65201:[[1587],256],65202:[[1587],256],65203:[[1587],256],65204:[[1587],256],65205:[[1588],256],65206:[[1588],256],65207:[[1588],256],65208:[[1588],256],65209:[[1589],256],65210:[[1589],256],65211:[[1589],256],65212:[[1589],256],65213:[[1590],256],65214:[[1590],256],65215:[[1590],256],65216:[[1590],256],65217:[[1591],256],65218:[[1591],256],65219:[[1591],256],65220:[[1591],256],65221:[[1592],256],65222:[[1592],256],65223:[[1592],256],65224:[[1592],256],65225:[[1593],256],65226:[[1593],256],65227:[[1593],256],65228:[[1593],256],65229:[[1594],256],65230:[[1594],256],65231:[[1594],256],65232:[[1594],256],65233:[[1601],256],65234:[[1601],256],65235:[[1601],256],65236:[[1601],256],65237:[[1602],256],65238:[[1602],256],65239:[[1602],256],65240:[[1602],256],65241:[[1603],256],65242:[[1603],256],65243:[[1603],256],65244:[[1603],256],65245:[[1604],256],65246:[[1604],256],65247:[[1604],256],65248:[[1604],256],65249:[[1605],256],65250:[[1605],256],65251:[[1605],256],65252:[[1605],256],65253:[[1606],256],65254:[[1606],256],65255:[[1606],256],65256:[[1606],256],65257:[[1607],256],65258:[[1607],256],65259:[[1607],256],65260:[[1607],256],65261:[[1608],256],65262:[[1608],256],65263:[[1609],256],65264:[[1609],256],65265:[[1610],256],65266:[[1610],256],65267:[[1610],256],65268:[[1610],256],65269:[[1604,1570],256],65270:[[1604,1570],256],65271:[[1604,1571],256],65272:[[1604,1571],256],65273:[[1604,1573],256],65274:[[1604,1573],256],65275:[[1604,1575],256],65276:[[1604,1575],256]}, | ||
370 | 65280:{65281:[[33],256],65282:[[34],256],65283:[[35],256],65284:[[36],256],65285:[[37],256],65286:[[38],256],65287:[[39],256],65288:[[40],256],65289:[[41],256],65290:[[42],256],65291:[[43],256],65292:[[44],256],65293:[[45],256],65294:[[46],256],65295:[[47],256],65296:[[48],256],65297:[[49],256],65298:[[50],256],65299:[[51],256],65300:[[52],256],65301:[[53],256],65302:[[54],256],65303:[[55],256],65304:[[56],256],65305:[[57],256],65306:[[58],256],65307:[[59],256],65308:[[60],256],65309:[[61],256],65310:[[62],256],65311:[[63],256],65312:[[64],256],65313:[[65],256],65314:[[66],256],65315:[[67],256],65316:[[68],256],65317:[[69],256],65318:[[70],256],65319:[[71],256],65320:[[72],256],65321:[[73],256],65322:[[74],256],65323:[[75],256],65324:[[76],256],65325:[[77],256],65326:[[78],256],65327:[[79],256],65328:[[80],256],65329:[[81],256],65330:[[82],256],65331:[[83],256],65332:[[84],256],65333:[[85],256],65334:[[86],256],65335:[[87],256],65336:[[88],256],65337:[[89],256],65338:[[90],256],65339:[[91],256],65340:[[92],256],65341:[[93],256],65342:[[94],256],65343:[[95],256],65344:[[96],256],65345:[[97],256],65346:[[98],256],65347:[[99],256],65348:[[100],256],65349:[[101],256],65350:[[102],256],65351:[[103],256],65352:[[104],256],65353:[[105],256],65354:[[106],256],65355:[[107],256],65356:[[108],256],65357:[[109],256],65358:[[110],256],65359:[[111],256],65360:[[112],256],65361:[[113],256],65362:[[114],256],65363:[[115],256],65364:[[116],256],65365:[[117],256],65366:[[118],256],65367:[[119],256],65368:[[120],256],65369:[[121],256],65370:[[122],256],65371:[[123],256],65372:[[124],256],65373:[[125],256],65374:[[126],256],65375:[[10629],256],65376:[[10630],256],65377:[[12290],256],65378:[[12300],256],65379:[[12301],256],65380:[[12289],256],65381:[[12539],256],65382:[[12530],256],65383:[[12449],256],65384:[[12451],256],65385:[[12453],256],65386:[[12455],256],65387:[[12457],256],65388:[[12515],256],65389:[[12517],256],65390:[[12519],256],65391:[[12483],256],65392:[[12540],256],65393:[[12450],256],65394:[[12452],256],65395:[[12454],256],65396:[[12456],256],65397:[[12458],256],65398:[[12459],256],65399:[[12461],256],65400:[[12463],256],65401:[[12465],256],65402:[[12467],256],65403:[[12469],256],65404:[[12471],256],65405:[[12473],256],65406:[[12475],256],65407:[[12477],256],65408:[[12479],256],65409:[[12481],256],65410:[[12484],256],65411:[[12486],256],65412:[[12488],256],65413:[[12490],256],65414:[[12491],256],65415:[[12492],256],65416:[[12493],256],65417:[[12494],256],65418:[[12495],256],65419:[[12498],256],65420:[[12501],256],65421:[[12504],256],65422:[[12507],256],65423:[[12510],256],65424:[[12511],256],65425:[[12512],256],65426:[[12513],256],65427:[[12514],256],65428:[[12516],256],65429:[[12518],256],65430:[[12520],256],65431:[[12521],256],65432:[[12522],256],65433:[[12523],256],65434:[[12524],256],65435:[[12525],256],65436:[[12527],256],65437:[[12531],256],65438:[[12441],256],65439:[[12442],256],65440:[[12644],256],65441:[[12593],256],65442:[[12594],256],65443:[[12595],256],65444:[[12596],256],65445:[[12597],256],65446:[[12598],256],65447:[[12599],256],65448:[[12600],256],65449:[[12601],256],65450:[[12602],256],65451:[[12603],256],65452:[[12604],256],65453:[[12605],256],65454:[[12606],256],65455:[[12607],256],65456:[[12608],256],65457:[[12609],256],65458:[[12610],256],65459:[[12611],256],65460:[[12612],256],65461:[[12613],256],65462:[[12614],256],65463:[[12615],256],65464:[[12616],256],65465:[[12617],256],65466:[[12618],256],65467:[[12619],256],65468:[[12620],256],65469:[[12621],256],65470:[[12622],256],65474:[[12623],256],65475:[[12624],256],65476:[[12625],256],65477:[[12626],256],65478:[[12627],256],65479:[[12628],256],65482:[[12629],256],65483:[[12630],256],65484:[[12631],256],65485:[[12632],256],65486:[[12633],256],65487:[[12634],256],65490:[[12635],256],65491:[[12636],256],65492:[[12637],256],65493:[[12638],256],65494:[[12639],256],65495:[[12640],256],65498:[[12641],256],65499:[[12642],256],65500:[[12643],256],65504:[[162],256],65505:[[163],256],65506:[[172],256],65507:[[175],256],65508:[[166],256],65509:[[165],256],65510:[[8361],256],65512:[[9474],256],65513:[[8592],256],65514:[[8593],256],65515:[[8594],256],65516:[[8595],256],65517:[[9632],256],65518:[[9675],256]} | ||
371 | |||
372 | }; | ||
373 | |||
374 | /***** Module to export */ | ||
375 | var unorm = { | ||
376 | nfc: nfc, | ||
377 | nfd: nfd, | ||
378 | nfkc: nfkc, | ||
379 | nfkd: nfkd | ||
380 | }; | ||
381 | |||
382 | /*globals module:true,define:true*/ | ||
383 | |||
384 | // CommonJS | ||
385 | if (typeof module === "object") { | ||
386 | module.exports = unorm; | ||
387 | |||
388 | // AMD | ||
389 | } else if (typeof define === "function" && define.amd) { | ||
390 | define("unorm", function () { | ||
391 | return unorm; | ||
392 | }); | ||
393 | |||
394 | // Global | ||
395 | } else { | ||
396 | root.unorm = unorm; | ||
397 | } | ||
398 | |||
399 | /***** Export as shim for String::normalize method *****/ | ||
400 | /* | ||
401 | http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#november_8_2013_draft_rev_21 | ||
402 | |||
403 | 21.1.3.12 String.prototype.normalize(form="NFC") | ||
404 | When the normalize method is called with one argument form, the following steps are taken: | ||
405 | |||
406 | 1. Let O be CheckObjectCoercible(this value). | ||
407 | 2. Let S be ToString(O). | ||
408 | 3. ReturnIfAbrupt(S). | ||
409 | 4. If form is not provided or undefined let form be "NFC". | ||
410 | 5. Let f be ToString(form). | ||
411 | 6. ReturnIfAbrupt(f). | ||
412 | 7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw a RangeError Exception. | ||
413 | 8. Let ns be the String value is the result of normalizing S into the normalization form named by f as specified in Unicode Standard Annex #15, UnicodeNormalizatoin Forms. | ||
414 | 9. Return ns. | ||
415 | |||
416 | The length property of the normalize method is 0. | ||
417 | |||
418 | *NOTE* The normalize function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. | ||
419 | */ | ||
420 | unorm.shimApplied = false; | ||
421 | |||
422 | if (!String.prototype.normalize) { | ||
423 | String.prototype.normalize = function(form) { | ||
424 | var str = "" + this; | ||
425 | form = form === undefined ? "NFC" : form; | ||
426 | |||
427 | if (form === "NFC") { | ||
428 | return unorm.nfc(str); | ||
429 | } else if (form === "NFD") { | ||
430 | return unorm.nfd(str); | ||
431 | } else if (form === "NFKC") { | ||
432 | return unorm.nfkc(str); | ||
433 | } else if (form === "NFKD") { | ||
434 | return unorm.nfkd(str); | ||
435 | } else { | ||
436 | throw new RangeError("Invalid normalization form: " + form); | ||
437 | } | ||
438 | }; | ||
439 | |||
440 | unorm.shimApplied = true; | ||
441 | } | ||
442 | }(this)); | ||