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
.bitcoinjs
= 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
){
5 // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
9 * The buffer module from node.js, for the browser.
11 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
14 function compare(a
, b
) {
22 for (var i
= 0, len
= Math
.min(x
, y
); i
< len
; ++i
) {
38 function isBuffer(b
) {
39 if (global
.Buffer
&& typeof global
.Buffer
.isBuffer
=== 'function') {
40 return global
.Buffer
.isBuffer(b
);
42 return !!(b
!= null && b
._isBuffer
);
45 // based on node assert, original notice:
47 // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
49 // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
51 // Originally from narwhal.js (http://narwhaljs.org)
52 // Copyright (c) 2009 Thomas Robinson <280north.com>
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:
61 // The above copyright notice and this permission notice shall be included in
62 // all copies or substantial portions of the Software.
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.
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';
77 function pToString (obj
) {
78 return Object
.prototype.toString
.call(obj
);
80 function isView(arrbuf
) {
81 if (isBuffer(arrbuf
)) {
84 if (typeof global
.ArrayBuffer
!== 'function') {
87 if (typeof ArrayBuffer
.isView
=== 'function') {
88 return ArrayBuffer
.isView(arrbuf
);
93 if (arrbuf
instanceof DataView
) {
96 if (arrbuf
.buffer
&& arrbuf
.buffer
instanceof ArrayBuffer
) {
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.
105 var assert
= module
.exports
= ok
;
107 // 2. The AssertionError is defined in assert.
108 // new assert.AssertionError({ message: message,
110 // expected: expected })
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
)) {
118 if (functionsHaveNames
) {
121 var str
= func
.toString();
122 var match
= str
.match(regex
);
123 return match
&& match
[1];
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;
134 this.message
= getMessage(this);
135 this.generatedMessage
= true;
137 var stackStartFunction
= options
.stackStartFunction
|| fail
;
138 if (Error
.captureStackTrace
) {
139 Error
.captureStackTrace(this, stackStartFunction
);
141 // non v8 browsers so we can have a stacktrace
142 var err
= new Error();
146 // try to strip useless frames
147 var fn_name
= getName(stackStartFunction
);
148 var idx
= out
.indexOf('\n' + fn_name
);
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);
161 // assert.AssertionError instanceof Error
162 util
.inherits(assert
.AssertionError
, Error
);
164 function truncate(s
, n
) {
165 if (typeof s
=== 'string') {
166 return s
.length
< n
? s : s
.slice(0, n
);
171 function inspect(something
) {
172 if (functionsHaveNames
|| !util
.isFunction(something
)) {
173 return util
.inspect(something
);
175 var rawname
= getName(something
);
176 var name
= rawname
? ': ' + rawname : '';
177 return '[Function' + name
+ ']';
179 function getMessage(self
) {
180 return truncate(inspect(self
.actual
), 128) + ' ' +
181 self
.operator
+ ' ' +
182 truncate(inspect(self
.expected
), 128);
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
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
196 function fail(actual
, expected
, message
, operator
, stackStartFunction
) {
197 throw new assert
.AssertionError({
202 stackStartFunction: stackStartFunction
206 // EXTENSION! allows for well behaved errors defined elsewhere.
209 // 4. Pure assertion tests whether a value is truthy, as determined
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);.
216 function ok(value
, message
) {
217 if (!value
) fail(value
, true, message
, '==', assert
.ok
);
221 // 5. The equality assertion tests shallow, coercive equality with
223 // assert.equal(actual, expected, message_opt);
225 assert
.equal
= function equal(actual
, expected
, message
) {
226 if (actual
!= expected
) fail(actual
, expected
, message
, '==', assert
.equal
);
229 // 6. The non-equality assertion tests for whether two objects are not equal
230 // with != assert.notEqual(actual, expected, message_opt);
232 assert
.notEqual
= function notEqual(actual
, expected
, message
) {
233 if (actual
== expected
) {
234 fail(actual
, expected
, message
, '!=', assert
.notEqual
);
238 // 7. The equivalence assertion tests a deep equality relation.
239 // assert.deepEqual(actual, expected, message_opt);
241 assert
.deepEqual
= function deepEqual(actual
, expected
, message
) {
242 if (!_deepEqual(actual
, expected
, false)) {
243 fail(actual
, expected
, message
, 'deepEqual', assert
.deepEqual
);
247 assert
.deepStrictEqual
= function deepStrictEqual(actual
, expected
, message
) {
248 if (!_deepEqual(actual
, expected
, true)) {
249 fail(actual
, expected
, message
, 'deepStrictEqual', assert
.deepStrictEqual
);
253 function _deepEqual(actual
, expected
, strict
, memos
) {
254 // 7.1. All identical values are equivalent, as determined by ===.
255 if (actual
=== expected
) {
257 } else if (isBuffer(actual
) && isBuffer(expected
)) {
258 return compare(actual
, expected
) === 0;
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();
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
;
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
;
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;
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
)) {
303 memos
= memos
|| {actual: [], expected: []};
305 var actualIndex
= memos
.actual
.indexOf(actual
);
306 if (actualIndex
!== -1) {
307 if (actualIndex
=== memos
.expected
.indexOf(expected
)) {
312 memos
.actual
.push(actual
);
313 memos
.expected
.push(expected
);
315 return objEquiv(actual
, expected
, strict
, memos
);
319 function isArguments(object
) {
320 return Object
.prototype.toString
.call(object
) == '[object Arguments]';
323 function objEquiv(a
, b
, strict
, actualVisitedObjects
) {
324 if (a
=== null || a
=== undefined || b
=== null || b
=== undefined)
326 // if one is a primitive, the other must be same
327 if (util
.isPrimitive(a
) || util
.isPrimitive(b
))
329 if (strict
&& Object
.getPrototypeOf(a
) !== Object
.getPrototypeOf(b
))
331 var aIsArgs
= isArguments(a
);
332 var bIsArgs
= isArguments(b
);
333 if ((aIsArgs
&& !bIsArgs
) || (!aIsArgs
&& bIsArgs
))
338 return _deepEqual(a
, b
, strict
);
340 var ka
= objectKeys(a
);
341 var kb
= objectKeys(b
);
343 // having the same number of owned properties (keys incorporates
345 if (ka
.length
!== kb
.length
)
347 //the same set of keys (although not necessarily the same order),
351 for (i
= ka
.length
- 1; i
>= 0; i
--) {
355 //equivalent values for every corresponding key, and
356 //~~~possibly expensive deep test
357 for (i
= ka
.length
- 1; i
>= 0; i
--) {
359 if (!_deepEqual(a
[key
], b
[key
], strict
, actualVisitedObjects
))
365 // 8. The non-equivalence assertion tests for any deep inequality.
366 // assert.notDeepEqual(actual, expected, message_opt);
368 assert
.notDeepEqual
= function notDeepEqual(actual
, expected
, message
) {
369 if (_deepEqual(actual
, expected
, false)) {
370 fail(actual
, expected
, message
, 'notDeepEqual', assert
.notDeepEqual
);
374 assert
.notDeepStrictEqual
= notDeepStrictEqual
;
375 function notDeepStrictEqual(actual
, expected
, message
) {
376 if (_deepEqual(actual
, expected
, true)) {
377 fail(actual
, expected
, message
, 'notDeepStrictEqual', notDeepStrictEqual
);
382 // 9. The strict equality assertion tests strict equality, as determined by ===.
383 // assert.strictEqual(actual, expected, message_opt);
385 assert
.strictEqual
= function strictEqual(actual
, expected
, message
) {
386 if (actual
!== expected
) {
387 fail(actual
, expected
, message
, '===', assert
.strictEqual
);
391 // 10. The strict non-equality assertion tests for strict inequality, as
392 // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
394 assert
.notStrictEqual
= function notStrictEqual(actual
, expected
, message
) {
395 if (actual
=== expected
) {
396 fail(actual
, expected
, message
, '!==', assert
.notStrictEqual
);
400 function expectedException(actual
, expected
) {
401 if (!actual
|| !expected
) {
405 if (Object
.prototype.toString
.call(expected
) == '[object RegExp]') {
406 return expected
.test(actual
);
410 if (actual
instanceof expected
) {
414 // Ignore. The instanceof check doesn't work for arrow functions.
417 if (Error
.isPrototypeOf(expected
)) {
421 return expected
.call({}, actual
) === true;
424 function _tryBlock(block
) {
434 function _throws(shouldThrow
, block
, expected
, message
) {
437 if (typeof block
!== 'function') {
438 throw new TypeError('"block" argument must be a function');
441 if (typeof expected
=== 'string') {
446 actual
= _tryBlock(block
);
448 message
= (expected
&& expected
.name
? ' (' + expected
.name
+ ').' : '.') +
449 (message
? ' ' + message : '.');
451 if (shouldThrow
&& !actual
) {
452 fail(actual
, expected
, 'Missing expected exception' + message
);
455 var userProvidedMessage
= typeof message
=== 'string';
456 var isUnwantedException
= !shouldThrow
&& util
.isError(actual
);
457 var isUnexpectedException
= !shouldThrow
&& actual
&& !expected
;
459 if ((isUnwantedException
&&
460 userProvidedMessage
&&
461 expectedException(actual
, expected
)) ||
462 isUnexpectedException
) {
463 fail(actual
, expected
, 'Got unwanted exception' + message
);
466 if ((shouldThrow
&& actual
&& expected
&&
467 !expectedException(actual
, expected
)) || (!shouldThrow
&& actual
)) {
472 // 11. Expected to throw an error:
473 // assert.throws(block, Error_opt, message_opt);
475 assert
.throws = function(block
, /*optional*/error
, /*optional*/message
) {
476 _throws(true, block
, error
, message
);
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
);
484 assert
.ifError = function(err
) { if (err
) throw err
; };
486 var objectKeys
= Object
.keys
|| function (obj
) {
488 for (var key
in obj
) {
489 if (hasOwn
.call(obj
, key
)) keys
.push(key
);
494 }).call(this,typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
495 },{"util/":33}],2:[function(require
,module
,exports
){
498 exports
.byteLength
= byteLength
499 exports
.toByteArray
= toByteArray
500 exports
.fromByteArray
= fromByteArray
504 var Arr
= typeof Uint8Array
!== 'undefined' ? Uint8Array : Array
506 var code
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
507 for (var i
= 0, len
= code
.length
; i
< len
; ++i
) {
509 revLookup
[code
.charCodeAt(i
)] = i
512 revLookup
['-'.charCodeAt(0)] = 62
513 revLookup
['_'.charCodeAt(0)] = 63
515 function placeHoldersCount (b64
) {
518 throw new Error('Invalid string. Length must be a multiple of 4')
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
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
)
534 function toByteArray (b64
) {
535 var i
, j
, l
, tmp
, placeHolders
, arr
537 placeHolders
= placeHoldersCount(b64
)
539 arr
= new Arr(len
* 3 / 4 - placeHolders
)
541 // if there are placeholders, only get up to the last complete 4 chars
542 l
= placeHolders
> 0 ? len
- 4 : len
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
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
565 function tripletToBase64 (num
) {
566 return lookup
[num
>> 18 & 0x3F] + lookup
[num
>> 12 & 0x3F] + lookup
[num
>> 6 & 0x3F] + lookup
[num
& 0x3F]
569 function encodeChunk (uint8
, start
, end
) {
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
))
576 return output
.join('')
579 function fromByteArray (uint8
) {
581 var len
= uint8
.length
582 var extraBytes
= len
% 3 // if we have 1 byte left, pad 2 bytes
585 var maxChunkLength
= 16383 // must be multiple of 3
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
)))
592 // pad the end with zeros, but make sure to not forget the extra bytes
593 if (extraBytes
=== 1) {
595 output
+= lookup
[tmp
>> 2]
596 output
+= lookup
[(tmp
<< 4) & 0x3F]
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]
608 return parts
.join('')
611 },{}],3:[function(require
,module
,exports
){
613 },{}],4:[function(require
,module
,exports
){
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
);
625 if (typeof encoding
=== 'number') {
626 throw new TypeError('encoding must not be number');
628 if (typeof size
!== 'number') {
629 throw new TypeError('size must be a number');
631 if (size
> MAX_LEN
) {
632 throw new RangeError('size is too large');
636 if (_fill
=== undefined) {
640 var buf
= new Buffer(size
);
641 if (typeof _fill
=== 'string') {
642 var fillBuf
= new Buffer(_fill
, enc
);
643 var flen
= fillBuf
.length
;
646 buf
[i
] = fillBuf
[i
% flen
];
653 exports
.allocUnsafe
= function allocUnsafe(size
) {
654 if (typeof Buffer
.allocUnsafe
=== 'function') {
655 return Buffer
.allocUnsafe(size
);
657 if (typeof size
!== 'number') {
658 throw new TypeError('size must be a number');
660 if (size
> MAX_LEN
) {
661 throw new RangeError('size is too large');
663 return new Buffer(size
);
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
);
669 if (typeof value
=== 'number') {
670 throw new TypeError('"value" argument must not be a number');
672 if (typeof value
=== 'string') {
673 return new Buffer(value
, encodingOrOffset
);
675 if (typeof ArrayBuffer
!== 'undefined' && value
instanceof ArrayBuffer
) {
676 var offset
= encodingOrOffset
;
677 if (arguments
.length
=== 1) {
678 return new Buffer(value
);
680 if (typeof offset
=== 'undefined') {
684 if (typeof len
=== 'undefined') {
685 len
= value
.byteLength
- offset
;
687 if (offset
>= value
.byteLength
) {
688 throw new RangeError('\'offset\' is out of bounds');
690 if (len
> value
.byteLength
- offset
) {
691 throw new RangeError('\'length\' is out of bounds');
693 return new Buffer(value
.slice(offset
, offset
+ len
));
695 if (Buffer
.isBuffer(value
)) {
696 var out
= new Buffer(value
.length
);
697 value
.copy(out
, 0, 0, value
.length
);
701 if (Array
.isArray(value
) || (typeof ArrayBuffer
!== 'undefined' && value
.buffer
instanceof ArrayBuffer
) || 'length' in value
) {
702 return new Buffer(value
);
704 if (value
.type
=== 'Buffer' && Array
.isArray(value
.data
)) {
705 return new Buffer(value
.data
);
709 throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
711 exports
.allocUnsafeSlow
= function allocUnsafeSlow(size
) {
712 if (typeof Buffer
.allocUnsafeSlow
=== 'function') {
713 return Buffer
.allocUnsafeSlow(size
);
715 if (typeof size
!== 'number') {
716 throw new TypeError('size must be a number');
718 if (size
>= MAX_LEN
) {
719 throw new RangeError('size is too large');
721 return new SlowBuffer(size
);
724 }).call(this,typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
725 },{"buffer":5}],5:[function(require
,module
,exports
){
727 * The buffer module from node.js, for the browser.
729 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
732 /* eslint-disable no-proto */
736 var base64
= require('base64-js')
737 var ieee754
= require('ieee754')
739 exports
.Buffer
= Buffer
740 exports
.SlowBuffer
= SlowBuffer
741 exports
.INSPECT_MAX_BYTES
= 50
743 var K_MAX_LENGTH
= 0x7fffffff
744 exports
.kMaxLength
= K_MAX_LENGTH
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)
752 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
753 * Opera 11.6+, iOS 4.2+.
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.
760 Buffer
.TYPED_ARRAY_SUPPORT
= typedArraySupport()
762 if (!Buffer
.TYPED_ARRAY_SUPPORT
&& typeof console
!== 'undefined' &&
763 typeof console
.error
=== 'function') {
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.'
770 function typedArraySupport () {
771 // Can typed array instances can be augmented?
773 var arr
= new Uint8Array(1)
774 arr
.__proto__
= {__proto__: Uint8Array
.prototype, foo: function () { return 42 }}
775 return arr
.foo() === 42
781 function createBuffer (length
) {
782 if (length
> K_MAX_LENGTH
) {
783 throw new RangeError('Invalid typed array length')
785 // Return an augmented `Uint8Array` instance
786 var buf
= new Uint8Array(length
)
787 buf
.__proto__
= Buffer
.prototype
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.
798 * The `Uint8Array` prototype remains unmodified.
801 function Buffer (arg
, encodingOrOffset
, length
) {
803 if (typeof arg
=== 'number') {
804 if (typeof encodingOrOffset
=== 'string') {
806 'If encoding is specified then the first argument must be a string'
809 return allocUnsafe(arg
)
811 return from(arg
, encodingOrOffset
, length
)
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
, {
825 Buffer
.poolSize
= 8192 // not used by this implementation
827 function from (value
, encodingOrOffset
, length
) {
828 if (typeof value
=== 'number') {
829 throw new TypeError('"value" argument must not be a number')
832 if (value
instanceof ArrayBuffer
) {
833 return fromArrayBuffer(value
, encodingOrOffset
, length
)
836 if (typeof value
=== 'string') {
837 return fromString(value
, encodingOrOffset
)
840 return fromObject(value
)
844 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
845 * if value is a number.
846 * Buffer.from(str[, encoding])
848 * Buffer.from(buffer)
849 * Buffer.from(arrayBuffer[, byteOffset[, length]])
851 Buffer
.from = function (value
, encodingOrOffset
, length
) {
852 return from(value
, encodingOrOffset
, length
)
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
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')
868 function alloc (size
, fill
, encoding
) {
871 return createBuffer(size
)
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
)
881 return createBuffer(size
)
885 * Creates a new filled Buffer instance.
886 * alloc(size[, fill[, encoding]])
888 Buffer
.alloc = function (size
, fill
, encoding
) {
889 return alloc(size
, fill
, encoding
)
892 function allocUnsafe (size
) {
894 return createBuffer(size
< 0 ? 0 : checked(size
) | 0)
898 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
900 Buffer
.allocUnsafe = function (size
) {
901 return allocUnsafe(size
)
904 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
906 Buffer
.allocUnsafeSlow = function (size
) {
907 return allocUnsafe(size
)
910 function fromString (string
, encoding
) {
911 if (typeof encoding
!== 'string' || encoding
=== '') {
915 if (!Buffer
.isEncoding(encoding
)) {
916 throw new TypeError('"encoding" must be a valid string encoding')
919 var length
= byteLength(string
, encoding
) | 0
920 var buf
= createBuffer(length
)
922 var actual
= buf
.write(string
, encoding
)
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
)
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
943 function fromArrayBuffer (array
, byteOffset
, length
) {
944 if (byteOffset
< 0 || array
.byteLength
< byteOffset
) {
945 throw new RangeError('\'offset\' is out of bounds')
948 if (array
.byteLength
< byteOffset
+ (length
|| 0)) {
949 throw new RangeError('\'length\' is out of bounds')
953 if (byteOffset
=== undefined && length
=== undefined) {
954 buf
= new Uint8Array(array
)
955 } else if (length
=== undefined) {
956 buf
= new Uint8Array(array
, byteOffset
)
958 buf
= new Uint8Array(array
, byteOffset
, length
)
961 // Return an augmented `Uint8Array` instance
962 buf
.__proto__
= Buffer
.prototype
966 function fromObject (obj
) {
967 if (Buffer
.isBuffer(obj
)) {
968 var len
= checked(obj
.length
) | 0
969 var buf
= createBuffer(len
)
971 if (buf
.length
=== 0) {
975 obj
.copy(buf
, 0, 0, len
)
980 if (isArrayBufferView(obj
) || 'length' in obj
) {
981 if (typeof obj
.length
!== 'number' || numberIsNaN(obj
.length
)) {
982 return createBuffer(0)
984 return fromArrayLike(obj
)
987 if (obj
.type
=== 'Buffer' && Array
.isArray(obj
.data
)) {
988 return fromArrayLike(obj
.data
)
992 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
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')
1005 function SlowBuffer (length
) {
1006 if (+length
!= length
) { // eslint-disable-line eqeqeq
1009 return Buffer
.alloc(+length
)
1012 Buffer
.isBuffer
= function isBuffer (b
) {
1013 return b
!= null && b
._isBuffer
=== true
1016 Buffer
.compare
= function compare (a
, b
) {
1017 if (!Buffer
.isBuffer(a
) || !Buffer
.isBuffer(b
)) {
1018 throw new TypeError('Arguments must be Buffers')
1021 if (a
=== b
) return 0
1026 for (var i
= 0, len
= Math
.min(x
, y
); i
< len
; ++i
) {
1027 if (a
[i
] !== b
[i
]) {
1034 if (x
< y
) return -1
1039 Buffer
.isEncoding
= function isEncoding (encoding
) {
1040 switch (String(encoding
).toLowerCase()) {
1058 Buffer
.concat
= function concat (list
, length
) {
1059 if (!Array
.isArray(list
)) {
1060 throw new TypeError('"list" argument must be an Array of Buffers')
1063 if (list
.length
=== 0) {
1064 return Buffer
.alloc(0)
1068 if (length
=== undefined) {
1070 for (i
= 0; i
< list
.length
; ++i
) {
1071 length
+= list
[i
].length
1075 var buffer
= Buffer
.allocUnsafe(length
)
1077 for (i
= 0; i
< list
.length
; ++i
) {
1079 if (!Buffer
.isBuffer(buf
)) {
1080 throw new TypeError('"list" argument must be an Array of Buffers')
1082 buf
.copy(buffer
, pos
)
1088 function byteLength (string
, encoding
) {
1089 if (Buffer
.isBuffer(string
)) {
1090 return string
.length
1092 if (isArrayBufferView(string
) || string
instanceof ArrayBuffer
) {
1093 return string
.byteLength
1095 if (typeof string
!== 'string') {
1096 string
= '' + string
1099 var len
= string
.length
1100 if (len
=== 0) return 0
1102 // Use a for loop to avoid recursion
1103 var loweredCase
= false
1113 return utf8ToBytes(string
).length
1122 return base64ToBytes(string
).length
1124 if (loweredCase
) return utf8ToBytes(string
).length
// assume utf8
1125 encoding
= ('' + encoding
).toLowerCase()
1130 Buffer
.byteLength
= byteLength
1132 function slowToString (encoding
, start
, end
) {
1133 var loweredCase
= false
1135 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
1136 // property of a typed array.
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) {
1145 // Return early if start > this.length. Done here to prevent potential uint32
1146 // coercion fail below.
1147 if (start
> this.length
) {
1151 if (end
=== undefined || end
> this.length
) {
1159 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
1167 if (!encoding
) encoding
= 'utf8'
1172 return hexSlice(this, start
, end
)
1176 return utf8Slice(this, start
, end
)
1179 return asciiSlice(this, start
, end
)
1183 return latin1Slice(this, start
, end
)
1186 return base64Slice(this, start
, end
)
1192 return utf16leSlice(this, start
, end
)
1195 if (loweredCase
) throw new TypeError('Unknown encoding: ' + encoding
)
1196 encoding
= (encoding
+ '').toLowerCase()
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
1210 function swap (b
, n
, m
) {
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')
1221 for (var i
= 0; i
< len
; i
+= 2) {
1222 swap(this, i
, i
+ 1)
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')
1232 for (var i
= 0; i
< len
; i
+= 4) {
1233 swap(this, i
, i
+ 3)
1234 swap(this, i
+ 1, i
+ 2)
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')
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)
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
)
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
1266 Buffer
.prototype.inspect
= function inspect () {
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
+= ' ... '
1273 return '<Buffer ' + str
+ '>'
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')
1281 if (start
=== undefined) {
1284 if (end
=== undefined) {
1285 end
= target
? target
.length : 0
1287 if (thisStart
=== undefined) {
1290 if (thisEnd
=== undefined) {
1291 thisEnd
= this.length
1294 if (start
< 0 || end
> target
.length
|| thisStart
< 0 || thisEnd
> this.length
) {
1295 throw new RangeError('out of range index')
1298 if (thisStart
>= thisEnd
&& start
>= end
) {
1301 if (thisStart
>= thisEnd
) {
1313 if (this === target
) return 0
1315 var x
= thisEnd
- thisStart
1317 var len
= Math
.min(x
, y
)
1319 var thisCopy
= this.slice(thisStart
, thisEnd
)
1320 var targetCopy
= target
.slice(start
, end
)
1322 for (var i
= 0; i
< len
; ++i
) {
1323 if (thisCopy
[i
] !== targetCopy
[i
]) {
1330 if (x
< y
) return -1
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`.
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
1348 // Normalize byteOffset
1349 if (typeof byteOffset
=== 'string') {
1350 encoding
= byteOffset
1352 } else if (byteOffset
> 0x7fffffff) {
1353 byteOffset
= 0x7fffffff
1354 } else if (byteOffset
< -0x80000000) {
1355 byteOffset
= -0x80000000
1357 byteOffset
= +byteOffset
// Coerce to Number.
1358 if (numberIsNaN(byteOffset
)) {
1359 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1360 byteOffset
= dir
? 0 : (buffer
.length
- 1)
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
) {
1367 else byteOffset
= buffer
.length
- 1
1368 } else if (byteOffset
< 0) {
1369 if (dir
) byteOffset
= 0
1374 if (typeof val
=== 'string') {
1375 val
= Buffer
.from(val
, encoding
)
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) {
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') {
1389 return Uint8Array
.prototype.indexOf
.call(buffer
, val
, byteOffset
)
1391 return Uint8Array
.prototype.lastIndexOf
.call(buffer
, val
, byteOffset
)
1394 return arrayIndexOf(buffer
, [ val
], byteOffset
, encoding
, dir
)
1397 throw new TypeError('val must be string, number or Buffer')
1400 function arrayIndexOf (arr
, val
, byteOffset
, encoding
, dir
) {
1402 var arrLength
= arr
.length
1403 var valLength
= val
.length
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) {
1419 function read (buf
, i
) {
1420 if (indexSize
=== 1) {
1423 return buf
.readUInt16BE(i
* indexSize
)
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
1435 if (foundIndex
!== -1) i
-= i
- foundIndex
1440 if (byteOffset
+ valLength
> arrLength
) byteOffset
= arrLength
- valLength
1441 for (i
= byteOffset
; i
>= 0; i
--) {
1443 for (var j
= 0; j
< valLength
; j
++) {
1444 if (read(arr
, i
+ j
) !== read(val
, j
)) {
1456 Buffer
.prototype.includes
= function includes (val
, byteOffset
, encoding
) {
1457 return this.indexOf(val
, byteOffset
, encoding
) !== -1
1460 Buffer
.prototype.indexOf
= function indexOf (val
, byteOffset
, encoding
) {
1461 return bidirectionalIndexOf(this, val
, byteOffset
, encoding
, true)
1464 Buffer
.prototype.lastIndexOf
= function lastIndexOf (val
, byteOffset
, encoding
) {
1465 return bidirectionalIndexOf(this, val
, byteOffset
, encoding
, false)
1468 function hexWrite (buf
, string
, offset
, length
) {
1469 offset
= Number(offset
) || 0
1470 var remaining
= buf
.length
- offset
1474 length
= Number(length
)
1475 if (length
> remaining
) {
1480 // must be an even number of digits
1481 var strLen
= string
.length
1482 if (strLen
% 2 !== 0) throw new TypeError('Invalid hex string')
1484 if (length
> strLen
/ 2) {
1487 for (var i
= 0; i
< length
; ++i
) {
1488 var parsed
= parseInt(string
.substr(i
* 2, 2), 16)
1489 if (numberIsNaN(parsed
)) return i
1490 buf
[offset
+ i
] = parsed
1495 function utf8Write (buf
, string
, offset
, length
) {
1496 return blitBuffer(utf8ToBytes(string
, buf
.length
- offset
), buf
, offset
, length
)
1499 function asciiWrite (buf
, string
, offset
, length
) {
1500 return blitBuffer(asciiToBytes(string
), buf
, offset
, length
)
1503 function latin1Write (buf
, string
, offset
, length
) {
1504 return asciiWrite(buf
, string
, offset
, length
)
1507 function base64Write (buf
, string
, offset
, length
) {
1508 return blitBuffer(base64ToBytes(string
), buf
, offset
, length
)
1511 function ucs2Write (buf
, string
, offset
, length
) {
1512 return blitBuffer(utf16leToBytes(string
, buf
.length
- offset
), buf
, offset
, length
)
1515 Buffer
.prototype.write
= function write (string
, offset
, length
, encoding
) {
1516 // Buffer#write(string)
1517 if (offset
=== undefined) {
1519 length
= this.length
1521 // Buffer#write(string, encoding)
1522 } else if (length
=== undefined && typeof offset
=== 'string') {
1524 length
= this.length
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'
1538 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1542 var remaining
= this.length
- offset
1543 if (length
=== undefined || length
> remaining
) length
= remaining
1545 if ((string
.length
> 0 && (length
< 0 || offset
< 0)) || offset
> this.length
) {
1546 throw new RangeError('Attempt to write outside buffer bounds')
1549 if (!encoding
) encoding
= 'utf8'
1551 var loweredCase
= false
1555 return hexWrite(this, string
, offset
, length
)
1559 return utf8Write(this, string
, offset
, length
)
1562 return asciiWrite(this, string
, offset
, length
)
1566 return latin1Write(this, string
, offset
, length
)
1569 // Warning: maxLength not taken into account in base64Write
1570 return base64Write(this, string
, offset
, length
)
1576 return ucs2Write(this, string
, offset
, length
)
1579 if (loweredCase
) throw new TypeError('Unknown encoding: ' + encoding
)
1580 encoding
= ('' + encoding
).toLowerCase()
1586 Buffer
.prototype.toJSON
= function toJSON () {
1589 data: Array
.prototype.slice
.call(this._arr
|| this, 0)
1593 function base64Slice (buf
, start
, end
) {
1594 if (start
=== 0 && end
=== buf
.length
) {
1595 return base64
.fromByteArray(buf
)
1597 return base64
.fromByteArray(buf
.slice(start
, end
))
1601 function utf8Slice (buf
, start
, end
) {
1602 end
= Math
.min(buf
.length
, end
)
1607 var firstByte
= buf
[i
]
1608 var codePoint
= null
1609 var bytesPerSequence
= (firstByte
> 0xEF) ? 4
1610 : (firstByte
> 0xDF) ? 3
1611 : (firstByte
> 0xBF) ? 2
1614 if (i
+ bytesPerSequence
<= end
) {
1615 var secondByte
, thirdByte
, fourthByte
, tempCodePoint
1617 switch (bytesPerSequence
) {
1619 if (firstByte
< 0x80) {
1620 codePoint
= firstByte
1624 secondByte
= buf
[i
+ 1]
1625 if ((secondByte
& 0xC0) === 0x80) {
1626 tempCodePoint
= (firstByte
& 0x1F) << 0x6 | (secondByte
& 0x3F)
1627 if (tempCodePoint
> 0x7F) {
1628 codePoint
= tempCodePoint
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
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
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
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
1668 i
+= bytesPerSequence
1671 return decodeCodePointsArray(res
)
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
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()
1685 // Decode in chunks to avoid "call stack size exceeded".
1689 res
+= String
.fromCharCode
.apply(
1691 codePoints
.slice(i
, i
+= MAX_ARGUMENTS_LENGTH
)
1697 function asciiSlice (buf
, start
, end
) {
1699 end
= Math
.min(buf
.length
, end
)
1701 for (var i
= start
; i
< end
; ++i
) {
1702 ret
+= String
.fromCharCode(buf
[i
] & 0x7F)
1707 function latin1Slice (buf
, start
, end
) {
1709 end
= Math
.min(buf
.length
, end
)
1711 for (var i
= start
; i
< end
; ++i
) {
1712 ret
+= String
.fromCharCode(buf
[i
])
1717 function hexSlice (buf
, start
, end
) {
1718 var len
= buf
.length
1720 if (!start
|| start
< 0) start
= 0
1721 if (!end
|| end
< 0 || end
> len
) end
= len
1724 for (var i
= start
; i
< end
; ++i
) {
1725 out
+= toHex(buf
[i
])
1730 function utf16leSlice (buf
, start
, end
) {
1731 var bytes
= buf
.slice(start
, end
)
1733 for (var i
= 0; i
< bytes
.length
; i
+= 2) {
1734 res
+= String
.fromCharCode(bytes
[i
] + (bytes
[i
+ 1] * 256))
1739 Buffer
.prototype.slice
= function slice (start
, end
) {
1740 var len
= this.length
1742 end
= end
=== undefined ? len : ~~end
1746 if (start
< 0) start
= 0
1747 } else if (start
> len
) {
1753 if (end
< 0) end
= 0
1754 } else if (end
> len
) {
1758 if (end
< start
) end
= start
1760 var newBuf
= this.subarray(start
, end
)
1761 // Return an augmented `Uint8Array` instance
1762 newBuf
.__proto__
= Buffer
.prototype
1767 * Need to make sure that buffer isn't trying to write out of bounds.
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')
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
)
1779 var val
= this[offset
]
1782 while (++i
< byteLength
&& (mul
*= 0x100)) {
1783 val
+= this[offset
+ i
] * mul
1789 Buffer
.prototype.readUIntBE
= function readUIntBE (offset
, byteLength
, noAssert
) {
1790 offset
= offset
>>> 0
1791 byteLength
= byteLength
>>> 0
1793 checkOffset(offset
, byteLength
, this.length
)
1796 var val
= this[offset
+ --byteLength
]
1798 while (byteLength
> 0 && (mul
*= 0x100)) {
1799 val
+= this[offset
+ --byteLength
] * mul
1805 Buffer
.prototype.readUInt8
= function readUInt8 (offset
, noAssert
) {
1806 offset
= offset
>>> 0
1807 if (!noAssert
) checkOffset(offset
, 1, this.length
)
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)
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]
1823 Buffer
.prototype.readUInt32LE
= function readUInt32LE (offset
, noAssert
) {
1824 offset
= offset
>>> 0
1825 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1827 return ((this[offset
]) |
1828 (this[offset
+ 1] << 8) |
1829 (this[offset
+ 2] << 16)) +
1830 (this[offset
+ 3] * 0x1000000)
1833 Buffer
.prototype.readUInt32BE
= function readUInt32BE (offset
, noAssert
) {
1834 offset
= offset
>>> 0
1835 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1837 return (this[offset
] * 0x1000000) +
1838 ((this[offset
+ 1] << 16) |
1839 (this[offset
+ 2] << 8) |
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
)
1848 var val
= this[offset
]
1851 while (++i
< byteLength
&& (mul
*= 0x100)) {
1852 val
+= this[offset
+ i
] * mul
1856 if (val
>= mul
) val
-= Math
.pow(2, 8 * byteLength
)
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
)
1868 var val
= this[offset
+ --i
]
1869 while (i
> 0 && (mul
*= 0x100)) {
1870 val
+= this[offset
+ --i
] * mul
1874 if (val
>= mul
) val
-= Math
.pow(2, 8 * byteLength
)
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)
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
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
1900 Buffer
.prototype.readInt32LE
= function readInt32LE (offset
, noAssert
) {
1901 offset
= offset
>>> 0
1902 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1904 return (this[offset
]) |
1905 (this[offset
+ 1] << 8) |
1906 (this[offset
+ 2] << 16) |
1907 (this[offset
+ 3] << 24)
1910 Buffer
.prototype.readInt32BE
= function readInt32BE (offset
, noAssert
) {
1911 offset
= offset
>>> 0
1912 if (!noAssert
) checkOffset(offset
, 4, this.length
)
1914 return (this[offset
] << 24) |
1915 (this[offset
+ 1] << 16) |
1916 (this[offset
+ 2] << 8) |
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)
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)
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)
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)
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')
1950 Buffer
.prototype.writeUIntLE
= function writeUIntLE (value
, offset
, byteLength
, noAssert
) {
1952 offset
= offset
>>> 0
1953 byteLength
= byteLength
>>> 0
1955 var maxBytes
= Math
.pow(2, 8 * byteLength
) - 1
1956 checkInt(this, value
, offset
, byteLength
, maxBytes
, 0)
1961 this[offset
] = value
& 0xFF
1962 while (++i
< byteLength
&& (mul
*= 0x100)) {
1963 this[offset
+ i
] = (value
/ mul
) & 0xFF
1966 return offset
+ byteLength
1969 Buffer
.prototype.writeUIntBE
= function writeUIntBE (value
, offset
, byteLength
, noAssert
) {
1971 offset
= offset
>>> 0
1972 byteLength
= byteLength
>>> 0
1974 var maxBytes
= Math
.pow(2, 8 * byteLength
) - 1
1975 checkInt(this, value
, offset
, byteLength
, maxBytes
, 0)
1978 var i
= byteLength
- 1
1980 this[offset
+ i
] = value
& 0xFF
1981 while (--i
>= 0 && (mul
*= 0x100)) {
1982 this[offset
+ i
] = (value
/ mul
) & 0xFF
1985 return offset
+ byteLength
1988 Buffer
.prototype.writeUInt8
= function writeUInt8 (value
, offset
, noAssert
) {
1990 offset
= offset
>>> 0
1991 if (!noAssert
) checkInt(this, value
, offset
, 1, 0xff, 0)
1992 this[offset
] = (value
& 0xff)
1996 Buffer
.prototype.writeUInt16LE
= function writeUInt16LE (value
, offset
, noAssert
) {
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)
2005 Buffer
.prototype.writeUInt16BE
= function writeUInt16BE (value
, offset
, noAssert
) {
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)
2014 Buffer
.prototype.writeUInt32LE
= function writeUInt32LE (value
, offset
, noAssert
) {
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)
2025 Buffer
.prototype.writeUInt32BE
= function writeUInt32BE (value
, offset
, noAssert
) {
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)
2036 Buffer
.prototype.writeIntLE
= function writeIntLE (value
, offset
, byteLength
, noAssert
) {
2038 offset
= offset
>>> 0
2040 var limit
= Math
.pow(2, (8 * byteLength
) - 1)
2042 checkInt(this, value
, offset
, byteLength
, limit
- 1, -limit
)
2048 this[offset
] = value
& 0xFF
2049 while (++i
< byteLength
&& (mul
*= 0x100)) {
2050 if (value
< 0 && sub
=== 0 && this[offset
+ i
- 1] !== 0) {
2053 this[offset
+ i
] = ((value
/ mul
) >> 0) - sub
& 0xFF
2056 return offset
+ byteLength
2059 Buffer
.prototype.writeIntBE
= function writeIntBE (value
, offset
, byteLength
, noAssert
) {
2061 offset
= offset
>>> 0
2063 var limit
= Math
.pow(2, (8 * byteLength
) - 1)
2065 checkInt(this, value
, offset
, byteLength
, limit
- 1, -limit
)
2068 var i
= byteLength
- 1
2071 this[offset
+ i
] = value
& 0xFF
2072 while (--i
>= 0 && (mul
*= 0x100)) {
2073 if (value
< 0 && sub
=== 0 && this[offset
+ i
+ 1] !== 0) {
2076 this[offset
+ i
] = ((value
/ mul
) >> 0) - sub
& 0xFF
2079 return offset
+ byteLength
2082 Buffer
.prototype.writeInt8
= function writeInt8 (value
, offset
, noAssert
) {
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)
2091 Buffer
.prototype.writeInt16LE
= function writeInt16LE (value
, offset
, noAssert
) {
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)
2100 Buffer
.prototype.writeInt16BE
= function writeInt16BE (value
, offset
, noAssert
) {
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)
2109 Buffer
.prototype.writeInt32LE
= function writeInt32LE (value
, offset
, noAssert
) {
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)
2120 Buffer
.prototype.writeInt32BE
= function writeInt32BE (value
, offset
, noAssert
) {
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)
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')
2137 function writeFloat (buf
, value
, offset
, littleEndian
, noAssert
) {
2139 offset
= offset
>>> 0
2141 checkIEEE754(buf
, value
, offset
, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
2143 ieee754
.write(buf
, value
, offset
, littleEndian
, 23, 4)
2147 Buffer
.prototype.writeFloatLE
= function writeFloatLE (value
, offset
, noAssert
) {
2148 return writeFloat(this, value
, offset
, true, noAssert
)
2151 Buffer
.prototype.writeFloatBE
= function writeFloatBE (value
, offset
, noAssert
) {
2152 return writeFloat(this, value
, offset
, false, noAssert
)
2155 function writeDouble (buf
, value
, offset
, littleEndian
, noAssert
) {
2157 offset
= offset
>>> 0
2159 checkIEEE754(buf
, value
, offset
, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
2161 ieee754
.write(buf
, value
, offset
, littleEndian
, 52, 8)
2165 Buffer
.prototype.writeDoubleLE
= function writeDoubleLE (value
, offset
, noAssert
) {
2166 return writeDouble(this, value
, offset
, true, noAssert
)
2169 Buffer
.prototype.writeDoubleBE
= function writeDoubleBE (value
, offset
, noAssert
) {
2170 return writeDouble(this, value
, offset
, false, noAssert
)
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
2181 // Copy 0 bytes; we're done
2182 if (end
=== start
) return 0
2183 if (target
.length
=== 0 || this.length
=== 0) return 0
2185 // Fatal error conditions
2186 if (targetStart
< 0) {
2187 throw new RangeError('targetStart out of bounds')
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')
2193 if (end
> this.length
) end
= this.length
2194 if (target
.length
- targetStart
< end
- start
) {
2195 end
= target
.length
- targetStart
+ start
2198 var len
= end
- start
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
]
2206 } else if (len
< 1000) {
2207 // ascending copy from start
2208 for (i
= 0; i
< len
; ++i
) {
2209 target
[i
+ targetStart
] = this[i
+ start
]
2212 Uint8Array
.prototype.set.call(
2214 this.subarray(start
, start
+ len
),
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') {
2233 } else if (typeof end
=== 'string') {
2237 if (val
.length
=== 1) {
2238 var code
= val
.charCodeAt(0)
2243 if (encoding
!== undefined && typeof encoding
!== 'string') {
2244 throw new TypeError('encoding must be a string')
2246 if (typeof encoding
=== 'string' && !Buffer
.isEncoding(encoding
)) {
2247 throw new TypeError('Unknown encoding: ' + encoding
)
2249 } else if (typeof val
=== 'number') {
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')
2263 end
= end
=== undefined ? this.length : end
>>> 0
2268 if (typeof val
=== 'number') {
2269 for (i
= start
; i
< end
; ++i
) {
2273 var bytes
= Buffer
.isBuffer(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
]
2288 var INVALID_BASE64_RE
= /[^+/0-9A
-Za
-z
-_
]/g
2290 function base64clean (str
) {
2291 // Node strips out invalid characters like \n and \t from the string, base64-js does not
2292 str
= str
.trim().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) {
2302 function toHex (n
) {
2303 if (n
< 16) return '0' + n
.toString(16)
2304 return n
.toString(16)
2307 function utf8ToBytes (string
, units
) {
2308 units
= units
|| Infinity
2310 var length
= string
.length
2311 var leadSurrogate
= null
2314 for (var i
= 0; i
< length
; ++i
) {
2315 codePoint
= string
.charCodeAt(i
)
2317 // is surrogate component
2318 if (codePoint
> 0xD7FF && codePoint
< 0xE000) {
2319 // last char was a lead
2320 if (!leadSurrogate
) {
2322 if (codePoint
> 0xDBFF) {
2324 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
2326 } else if (i
+ 1 === length
) {
2328 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
2333 leadSurrogate
= codePoint
2339 if (codePoint
< 0xDC00) {
2340 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
2341 leadSurrogate
= codePoint
2345 // valid surrogate pair
2346 codePoint
= (leadSurrogate
- 0xD800 << 10 | codePoint
- 0xDC00) + 0x10000
2347 } else if (leadSurrogate
) {
2348 // valid bmp char, but last char was a lead
2349 if ((units
-= 3) > -1) bytes
.push(0xEF, 0xBF, 0xBD)
2352 leadSurrogate
= null
2355 if (codePoint
< 0x80) {
2356 if ((units
-= 1) < 0) break
2357 bytes
.push(codePoint
)
2358 } else if (codePoint
< 0x800) {
2359 if ((units
-= 2) < 0) break
2361 codePoint
>> 0x6 | 0xC0,
2362 codePoint
& 0x3F | 0x80
2364 } else if (codePoint
< 0x10000) {
2365 if ((units
-= 3) < 0) break
2367 codePoint
>> 0xC | 0xE0,
2368 codePoint
>> 0x6 & 0x3F | 0x80,
2369 codePoint
& 0x3F | 0x80
2371 } else if (codePoint
< 0x110000) {
2372 if ((units
-= 4) < 0) break
2374 codePoint
>> 0x12 | 0xF0,
2375 codePoint
>> 0xC & 0x3F | 0x80,
2376 codePoint
>> 0x6 & 0x3F | 0x80,
2377 codePoint
& 0x3F | 0x80
2380 throw new Error('Invalid code point')
2387 function asciiToBytes (str
) {
2389 for (var i
= 0; i
< str
.length
; ++i
) {
2390 // Node's code seems to be doing this and not & 0x7F..
2391 byteArray
.push(str
.charCodeAt(i
) & 0xFF)
2396 function utf16leToBytes (str
, units
) {
2399 for (var i
= 0; i
< str
.length
; ++i
) {
2400 if ((units
-= 2) < 0) break
2402 c
= str
.charCodeAt(i
)
2412 function base64ToBytes (str
) {
2413 return base64
.toByteArray(base64clean(str
))
2416 function blitBuffer (src
, dst
, offset
, length
) {
2417 for (var i
= 0; i
< length
; ++i
) {
2418 if ((i
+ offset
>= dst
.length
) || (i
>= src
.length
)) break
2419 dst
[i
+ offset
] = src
[i
]
2424 // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
2425 function isArrayBufferView (obj
) {
2426 return (typeof ArrayBuffer
.isView
=== 'function') && ArrayBuffer
.isView(obj
)
2429 function numberIsNaN (obj
) {
2430 return obj
!== obj
// eslint-disable-line no-self-compare
2433 },{"base64-js":2,"ieee754":8}],6:[function(require
,module
,exports
){
2435 // Copyright Joyent, Inc. and other Node contributors.
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:
2445 // The above copyright notice and this permission notice shall be included
2446 // in all copies or substantial portions of the Software.
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.
2456 // NOTE: These type checking functions intentionally don't use `instanceof`
2457 // because it is fragile and can be easily faked with `Object.create()`.
2459 function isArray(arg
) {
2460 if (Array
.isArray
) {
2461 return Array
.isArray(arg
);
2463 return objectToString(arg
) === '[object Array]';
2465 exports
.isArray
= isArray
;
2467 function isBoolean(arg
) {
2468 return typeof arg
=== 'boolean';
2470 exports
.isBoolean
= isBoolean
;
2472 function isNull(arg
) {
2473 return arg
=== null;
2475 exports
.isNull
= isNull
;
2477 function isNullOrUndefined(arg
) {
2480 exports
.isNullOrUndefined
= isNullOrUndefined
;
2482 function isNumber(arg
) {
2483 return typeof arg
=== 'number';
2485 exports
.isNumber
= isNumber
;
2487 function isString(arg
) {
2488 return typeof arg
=== 'string';
2490 exports
.isString
= isString
;
2492 function isSymbol(arg
) {
2493 return typeof arg
=== 'symbol';
2495 exports
.isSymbol
= isSymbol
;
2497 function isUndefined(arg
) {
2498 return arg
=== void 0;
2500 exports
.isUndefined
= isUndefined
;
2502 function isRegExp(re
) {
2503 return objectToString(re
) === '[object RegExp]';
2505 exports
.isRegExp
= isRegExp
;
2507 function isObject(arg
) {
2508 return typeof arg
=== 'object' && arg
!== null;
2510 exports
.isObject
= isObject
;
2512 function isDate(d
) {
2513 return objectToString(d
) === '[object Date]';
2515 exports
.isDate
= isDate
;
2517 function isError(e
) {
2518 return (objectToString(e
) === '[object Error]' || e
instanceof Error
);
2520 exports
.isError
= isError
;
2522 function isFunction(arg
) {
2523 return typeof arg
=== 'function';
2525 exports
.isFunction
= isFunction
;
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';
2535 exports
.isPrimitive
= isPrimitive
;
2537 exports
.isBuffer
= Buffer
.isBuffer
;
2539 function objectToString(o
) {
2540 return Object
.prototype.toString
.call(o
);
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.
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:
2555 // The above copyright notice and this permission notice shall be included
2556 // in all copies or substantial portions of the Software.
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.
2566 function EventEmitter() {
2567 this._events
= this._events
|| {};
2568 this._maxListeners
= this._maxListeners
|| undefined;
2570 module
.exports
= EventEmitter
;
2572 // Backwards-compat with node 0.10.x
2573 EventEmitter
.EventEmitter
= EventEmitter
;
2575 EventEmitter
.prototype._events
= undefined;
2576 EventEmitter
.prototype._maxListeners
= undefined;
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;
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
;
2591 EventEmitter
.prototype.emit = function(type
) {
2592 var er
, handler
, len
, args
, i
, listeners
;
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
)) {
2602 if (er
instanceof Error
) {
2603 throw er
; // Unhandled 'error' event
2605 // At least give some kind of context to the user
2606 var err
= new Error('Uncaught, unspecified "error" event. (' + er
+ ')');
2613 handler
= this._events
[type
];
2615 if (isUndefined(handler
))
2618 if (isFunction(handler
)) {
2619 switch (arguments
.length
) {
2625 handler
.call(this, arguments
[1]);
2628 handler
.call(this, arguments
[1], arguments
[2]);
2632 args
= Array
.prototype.slice
.call(arguments
, 1);
2633 handler
.apply(this, args
);
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
);
2646 EventEmitter
.prototype.addListener = function(type
, listener
) {
2649 if (!isFunction(listener
))
2650 throw TypeError('listener must be a function');
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
);
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
);
2669 // Adding the second element, need to change to array.
2670 this._events
[type
] = [this._events
[type
], listener
];
2672 // Check for listener leak
2673 if (isObject(this._events
[type
]) && !this._events
[type
].warned
) {
2674 if (!isUndefined(this._maxListeners
)) {
2675 m
= this._maxListeners
;
2677 m
= EventEmitter
.defaultMaxListeners
;
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
2696 EventEmitter
.prototype.on
= EventEmitter
.prototype.addListener
;
2698 EventEmitter
.prototype.once = function(type
, listener
) {
2699 if (!isFunction(listener
))
2700 throw TypeError('listener must be a function');
2705 this.removeListener(type
, g
);
2709 listener
.apply(this, arguments
);
2713 g
.listener
= listener
;
2719 // emits a 'removeListener' event iff the listener was removed
2720 EventEmitter
.prototype.removeListener = function(type
, listener
) {
2721 var list
, position
, length
, i
;
2723 if (!isFunction(listener
))
2724 throw TypeError('listener must be a function');
2726 if (!this._events
|| !this._events
[type
])
2729 list
= this._events
[type
];
2730 length
= list
.length
;
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
);
2739 } else if (isObject(list
)) {
2740 for (i
= length
; i
-- > 0;) {
2741 if (list
[i
] === listener
||
2742 (list
[i
].listener
&& list
[i
].listener
=== listener
)) {
2751 if (list
.length
=== 1) {
2753 delete this._events
[type
];
2755 list
.splice(position
, 1);
2758 if (this._events
.removeListener
)
2759 this.emit('removeListener', type
, listener
);
2765 EventEmitter
.prototype.removeAllListeners = function(type
) {
2771 // not listening for removeListener, no need to emit
2772 if (!this._events
.removeListener
) {
2773 if (arguments
.length
=== 0)
2775 else if (this._events
[type
])
2776 delete this._events
[type
];
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
);
2786 this.removeAllListeners('removeListener');
2791 listeners
= this._events
[type
];
2793 if (isFunction(listeners
)) {
2794 this.removeListener(type
, listeners
);
2795 } else if (listeners
) {
2797 while (listeners
.length
)
2798 this.removeListener(type
, listeners
[listeners
.length
- 1]);
2800 delete this._events
[type
];
2805 EventEmitter
.prototype.listeners = function(type
) {
2807 if (!this._events
|| !this._events
[type
])
2809 else if (isFunction(this._events
[type
]))
2810 ret
= [this._events
[type
]];
2812 ret
= this._events
[type
].slice();
2816 EventEmitter
.prototype.listenerCount = function(type
) {
2818 var evlistener
= this._events
[type
];
2820 if (isFunction(evlistener
))
2822 else if (evlistener
)
2823 return evlistener
.length
;
2828 EventEmitter
.listenerCount = function(emitter
, type
) {
2829 return emitter
.listenerCount(type
);
2832 function isFunction(arg
) {
2833 return typeof arg
=== 'function';
2836 function isNumber(arg
) {
2837 return typeof arg
=== 'number';
2840 function isObject(arg
) {
2841 return typeof arg
=== 'object' && arg
!== null;
2844 function isUndefined(arg
) {
2845 return arg
=== void 0;
2848 },{}],8:[function(require
,module
,exports
){
2849 exports
.read = function (buffer
, offset
, isLE
, mLen
, nBytes
) {
2851 var eLen
= nBytes
* 8 - mLen
- 1
2852 var eMax
= (1 << eLen
) - 1
2853 var eBias
= eMax
>> 1
2855 var i
= isLE
? (nBytes
- 1) : 0
2856 var d
= isLE
? -1 : 1
2857 var s
= buffer
[offset
+ i
]
2861 e
= s
& ((1 << (-nBits
)) - 1)
2864 for (; nBits
> 0; e
= e
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8) {}
2866 m
= e
& ((1 << (-nBits
)) - 1)
2869 for (; nBits
> 0; m
= m
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8) {}
2873 } else if (e
=== eMax
) {
2874 return m
? NaN : ((s
? -1 : 1) * Infinity
)
2876 m
= m
+ Math
.pow(2, mLen
)
2879 return (s
? -1 : 1) * m
* Math
.pow(2, e
- mLen
)
2882 exports
.write = function (buffer
, value
, offset
, isLE
, mLen
, nBytes
) {
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
2892 value
= Math
.abs(value
)
2894 if (isNaN(value
) || value
=== Infinity
) {
2895 m
= isNaN(value
) ? 1 : 0
2898 e
= Math
.floor(Math
.log(value
) / Math
.LN2
)
2899 if (value
* (c
= Math
.pow(2, -e
)) < 1) {
2903 if (e
+ eBias
>= 1) {
2906 value
+= rt
* Math
.pow(2, 1 - eBias
)
2908 if (value
* c
>= 2) {
2913 if (e
+ eBias
>= eMax
) {
2916 } else if (e
+ eBias
>= 1) {
2917 m
= (value
* c
- 1) * Math
.pow(2, mLen
)
2920 m
= value
* Math
.pow(2, eBias
- 1) * Math
.pow(2, mLen
)
2925 for (; mLen
>= 8; buffer
[offset
+ i
] = m
& 0xff, i
+= d
, m
/= 256, mLen
-= 8) {}
2929 for (; eLen
> 0; buffer
[offset
+ i
] = e
& 0xff, i
+= d
, e
/= 256, eLen
-= 8) {}
2931 buffer
[offset
+ i
- d
] |= s
* 128
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, {
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
2959 },{}],10:[function(require
,module
,exports
){
2961 * Determine if an object is a Buffer
2963 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
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
)
2973 function isBuffer (obj
) {
2974 return !!obj
.constructor && typeof obj
.constructor.isBuffer
=== 'function' && obj
.constructor.isBuffer(obj
)
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))
2982 },{}],11:[function(require
,module
,exports
){
2983 var toString
= {}.toString
;
2985 module
.exports
= Array
.isArray
|| function (arr
) {
2986 return toString
.call(arr
) == '[object Array]';
2989 },{}],12:[function(require
,module
,exports
){
2990 (function (process
){
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
;
2998 module
.exports
= process
.nextTick
;
3001 function nextTick(fn
, arg1
, arg2
, arg3
) {
3002 if (typeof fn
!== 'function') {
3003 throw new TypeError('"callback" argument must be a function');
3005 var len
= arguments
.length
;
3010 return process
.nextTick(fn
);
3012 return process
.nextTick(function afterTickOne() {
3013 fn
.call(null, arg1
);
3016 return process
.nextTick(function afterTickTwo() {
3017 fn
.call(null, arg1
, arg2
);
3020 return process
.nextTick(function afterTickThree() {
3021 fn
.call(null, arg1
, arg2
, arg3
);
3024 args
= new Array(len
- 1);
3026 while (i
< args
.length
) {
3027 args
[i
++] = arguments
[i
];
3029 return process
.nextTick(function afterTick() {
3030 fn
.apply(null, args
);
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
= {};
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.
3045 var cachedSetTimeout
;
3046 var cachedClearTimeout
;
3048 function defaultSetTimout() {
3049 throw new Error('setTimeout has not been defined');
3051 function defaultClearTimeout () {
3052 throw new Error('clearTimeout has not been defined');
3056 if (typeof setTimeout
=== 'function') {
3057 cachedSetTimeout
= setTimeout
;
3059 cachedSetTimeout
= defaultSetTimout
;
3062 cachedSetTimeout
= defaultSetTimout
;
3065 if (typeof clearTimeout
=== 'function') {
3066 cachedClearTimeout
= clearTimeout
;
3068 cachedClearTimeout
= defaultClearTimeout
;
3071 cachedClearTimeout
= defaultClearTimeout
;
3074 function runTimeout(fun
) {
3075 if (cachedSetTimeout
=== setTimeout
) {
3076 //normal enviroments in sane situations
3077 return setTimeout(fun
, 0);
3079 // if setTimeout wasn't available but was latter defined
3080 if ((cachedSetTimeout
=== defaultSetTimout
|| !cachedSetTimeout
) && setTimeout
) {
3081 cachedSetTimeout
= setTimeout
;
3082 return setTimeout(fun
, 0);
3085 // when when somebody has screwed with setTimeout but no I.E. maddness
3086 return cachedSetTimeout(fun
, 0);
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);
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);
3099 function runClearTimeout(marker
) {
3100 if (cachedClearTimeout
=== clearTimeout
) {
3101 //normal enviroments in sane situations
3102 return clearTimeout(marker
);
3104 // if clearTimeout wasn't available but was latter defined
3105 if ((cachedClearTimeout
=== defaultClearTimeout
|| !cachedClearTimeout
) && clearTimeout
) {
3106 cachedClearTimeout
= clearTimeout
;
3107 return clearTimeout(marker
);
3110 // when when somebody has screwed with setTimeout but no I.E. maddness
3111 return cachedClearTimeout(marker
);
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
);
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
);
3127 var draining
= false;
3129 var queueIndex
= -1;
3131 function cleanUpNextTick() {
3132 if (!draining
|| !currentQueue
) {
3136 if (currentQueue
.length
) {
3137 queue
= currentQueue
.concat(queue
);
3146 function drainQueue() {
3150 var timeout
= runTimeout(cleanUpNextTick
);
3153 var len
= queue
.length
;
3155 currentQueue
= queue
;
3157 while (++queueIndex
< len
) {
3159 currentQueue
[queueIndex
].run();
3165 currentQueue
= null;
3167 runClearTimeout(timeout
);
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
];
3177 queue
.push(new Item(fun
, args
));
3178 if (queue
.length
=== 1 && !draining
) {
3179 runTimeout(drainQueue
);
3183 // v8 likes predictible objects
3184 function Item(fun
, array
) {
3188 Item
.prototype.run = function () {
3189 this.fun
.apply(null, this.array
);
3191 process
.title
= 'browser';
3192 process
.browser
= true;
3195 process
.version
= ''; // empty string to avoid regexp issues
3196 process
.versions
= {};
3201 process
.addListener
= noop
;
3202 process
.once
= noop
;
3204 process
.removeListener
= noop
;
3205 process
.removeAllListeners
= noop
;
3206 process
.emit
= noop
;
3207 process
.prependListener
= noop
;
3208 process
.prependOnceListener
= noop
;
3210 process
.listeners = function (name
) { return [] }
3212 process
.binding = function (name
) {
3213 throw new Error('process.binding is not supported');
3216 process
.cwd = function () { return '/' };
3217 process
.chdir = function (dir
) {
3218 throw new Error('process.chdir is not supported');
3220 process
.umask = function() { return 0; };
3222 },{}],14:[function(require
,module
,exports
){
3223 module
.exports
= require('./lib/_stream_duplex.js');
3225 },{"./lib/_stream_duplex.js":15}],15:[function(require
,module
,exports
){
3226 // a duplex stream is just a stream that is both readable and writable.
3227 // Since JS doesn't have multiple prototypal inheritance, this class
3228 // prototypally inherits from Readable, and then parasitically from
3235 var objectKeys
= Object
.keys
|| function (obj
) {
3237 for (var key
in obj
) {
3243 module.exports = Duplex;
3246 var processNextTick
= require('process-nextick-args');
3250 var util
= require('core-util-is');
3251 util
.inherits
= require('inherits');
3254 var Readable = require('./_stream_readable');
3255 var Writable = require('./_stream_writable');
3257 util.inherits(Duplex, Readable);
3259 var keys = objectKeys(Writable.prototype);
3260 for (var v = 0; v < keys.length; v++) {
3261 var method = keys[v];
3262 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
3265 function Duplex(options) {
3266 if (!(this instanceof Duplex)) return new Duplex(options);
3268 Readable.call(this, options);
3269 Writable.call(this, options);
3271 if (options && options.readable === false) this.readable = false;
3273 if (options && options.writable === false) this.writable = false;
3275 this.allowHalfOpen = true;
3276 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
3278 this.once('end', onend);
3281 // the no-half-open enforcer
3283 // if we allow half-open state, or if the writable side ended,
3285 if (this.allowHalfOpen || this._writableState.ended) return;
3287 // no more data can be written.
3288 // But allow more writes to happen in this tick.
3289 processNextTick(onEndNT, this);
3292 function onEndNT(self) {
3296 function forEach(xs, f) {
3297 for (var i = 0, l = xs.length; i < l; i++) {
3301 },{"./_stream_readable":17,"./_stream_writable":19,"core-util-is":6,"inherits":9,"process-nextick-args":12}],16:[function(require,module,exports){
3302 // a passthrough stream.
3303 // basically just the most minimal sort of Transform stream.
3304 // Every written chunk gets output as-is.
3308 module.exports = PassThrough;
3310 var Transform = require('./_stream_transform');
3313 var util
= require('core-util-is');
3314 util
.inherits
= require('inherits');
3317 util.inherits(PassThrough, Transform);
3319 function PassThrough(options) {
3320 if (!(this instanceof PassThrough)) return new PassThrough(options);
3322 Transform.call(this, options);
3325 PassThrough.prototype._transform = function (chunk, encoding, cb) {
3328 },{"./_stream_transform":18,"core-util-is":6,"inherits":9}],17:[function(require,module,exports){
3329 (function (process){
3332 module.exports = Readable;
3335 var processNextTick
= require('process-nextick-args');
3339 var isArray
= require('isarray');
3346 Readable.ReadableState = ReadableState;
3349 var EE
= require('events').EventEmitter
;
3351 var EElistenerCount = function (emitter
, type
) {
3352 return emitter
.listeners(type
).length
;
3357 var Stream
= require('./internal/streams/stream');
3360 var Buffer = require('buffer').Buffer;
3362 var bufferShim
= require('buffer-shims');
3366 var util
= require('core-util-is');
3367 util
.inherits
= require('inherits');
3371 var debugUtil
= require('util');
3373 if (debugUtil
&& debugUtil
.debuglog
) {
3374 debug
= debugUtil
.debuglog('stream');
3376 debug = function () {};
3380 var BufferList = require('./internal/streams/BufferList');
3383 util.inherits(Readable, Stream);
3385 var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
3387 function prependListener(emitter, event, fn) {
3388 // Sadly this is not cacheable as some libraries bundle their own
3389 // event emitter implementation with them.
3390 if (typeof emitter.prependListener === 'function') {
3391 return emitter.prependListener(event, fn);
3393 // This is a hack to make sure that our error handler is attached before any
3394 // userland ones. NEVER DO THIS. This is here only because this code needs
3395 // to continue to work with older versions of Node.js that do not include
3396 // the prependListener() method. The goal is to eventually remove this hack.
3397 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]];
3401 function ReadableState(options, stream) {
3402 Duplex = Duplex || require('./_stream_duplex');
3404 options = options || {};
3406 // object stream flag. Used to make read(n) ignore n and to
3407 // make all the buffer merging and length checks go away
3408 this.objectMode = !!options.objectMode;
3410 if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
3412 // the point at which it stops calling _read() to fill the buffer
3413 // Note: 0 is a valid value, means "don't call _read preemptively ever"
3414 var hwm = options.highWaterMark;
3415 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
3416 this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
3419 this.highWaterMark = ~~this.highWaterMark;
3421 // A linked list is used to store data chunks instead of an array because the
3422 // linked list can remove elements from the beginning faster than
3424 this.buffer = new BufferList();
3427 this.pipesCount = 0;
3428 this.flowing = null;
3430 this.endEmitted = false;
3431 this.reading = false;
3433 // a flag to be able to tell if the onwrite cb is called immediately,
3434 // or on a later tick. We set this to true at first, because any
3435 // actions that shouldn't happen until "later" should generally also
3436 // not happen before the first write call.
3439 // whenever we return null, then we set a flag to say
3440 // that we're awaiting a 'readable' event emission.
3441 this.needReadable = false;
3442 this.emittedReadable = false;
3443 this.readableListening = false;
3444 this.resumeScheduled = false;
3446 // Crypto is kind of old and crusty. Historically, its default string
3447 // encoding is 'binary' so we have to make this configurable.
3448 // Everything else in the universe uses 'utf8', though.
3449 this.defaultEncoding = options.defaultEncoding || 'utf8';
3451 // when piping, we only care about 'readable' events that happen
3452 // after read()ing all the bytes and not getting any pushback.
3453 this.ranOut = false;
3455 // the number of writers that are awaiting a drain event in .pipe()s
3456 this.awaitDrain = 0;
3458 // if true, a maybeReadMore has been scheduled
3459 this.readingMore = false;
3461 this.decoder = null;
3462 this.encoding = null;
3463 if (options.encoding) {
3464 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
3465 this.decoder = new StringDecoder(options.encoding);
3466 this.encoding = options.encoding;
3470 function Readable(options) {
3471 Duplex = Duplex || require('./_stream_duplex');
3473 if (!(this instanceof Readable)) return new Readable(options);
3475 this._readableState = new ReadableState(options, this);
3478 this.readable = true;
3480 if (options && typeof options.read === 'function') this._read = options.read;
3485 // Manually shove something into the read() buffer.
3486 // This returns true if the highWaterMark has not been hit yet,
3487 // similar to how Writable.write() returns true if you should
3488 // write() some more.
3489 Readable.prototype.push = function (chunk, encoding) {
3490 var state = this._readableState;
3492 if (!state.objectMode && typeof chunk === 'string') {
3493 encoding = encoding || state.defaultEncoding;
3494 if (encoding !== state.encoding) {
3495 chunk = bufferShim.from(chunk, encoding);
3500 return readableAddChunk(this, state, chunk, encoding, false);
3503 // Unshift should *always* be something directly out of read()
3504 Readable.prototype.unshift = function (chunk) {
3505 var state = this._readableState;
3506 return readableAddChunk(this, state, chunk, '', true);
3509 Readable.prototype.isPaused = function () {
3510 return this._readableState.flowing === false;
3513 function readableAddChunk(stream, state, chunk, encoding, addToFront) {
3514 var er = chunkInvalid(state, chunk);
3516 stream.emit('error', er);
3517 } else if (chunk === null) {
3518 state.reading = false;
3519 onEofChunk(stream, state);
3520 } else if (state.objectMode || chunk && chunk.length > 0) {
3521 if (state.ended && !addToFront) {
3522 var e = new Error('stream.push() after EOF');
3523 stream.emit('error', e);
3524 } else if (state.endEmitted && addToFront) {
3525 var _e = new Error('stream.unshift() after end event');
3526 stream.emit('error', _e);
3529 if (state.decoder && !addToFront && !encoding) {
3530 chunk = state.decoder.write(chunk);
3531 skipAdd = !state.objectMode && chunk.length === 0;
3534 if (!addToFront) state.reading = false;
3536 // Don't add to the buffer if we've decoded to an empty string chunk and
3537 // we're not in object mode
3539 // if we want the data now, just emit it.
3540 if (state.flowing && state.length === 0 && !state.sync) {
3541 stream.emit('data', chunk);
3544 // update the buffer info.
3545 state.length += state.objectMode ? 1 : chunk.length;
3546 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
3548 if (state.needReadable) emitReadable(stream);
3552 maybeReadMore(stream, state);
3554 } else if (!addToFront) {
3555 state.reading = false;
3558 return needMoreData(state);
3561 // if it's past the high water mark, we can push in some more.
3562 // Also, if we have no data yet, we can stand some
3563 // more bytes. This is to work around cases where hwm=0,
3564 // such as the repl. Also, if the push() triggered a
3565 // readable event, and the user called read(largeNumber) such that
3566 // needReadable was set, then we ought to push more, so that another
3567 // 'readable' event will be triggered.
3568 function needMoreData(state) {
3569 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
3572 // backwards compatibility.
3573 Readable.prototype.setEncoding = function (enc) {
3574 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
3575 this._readableState.decoder = new StringDecoder(enc);
3576 this._readableState.encoding = enc;
3580 // Don't raise the hwm > 8MB
3581 var MAX_HWM = 0x800000;
3582 function computeNewHighWaterMark(n) {
3586 // Get the next highest power of 2 to prevent increasing hwm excessively in
3599 // This function is designed to be inlinable, so please take care when making
3600 // changes to the function body.
3601 function howMuchToRead(n, state) {
3602 if (n <= 0 || state.length === 0 && state.ended) return 0;
3603 if (state.objectMode) return 1;
3605 // Only flow one buffer at a time
3606 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
3608 // If we're asking for more than the current hwm, then raise the hwm.
3609 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
3610 if (n <= state.length) return n;
3611 // Don't have enough
3613 state.needReadable = true;
3616 return state.length;
3619 // you can override either this method, or the async _read(n) below.
3620 Readable.prototype.read = function (n) {
3622 n = parseInt(n, 10);
3623 var state = this._readableState;
3626 if (n !== 0) state.emittedReadable = false;
3628 // if we're doing read(0) to trigger a readable event, but we
3629 // already have a bunch of data in the buffer, then just trigger
3630 // the 'readable' event and move on.
3631 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
3632 debug('read: emitReadable', state.length, state.ended);
3633 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
3637 n = howMuchToRead(n, state);
3639 // if we've ended, and we're now clear, then finish it up.
3640 if (n === 0 && state.ended) {
3641 if (state.length === 0) endReadable(this);
3645 // All the actual chunk generation logic needs to be
3646 // *below* the call to _read. The reason is that in certain
3647 // synthetic stream cases, such as passthrough streams, _read
3648 // may be a completely synchronous operation which may change
3649 // the state of the read buffer, providing enough data when
3650 // before there was *not* enough.
3652 // So, the steps are:
3653 // 1. Figure out what the state of things will be after we do
3654 // a read from the buffer.
3656 // 2. If that resulting state will trigger a _read, then call _read.
3657 // Note that this may be asynchronous, or synchronous. Yes, it is
3658 // deeply ugly to write APIs this way, but that still doesn't mean
3659 // that the Readable class should behave improperly, as streams are
3660 // designed to be sync/async agnostic.
3661 // Take note if the _read call is sync or async (ie, if the read call
3662 // has returned yet), so that we know whether or not it's safe to emit
3665 // 3. Actually pull the requested chunks out of the buffer and return.
3667 // if we need a readable event, then we need to do some reading.
3668 var doRead = state.needReadable;
3669 debug('need readable', doRead);
3671 // if we currently have less than the highWaterMark, then also read some
3672 if (state.length === 0 || state.length - n < state.highWaterMark) {
3674 debug('length less than watermark', doRead);
3677 // however, if we've ended, then there's no point, and if we're already
3678 // reading, then it's unnecessary.
3679 if (state.ended || state.reading) {
3681 debug('reading or ended', doRead);
3682 } else if (doRead) {
3684 state.reading = true;
3686 // if the length is currently zero, then we *need* a readable event.
3687 if (state.length === 0) state.needReadable = true;
3688 // call internal read method
3689 this._read(state.highWaterMark);
3691 // If _read pushed data synchronously, then `reading` will be false,
3692 // and we need to re-evaluate how much data we can return to the user.
3693 if (!state.reading) n = howMuchToRead(nOrig, state);
3697 if (n > 0) ret = fromList(n, state);else ret = null;
3700 state.needReadable = true;
3706 if (state.length === 0) {
3707 // If we have nothing in the buffer, then we want to know
3708 // as soon as we *do* get something into the buffer.
3709 if (!state.ended) state.needReadable = true;
3711 // If we tried to read() past the EOF, then emit end on the next tick.
3712 if (nOrig !== n && state.ended) endReadable(this);
3715 if (ret !== null) this.emit('data', ret);
3720 function chunkInvalid(state, chunk) {
3722 if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
3723 er = new TypeError('Invalid non-string/buffer chunk');
3728 function onEofChunk(stream, state) {
3729 if (state.ended) return;
3730 if (state.decoder) {
3731 var chunk = state.decoder.end();
3732 if (chunk && chunk.length) {
3733 state.buffer.push(chunk);
3734 state.length += state.objectMode ? 1 : chunk.length;
3739 // emit 'readable' now to make sure it gets picked up.
3740 emitReadable(stream);
3743 // Don't emit readable right away in sync mode, because this can trigger
3744 // another read() call => stack overflow. This way, it might trigger
3745 // a nextTick recursion warning, but that's not so bad.
3746 function emitReadable(stream) {
3747 var state = stream._readableState;
3748 state.needReadable = false;
3749 if (!state.emittedReadable) {
3750 debug('emitReadable', state.flowing);
3751 state.emittedReadable = true;
3752 if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream);
3756 function emitReadable_(stream) {
3757 debug('emit readable');
3758 stream.emit('readable');
3762 // at this point, the user has presumably seen the 'readable' event,
3763 // and called read() to consume some data. that may have triggered
3764 // in turn another _read(n) call, in which case reading = true if
3765 // it's in progress.
3766 // However, if we're not ended, or reading, and the length < hwm,
3767 // then go ahead and try to read some more preemptively.
3768 function maybeReadMore(stream, state) {
3769 if (!state.readingMore) {
3770 state.readingMore = true;
3771 processNextTick(maybeReadMore_, stream, state);
3775 function maybeReadMore_(stream, state) {
3776 var len = state.length;
3777 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
3778 debug('maybeReadMore read 0');
3780 if (len === state.length)
3781 // didn't get any data, stop spinning.
3782 break;else len = state.length;
3784 state.readingMore = false;
3787 // abstract method. to be overridden in specific implementation classes.
3788 // call cb(er, data) where data is <= n in length.
3789 // for virtual (non-string, non-buffer) streams, "length" is somewhat
3790 // arbitrary, and perhaps not very meaningful.
3791 Readable.prototype._read = function (n) {
3792 this.emit('error', new Error('_read() is not implemented'));
3795 Readable.prototype.pipe = function (dest, pipeOpts) {
3797 var state = this._readableState;
3799 switch (state.pipesCount) {
3804 state.pipes = [state.pipes, dest];
3807 state.pipes.push(dest);
3810 state.pipesCount += 1;
3811 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
3813 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
3815 var endFn = doEnd ? onend : cleanup;
3816 if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
3818 dest.on('unpipe', onunpipe);
3819 function onunpipe(readable) {
3821 if (readable === src) {
3831 // when the dest drains, it reduces the awaitDrain counter
3832 // on the source. This would be more elegant with a .once()
3833 // handler in flow(), but adding and removing repeatedly is
3835 var ondrain = pipeOnDrain(src);
3836 dest.on('drain', ondrain);
3838 var cleanedUp = false;
3839 function cleanup() {
3841 // cleanup event handlers once the pipe is broken
3842 dest.removeListener('close', onclose);
3843 dest.removeListener('finish', onfinish);
3844 dest.removeListener('drain', ondrain);
3845 dest.removeListener('error', onerror);
3846 dest.removeListener('unpipe', onunpipe);
3847 src.removeListener('end', onend);
3848 src.removeListener('end', cleanup);
3849 src.removeListener('data', ondata);
3853 // if the reader is waiting for a drain event from this
3854 // specific writer, then it would cause it to never start
3856 // So, if this is awaiting a drain, then we just call it now.
3857 // If we don't know, then assume that we are waiting for one.
3858 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
3861 // If the user pushes more data while we're writing to dest then we'll end up
3862 // in ondata again. However, we only want to increase awaitDrain once because
3863 // dest will only emit one 'drain' event for the multiple writes.
3864 // => Introduce a guard on increasing awaitDrain.
3865 var increasedAwaitDrain = false;
3866 src.on('data', ondata);
3867 function ondata(chunk) {
3869 increasedAwaitDrain = false;
3870 var ret = dest.write(chunk);
3871 if (false === ret && !increasedAwaitDrain) {
3872 // If the user unpiped during `dest.write()`, it is possible
3873 // to get stuck in a permanently paused state if that write
3874 // also returned false.
3875 // => Check whether `dest` is still a piping destination.
3876 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
3877 debug('false write response, pause', src._readableState.awaitDrain);
3878 src._readableState.awaitDrain++;
3879 increasedAwaitDrain = true;
3885 // if the dest has an error, then stop piping into it.
3886 // however, don't suppress the throwing behavior for this.
3887 function onerror(er) {
3888 debug('onerror', er);
3890 dest.removeListener('error', onerror);
3891 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
3894 // Make sure our error handler is attached before userland ones.
3895 prependListener(dest, 'error', onerror);
3897 // Both close and finish should trigger unpipe, but only once.
3898 function onclose() {
3899 dest.removeListener('finish', onfinish);
3902 dest.once('close', onclose);
3903 function onfinish() {
3905 dest.removeListener('close', onclose);
3908 dest.once('finish', onfinish);
3915 // tell the dest that it's being piped to
3916 dest.emit('pipe', src);
3918 // start the flow if it hasn't been started already.
3919 if (!state.flowing) {
3920 debug('pipe resume');
3927 function pipeOnDrain(src) {
3928 return function () {
3929 var state = src._readableState;
3930 debug('pipeOnDrain', state.awaitDrain);
3931 if (state.awaitDrain) state.awaitDrain--;
3932 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
3933 state.flowing = true;
3939 Readable.prototype.unpipe = function (dest) {
3940 var state = this._readableState;
3942 // if we're not piping anywhere, then do nothing.
3943 if (state.pipesCount === 0) return this;
3945 // just one destination. most common case.
3946 if (state.pipesCount === 1) {
3947 // passed in one, but it's not the right one.
3948 if (dest && dest !== state.pipes) return this;
3950 if (!dest) dest = state.pipes;
3954 state.pipesCount = 0;
3955 state.flowing = false;
3956 if (dest) dest.emit('unpipe', this);
3960 // slow case. multiple pipe destinations.
3964 var dests = state.pipes;
3965 var len = state.pipesCount;
3967 state.pipesCount = 0;
3968 state.flowing = false;
3970 for (var i = 0; i < len; i++) {
3971 dests[i].emit('unpipe', this);
3975 // try to find the right one.
3976 var index = indexOf(state.pipes, dest);
3977 if (index === -1) return this;
3979 state.pipes.splice(index, 1);
3980 state.pipesCount -= 1;
3981 if (state.pipesCount === 1) state.pipes = state.pipes[0];
3983 dest.emit('unpipe', this);
3988 // set up data events if they are asked for
3989 // Ensure readable listeners eventually get something
3990 Readable.prototype.on = function (ev, fn) {
3991 var res = Stream.prototype.on.call(this, ev, fn);
3993 if (ev === 'data') {
3994 // Start flowing on next tick if stream isn't explicitly paused
3995 if (this._readableState.flowing !== false) this.resume();
3996 } else if (ev === 'readable') {
3997 var state = this._readableState;
3998 if (!state.endEmitted && !state.readableListening) {
3999 state.readableListening = state.needReadable = true;
4000 state.emittedReadable = false;
4001 if (!state.reading) {
4002 processNextTick(nReadingNextTick, this);
4003 } else if (state.length) {
4004 emitReadable(this, state);
4011 Readable.prototype.addListener = Readable.prototype.on;
4013 function nReadingNextTick(self) {
4014 debug('readable nexttick read 0');
4018 // pause() and resume() are remnants of the legacy readable stream API
4019 // If the user uses them, then switch into old mode.
4020 Readable.prototype.resume = function () {
4021 var state = this._readableState;
4022 if (!state.flowing) {
4024 state.flowing = true;
4025 resume(this, state);
4030 function resume(stream, state) {
4031 if (!state.resumeScheduled) {
4032 state.resumeScheduled = true;
4033 processNextTick(resume_, stream, state);
4037 function resume_(stream, state) {
4038 if (!state.reading) {
4039 debug('resume read 0');
4043 state.resumeScheduled = false;
4044 state.awaitDrain = 0;
4045 stream.emit('resume');
4047 if (state.flowing && !state.reading) stream.read(0);
4050 Readable.prototype.pause = function () {
4051 debug('call pause flowing=%j', this._readableState.flowing);
4052 if (false !== this._readableState.flowing) {
4054 this._readableState.flowing = false;
4060 function flow(stream) {
4061 var state = stream._readableState;
4062 debug('flow', state.flowing);
4063 while (state.flowing && stream.read() !== null) {}
4066 // wrap an old-style stream as the async data source.
4067 // This is *not* part of the readable stream interface.
4068 // It is an ugly unfortunate mess of history.
4069 Readable.prototype.wrap = function (stream) {
4070 var state = this._readableState;
4074 stream.on('end', function () {
4075 debug('wrapped end');
4076 if (state.decoder && !state.ended) {
4077 var chunk = state.decoder.end();
4078 if (chunk && chunk.length) self.push(chunk);
4084 stream.on('data', function (chunk) {
4085 debug('wrapped data');
4086 if (state.decoder) chunk = state.decoder.write(chunk);
4088 // don't skip over falsy values in objectMode
4089 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
4091 var ret = self.push(chunk);
4098 // proxy all the other methods.
4099 // important when wrapping filters and duplexes.
4100 for (var i in stream) {
4101 if (this[i] === undefined && typeof stream[i] === 'function') {
4102 this[i] = function (method) {
4103 return function () {
4104 return stream[method].apply(stream, arguments);
4110 // proxy certain important events.
4111 for (var n = 0; n < kProxyEvents.length; n++) {
4112 stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n]));
4115 // when we try to consume some more bytes, simply unpause the
4116 // underlying stream.
4117 self._read = function (n) {
4118 debug('wrapped _read', n);
4128 // exposed for testing purposes only.
4129 Readable._fromList = fromList;
4131 // Pluck off n bytes from an array of buffers.
4132 // Length is the combined lengths of all the buffers in the list.
4133 // This function is designed to be inlinable, so please take care when making
4134 // changes to the function body.
4135 function fromList(n, state) {
4137 if (state.length === 0) return null;
4140 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
4141 // read it all, truncate the list
4142 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);
4143 state.buffer.clear();
4145 // read part of list
4146 ret = fromListPartial(n, state.buffer, state.decoder);
4152 // Extracts only enough buffered data to satisfy the amount requested.
4153 // This function is designed to be inlinable, so please take care when making
4154 // changes to the function body.
4155 function fromListPartial(n, list, hasStrings) {
4157 if (n < list.head.data.length) {
4158 // slice is the same for buffers and strings
4159 ret = list.head.data.slice(0, n);
4160 list.head.data = list.head.data.slice(n);
4161 } else if (n === list.head.data.length) {
4162 // first chunk is a perfect match
4165 // result spans more than one buffer
4166 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
4171 // Copies a specified amount of characters from the list of buffered data
4173 // This function is designed to be inlinable, so please take care when making
4174 // changes to the function body.
4175 function copyFromBufferString(n, list) {
4180 while (p = p.next) {
4182 var nb = n > str.length ? str.length : n;
4183 if (nb === str.length) ret += str;else ret += str.slice(0, n);
4186 if (nb === str.length) {
4188 if (p.next) list.head = p.next;else list.head = list.tail = null;
4191 p.data = str.slice(nb);
4201 // Copies a specified amount of bytes from the list of buffered data chunks.
4202 // This function is designed to be inlinable, so please take care when making
4203 // changes to the function body.
4204 function copyFromBuffer(n, list) {
4205 var ret = bufferShim.allocUnsafe(n);
4210 while (p = p.next) {
4212 var nb = n > buf.length ? buf.length : n;
4213 buf.copy(ret, ret.length - n, 0, nb);
4216 if (nb === buf.length) {
4218 if (p.next) list.head = p.next;else list.head = list.tail = null;
4221 p.data = buf.slice(nb);
4231 function endReadable(stream) {
4232 var state = stream._readableState;
4234 // If we get here before consuming all the bytes, then that is a
4235 // bug in node. Should never happen.
4236 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
4238 if (!state.endEmitted) {
4240 processNextTick(endReadableNT, state, stream);
4244 function endReadableNT(state, stream) {
4245 // Check that we didn't get one last unshift.
4246 if (!state.endEmitted && state.length === 0) {
4247 state.endEmitted = true;
4248 stream.readable = false;
4253 function forEach(xs, f) {
4254 for (var i = 0, l = xs.length; i < l; i++) {
4259 function indexOf(xs, x) {
4260 for (var i = 0, l = xs.length; i < l; i++) {
4261 if (xs[i] === x) return i;
4265 }).call(this,require('_process'))
4266 },{"./_stream_duplex":15,"./internal/streams/BufferList":20,"./internal/streams/stream":21,"_process":13,"buffer":5,"buffer-shims":4,"core-util-is":6,"events":7,"inherits":9,"isarray":11,"process-nextick-args":12,"string_decoder/":22,"util":3}],18:[function(require,module,exports){
4267 // a transform stream is a readable/writable stream where you do
4268 // something with the data. Sometimes it's called a "filter",
4269 // but that's not a great name for it, since that implies a thing where
4270 // some bits pass through, and others are simply ignored. (That would
4271 // be a valid example of a transform, of course.)
4273 // While the output is causally related to the input, it's not a
4274 // necessarily symmetric or synchronous transformation. For example,
4275 // a zlib stream might take multiple plain-text writes(), and then
4276 // emit a single compressed chunk some time in the future.
4278 // Here's how this works:
4280 // The Transform stream has all the aspects of the readable and writable
4281 // stream classes. When you write(chunk), that calls _write(chunk,cb)
4282 // internally, and returns false if there's a lot of pending writes
4283 // buffered up. When you call read(), that calls _read(n) until
4284 // there's enough pending readable data buffered up.
4286 // In a transform stream, the written data is placed in a buffer. When
4287 // _read(n) is called, it transforms the queued up data, calling the
4288 // buffered _write cb's as it consumes chunks. If consuming a single
4289 // written chunk would result in multiple output chunks, then the first
4290 // outputted bit calls the readcb, and subsequent chunks just go into
4291 // the read buffer, and will cause it to emit 'readable' if necessary.
4293 // This way, back-pressure is actually determined by the reading side,
4294 // since _read has to be called to start processing a new chunk. However,
4295 // a pathological inflate type of transform can cause excessive buffering
4296 // here. For example, imagine a stream where every byte of input is
4297 // interpreted as an integer from 0-255, and then results in that many
4298 // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
4299 // 1kb of data being output. In this case, you could write a very small
4300 // amount of input, and end up with a very large amount of output. In
4301 // such a pathological inflating mechanism, there'd be no way to tell
4302 // the system to stop doing the transform. A single 4MB write could
4303 // cause the system to run out of memory.
4305 // However, even in such a pathological case, only a single written chunk
4306 // would be consumed, and then the rest would wait (un-transformed) until
4307 // the results of the previous transformed chunk were consumed.
4311 module.exports = Transform;
4313 var Duplex = require('./_stream_duplex');
4316 var util
= require('core-util-is');
4317 util
.inherits
= require('inherits');
4320 util.inherits(Transform, Duplex);
4322 function TransformState(stream) {
4323 this.afterTransform = function (er, data) {
4324 return afterTransform(stream, er, data);
4327 this.needTransform = false;
4328 this.transforming = false;
4329 this.writecb = null;
4330 this.writechunk = null;
4331 this.writeencoding = null;
4334 function afterTransform(stream, er, data) {
4335 var ts = stream._transformState;
4336 ts.transforming = false;
4338 var cb = ts.writecb;
4340 if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
4342 ts.writechunk = null;
4345 if (data !== null && data !== undefined) stream.push(data);
4349 var rs = stream._readableState;
4351 if (rs.needReadable || rs.length < rs.highWaterMark) {
4352 stream._read(rs.highWaterMark);
4356 function Transform(options) {
4357 if (!(this instanceof Transform)) return new Transform(options);
4359 Duplex.call(this, options);
4361 this._transformState = new TransformState(this);
4365 // start out asking for a readable event once data is transformed.
4366 this._readableState.needReadable = true;
4368 // we have implemented the _read method, and done the other things
4369 // that Readable wants before the first _read call, so unset the
4371 this._readableState.sync = false;
4374 if (typeof options.transform === 'function') this._transform = options.transform;
4376 if (typeof options.flush === 'function') this._flush = options.flush;
4379 // When the writable side finishes, then flush out anything remaining.
4380 this.once('prefinish', function () {
4381 if (typeof this._flush === 'function') this._flush(function (er, data) {
4382 done(stream, er, data);
4383 });else done(stream);
4387 Transform.prototype.push = function (chunk, encoding) {
4388 this._transformState.needTransform = false;
4389 return Duplex.prototype.push.call(this, chunk, encoding);
4392 // This is the part where you do stuff!
4393 // override this function in implementation classes.
4394 // 'chunk' is an input chunk.
4396 // Call `push(newChunk)` to pass along transformed output
4397 // to the readable side. You may call 'push' zero or more times.
4399 // Call `cb(err)` when you are done with this chunk. If you pass
4400 // an error, then that'll put the hurt on the whole operation. If you
4401 // never call cb(), then you'll never get another chunk.
4402 Transform.prototype._transform = function (chunk, encoding, cb) {
4403 throw new Error('_transform() is not implemented');
4406 Transform.prototype._write = function (chunk, encoding, cb) {
4407 var ts = this._transformState;
4409 ts.writechunk = chunk;
4410 ts.writeencoding = encoding;
4411 if (!ts.transforming) {
4412 var rs = this._readableState;
4413 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
4417 // Doesn't matter what the args are here.
4418 // _transform does all the work.
4419 // That we got here means that the readable side wants more data.
4420 Transform.prototype._read = function (n) {
4421 var ts = this._transformState;
4423 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
4424 ts.transforming = true;
4425 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4427 // mark that we need a transform, so that any data that comes in
4428 // will get processed, now that we've asked for it.
4429 ts.needTransform = true;
4433 function done(stream, er, data) {
4434 if (er) return stream.emit('error', er);
4436 if (data !== null && data !== undefined) stream.push(data);
4438 // if there's nothing in the write buffer, then that means
4439 // that nothing more will ever be provided
4440 var ws = stream._writableState;
4441 var ts = stream._transformState;
4443 if (ws.length) throw new Error('Calling transform done when ws.length != 0');
4445 if (ts.transforming) throw new Error('Calling transform done when still transforming');
4447 return stream.push(null);
4449 },{"./_stream_duplex":15,"core-util-is":6,"inherits":9}],19:[function(require,module,exports){
4450 (function (process){
4451 // A bit simpler than readable streams.
4452 // Implement an async ._write(chunk, encoding, cb), and it'll handle all
4453 // the drain event emission and buffering.
4457 module.exports = Writable;
4460 var processNextTick
= require('process-nextick-args');
4464 var asyncWrite
= !process
.browser
&& ['v0.10', 'v0.9.'].indexOf(process
.version
.slice(0, 5)) > -1 ? setImmediate : processNextTick
;
4471 Writable.WritableState = WritableState;
4474 var util
= require('core-util-is');
4475 util
.inherits
= require('inherits');
4479 var internalUtil
= {
4480 deprecate: require('util-deprecate')
4485 var Stream
= require('./internal/streams/stream');
4488 var Buffer = require('buffer').Buffer;
4490 var bufferShim
= require('buffer-shims');
4493 util.inherits(Writable, Stream);
4497 function WriteReq(chunk, encoding, cb) {
4499 this.encoding = encoding;
4504 function WritableState(options, stream) {
4505 Duplex = Duplex || require('./_stream_duplex');
4507 options = options || {};
4509 // object stream flag to indicate whether or not this stream
4510 // contains buffers or objects.
4511 this.objectMode = !!options.objectMode;
4513 if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
4515 // the point at which write() starts returning false
4516 // Note: 0 is a valid value, means that we always return false if
4517 // the entire buffer is not flushed immediately on write()
4518 var hwm = options.highWaterMark;
4519 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
4520 this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
4523 this.highWaterMark = ~~this.highWaterMark;
4525 // drain event flag.
4526 this.needDrain = false;
4527 // at the start of calling end()
4528 this.ending = false;
4529 // when end() has been called, and returned
4531 // when 'finish' is emitted
4532 this.finished = false;
4534 // should we decode strings into buffers before passing to _write?
4535 // this is here so that some node-core streams can optimize string
4536 // handling at a lower level.
4537 var noDecode = options.decodeStrings === false;
4538 this.decodeStrings = !noDecode;
4540 // Crypto is kind of old and crusty. Historically, its default string
4541 // encoding is 'binary' so we have to make this configurable.
4542 // Everything else in the universe uses 'utf8', though.
4543 this.defaultEncoding = options.defaultEncoding || 'utf8';
4545 // not an actual buffer we keep track of, but a measurement
4546 // of how much we're waiting to get pushed to some underlying
4550 // a flag to see when we're in the middle of a write.
4551 this.writing = false;
4553 // when true all writes will be buffered until .uncork() call
4556 // a flag to be able to tell if the onwrite cb is called immediately,
4557 // or on a later tick. We set this to true at first, because any
4558 // actions that shouldn't happen until "later" should generally also
4559 // not happen before the first write call.
4562 // a flag to know if we're processing previously buffered items, which
4563 // may call the _write() callback in the same tick, so that we don't
4564 // end up in an overlapped onwrite situation.
4565 this.bufferProcessing = false;
4567 // the callback that's passed to _write(chunk,cb)
4568 this.onwrite = function (er) {
4569 onwrite(stream, er);
4572 // the callback that the user supplies to write(chunk,encoding,cb)
4573 this.writecb = null;
4575 // the amount that is being written when _write is called.
4578 this.bufferedRequest = null;
4579 this.lastBufferedRequest = null;
4581 // number of pending user-supplied write callbacks
4582 // this must be 0 before 'finish' can be emitted
4585 // emit prefinish if the only thing we're waiting for is _write cbs
4586 // This is relevant for synchronous Transform streams
4587 this.prefinished = false;
4589 // True if the error was already emitted and should not be thrown again
4590 this.errorEmitted = false;
4592 // count buffered requests
4593 this.bufferedRequestCount = 0;
4595 // allocate the first CorkedRequest, there is always
4596 // one allocated and free to use, and we maintain at most two
4597 this.corkedRequestsFree = new CorkedRequest(this);
4600 WritableState.prototype.getBuffer = function getBuffer() {
4601 var current = this.bufferedRequest;
4605 current = current.next;
4612 Object.defineProperty(WritableState.prototype, 'buffer', {
4613 get: internalUtil.deprecate(function () {
4614 return this.getBuffer();
4615 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
4620 // Test _writableState for inheritance to account for Duplex streams,
4621 // whose prototype chain only points to Readable.
4622 var realHasInstance;
4623 if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
4624 realHasInstance = Function.prototype[Symbol.hasInstance];
4625 Object.defineProperty(Writable, Symbol.hasInstance, {
4626 value: function (object) {
4627 if (realHasInstance.call(this, object)) return true;
4629 return object && object._writableState instanceof WritableState;
4633 realHasInstance = function (object) {
4634 return object instanceof this;
4638 function Writable(options) {
4639 Duplex = Duplex || require('./_stream_duplex');
4641 // Writable ctor is applied to Duplexes, too.
4642 // `realHasInstance` is necessary because using plain `instanceof`
4643 // would return false, as no `_writableState` property is attached.
4645 // Trying to use the custom `instanceof` for Writable here will also break the
4646 // Node.js LazyTransform implementation, which has a non-trivial getter for
4647 // `_writableState` that would lead to infinite recursion.
4648 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
4649 return new Writable(options);
4652 this._writableState = new WritableState(options, this);
4655 this.writable = true;
4658 if (typeof options.write === 'function') this._write = options.write;
4660 if (typeof options.writev === 'function') this._writev = options.writev;
4666 // Otherwise people can pipe Writable streams, which is just wrong.
4667 Writable.prototype.pipe = function () {
4668 this.emit('error', new Error('Cannot pipe, not readable'));
4671 function writeAfterEnd(stream, cb) {
4672 var er = new Error('write after end');
4673 // TODO: defer error events consistently everywhere, not just the cb
4674 stream.emit('error', er);
4675 processNextTick(cb, er);
4678 // Checks that a user-supplied chunk is valid, especially for the particular
4679 // mode the stream is in. Currently this means that `null` is never accepted
4680 // and undefined/non-string values are only allowed in object mode.
4681 function validChunk(stream, state, chunk, cb) {
4685 if (chunk === null) {
4686 er = new TypeError('May not write null values to stream');
4687 } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
4688 er = new TypeError('Invalid non-string/buffer chunk');
4691 stream.emit('error', er);
4692 processNextTick(cb, er);
4698 Writable.prototype.write = function (chunk, encoding, cb) {
4699 var state = this._writableState;
4701 var isBuf = Buffer.isBuffer(chunk);
4703 if (typeof encoding === 'function') {
4708 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
4710 if (typeof cb !== 'function') cb = nop;
4712 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
4714 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
4720 Writable.prototype.cork = function () {
4721 var state = this._writableState;
4726 Writable.prototype.uncork = function () {
4727 var state = this._writableState;
4732 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
4736 Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
4737 // node::ParseEncoding() requires lower case.
4738 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
4739 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);
4740 this._writableState.defaultEncoding = encoding;
4744 function decodeChunk(state, chunk, encoding) {
4745 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
4746 chunk = bufferShim.from(chunk, encoding);
4751 // if we're already writing something, then just put this
4752 // in the queue, and wait our turn. Otherwise, call _write
4753 // If we return false, then we need a drain event, so set that flag.
4754 function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
4756 chunk = decodeChunk(state, chunk, encoding);
4757 if (Buffer.isBuffer(chunk)) encoding = 'buffer';
4759 var len = state.objectMode ? 1 : chunk.length;
4761 state.length += len;
4763 var ret = state.length < state.highWaterMark;
4764 // we must ensure that previous needDrain will not be reset to false.
4765 if (!ret) state.needDrain = true;
4767 if (state.writing || state.corked) {
4768 var last = state.lastBufferedRequest;
4769 state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
4771 last.next = state.lastBufferedRequest;
4773 state.bufferedRequest = state.lastBufferedRequest;
4775 state.bufferedRequestCount += 1;
4777 doWrite(stream, state, false, len, chunk, encoding, cb);
4783 function doWrite(stream, state, writev, len, chunk, encoding, cb) {
4784 state.writelen = len;
4786 state.writing = true;
4788 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
4792 function onwriteError(stream, state, sync, er, cb) {
4794 if (sync) processNextTick(cb, er);else cb(er);
4796 stream._writableState.errorEmitted = true;
4797 stream.emit('error', er);
4800 function onwriteStateUpdate(state) {
4801 state.writing = false;
4802 state.writecb = null;
4803 state.length -= state.writelen;
4807 function onwrite(stream, er) {
4808 var state = stream._writableState;
4809 var sync = state.sync;
4810 var cb = state.writecb;
4812 onwriteStateUpdate(state);
4814 if (er) onwriteError(stream, state, sync, er, cb);else {
4815 // Check if we're actually ready to finish, but don't emit yet
4816 var finished = needFinish(state);
4818 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
4819 clearBuffer(stream, state);
4824 asyncWrite(afterWrite
, stream
, state
, finished
, cb
);
4827 afterWrite(stream, state, finished, cb);
4832 function afterWrite(stream, state, finished, cb) {
4833 if (!finished) onwriteDrain(stream, state);
4836 finishMaybe(stream, state);
4839 // Must force callback to be called on nextTick, so that we don't
4840 // emit 'drain' before the write() consumer gets the 'false' return
4841 // value, and has a chance to attach a 'drain' listener.
4842 function onwriteDrain(stream, state) {
4843 if (state.length === 0 && state.needDrain) {
4844 state.needDrain = false;
4845 stream.emit('drain');
4849 // if there's something in the buffer waiting, then process it
4850 function clearBuffer(stream, state) {
4851 state.bufferProcessing = true;
4852 var entry = state.bufferedRequest;
4854 if (stream._writev && entry && entry.next) {
4855 // Fast case, write everything using _writev()
4856 var l = state.bufferedRequestCount;
4857 var buffer = new Array(l);
4858 var holder = state.corkedRequestsFree;
4859 holder.entry = entry;
4863 buffer[count] = entry;
4868 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
4870 // doWrite is almost always async, defer these to save a bit of time
4871 // as the hot path ends with doWrite
4873 state.lastBufferedRequest = null;
4875 state.corkedRequestsFree = holder.next;
4878 state.corkedRequestsFree = new CorkedRequest(state);
4881 // Slow case, write chunks one-by-one
4883 var chunk = entry.chunk;
4884 var encoding = entry.encoding;
4885 var cb = entry.callback;
4886 var len = state.objectMode ? 1 : chunk.length;
4888 doWrite(stream, state, false, len, chunk, encoding, cb);
4890 // if we didn't call the onwrite immediately, then
4891 // it means that we need to wait until it does.
4892 // also, that means that the chunk and cb are currently
4893 // being processed, so move the buffer counter past them.
4894 if (state.writing) {
4899 if (entry === null) state.lastBufferedRequest = null;
4902 state.bufferedRequestCount = 0;
4903 state.bufferedRequest = entry;
4904 state.bufferProcessing = false;
4907 Writable.prototype._write = function (chunk, encoding, cb) {
4908 cb(new Error('_write() is not implemented'));
4911 Writable.prototype._writev = null;
4913 Writable.prototype.end = function (chunk, encoding, cb) {
4914 var state = this._writableState;
4916 if (typeof chunk === 'function') {
4920 } else if (typeof encoding === 'function') {
4925 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
4927 // .end() fully uncorks
4933 // ignore unnecessary end() calls.
4934 if (!state.ending && !state.finished) endWritable(this, state, cb);
4937 function needFinish(state) {
4938 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
4941 function prefinish(stream, state) {
4942 if (!state.prefinished) {
4943 state.prefinished = true;
4944 stream.emit('prefinish');
4948 function finishMaybe(stream, state) {
4949 var need = needFinish(state);
4951 if (state.pendingcb === 0) {
4952 prefinish(stream, state);
4953 state.finished = true;
4954 stream.emit('finish');
4956 prefinish(stream, state);
4962 function endWritable(stream, state, cb) {
4963 state.ending = true;
4964 finishMaybe(stream, state);
4966 if (state.finished) processNextTick(cb);else stream.once('finish', cb);
4969 stream.writable = false;
4972 // It seems a linked list but it is not
4973 // there will be only 2 of these for each stream
4974 function CorkedRequest(state) {
4979 this.finish = function (err) {
4980 var entry = _this.entry;
4983 var cb = entry.callback;
4988 if (state.corkedRequestsFree) {
4989 state.corkedRequestsFree.next = _this;
4991 state.corkedRequestsFree = _this;
4995 }).call(this,require('_process'))
4996 },{"./_stream_duplex":15,"./internal/streams/stream":21,"_process":13,"buffer":5,"buffer-shims":4,"core-util-is":6,"inherits":9,"process-nextick-args":12,"util-deprecate":30}],20:[function(require,module,exports){
4999 var Buffer = require('buffer').Buffer;
5001 var bufferShim
= require('buffer-shims');
5004 module.exports = BufferList;
5006 function BufferList() {
5012 BufferList.prototype.push = function (v) {
5013 var entry = { data: v, next: null };
5014 if (this.length > 0) this.tail.next = entry;else this.head = entry;
5019 BufferList.prototype.unshift = function (v) {
5020 var entry = { data: v, next: this.head };
5021 if (this.length === 0) this.tail = entry;
5026 BufferList.prototype.shift = function () {
5027 if (this.length === 0) return;
5028 var ret = this.head.data;
5029 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
5034 BufferList.prototype.clear = function () {
5035 this.head = this.tail = null;
5039 BufferList.prototype.join = function (s) {
5040 if (this.length === 0) return '';
5042 var ret = '' + p.data;
5043 while (p = p.next) {
5048 BufferList.prototype.concat = function (n) {
5049 if (this.length === 0) return bufferShim.alloc(0);
5050 if (this.length === 1) return this.head.data;
5051 var ret = bufferShim.allocUnsafe(n >>> 0);
5055 p.data.copy(ret, i);
5061 },{"buffer":5,"buffer-shims":4}],21:[function(require,module,exports){
5062 module.exports = require('events').EventEmitter;
5064 },{"events":7}],22:[function(require,module,exports){
5067 var Buffer = require('safe-buffer').Buffer;
5069 var isEncoding = Buffer.isEncoding || function (encoding) {
5070 encoding = '' + encoding;
5071 switch (encoding && encoding.toLowerCase()) {
5072 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':
5079 function _normalizeEncoding(enc) {
5080 if (!enc) return 'utf8';
5100 if (retried) return; // undefined
5101 enc = ('' + enc).toLowerCase();
5107 // Do not cache `Buffer.isEncoding` when checking encoding names as some
5108 // modules monkey-patch it to support additional encodings
5109 function normalizeEncoding(enc) {
5110 var nenc = _normalizeEncoding(enc);
5111 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
5115 // StringDecoder provides an interface for efficiently splitting a series of
5116 // buffers into a series of JS strings without breaking apart multi-byte
5118 exports.StringDecoder = StringDecoder;
5119 function StringDecoder(encoding) {
5120 this.encoding = normalizeEncoding(encoding);
5122 switch (this.encoding) {
5124 this.text = utf16Text;
5125 this.end = utf16End;
5129 this.fillLast = utf8FillLast;
5133 this.text = base64Text;
5134 this.end = base64End;
5138 this.write = simpleWrite;
5139 this.end = simpleEnd;
5144 this.lastChar = Buffer.allocUnsafe(nb);
5147 StringDecoder.prototype.write = function (buf) {
5148 if (buf.length === 0) return '';
5151 if (this.lastNeed) {
5152 r = this.fillLast(buf);
5153 if (r === undefined) return '';
5159 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
5163 StringDecoder.prototype.end = utf8End;
5165 // Returns only complete characters in a Buffer
5166 StringDecoder.prototype.text = utf8Text;
5168 // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
5169 StringDecoder.prototype.fillLast = function (buf) {
5170 if (this.lastNeed <= buf.length) {
5171 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
5172 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
5174 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
5175 this.lastNeed -= buf.length;
5178 // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
5179 // continuation byte.
5180 function utf8CheckByte(byte) {
5181 if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
5185 // Checks at most 3 bytes at the end of a Buffer in order to detect an
5186 // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
5187 // needed to complete the UTF-8 character (if applicable) are returned.
5188 function utf8CheckIncomplete(self, buf, i) {
5189 var j = buf.length - 1;
5190 if (j < i) return 0;
5191 var nb = utf8CheckByte(buf[j]);
5193 if (nb > 0) self.lastNeed = nb - 1;
5196 if (--j < i) return 0;
5197 nb = utf8CheckByte(buf[j]);
5199 if (nb > 0) self.lastNeed = nb - 2;
5202 if (--j < i) return 0;
5203 nb = utf8CheckByte(buf[j]);
5206 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
5213 // Validates as many continuation bytes for a multi-byte UTF-8 character as
5214 // needed or are available. If we see a non-continuation byte where we expect
5215 // one, we "replace" the validated continuation bytes we've seen so far with
5216 // UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding
5217 // behavior. The continuation byte check is included three times in the case
5218 // where all of the continuation bytes for a character exist in the same buffer.
5219 // It is also done this way as a slight performance increase instead of using a
5221 function utf8CheckExtraBytes(self, buf, p) {
5222 if ((buf[0] & 0xC0) !== 0x80) {
5224 return '\ufffd'.repeat(p);
5226 if (self.lastNeed > 1 && buf.length > 1) {
5227 if ((buf[1] & 0xC0) !== 0x80) {
5229 return '\ufffd'.repeat(p + 1);
5231 if (self.lastNeed > 2 && buf.length > 2) {
5232 if ((buf[2] & 0xC0) !== 0x80) {
5234 return '\ufffd'.repeat(p + 2);
5240 // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
5241 function utf8FillLast(buf) {
5242 var p = this.lastTotal - this.lastNeed;
5243 var r = utf8CheckExtraBytes(this, buf, p);
5244 if (r !== undefined) return r;
5245 if (this.lastNeed <= buf.length) {
5246 buf.copy(this.lastChar, p, 0, this.lastNeed);
5247 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
5249 buf.copy(this.lastChar, p, 0, buf.length);
5250 this.lastNeed -= buf.length;
5253 // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
5254 // partial character, the character's bytes are buffered until the required
5255 // number of bytes are available.
5256 function utf8Text(buf, i) {
5257 var total = utf8CheckIncomplete(this, buf, i);
5258 if (!this.lastNeed) return buf.toString('utf8', i);
5259 this.lastTotal = total;
5260 var end = buf.length - (total - this.lastNeed);
5261 buf.copy(this.lastChar, 0, end);
5262 return buf.toString('utf8', i, end);
5265 // For UTF-8, a replacement character for each buffered byte of a (partial)
5266 // character needs to be added to the output.
5267 function utf8End(buf) {
5268 var r = buf && buf.length ? this.write(buf) : '';
5269 if (this.lastNeed) return r + '\ufffd'.repeat(this.lastTotal - this.lastNeed);
5273 // UTF-16LE typically needs two bytes per character, but even if we have an even
5274 // number of bytes available, we need to check if we end on a leading/high
5275 // surrogate. In that case, we need to wait for the next two bytes in order to
5276 // decode the last character properly.
5277 function utf16Text(buf, i) {
5278 if ((buf.length - i) % 2 === 0) {
5279 var r = buf.toString('utf16le', i);
5281 var c = r.charCodeAt(r.length - 1);
5282 if (c >= 0xD800 && c <= 0xDBFF) {
5285 this.lastChar[0] = buf[buf.length - 2];
5286 this.lastChar[1] = buf[buf.length - 1];
5287 return r.slice(0, -1);
5294 this.lastChar[0] = buf[buf.length - 1];
5295 return buf.toString('utf16le', i, buf.length - 1);
5298 // For UTF-16LE we do not explicitly append special replacement characters if we
5299 // end on a partial character, we simply let v8 handle that.
5300 function utf16End(buf) {
5301 var r = buf && buf.length ? this.write(buf) : '';
5302 if (this.lastNeed) {
5303 var end = this.lastTotal - this.lastNeed;
5304 return r + this.lastChar.toString('utf16le', 0, end);
5309 function base64Text(buf, i) {
5310 var n = (buf.length - i) % 3;
5311 if (n === 0) return buf.toString('base64', i);
5312 this.lastNeed = 3 - n;
5315 this.lastChar[0] = buf[buf.length - 1];
5317 this.lastChar[0] = buf[buf.length - 2];
5318 this.lastChar[1] = buf[buf.length - 1];
5320 return buf.toString('base64', i, buf.length - n);
5323 function base64End(buf) {
5324 var r = buf && buf.length ? this.write(buf) : '';
5325 if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
5329 // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
5330 function simpleWrite(buf) {
5331 return buf.toString(this.encoding);
5334 function simpleEnd(buf) {
5335 return buf && buf.length ? this.write(buf) : '';
5337 },{"safe-buffer":27}],23:[function(require,module,exports){
5338 module.exports = require('./readable').PassThrough
5340 },{"./readable":24}],24:[function(require,module,exports){
5341 exports = module.exports = require('./lib/_stream_readable.js');
5342 exports.Stream = exports;
5343 exports.Readable = exports;
5344 exports.Writable = require('./lib/_stream_writable.js');
5345 exports.Duplex = require('./lib/_stream_duplex.js');
5346 exports.Transform = require('./lib/_stream_transform.js');
5347 exports.PassThrough = require('./lib/_stream_passthrough.js');
5349 },{"./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}],25:[function(require,module,exports){
5350 module.exports = require('./readable').Transform
5352 },{"./readable":24}],26:[function(require,module,exports){
5353 module.exports = require('./lib/_stream_writable.js');
5355 },{"./lib/_stream_writable.js":19}],27:[function(require,module,exports){
5356 module.exports = require('buffer')
5358 },{"buffer":5}],28:[function(require,module,exports){
5359 // Copyright Joyent, Inc. and other Node contributors.
5361 // Permission is hereby granted, free of charge, to any person obtaining a
5362 // copy of this software and associated documentation files (the
5363 // "Software"), to deal in the Software without restriction, including
5364 // without limitation the rights to use, copy, modify, merge, publish,
5365 // distribute, sublicense, and/or sell copies of the Software, and to permit
5366 // persons to whom the Software is furnished to do so, subject to the
5367 // following conditions:
5369 // The above copyright notice and this permission notice shall be included
5370 // in all copies or substantial portions of the Software.
5372 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5373 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5374 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5375 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5376 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5377 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5378 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5380 module.exports = Stream;
5382 var EE = require('events').EventEmitter;
5383 var inherits = require('inherits');
5385 inherits(Stream, EE);
5386 Stream.Readable = require('readable-stream/readable.js');
5387 Stream.Writable = require('readable-stream/writable.js');
5388 Stream.Duplex = require('readable-stream/duplex.js');
5389 Stream.Transform = require('readable-stream/transform.js');
5390 Stream.PassThrough = require('readable-stream/passthrough.js');
5392 // Backwards-compat with node 0.4.x
5393 Stream.Stream = Stream;
5397 // old-style streams. Note that the pipe method (the only relevant
5398 // part of this class) is overridden in the Readable class.
5404 Stream.prototype.pipe = function(dest, options) {
5407 function ondata(chunk) {
5408 if (dest.writable) {
5409 if (false === dest.write(chunk) && source.pause) {
5415 source.on('data', ondata);
5417 function ondrain() {
5418 if (source.readable && source.resume) {
5423 dest.on('drain', ondrain);
5425 // If the 'end' option is not supplied, dest.end() will be called when
5426 // source gets the 'end' or 'close' events. Only dest.end() once.
5427 if (!dest._isStdio && (!options || options.end !== false)) {
5428 source.on('end', onend);
5429 source.on('close', onclose);
5432 var didOnEnd = false;
5434 if (didOnEnd) return;
5441 function onclose() {
5442 if (didOnEnd) return;
5445 if (typeof dest.destroy === 'function') dest.destroy();
5448 // don't leave dangling pipes when there are errors.
5449 function onerror(er) {
5451 if (EE.listenerCount(this, 'error') === 0) {
5452 throw er; // Unhandled stream error in pipe.
5456 source.on('error', onerror);
5457 dest.on('error', onerror);
5459 // remove all the event listeners that were added.
5460 function cleanup() {
5461 source.removeListener('data', ondata);
5462 dest.removeListener('drain', ondrain);
5464 source.removeListener('end', onend);
5465 source.removeListener('close', onclose);
5467 source.removeListener('error', onerror);
5468 dest.removeListener('error', onerror);
5470 source.removeListener('end', cleanup);
5471 source.removeListener('close', cleanup);
5473 dest.removeListener('close', cleanup);
5476 source.on('end', cleanup);
5477 source.on('close', cleanup);
5479 dest.on('close', cleanup);
5481 dest.emit('pipe', source);
5483 // Allow for unix-like usage: A.pipe(B).pipe(C)
5487 },{"events":7,"inherits":9,"readable-stream/duplex.js":14,"readable-stream/passthrough.js":23,"readable-stream/readable.js":24,"readable-stream/transform.js":25,"readable-stream/writable.js":26}],29:[function(require,module,exports){
5488 // Copyright Joyent, Inc. and other Node contributors.
5490 // Permission is hereby granted, free of charge, to any person obtaining a
5491 // copy of this software and associated documentation files (the
5492 // "Software"), to deal in the Software without restriction, including
5493 // without limitation the rights to use, copy, modify, merge, publish,
5494 // distribute, sublicense, and/or sell copies of the Software, and to permit
5495 // persons to whom the Software is furnished to do so, subject to the
5496 // following conditions:
5498 // The above copyright notice and this permission notice shall be included
5499 // in all copies or substantial portions of the Software.
5501 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5502 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5503 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5504 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5505 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5506 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5507 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5509 var Buffer = require('buffer').Buffer;
5511 var isBufferEncoding = Buffer.isEncoding
5512 || function(encoding) {
5513 switch (encoding && encoding.toLowerCase()) {
5514 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;
5515 default: return false;
5520 function assertEncoding(encoding) {
5521 if (encoding && !isBufferEncoding(encoding)) {
5522 throw new Error('Unknown encoding: ' + encoding);
5526 // StringDecoder provides an interface for efficiently splitting a series of
5527 // buffers into a series of JS strings without breaking apart multi-byte
5528 // characters. CESU-8 is handled as part of the UTF-8 encoding.
5530 // @TODO Handling all encodings inside a single object makes it very difficult
5531 // to reason about this code, so it should be split up in the future.
5532 // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
5533 // points as used by CESU-8.
5534 var StringDecoder = exports.StringDecoder = function(encoding) {
5535 this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
5536 assertEncoding(encoding);
5537 switch (this.encoding) {
5539 // CESU-8 represents each of Surrogate Pair by 3-bytes
5540 this.surrogateSize = 3;
5544 // UTF-16 represents each of Surrogate Pair by 2-bytes
5545 this.surrogateSize = 2;
5546 this.detectIncompleteChar = utf16DetectIncompleteChar;
5549 // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
5550 this.surrogateSize = 3;
5551 this.detectIncompleteChar = base64DetectIncompleteChar;
5554 this.write = passThroughWrite;
5558 // Enough space to store all bytes of a single character. UTF-8 needs 4
5559 // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
5560 this.charBuffer = new Buffer(6);
5561 // Number of bytes received for the current incomplete multi-byte character.
5562 this.charReceived = 0;
5563 // Number of bytes expected for the current incomplete multi-byte character.
5564 this.charLength = 0;
5568 // write decodes the given buffer and returns it as JS string that is
5569 // guaranteed to not contain any partial multi-byte characters. Any partial
5570 // character found at the end of the buffer is buffered up, and will be
5571 // returned when calling write again with the remaining bytes.
5573 // Note: Converting a Buffer containing an orphan surrogate to a String
5574 // currently works, but converting a String to a Buffer (via `new Buffer`, or
5575 // Buffer#write) will replace incomplete surrogates with the unicode
5576 // replacement character. See https://codereview.chromium.org/121173009/ .
5577 StringDecoder.prototype.write = function(buffer) {
5579 // if our last write ended with an incomplete multibyte character
5580 while (this.charLength) {
5581 // determine how many remaining bytes this buffer has to offer for this char
5582 var available = (buffer.length >= this.charLength - this.charReceived) ?
5583 this.charLength - this.charReceived :
5586 // add the new bytes to the char buffer
5587 buffer.copy(this.charBuffer, this.charReceived, 0, available);
5588 this.charReceived += available;
5590 if (this.charReceived < this.charLength) {
5591 // still not enough chars in this buffer? wait for more ...
5595 // remove bytes belonging to the current character from the buffer
5596 buffer = buffer.slice(available, buffer.length);
5598 // get the character that was split
5599 charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
5601 // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
5602 var charCode = charStr.charCodeAt(charStr.length - 1);
5603 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
5604 this.charLength += this.surrogateSize;
5608 this.charReceived = this.charLength = 0;
5610 // if there are no more bytes in this buffer, just emit our char
5611 if (buffer.length === 0) {
5617 // determine and set charLength / charReceived
5618 this.detectIncompleteChar(buffer);
5620 var end = buffer.length;
5621 if (this.charLength) {
5622 // buffer the incomplete character bytes we got
5623 buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
5624 end -= this.charReceived;
5627 charStr += buffer.toString(this.encoding, 0, end);
5629 var end = charStr.length - 1;
5630 var charCode = charStr.charCodeAt(end);
5631 // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
5632 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
5633 var size = this.surrogateSize;
5634 this.charLength += size;
5635 this.charReceived += size;
5636 this.charBuffer.copy(this.charBuffer, size, 0, size);
5637 buffer.copy(this.charBuffer, 0, 0, size);
5638 return charStr.substring(0, end);
5641 // or just emit the charStr
5645 // detectIncompleteChar determines if there is an incomplete UTF-8 character at
5646 // the end of the given buffer. If so, it sets this.charLength to the byte
5647 // length that character, and sets this.charReceived to the number of bytes
5648 // that are available for this character.
5649 StringDecoder.prototype.detectIncompleteChar = function(buffer) {
5650 // determine how many bytes we have to check at the end of this buffer
5651 var i = (buffer.length >= 3) ? 3 : buffer.length;
5653 // Figure out if one of the last i bytes of our buffer announces an
5655 for (; i > 0; i--) {
5656 var c = buffer[buffer.length - i];
5658 // See http://en.wikipedia.org/wiki/UTF-8#Description
5661 if (i == 1 && c >> 5 == 0x06) {
5662 this.charLength = 2;
5667 if (i <= 2 && c >> 4 == 0x0E) {
5668 this.charLength = 3;
5673 if (i <= 3 && c >> 3 == 0x1E) {
5674 this.charLength = 4;
5678 this.charReceived = i;
5681 StringDecoder.prototype.end = function(buffer) {
5683 if (buffer && buffer.length)
5684 res = this.write(buffer);
5686 if (this.charReceived) {
5687 var cr = this.charReceived;
5688 var buf = this.charBuffer;
5689 var enc = this.encoding;
5690 res += buf.slice(0, cr).toString(enc);
5696 function passThroughWrite(buffer) {
5697 return buffer.toString(this.encoding);
5700 function utf16DetectIncompleteChar(buffer) {
5701 this.charReceived = buffer.length % 2;
5702 this.charLength = this.charReceived ? 2 : 0;
5705 function base64DetectIncompleteChar(buffer) {
5706 this.charReceived = buffer.length % 3;
5707 this.charLength = this.charReceived ? 3 : 0;
5710 },{"buffer":5}],30:[function(require,module,exports){
5717 module
.exports
= deprecate
;
5720 * Mark that a method should not be used.
5721 * Returns a modified function which warns once by default.
5723 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
5725 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
5726 * will throw an Error when invoked.
5728 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
5729 * will invoke `console.trace()` instead of `console.error()`.
5731 * @param {Function} fn - the function to deprecate
5732 * @param {String} msg - the string to print to the console when `fn` is invoked
5733 * @returns {Function} a new "deprecated" version of `fn`
5737 function deprecate (fn
, msg
) {
5738 if (config('noDeprecation')) {
5743 function deprecated() {
5745 if (config('throwDeprecation')) {
5746 throw new Error(msg
);
5747 } else if (config('traceDeprecation')) {
5754 return fn
.apply(this, arguments
);
5761 * Checks `localStorage` for boolean values for the given `name`.
5763 * @param {String} name
5764 * @returns {Boolean}
5768 function config (name
) {
5769 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
5771 if (!global
.localStorage
) return false;
5775 var val
= global
.localStorage
[name
];
5776 if (null == val
) return false;
5777 return String(val
).toLowerCase() === 'true';
5780 }).call(this,typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
5781 },{}],31:[function(require
,module
,exports
){
5782 arguments
[4][9][0].apply(exports
,arguments
)
5783 },{"dup":9}],32:[function(require
,module
,exports
){
5784 module
.exports
= function isBuffer(arg
) {
5785 return arg
&& typeof arg
=== 'object'
5786 && typeof arg
.copy
=== 'function'
5787 && typeof arg
.fill
=== 'function'
5788 && typeof arg
.readUInt8
=== 'function';
5790 },{}],33:[function(require
,module
,exports
){
5791 (function (process
,global
){
5792 // Copyright Joyent, Inc. and other Node contributors.
5794 // Permission is hereby granted, free of charge, to any person obtaining a
5795 // copy of this software and associated documentation files (the
5796 // "Software"), to deal in the Software without restriction, including
5797 // without limitation the rights to use, copy, modify, merge, publish,
5798 // distribute, sublicense, and/or sell copies of the Software, and to permit
5799 // persons to whom the Software is furnished to do so, subject to the
5800 // following conditions:
5802 // The above copyright notice and this permission notice shall be included
5803 // in all copies or substantial portions of the Software.
5805 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5806 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5807 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5808 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5809 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5810 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5811 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5813 var formatRegExp
= /%[sdj%]/g;
5814 exports
.format = function(f
) {
5817 for (var i
= 0; i
< arguments
.length
; i
++) {
5818 objects
.push(inspect(arguments
[i
]));
5820 return objects
.join(' ');
5824 var args
= arguments
;
5825 var len
= args
.length
;
5826 var str
= String(f
).replace(formatRegExp
, function(x
) {
5827 if (x
=== '%%') return '%';
5828 if (i
>= len
) return x
;
5830 case '%s': return String(args
[i
++]);
5831 case '%d': return Number(args
[i
++]);
5834 return JSON
.stringify(args
[i
++]);
5836 return '[Circular]';
5842 for (var x
= args
[i
]; i
< len
; x
= args
[++i
]) {
5843 if (isNull(x
) || !isObject(x
)) {
5846 str
+= ' ' + inspect(x
);
5853 // Mark that a method should not be used.
5854 // Returns a modified function which warns once by default.
5855 // If --no-deprecation is set, then it is a no-op.
5856 exports
.deprecate = function(fn
, msg
) {
5857 // Allow for deprecating things in the process of starting up.
5858 if (isUndefined(global
.process
)) {
5860 return exports
.deprecate(fn
, msg
).apply(this, arguments
);
5864 if (process
.noDeprecation
=== true) {
5869 function deprecated() {
5871 if (process
.throwDeprecation
) {
5872 throw new Error(msg
);
5873 } else if (process
.traceDeprecation
) {
5880 return fn
.apply(this, arguments
);
5889 exports
.debuglog = function(set) {
5890 if (isUndefined(debugEnviron
))
5891 debugEnviron
= process
.env
.NODE_DEBUG
|| '';
5892 set = set.toUpperCase();
5894 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron
)) {
5895 var pid
= process
.pid
;
5896 debugs
[set] = function() {
5897 var msg
= exports
.format
.apply(exports
, arguments
);
5898 console
.error('%s %d: %s', set, pid
, msg
);
5901 debugs
[set] = function() {};
5909 * Echos the value of a value. Trys to print the value out
5910 * in the best way possible given the different types.
5912 * @param {Object} obj The object to print out.
5913 * @param {Object} opts Optional options object that alters the output.
5915 /* legacy: obj, showHidden, depth, colors*/
5916 function inspect(obj
, opts
) {
5920 stylize: stylizeNoColor
5923 if (arguments
.length
>= 3) ctx
.depth
= arguments
[2];
5924 if (arguments
.length
>= 4) ctx
.colors
= arguments
[3];
5925 if (isBoolean(opts
)) {
5927 ctx
.showHidden
= opts
;
5929 // got an "options" object
5930 exports
._extend(ctx
, opts
);
5932 // set default options
5933 if (isUndefined(ctx
.showHidden
)) ctx
.showHidden
= false;
5934 if (isUndefined(ctx
.depth
)) ctx
.depth
= 2;
5935 if (isUndefined(ctx
.colors
)) ctx
.colors
= false;
5936 if (isUndefined(ctx
.customInspect
)) ctx
.customInspect
= true;
5937 if (ctx
.colors
) ctx
.stylize
= stylizeWithColor
;
5938 return formatValue(ctx
, obj
, ctx
.depth
);
5940 exports
.inspect
= inspect
;
5943 // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
5947 'underline' : [4, 24],
5948 'inverse' : [7, 27],
5955 'magenta' : [35, 39],
5960 // Don't use 'blue' not visible on cmd.exe
5964 'boolean': 'yellow',
5965 'undefined': 'grey',
5969 // "name": intentionally not styling
5974 function stylizeWithColor(str
, styleType
) {
5975 var style
= inspect
.styles
[styleType
];
5978 return '\u001b[' + inspect
.colors
[style
][0] + 'm' + str
+
5979 '\u001b[' + inspect
.colors
[style
][1] + 'm';
5986 function stylizeNoColor(str
, styleType
) {
5991 function arrayToHash(array
) {
5994 array
.forEach(function(val
, idx
) {
6002 function formatValue(ctx
, value
, recurseTimes
) {
6003 // Provide a hook for user-specified inspect functions.
6004 // Check that value is an object with an inspect function on it
6005 if (ctx
.customInspect
&&
6007 isFunction(value
.inspect
) &&
6008 // Filter out the util module, it's inspect function is special
6009 value
.inspect
!== exports
.inspect
&&
6010 // Also filter out any prototype objects using the circular check.
6011 !(value
.constructor && value
.constructor.prototype === value
)) {
6012 var ret
= value
.inspect(recurseTimes
, ctx
);
6013 if (!isString(ret
)) {
6014 ret
= formatValue(ctx
, ret
, recurseTimes
);
6019 // Primitive types cannot have properties
6020 var primitive
= formatPrimitive(ctx
, value
);
6025 // Look up the keys of the object.
6026 var keys
= Object
.keys(value
);
6027 var visibleKeys
= arrayToHash(keys
);
6029 if (ctx
.showHidden
) {
6030 keys
= Object
.getOwnPropertyNames(value
);
6033 // IE doesn't make error fields non-enumerable
6034 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
6036 && (keys
.indexOf('message') >= 0 || keys
.indexOf('description') >= 0)) {
6037 return formatError(value
);
6040 // Some type of object without properties can be shortcutted.
6041 if (keys
.length
=== 0) {
6042 if (isFunction(value
)) {
6043 var name
= value
.name
? ': ' + value
.name : '';
6044 return ctx
.stylize('[Function' + name
+ ']', 'special');
6046 if (isRegExp(value
)) {
6047 return ctx
.stylize(RegExp
.prototype.toString
.call(value
), 'regexp');
6049 if (isDate(value
)) {
6050 return ctx
.stylize(Date
.prototype.toString
.call(value
), 'date');
6052 if (isError(value
)) {
6053 return formatError(value
);
6057 var base
= '', array
= false, braces
= ['{', '}'];
6059 // Make Array say that they are Array
6060 if (isArray(value
)) {
6062 braces
= ['[', ']'];
6065 // Make functions say that they are functions
6066 if (isFunction(value
)) {
6067 var n
= value
.name
? ': ' + value
.name : '';
6068 base
= ' [Function' + n
+ ']';
6071 // Make RegExps say that they are RegExps
6072 if (isRegExp(value
)) {
6073 base
= ' ' + RegExp
.prototype.toString
.call(value
);
6076 // Make dates with properties first say the date
6077 if (isDate(value
)) {
6078 base
= ' ' + Date
.prototype.toUTCString
.call(value
);
6081 // Make error with message first say the error
6082 if (isError(value
)) {
6083 base
= ' ' + formatError(value
);
6086 if (keys
.length
=== 0 && (!array
|| value
.length
== 0)) {
6087 return braces
[0] + base
+ braces
[1];
6090 if (recurseTimes
< 0) {
6091 if (isRegExp(value
)) {
6092 return ctx
.stylize(RegExp
.prototype.toString
.call(value
), 'regexp');
6094 return ctx
.stylize('[Object]', 'special');
6098 ctx
.seen
.push(value
);
6102 output
= formatArray(ctx
, value
, recurseTimes
, visibleKeys
, keys
);
6104 output
= keys
.map(function(key
) {
6105 return formatProperty(ctx
, value
, recurseTimes
, visibleKeys
, key
, array
);
6111 return reduceToSingleString(output
, base
, braces
);
6115 function formatPrimitive(ctx
, value
) {
6116 if (isUndefined(value
))
6117 return ctx
.stylize('undefined', 'undefined');
6118 if (isString(value
)) {
6119 var simple
= '\'' + JSON
.stringify(value
).replace(/^"|"$/g, '')
6120 .replace(/'/g, "\\'")
6121 .replace(/\\"/g
, '"') + '\'';
6122 return ctx
.stylize(simple
, 'string');
6124 if (isNumber(value
))
6125 return ctx
.stylize('' + value
, 'number');
6126 if (isBoolean(value
))
6127 return ctx
.stylize('' + value
, 'boolean');
6128 // For some reason typeof null is "object", so special case here.
6130 return ctx
.stylize('null', 'null');
6134 function formatError(value
) {
6135 return '[' + Error
.prototype.toString
.call(value
) + ']';
6139 function formatArray(ctx
, value
, recurseTimes
, visibleKeys
, keys
) {
6141 for (var i
= 0, l
= value
.length
; i
< l
; ++i
) {
6142 if (hasOwnProperty(value
, String(i
))) {
6143 output
.push(formatProperty(ctx
, value
, recurseTimes
, visibleKeys
,
6149 keys
.forEach(function(key
) {
6150 if (!key
.match(/^\d+$/)) {
6151 output
.push(formatProperty(ctx
, value
, recurseTimes
, visibleKeys
,
6159 function formatProperty(ctx
, value
, recurseTimes
, visibleKeys
, key
, array
) {
6160 var name
, str
, desc
;
6161 desc
= Object
.getOwnPropertyDescriptor(value
, key
) || { value: value
[key
] };
6164 str
= ctx
.stylize('[Getter/Setter]', 'special');
6166 str
= ctx
.stylize('[Getter]', 'special');
6170 str
= ctx
.stylize('[Setter]', 'special');
6173 if (!hasOwnProperty(visibleKeys
, key
)) {
6174 name
= '[' + key
+ ']';
6177 if (ctx
.seen
.indexOf(desc
.value
) < 0) {
6178 if (isNull(recurseTimes
)) {
6179 str
= formatValue(ctx
, desc
.value
, null);
6181 str
= formatValue(ctx
, desc
.value
, recurseTimes
- 1);
6183 if (str
.indexOf('\n') > -1) {
6185 str
= str
.split('\n').map(function(line
) {
6187 }).join('\n').substr(2);
6189 str
= '\n' + str
.split('\n').map(function(line
) {
6195 str
= ctx
.stylize('[Circular]', 'special');
6198 if (isUndefined(name
)) {
6199 if (array
&& key
.match(/^\d+$/)) {
6202 name
= JSON
.stringify('' + key
);
6203 if (name
.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
6204 name
= name
.substr(1, name
.length
- 2);
6205 name
= ctx
.stylize(name
, 'name');
6207 name
= name
.replace(/'/g, "\\'")
6208 .replace(/\\"/g
, '"')
6209 .replace(/(^"|"$)/g, "'");
6210 name
= ctx
.stylize(name
, 'string');
6214 return name
+ ': ' + str
;
6218 function reduceToSingleString(output
, base
, braces
) {
6219 var numLinesEst
= 0;
6220 var length
= output
.reduce(function(prev
, cur
) {
6222 if (cur
.indexOf('\n') >= 0) numLinesEst
++;
6223 return prev
+ cur
.replace(/\u001b\[\d\d?m/g, '').length
+ 1;
6228 (base
=== '' ? '' : base
+ '\n ') +
6230 output
.join(',\n ') +
6235 return braces
[0] + base
+ ' ' + output
.join(', ') + ' ' + braces
[1];
6239 // NOTE: These type checking functions intentionally don't use `instanceof`
6240 // because it is fragile and can be easily faked with `Object.create()`.
6241 function isArray(ar
) {
6242 return Array
.isArray(ar
);
6244 exports
.isArray
= isArray
;
6246 function isBoolean(arg
) {
6247 return typeof arg
=== 'boolean';
6249 exports
.isBoolean
= isBoolean
;
6251 function isNull(arg
) {
6252 return arg
=== null;
6254 exports
.isNull
= isNull
;
6256 function isNullOrUndefined(arg
) {
6259 exports
.isNullOrUndefined
= isNullOrUndefined
;
6261 function isNumber(arg
) {
6262 return typeof arg
=== 'number';
6264 exports
.isNumber
= isNumber
;
6266 function isString(arg
) {
6267 return typeof arg
=== 'string';
6269 exports
.isString
= isString
;
6271 function isSymbol(arg
) {
6272 return typeof arg
=== 'symbol';
6274 exports
.isSymbol
= isSymbol
;
6276 function isUndefined(arg
) {
6277 return arg
=== void 0;
6279 exports
.isUndefined
= isUndefined
;
6281 function isRegExp(re
) {
6282 return isObject(re
) && objectToString(re
) === '[object RegExp]';
6284 exports
.isRegExp
= isRegExp
;
6286 function isObject(arg
) {
6287 return typeof arg
=== 'object' && arg
!== null;
6289 exports
.isObject
= isObject
;
6291 function isDate(d
) {
6292 return isObject(d
) && objectToString(d
) === '[object Date]';
6294 exports
.isDate
= isDate
;
6296 function isError(e
) {
6297 return isObject(e
) &&
6298 (objectToString(e
) === '[object Error]' || e
instanceof Error
);
6300 exports
.isError
= isError
;
6302 function isFunction(arg
) {
6303 return typeof arg
=== 'function';
6305 exports
.isFunction
= isFunction
;
6307 function isPrimitive(arg
) {
6308 return arg
=== null ||
6309 typeof arg
=== 'boolean' ||
6310 typeof arg
=== 'number' ||
6311 typeof arg
=== 'string' ||
6312 typeof arg
=== 'symbol' || // ES6 symbol
6313 typeof arg
=== 'undefined';
6315 exports
.isPrimitive
= isPrimitive
;
6317 exports
.isBuffer
= require('./support/isBuffer');
6319 function objectToString(o
) {
6320 return Object
.prototype.toString
.call(o
);
6325 return n
< 10 ? '0' + n
.toString(10) : n
.toString(10);
6329 var months
= ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
6330 'Oct', 'Nov', 'Dec'];
6333 function timestamp() {
6335 var time
= [pad(d
.getHours()),
6336 pad(d
.getMinutes()),
6337 pad(d
.getSeconds())].join(':');
6338 return [d
.getDate(), months
[d
.getMonth()], time
].join(' ');
6342 // log is just a thin wrapper to console.log that prepends a timestamp
6343 exports
.log = function() {
6344 console
.log('%s - %s', timestamp(), exports
.format
.apply(exports
, arguments
));
6349 * Inherit the prototype methods from one constructor into another.
6351 * The Function.prototype.inherits from lang.js rewritten as a standalone
6352 * function (not on Function.prototype). NOTE: If this file is to be loaded
6353 * during bootstrapping this function needs to be rewritten using some native
6354 * functions as prototype setup using normal JavaScript does not work as
6355 * expected during bootstrapping (see mirror.js in r114903).
6357 * @param {function} ctor Constructor function which needs to inherit the
6359 * @param {function} superCtor Constructor function to inherit prototype from.
6361 exports
.inherits
= require('inherits');
6363 exports
._extend = function(origin
, add
) {
6364 // Don't do anything if add isn't an object
6365 if (!add
|| !isObject(add
)) return origin
;
6367 var keys
= Object
.keys(add
);
6368 var i
= keys
.length
;
6370 origin
[keys
[i
]] = add
[keys
[i
]];
6375 function hasOwnProperty(obj
, prop
) {
6376 return Object
.prototype.hasOwnProperty
.call(obj
, prop
);
6379 }).call(this,require('_process'),typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
6380 },{"./support/isBuffer":32,"_process":13,"inherits":31}],34:[function(require
,module
,exports
){
6382 base58: require('bs58'),
6383 bitcoin: require('bitcoinjs-lib'),
6384 ecurve: require('ecurve'),
6385 BigInteger: require('bigi'),
6386 Buffer: require('buffer'),
6387 elliptic: require('elliptic'),
6388 bs58check: require('bs58check'),
6391 module
.exports
= bitcoin
;
6393 },{"bigi":39,"bitcoinjs-lib":52,"bs58":83,"bs58check":85,"buffer":5,"ecurve":94,"elliptic":97}],35:[function(require
,module
,exports
){
6395 // Forked from https://github.com/cryptocoinjs/bs58
6396 // Originally written by Mike Hearn for BitcoinJ
6397 // Copyright (c) 2011 Google Inc
6398 // Ported to JavaScript by Stefan Thomas
6399 // Merged Buffer refactorings from base58-native by Stephen Pair
6400 // Copyright (c) 2013 BitPay Inc
6402 var Buffer
= require('safe-buffer').Buffer
6404 module
.exports
= function base (ALPHABET
) {
6405 var ALPHABET_MAP
= {}
6406 var BASE
= ALPHABET
.length
6407 var LEADER
= ALPHABET
.charAt(0)
6409 // pre-compute lookup table
6410 for (var z
= 0; z
< ALPHABET
.length
; z
++) {
6411 var x
= ALPHABET
.charAt(z
)
6413 if (ALPHABET_MAP
[x
] !== undefined) throw new TypeError(x
+ ' is ambiguous')
6417 function encode (source
) {
6418 if (source
.length
=== 0) return ''
6421 for (var i
= 0; i
< source
.length
; ++i
) {
6422 for (var j
= 0, carry
= source
[i
]; j
< digits
.length
; ++j
) {
6423 carry
+= digits
[j
] << 8
6424 digits
[j
] = carry
% BASE
6425 carry
= (carry
/ BASE
) | 0
6429 digits
.push(carry
% BASE
)
6430 carry
= (carry
/ BASE
) | 0
6436 // deal with leading zeros
6437 for (var k
= 0; source
[k
] === 0 && k
< source
.length
- 1; ++k
) string
+= ALPHABET
[0]
6438 // convert digits to a string
6439 for (var q
= digits
.length
- 1; q
>= 0; --q
) string
+= ALPHABET
[digits
[q
]]
6444 function decodeUnsafe (string
) {
6445 if (string
.length
=== 0) return Buffer
.allocUnsafe(0)
6448 for (var i
= 0; i
< string
.length
; i
++) {
6449 var value
= ALPHABET_MAP
[string
[i
]]
6450 if (value
=== undefined) return
6452 for (var j
= 0, carry
= value
; j
< bytes
.length
; ++j
) {
6453 carry
+= bytes
[j
] * BASE
6454 bytes
[j
] = carry
& 0xff
6459 bytes
.push(carry
& 0xff)
6464 // deal with leading zeros
6465 for (var k
= 0; string
[k
] === LEADER
&& k
< string
.length
- 1; ++k
) {
6469 return Buffer
.from(bytes
.reverse())
6472 function decode (string
) {
6473 var buffer
= decodeUnsafe(string
)
6474 if (buffer
) return buffer
6476 throw new Error('Non-base' + BASE
+ ' character')
6481 decodeUnsafe: decodeUnsafe
,
6486 },{"safe-buffer":128}],36:[function(require
,module
,exports
){
6488 let ALPHABET
= 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
6490 // pre-compute lookup table
6491 let ALPHABET_MAP
= {}
6492 for (let z
= 0; z
< ALPHABET
.length
; z
++) {
6493 let x
= ALPHABET
.charAt(z
)
6495 if (ALPHABET_MAP
[x
] !== undefined) throw new TypeError(x
+ ' is ambiguous')
6499 function polymodStep (pre
) {
6501 return ((pre
& 0x1FFFFFF) << 5) ^
6502 (-((b
>> 0) & 1) & 0x3b6a57b2) ^
6503 (-((b
>> 1) & 1) & 0x26508e6d) ^
6504 (-((b
>> 2) & 1) & 0x1ea119fa) ^
6505 (-((b
>> 3) & 1) & 0x3d4233dd) ^
6506 (-((b
>> 4) & 1) & 0x2a1462b3)
6509 function prefixChk (prefix
) {
6511 for (let i
= 0; i
< prefix
.length
; ++i
) {
6512 let c
= prefix
.charCodeAt(i
)
6513 if (c
< 33 || c
> 126) throw new Error('Invalid prefix (' + prefix
+ ')')
6515 chk
= polymodStep(chk
) ^ (c
>> 5)
6517 chk
= polymodStep(chk
)
6519 for (let i
= 0; i
< prefix
.length
; ++i
) {
6520 let v
= prefix
.charCodeAt(i
)
6521 chk
= polymodStep(chk
) ^ (v
& 0x1f)
6526 function encode (prefix
, words
) {
6528 if ((prefix
.length
+ 7 + words
.length
) > 90) throw new TypeError('Exceeds Bech32 maximum length')
6529 prefix
= prefix
.toLowerCase()
6531 // determine chk mod
6532 let chk
= prefixChk(prefix
)
6533 let result
= prefix
+ '1'
6534 for (let i
= 0; i
< words
.length
; ++i
) {
6536 if ((x
>> 5) !== 0) throw new Error('Non 5-bit word')
6538 chk
= polymodStep(chk
) ^ x
6539 result
+= ALPHABET
.charAt(x
)
6542 for (let i
= 0; i
< 6; ++i
) {
6543 chk
= polymodStep(chk
)
6547 for (let i
= 0; i
< 6; ++i
) {
6548 let v
= (chk
>> ((5 - i
) * 5)) & 0x1f
6549 result
+= ALPHABET
.charAt(v
)
6555 function decode (str
) {
6556 if (str
.length
< 8) throw new TypeError(str
+ ' too short')
6557 if (str
.length
> 90) throw new TypeError(str
+ ' too long')
6559 // don't allow mixed case
6560 let lowered
= str
.toLowerCase()
6561 let uppered
= str
.toUpperCase()
6562 if (str
!== lowered
&& str
!== uppered
) throw new Error('Mixed-case string ' + str
)
6565 let split
= str
.lastIndexOf('1')
6566 if (split
=== 0) throw new Error('Missing prefix for ' + str
)
6568 let prefix
= str
.slice(0, split
)
6569 let wordChars
= str
.slice(split
+ 1)
6570 if (wordChars
.length
< 6) throw new Error('Data too short')
6572 let chk
= prefixChk(prefix
)
6574 for (let i
= 0; i
< wordChars
.length
; ++i
) {
6575 let c
= wordChars
.charAt(i
)
6576 let v
= ALPHABET_MAP
[c
]
6577 if (v
=== undefined) throw new Error('Unknown character ' + c
)
6578 chk
= polymodStep(chk
) ^ v
6580 // not in the checksum?
6581 if (i
+ 6 >= wordChars
.length
) continue
6585 if (chk
!== 1) throw new Error('Invalid checksum for ' + str
)
6586 return { prefix
, words
}
6589 function convert (data
, inBits
, outBits
, pad
) {
6592 let maxV
= (1 << outBits
) - 1
6595 for (let i
= 0; i
< data
.length
; ++i
) {
6596 value
= (value
<< inBits
) | data
[i
]
6599 while (bits
>= outBits
) {
6601 result
.push((value
>> bits
) & maxV
)
6607 result
.push((value
<< (outBits
- bits
)) & maxV
)
6610 if (bits
>= inBits
) throw new Error('Excess padding')
6611 if ((value
<< (outBits
- bits
)) & maxV
) throw new Error('Non-zero padding')
6617 function toWords (bytes
) {
6618 return convert(bytes
, 8, 5, true)
6621 function fromWords (words
) {
6622 return convert(words
, 5, 8, false)
6625 module
.exports
= { decode
, encode
, toWords
, fromWords
}
6627 },{}],37:[function(require
,module
,exports
){
6628 // (public) Constructor
6629 function BigInteger(a
, b
, c
) {
6630 if (!(this instanceof BigInteger
))
6631 return new BigInteger(a
, b
, c
)
6634 if ("number" == typeof a
) this.fromNumber(a
, b
, c
)
6635 else if (b
== null && "string" != typeof a
) this.fromString(a
, 256)
6636 else this.fromString(a
, b
)
6640 var proto
= BigInteger
.prototype
6642 // duck-typed isBigInteger
6643 proto
.__bigi
= require('../package.json').version
6644 BigInteger
.isBigInteger = function (obj
, check_ver
) {
6645 return obj
&& obj
.__bigi
&& (!check_ver
|| obj
.__bigi
=== proto
.__bigi
)
6651 // am: Compute w_j += (x*this_i), propagate carries,
6652 // c is initial carry, returns final carry.
6653 // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
6654 // We need to select the fastest one that works in this environment.
6656 // am1: use a single mult and divide to get the high bits,
6657 // max digit bits should be 26 because
6658 // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
6659 function am1(i
, x
, w
, j
, c
, n
) {
6661 var v
= x
* this[i
++] + w
[j
] + c
6662 c
= Math
.floor(v
/ 0x4000000)
6663 w
[j
++] = v
& 0x3ffffff
6667 // am2 avoids a big mult-and-extract completely.
6668 // Max digit bits should be <= 30 because we do bitwise ops
6669 // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
6670 function am2(i
, x
, w
, j
, c
, n
) {
6671 var xl
= x
& 0x7fff,
6674 var l
= this[i
] & 0x7fff
6675 var h
= this[i
++] >> 15
6676 var m
= xh
* l
+ h
* xl
6677 l
= xl
* l
+ ((m
& 0x7fff) << 15) + w
[j
] + (c
& 0x3fffffff)
6678 c
= (l
>>> 30) + (m
>>> 15) + xh
* h
+ (c
>>> 30)
6679 w
[j
++] = l
& 0x3fffffff
6683 // Alternately, set max digit bits to 28 since some
6684 // browsers slow down when dealing with 32-bit numbers.
6685 function am3(i
, x
, w
, j
, c
, n
) {
6686 var xl
= x
& 0x3fff,
6689 var l
= this[i
] & 0x3fff
6690 var h
= this[i
++] >> 14
6691 var m
= xh
* l
+ h
* xl
6692 l
= xl
* l
+ ((m
& 0x3fff) << 14) + w
[j
] + c
6693 c
= (l
>> 28) + (m
>> 14) + xh
* h
6694 w
[j
++] = l
& 0xfffffff
6700 BigInteger
.prototype.am
= am1
6703 BigInteger
.prototype.DB
= dbits
6704 BigInteger
.prototype.DM
= ((1 << dbits
) - 1)
6705 var DV
= BigInteger
.prototype.DV
= (1 << dbits
)
6708 BigInteger
.prototype.FV
= Math
.pow(2, BI_FP
)
6709 BigInteger
.prototype.F1
= BI_FP
- dbits
6710 BigInteger
.prototype.F2
= 2 * dbits
- BI_FP
6712 // Digit conversions
6713 var BI_RM
= "0123456789abcdefghijklmnopqrstuvwxyz"
6714 var BI_RC
= new Array()
6716 rr
= "0".charCodeAt(0)
6717 for (vv
= 0; vv
<= 9; ++vv
) BI_RC
[rr
++] = vv
6718 rr
= "a".charCodeAt(0)
6719 for (vv
= 10; vv
< 36; ++vv
) BI_RC
[rr
++] = vv
6720 rr
= "A".charCodeAt(0)
6721 for (vv
= 10; vv
< 36; ++vv
) BI_RC
[rr
++] = vv
6723 function int2char(n
) {
6724 return BI_RM
.charAt(n
)
6727 function intAt(s
, i
) {
6728 var c
= BI_RC
[s
.charCodeAt(i
)]
6729 return (c
== null) ? -1 : c
6732 // (protected) copy this to r
6733 function bnpCopyTo(r
) {
6734 for (var i
= this.t
- 1; i
>= 0; --i
) r
[i
] = this[i
]
6739 // (protected) set from integer value x, -DV <= x < DV
6740 function bnpFromInt(x
) {
6742 this.s
= (x
< 0) ? -1 : 0
6743 if (x
> 0) this[0] = x
6744 else if (x
< -1) this[0] = x
+ DV
6748 // return bigint initialized to value
6750 var r
= new BigInteger()
6755 // (protected) set from string and radix
6756 function bnpFromString(s
, b
) {
6761 else if (b
== 8) k
= 3
6762 else if (b
== 256) k
= 8; // byte array
6763 else if (b
== 2) k
= 1
6764 else if (b
== 32) k
= 5
6765 else if (b
== 4) k
= 2
6767 self
.fromRadix(s
, b
)
6776 var x
= (k
== 8) ? s
[i
] & 0xff : intAt(s
, i
)
6778 if (s
.charAt(i
) == "-") mi
= true
6784 else if (sh
+ k
> self
.DB
) {
6785 self
[self
.t
- 1] |= (x
& ((1 << (self
.DB
- sh
)) - 1)) << sh
6786 self
[self
.t
++] = (x
>> (self
.DB
- sh
))
6788 self
[self
.t
- 1] |= x
<< sh
6790 if (sh
>= self
.DB
) sh
-= self
.DB
6792 if (k
== 8 && (s
[0] & 0x80) != 0) {
6794 if (sh
> 0) self
[self
.t
- 1] |= ((1 << (self
.DB
- sh
)) - 1) << sh
6797 if (mi
) BigInteger
.ZERO
.subTo(self
, self
)
6800 // (protected) clamp off excess high words
6801 function bnpClamp() {
6802 var c
= this.s
& this.DM
6803 while (this.t
> 0 && this[this.t
- 1] == c
)--this.t
6806 // (public) return string representation in given radix
6807 function bnToString(b
) {
6809 if (self
.s
< 0) return "-" + self
.negate()
6813 else if (b
== 8) k
= 3
6814 else if (b
== 2) k
= 1
6815 else if (b
== 32) k
= 5
6816 else if (b
== 4) k
= 2
6817 else return self
.toRadix(b
)
6818 var km
= (1 << k
) - 1,
6822 var p
= self
.DB
- (i
* self
.DB
) % k
6824 if (p
< self
.DB
&& (d
= self
[i
] >> p
) > 0) {
6830 d
= (self
[i
] & ((1 << p
) - 1)) << (k
- p
)
6831 d
|= self
[--i
] >> (p
+= self
.DB
- k
)
6833 d
= (self
[i
] >> (p
-= k
)) & km
6840 if (m
) r
+= int2char(d
)
6847 function bnNegate() {
6848 var r
= new BigInteger()
6849 BigInteger
.ZERO
.subTo(this, r
)
6855 return (this.s
< 0) ? this.negate() : this
6858 // (public) return + if this > a, - if this < a, 0 if equal
6859 function bnCompareTo(a
) {
6860 var r
= this.s
- a
.s
6861 if (r
!= 0) return r
6864 if (r
!= 0) return (this.s
< 0) ? -r : r
6866 if ((r
= this[i
] - a
[i
]) != 0) return r
6870 // returns bit length of the integer x
6874 if ((t
= x
>>> 16) != 0) {
6878 if ((t
= x
>> 8) != 0) {
6882 if ((t
= x
>> 4) != 0) {
6886 if ((t
= x
>> 2) != 0) {
6890 if ((t
= x
>> 1) != 0) {
6897 // (public) return the number of bits in "this"
6898 function bnBitLength() {
6899 if (this.t
<= 0) return 0
6900 return this.DB
* (this.t
- 1) + nbits(this[this.t
- 1] ^ (this.s
& this.DM
))
6903 // (public) return the number of bytes in "this"
6904 function bnByteLength() {
6905 return this.bitLength() >> 3
6908 // (protected) r = this << n*DB
6909 function bnpDLShiftTo(n
, r
) {
6911 for (i
= this.t
- 1; i
>= 0; --i
) r
[i
+ n
] = this[i
]
6912 for (i
= n
- 1; i
>= 0; --i
) r
[i
] = 0
6917 // (protected) r = this >> n*DB
6918 function bnpDRShiftTo(n
, r
) {
6919 for (var i
= n
; i
< this.t
; ++i
) r
[i
- n
] = this[i
]
6920 r
.t
= Math
.max(this.t
- n
, 0)
6924 // (protected) r = this << n
6925 function bnpLShiftTo(n
, r
) {
6927 var bs
= n
% self
.DB
6928 var cbs
= self
.DB
- bs
6929 var bm
= (1 << cbs
) - 1
6930 var ds
= Math
.floor(n
/ self
.DB
),
6931 c
= (self
.s
<< bs
) & self
.DM
,
6933 for (i
= self
.t
- 1; i
>= 0; --i
) {
6934 r
[i
+ ds
+ 1] = (self
[i
] >> cbs
) | c
6935 c
= (self
[i
] & bm
) << bs
6937 for (i
= ds
- 1; i
>= 0; --i
) r
[i
] = 0
6939 r
.t
= self
.t
+ ds
+ 1
6944 // (protected) r = this >> n
6945 function bnpRShiftTo(n
, r
) {
6948 var ds
= Math
.floor(n
/ self
.DB
)
6953 var bs
= n
% self
.DB
6954 var cbs
= self
.DB
- bs
6955 var bm
= (1 << bs
) - 1
6956 r
[0] = self
[ds
] >> bs
6957 for (var i
= ds
+ 1; i
< self
.t
; ++i
) {
6958 r
[i
- ds
- 1] |= (self
[i
] & bm
) << cbs
6959 r
[i
- ds
] = self
[i
] >> bs
6961 if (bs
> 0) r
[self
.t
- ds
- 1] |= (self
.s
& bm
) << cbs
6966 // (protected) r = this - a
6967 function bnpSubTo(a
, r
) {
6971 m
= Math
.min(a
.t
, self
.t
)
6974 r
[i
++] = c
& self
.DM
6979 while (i
< self
.t
) {
6981 r
[i
++] = c
& self
.DM
6989 r
[i
++] = c
& self
.DM
6994 r
.s
= (c
< 0) ? -1 : 0
6995 if (c
< -1) r
[i
++] = self
.DV
+ c
6996 else if (c
> 0) r
[i
++] = c
7001 // (protected) r = this * a, r != this,a (HAC 14.12)
7002 // "this" should be the larger one if appropriate.
7003 function bnpMultiplyTo(a
, r
) {
7008 while (--i
>= 0) r
[i
] = 0
7009 for (i
= 0; i
< y
.t
; ++i
) r
[i
+ x
.t
] = x
.am(0, y
[i
], r
, i
, 0, x
.t
)
7012 if (this.s
!= a
.s
) BigInteger
.ZERO
.subTo(r
, r
)
7015 // (protected) r = this^2, r != this (HAC 14.16)
7016 function bnpSquareTo(r
) {
7018 var i
= r
.t
= 2 * x
.t
7019 while (--i
>= 0) r
[i
] = 0
7020 for (i
= 0; i
< x
.t
- 1; ++i
) {
7021 var c
= x
.am(i
, x
[i
], r
, 2 * i
, 0, 1)
7022 if ((r
[i
+ x
.t
] += x
.am(i
+ 1, 2 * x
[i
], r
, 2 * i
+ 1, c
, x
.t
- i
- 1)) >= x
.DV
) {
7027 if (r
.t
> 0) r
[r
.t
- 1] += x
.am(i
, x
[i
], r
, 2 * i
, 0, 1)
7032 // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
7033 // r != q, this != m. q or r may be null.
7034 function bnpDivRemTo(m
, q
, r
) {
7037 if (pm
.t
<= 0) return
7040 if (q
!= null) q
.fromInt(0)
7041 if (r
!= null) self
.copyTo(r
)
7044 if (r
== null) r
= new BigInteger()
7045 var y
= new BigInteger(),
7048 var nsh
= self
.DB
- nbits(pm
[pm
.t
- 1]); // normalize modulus
7059 var yt
= y0
* (1 << self
.F1
) + ((ys
> 1) ? y
[ys
- 2] >> self
.F2 : 0)
7060 var d1
= self
.FV
/ yt
,
7061 d2
= (1 << self
.F1
) / yt
,
7065 t
= (q
== null) ? new BigInteger() : q
7067 if (r
.compareTo(t
) >= 0) {
7071 BigInteger
.ONE
.dlShiftTo(ys
, t
)
7072 t
.subTo(y
, y
); // "negative" y so we can replace sub with am later
7073 while (y
.t
< ys
) y
[y
.t
++] = 0
7075 // Estimate quotient digit
7076 var qd
= (r
[--i
] == y0
) ? self
.DM : Math
.floor(r
[i
] * d1
+ (r
[i
- 1] + e
) * d2
)
7077 if ((r
[i
] += y
.am(0, qd
, r
, j
, 0, ys
)) < qd
) { // Try it out
7080 while (r
[i
] < --qd
) r
.subTo(t
, r
)
7085 if (ts
!= ms
) BigInteger
.ZERO
.subTo(q
, q
)
7089 if (nsh
> 0) r
.rShiftTo(nsh
, r
); // Denormalize remainder
7090 if (ts
< 0) BigInteger
.ZERO
.subTo(r
, r
)
7093 // (public) this mod a
7095 var r
= new BigInteger()
7097 .divRemTo(a
, null, r
)
7098 if (this.s
< 0 && r
.compareTo(BigInteger
.ZERO
) > 0) a
.subTo(r
, r
)
7102 // Modular reduction using "classic" algorithm
7103 function Classic(m
) {
7107 function cConvert(x
) {
7108 if (x
.s
< 0 || x
.compareTo(this.m
) >= 0) return x
.mod(this.m
)
7112 function cRevert(x
) {
7116 function cReduce(x
) {
7117 x
.divRemTo(this.m
, null, x
)
7120 function cMulTo(x
, y
, r
) {
7125 function cSqrTo(x
, r
) {
7130 Classic
.prototype.convert
= cConvert
7131 Classic
.prototype.revert
= cRevert
7132 Classic
.prototype.reduce
= cReduce
7133 Classic
.prototype.mulTo
= cMulTo
7134 Classic
.prototype.sqrTo
= cSqrTo
7136 // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
7140 // xy(2-xy) = (1+km)(1-km)
7141 // x[y(2-xy)] = 1-k^2m^2
7142 // x[y(2-xy)] == 1 (mod m^2)
7143 // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
7144 // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
7145 // JS multiply "overflows" differently from C/C++, so care is needed here.
7146 function bnpInvDigit() {
7147 if (this.t
< 1) return 0
7149 if ((x
& 1) == 0) return 0
7150 var y
= x
& 3; // y == 1/x mod 2^2
7151 y
= (y
* (2 - (x
& 0xf) * y
)) & 0xf; // y == 1/x mod 2^4
7152 y
= (y
* (2 - (x
& 0xff) * y
)) & 0xff; // y == 1/x mod 2^8
7153 y
= (y
* (2 - (((x
& 0xffff) * y
) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
7154 // last step - calculate inverse mod DV directly
7155 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
7156 y
= (y
* (2 - x
* y
% this.DV
)) % this.DV
; // y == 1/x mod 2^dbits
7157 // we really want the negative inverse, and -DV < y < DV
7158 return (y
> 0) ? this.DV
- y : -y
7161 // Montgomery reduction
7162 function Montgomery(m
) {
7164 this.mp
= m
.invDigit()
7165 this.mpl
= this.mp
& 0x7fff
7166 this.mph
= this.mp
>> 15
7167 this.um
= (1 << (m
.DB
- 15)) - 1
7172 function montConvert(x
) {
7173 var r
= new BigInteger()
7175 .dlShiftTo(this.m
.t
, r
)
7176 r
.divRemTo(this.m
, null, r
)
7177 if (x
.s
< 0 && r
.compareTo(BigInteger
.ZERO
) > 0) this.m
.subTo(r
, r
)
7182 function montRevert(x
) {
7183 var r
= new BigInteger()
7189 // x = x/R mod m (HAC 14.32)
7190 function montReduce(x
) {
7191 while (x
.t
<= this.mt2
) // pad x so am has enough room later
7193 for (var i
= 0; i
< this.m
.t
; ++i
) {
7194 // faster way of calculating u0 = x[i]*mp mod DV
7195 var j
= x
[i
] & 0x7fff
7196 var u0
= (j
* this.mpl
+ (((j
* this.mph
+ (x
[i
] >> 15) * this.mpl
) & this.um
) << 15)) & x
.DM
7197 // use am to combine the multiply-shift-add into one call
7199 x
[j
] += this.m
.am(0, u0
, x
, i
, 0, this.m
.t
)
7201 while (x
[j
] >= x
.DV
) {
7207 x
.drShiftTo(this.m
.t
, x
)
7208 if (x
.compareTo(this.m
) >= 0) x
.subTo(this.m
, x
)
7211 // r = "x^2/R mod m"; x != r
7212 function montSqrTo(x
, r
) {
7217 // r = "xy/R mod m"; x,y != r
7218 function montMulTo(x
, y
, r
) {
7223 Montgomery
.prototype.convert
= montConvert
7224 Montgomery
.prototype.revert
= montRevert
7225 Montgomery
.prototype.reduce
= montReduce
7226 Montgomery
.prototype.mulTo
= montMulTo
7227 Montgomery
.prototype.sqrTo
= montSqrTo
7229 // (protected) true iff this is even
7230 function bnpIsEven() {
7231 return ((this.t
> 0) ? (this[0] & 1) : this.s
) == 0
7234 // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
7235 function bnpExp(e
, z
) {
7236 if (e
> 0xffffffff || e
< 1) return BigInteger
.ONE
7237 var r
= new BigInteger(),
7238 r2
= new BigInteger(),
7239 g
= z
.convert(this),
7244 if ((e
& (1 << i
)) > 0) z
.mulTo(r2
, g
, r
)
7254 // (public) this^e % m, 0 <= e < 2^32
7255 function bnModPowInt(e
, m
) {
7257 if (e
< 256 || m
.isEven()) z
= new Classic(m
)
7258 else z
= new Montgomery(m
)
7259 return this.exp(e
, z
)
7263 proto
.copyTo
= bnpCopyTo
7264 proto
.fromInt
= bnpFromInt
7265 proto
.fromString
= bnpFromString
7266 proto
.clamp
= bnpClamp
7267 proto
.dlShiftTo
= bnpDLShiftTo
7268 proto
.drShiftTo
= bnpDRShiftTo
7269 proto
.lShiftTo
= bnpLShiftTo
7270 proto
.rShiftTo
= bnpRShiftTo
7271 proto
.subTo
= bnpSubTo
7272 proto
.multiplyTo
= bnpMultiplyTo
7273 proto
.squareTo
= bnpSquareTo
7274 proto
.divRemTo
= bnpDivRemTo
7275 proto
.invDigit
= bnpInvDigit
7276 proto
.isEven
= bnpIsEven
7280 proto
.toString
= bnToString
7281 proto
.negate
= bnNegate
7283 proto
.compareTo
= bnCompareTo
7284 proto
.bitLength
= bnBitLength
7285 proto
.byteLength
= bnByteLength
7287 proto
.modPowInt
= bnModPowInt
7290 function bnClone() {
7291 var r
= new BigInteger()
7296 // (public) return value as integer
7297 function bnIntValue() {
7299 if (this.t
== 1) return this[0] - this.DV
7300 else if (this.t
== 0) return -1
7301 } else if (this.t
== 1) return this[0]
7302 else if (this.t
== 0) return 0
7303 // assumes 16 < DB < 32
7304 return ((this[1] & ((1 << (32 - this.DB
)) - 1)) << this.DB
) | this[0]
7307 // (public) return value as byte
7308 function bnByteValue() {
7309 return (this.t
== 0) ? this.s : (this[0] << 24) >> 24
7312 // (public) return value as short (assumes DB>=16)
7313 function bnShortValue() {
7314 return (this.t
== 0) ? this.s : (this[0] << 16) >> 16
7317 // (protected) return x s.t. r^x < DV
7318 function bnpChunkSize(r
) {
7319 return Math
.floor(Math
.LN2
* this.DB
/ Math
.log(r
))
7322 // (public) 0 if this == 0, 1 if this > 0
7323 function bnSigNum() {
7324 if (this.s
< 0) return -1
7325 else if (this.t
<= 0 || (this.t
== 1 && this[0] <= 0)) return 0
7329 // (protected) convert to radix string
7330 function bnpToRadix(b
) {
7331 if (b
== null) b
= 10
7332 if (this.signum() == 0 || b
< 2 || b
> 36) return "0"
7333 var cs
= this.chunkSize(b
)
7334 var a
= Math
.pow(b
, cs
)
7336 y
= new BigInteger(),
7337 z
= new BigInteger(),
7339 this.divRemTo(d
, y
, z
)
7340 while (y
.signum() > 0) {
7341 r
= (a
+ z
.intValue())
7350 // (protected) convert from radix string
7351 function bnpFromRadix(s
, b
) {
7354 if (b
== null) b
= 10
7355 var cs
= self
.chunkSize(b
)
7356 var d
= Math
.pow(b
, cs
),
7360 for (var i
= 0; i
< s
.length
; ++i
) {
7363 if (s
.charAt(i
) == "-" && self
.signum() == 0) mi
= true
7369 self
.dAddOffset(w
, 0)
7375 self
.dMultiply(Math
.pow(b
, j
))
7376 self
.dAddOffset(w
, 0)
7378 if (mi
) BigInteger
.ZERO
.subTo(self
, self
)
7381 // (protected) alternate constructor
7382 function bnpFromNumber(a
, b
, c
) {
7384 if ("number" == typeof b
) {
7385 // new BigInteger(int,int,RNG)
7386 if (a
< 2) self
.fromInt(1)
7388 self
.fromNumber(a
, c
)
7389 if (!self
.testBit(a
- 1)) // force MSB set
7390 self
.bitwiseTo(BigInteger
.ONE
.shiftLeft(a
- 1), op_or
, self
)
7391 if (self
.isEven()) self
.dAddOffset(1, 0); // force odd
7392 while (!self
.isProbablePrime(b
)) {
7393 self
.dAddOffset(2, 0)
7394 if (self
.bitLength() > a
) self
.subTo(BigInteger
.ONE
.shiftLeft(a
- 1), self
)
7398 // new BigInteger(int,RNG)
7399 var x
= new Array(),
7401 x
.length
= (a
>> 3) + 1
7403 if (t
> 0) x
[0] &= ((1 << t
) - 1)
7405 self
.fromString(x
, 256)
7409 // (public) convert to bigendian byte array
7410 function bnToByteArray() {
7415 var p
= self
.DB
- (i
* self
.DB
) % 8,
7418 if (p
< self
.DB
&& (d
= self
[i
] >> p
) != (self
.s
& self
.DM
) >> p
)
7419 r
[k
++] = d
| (self
.s
<< (self
.DB
- p
))
7422 d
= (self
[i
] & ((1 << p
) - 1)) << (8 - p
)
7423 d
|= self
[--i
] >> (p
+= self
.DB
- 8)
7425 d
= (self
[i
] >> (p
-= 8)) & 0xff
7431 if ((d
& 0x80) != 0) d
|= -256
7432 if (k
=== 0 && (self
.s
& 0x80) != (d
& 0x80))++k
7433 if (k
> 0 || d
!= self
.s
) r
[k
++] = d
7439 function bnEquals(a
) {
7440 return (this.compareTo(a
) == 0)
7444 return (this.compareTo(a
) < 0) ? this : a
7448 return (this.compareTo(a
) > 0) ? this : a
7451 // (protected) r = this op a (bitwise)
7452 function bnpBitwiseTo(a
, op
, r
) {
7454 var i
, f
, m
= Math
.min(a
.t
, self
.t
)
7455 for (i
= 0; i
< m
; ++i
) r
[i
] = op(self
[i
], a
[i
])
7458 for (i
= m
; i
< self
.t
; ++i
) r
[i
] = op(self
[i
], f
)
7461 f
= self
.s
& self
.DM
7462 for (i
= m
; i
< a
.t
; ++i
) r
[i
] = op(f
, a
[i
])
7465 r
.s
= op(self
.s
, a
.s
)
7469 // (public) this & a
7470 function op_and(x
, y
) {
7475 var r
= new BigInteger()
7476 this.bitwiseTo(a
, op_and
, r
)
7480 // (public) this | a
7481 function op_or(x
, y
) {
7486 var r
= new BigInteger()
7487 this.bitwiseTo(a
, op_or
, r
)
7491 // (public) this ^ a
7492 function op_xor(x
, y
) {
7497 var r
= new BigInteger()
7498 this.bitwiseTo(a
, op_xor
, r
)
7502 // (public) this & ~a
7503 function op_andnot(x
, y
) {
7507 function bnAndNot(a
) {
7508 var r
= new BigInteger()
7509 this.bitwiseTo(a
, op_andnot
, r
)
7515 var r
= new BigInteger()
7516 for (var i
= 0; i
< this.t
; ++i
) r
[i
] = this.DM
& ~this[i
]
7522 // (public) this << n
7523 function bnShiftLeft(n
) {
7524 var r
= new BigInteger()
7525 if (n
< 0) this.rShiftTo(-n
, r
)
7526 else this.lShiftTo(n
, r
)
7530 // (public) this >> n
7531 function bnShiftRight(n
) {
7532 var r
= new BigInteger()
7533 if (n
< 0) this.lShiftTo(-n
, r
)
7534 else this.rShiftTo(n
, r
)
7538 // return index of lowest 1-bit in x, x < 2^31
7540 if (x
== 0) return -1
7542 if ((x
& 0xffff) == 0) {
7546 if ((x
& 0xff) == 0) {
7550 if ((x
& 0xf) == 0) {
7558 if ((x
& 1) == 0)++r
7562 // (public) returns index of lowest 1-bit (or -1 if none)
7563 function bnGetLowestSetBit() {
7564 for (var i
= 0; i
< this.t
; ++i
)
7565 if (this[i
] != 0) return i
* this.DB
+ lbit(this[i
])
7566 if (this.s
< 0) return this.t
* this.DB
7570 // return number of 1 bits in x
7580 // (public) return number of set bits
7581 function bnBitCount() {
7583 x
= this.s
& this.DM
7584 for (var i
= 0; i
< this.t
; ++i
) r
+= cbit(this[i
] ^ x
)
7588 // (public) true iff nth bit is set
7589 function bnTestBit(n
) {
7590 var j
= Math
.floor(n
/ this.DB
)
7591 if (j
>= this.t
) return (this.s
!= 0)
7592 return ((this[j
] & (1 << (n
% this.DB
))) != 0)
7595 // (protected) this op (1<<n)
7596 function bnpChangeBit(n
, op
) {
7597 var r
= BigInteger
.ONE
.shiftLeft(n
)
7598 this.bitwiseTo(r
, op
, r
)
7602 // (public) this | (1<<n)
7603 function bnSetBit(n
) {
7604 return this.changeBit(n
, op_or
)
7607 // (public) this & ~(1<<n)
7608 function bnClearBit(n
) {
7609 return this.changeBit(n
, op_andnot
)
7612 // (public) this ^ (1<<n)
7613 function bnFlipBit(n
) {
7614 return this.changeBit(n
, op_xor
)
7617 // (protected) r = this + a
7618 function bnpAddTo(a
, r
) {
7623 m
= Math
.min(a
.t
, self
.t
)
7626 r
[i
++] = c
& self
.DM
7631 while (i
< self
.t
) {
7633 r
[i
++] = c
& self
.DM
7641 r
[i
++] = c
& self
.DM
7646 r
.s
= (c
< 0) ? -1 : 0
7647 if (c
> 0) r
[i
++] = c
7648 else if (c
< -1) r
[i
++] = self
.DV
+ c
7653 // (public) this + a
7655 var r
= new BigInteger()
7660 // (public) this - a
7661 function bnSubtract(a
) {
7662 var r
= new BigInteger()
7667 // (public) this * a
7668 function bnMultiply(a
) {
7669 var r
= new BigInteger()
7670 this.multiplyTo(a
, r
)
7675 function bnSquare() {
7676 var r
= new BigInteger()
7681 // (public) this / a
7682 function bnDivide(a
) {
7683 var r
= new BigInteger()
7684 this.divRemTo(a
, r
, null)
7688 // (public) this % a
7689 function bnRemainder(a
) {
7690 var r
= new BigInteger()
7691 this.divRemTo(a
, null, r
)
7695 // (public) [this/a,this%a]
7696 function bnDivideAndRemainder(a
) {
7697 var q
= new BigInteger(),
7698 r
= new BigInteger()
7699 this.divRemTo(a
, q
, r
)
7700 return new Array(q
, r
)
7703 // (protected) this *= n, this >= 0, 1 < n < DV
7704 function bnpDMultiply(n
) {
7705 this[this.t
] = this.am(0, n
- 1, this, 0, 0, this.t
)
7710 // (protected) this += n << w words, this >= 0
7711 function bnpDAddOffset(n
, w
) {
7713 while (this.t
<= w
) this[this.t
++] = 0
7715 while (this[w
] >= this.DV
) {
7717 if (++w
>= this.t
) this[this.t
++] = 0
7723 function NullExp() {}
7729 function nMulTo(x
, y
, r
) {
7733 function nSqrTo(x
, r
) {
7737 NullExp
.prototype.convert
= nNop
7738 NullExp
.prototype.revert
= nNop
7739 NullExp
.prototype.mulTo
= nMulTo
7740 NullExp
.prototype.sqrTo
= nSqrTo
7744 return this.exp(e
, new NullExp())
7747 // (protected) r = lower n words of "this * a", a.t <= n
7748 // "this" should be the larger one if appropriate.
7749 function bnpMultiplyLowerTo(a
, n
, r
) {
7750 var i
= Math
.min(this.t
+ a
.t
, n
)
7751 r
.s
= 0; // assumes a,this >= 0
7753 while (i
> 0) r
[--i
] = 0
7755 for (j
= r
.t
- this.t
; i
< j
; ++i
) r
[i
+ this.t
] = this.am(0, a
[i
], r
, i
, 0, this.t
)
7756 for (j
= Math
.min(a
.t
, n
); i
< j
; ++i
) this.am(0, a
[i
], r
, i
, 0, n
- i
)
7760 // (protected) r = "this * a" without lower n words, n > 0
7761 // "this" should be the larger one if appropriate.
7762 function bnpMultiplyUpperTo(a
, n
, r
) {
7764 var i
= r
.t
= this.t
+ a
.t
- n
7765 r
.s
= 0; // assumes a,this >= 0
7766 while (--i
>= 0) r
[i
] = 0
7767 for (i
= Math
.max(n
- this.t
, 0); i
< a
.t
; ++i
)
7768 r
[this.t
+ i
- n
] = this.am(n
- i
, a
[i
], r
, 0, 0, this.t
+ i
- n
)
7773 // Barrett modular reduction
7774 function Barrett(m
) {
7776 this.r2
= new BigInteger()
7777 this.q3
= new BigInteger()
7778 BigInteger
.ONE
.dlShiftTo(2 * m
.t
, this.r2
)
7779 this.mu
= this.r2
.divide(m
)
7783 function barrettConvert(x
) {
7784 if (x
.s
< 0 || x
.t
> 2 * this.m
.t
) return x
.mod(this.m
)
7785 else if (x
.compareTo(this.m
) < 0) return x
7787 var r
= new BigInteger()
7794 function barrettRevert(x
) {
7798 // x = x mod m (HAC 14.42)
7799 function barrettReduce(x
) {
7801 x
.drShiftTo(self
.m
.t
- 1, self
.r2
)
7802 if (x
.t
> self
.m
.t
+ 1) {
7806 self
.mu
.multiplyUpperTo(self
.r2
, self
.m
.t
+ 1, self
.q3
)
7807 self
.m
.multiplyLowerTo(self
.q3
, self
.m
.t
+ 1, self
.r2
)
7808 while (x
.compareTo(self
.r2
) < 0) x
.dAddOffset(1, self
.m
.t
+ 1)
7810 while (x
.compareTo(self
.m
) >= 0) x
.subTo(self
.m
, x
)
7813 // r = x^2 mod m; x != r
7814 function barrettSqrTo(x
, r
) {
7819 // r = x*y mod m; x,y != r
7820 function barrettMulTo(x
, y
, r
) {
7825 Barrett
.prototype.convert
= barrettConvert
7826 Barrett
.prototype.revert
= barrettRevert
7827 Barrett
.prototype.reduce
= barrettReduce
7828 Barrett
.prototype.mulTo
= barrettMulTo
7829 Barrett
.prototype.sqrTo
= barrettSqrTo
7831 // (public) this^e % m (HAC 14.85)
7832 function bnModPow(e
, m
) {
7833 var i
= e
.bitLength(),
7836 if (i
<= 0) return r
7837 else if (i
< 18) k
= 1
7838 else if (i
< 48) k
= 3
7839 else if (i
< 144) k
= 4
7840 else if (i
< 768) k
= 5
7844 else if (m
.isEven())
7847 z
= new Montgomery(m
)
7850 var g
= new Array(),
7854 g
[1] = z
.convert(this)
7856 var g2
= new BigInteger()
7859 g
[n
] = new BigInteger()
7860 z
.mulTo(g2
, g
[n
- 2], g
[n
])
7867 r2
= new BigInteger(),
7871 if (i
>= k1
) w
= (e
[j
] >> (i
- k1
)) & km
7873 w
= (e
[j
] & ((1 << (i
+ 1)) - 1)) << (k1
- i
)
7874 if (j
> 0) w
|= e
[j
- 1] >> (this.DB
+ i
- k1
)
7878 while ((w
& 1) == 0) {
7886 if (is1
) { // ret == 1, don't bother squaring or multiplying it
7895 if (n
> 0) z
.sqrTo(r
, r2
)
7901 z
.mulTo(r2
, g
[w
], r
)
7904 while (j
>= 0 && (e
[j
] & (1 << i
)) == 0) {
7918 // (public) gcd(this,a) (HAC 14.54)
7920 var x
= (this.s
< 0) ? this.negate() : this.clone()
7921 var y
= (a
.s
< 0) ? a
.negate() : a
.clone()
7922 if (x
.compareTo(y
) < 0) {
7927 var i
= x
.getLowestSetBit(),
7928 g
= y
.getLowestSetBit()
7935 while (x
.signum() > 0) {
7936 if ((i
= x
.getLowestSetBit()) > 0) x
.rShiftTo(i
, x
)
7937 if ((i
= y
.getLowestSetBit()) > 0) y
.rShiftTo(i
, y
)
7938 if (x
.compareTo(y
) >= 0) {
7946 if (g
> 0) y
.lShiftTo(g
, y
)
7950 // (protected) this % n, n < 2^26
7951 function bnpModInt(n
) {
7952 if (n
<= 0) return 0
7953 var d
= this.DV
% n
,
7954 r
= (this.s
< 0) ? n
- 1 : 0
7956 if (d
== 0) r
= this[0] % n
7958 for (var i
= this.t
- 1; i
>= 0; --i
) r
= (d
* r
+ this[i
]) % n
7962 // (public) 1/this % m (HAC 14.61)
7963 function bnModInverse(m
) {
7965 if (this.signum() === 0) throw new Error('division by zero')
7966 if ((this.isEven() && ac
) || m
.signum() == 0) return BigInteger
.ZERO
7973 while (u
.signum() != 0) {
7974 while (u
.isEven()) {
7977 if (!a
.isEven() || !b
.isEven()) {
7982 } else if (!b
.isEven()) b
.subTo(m
, b
)
7985 while (v
.isEven()) {
7988 if (!c
.isEven() || !d
.isEven()) {
7993 } else if (!d
.isEven()) d
.subTo(m
, d
)
7996 if (u
.compareTo(v
) >= 0) {
7998 if (ac
) a
.subTo(c
, a
)
8002 if (ac
) c
.subTo(a
, c
)
8006 if (v
.compareTo(BigInteger
.ONE
) != 0) return BigInteger
.ZERO
8007 while (d
.compareTo(m
) >= 0) d
.subTo(m
, d
)
8008 while (d
.signum() < 0) d
.addTo(m
, d
)
8013 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
8014 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
8015 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
8016 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
8017 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
8018 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
8019 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
8020 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
8021 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811,
8022 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
8023 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
8026 var lplim
= (1 << 26) / lowprimes
[lowprimes
.length
- 1]
8028 // (public) test primality with certainty >= 1-.5^t
8029 function bnIsProbablePrime(t
) {
8030 var i
, x
= this.abs()
8031 if (x
.t
== 1 && x
[0] <= lowprimes
[lowprimes
.length
- 1]) {
8032 for (i
= 0; i
< lowprimes
.length
; ++i
)
8033 if (x
[0] == lowprimes
[i
]) return true
8036 if (x
.isEven()) return false
8038 while (i
< lowprimes
.length
) {
8039 var m
= lowprimes
[i
],
8041 while (j
< lowprimes
.length
&& m
< lplim
) m
*= lowprimes
[j
++]
8043 while (i
< j
) if (m
% lowprimes
[i
++] == 0) return false
8045 return x
.millerRabin(t
)
8048 // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
8049 function bnpMillerRabin(t
) {
8050 var n1
= this.subtract(BigInteger
.ONE
)
8051 var k
= n1
.getLowestSetBit()
8052 if (k
<= 0) return false
8053 var r
= n1
.shiftRight(k
)
8055 if (t
> lowprimes
.length
) t
= lowprimes
.length
8056 var a
= new BigInteger(null)
8058 for (var i
= 0; i
< t
; ++i
) {
8060 j
= lowprimes
[Math
.floor(Math
.random() * lowprimes
.length
)]
8061 if (bases
.indexOf(j
) == -1) break
8065 var y
= a
.modPow(r
, this)
8066 if (y
.compareTo(BigInteger
.ONE
) != 0 && y
.compareTo(n1
) != 0) {
8068 while (j
++ < k
&& y
.compareTo(n1
) != 0) {
8069 y
= y
.modPowInt(2, this)
8070 if (y
.compareTo(BigInteger
.ONE
) == 0) return false
8072 if (y
.compareTo(n1
) != 0) return false
8079 proto
.chunkSize
= bnpChunkSize
8080 proto
.toRadix
= bnpToRadix
8081 proto
.fromRadix
= bnpFromRadix
8082 proto
.fromNumber
= bnpFromNumber
8083 proto
.bitwiseTo
= bnpBitwiseTo
8084 proto
.changeBit
= bnpChangeBit
8085 proto
.addTo
= bnpAddTo
8086 proto
.dMultiply
= bnpDMultiply
8087 proto
.dAddOffset
= bnpDAddOffset
8088 proto
.multiplyLowerTo
= bnpMultiplyLowerTo
8089 proto
.multiplyUpperTo
= bnpMultiplyUpperTo
8090 proto
.modInt
= bnpModInt
8091 proto
.millerRabin
= bnpMillerRabin
8094 proto
.clone
= bnClone
8095 proto
.intValue
= bnIntValue
8096 proto
.byteValue
= bnByteValue
8097 proto
.shortValue
= bnShortValue
8098 proto
.signum
= bnSigNum
8099 proto
.toByteArray
= bnToByteArray
8100 proto
.equals
= bnEquals
8106 proto
.andNot
= bnAndNot
8108 proto
.shiftLeft
= bnShiftLeft
8109 proto
.shiftRight
= bnShiftRight
8110 proto
.getLowestSetBit
= bnGetLowestSetBit
8111 proto
.bitCount
= bnBitCount
8112 proto
.testBit
= bnTestBit
8113 proto
.setBit
= bnSetBit
8114 proto
.clearBit
= bnClearBit
8115 proto
.flipBit
= bnFlipBit
8117 proto
.subtract
= bnSubtract
8118 proto
.multiply
= bnMultiply
8119 proto
.divide
= bnDivide
8120 proto
.remainder
= bnRemainder
8121 proto
.divideAndRemainder
= bnDivideAndRemainder
8122 proto
.modPow
= bnModPow
8123 proto
.modInverse
= bnModInverse
8126 proto
.isProbablePrime
= bnIsProbablePrime
8128 // JSBN-specific extension
8129 proto
.square
= bnSquare
8132 BigInteger
.ZERO
= nbv(0)
8133 BigInteger
.ONE
= nbv(1)
8134 BigInteger
.valueOf
= nbv
8136 module
.exports
= BigInteger
8138 },{"../package.json":40}],38:[function(require
,module
,exports
){
8140 // FIXME: Kind of a weird way to throw exceptions, consider removing
8141 var assert
= require('assert')
8142 var BigInteger
= require('./bigi')
8145 * Turns a byte array into a big integer.
8147 * This function will interpret a byte array as a big integer in big
8150 BigInteger
.fromByteArrayUnsigned = function(byteArray
) {
8151 // BigInteger expects a DER integer conformant byte array
8152 if (byteArray
[0] & 0x80) {
8153 return new BigInteger([0].concat(byteArray
))
8156 return new BigInteger(byteArray
)
8160 * Returns a byte array representation of the big integer.
8162 * This returns the absolute of the contained value in big endian
8163 * form. A value of zero results in an empty array.
8165 BigInteger
.prototype.toByteArrayUnsigned = function() {
8166 var byteArray
= this.toByteArray()
8167 return byteArray
[0] === 0 ? byteArray
.slice(1) : byteArray
8170 BigInteger
.fromDERInteger = function(byteArray
) {
8171 return new BigInteger(byteArray
)
8175 * Converts BigInteger to a DER integer representation.
8177 * The format for this value uses the most significant bit as a sign
8178 * bit. If the most significant bit is already set and the integer is
8179 * positive, a 0x00 is prepended.
8195 * -62300 => 0xff0ca4
8197 BigInteger
.prototype.toDERInteger
= BigInteger
.prototype.toByteArray
8199 BigInteger
.fromBuffer = function(buffer
) {
8200 // BigInteger expects a DER integer conformant byte array
8201 if (buffer
[0] & 0x80) {
8202 var byteArray
= Array
.prototype.slice
.call(buffer
)
8204 return new BigInteger([0].concat(byteArray
))
8207 return new BigInteger(buffer
)
8210 BigInteger
.fromHex = function(hex
) {
8211 if (hex
=== '') return BigInteger
.ZERO
8213 assert
.equal(hex
, hex
.match(/^[A-Fa-f0-9]+/), 'Invalid hex string')
8214 assert
.equal(hex
.length
% 2, 0, 'Incomplete hex')
8215 return new BigInteger(hex
, 16)
8218 BigInteger
.prototype.toBuffer = function(size
) {
8219 var byteArray
= this.toByteArrayUnsigned()
8222 var padding
= size
- byteArray
.length
8223 while (zeros
.length
< padding
) zeros
.push(0)
8225 return new Buffer(zeros
.concat(byteArray
))
8228 BigInteger
.prototype.toHex = function(size
) {
8229 return this.toBuffer(size
).toString('hex')
8232 }).call(this,require("buffer").Buffer
)
8233 },{"./bigi":37,"assert":1,"buffer":5}],39:[function(require
,module
,exports
){
8234 var BigInteger
= require('./bigi')
8237 require('./convert')
8239 module
.exports
= BigInteger
8240 },{"./bigi":37,"./convert":38}],40:[function(require
,module
,exports
){
8245 "/home/ian/git/bitcoin/bitcoinjs-lib-browser"
8248 "_from": "bigi@latest",
8249 "_id": "bigi@1.4.2",
8251 "_installable": true,
8252 "_location": "/bigi",
8253 "_nodeVersion": "6.1.0",
8254 "_npmOperationalInternal": {
8255 "host": "packages-12-west.internal.npmjs.com",
8256 "tmp": "tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"
8259 "email": "jprichardson@gmail.com",
8260 "name": "jprichardson"
8262 "_npmVersion": "3.8.6",
8263 "_phantomChildren": {},
8277 "_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
8278 "_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
8279 "_shrinkwrap": null,
8281 "_where": "/home/ian/git/bitcoin/bitcoinjs-lib-browser",
8283 "url": "https://github.com/cryptocoinjs/bigi/issues"
8286 "description": "Big integers.",
8287 "devDependencies": {
8288 "coveralls": "^2.11.2",
8289 "istanbul": "^0.3.5",
8296 "shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
8297 "tarball": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
8299 "gitHead": "c25308081c896ff84702303722bf5ecd8b3f78e3",
8300 "homepage": "https://github.com/cryptocoinjs/bigi#readme",
8318 "main": "./lib/index.js",
8321 "email": "boydb@midnightdesign.ws",
8322 "name": "midnightlightning"
8325 "email": "sidazhang89@gmail.com",
8329 "email": "npm@shesek.info",
8333 "email": "jprichardson@gmail.com",
8334 "name": "jprichardson"
8338 "optionalDependencies": {},
8339 "readme": "ERROR: No README data found!",
8342 "url": "git+https://github.com/cryptocoinjs/bigi.git"
8345 "browser-test": "mochify --wd -R spec",
8346 "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
8347 "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
8348 "jshint": "jshint --config jshint.json lib/*.js ; true",
8349 "test": "_mocha -- test/*.js",
8357 "safari/6.0..latest",
8358 "iphone/6.0..latest",
8359 "android-browser/4.2..latest"
8361 "files": "test/*.js",
8367 },{}],41:[function(require
,module
,exports
){
8368 // Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
8369 // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
8370 // NOTE: SIGHASH byte ignored AND restricted, truncate before use
8372 var Buffer
= require('safe-buffer').Buffer
8374 function check (buffer
) {
8375 if (buffer
.length
< 8) return false
8376 if (buffer
.length
> 72) return false
8377 if (buffer
[0] !== 0x30) return false
8378 if (buffer
[1] !== buffer
.length
- 2) return false
8379 if (buffer
[2] !== 0x02) return false
8381 var lenR
= buffer
[3]
8382 if (lenR
=== 0) return false
8383 if (5 + lenR
>= buffer
.length
) return false
8384 if (buffer
[4 + lenR
] !== 0x02) return false
8386 var lenS
= buffer
[5 + lenR
]
8387 if (lenS
=== 0) return false
8388 if ((6 + lenR
+ lenS
) !== buffer
.length
) return false
8390 if (buffer
[4] & 0x80) return false
8391 if (lenR
> 1 && (buffer
[4] === 0x00) && !(buffer
[5] & 0x80)) return false
8393 if (buffer
[lenR
+ 6] & 0x80) return false
8394 if (lenS
> 1 && (buffer
[lenR
+ 6] === 0x00) && !(buffer
[lenR
+ 7] & 0x80)) return false
8398 function decode (buffer
) {
8399 if (buffer
.length
< 8) throw new Error('DER sequence length is too short')
8400 if (buffer
.length
> 72) throw new Error('DER sequence length is too long')
8401 if (buffer
[0] !== 0x30) throw new Error('Expected DER sequence')
8402 if (buffer
[1] !== buffer
.length
- 2) throw new Error('DER sequence length is invalid')
8403 if (buffer
[2] !== 0x02) throw new Error('Expected DER integer')
8405 var lenR
= buffer
[3]
8406 if (lenR
=== 0) throw new Error('R length is zero')
8407 if (5 + lenR
>= buffer
.length
) throw new Error('R length is too long')
8408 if (buffer
[4 + lenR
] !== 0x02) throw new Error('Expected DER integer (2)')
8410 var lenS
= buffer
[5 + lenR
]
8411 if (lenS
=== 0) throw new Error('S length is zero')
8412 if ((6 + lenR
+ lenS
) !== buffer
.length
) throw new Error('S length is invalid')
8414 if (buffer
[4] & 0x80) throw new Error('R value is negative')
8415 if (lenR
> 1 && (buffer
[4] === 0x00) && !(buffer
[5] & 0x80)) throw new Error('R value excessively padded')
8417 if (buffer
[lenR
+ 6] & 0x80) throw new Error('S value is negative')
8418 if (lenS
> 1 && (buffer
[lenR
+ 6] === 0x00) && !(buffer
[lenR
+ 7] & 0x80)) throw new Error('S value excessively padded')
8420 // non-BIP66 - extract R, S values
8422 r: buffer
.slice(4, 4 + lenR
),
8423 s: buffer
.slice(6 + lenR
)
8428 * Expects r and s to be positive DER integers.
8430 * The DER format uses the most significant bit as a sign bit (& 0x80).
8431 * If the significant bit is set AND the integer is positive, a 0x00 is prepended.
8447 * -62300 => 0xff0ca4
8449 function encode (r
, s
) {
8452 if (lenR
=== 0) throw new Error('R length is zero')
8453 if (lenS
=== 0) throw new Error('S length is zero')
8454 if (lenR
> 33) throw new Error('R length is too long')
8455 if (lenS
> 33) throw new Error('S length is too long')
8456 if (r
[0] & 0x80) throw new Error('R value is negative')
8457 if (s
[0] & 0x80) throw new Error('S value is negative')
8458 if (lenR
> 1 && (r
[0] === 0x00) && !(r
[1] & 0x80)) throw new Error('R value excessively padded')
8459 if (lenS
> 1 && (s
[0] === 0x00) && !(s
[1] & 0x80)) throw new Error('S value excessively padded')
8461 var signature
= Buffer
.allocUnsafe(6 + lenR
+ lenS
)
8463 // 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
8465 signature
[1] = signature
.length
- 2
8467 signature
[3] = r
.length
8468 r
.copy(signature
, 4)
8469 signature
[4 + lenR
] = 0x02
8470 signature
[5 + lenR
] = s
.length
8471 s
.copy(signature
, 6 + lenR
)
8482 },{"safe-buffer":128}],42:[function(require
,module
,exports
){
8520 "OP_TOALTSTACK": 107,
8521 "OP_FROMALTSTACK": 108,
8551 "OP_EQUALVERIFY": 136,
8552 "OP_RESERVED1": 137,
8553 "OP_RESERVED2": 138,
8562 "OP_0NOTEQUAL": 146,
8574 "OP_NUMEQUALVERIFY": 157,
8575 "OP_NUMNOTEQUAL": 158,
8577 "OP_GREATERTHAN": 160,
8578 "OP_LESSTHANOREQUAL": 161,
8579 "OP_GREATERTHANOREQUAL": 162,
8585 "OP_RIPEMD160": 166,
8590 "OP_CODESEPARATOR": 171,
8592 "OP_CHECKSIGVERIFY": 173,
8593 "OP_CHECKMULTISIG": 174,
8594 "OP_CHECKMULTISIGVERIFY": 175,
8598 "OP_CHECKLOCKTIMEVERIFY": 177,
8609 "OP_PUBKEYHASH": 253,
8611 "OP_INVALIDOPCODE": 255
8614 },{}],43:[function(require
,module
,exports
){
8615 var OPS
= require('./index.json')
8618 for (var op
in OPS
) {
8623 module
.exports
= map
8625 },{"./index.json":42}],44:[function(require
,module
,exports
){
8626 var Buffer
= require('safe-buffer').Buffer
8627 var bech32
= require('bech32')
8628 var bs58check
= require('bs58check')
8629 var bscript
= require('./script')
8630 var btemplates
= require('./templates')
8631 var networks
= require('./networks')
8632 var typeforce
= require('typeforce')
8633 var types
= require('./types')
8635 function fromBase58Check (address
) {
8636 var payload
= bs58check
.decode(address
)
8638 // TODO: 4.0.0, move to "toOutputScript"
8639 if (payload
.length
< 21) throw new TypeError(address
+ ' is too short')
8640 if (payload
.length
> 21) throw new TypeError(address
+ ' is too long')
8642 var version
= payload
.readUInt8(0)
8643 var hash
= payload
.slice(1)
8645 return { version: version
, hash: hash
}
8648 function fromBech32 (address
) {
8649 var result
= bech32
.decode(address
)
8650 var data
= bech32
.fromWords(result
.words
.slice(1))
8653 version: result
.words
[0],
8654 prefix: result
.prefix
,
8655 data: Buffer
.from(data
)
8659 function toBase58Check (hash
, version
) {
8660 typeforce(types
.tuple(types
.Hash160bit
, types
.UInt8
), arguments
)
8662 var payload
= Buffer
.allocUnsafe(21)
8663 payload
.writeUInt8(version
, 0)
8664 hash
.copy(payload
, 1)
8666 return bs58check
.encode(payload
)
8669 function toBech32 (data
, version
, prefix
) {
8670 var words
= bech32
.toWords(data
)
8671 words
.unshift(version
)
8673 return bech32
.encode(prefix
, words
)
8676 function fromOutputScript (outputScript
, network
) {
8677 network
= network
|| networks
.bitcoin
8679 if (btemplates
.pubKeyHash
.output
.check(outputScript
)) return toBase58Check(bscript
.compile(outputScript
).slice(3, 23), network
.pubKeyHash
)
8680 if (btemplates
.scriptHash
.output
.check(outputScript
)) return toBase58Check(bscript
.compile(outputScript
).slice(2, 22), network
.scriptHash
)
8681 if (btemplates
.witnessPubKeyHash
.output
.check(outputScript
)) return toBech32(bscript
.compile(outputScript
).slice(2, 22), 0, network
.bech32
)
8682 if (btemplates
.witnessScriptHash
.output
.check(outputScript
)) return toBech32(bscript
.compile(outputScript
).slice(2, 34), 0, network
.bech32
)
8684 throw new Error(bscript
.toASM(outputScript
) + ' has no matching Address')
8687 function toOutputScript (address
, network
) {
8688 network
= network
|| networks
.bitcoin
8692 decode
= fromBase58Check(address
)
8696 if (decode
.version
=== network
.pubKeyHash
) return btemplates
.pubKeyHash
.output
.encode(decode
.hash
)
8697 if (decode
.version
=== network
.scriptHash
) return btemplates
.scriptHash
.output
.encode(decode
.hash
)
8700 decode
= fromBech32(address
)
8704 if (decode
.prefix
!== network
.bech32
) throw new Error(address
+ ' has an invalid prefix')
8705 if (decode
.version
=== 0) {
8706 if (decode
.data
.length
=== 20) return btemplates
.witnessPubKeyHash
.output
.encode(decode
.data
)
8707 if (decode
.data
.length
=== 32) return btemplates
.witnessScriptHash
.output
.encode(decode
.data
)
8712 throw new Error(address
+ ' has no matching Script')
8716 fromBase58Check: fromBase58Check
,
8717 fromBech32: fromBech32
,
8718 fromOutputScript: fromOutputScript
,
8719 toBase58Check: toBase58Check
,
8721 toOutputScript: toOutputScript
8724 },{"./networks":53,"./script":54,"./templates":56,"./types":80,"bech32":36,"bs58check":85,"safe-buffer":128,"typeforce":139}],45:[function(require
,module
,exports
){
8725 var Buffer
= require('safe-buffer').Buffer
8726 var bcrypto
= require('./crypto')
8727 var fastMerkleRoot
= require('merkle-lib/fastRoot')
8728 var typeforce
= require('typeforce')
8729 var types
= require('./types')
8730 var varuint
= require('varuint-bitcoin')
8732 var Transaction
= require('./transaction')
8736 this.prevHash
= null
8737 this.merkleRoot
= null
8743 Block
.fromBuffer = function (buffer
) {
8744 if (buffer
.length
< 80) throw new Error('Buffer too small (< 80 bytes)')
8747 function readSlice (n
) {
8749 return buffer
.slice(offset
- n
, offset
)
8752 function readUInt32 () {
8753 var i
= buffer
.readUInt32LE(offset
)
8758 function readInt32 () {
8759 var i
= buffer
.readInt32LE(offset
)
8764 var block
= new Block()
8765 block
.version
= readInt32()
8766 block
.prevHash
= readSlice(32)
8767 block
.merkleRoot
= readSlice(32)
8768 block
.timestamp
= readUInt32()
8769 block
.bits
= readUInt32()
8770 block
.nonce
= readUInt32()
8772 if (buffer
.length
=== 80) return block
8774 function readVarInt () {
8775 var vi
= varuint
.decode(buffer
, offset
)
8776 offset
+= varuint
.decode
.bytes
8780 function readTransaction () {
8781 var tx
= Transaction
.fromBuffer(buffer
.slice(offset
), true)
8782 offset
+= tx
.byteLength()
8786 var nTransactions
= readVarInt()
8787 block
.transactions
= []
8789 for (var i
= 0; i
< nTransactions
; ++i
) {
8790 var tx
= readTransaction()
8791 block
.transactions
.push(tx
)
8797 Block
.prototype.byteLength = function (headersOnly
) {
8798 if (headersOnly
|| !this.transactions
) return 80
8800 return 80 + varuint
.encodingLength(this.transactions
.length
) + this.transactions
.reduce(function (a
, x
) {
8801 return a
+ x
.byteLength()
8805 Block
.fromHex = function (hex
) {
8806 return Block
.fromBuffer(Buffer
.from(hex
, 'hex'))
8809 Block
.prototype.getHash = function () {
8810 return bcrypto
.hash256(this.toBuffer(true))
8813 Block
.prototype.getId = function () {
8814 return this.getHash().reverse().toString('hex')
8817 Block
.prototype.getUTCDate = function () {
8818 var date
= new Date(0) // epoch
8819 date
.setUTCSeconds(this.timestamp
)
8824 // TODO: buffer, offset compatibility
8825 Block
.prototype.toBuffer = function (headersOnly
) {
8826 var buffer
= Buffer
.allocUnsafe(this.byteLength(headersOnly
))
8829 function writeSlice (slice
) {
8830 slice
.copy(buffer
, offset
)
8831 offset
+= slice
.length
8834 function writeInt32 (i
) {
8835 buffer
.writeInt32LE(i
, offset
)
8838 function writeUInt32 (i
) {
8839 buffer
.writeUInt32LE(i
, offset
)
8843 writeInt32(this.version
)
8844 writeSlice(this.prevHash
)
8845 writeSlice(this.merkleRoot
)
8846 writeUInt32(this.timestamp
)
8847 writeUInt32(this.bits
)
8848 writeUInt32(this.nonce
)
8850 if (headersOnly
|| !this.transactions
) return buffer
8852 varuint
.encode(this.transactions
.length
, buffer
, offset
)
8853 offset
+= varuint
.encode
.bytes
8855 this.transactions
.forEach(function (tx
) {
8856 var txSize
= tx
.byteLength() // TODO: extract from toBuffer?
8857 tx
.toBuffer(buffer
, offset
)
8864 Block
.prototype.toHex = function (headersOnly
) {
8865 return this.toBuffer(headersOnly
).toString('hex')
8868 Block
.calculateTarget = function (bits
) {
8869 var exponent
= ((bits
& 0xff000000) >> 24) - 3
8870 var mantissa
= bits
& 0x007fffff
8871 var target
= Buffer
.alloc(32, 0)
8872 target
.writeUInt32BE(mantissa
, 28 - exponent
)
8876 Block
.calculateMerkleRoot = function (transactions
) {
8877 typeforce([{ getHash: types
.Function
}], transactions
)
8878 if (transactions
.length
=== 0) throw TypeError('Cannot compute merkle root for zero transactions')
8880 var hashes
= transactions
.map(function (transaction
) {
8881 return transaction
.getHash()
8884 return fastMerkleRoot(hashes
, bcrypto
.hash256
)
8887 Block
.prototype.checkMerkleRoot = function () {
8888 if (!this.transactions
) return false
8890 var actualMerkleRoot
= Block
.calculateMerkleRoot(this.transactions
)
8891 return this.merkleRoot
.compare(actualMerkleRoot
) === 0
8894 Block
.prototype.checkProofOfWork = function () {
8895 var hash
= this.getHash().reverse()
8896 var target
= Block
.calculateTarget(this.bits
)
8898 return hash
.compare(target
) <= 0
8901 module
.exports
= Block
8903 },{"./crypto":47,"./transaction":78,"./types":80,"merkle-lib/fastRoot":122,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],46:[function(require
,module
,exports
){
8904 var pushdata
= require('pushdata-bitcoin')
8905 var varuint
= require('varuint-bitcoin')
8907 // https://github.com/feross/buffer/blob/master/index.js#L1127
8908 function verifuint (value
, max
) {
8909 if (typeof value
!== 'number') throw new Error('cannot write a non-number as a number')
8910 if (value
< 0) throw new Error('specified a negative value for writing an unsigned value')
8911 if (value
> max
) throw new Error('RangeError: value out of range')
8912 if (Math
.floor(value
) !== value
) throw new Error('value has a fractional component')
8915 function readUInt64LE (buffer
, offset
) {
8916 var a
= buffer
.readUInt32LE(offset
)
8917 var b
= buffer
.readUInt32LE(offset
+ 4)
8920 verifuint(b
+ a
, 0x001fffffffffffff)
8925 function writeUInt64LE (buffer
, value
, offset
) {
8926 verifuint(value
, 0x001fffffffffffff)
8928 buffer
.writeInt32LE(value
& -1, offset
)
8929 buffer
.writeUInt32LE(Math
.floor(value
/ 0x100000000), offset
+ 4)
8933 // TODO: remove in 4.0.0?
8934 function readVarInt (buffer
, offset
) {
8935 var result
= varuint
.decode(buffer
, offset
)
8939 size: varuint
.decode
.bytes
8943 // TODO: remove in 4.0.0?
8944 function writeVarInt (buffer
, number
, offset
) {
8945 varuint
.encode(number
, buffer
, offset
)
8946 return varuint
.encode
.bytes
8950 pushDataSize: pushdata
.encodingLength
,
8951 readPushDataInt: pushdata
.decode
,
8952 readUInt64LE: readUInt64LE
,
8953 readVarInt: readVarInt
,
8954 varIntBuffer: varuint
.encode
,
8955 varIntSize: varuint
.encodingLength
,
8956 writePushDataInt: pushdata
.encode
,
8957 writeUInt64LE: writeUInt64LE
,
8958 writeVarInt: writeVarInt
8961 },{"pushdata-bitcoin":125,"varuint-bitcoin":141}],47:[function(require
,module
,exports
){
8962 var createHash
= require('create-hash')
8964 function ripemd160 (buffer
) {
8965 return createHash('rmd160').update(buffer
).digest()
8968 function sha1 (buffer
) {
8969 return createHash('sha1').update(buffer
).digest()
8972 function sha256 (buffer
) {
8973 return createHash('sha256').update(buffer
).digest()
8976 function hash160 (buffer
) {
8977 return ripemd160(sha256(buffer
))
8980 function hash256 (buffer
) {
8981 return sha256(sha256(buffer
))
8987 ripemd160: ripemd160
,
8992 },{"create-hash":87}],48:[function(require
,module
,exports
){
8993 var Buffer
= require('safe-buffer').Buffer
8994 var createHmac
= require('create-hmac')
8995 var typeforce
= require('typeforce')
8996 var types
= require('./types')
8998 var BigInteger
= require('bigi')
8999 var ECSignature
= require('./ecsignature')
9001 var ZERO
= Buffer
.alloc(1, 0)
9002 var ONE
= Buffer
.alloc(1, 1)
9004 var ecurve
= require('ecurve')
9005 var secp256k1
= ecurve
.getCurveByName('secp256k1')
9007 // https://tools.ietf.org/html/rfc6979#section-3.2
9008 function deterministicGenerateK (hash
, x
, checkSig
) {
9009 typeforce(types
.tuple(
9015 // Step A, ignored as hash already provided
9018 var k
= Buffer
.alloc(32, 0)
9019 var v
= Buffer
.alloc(32, 1)
9022 k
= createHmac('sha256', k
)
9030 v
= createHmac('sha256', k
).update(v
).digest()
9033 k
= createHmac('sha256', k
)
9041 v
= createHmac('sha256', k
).update(v
).digest()
9043 // Step H1/H2a, ignored as tlen === qlen (256 bit)
9045 v
= createHmac('sha256', k
).update(v
).digest()
9047 var T
= BigInteger
.fromBuffer(v
)
9049 // Step H3, repeat until T is within the interval [1, n - 1] and is suitable for ECDSA
9050 while (T
.signum() <= 0 || T
.compareTo(secp256k1
.n
) >= 0 || !checkSig(T
)) {
9051 k
= createHmac('sha256', k
)
9056 v
= createHmac('sha256', k
).update(v
).digest()
9058 // Step H1/H2a, again, ignored as tlen === qlen (256 bit)
9060 v
= createHmac('sha256', k
).update(v
).digest()
9061 T
= BigInteger
.fromBuffer(v
)
9067 var N_OVER_TWO
= secp256k1
.n
.shiftRight(1)
9069 function sign (hash
, d
) {
9070 typeforce(types
.tuple(types
.Hash256bit
, types
.BigInt
), arguments
)
9072 var x
= d
.toBuffer(32)
9073 var e
= BigInteger
.fromBuffer(hash
)
9078 deterministicGenerateK(hash
, x
, function (k
) {
9079 var Q
= G
.multiply(k
)
9081 if (secp256k1
.isInfinity(Q
)) return false
9083 r
= Q
.affineX
.mod(n
)
9084 if (r
.signum() === 0) return false
9086 s
= k
.modInverse(n
).multiply(e
.add(d
.multiply(r
))).mod(n
)
9087 if (s
.signum() === 0) return false
9092 // enforce low S values, see bip62: 'low s values in signatures'
9093 if (s
.compareTo(N_OVER_TWO
) > 0) {
9097 return new ECSignature(r
, s
)
9100 function verify (hash
, signature
, Q
) {
9101 typeforce(types
.tuple(
9113 // 1.4.1 Enforce r and s are both integers in the interval [1, n − 1]
9114 if (r
.signum() <= 0 || r
.compareTo(n
) >= 0) return false
9115 if (s
.signum() <= 0 || s
.compareTo(n
) >= 0) return false
9117 // 1.4.2 H = Hash(M), already done by the user
9119 var e
= BigInteger
.fromBuffer(hash
)
9122 var sInv
= s
.modInverse(n
)
9124 // 1.4.4 Compute u1 = es^−1 mod n
9125 // u2 = rs^−1 mod n
9126 var u1
= e
.multiply(sInv
).mod(n
)
9127 var u2
= r
.multiply(sInv
).mod(n
)
9129 // 1.4.5 Compute R = (xR, yR)
9131 var R
= G
.multiplyTwo(u1
, Q
, u2
)
9133 // 1.4.5 (cont.) Enforce R is not at infinity
9134 if (secp256k1
.isInfinity(R
)) return false
9136 // 1.4.6 Convert the field element R.x to an integer
9139 // 1.4.7 Set v = xR mod n
9142 // 1.4.8 If v = r, output "valid", and if v != r, output "invalid"
9147 deterministicGenerateK: deterministicGenerateK
,
9155 },{"./ecsignature":50,"./types":80,"bigi":39,"create-hmac":90,"ecurve":94,"safe-buffer":128,"typeforce":139}],49:[function(require
,module
,exports
){
9156 var baddress
= require('./address')
9157 var bcrypto
= require('./crypto')
9158 var ecdsa
= require('./ecdsa')
9159 var randomBytes
= require('randombytes')
9160 var typeforce
= require('typeforce')
9161 var types
= require('./types')
9162 var wif
= require('wif')
9164 var NETWORKS
= require('./networks')
9165 var BigInteger
= require('bigi')
9167 var ecurve
= require('ecurve')
9168 var secp256k1
= ecdsa
.__curve
9170 function ECPair (d
, Q
, options
) {
9173 compressed: types
.maybe(types
.Boolean
),
9174 network: types
.maybe(types
.Network
)
9178 options
= options
|| {}
9181 if (d
.signum() <= 0) throw new Error('Private key must be greater than 0')
9182 if (d
.compareTo(secp256k1
.n
) >= 0) throw new Error('Private key must be less than the curve order')
9183 if (Q
) throw new TypeError('Unexpected publicKey parameter')
9187 typeforce(types
.ECPoint
, Q
)
9192 this.compressed
= options
.compressed
=== undefined ? true : options
.compressed
9193 this.network
= options
.network
|| NETWORKS
.bitcoin
9196 Object
.defineProperty(ECPair
.prototype, 'Q', {
9198 if (!this.__Q
&& this.d
) {
9199 this.__Q
= secp256k1
.G
.multiply(this.d
)
9206 ECPair
.fromPublicKeyBuffer = function (buffer
, network
) {
9207 var Q
= ecurve
.Point
.decodeFrom(secp256k1
, buffer
)
9209 return new ECPair(null, Q
, {
9210 compressed: Q
.compressed
,
9215 ECPair
.fromWIF = function (string
, network
) {
9216 var decoded
= wif
.decode(string
)
9217 var version
= decoded
.version
9219 // list of networks?
9220 if (types
.Array(network
)) {
9221 network
= network
.filter(function (x
) {
9222 return version
=== x
.wif
9225 if (!network
) throw new Error('Unknown network version')
9227 // otherwise, assume a network object (or default to bitcoin)
9229 network
= network
|| NETWORKS
.bitcoin
9231 if (version
!== network
.wif
) throw new Error('Invalid network version')
9234 var d
= BigInteger
.fromBuffer(decoded
.privateKey
)
9236 return new ECPair(d
, null, {
9237 compressed: decoded
.compressed
,
9242 ECPair
.makeRandom = function (options
) {
9243 options
= options
|| {}
9245 var rng
= options
.rng
|| randomBytes
9249 var buffer
= rng(32)
9250 typeforce(types
.Buffer256bit
, buffer
)
9252 d
= BigInteger
.fromBuffer(buffer
)
9253 } while (d
.signum() <= 0 || d
.compareTo(secp256k1
.n
) >= 0)
9255 return new ECPair(d
, null, options
)
9258 ECPair
.prototype.getAddress = function () {
9259 return baddress
.toBase58Check(bcrypto
.hash160(this.getPublicKeyBuffer()), this.getNetwork().pubKeyHash
)
9262 ECPair
.prototype.getNetwork = function () {
9266 ECPair
.prototype.getPublicKeyBuffer = function () {
9267 return this.Q
.getEncoded(this.compressed
)
9270 ECPair
.prototype.sign = function (hash
) {
9271 if (!this.d
) throw new Error('Missing private key')
9273 return ecdsa
.sign(hash
, this.d
)
9276 ECPair
.prototype.toWIF = function () {
9277 if (!this.d
) throw new Error('Missing private key')
9279 return wif
.encode(this.network
.wif
, this.d
.toBuffer(32), this.compressed
)
9282 ECPair
.prototype.verify = function (hash
, signature
) {
9283 return ecdsa
.verify(hash
, signature
, this.Q
)
9286 module
.exports
= ECPair
9288 },{"./address":44,"./crypto":47,"./ecdsa":48,"./networks":53,"./types":80,"bigi":39,"ecurve":94,"randombytes":126,"typeforce":139,"wif":142}],50:[function(require
,module
,exports
){
9290 var bip66
= require('bip66')
9291 var typeforce
= require('typeforce')
9292 var types
= require('./types')
9294 var BigInteger
= require('bigi')
9296 function ECSignature (r
, s
) {
9297 typeforce(types
.tuple(types
.BigInt
, types
.BigInt
), arguments
)
9303 ECSignature
.parseCompact = function (buffer
) {
9304 typeforce(types
.BufferN(65), buffer
)
9306 var flagByte
= buffer
.readUInt8(0) - 27
9307 if (flagByte
!== (flagByte
& 7)) throw new Error('Invalid signature parameter')
9309 var compressed
= !!(flagByte
& 4)
9310 var recoveryParam
= flagByte
& 3
9311 var signature
= ECSignature
.fromRSBuffer(buffer
.slice(1))
9314 compressed: compressed
,
9316 signature: signature
9320 ECSignature
.fromRSBuffer = function (buffer
) {
9321 typeforce(types
.BufferN(64), buffer
)
9323 var r
= BigInteger
.fromBuffer(buffer
.slice(0, 32))
9324 var s
= BigInteger
.fromBuffer(buffer
.slice(32, 64))
9325 return new ECSignature(r
, s
)
9328 ECSignature
.fromDER = function (buffer
) {
9329 var decode
= bip66
.decode(buffer
)
9330 var r
= BigInteger
.fromDERInteger(decode
.r
)
9331 var s
= BigInteger
.fromDERInteger(decode
.s
)
9333 return new ECSignature(r
, s
)
9336 // BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed)
9337 ECSignature
.parseScriptSignature = function (buffer
) {
9338 var hashType
= buffer
.readUInt8(buffer
.length
- 1)
9339 var hashTypeMod
= hashType
& ~0x80
9341 if (hashTypeMod
<= 0x00 || hashTypeMod
>= 0x04) throw new Error('Invalid hashType ' + hashType
)
9344 signature: ECSignature
.fromDER(buffer
.slice(0, -1)),
9349 ECSignature
.prototype.toCompact = function (i
, compressed
) {
9356 var buffer
= Buffer
.alloc(65)
9357 buffer
.writeUInt8(i
, 0)
9358 this.toRSBuffer(buffer
, 1)
9362 ECSignature
.prototype.toDER = function () {
9363 var r
= Buffer
.from(this.r
.toDERInteger())
9364 var s
= Buffer
.from(this.s
.toDERInteger())
9366 return bip66
.encode(r
, s
)
9369 ECSignature
.prototype.toRSBuffer = function (buffer
, offset
) {
9370 buffer
= buffer
|| Buffer
.alloc(64)
9371 this.r
.toBuffer(32).copy(buffer
, offset
)
9372 this.s
.toBuffer(32).copy(buffer
, offset
+ 32)
9376 ECSignature
.prototype.toScriptSignature = function (hashType
) {
9377 var hashTypeMod
= hashType
& ~0x80
9378 if (hashTypeMod
<= 0 || hashTypeMod
>= 4) throw new Error('Invalid hashType ' + hashType
)
9380 var hashTypeBuffer
= Buffer
.alloc(1)
9381 hashTypeBuffer
.writeUInt8(hashType
, 0)
9383 return Buffer
.concat([this.toDER(), hashTypeBuffer
])
9386 module
.exports
= ECSignature
9388 }).call(this,require("buffer").Buffer
)
9389 },{"./types":80,"bigi":39,"bip66":41,"buffer":5,"typeforce":139}],51:[function(require
,module
,exports
){
9390 var Buffer
= require('safe-buffer').Buffer
9391 var base58check
= require('bs58check')
9392 var bcrypto
= require('./crypto')
9393 var createHmac
= require('create-hmac')
9394 var typeforce
= require('typeforce')
9395 var types
= require('./types')
9396 var NETWORKS
= require('./networks')
9398 var BigInteger
= require('bigi')
9399 var ECPair
= require('./ecpair')
9401 var ecurve
= require('ecurve')
9402 var curve
= ecurve
.getCurveByName('secp256k1')
9404 function HDNode (keyPair
, chainCode
) {
9405 typeforce(types
.tuple('ECPair', types
.Buffer256bit
), arguments
)
9407 if (!keyPair
.compressed
) throw new TypeError('BIP32 only allows compressed keyPairs')
9409 this.keyPair
= keyPair
9410 this.chainCode
= chainCode
9413 this.parentFingerprint
= 0x00000000
9416 HDNode
.HIGHEST_BIT
= 0x80000000
9418 HDNode
.MASTER_SECRET
= Buffer
.from('Bitcoin seed', 'utf8')
9420 HDNode
.fromSeedBuffer = function (seed
, network
) {
9421 typeforce(types
.tuple(types
.Buffer
, types
.maybe(types
.Network
)), arguments
)
9423 if (seed
.length
< 16) throw new TypeError('Seed should be at least 128 bits')
9424 if (seed
.length
> 64) throw new TypeError('Seed should be at most 512 bits')
9426 var I
= createHmac('sha512', HDNode
.MASTER_SECRET
).update(seed
).digest()
9427 var IL
= I
.slice(0, 32)
9428 var IR
= I
.slice(32)
9430 // In case IL is 0 or >= n, the master key is invalid
9431 // This is handled by the ECPair constructor
9432 var pIL
= BigInteger
.fromBuffer(IL
)
9433 var keyPair
= new ECPair(pIL
, null, {
9437 return new HDNode(keyPair
, IR
)
9440 HDNode
.fromSeedHex = function (hex
, network
) {
9441 return HDNode
.fromSeedBuffer(Buffer
.from(hex
, 'hex'), network
)
9444 HDNode
.fromBase58 = function (string
, networks
) {
9445 var buffer
= base58check
.decode(string
)
9446 if (buffer
.length
!== 78) throw new Error('Invalid buffer length')
9448 // 4 bytes: version bytes
9449 var version
= buffer
.readUInt32BE(0)
9452 // list of networks?
9453 if (Array
.isArray(networks
)) {
9454 network
= networks
.filter(function (x
) {
9455 return version
=== x
.bip32
.private ||
9456 version
=== x
.bip32
.public
9459 if (!network
) throw new Error('Unknown network version')
9461 // otherwise, assume a network object (or default to bitcoin)
9463 network
= networks
|| NETWORKS
.bitcoin
9466 if (version
!== network
.bip32
.private &&
9467 version
!== network
.bip32
.public) throw new Error('Invalid network version')
9469 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ...
9470 var depth
= buffer
[4]
9472 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
9473 var parentFingerprint
= buffer
.readUInt32BE(5)
9475 if (parentFingerprint
!== 0x00000000) throw new Error('Invalid parent fingerprint')
9478 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
9479 // This is encoded in MSB order. (0x00000000 if master key)
9480 var index
= buffer
.readUInt32BE(9)
9481 if (depth
=== 0 && index
!== 0) throw new Error('Invalid index')
9483 // 32 bytes: the chain code
9484 var chainCode
= buffer
.slice(13, 45)
9487 // 33 bytes: private key data (0x00 + k)
9488 if (version
=== network
.bip32
.private) {
9489 if (buffer
.readUInt8(45) !== 0x00) throw new Error('Invalid private key')
9491 var d
= BigInteger
.fromBuffer(buffer
.slice(46, 78))
9492 keyPair
= new ECPair(d
, null, { network: network
})
9494 // 33 bytes: public key data (0x02 + X or 0x03 + X)
9496 var Q
= ecurve
.Point
.decodeFrom(curve
, buffer
.slice(45, 78))
9497 // Q.compressed is assumed, if somehow this assumption is broken, `new HDNode` will throw
9499 // Verify that the X coordinate in the public point corresponds to a point on the curve.
9500 // If not, the extended public key is invalid.
9503 keyPair
= new ECPair(null, Q
, { network: network
})
9506 var hd
= new HDNode(keyPair
, chainCode
)
9509 hd
.parentFingerprint
= parentFingerprint
9514 HDNode
.prototype.getAddress = function () {
9515 return this.keyPair
.getAddress()
9518 HDNode
.prototype.getIdentifier = function () {
9519 return bcrypto
.hash160(this.keyPair
.getPublicKeyBuffer())
9522 HDNode
.prototype.getFingerprint = function () {
9523 return this.getIdentifier().slice(0, 4)
9526 HDNode
.prototype.getNetwork = function () {
9527 return this.keyPair
.getNetwork()
9530 HDNode
.prototype.getPublicKeyBuffer = function () {
9531 return this.keyPair
.getPublicKeyBuffer()
9534 HDNode
.prototype.neutered = function () {
9535 var neuteredKeyPair
= new ECPair(null, this.keyPair
.Q
, {
9536 network: this.keyPair
.network
9539 var neutered
= new HDNode(neuteredKeyPair
, this.chainCode
)
9540 neutered
.depth
= this.depth
9541 neutered
.index
= this.index
9542 neutered
.parentFingerprint
= this.parentFingerprint
9547 HDNode
.prototype.sign = function (hash
) {
9548 return this.keyPair
.sign(hash
)
9551 HDNode
.prototype.verify = function (hash
, signature
) {
9552 return this.keyPair
.verify(hash
, signature
)
9555 HDNode
.prototype.toBase58 = function (__isPrivate
) {
9556 if (__isPrivate
!== undefined) throw new TypeError('Unsupported argument in 2.0.0')
9559 var network
= this.keyPair
.network
9560 var version
= (!this.isNeutered()) ? network
.bip32
.private : network
.bip32
.public
9561 var buffer
= Buffer
.allocUnsafe(78)
9563 // 4 bytes: version bytes
9564 buffer
.writeUInt32BE(version
, 0)
9566 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ....
9567 buffer
.writeUInt8(this.depth
, 4)
9569 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
9570 buffer
.writeUInt32BE(this.parentFingerprint
, 5)
9572 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
9573 // This is encoded in big endian. (0x00000000 if master key)
9574 buffer
.writeUInt32BE(this.index
, 9)
9576 // 32 bytes: the chain code
9577 this.chainCode
.copy(buffer
, 13)
9579 // 33 bytes: the public key or private key data
9580 if (!this.isNeutered()) {
9581 // 0x00 + k for private keys
9582 buffer
.writeUInt8(0, 45)
9583 this.keyPair
.d
.toBuffer(32).copy(buffer
, 46)
9585 // 33 bytes: the public key
9587 // X9.62 encoding for public keys
9588 this.keyPair
.getPublicKeyBuffer().copy(buffer
, 45)
9591 return base58check
.encode(buffer
)
9594 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
9595 HDNode
.prototype.derive = function (index
) {
9596 typeforce(types
.UInt32
, index
)
9598 var isHardened
= index
>= HDNode
.HIGHEST_BIT
9599 var data
= Buffer
.allocUnsafe(37)
9603 if (this.isNeutered()) throw new TypeError('Could not derive hardened child key')
9605 // data = 0x00 || ser256(kpar) || ser32(index)
9607 this.keyPair
.d
.toBuffer(32).copy(data
, 1)
9608 data
.writeUInt32BE(index
, 33)
9612 // data = serP(point(kpar)) || ser32(index)
9613 // = serP(Kpar) || ser32(index)
9614 this.keyPair
.getPublicKeyBuffer().copy(data
, 0)
9615 data
.writeUInt32BE(index
, 33)
9618 var I
= createHmac('sha512', this.chainCode
).update(data
).digest()
9619 var IL
= I
.slice(0, 32)
9620 var IR
= I
.slice(32)
9622 var pIL
= BigInteger
.fromBuffer(IL
)
9624 // In case parse256(IL) >= n, proceed with the next value for i
9625 if (pIL
.compareTo(curve
.n
) >= 0) {
9626 return this.derive(index
+ 1)
9629 // Private parent key -> private child key
9631 if (!this.isNeutered()) {
9632 // ki = parse256(IL) + kpar (mod n)
9633 var ki
= pIL
.add(this.keyPair
.d
).mod(curve
.n
)
9635 // In case ki == 0, proceed with the next value for i
9636 if (ki
.signum() === 0) {
9637 return this.derive(index
+ 1)
9640 derivedKeyPair
= new ECPair(ki
, null, {
9641 network: this.keyPair
.network
9644 // Public parent key -> public child key
9646 // Ki = point(parse256(IL)) + Kpar
9648 var Ki
= curve
.G
.multiply(pIL
).add(this.keyPair
.Q
)
9650 // In case Ki is the point at infinity, proceed with the next value for i
9651 if (curve
.isInfinity(Ki
)) {
9652 return this.derive(index
+ 1)
9655 derivedKeyPair
= new ECPair(null, Ki
, {
9656 network: this.keyPair
.network
9660 var hd
= new HDNode(derivedKeyPair
, IR
)
9661 hd
.depth
= this.depth
+ 1
9663 hd
.parentFingerprint
= this.getFingerprint().readUInt32BE(0)
9668 HDNode
.prototype.deriveHardened = function (index
) {
9669 typeforce(types
.UInt31
, index
)
9671 // Only derives hardened private keys by default
9672 return this.derive(index
+ HDNode
.HIGHEST_BIT
)
9675 // Private === not neutered
9676 // Public === neutered
9677 HDNode
.prototype.isNeutered = function () {
9678 return !(this.keyPair
.d
)
9681 HDNode
.prototype.derivePath = function (path
) {
9682 typeforce(types
.BIP32Path
, path
)
9684 var splitPath
= path
.split('/')
9685 if (splitPath
[0] === 'm') {
9686 if (this.parentFingerprint
) {
9687 throw new Error('Not a master node')
9690 splitPath
= splitPath
.slice(1)
9693 return splitPath
.reduce(function (prevHd
, indexStr
) {
9695 if (indexStr
.slice(-1) === "'") {
9696 index
= parseInt(indexStr
.slice(0, -1), 10)
9697 return prevHd
.deriveHardened(index
)
9699 index
= parseInt(indexStr
, 10)
9700 return prevHd
.derive(index
)
9705 module
.exports
= HDNode
9707 },{"./crypto":47,"./ecpair":49,"./networks":53,"./types":80,"bigi":39,"bs58check":85,"create-hmac":90,"ecurve":94,"safe-buffer":128,"typeforce":139}],52:[function(require
,module
,exports
){
9708 var script
= require('./script')
9710 var templates
= require('./templates')
9711 for (var key
in templates
) {
9712 script
[key
] = templates
[key
]
9716 bufferutils: require('./bufferutils'), // TODO: remove in 4.0.0
9718 Block: require('./block'),
9719 ECPair: require('./ecpair'),
9720 ECSignature: require('./ecsignature'),
9721 HDNode: require('./hdnode'),
9722 Transaction: require('./transaction'),
9723 TransactionBuilder: require('./transaction_builder'),
9725 address: require('./address'),
9726 crypto: require('./crypto'),
9727 networks: require('./networks'),
9728 opcodes: require('bitcoin-ops'),
9732 },{"./address":44,"./block":45,"./bufferutils":46,"./crypto":47,"./ecpair":49,"./ecsignature":50,"./hdnode":51,"./networks":53,"./script":54,"./templates":56,"./transaction":78,"./transaction_builder":79,"bitcoin-ops":42}],53:[function(require
,module
,exports
){
9733 // https://en.bitcoin.it/wiki/List_of_address_prefixes
9734 // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
9738 messagePrefix: '\x18Bitcoin Signed Message:\n',
9749 messagePrefix: '\x18Bitcoin Signed Message:\n',
9760 messagePrefix: '\x19Litecoin Signed Message:\n',
9771 },{}],54:[function(require
,module
,exports
){
9772 var Buffer
= require('safe-buffer').Buffer
9773 var bip66
= require('bip66')
9774 var pushdata
= require('pushdata-bitcoin')
9775 var typeforce
= require('typeforce')
9776 var types
= require('./types')
9777 var scriptNumber
= require('./script_number')
9779 var OPS
= require('bitcoin-ops')
9780 var REVERSE_OPS
= require('bitcoin-ops/map')
9781 var OP_INT_BASE
= OPS
.OP_RESERVED
// OP_1 - 1
9783 function isOPInt (value
) {
9784 return types
.Number(value
) &&
9785 ((value
=== OPS
.OP_0
) ||
9786 (value
>= OPS
.OP_1
&& value
<= OPS
.OP_16
) ||
9787 (value
=== OPS
.OP_1NEGATE
))
9790 function isPushOnlyChunk (value
) {
9791 return types
.Buffer(value
) || isOPInt(value
)
9794 function isPushOnly (value
) {
9795 return types
.Array(value
) && value
.every(isPushOnlyChunk
)
9798 function asMinimalOP (buffer
) {
9799 if (buffer
.length
=== 0) return OPS
.OP_0
9800 if (buffer
.length
!== 1) return
9801 if (buffer
[0] >= 1 && buffer
[0] <= 16) return OP_INT_BASE
+ buffer
[0]
9802 if (buffer
[0] === 0x81) return OPS
.OP_1NEGATE
9805 function compile (chunks
) {
9807 if (Buffer
.isBuffer(chunks
)) return chunks
9809 typeforce(types
.Array
, chunks
)
9811 var bufferSize
= chunks
.reduce(function (accum
, chunk
) {
9813 if (Buffer
.isBuffer(chunk
)) {
9814 // adhere to BIP62.3, minimal push policy
9815 if (chunk
.length
=== 1 && asMinimalOP(chunk
) !== undefined) {
9819 return accum
+ pushdata
.encodingLength(chunk
.length
) + chunk
.length
9826 var buffer
= Buffer
.allocUnsafe(bufferSize
)
9829 chunks
.forEach(function (chunk
) {
9831 if (Buffer
.isBuffer(chunk
)) {
9832 // adhere to BIP62.3, minimal push policy
9833 var opcode
= asMinimalOP(chunk
)
9834 if (opcode
!== undefined) {
9835 buffer
.writeUInt8(opcode
, offset
)
9840 offset
+= pushdata
.encode(buffer
, chunk
.length
, offset
)
9841 chunk
.copy(buffer
, offset
)
9842 offset
+= chunk
.length
9846 buffer
.writeUInt8(chunk
, offset
)
9851 if (offset
!== buffer
.length
) throw new Error('Could not decode chunks')
9855 function decompile (buffer
) {
9857 if (types
.Array(buffer
)) return buffer
9859 typeforce(types
.Buffer
, buffer
)
9864 while (i
< buffer
.length
) {
9865 var opcode
= buffer
[i
]
9868 if ((opcode
> OPS
.OP_0
) && (opcode
<= OPS
.OP_PUSHDATA4
)) {
9869 var d
= pushdata
.decode(buffer
, i
)
9871 // did reading a pushDataInt fail? empty script
9872 if (d
=== null) return []
9875 // attempt to read too much data? empty script
9876 if (i
+ d
.number
> buffer
.length
) return []
9878 var data
= buffer
.slice(i
, i
+ d
.number
)
9881 // decompile minimally
9882 var op
= asMinimalOP(data
)
9883 if (op
!== undefined) {
9900 function toASM (chunks
) {
9901 if (Buffer
.isBuffer(chunks
)) {
9902 chunks
= decompile(chunks
)
9905 return chunks
.map(function (chunk
) {
9907 if (Buffer
.isBuffer(chunk
)) {
9908 var op
= asMinimalOP(chunk
)
9909 if (op
=== undefined) return chunk
.toString('hex')
9914 return REVERSE_OPS
[chunk
]
9918 function fromASM (asm
) {
9919 typeforce(types
.String
, asm
)
9921 return compile(asm
.split(' ').map(function (chunkStr
) {
9923 if (OPS
[chunkStr
] !== undefined) return OPS
[chunkStr
]
9924 typeforce(types
.Hex
, chunkStr
)
9927 return Buffer
.from(chunkStr
, 'hex')
9931 function toStack (chunks
) {
9932 chunks
= decompile(chunks
)
9933 typeforce(isPushOnly
, chunks
)
9935 return chunks
.map(function (op
) {
9936 if (Buffer
.isBuffer(op
)) return op
9937 if (op
=== OPS
.OP_0
) return Buffer
.allocUnsafe(0)
9939 return scriptNumber
.encode(op
- OP_INT_BASE
)
9943 function isCanonicalPubKey (buffer
) {
9944 if (!Buffer
.isBuffer(buffer
)) return false
9945 if (buffer
.length
< 33) return false
9947 switch (buffer
[0]) {
9950 return buffer
.length
=== 33
9952 return buffer
.length
=== 65
9958 function isDefinedHashType (hashType
) {
9959 var hashTypeMod
= hashType
& ~0x80
9961 // return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE
9962 return hashTypeMod
> 0x00 && hashTypeMod
< 0x04
9965 function isCanonicalSignature (buffer
) {
9966 if (!Buffer
.isBuffer(buffer
)) return false
9967 if (!isDefinedHashType(buffer
[buffer
.length
- 1])) return false
9969 return bip66
.check(buffer
.slice(0, -1))
9974 decompile: decompile
,
9979 number: require('./script_number'),
9981 isCanonicalPubKey: isCanonicalPubKey
,
9982 isCanonicalSignature: isCanonicalSignature
,
9983 isPushOnly: isPushOnly
,
9984 isDefinedHashType: isDefinedHashType
9987 },{"./script_number":55,"./types":80,"bip66":41,"bitcoin-ops":42,"bitcoin-ops/map":43,"pushdata-bitcoin":125,"safe-buffer":128,"typeforce":139}],55:[function(require
,module
,exports
){
9988 var Buffer
= require('safe-buffer').Buffer
9990 function decode (buffer
, maxLength
, minimal
) {
9991 maxLength
= maxLength
|| 4
9992 minimal
= minimal
=== undefined ? true : minimal
9994 var length
= buffer
.length
9995 if (length
=== 0) return 0
9996 if (length
> maxLength
) throw new TypeError('Script number overflow')
9998 if ((buffer
[length
- 1] & 0x7f) === 0) {
9999 if (length
<= 1 || (buffer
[length
- 2] & 0x80) === 0) throw new Error('Non-minimally encoded script number')
10004 if (length
=== 5) {
10005 var a
= buffer
.readUInt32LE(0)
10006 var b
= buffer
.readUInt8(4)
10008 if (b
& 0x80) return -(((b
& ~0x80) * 0x100000000) + a
)
10009 return (b
* 0x100000000) + a
10014 // 32-bit / 24-bit / 16-bit / 8-bit
10015 for (var i
= 0; i
< length
; ++i
) {
10016 result
|= buffer
[i
] << (8 * i
)
10019 if (buffer
[length
- 1] & 0x80) return -(result
& ~(0x80 << (8 * (length
- 1))))
10023 function scriptNumSize (i
) {
10024 return i
> 0x7fffffff ? 5
10032 function encode (number
) {
10033 var value
= Math
.abs(number
)
10034 var size
= scriptNumSize(value
)
10035 var buffer
= Buffer
.allocUnsafe(size
)
10036 var negative
= number
< 0
10038 for (var i
= 0; i
< size
; ++i
) {
10039 buffer
.writeUInt8(value
& 0xff, i
)
10043 if (buffer
[size
- 1] & 0x80) {
10044 buffer
.writeUInt8(negative
? 0x80 : 0x00, size
- 1)
10045 } else if (negative
) {
10046 buffer
[size
- 1] |= 0x80
10057 },{"safe-buffer":128}],56:[function(require
,module
,exports
){
10058 var decompile
= require('../script').decompile
10059 var multisig
= require('./multisig')
10060 var nullData
= require('./nulldata')
10061 var pubKey
= require('./pubkey')
10062 var pubKeyHash
= require('./pubkeyhash')
10063 var scriptHash
= require('./scripthash')
10064 var witnessPubKeyHash
= require('./witnesspubkeyhash')
10065 var witnessScriptHash
= require('./witnessscripthash')
10066 var witnessCommitment
= require('./witnesscommitment')
10069 MULTISIG: 'multisig',
10070 NONSTANDARD: 'nonstandard',
10071 NULLDATA: 'nulldata',
10073 P2PKH: 'pubkeyhash',
10074 P2SH: 'scripthash',
10075 P2WPKH: 'witnesspubkeyhash',
10076 P2WSH: 'witnessscripthash',
10077 WITNESS_COMMITMENT: 'witnesscommitment'
10080 function classifyOutput (script
) {
10081 if (witnessPubKeyHash
.output
.check(script
)) return types
.P2WPKH
10082 if (witnessScriptHash
.output
.check(script
)) return types
.P2WSH
10083 if (pubKeyHash
.output
.check(script
)) return types
.P2PKH
10084 if (scriptHash
.output
.check(script
)) return types
.P2SH
10086 // XXX: optimization, below functions .decompile before use
10087 var chunks
= decompile(script
)
10088 if (multisig
.output
.check(chunks
)) return types
.MULTISIG
10089 if (pubKey
.output
.check(chunks
)) return types
.P2PK
10090 if (witnessCommitment
.output
.check(chunks
)) return types
.WITNESS_COMMITMENT
10091 if (nullData
.output
.check(chunks
)) return types
.NULLDATA
10093 return types
.NONSTANDARD
10096 function classifyInput (script
, allowIncomplete
) {
10097 // XXX: optimization, below functions .decompile before use
10098 var chunks
= decompile(script
)
10100 if (pubKeyHash
.input
.check(chunks
)) return types
.P2PKH
10101 if (scriptHash
.input
.check(chunks
, allowIncomplete
)) return types
.P2SH
10102 if (multisig
.input
.check(chunks
, allowIncomplete
)) return types
.MULTISIG
10103 if (pubKey
.input
.check(chunks
)) return types
.P2PK
10105 return types
.NONSTANDARD
10108 function classifyWitness (script
, allowIncomplete
) {
10109 // XXX: optimization, below functions .decompile before use
10110 var chunks
= decompile(script
)
10112 if (witnessPubKeyHash
.input
.check(chunks
)) return types
.P2WPKH
10113 if (witnessScriptHash
.input
.check(chunks
, allowIncomplete
)) return types
.P2WSH
10115 return types
.NONSTANDARD
10119 classifyInput: classifyInput
,
10120 classifyOutput: classifyOutput
,
10121 classifyWitness: classifyWitness
,
10122 multisig: multisig
,
10123 nullData: nullData
,
10125 pubKeyHash: pubKeyHash
,
10126 scriptHash: scriptHash
,
10127 witnessPubKeyHash: witnessPubKeyHash
,
10128 witnessScriptHash: witnessScriptHash
,
10129 witnessCommitment: witnessCommitment
,
10133 },{"../script":54,"./multisig":57,"./nulldata":60,"./pubkey":61,"./pubkeyhash":64,"./scripthash":67,"./witnesscommitment":70,"./witnesspubkeyhash":72,"./witnessscripthash":75}],57:[function(require
,module
,exports
){
10135 input: require('./input'),
10136 output: require('./output')
10139 },{"./input":58,"./output":59}],58:[function(require
,module
,exports
){
10140 // OP_0 [signatures ...]
10142 var Buffer
= require('safe-buffer').Buffer
10143 var bscript
= require('../../script')
10144 var p2mso
= require('./output')
10145 var typeforce
= require('typeforce')
10146 var OPS
= require('bitcoin-ops')
10148 function partialSignature (value
) {
10149 return value
=== OPS
.OP_0
|| bscript
.isCanonicalSignature(value
)
10152 function check (script
, allowIncomplete
) {
10153 var chunks
= bscript
.decompile(script
)
10154 if (chunks
.length
< 2) return false
10155 if (chunks
[0] !== OPS
.OP_0
) return false
10157 if (allowIncomplete
) {
10158 return chunks
.slice(1).every(partialSignature
)
10161 return chunks
.slice(1).every(bscript
.isCanonicalSignature
)
10163 check
.toJSON = function () { return 'multisig input' }
10165 var EMPTY_BUFFER
= Buffer
.allocUnsafe(0)
10167 function encodeStack (signatures
, scriptPubKey
) {
10168 typeforce([partialSignature
], signatures
)
10170 if (scriptPubKey
) {
10171 var scriptData
= p2mso
.decode(scriptPubKey
)
10173 if (signatures
.length
< scriptData
.m
) {
10174 throw new TypeError('Not enough signatures provided')
10177 if (signatures
.length
> scriptData
.pubKeys
.length
) {
10178 throw new TypeError('Too many signatures provided')
10182 return [].concat(EMPTY_BUFFER
, signatures
.map(function (sig
) {
10183 if (sig
=== OPS
.OP_0
) {
10184 return EMPTY_BUFFER
10190 function encode (signatures
, scriptPubKey
) {
10191 return bscript
.compile(encodeStack(signatures
, scriptPubKey
))
10194 function decodeStack (stack
, allowIncomplete
) {
10195 typeforce(check
, stack
, allowIncomplete
)
10196 return stack
.slice(1)
10199 function decode (buffer
, allowIncomplete
) {
10200 var stack
= bscript
.decompile(buffer
)
10201 return decodeStack(stack
, allowIncomplete
)
10207 decodeStack: decodeStack
,
10209 encodeStack: encodeStack
10212 },{"../../script":54,"./output":59,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],59:[function(require
,module
,exports
){
10213 // m [pubKeys ...] n OP_CHECKMULTISIG
10215 var bscript
= require('../../script')
10216 var types
= require('../../types')
10217 var typeforce
= require('typeforce')
10218 var OPS
= require('bitcoin-ops')
10219 var OP_INT_BASE
= OPS
.OP_RESERVED
// OP_1 - 1
10221 function check (script
, allowIncomplete
) {
10222 var chunks
= bscript
.decompile(script
)
10224 if (chunks
.length
< 4) return false
10225 if (chunks
[chunks
.length
- 1] !== OPS
.OP_CHECKMULTISIG
) return false
10226 if (!types
.Number(chunks
[0])) return false
10227 if (!types
.Number(chunks
[chunks
.length
- 2])) return false
10228 var m
= chunks
[0] - OP_INT_BASE
10229 var n
= chunks
[chunks
.length
- 2] - OP_INT_BASE
10231 if (m
<= 0) return false
10232 if (n
> 16) return false
10233 if (m
> n
) return false
10234 if (n
!== chunks
.length
- 3) return false
10235 if (allowIncomplete
) return true
10237 var keys
= chunks
.slice(1, -2)
10238 return keys
.every(bscript
.isCanonicalPubKey
)
10240 check
.toJSON = function () { return 'multi-sig output' }
10242 function encode (m
, pubKeys
) {
10245 pubKeys: [bscript
.isCanonicalPubKey
]
10251 var n
= pubKeys
.length
10252 if (n
< m
) throw new TypeError('Not enough pubKeys provided')
10254 return bscript
.compile([].concat(
10258 OPS
.OP_CHECKMULTISIG
10262 function decode (buffer
, allowIncomplete
) {
10263 var chunks
= bscript
.decompile(buffer
)
10264 typeforce(check
, chunks
, allowIncomplete
)
10267 m: chunks
[0] - OP_INT_BASE
,
10268 pubKeys: chunks
.slice(1, -2)
10278 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],60:[function(require
,module
,exports
){
10279 // OP_RETURN {data}
10281 var bscript
= require('../script')
10282 var types
= require('../types')
10283 var typeforce
= require('typeforce')
10284 var OPS
= require('bitcoin-ops')
10286 function check (script
) {
10287 var buffer
= bscript
.compile(script
)
10289 return buffer
.length
> 1 &&
10290 buffer
[0] === OPS
.OP_RETURN
10292 check
.toJSON = function () { return 'null data output' }
10294 function encode (data
) {
10295 typeforce(types
.Buffer
, data
)
10297 return bscript
.compile([OPS
.OP_RETURN
, data
])
10300 function decode (buffer
) {
10301 typeforce(check
, buffer
)
10303 return buffer
.slice(2)
10314 },{"../script":54,"../types":80,"bitcoin-ops":42,"typeforce":139}],61:[function(require
,module
,exports
){
10315 arguments
[4][57][0].apply(exports
,arguments
)
10316 },{"./input":62,"./output":63,"dup":57}],62:[function(require
,module
,exports
){
10319 var bscript
= require('../../script')
10320 var typeforce
= require('typeforce')
10322 function check (script
) {
10323 var chunks
= bscript
.decompile(script
)
10325 return chunks
.length
=== 1 &&
10326 bscript
.isCanonicalSignature(chunks
[0])
10328 check
.toJSON = function () { return 'pubKey input' }
10330 function encodeStack (signature
) {
10331 typeforce(bscript
.isCanonicalSignature
, signature
)
10335 function encode (signature
) {
10336 return bscript
.compile(encodeStack(signature
))
10339 function decodeStack (stack
) {
10340 typeforce(check
, stack
)
10344 function decode (buffer
) {
10345 var stack
= bscript
.decompile(buffer
)
10346 return decodeStack(stack
)
10352 decodeStack: decodeStack
,
10354 encodeStack: encodeStack
10357 },{"../../script":54,"typeforce":139}],63:[function(require
,module
,exports
){
10358 // {pubKey} OP_CHECKSIG
10360 var bscript
= require('../../script')
10361 var typeforce
= require('typeforce')
10362 var OPS
= require('bitcoin-ops')
10364 function check (script
) {
10365 var chunks
= bscript
.decompile(script
)
10367 return chunks
.length
=== 2 &&
10368 bscript
.isCanonicalPubKey(chunks
[0]) &&
10369 chunks
[1] === OPS
.OP_CHECKSIG
10371 check
.toJSON = function () { return 'pubKey output' }
10373 function encode (pubKey
) {
10374 typeforce(bscript
.isCanonicalPubKey
, pubKey
)
10376 return bscript
.compile([pubKey
, OPS
.OP_CHECKSIG
])
10379 function decode (buffer
) {
10380 var chunks
= bscript
.decompile(buffer
)
10381 typeforce(check
, chunks
)
10392 },{"../../script":54,"bitcoin-ops":42,"typeforce":139}],64:[function(require
,module
,exports
){
10393 arguments
[4][57][0].apply(exports
,arguments
)
10394 },{"./input":65,"./output":66,"dup":57}],65:[function(require
,module
,exports
){
10395 // {signature} {pubKey}
10397 var bscript
= require('../../script')
10398 var typeforce
= require('typeforce')
10400 function check (script
) {
10401 var chunks
= bscript
.decompile(script
)
10403 return chunks
.length
=== 2 &&
10404 bscript
.isCanonicalSignature(chunks
[0]) &&
10405 bscript
.isCanonicalPubKey(chunks
[1])
10407 check
.toJSON = function () { return 'pubKeyHash input' }
10409 function encodeStack (signature
, pubKey
) {
10411 signature: bscript
.isCanonicalSignature
,
10412 pubKey: bscript
.isCanonicalPubKey
10414 signature: signature
,
10418 return [signature
, pubKey
]
10421 function encode (signature
, pubKey
) {
10422 return bscript
.compile(encodeStack(signature
, pubKey
))
10425 function decodeStack (stack
) {
10426 typeforce(check
, stack
)
10429 signature: stack
[0],
10434 function decode (buffer
) {
10435 var stack
= bscript
.decompile(buffer
)
10436 return decodeStack(stack
)
10442 decodeStack: decodeStack
,
10444 encodeStack: encodeStack
10447 },{"../../script":54,"typeforce":139}],66:[function(require
,module
,exports
){
10448 // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
10450 var bscript
= require('../../script')
10451 var types
= require('../../types')
10452 var typeforce
= require('typeforce')
10453 var OPS
= require('bitcoin-ops')
10455 function check (script
) {
10456 var buffer
= bscript
.compile(script
)
10458 return buffer
.length
=== 25 &&
10459 buffer
[0] === OPS
.OP_DUP
&&
10460 buffer
[1] === OPS
.OP_HASH160
&&
10461 buffer
[2] === 0x14 &&
10462 buffer
[23] === OPS
.OP_EQUALVERIFY
&&
10463 buffer
[24] === OPS
.OP_CHECKSIG
10465 check
.toJSON = function () { return 'pubKeyHash output' }
10467 function encode (pubKeyHash
) {
10468 typeforce(types
.Hash160bit
, pubKeyHash
)
10470 return bscript
.compile([
10474 OPS
.OP_EQUALVERIFY
,
10479 function decode (buffer
) {
10480 typeforce(check
, buffer
)
10482 return buffer
.slice(3, 23)
10491 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],67:[function(require
,module
,exports
){
10492 arguments
[4][57][0].apply(exports
,arguments
)
10493 },{"./input":68,"./output":69,"dup":57}],68:[function(require
,module
,exports
){
10494 // <scriptSig> {serialized scriptPubKey script}
10496 var Buffer
= require('safe-buffer').Buffer
10497 var bscript
= require('../../script')
10498 var typeforce
= require('typeforce')
10500 var p2ms
= require('../multisig/')
10501 var p2pk
= require('../pubkey/')
10502 var p2pkh
= require('../pubkeyhash/')
10503 var p2wpkho
= require('../witnesspubkeyhash/output')
10504 var p2wsho
= require('../witnessscripthash/output')
10506 function check (script
, allowIncomplete
) {
10507 var chunks
= bscript
.decompile(script
)
10508 if (chunks
.length
< 1) return false
10510 var lastChunk
= chunks
[chunks
.length
- 1]
10511 if (!Buffer
.isBuffer(lastChunk
)) return false
10513 var scriptSigChunks
= bscript
.decompile(bscript
.compile(chunks
.slice(0, -1)))
10514 var redeemScriptChunks
= bscript
.decompile(lastChunk
)
10516 // is redeemScript a valid script?
10517 if (redeemScriptChunks
.length
=== 0) return false
10519 // is redeemScriptSig push only?
10520 if (!bscript
.isPushOnly(scriptSigChunks
)) return false
10523 if (chunks
.length
=== 1) {
10524 return p2wsho
.check(redeemScriptChunks
) ||
10525 p2wpkho
.check(redeemScriptChunks
)
10529 if (p2pkh
.input
.check(scriptSigChunks
) &&
10530 p2pkh
.output
.check(redeemScriptChunks
)) return true
10532 if (p2ms
.input
.check(scriptSigChunks
, allowIncomplete
) &&
10533 p2ms
.output
.check(redeemScriptChunks
)) return true
10535 if (p2pk
.input
.check(scriptSigChunks
) &&
10536 p2pk
.output
.check(redeemScriptChunks
)) return true
10540 check
.toJSON = function () { return 'scriptHash input' }
10542 function encodeStack (redeemScriptStack
, redeemScript
) {
10543 var serializedScriptPubKey
= bscript
.compile(redeemScript
)
10545 return [].concat(redeemScriptStack
, serializedScriptPubKey
)
10548 function encode (redeemScriptSig
, redeemScript
) {
10549 var redeemScriptStack
= bscript
.decompile(redeemScriptSig
)
10551 return bscript
.compile(encodeStack(redeemScriptStack
, redeemScript
))
10554 function decodeStack (stack
) {
10555 typeforce(check
, stack
)
10558 redeemScriptStack: stack
.slice(0, -1),
10559 redeemScript: stack
[stack
.length
- 1]
10563 function decode (buffer
) {
10564 var stack
= bscript
.decompile(buffer
)
10565 var result
= decodeStack(stack
)
10566 result
.redeemScriptSig
= bscript
.compile(result
.redeemScriptStack
)
10567 delete result
.redeemScriptStack
10574 decodeStack: decodeStack
,
10576 encodeStack: encodeStack
10579 },{"../../script":54,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"../witnesspubkeyhash/output":74,"../witnessscripthash/output":77,"safe-buffer":128,"typeforce":139}],69:[function(require
,module
,exports
){
10580 // OP_HASH160 {scriptHash} OP_EQUAL
10582 var bscript
= require('../../script')
10583 var types
= require('../../types')
10584 var typeforce
= require('typeforce')
10585 var OPS
= require('bitcoin-ops')
10587 function check (script
) {
10588 var buffer
= bscript
.compile(script
)
10590 return buffer
.length
=== 23 &&
10591 buffer
[0] === OPS
.OP_HASH160
&&
10592 buffer
[1] === 0x14 &&
10593 buffer
[22] === OPS
.OP_EQUAL
10595 check
.toJSON = function () { return 'scriptHash output' }
10597 function encode (scriptHash
) {
10598 typeforce(types
.Hash160bit
, scriptHash
)
10600 return bscript
.compile([OPS
.OP_HASH160
, scriptHash
, OPS
.OP_EQUAL
])
10603 function decode (buffer
) {
10604 typeforce(check
, buffer
)
10606 return buffer
.slice(2, 22)
10615 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],70:[function(require
,module
,exports
){
10617 output: require('./output')
10620 },{"./output":71}],71:[function(require
,module
,exports
){
10621 // OP_RETURN {aa21a9ed} {commitment}
10623 var Buffer
= require('safe-buffer').Buffer
10624 var bscript
= require('../../script')
10625 var types
= require('../../types')
10626 var typeforce
= require('typeforce')
10627 var OPS
= require('bitcoin-ops')
10629 var HEADER
= Buffer
.from('aa21a9ed', 'hex')
10631 function check (script
) {
10632 var buffer
= bscript
.compile(script
)
10634 return buffer
.length
> 37 &&
10635 buffer
[0] === OPS
.OP_RETURN
&&
10636 buffer
[1] === 0x24 &&
10637 buffer
.slice(2, 6).equals(HEADER
)
10640 check
.toJSON = function () { return 'Witness commitment output' }
10642 function encode (commitment
) {
10643 typeforce(types
.Hash256bit
, commitment
)
10645 var buffer
= Buffer
.allocUnsafe(36)
10646 HEADER
.copy(buffer
, 0)
10647 commitment
.copy(buffer
, 4)
10649 return bscript
.compile([OPS
.OP_RETURN
, buffer
])
10652 function decode (buffer
) {
10653 typeforce(check
, buffer
)
10655 return bscript
.decompile(buffer
)[1].slice(4, 36)
10664 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],72:[function(require
,module
,exports
){
10665 arguments
[4][57][0].apply(exports
,arguments
)
10666 },{"./input":73,"./output":74,"dup":57}],73:[function(require
,module
,exports
){
10667 // {signature} {pubKey}
10669 var bscript
= require('../../script')
10670 var typeforce
= require('typeforce')
10672 function isCompressedCanonicalPubKey (pubKey
) {
10673 return bscript
.isCanonicalPubKey(pubKey
) && pubKey
.length
=== 33
10676 function check (script
) {
10677 var chunks
= bscript
.decompile(script
)
10679 return chunks
.length
=== 2 &&
10680 bscript
.isCanonicalSignature(chunks
[0]) &&
10681 isCompressedCanonicalPubKey(chunks
[1])
10683 check
.toJSON = function () { return 'witnessPubKeyHash input' }
10685 function encodeStack (signature
, pubKey
) {
10687 signature: bscript
.isCanonicalSignature
,
10688 pubKey: isCompressedCanonicalPubKey
10690 signature: signature
,
10694 return [signature
, pubKey
]
10697 function decodeStack (stack
) {
10698 typeforce(check
, stack
)
10701 signature: stack
[0],
10708 decodeStack: decodeStack
,
10709 encodeStack: encodeStack
10712 },{"../../script":54,"typeforce":139}],74:[function(require
,module
,exports
){
10713 // OP_0 {pubKeyHash}
10715 var bscript
= require('../../script')
10716 var types
= require('../../types')
10717 var typeforce
= require('typeforce')
10718 var OPS
= require('bitcoin-ops')
10720 function check (script
) {
10721 var buffer
= bscript
.compile(script
)
10723 return buffer
.length
=== 22 &&
10724 buffer
[0] === OPS
.OP_0
&&
10727 check
.toJSON = function () { return 'Witness pubKeyHash output' }
10729 function encode (pubKeyHash
) {
10730 typeforce(types
.Hash160bit
, pubKeyHash
)
10732 return bscript
.compile([OPS
.OP_0
, pubKeyHash
])
10735 function decode (buffer
) {
10736 typeforce(check
, buffer
)
10738 return buffer
.slice(2)
10747 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],75:[function(require
,module
,exports
){
10748 arguments
[4][57][0].apply(exports
,arguments
)
10749 },{"./input":76,"./output":77,"dup":57}],76:[function(require
,module
,exports
){
10750 (function (Buffer
){
10751 // <scriptSig> {serialized scriptPubKey script}
10753 var bscript
= require('../../script')
10754 var types
= require('../../types')
10755 var typeforce
= require('typeforce')
10757 var p2ms
= require('../multisig/')
10758 var p2pk
= require('../pubkey/')
10759 var p2pkh
= require('../pubkeyhash/')
10761 function check (chunks
, allowIncomplete
) {
10762 typeforce(types
.Array
, chunks
)
10763 if (chunks
.length
< 1) return false
10765 var witnessScript
= chunks
[chunks
.length
- 1]
10766 if (!Buffer
.isBuffer(witnessScript
)) return false
10768 var witnessScriptChunks
= bscript
.decompile(witnessScript
)
10770 // is witnessScript a valid script?
10771 if (witnessScriptChunks
.length
=== 0) return false
10773 var witnessRawScriptSig
= bscript
.compile(chunks
.slice(0, -1))
10776 if (p2pkh
.input
.check(witnessRawScriptSig
) &&
10777 p2pkh
.output
.check(witnessScriptChunks
)) return true
10779 if (p2ms
.input
.check(witnessRawScriptSig
, allowIncomplete
) &&
10780 p2ms
.output
.check(witnessScriptChunks
)) return true
10782 if (p2pk
.input
.check(witnessRawScriptSig
) &&
10783 p2pk
.output
.check(witnessScriptChunks
)) return true
10787 check
.toJSON = function () { return 'witnessScriptHash input' }
10789 function encodeStack (witnessData
, witnessScript
) {
10791 witnessData: [types
.Buffer
],
10792 witnessScript: types
.Buffer
10794 witnessData: witnessData
,
10795 witnessScript: witnessScript
10798 return [].concat(witnessData
, witnessScript
)
10801 function decodeStack (chunks
) {
10802 typeforce(check
, chunks
)
10804 witnessData: chunks
.slice(0, -1),
10805 witnessScript: chunks
[chunks
.length
- 1]
10811 decodeStack: decodeStack
,
10812 encodeStack: encodeStack
10815 }).call(this,{"isBuffer":require("../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
10816 },{"../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10,"../../script":54,"../../types":80,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"typeforce":139}],77:[function(require
,module
,exports
){
10817 // OP_0 {scriptHash}
10819 var bscript
= require('../../script')
10820 var types
= require('../../types')
10821 var typeforce
= require('typeforce')
10822 var OPS
= require('bitcoin-ops')
10824 function check (script
) {
10825 var buffer
= bscript
.compile(script
)
10827 return buffer
.length
=== 34 &&
10828 buffer
[0] === OPS
.OP_0
&&
10831 check
.toJSON = function () { return 'Witness scriptHash output' }
10833 function encode (scriptHash
) {
10834 typeforce(types
.Hash256bit
, scriptHash
)
10836 return bscript
.compile([OPS
.OP_0
, scriptHash
])
10839 function decode (buffer
) {
10840 typeforce(check
, buffer
)
10842 return buffer
.slice(2)
10851 },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],78:[function(require
,module
,exports
){
10852 var Buffer
= require('safe-buffer').Buffer
10853 var bcrypto
= require('./crypto')
10854 var bscript
= require('./script')
10855 var bufferutils
= require('./bufferutils')
10856 var opcodes
= require('bitcoin-ops')
10857 var typeforce
= require('typeforce')
10858 var types
= require('./types')
10859 var varuint
= require('varuint-bitcoin')
10861 function varSliceSize (someScript
) {
10862 var length
= someScript
.length
10864 return varuint
.encodingLength(length
) + length
10867 function vectorSize (someVector
) {
10868 var length
= someVector
.length
10870 return varuint
.encodingLength(length
) + someVector
.reduce(function (sum
, witness
) {
10871 return sum
+ varSliceSize(witness
)
10875 function Transaction () {
10882 Transaction
.DEFAULT_SEQUENCE
= 0xffffffff
10883 Transaction
.SIGHASH_ALL
= 0x01
10884 Transaction
.SIGHASH_NONE
= 0x02
10885 Transaction
.SIGHASH_SINGLE
= 0x03
10886 Transaction
.SIGHASH_ANYONECANPAY
= 0x80
10887 Transaction
.ADVANCED_TRANSACTION_MARKER
= 0x00
10888 Transaction
.ADVANCED_TRANSACTION_FLAG
= 0x01
10890 var EMPTY_SCRIPT
= Buffer
.allocUnsafe(0)
10891 var EMPTY_WITNESS
= []
10892 var ZERO
= Buffer
.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
10893 var ONE
= Buffer
.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
10894 var VALUE_UINT64_MAX
= Buffer
.from('ffffffffffffffff', 'hex')
10895 var BLANK_OUTPUT
= {
10896 script: EMPTY_SCRIPT
,
10897 valueBuffer: VALUE_UINT64_MAX
10900 Transaction
.fromBuffer = function (buffer
, __noStrict
) {
10902 function readSlice (n
) {
10904 return buffer
.slice(offset
- n
, offset
)
10907 function readUInt32 () {
10908 var i
= buffer
.readUInt32LE(offset
)
10913 function readInt32 () {
10914 var i
= buffer
.readInt32LE(offset
)
10919 function readUInt64 () {
10920 var i
= bufferutils
.readUInt64LE(buffer
, offset
)
10925 function readVarInt () {
10926 var vi
= varuint
.decode(buffer
, offset
)
10927 offset
+= varuint
.decode
.bytes
10931 function readVarSlice () {
10932 return readSlice(readVarInt())
10935 function readVector () {
10936 var count
= readVarInt()
10938 for (var i
= 0; i
< count
; i
++) vector
.push(readVarSlice())
10942 var tx
= new Transaction()
10943 tx
.version
= readInt32()
10945 var marker
= buffer
.readUInt8(offset
)
10946 var flag
= buffer
.readUInt8(offset
+ 1)
10948 var hasWitnesses
= false
10949 if (marker
=== Transaction
.ADVANCED_TRANSACTION_MARKER
&&
10950 flag
=== Transaction
.ADVANCED_TRANSACTION_FLAG
) {
10952 hasWitnesses
= true
10955 var vinLen
= readVarInt()
10956 for (var i
= 0; i
< vinLen
; ++i
) {
10958 hash: readSlice(32),
10959 index: readUInt32(),
10960 script: readVarSlice(),
10961 sequence: readUInt32(),
10962 witness: EMPTY_WITNESS
10966 var voutLen
= readVarInt()
10967 for (i
= 0; i
< voutLen
; ++i
) {
10969 value: readUInt64(),
10970 script: readVarSlice()
10974 if (hasWitnesses
) {
10975 for (i
= 0; i
< vinLen
; ++i
) {
10976 tx
.ins
[i
].witness
= readVector()
10979 // was this pointless?
10980 if (!tx
.hasWitnesses()) throw new Error('Transaction has superfluous witness data')
10983 tx
.locktime
= readUInt32()
10985 if (__noStrict
) return tx
10986 if (offset
!== buffer
.length
) throw new Error('Transaction has unexpected data')
10991 Transaction
.fromHex = function (hex
) {
10992 return Transaction
.fromBuffer(Buffer
.from(hex
, 'hex'))
10995 Transaction
.isCoinbaseHash = function (buffer
) {
10996 typeforce(types
.Hash256bit
, buffer
)
10997 for (var i
= 0; i
< 32; ++i
) {
10998 if (buffer
[i
] !== 0) return false
11003 Transaction
.prototype.isCoinbase = function () {
11004 return this.ins
.length
=== 1 && Transaction
.isCoinbaseHash(this.ins
[0].hash
)
11007 Transaction
.prototype.addInput = function (hash
, index
, sequence
, scriptSig
) {
11008 typeforce(types
.tuple(
11011 types
.maybe(types
.UInt32
),
11012 types
.maybe(types
.Buffer
)
11015 if (types
.Null(sequence
)) {
11016 sequence
= Transaction
.DEFAULT_SEQUENCE
11019 // Add the input and return the input's index
11020 return (this.ins
.push({
11023 script: scriptSig
|| EMPTY_SCRIPT
,
11024 sequence: sequence
,
11025 witness: EMPTY_WITNESS
11029 Transaction
.prototype.addOutput = function (scriptPubKey
, value
) {
11030 typeforce(types
.tuple(types
.Buffer
, types
.Satoshi
), arguments
)
11032 // Add the output and return the output's index
11033 return (this.outs
.push({
11034 script: scriptPubKey
,
11039 Transaction
.prototype.hasWitnesses = function () {
11040 return this.ins
.some(function (x
) {
11041 return x
.witness
.length
!== 0
11045 Transaction
.prototype.weight = function () {
11046 var base
= this.__byteLength(false)
11047 var total
= this.__byteLength(true)
11048 return base
* 3 + total
11051 Transaction
.prototype.virtualSize = function () {
11052 return Math
.ceil(this.weight() / 4)
11055 Transaction
.prototype.byteLength = function () {
11056 return this.__byteLength(true)
11059 Transaction
.prototype.__byteLength = function (__allowWitness
) {
11060 var hasWitnesses
= __allowWitness
&& this.hasWitnesses()
11063 (hasWitnesses
? 10 : 8) +
11064 varuint
.encodingLength(this.ins
.length
) +
11065 varuint
.encodingLength(this.outs
.length
) +
11066 this.ins
.reduce(function (sum
, input
) { return sum
+ 40 + varSliceSize(input
.script
) }, 0) +
11067 this.outs
.reduce(function (sum
, output
) { return sum
+ 8 + varSliceSize(output
.script
) }, 0) +
11068 (hasWitnesses
? this.ins
.reduce(function (sum
, input
) { return sum
+ vectorSize(input
.witness
) }, 0) : 0)
11072 Transaction
.prototype.clone = function () {
11073 var newTx
= new Transaction()
11074 newTx
.version
= this.version
11075 newTx
.locktime
= this.locktime
11077 newTx
.ins
= this.ins
.map(function (txIn
) {
11081 script: txIn
.script
,
11082 sequence: txIn
.sequence
,
11083 witness: txIn
.witness
11087 newTx
.outs
= this.outs
.map(function (txOut
) {
11089 script: txOut
.script
,
11098 * Hash transaction for signing a specific input.
11100 * Bitcoin uses a different hash for each signed transaction input.
11101 * This method copies the transaction, makes the necessary changes based on the
11102 * hashType, and then hashes the result.
11103 * This hash can then be used to sign the provided transaction input.
11105 Transaction
.prototype.hashForSignature = function (inIndex
, prevOutScript
, hashType
) {
11106 typeforce(types
.tuple(types
.UInt32
, types
.Buffer
, /* types.UInt8 */ types
.Number
), arguments
)
11108 // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
11109 if (inIndex
>= this.ins
.length
) return ONE
11111 // ignore OP_CODESEPARATOR
11112 var ourScript
= bscript
.compile(bscript
.decompile(prevOutScript
).filter(function (x
) {
11113 return x
!== opcodes
.OP_CODESEPARATOR
11116 var txTmp
= this.clone()
11118 // SIGHASH_NONE: ignore all outputs? (wildcard payee)
11119 if ((hashType
& 0x1f) === Transaction
.SIGHASH_NONE
) {
11122 // ignore sequence numbers (except at inIndex)
11123 txTmp
.ins
.forEach(function (input
, i
) {
11124 if (i
=== inIndex
) return
11129 // SIGHASH_SINGLE: ignore all outputs, except at the same index?
11130 } else if ((hashType
& 0x1f) === Transaction
.SIGHASH_SINGLE
) {
11131 // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60
11132 if (inIndex
>= this.outs
.length
) return ONE
11134 // truncate outputs after
11135 txTmp
.outs
.length
= inIndex
+ 1
11137 // "blank" outputs before
11138 for (var i
= 0; i
< inIndex
; i
++) {
11139 txTmp
.outs
[i
] = BLANK_OUTPUT
11142 // ignore sequence numbers (except at inIndex)
11143 txTmp
.ins
.forEach(function (input
, y
) {
11144 if (y
=== inIndex
) return
11150 // SIGHASH_ANYONECANPAY: ignore inputs entirely?
11151 if (hashType
& Transaction
.SIGHASH_ANYONECANPAY
) {
11152 txTmp
.ins
= [txTmp
.ins
[inIndex
]]
11153 txTmp
.ins
[0].script
= ourScript
11155 // SIGHASH_ALL: only ignore input scripts
11157 // "blank" others input scripts
11158 txTmp
.ins
.forEach(function (input
) { input
.script
= EMPTY_SCRIPT
})
11159 txTmp
.ins
[inIndex
].script
= ourScript
11162 // serialize and hash
11163 var buffer
= Buffer
.allocUnsafe(txTmp
.__byteLength(false) + 4)
11164 buffer
.writeInt32LE(hashType
, buffer
.length
- 4)
11165 txTmp
.__toBuffer(buffer
, 0, false)
11167 return bcrypto
.hash256(buffer
)
11170 Transaction
.prototype.hashForWitnessV0 = function (inIndex
, prevOutScript
, value
, hashType
) {
11171 typeforce(types
.tuple(types
.UInt32
, types
.Buffer
, types
.Satoshi
, types
.UInt32
), arguments
)
11173 var tbuffer
, toffset
11174 function writeSlice (slice
) { toffset
+= slice
.copy(tbuffer
, toffset
) }
11175 function writeUInt32 (i
) { toffset
= tbuffer
.writeUInt32LE(i
, toffset
) }
11176 function writeUInt64 (i
) { toffset
= bufferutils
.writeUInt64LE(tbuffer
, i
, toffset
) }
11177 function writeVarInt (i
) {
11178 varuint
.encode(i
, tbuffer
, toffset
)
11179 toffset
+= varuint
.encode
.bytes
11181 function writeVarSlice (slice
) { writeVarInt(slice
.length
); writeSlice(slice
) }
11183 var hashOutputs
= ZERO
11184 var hashPrevouts
= ZERO
11185 var hashSequence
= ZERO
11187 if (!(hashType
& Transaction
.SIGHASH_ANYONECANPAY
)) {
11188 tbuffer
= Buffer
.allocUnsafe(36 * this.ins
.length
)
11191 this.ins
.forEach(function (txIn
) {
11192 writeSlice(txIn
.hash
)
11193 writeUInt32(txIn
.index
)
11196 hashPrevouts
= bcrypto
.hash256(tbuffer
)
11199 if (!(hashType
& Transaction
.SIGHASH_ANYONECANPAY
) &&
11200 (hashType
& 0x1f) !== Transaction
.SIGHASH_SINGLE
&&
11201 (hashType
& 0x1f) !== Transaction
.SIGHASH_NONE
) {
11202 tbuffer
= Buffer
.allocUnsafe(4 * this.ins
.length
)
11205 this.ins
.forEach(function (txIn
) {
11206 writeUInt32(txIn
.sequence
)
11209 hashSequence
= bcrypto
.hash256(tbuffer
)
11212 if ((hashType
& 0x1f) !== Transaction
.SIGHASH_SINGLE
&&
11213 (hashType
& 0x1f) !== Transaction
.SIGHASH_NONE
) {
11214 var txOutsSize
= this.outs
.reduce(function (sum
, output
) {
11215 return sum
+ 8 + varSliceSize(output
.script
)
11218 tbuffer
= Buffer
.allocUnsafe(txOutsSize
)
11221 this.outs
.forEach(function (out
) {
11222 writeUInt64(out
.value
)
11223 writeVarSlice(out
.script
)
11226 hashOutputs
= bcrypto
.hash256(tbuffer
)
11227 } else if ((hashType
& 0x1f) === Transaction
.SIGHASH_SINGLE
&& inIndex
< this.outs
.length
) {
11228 var output
= this.outs
[inIndex
]
11230 tbuffer
= Buffer
.allocUnsafe(8 + varSliceSize(output
.script
))
11232 writeUInt64(output
.value
)
11233 writeVarSlice(output
.script
)
11235 hashOutputs
= bcrypto
.hash256(tbuffer
)
11238 tbuffer
= Buffer
.allocUnsafe(156 + varSliceSize(prevOutScript
))
11241 var input
= this.ins
[inIndex
]
11242 writeUInt32(this.version
)
11243 writeSlice(hashPrevouts
)
11244 writeSlice(hashSequence
)
11245 writeSlice(input
.hash
)
11246 writeUInt32(input
.index
)
11247 writeVarSlice(prevOutScript
)
11249 writeUInt32(input
.sequence
)
11250 writeSlice(hashOutputs
)
11251 writeUInt32(this.locktime
)
11252 writeUInt32(hashType
)
11253 return bcrypto
.hash256(tbuffer
)
11256 Transaction
.prototype.getHash = function () {
11257 return bcrypto
.hash256(this.__toBuffer(undefined, undefined, false))
11260 Transaction
.prototype.getId = function () {
11261 // transaction hash's are displayed in reverse order
11262 return this.getHash().reverse().toString('hex')
11265 Transaction
.prototype.toBuffer = function (buffer
, initialOffset
) {
11266 return this.__toBuffer(buffer
, initialOffset
, true)
11269 Transaction
.prototype.__toBuffer = function (buffer
, initialOffset
, __allowWitness
) {
11270 if (!buffer
) buffer
= Buffer
.allocUnsafe(this.__byteLength(__allowWitness
))
11272 var offset
= initialOffset
|| 0
11273 function writeSlice (slice
) { offset
+= slice
.copy(buffer
, offset
) }
11274 function writeUInt8 (i
) { offset
= buffer
.writeUInt8(i
, offset
) }
11275 function writeUInt32 (i
) { offset
= buffer
.writeUInt32LE(i
, offset
) }
11276 function writeInt32 (i
) { offset
= buffer
.writeInt32LE(i
, offset
) }
11277 function writeUInt64 (i
) { offset
= bufferutils
.writeUInt64LE(buffer
, i
, offset
) }
11278 function writeVarInt (i
) {
11279 varuint
.encode(i
, buffer
, offset
)
11280 offset
+= varuint
.encode
.bytes
11282 function writeVarSlice (slice
) { writeVarInt(slice
.length
); writeSlice(slice
) }
11283 function writeVector (vector
) { writeVarInt(vector
.length
); vector
.forEach(writeVarSlice
) }
11285 writeInt32(this.version
)
11287 var hasWitnesses
= __allowWitness
&& this.hasWitnesses()
11289 if (hasWitnesses
) {
11290 writeUInt8(Transaction
.ADVANCED_TRANSACTION_MARKER
)
11291 writeUInt8(Transaction
.ADVANCED_TRANSACTION_FLAG
)
11294 writeVarInt(this.ins
.length
)
11296 this.ins
.forEach(function (txIn
) {
11297 writeSlice(txIn
.hash
)
11298 writeUInt32(txIn
.index
)
11299 writeVarSlice(txIn
.script
)
11300 writeUInt32(txIn
.sequence
)
11303 writeVarInt(this.outs
.length
)
11304 this.outs
.forEach(function (txOut
) {
11305 if (!txOut
.valueBuffer
) {
11306 writeUInt64(txOut
.value
)
11308 writeSlice(txOut
.valueBuffer
)
11311 writeVarSlice(txOut
.script
)
11314 if (hasWitnesses
) {
11315 this.ins
.forEach(function (input
) {
11316 writeVector(input
.witness
)
11320 writeUInt32(this.locktime
)
11322 // avoid slicing unless necessary
11323 if (initialOffset
!== undefined) return buffer
.slice(initialOffset
, offset
)
11327 Transaction
.prototype.toHex = function () {
11328 return this.toBuffer().toString('hex')
11331 Transaction
.prototype.setInputScript = function (index
, scriptSig
) {
11332 typeforce(types
.tuple(types
.Number
, types
.Buffer
), arguments
)
11334 this.ins
[index
].script
= scriptSig
11337 Transaction
.prototype.setWitness = function (index
, witness
) {
11338 typeforce(types
.tuple(types
.Number
, [types
.Buffer
]), arguments
)
11340 this.ins
[index
].witness
= witness
11343 module
.exports
= Transaction
11345 },{"./bufferutils":46,"./crypto":47,"./script":54,"./types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],79:[function(require
,module
,exports
){
11346 var Buffer
= require('safe-buffer').Buffer
11347 var baddress
= require('./address')
11348 var bcrypto
= require('./crypto')
11349 var bscript
= require('./script')
11350 var btemplates
= require('./templates')
11351 var networks
= require('./networks')
11352 var ops
= require('bitcoin-ops')
11353 var typeforce
= require('typeforce')
11354 var types
= require('./types')
11355 var scriptTypes
= btemplates
.types
11356 var SIGNABLE
= [btemplates
.types
.P2PKH
, btemplates
.types
.P2PK
, btemplates
.types
.MULTISIG
]
11357 var P2SH
= SIGNABLE
.concat([btemplates
.types
.P2WPKH
, btemplates
.types
.P2WSH
])
11359 var ECPair
= require('./ecpair')
11360 var ECSignature
= require('./ecsignature')
11361 var Transaction
= require('./transaction')
11363 function supportedType (type
) {
11364 return SIGNABLE
.indexOf(type
) !== -1
11367 function supportedP2SHType (type
) {
11368 return P2SH
.indexOf(type
) !== -1
11371 function extractChunks (type
, chunks
, script
) {
11373 var signatures
= []
11375 case scriptTypes
.P2PKH:
11376 // if (redeemScript) throw new Error('Nonstandard... P2SH(P2PKH)')
11377 pubKeys
= chunks
.slice(1)
11378 signatures
= chunks
.slice(0, 1)
11381 case scriptTypes
.P2PK:
11382 pubKeys
[0] = script
? btemplates
.pubKey
.output
.decode(script
) : undefined
11383 signatures
= chunks
.slice(0, 1)
11386 case scriptTypes
.MULTISIG:
11388 var multisig
= btemplates
.multisig
.output
.decode(script
)
11389 pubKeys
= multisig
.pubKeys
11392 signatures
= chunks
.slice(1).map(function (chunk
) {
11393 return chunk
.length
=== 0 ? undefined : chunk
11400 signatures: signatures
11403 function expandInput (scriptSig
, witnessStack
) {
11404 if (scriptSig
.length
=== 0 && witnessStack
.length
=== 0) return {}
11412 var witnessScriptType
11413 var redeemScriptType
11414 var witness
= false
11420 var scriptSigChunks
= bscript
.decompile(scriptSig
)
11421 var sigType
= btemplates
.classifyInput(scriptSigChunks
, true)
11422 if (sigType
=== scriptTypes
.P2SH
) {
11424 redeemScript
= scriptSigChunks
[scriptSigChunks
.length
- 1]
11425 redeemScriptType
= btemplates
.classifyOutput(redeemScript
)
11426 prevOutScript
= btemplates
.scriptHash
.output
.encode(bcrypto
.hash160(redeemScript
))
11427 prevOutType
= scriptTypes
.P2SH
11428 script
= redeemScript
11431 var classifyWitness
= btemplates
.classifyWitness(witnessStack
, true)
11432 if (classifyWitness
=== scriptTypes
.P2WSH
) {
11433 witnessScript
= witnessStack
[witnessStack
.length
- 1]
11434 witnessScriptType
= btemplates
.classifyOutput(witnessScript
)
11437 if (scriptSig
.length
=== 0) {
11438 prevOutScript
= btemplates
.witnessScriptHash
.output
.encode(bcrypto
.sha256(witnessScript
))
11439 prevOutType
= scriptTypes
.P2WSH
11440 if (redeemScript
!== undefined) {
11441 throw new Error('Redeem script given when unnecessary')
11445 if (!redeemScript
) {
11446 throw new Error('No redeemScript provided for P2WSH, but scriptSig non-empty')
11448 witnessProgram
= btemplates
.witnessScriptHash
.output
.encode(bcrypto
.sha256(witnessScript
))
11449 if (!redeemScript
.equals(witnessProgram
)) {
11450 throw new Error('Redeem script didn\'t match witnessScript')
11454 if (!supportedType(btemplates
.classifyOutput(witnessScript
))) {
11455 throw new Error('unsupported witness script')
11458 script
= witnessScript
11459 scriptType
= witnessScriptType
11460 chunks
= witnessStack
.slice(0, -1)
11461 } else if (classifyWitness
=== scriptTypes
.P2WPKH
) {
11463 var key
= witnessStack
[witnessStack
.length
- 1]
11464 var keyHash
= bcrypto
.hash160(key
)
11465 if (scriptSig
.length
=== 0) {
11466 prevOutScript
= btemplates
.witnessPubKeyHash
.output
.encode(keyHash
)
11467 prevOutType
= scriptTypes
.P2WPKH
11468 if (typeof redeemScript
!== 'undefined') {
11469 throw new Error('Redeem script given when unnecessary')
11472 if (!redeemScript
) {
11473 throw new Error('No redeemScript provided for P2WPKH, but scriptSig wasn\'t empty')
11475 witnessProgram
= btemplates
.witnessPubKeyHash
.output
.encode(keyHash
)
11476 if (!redeemScript
.equals(witnessProgram
)) {
11477 throw new Error('Redeem script did not have the right witness program')
11481 scriptType
= scriptTypes
.P2PKH
11482 chunks
= witnessStack
11483 } else if (redeemScript
) {
11484 if (!supportedP2SHType(redeemScriptType
)) {
11485 throw new Error('Bad redeemscript!')
11488 script
= redeemScript
11489 scriptType
= redeemScriptType
11490 chunks
= scriptSigChunks
.slice(0, -1)
11492 prevOutType
= scriptType
= btemplates
.classifyInput(scriptSig
)
11493 chunks
= scriptSigChunks
11496 var expanded
= extractChunks(scriptType
, chunks
, script
)
11499 pubKeys: expanded
.pubKeys
,
11500 signatures: expanded
.signatures
,
11501 prevOutScript: prevOutScript
,
11502 prevOutType: prevOutType
,
11503 signType: scriptType
,
11504 signScript: script
,
11505 witness: Boolean(witness
)
11509 result
.redeemScript
= redeemScript
11510 result
.redeemScriptType
= redeemScriptType
11514 result
.witnessScript
= witnessScript
11515 result
.witnessScriptType
= witnessScriptType
11521 // could be done in expandInput, but requires the original Transaction for hashForSignature
11522 function fixMultisigOrder (input
, transaction
, vin
) {
11523 if (input
.redeemScriptType
!== scriptTypes
.MULTISIG
|| !input
.redeemScript
) return
11524 if (input
.pubKeys
.length
=== input
.signatures
.length
) return
11526 var unmatched
= input
.signatures
.concat()
11528 input
.signatures
= input
.pubKeys
.map(function (pubKey
) {
11529 var keyPair
= ECPair
.fromPublicKeyBuffer(pubKey
)
11532 // check for a signature
11533 unmatched
.some(function (signature
, i
) {
11534 // skip if undefined || OP_0
11535 if (!signature
) return false
11537 // TODO: avoid O(n) hashForSignature
11538 var parsed
= ECSignature
.parseScriptSignature(signature
)
11539 var hash
= transaction
.hashForSignature(vin
, input
.redeemScript
, parsed
.hashType
)
11541 // skip if signature does not match pubKey
11542 if (!keyPair
.verify(hash
, parsed
.signature
)) return false
11544 // remove matched signature from unmatched
11545 unmatched
[i
] = undefined
11555 function expandOutput (script
, scriptType
, ourPubKey
) {
11556 typeforce(types
.Buffer
, script
)
11558 var scriptChunks
= bscript
.decompile(script
)
11560 scriptType
= btemplates
.classifyOutput(script
)
11565 switch (scriptType
) {
11566 // does our hash160(pubKey) match the output scripts?
11567 case scriptTypes
.P2PKH:
11568 if (!ourPubKey
) break
11570 var pkh1
= scriptChunks
[2]
11571 var pkh2
= bcrypto
.hash160(ourPubKey
)
11572 if (pkh1
.equals(pkh2
)) pubKeys
= [ourPubKey
]
11575 // does our hash160(pubKey) match the output scripts?
11576 case scriptTypes
.P2WPKH:
11577 if (!ourPubKey
) break
11579 var wpkh1
= scriptChunks
[1]
11580 var wpkh2
= bcrypto
.hash160(ourPubKey
)
11581 if (wpkh1
.equals(wpkh2
)) pubKeys
= [ourPubKey
]
11584 case scriptTypes
.P2PK:
11585 pubKeys
= scriptChunks
.slice(0, 1)
11588 case scriptTypes
.MULTISIG:
11589 pubKeys
= scriptChunks
.slice(1, -2)
11592 default: return { scriptType: scriptType
}
11597 scriptType: scriptType
,
11598 signatures: pubKeys
.map(function () { return undefined })
11602 function checkP2SHInput (input
, redeemScriptHash
) {
11603 if (input
.prevOutType
) {
11604 if (input
.prevOutType
!== scriptTypes
.P2SH
) throw new Error('PrevOutScript must be P2SH')
11606 var prevOutScriptScriptHash
= bscript
.decompile(input
.prevOutScript
)[1]
11607 if (!prevOutScriptScriptHash
.equals(redeemScriptHash
)) throw new Error('Inconsistent hash160(RedeemScript)')
11611 function checkP2WSHInput (input
, witnessScriptHash
) {
11612 if (input
.prevOutType
) {
11613 if (input
.prevOutType
!== scriptTypes
.P2WSH
) throw new Error('PrevOutScript must be P2WSH')
11615 var scriptHash
= bscript
.decompile(input
.prevOutScript
)[1]
11616 if (!scriptHash
.equals(witnessScriptHash
)) throw new Error('Inconsistent sha25(WitnessScript)')
11620 function prepareInput (input
, kpPubKey
, redeemScript
, witnessValue
, witnessScript
) {
11627 var redeemScriptHash
11629 var witness
= false
11632 var witnessScriptHash
11637 if (redeemScript
&& witnessScript
) {
11638 redeemScriptHash
= bcrypto
.hash160(redeemScript
)
11639 witnessScriptHash
= bcrypto
.sha256(witnessScript
)
11640 checkP2SHInput(input
, redeemScriptHash
)
11642 if (!redeemScript
.equals(btemplates
.witnessScriptHash
.output
.encode(witnessScriptHash
))) throw new Error('Witness script inconsistent with redeem script')
11644 expanded
= expandOutput(witnessScript
, undefined, kpPubKey
)
11645 if (!expanded
.pubKeys
) throw new Error('WitnessScript not supported "' + bscript
.toASM(redeemScript
) + '"')
11647 prevOutType
= btemplates
.types
.P2SH
11648 prevOutScript
= btemplates
.scriptHash
.output
.encode(redeemScriptHash
)
11649 p2sh
= witness
= p2wsh
= true
11650 p2shType
= btemplates
.types
.P2WSH
11651 signType
= witnessType
= expanded
.scriptType
11652 signScript
= witnessScript
11653 } else if (redeemScript
) {
11654 redeemScriptHash
= bcrypto
.hash160(redeemScript
)
11655 checkP2SHInput(input
, redeemScriptHash
)
11657 expanded
= expandOutput(redeemScript
, undefined, kpPubKey
)
11658 if (!expanded
.pubKeys
) throw new Error('RedeemScript not supported "' + bscript
.toASM(redeemScript
) + '"')
11660 prevOutType
= btemplates
.types
.P2SH
11661 prevOutScript
= btemplates
.scriptHash
.output
.encode(redeemScriptHash
)
11663 signType
= p2shType
= expanded
.scriptType
11664 signScript
= redeemScript
11665 witness
= signType
=== btemplates
.types
.P2WPKH
11666 } else if (witnessScript
) {
11667 witnessScriptHash
= bcrypto
.sha256(witnessScript
)
11668 checkP2WSHInput(input
, witnessScriptHash
)
11670 expanded
= expandOutput(witnessScript
, undefined, kpPubKey
)
11671 if (!expanded
.pubKeys
) throw new Error('WitnessScript not supported "' + bscript
.toASM(redeemScript
) + '"')
11673 prevOutType
= btemplates
.types
.P2WSH
11674 prevOutScript
= btemplates
.witnessScriptHash
.output
.encode(witnessScriptHash
)
11675 witness
= p2wsh
= true
11676 signType
= witnessType
= expanded
.scriptType
11677 signScript
= witnessScript
11678 } else if (input
.prevOutType
) {
11679 // embedded scripts are not possible without a redeemScript
11680 if (input
.prevOutType
=== scriptTypes
.P2SH
||
11681 input
.prevOutType
=== scriptTypes
.P2WSH
) {
11682 throw new Error('PrevOutScript is ' + input
.prevOutType
+ ', requires redeemScript')
11685 prevOutType
= input
.prevOutType
11686 prevOutScript
= input
.prevOutScript
11687 expanded
= expandOutput(input
.prevOutScript
, input
.prevOutType
, kpPubKey
)
11688 if (!expanded
.pubKeys
) return
11690 witness
= (input
.prevOutType
=== scriptTypes
.P2WPKH
)
11691 signType
= prevOutType
11692 signScript
= prevOutScript
11694 prevOutScript
= btemplates
.pubKeyHash
.output
.encode(bcrypto
.hash160(kpPubKey
))
11695 expanded
= expandOutput(prevOutScript
, scriptTypes
.P2PKH
, kpPubKey
)
11697 prevOutType
= scriptTypes
.P2PKH
11699 signType
= prevOutType
11700 signScript
= prevOutScript
11703 if (signType
=== scriptTypes
.P2WPKH
) {
11704 signScript
= btemplates
.pubKeyHash
.output
.encode(btemplates
.witnessPubKeyHash
.output
.decode(signScript
))
11708 input
.redeemScript
= redeemScript
11709 input
.redeemScriptType
= p2shType
11713 input
.witnessScript
= witnessScript
11714 input
.witnessScriptType
= witnessType
11717 input
.pubKeys
= expanded
.pubKeys
11718 input
.signatures
= expanded
.signatures
11719 input
.signScript
= signScript
11720 input
.signType
= signType
11721 input
.prevOutScript
= prevOutScript
11722 input
.prevOutType
= prevOutType
11723 input
.witness
= witness
11726 function buildStack (type
, signatures
, pubKeys
, allowIncomplete
) {
11727 if (type
=== scriptTypes
.P2PKH
) {
11728 if (signatures
.length
=== 1 && Buffer
.isBuffer(signatures
[0]) && pubKeys
.length
=== 1) return btemplates
.pubKeyHash
.input
.encodeStack(signatures
[0], pubKeys
[0])
11729 } else if (type
=== scriptTypes
.P2PK
) {
11730 if (signatures
.length
=== 1 && Buffer
.isBuffer(signatures
[0])) return btemplates
.pubKey
.input
.encodeStack(signatures
[0])
11731 } else if (type
=== scriptTypes
.MULTISIG
) {
11732 if (signatures
.length
> 0) {
11733 signatures
= signatures
.map(function (signature
) {
11734 return signature
|| ops
.OP_0
11736 if (!allowIncomplete
) {
11737 // remove blank signatures
11738 signatures
= signatures
.filter(function (x
) { return x
!== ops
.OP_0
})
11741 return btemplates
.multisig
.input
.encodeStack(signatures
)
11744 throw new Error('Not yet supported')
11747 if (!allowIncomplete
) throw new Error('Not enough signatures provided')
11751 function buildInput (input
, allowIncomplete
) {
11752 var scriptType
= input
.prevOutType
11756 if (supportedType(scriptType
)) {
11757 sig
= buildStack(scriptType
, input
.signatures
, input
.pubKeys
, allowIncomplete
)
11761 if (scriptType
=== btemplates
.types
.P2SH
) {
11762 // We can remove this error later when we have a guarantee prepareInput
11763 // rejects unsignable scripts - it MUST be signable at this point.
11764 if (!allowIncomplete
&& !supportedP2SHType(input
.redeemScriptType
)) {
11765 throw new Error('Impossible to sign this type')
11768 if (supportedType(input
.redeemScriptType
)) {
11769 sig
= buildStack(input
.redeemScriptType
, input
.signatures
, input
.pubKeys
, allowIncomplete
)
11772 // If it wasn't SIGNABLE, it's witness, defer to that
11773 if (input
.redeemScriptType
) {
11775 scriptType
= input
.redeemScriptType
11779 switch (scriptType
) {
11780 // P2WPKH is a special case of P2PKH
11781 case btemplates
.types
.P2WPKH:
11782 witness
= buildStack(btemplates
.types
.P2PKH
, input
.signatures
, input
.pubKeys
, allowIncomplete
)
11785 case btemplates
.types
.P2WSH:
11786 // We can remove this check later
11787 if (!allowIncomplete
&& !supportedType(input
.witnessScriptType
)) {
11788 throw new Error('Impossible to sign this type')
11791 if (supportedType(input
.witnessScriptType
)) {
11792 witness
= buildStack(input
.witnessScriptType
, input
.signatures
, input
.pubKeys
, allowIncomplete
)
11793 witness
.push(input
.witnessScript
)
11794 scriptType
= input
.witnessScriptType
11800 // append redeemScript if necessary
11802 sig
.push(input
.redeemScript
)
11807 script: bscript
.compile(sig
),
11812 function TransactionBuilder (network
, maximumFeeRate
) {
11813 this.prevTxMap
= {}
11814 this.network
= network
|| networks
.bitcoin
11816 // WARNING: This is __NOT__ to be relied on, its just another potential safety mechanism (safety in-depth)
11817 this.maximumFeeRate
= maximumFeeRate
|| 1000
11820 this.tx
= new Transaction()
11823 TransactionBuilder
.prototype.setLockTime = function (locktime
) {
11824 typeforce(types
.UInt32
, locktime
)
11826 // if any signatures exist, throw
11827 if (this.inputs
.some(function (input
) {
11828 if (!input
.signatures
) return false
11830 return input
.signatures
.some(function (s
) { return s
})
11832 throw new Error('No, this would invalidate signatures')
11835 this.tx
.locktime
= locktime
11838 TransactionBuilder
.prototype.setVersion = function (version
) {
11839 typeforce(types
.UInt32
, version
)
11841 // XXX: this might eventually become more complex depending on what the versions represent
11842 this.tx
.version
= version
11845 TransactionBuilder
.fromTransaction = function (transaction
, network
) {
11846 var txb
= new TransactionBuilder(network
)
11848 // Copy transaction fields
11849 txb
.setVersion(transaction
.version
)
11850 txb
.setLockTime(transaction
.locktime
)
11852 // Copy outputs (done first to avoid signature invalidation)
11853 transaction
.outs
.forEach(function (txOut
) {
11854 txb
.addOutput(txOut
.script
, txOut
.value
)
11858 transaction
.ins
.forEach(function (txIn
) {
11859 txb
.__addInputUnsafe(txIn
.hash
, txIn
.index
, {
11860 sequence: txIn
.sequence
,
11861 script: txIn
.script
,
11862 witness: txIn
.witness
11866 // fix some things not possible through the public API
11867 txb
.inputs
.forEach(function (input
, i
) {
11868 fixMultisigOrder(input
, transaction
, i
)
11874 TransactionBuilder
.prototype.addInput = function (txHash
, vout
, sequence
, prevOutScript
) {
11875 if (!this.__canModifyInputs()) {
11876 throw new Error('No, this would invalidate signatures')
11881 // is it a hex string?
11882 if (typeof txHash
=== 'string') {
11883 // transaction hashs's are displayed in reverse order, un-reverse it
11884 txHash
= Buffer
.from(txHash
, 'hex').reverse()
11886 // is it a Transaction object?
11887 } else if (txHash
instanceof Transaction
) {
11888 var txOut
= txHash
.outs
[vout
]
11889 prevOutScript
= txOut
.script
11890 value
= txOut
.value
11892 txHash
= txHash
.getHash()
11895 return this.__addInputUnsafe(txHash
, vout
, {
11896 sequence: sequence
,
11897 prevOutScript: prevOutScript
,
11902 TransactionBuilder
.prototype.__addInputUnsafe = function (txHash
, vout
, options
) {
11903 if (Transaction
.isCoinbaseHash(txHash
)) {
11904 throw new Error('coinbase inputs not supported')
11907 var prevTxOut
= txHash
.toString('hex') + ':' + vout
11908 if (this.prevTxMap
[prevTxOut
] !== undefined) throw new Error('Duplicate TxOut: ' + prevTxOut
)
11912 // derive what we can from the scriptSig
11913 if (options
.script
!== undefined) {
11914 input
= expandInput(options
.script
, options
.witness
|| [])
11917 // if an input value was given, retain it
11918 if (options
.value
!== undefined) {
11919 input
.value
= options
.value
11922 // derive what we can from the previous transactions output script
11923 if (!input
.prevOutScript
&& options
.prevOutScript
) {
11926 if (!input
.pubKeys
&& !input
.signatures
) {
11927 var expanded
= expandOutput(options
.prevOutScript
)
11929 if (expanded
.pubKeys
) {
11930 input
.pubKeys
= expanded
.pubKeys
11931 input
.signatures
= expanded
.signatures
11934 prevOutType
= expanded
.scriptType
11937 input
.prevOutScript
= options
.prevOutScript
11938 input
.prevOutType
= prevOutType
|| btemplates
.classifyOutput(options
.prevOutScript
)
11941 var vin
= this.tx
.addInput(txHash
, vout
, options
.sequence
, options
.scriptSig
)
11942 this.inputs
[vin
] = input
11943 this.prevTxMap
[prevTxOut
] = vin
11947 TransactionBuilder
.prototype.addOutput = function (scriptPubKey
, value
) {
11948 if (!this.__canModifyOutputs()) {
11949 throw new Error('No, this would invalidate signatures')
11952 // Attempt to get a script if it's a base58 address string
11953 if (typeof scriptPubKey
=== 'string') {
11954 scriptPubKey
= baddress
.toOutputScript(scriptPubKey
, this.network
)
11957 return this.tx
.addOutput(scriptPubKey
, value
)
11960 TransactionBuilder
.prototype.build = function () {
11961 return this.__build(false)
11963 TransactionBuilder
.prototype.buildIncomplete = function () {
11964 return this.__build(true)
11967 TransactionBuilder
.prototype.__build = function (allowIncomplete
) {
11968 if (!allowIncomplete
) {
11969 if (!this.tx
.ins
.length
) throw new Error('Transaction has no inputs')
11970 if (!this.tx
.outs
.length
) throw new Error('Transaction has no outputs')
11973 var tx
= this.tx
.clone()
11974 // Create script signatures from inputs
11975 this.inputs
.forEach(function (input
, i
) {
11976 var scriptType
= input
.witnessScriptType
|| input
.redeemScriptType
|| input
.prevOutType
11977 if (!scriptType
&& !allowIncomplete
) throw new Error('Transaction is not complete')
11978 var result
= buildInput(input
, allowIncomplete
)
11980 // skip if no result
11981 if (!allowIncomplete
) {
11982 if (!supportedType(result
.type
) && result
.type
!== btemplates
.types
.P2WPKH
) {
11983 throw new Error(result
.type
+ ' not supported')
11987 tx
.setInputScript(i
, result
.script
)
11988 tx
.setWitness(i
, result
.witness
)
11991 if (!allowIncomplete
) {
11992 // do not rely on this, its merely a last resort
11993 if (this.__overMaximumFees(tx
.virtualSize())) {
11994 throw new Error('Transaction has absurd fees')
12001 function canSign (input
) {
12002 return input
.prevOutScript
!== undefined &&
12003 input
.signScript
!== undefined &&
12004 input
.pubKeys
!== undefined &&
12005 input
.signatures
!== undefined &&
12006 input
.signatures
.length
=== input
.pubKeys
.length
&&
12007 input
.pubKeys
.length
> 0 &&
12009 input
.witness
=== false ||
12010 (input
.witness
=== true && input
.value
!== undefined)
12014 TransactionBuilder
.prototype.sign = function (vin
, keyPair
, redeemScript
, hashType
, witnessValue
, witnessScript
) {
12015 // TODO: remove keyPair.network matching in 4.0.0
12016 if (keyPair
.network
&& keyPair
.network
!== this.network
) throw new TypeError('Inconsistent network')
12017 if (!this.inputs
[vin
]) throw new Error('No input at index: ' + vin
)
12018 hashType
= hashType
|| Transaction
.SIGHASH_ALL
12020 var input
= this.inputs
[vin
]
12022 // if redeemScript was previously provided, enforce consistency
12023 if (input
.redeemScript
!== undefined &&
12025 !input
.redeemScript
.equals(redeemScript
)) {
12026 throw new Error('Inconsistent redeemScript')
12029 var kpPubKey
= keyPair
.publicKey
|| keyPair
.getPublicKeyBuffer()
12030 if (!canSign(input
)) {
12031 if (witnessValue
!== undefined) {
12032 if (input
.value
!== undefined && input
.value
!== witnessValue
) throw new Error('Input didn\'t match witnessValue')
12033 typeforce(types
.Satoshi
, witnessValue
)
12034 input
.value
= witnessValue
12037 if (!canSign(input
)) prepareInput(input
, kpPubKey
, redeemScript
, witnessValue
, witnessScript
)
12038 if (!canSign(input
)) throw Error(input
.prevOutType
+ ' not supported')
12043 if (input
.witness
) {
12044 signatureHash
= this.tx
.hashForWitnessV0(vin
, input
.signScript
, input
.value
, hashType
)
12046 signatureHash
= this.tx
.hashForSignature(vin
, input
.signScript
, hashType
)
12049 // enforce in order signing of public keys
12050 var signed
= input
.pubKeys
.some(function (pubKey
, i
) {
12051 if (!kpPubKey
.equals(pubKey
)) return false
12052 if (input
.signatures
[i
]) throw new Error('Signature already exists')
12053 if (kpPubKey
.length
!== 33 &&
12054 input
.signType
=== scriptTypes
.P2WPKH
) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
12056 var signature
= keyPair
.sign(signatureHash
)
12057 if (Buffer
.isBuffer(signature
)) signature
= ECSignature
.fromRSBuffer(signature
)
12059 input
.signatures
[i
] = signature
.toScriptSignature(hashType
)
12063 if (!signed
) throw new Error('Key pair cannot sign for this input')
12066 function signatureHashType (buffer
) {
12067 return buffer
.readUInt8(buffer
.length
- 1)
12070 TransactionBuilder
.prototype.__canModifyInputs = function () {
12071 return this.inputs
.every(function (input
) {
12073 if (input
.signatures
=== undefined) return true
12075 return input
.signatures
.every(function (signature
) {
12076 if (!signature
) return true
12077 var hashType
= signatureHashType(signature
)
12079 // if SIGHASH_ANYONECANPAY is set, signatures would not
12080 // be invalidated by more inputs
12081 return hashType
& Transaction
.SIGHASH_ANYONECANPAY
12086 TransactionBuilder
.prototype.__canModifyOutputs = function () {
12087 var nInputs
= this.tx
.ins
.length
12088 var nOutputs
= this.tx
.outs
.length
12090 return this.inputs
.every(function (input
) {
12091 if (input
.signatures
=== undefined) return true
12093 return input
.signatures
.every(function (signature
) {
12094 if (!signature
) return true
12095 var hashType
= signatureHashType(signature
)
12097 var hashTypeMod
= hashType
& 0x1f
12098 if (hashTypeMod
=== Transaction
.SIGHASH_NONE
) return true
12099 if (hashTypeMod
=== Transaction
.SIGHASH_SINGLE
) {
12100 // if SIGHASH_SINGLE is set, and nInputs > nOutputs
12101 // some signatures would be invalidated by the addition
12103 return nInputs
<= nOutputs
12109 TransactionBuilder
.prototype.__overMaximumFees = function (bytes
) {
12110 // not all inputs will have .value defined
12111 var incoming
= this.inputs
.reduce(function (a
, x
) { return a
+ (x
.value
>>> 0) }, 0)
12113 // but all outputs do, and if we have any input value
12114 // we can immediately determine if the outputs are too small
12115 var outgoing
= this.tx
.outs
.reduce(function (a
, x
) { return a
+ x
.value
}, 0)
12116 var fee
= incoming
- outgoing
12117 var feeRate
= fee
/ bytes
12119 return feeRate
> this.maximumFeeRate
12122 module
.exports
= TransactionBuilder
12124 },{"./address":44,"./crypto":47,"./ecpair":49,"./ecsignature":50,"./networks":53,"./script":54,"./templates":56,"./transaction":78,"./types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],80:[function(require
,module
,exports
){
12125 var typeforce
= require('typeforce')
12127 var UINT31_MAX
= Math
.pow(2, 31) - 1
12128 function UInt31 (value
) {
12129 return typeforce
.UInt32(value
) && value
<= UINT31_MAX
12132 function BIP32Path (value
) {
12133 return typeforce
.String(value
) && value
.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
12135 BIP32Path
.toJSON = function () { return 'BIP32 derivation path' }
12137 var SATOSHI_MAX
= 21 * 1e14
12138 function Satoshi (value
) {
12139 return typeforce
.UInt53(value
) && value
<= SATOSHI_MAX
12142 // external dependent types
12143 var BigInt
= typeforce
.quacksLike('BigInteger')
12144 var ECPoint
= typeforce
.quacksLike('Point')
12146 // exposed, external API
12147 var ECSignature
= typeforce
.compile({ r: BigInt
, s: BigInt
})
12148 var Network
= typeforce
.compile({
12149 messagePrefix: typeforce
.oneOf(typeforce
.Buffer
, typeforce
.String
),
12151 public: typeforce
.UInt32
,
12152 private: typeforce
.UInt32
12154 pubKeyHash: typeforce
.UInt8
,
12155 scriptHash: typeforce
.UInt8
,
12156 wif: typeforce
.UInt8
12159 // extend typeforce types with ours
12162 BIP32Path: BIP32Path
,
12163 Buffer256bit: typeforce
.BufferN(32),
12165 ECSignature: ECSignature
,
12166 Hash160bit: typeforce
.BufferN(20),
12167 Hash256bit: typeforce
.BufferN(32),
12173 for (var typeName
in typeforce
) {
12174 types
[typeName
] = typeforce
[typeName
]
12177 module
.exports
= types
12179 },{"typeforce":139}],81:[function(require
,module
,exports
){
12180 (function (module
, exports
) {
12184 function assert (val
, msg
) {
12185 if (!val
) throw new Error(msg
|| 'Assertion failed');
12188 // Could use `inherits` module, but don't want to move from single file
12189 // architecture yet.
12190 function inherits (ctor
, superCtor
) {
12191 ctor
.super_
= superCtor
;
12192 var TempCtor = function () {};
12193 TempCtor
.prototype = superCtor
.prototype;
12194 ctor
.prototype = new TempCtor();
12195 ctor
.prototype.constructor = ctor
;
12200 function BN (number
, base
, endian
) {
12201 if (BN
.isBN(number
)) {
12209 // Reduction context
12212 if (number
!== null) {
12213 if (base
=== 'le' || base
=== 'be') {
12218 this._init(number
|| 0, base
|| 10, endian
|| 'be');
12221 if (typeof module
=== 'object') {
12222 module
.exports
= BN
;
12232 Buffer
= require('buf' + 'fer').Buffer
;
12236 BN
.isBN
= function isBN (num
) {
12237 if (num
instanceof BN
) {
12241 return num
!== null && typeof num
=== 'object' &&
12242 num
.constructor.wordSize
=== BN
.wordSize
&& Array
.isArray(num
.words
);
12245 BN
.max
= function max (left
, right
) {
12246 if (left
.cmp(right
) > 0) return left
;
12250 BN
.min
= function min (left
, right
) {
12251 if (left
.cmp(right
) < 0) return left
;
12255 BN
.prototype._init
= function init (number
, base
, endian
) {
12256 if (typeof number
=== 'number') {
12257 return this._initNumber(number
, base
, endian
);
12260 if (typeof number
=== 'object') {
12261 return this._initArray(number
, base
, endian
);
12264 if (base
=== 'hex') {
12267 assert(base
=== (base
| 0) && base
>= 2 && base
<= 36);
12269 number
= number
.toString().replace(/\s+/g, '');
12271 if (number
[0] === '-') {
12276 this._parseHex(number
, start
);
12278 this._parseBase(number
, base
, start
);
12281 if (number
[0] === '-') {
12287 if (endian
!== 'le') return;
12289 this._initArray(this.toArray(), base
, endian
);
12292 BN
.prototype._initNumber
= function _initNumber (number
, base
, endian
) {
12297 if (number
< 0x4000000) {
12298 this.words
= [ number
& 0x3ffffff ];
12300 } else if (number
< 0x10000000000000) {
12302 number
& 0x3ffffff,
12303 (number
/ 0x4000000) & 0x3ffffff
12307 assert(number
< 0x20000000000000); // 2 ^ 53 (unsafe)
12309 number
& 0x3ffffff,
12310 (number
/ 0x4000000) & 0x3ffffff,
12316 if (endian
!== 'le') return;
12318 // Reverse the bytes
12319 this._initArray(this.toArray(), base
, endian
);
12322 BN
.prototype._initArray
= function _initArray (number
, base
, endian
) {
12323 // Perhaps a Uint8Array
12324 assert(typeof number
.length
=== 'number');
12325 if (number
.length
<= 0) {
12326 this.words
= [ 0 ];
12331 this.length
= Math
.ceil(number
.length
/ 3);
12332 this.words
= new Array(this.length
);
12333 for (var i
= 0; i
< this.length
; i
++) {
12339 if (endian
=== 'be') {
12340 for (i
= number
.length
- 1, j
= 0; i
>= 0; i
-= 3) {
12341 w
= number
[i
] | (number
[i
- 1] << 8) | (number
[i
- 2] << 16);
12342 this.words
[j
] |= (w
<< off
) & 0x3ffffff;
12343 this.words
[j
+ 1] = (w
>>> (26 - off
)) & 0x3ffffff;
12350 } else if (endian
=== 'le') {
12351 for (i
= 0, j
= 0; i
< number
.length
; i
+= 3) {
12352 w
= number
[i
] | (number
[i
+ 1] << 8) | (number
[i
+ 2] << 16);
12353 this.words
[j
] |= (w
<< off
) & 0x3ffffff;
12354 this.words
[j
+ 1] = (w
>>> (26 - off
)) & 0x3ffffff;
12362 return this.strip();
12365 function parseHex (str
, start
, end
) {
12367 var len
= Math
.min(str
.length
, end
);
12368 for (var i
= start
; i
< len
; i
++) {
12369 var c
= str
.charCodeAt(i
) - 48;
12374 if (c
>= 49 && c
<= 54) {
12378 } else if (c
>= 17 && c
<= 22) {
12389 BN
.prototype._parseHex
= function _parseHex (number
, start
) {
12390 // Create possibly bigger array to ensure that it fits the number
12391 this.length
= Math
.ceil((number
.length
- start
) / 6);
12392 this.words
= new Array(this.length
);
12393 for (var i
= 0; i
< this.length
; i
++) {
12398 // Scan 24-bit chunks and add them to the number
12400 for (i
= number
.length
- 6, j
= 0; i
>= start
; i
-= 6) {
12401 w
= parseHex(number
, i
, i
+ 6);
12402 this.words
[j
] |= (w
<< off
) & 0x3ffffff;
12403 // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
12404 this.words
[j
+ 1] |= w
>>> (26 - off
) & 0x3fffff;
12411 if (i
+ 6 !== start
) {
12412 w
= parseHex(number
, start
, i
+ 6);
12413 this.words
[j
] |= (w
<< off
) & 0x3ffffff;
12414 this.words
[j
+ 1] |= w
>>> (26 - off
) & 0x3fffff;
12419 function parseBase (str
, start
, end
, mul
) {
12421 var len
= Math
.min(str
.length
, end
);
12422 for (var i
= start
; i
< len
; i
++) {
12423 var c
= str
.charCodeAt(i
) - 48;
12432 } else if (c
>= 17) {
12443 BN
.prototype._parseBase
= function _parseBase (number
, base
, start
) {
12444 // Initialize as zero
12445 this.words
= [ 0 ];
12448 // Find length of limb in base
12449 for (var limbLen
= 0, limbPow
= 1; limbPow
<= 0x3ffffff; limbPow
*= base
) {
12453 limbPow
= (limbPow
/ base
) | 0;
12455 var total
= number
.length
- start
;
12456 var mod
= total
% limbLen
;
12457 var end
= Math
.min(total
, total
- mod
) + start
;
12460 for (var i
= start
; i
< end
; i
+= limbLen
) {
12461 word
= parseBase(number
, i
, i
+ limbLen
, base
);
12463 this.imuln(limbPow
);
12464 if (this.words
[0] + word
< 0x4000000) {
12465 this.words
[0] += word
;
12473 word
= parseBase(number
, i
, number
.length
, base
);
12475 for (i
= 0; i
< mod
; i
++) {
12480 if (this.words
[0] + word
< 0x4000000) {
12481 this.words
[0] += word
;
12488 BN
.prototype.copy
= function copy (dest
) {
12489 dest
.words
= new Array(this.length
);
12490 for (var i
= 0; i
< this.length
; i
++) {
12491 dest
.words
[i
] = this.words
[i
];
12493 dest
.length
= this.length
;
12494 dest
.negative
= this.negative
;
12495 dest
.red
= this.red
;
12498 BN
.prototype.clone
= function clone () {
12499 var r
= new BN(null);
12504 BN
.prototype._expand
= function _expand (size
) {
12505 while (this.length
< size
) {
12506 this.words
[this.length
++] = 0;
12511 // Remove leading `0` from `this`
12512 BN
.prototype.strip
= function strip () {
12513 while (this.length
> 1 && this.words
[this.length
- 1] === 0) {
12516 return this._normSign();
12519 BN
.prototype._normSign
= function _normSign () {
12521 if (this.length
=== 1 && this.words
[0] === 0) {
12527 BN
.prototype.inspect
= function inspect () {
12528 return (this.red
? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
12534 var groupSizes = [];
12535 var groupBases = [];
12539 while (++i < BN.wordSize) {
12548 while (++base < 36 + 1) {
12551 while (groupBase < (1 << BN.wordSize) / base) {
12555 groupSizes[base] = groupSize;
12556 groupBases[base] = groupBase;
12578 '0000000000000000',
12579 '00000000000000000',
12580 '000000000000000000',
12581 '0000000000000000000',
12582 '00000000000000000000',
12583 '000000000000000000000',
12584 '0000000000000000000000',
12585 '00000000000000000000000',
12586 '000000000000000000000000',
12587 '0000000000000000000000000'
12592 25, 16, 12, 11, 10, 9, 8,
12593 8, 7, 7, 7, 7, 6, 6,
12594 6, 6, 6, 6, 6, 5, 5,
12595 5, 5, 5, 5, 5, 5, 5,
12596 5, 5, 5, 5, 5, 5, 5
12601 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
12602 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
12603 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
12604 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
12605 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
12608 BN
.prototype.toString
= function toString (base
, padding
) {
12610 padding
= padding
| 0 || 1;
12613 if (base
=== 16 || base
=== 'hex') {
12617 for (var i
= 0; i
< this.length
; i
++) {
12618 var w
= this.words
[i
];
12619 var word
= (((w
<< off
) | carry
) & 0xffffff).toString(16);
12620 carry
= (w
>>> (24 - off
)) & 0xffffff;
12621 if (carry
!== 0 || i
!== this.length
- 1) {
12622 out
= zeros
[6 - word
.length
] + word
+ out
;
12633 out
= carry
.toString(16) + out
;
12635 while (out
.length
% padding
!== 0) {
12638 if (this.negative
!== 0) {
12644 if (base
=== (base
| 0) && base
>= 2 && base
<= 36) {
12645 // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
12646 var groupSize
= groupSizes
[base
];
12647 // var groupBase = Math.pow(base, groupSize);
12648 var groupBase
= groupBases
[base
];
12650 var c
= this.clone();
12652 while (!c
.isZero()) {
12653 var r
= c
.modn(groupBase
).toString(base
);
12654 c
= c
.idivn(groupBase
);
12657 out
= zeros
[groupSize
- r
.length
] + r
+ out
;
12662 if (this.isZero()) {
12665 while (out
.length
% padding
!== 0) {
12668 if (this.negative
!== 0) {
12674 assert(false, 'Base should be between 2 and 36');
12677 BN
.prototype.toNumber
= function toNumber () {
12678 var ret
= this.words
[0];
12679 if (this.length
=== 2) {
12680 ret
+= this.words
[1] * 0x4000000;
12681 } else if (this.length
=== 3 && this.words
[2] === 0x01) {
12682 // NOTE: at this stage it is known that the top bit is set
12683 ret
+= 0x10000000000000 + (this.words
[1] * 0x4000000);
12684 } else if (this.length
> 2) {
12685 assert(false, 'Number can only safely store up to 53 bits');
12687 return (this.negative
!== 0) ? -ret : ret
;
12690 BN
.prototype.toJSON
= function toJSON () {
12691 return this.toString(16);
12694 BN
.prototype.toBuffer
= function toBuffer (endian
, length
) {
12695 assert(typeof Buffer
!== 'undefined');
12696 return this.toArrayLike(Buffer
, endian
, length
);
12699 BN
.prototype.toArray
= function toArray (endian
, length
) {
12700 return this.toArrayLike(Array
, endian
, length
);
12703 BN
.prototype.toArrayLike
= function toArrayLike (ArrayType
, endian
, length
) {
12704 var byteLength
= this.byteLength();
12705 var reqLength
= length
|| Math
.max(1, byteLength
);
12706 assert(byteLength
<= reqLength
, 'byte array longer than desired length');
12707 assert(reqLength
> 0, 'Requested array length <= 0');
12710 var littleEndian
= endian
=== 'le';
12711 var res
= new ArrayType(reqLength
);
12714 var q
= this.clone();
12715 if (!littleEndian
) {
12716 // Assume big-endian
12717 for (i
= 0; i
< reqLength
- byteLength
; i
++) {
12721 for (i
= 0; !q
.isZero(); i
++) {
12725 res
[reqLength
- i
- 1] = b
;
12728 for (i
= 0; !q
.isZero(); i
++) {
12735 for (; i
< reqLength
; i
++) {
12744 BN
.prototype._countBits
= function _countBits (w
) {
12745 return 32 - Math
.clz32(w
);
12748 BN
.prototype._countBits
= function _countBits (w
) {
12771 BN
.prototype._zeroBits
= function _zeroBits (w
) {
12773 if (w
=== 0) return 26;
12777 if ((t
& 0x1fff) === 0) {
12781 if ((t
& 0x7f) === 0) {
12785 if ((t
& 0xf) === 0) {
12789 if ((t
& 0x3) === 0) {
12793 if ((t
& 0x1) === 0) {
12799 // Return number of used bits in a BN
12800 BN
.prototype.bitLength
= function bitLength () {
12801 var w
= this.words
[this.length
- 1];
12802 var hi
= this._countBits(w
);
12803 return (this.length
- 1) * 26 + hi
;
12806 function toBitArray (num
) {
12807 var w
= new Array(num
.bitLength());
12809 for (var bit
= 0; bit
< w
.length
; bit
++) {
12810 var off
= (bit
/ 26) | 0;
12811 var wbit
= bit
% 26;
12813 w
[bit
] = (num
.words
[off
] & (1 << wbit
)) >>> wbit
;
12819 // Number of trailing zero bits
12820 BN
.prototype.zeroBits
= function zeroBits () {
12821 if (this.isZero()) return 0;
12824 for (var i
= 0; i
< this.length
; i
++) {
12825 var b
= this._zeroBits(this.words
[i
]);
12827 if (b
!== 26) break;
12832 BN
.prototype.byteLength
= function byteLength () {
12833 return Math
.ceil(this.bitLength() / 8);
12836 BN
.prototype.toTwos
= function toTwos (width
) {
12837 if (this.negative
!== 0) {
12838 return this.abs().inotn(width
).iaddn(1);
12840 return this.clone();
12843 BN
.prototype.fromTwos
= function fromTwos (width
) {
12844 if (this.testn(width
- 1)) {
12845 return this.notn(width
).iaddn(1).ineg();
12847 return this.clone();
12850 BN
.prototype.isNeg
= function isNeg () {
12851 return this.negative
!== 0;
12854 // Return negative clone of `this`
12855 BN
.prototype.neg
= function neg () {
12856 return this.clone().ineg();
12859 BN
.prototype.ineg
= function ineg () {
12860 if (!this.isZero()) {
12861 this.negative
^= 1;
12867 // Or `num` with `this` in-place
12868 BN
.prototype.iuor
= function iuor (num
) {
12869 while (this.length
< num
.length
) {
12870 this.words
[this.length
++] = 0;
12873 for (var i
= 0; i
< num
.length
; i
++) {
12874 this.words
[i
] = this.words
[i
] | num
.words
[i
];
12877 return this.strip();
12880 BN
.prototype.ior
= function ior (num
) {
12881 assert((this.negative
| num
.negative
) === 0);
12882 return this.iuor(num
);
12885 // Or `num` with `this`
12886 BN
.prototype.or
= function or (num
) {
12887 if (this.length
> num
.length
) return this.clone().ior(num
);
12888 return num
.clone().ior(this);
12891 BN
.prototype.uor
= function uor (num
) {
12892 if (this.length
> num
.length
) return this.clone().iuor(num
);
12893 return num
.clone().iuor(this);
12896 // And `num` with `this` in-place
12897 BN
.prototype.iuand
= function iuand (num
) {
12898 // b = min-length(num, this)
12900 if (this.length
> num
.length
) {
12906 for (var i
= 0; i
< b
.length
; i
++) {
12907 this.words
[i
] = this.words
[i
] & num
.words
[i
];
12910 this.length
= b
.length
;
12912 return this.strip();
12915 BN
.prototype.iand
= function iand (num
) {
12916 assert((this.negative
| num
.negative
) === 0);
12917 return this.iuand(num
);
12920 // And `num` with `this`
12921 BN
.prototype.and
= function and (num
) {
12922 if (this.length
> num
.length
) return this.clone().iand(num
);
12923 return num
.clone().iand(this);
12926 BN
.prototype.uand
= function uand (num
) {
12927 if (this.length
> num
.length
) return this.clone().iuand(num
);
12928 return num
.clone().iuand(this);
12931 // Xor `num` with `this` in-place
12932 BN
.prototype.iuxor
= function iuxor (num
) {
12933 // a.length > b.length
12936 if (this.length
> num
.length
) {
12944 for (var i
= 0; i
< b
.length
; i
++) {
12945 this.words
[i
] = a
.words
[i
] ^ b
.words
[i
];
12949 for (; i
< a
.length
; i
++) {
12950 this.words
[i
] = a
.words
[i
];
12954 this.length
= a
.length
;
12956 return this.strip();
12959 BN
.prototype.ixor
= function ixor (num
) {
12960 assert((this.negative
| num
.negative
) === 0);
12961 return this.iuxor(num
);
12964 // Xor `num` with `this`
12965 BN
.prototype.xor
= function xor (num
) {
12966 if (this.length
> num
.length
) return this.clone().ixor(num
);
12967 return num
.clone().ixor(this);
12970 BN
.prototype.uxor
= function uxor (num
) {
12971 if (this.length
> num
.length
) return this.clone().iuxor(num
);
12972 return num
.clone().iuxor(this);
12975 // Not ``this`` with ``width`` bitwidth
12976 BN
.prototype.inotn
= function inotn (width
) {
12977 assert(typeof width
=== 'number' && width
>= 0);
12979 var bytesNeeded
= Math
.ceil(width
/ 26) | 0;
12980 var bitsLeft
= width
% 26;
12982 // Extend the buffer with leading zeroes
12983 this._expand(bytesNeeded
);
12985 if (bitsLeft
> 0) {
12989 // Handle complete words
12990 for (var i
= 0; i
< bytesNeeded
; i
++) {
12991 this.words
[i
] = ~this.words
[i
] & 0x3ffffff;
12994 // Handle the residue
12995 if (bitsLeft
> 0) {
12996 this.words
[i
] = ~this.words
[i
] & (0x3ffffff >> (26 - bitsLeft
));
12999 // And remove leading zeroes
13000 return this.strip();
13003 BN
.prototype.notn
= function notn (width
) {
13004 return this.clone().inotn(width
);
13007 // Set `bit` of `this`
13008 BN
.prototype.setn
= function setn (bit
, val
) {
13009 assert(typeof bit
=== 'number' && bit
>= 0);
13011 var off
= (bit
/ 26) | 0;
13012 var wbit
= bit
% 26;
13014 this._expand(off
+ 1);
13017 this.words
[off
] = this.words
[off
] | (1 << wbit
);
13019 this.words
[off
] = this.words
[off
] & ~(1 << wbit
);
13022 return this.strip();
13025 // Add `num` to `this` in-place
13026 BN
.prototype.iadd
= function iadd (num
) {
13029 // negative + positive
13030 if (this.negative
!== 0 && num
.negative
=== 0) {
13032 r
= this.isub(num
);
13033 this.negative
^= 1;
13034 return this._normSign();
13036 // positive + negative
13037 } else if (this.negative
=== 0 && num
.negative
!== 0) {
13039 r
= this.isub(num
);
13041 return r
._normSign();
13044 // a.length > b.length
13046 if (this.length
> num
.length
) {
13055 for (var i
= 0; i
< b
.length
; i
++) {
13056 r
= (a
.words
[i
] | 0) + (b
.words
[i
] | 0) + carry
;
13057 this.words
[i
] = r
& 0x3ffffff;
13060 for (; carry
!== 0 && i
< a
.length
; i
++) {
13061 r
= (a
.words
[i
] | 0) + carry
;
13062 this.words
[i
] = r
& 0x3ffffff;
13066 this.length
= a
.length
;
13068 this.words
[this.length
] = carry
;
13070 // Copy the rest of the words
13071 } else if (a
!== this) {
13072 for (; i
< a
.length
; i
++) {
13073 this.words
[i
] = a
.words
[i
];
13080 // Add `num` to `this`
13081 BN
.prototype.add
= function add (num
) {
13083 if (num
.negative
!== 0 && this.negative
=== 0) {
13085 res
= this.sub(num
);
13088 } else if (num
.negative
=== 0 && this.negative
!== 0) {
13090 res
= num
.sub(this);
13095 if (this.length
> num
.length
) return this.clone().iadd(num
);
13097 return num
.clone().iadd(this);
13100 // Subtract `num` from `this` in-place
13101 BN
.prototype.isub
= function isub (num
) {
13102 // this - (-num) = this + num
13103 if (num
.negative
!== 0) {
13105 var r
= this.iadd(num
);
13107 return r
._normSign();
13109 // -this - num = -(this + num)
13110 } else if (this.negative
!== 0) {
13114 return this._normSign();
13117 // At this point both numbers are positive
13118 var cmp
= this.cmp(num
);
13120 // Optimization - zeroify
13139 for (var i
= 0; i
< b
.length
; i
++) {
13140 r
= (a
.words
[i
] | 0) - (b
.words
[i
] | 0) + carry
;
13142 this.words
[i
] = r
& 0x3ffffff;
13144 for (; carry
!== 0 && i
< a
.length
; i
++) {
13145 r
= (a
.words
[i
] | 0) + carry
;
13147 this.words
[i
] = r
& 0x3ffffff;
13150 // Copy rest of the words
13151 if (carry
=== 0 && i
< a
.length
&& a
!== this) {
13152 for (; i
< a
.length
; i
++) {
13153 this.words
[i
] = a
.words
[i
];
13157 this.length
= Math
.max(this.length
, i
);
13163 return this.strip();
13166 // Subtract `num` from `this`
13167 BN
.prototype.sub
= function sub (num
) {
13168 return this.clone().isub(num
);
13171 function smallMulTo (self
, num
, out
) {
13172 out
.negative
= num
.negative
^ self
.negative
;
13173 var len
= (self
.length
+ num
.length
) | 0;
13175 len
= (len
- 1) | 0;
13177 // Peel one iteration (compiler can't do it, because of code complexity)
13178 var a
= self
.words
[0] | 0;
13179 var b
= num
.words
[0] | 0;
13182 var lo
= r
& 0x3ffffff;
13183 var carry
= (r
/ 0x4000000) | 0;
13186 for (var k
= 1; k
< len
; k
++) {
13187 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
13188 // note that ncarry could be >= 0x3ffffff
13189 var ncarry
= carry
>>> 26;
13190 var rword
= carry
& 0x3ffffff;
13191 var maxJ
= Math
.min(k
, num
.length
- 1);
13192 for (var j
= Math
.max(0, k
- self
.length
+ 1); j
<= maxJ
; j
++) {
13193 var i
= (k
- j
) | 0;
13194 a
= self
.words
[i
] | 0;
13195 b
= num
.words
[j
] | 0;
13197 ncarry
+= (r
/ 0x4000000) | 0;
13198 rword
= r
& 0x3ffffff;
13200 out
.words
[k
] = rword
| 0;
13201 carry
= ncarry
| 0;
13204 out
.words
[k
] = carry
| 0;
13209 return out
.strip();
13212 // TODO(indutny): it may be reasonable to omit it for users who don't need
13213 // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
13214 // multiplication (like elliptic secp256k1).
13215 var comb10MulTo
= function comb10MulTo (self
, num
, out
) {
13216 var a
= self
.words
;
13224 var al0
= a0
& 0x1fff;
13225 var ah0
= a0
>>> 13;
13227 var al1
= a1
& 0x1fff;
13228 var ah1
= a1
>>> 13;
13230 var al2
= a2
& 0x1fff;
13231 var ah2
= a2
>>> 13;
13233 var al3
= a3
& 0x1fff;
13234 var ah3
= a3
>>> 13;
13236 var al4
= a4
& 0x1fff;
13237 var ah4
= a4
>>> 13;
13239 var al5
= a5
& 0x1fff;
13240 var ah5
= a5
>>> 13;
13242 var al6
= a6
& 0x1fff;
13243 var ah6
= a6
>>> 13;
13245 var al7
= a7
& 0x1fff;
13246 var ah7
= a7
>>> 13;
13248 var al8
= a8
& 0x1fff;
13249 var ah8
= a8
>>> 13;
13251 var al9
= a9
& 0x1fff;
13252 var ah9
= a9
>>> 13;
13254 var bl0
= b0
& 0x1fff;
13255 var bh0
= b0
>>> 13;
13257 var bl1
= b1
& 0x1fff;
13258 var bh1
= b1
>>> 13;
13260 var bl2
= b2
& 0x1fff;
13261 var bh2
= b2
>>> 13;
13263 var bl3
= b3
& 0x1fff;
13264 var bh3
= b3
>>> 13;
13266 var bl4
= b4
& 0x1fff;
13267 var bh4
= b4
>>> 13;
13269 var bl5
= b5
& 0x1fff;
13270 var bh5
= b5
>>> 13;
13272 var bl6
= b6
& 0x1fff;
13273 var bh6
= b6
>>> 13;
13275 var bl7
= b7
& 0x1fff;
13276 var bh7
= b7
>>> 13;
13278 var bl8
= b8
& 0x1fff;
13279 var bh8
= b8
>>> 13;
13281 var bl9
= b9
& 0x1fff;
13282 var bh9
= b9
>>> 13;
13284 out
.negative
= self
.negative
^ num
.negative
;
13287 lo
= Math
.imul(al0
, bl0
);
13288 mid
= Math
.imul(al0
, bh0
);
13289 mid
= (mid
+ Math
.imul(ah0
, bl0
)) | 0;
13290 hi
= Math
.imul(ah0
, bh0
);
13291 var w0
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13292 c
= (((hi
+ (mid
>>> 13)) | 0) + (w0
>>> 26)) | 0;
13295 lo
= Math
.imul(al1
, bl0
);
13296 mid
= Math
.imul(al1
, bh0
);
13297 mid
= (mid
+ Math
.imul(ah1
, bl0
)) | 0;
13298 hi
= Math
.imul(ah1
, bh0
);
13299 lo
= (lo
+ Math
.imul(al0
, bl1
)) | 0;
13300 mid
= (mid
+ Math
.imul(al0
, bh1
)) | 0;
13301 mid
= (mid
+ Math
.imul(ah0
, bl1
)) | 0;
13302 hi
= (hi
+ Math
.imul(ah0
, bh1
)) | 0;
13303 var w1
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13304 c
= (((hi
+ (mid
>>> 13)) | 0) + (w1
>>> 26)) | 0;
13307 lo
= Math
.imul(al2
, bl0
);
13308 mid
= Math
.imul(al2
, bh0
);
13309 mid
= (mid
+ Math
.imul(ah2
, bl0
)) | 0;
13310 hi
= Math
.imul(ah2
, bh0
);
13311 lo
= (lo
+ Math
.imul(al1
, bl1
)) | 0;
13312 mid
= (mid
+ Math
.imul(al1
, bh1
)) | 0;
13313 mid
= (mid
+ Math
.imul(ah1
, bl1
)) | 0;
13314 hi
= (hi
+ Math
.imul(ah1
, bh1
)) | 0;
13315 lo
= (lo
+ Math
.imul(al0
, bl2
)) | 0;
13316 mid
= (mid
+ Math
.imul(al0
, bh2
)) | 0;
13317 mid
= (mid
+ Math
.imul(ah0
, bl2
)) | 0;
13318 hi
= (hi
+ Math
.imul(ah0
, bh2
)) | 0;
13319 var w2
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13320 c
= (((hi
+ (mid
>>> 13)) | 0) + (w2
>>> 26)) | 0;
13323 lo
= Math
.imul(al3
, bl0
);
13324 mid
= Math
.imul(al3
, bh0
);
13325 mid
= (mid
+ Math
.imul(ah3
, bl0
)) | 0;
13326 hi
= Math
.imul(ah3
, bh0
);
13327 lo
= (lo
+ Math
.imul(al2
, bl1
)) | 0;
13328 mid
= (mid
+ Math
.imul(al2
, bh1
)) | 0;
13329 mid
= (mid
+ Math
.imul(ah2
, bl1
)) | 0;
13330 hi
= (hi
+ Math
.imul(ah2
, bh1
)) | 0;
13331 lo
= (lo
+ Math
.imul(al1
, bl2
)) | 0;
13332 mid
= (mid
+ Math
.imul(al1
, bh2
)) | 0;
13333 mid
= (mid
+ Math
.imul(ah1
, bl2
)) | 0;
13334 hi
= (hi
+ Math
.imul(ah1
, bh2
)) | 0;
13335 lo
= (lo
+ Math
.imul(al0
, bl3
)) | 0;
13336 mid
= (mid
+ Math
.imul(al0
, bh3
)) | 0;
13337 mid
= (mid
+ Math
.imul(ah0
, bl3
)) | 0;
13338 hi
= (hi
+ Math
.imul(ah0
, bh3
)) | 0;
13339 var w3
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13340 c
= (((hi
+ (mid
>>> 13)) | 0) + (w3
>>> 26)) | 0;
13343 lo
= Math
.imul(al4
, bl0
);
13344 mid
= Math
.imul(al4
, bh0
);
13345 mid
= (mid
+ Math
.imul(ah4
, bl0
)) | 0;
13346 hi
= Math
.imul(ah4
, bh0
);
13347 lo
= (lo
+ Math
.imul(al3
, bl1
)) | 0;
13348 mid
= (mid
+ Math
.imul(al3
, bh1
)) | 0;
13349 mid
= (mid
+ Math
.imul(ah3
, bl1
)) | 0;
13350 hi
= (hi
+ Math
.imul(ah3
, bh1
)) | 0;
13351 lo
= (lo
+ Math
.imul(al2
, bl2
)) | 0;
13352 mid
= (mid
+ Math
.imul(al2
, bh2
)) | 0;
13353 mid
= (mid
+ Math
.imul(ah2
, bl2
)) | 0;
13354 hi
= (hi
+ Math
.imul(ah2
, bh2
)) | 0;
13355 lo
= (lo
+ Math
.imul(al1
, bl3
)) | 0;
13356 mid
= (mid
+ Math
.imul(al1
, bh3
)) | 0;
13357 mid
= (mid
+ Math
.imul(ah1
, bl3
)) | 0;
13358 hi
= (hi
+ Math
.imul(ah1
, bh3
)) | 0;
13359 lo
= (lo
+ Math
.imul(al0
, bl4
)) | 0;
13360 mid
= (mid
+ Math
.imul(al0
, bh4
)) | 0;
13361 mid
= (mid
+ Math
.imul(ah0
, bl4
)) | 0;
13362 hi
= (hi
+ Math
.imul(ah0
, bh4
)) | 0;
13363 var w4
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13364 c
= (((hi
+ (mid
>>> 13)) | 0) + (w4
>>> 26)) | 0;
13367 lo
= Math
.imul(al5
, bl0
);
13368 mid
= Math
.imul(al5
, bh0
);
13369 mid
= (mid
+ Math
.imul(ah5
, bl0
)) | 0;
13370 hi
= Math
.imul(ah5
, bh0
);
13371 lo
= (lo
+ Math
.imul(al4
, bl1
)) | 0;
13372 mid
= (mid
+ Math
.imul(al4
, bh1
)) | 0;
13373 mid
= (mid
+ Math
.imul(ah4
, bl1
)) | 0;
13374 hi
= (hi
+ Math
.imul(ah4
, bh1
)) | 0;
13375 lo
= (lo
+ Math
.imul(al3
, bl2
)) | 0;
13376 mid
= (mid
+ Math
.imul(al3
, bh2
)) | 0;
13377 mid
= (mid
+ Math
.imul(ah3
, bl2
)) | 0;
13378 hi
= (hi
+ Math
.imul(ah3
, bh2
)) | 0;
13379 lo
= (lo
+ Math
.imul(al2
, bl3
)) | 0;
13380 mid
= (mid
+ Math
.imul(al2
, bh3
)) | 0;
13381 mid
= (mid
+ Math
.imul(ah2
, bl3
)) | 0;
13382 hi
= (hi
+ Math
.imul(ah2
, bh3
)) | 0;
13383 lo
= (lo
+ Math
.imul(al1
, bl4
)) | 0;
13384 mid
= (mid
+ Math
.imul(al1
, bh4
)) | 0;
13385 mid
= (mid
+ Math
.imul(ah1
, bl4
)) | 0;
13386 hi
= (hi
+ Math
.imul(ah1
, bh4
)) | 0;
13387 lo
= (lo
+ Math
.imul(al0
, bl5
)) | 0;
13388 mid
= (mid
+ Math
.imul(al0
, bh5
)) | 0;
13389 mid
= (mid
+ Math
.imul(ah0
, bl5
)) | 0;
13390 hi
= (hi
+ Math
.imul(ah0
, bh5
)) | 0;
13391 var w5
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13392 c
= (((hi
+ (mid
>>> 13)) | 0) + (w5
>>> 26)) | 0;
13395 lo
= Math
.imul(al6
, bl0
);
13396 mid
= Math
.imul(al6
, bh0
);
13397 mid
= (mid
+ Math
.imul(ah6
, bl0
)) | 0;
13398 hi
= Math
.imul(ah6
, bh0
);
13399 lo
= (lo
+ Math
.imul(al5
, bl1
)) | 0;
13400 mid
= (mid
+ Math
.imul(al5
, bh1
)) | 0;
13401 mid
= (mid
+ Math
.imul(ah5
, bl1
)) | 0;
13402 hi
= (hi
+ Math
.imul(ah5
, bh1
)) | 0;
13403 lo
= (lo
+ Math
.imul(al4
, bl2
)) | 0;
13404 mid
= (mid
+ Math
.imul(al4
, bh2
)) | 0;
13405 mid
= (mid
+ Math
.imul(ah4
, bl2
)) | 0;
13406 hi
= (hi
+ Math
.imul(ah4
, bh2
)) | 0;
13407 lo
= (lo
+ Math
.imul(al3
, bl3
)) | 0;
13408 mid
= (mid
+ Math
.imul(al3
, bh3
)) | 0;
13409 mid
= (mid
+ Math
.imul(ah3
, bl3
)) | 0;
13410 hi
= (hi
+ Math
.imul(ah3
, bh3
)) | 0;
13411 lo
= (lo
+ Math
.imul(al2
, bl4
)) | 0;
13412 mid
= (mid
+ Math
.imul(al2
, bh4
)) | 0;
13413 mid
= (mid
+ Math
.imul(ah2
, bl4
)) | 0;
13414 hi
= (hi
+ Math
.imul(ah2
, bh4
)) | 0;
13415 lo
= (lo
+ Math
.imul(al1
, bl5
)) | 0;
13416 mid
= (mid
+ Math
.imul(al1
, bh5
)) | 0;
13417 mid
= (mid
+ Math
.imul(ah1
, bl5
)) | 0;
13418 hi
= (hi
+ Math
.imul(ah1
, bh5
)) | 0;
13419 lo
= (lo
+ Math
.imul(al0
, bl6
)) | 0;
13420 mid
= (mid
+ Math
.imul(al0
, bh6
)) | 0;
13421 mid
= (mid
+ Math
.imul(ah0
, bl6
)) | 0;
13422 hi
= (hi
+ Math
.imul(ah0
, bh6
)) | 0;
13423 var w6
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13424 c
= (((hi
+ (mid
>>> 13)) | 0) + (w6
>>> 26)) | 0;
13427 lo
= Math
.imul(al7
, bl0
);
13428 mid
= Math
.imul(al7
, bh0
);
13429 mid
= (mid
+ Math
.imul(ah7
, bl0
)) | 0;
13430 hi
= Math
.imul(ah7
, bh0
);
13431 lo
= (lo
+ Math
.imul(al6
, bl1
)) | 0;
13432 mid
= (mid
+ Math
.imul(al6
, bh1
)) | 0;
13433 mid
= (mid
+ Math
.imul(ah6
, bl1
)) | 0;
13434 hi
= (hi
+ Math
.imul(ah6
, bh1
)) | 0;
13435 lo
= (lo
+ Math
.imul(al5
, bl2
)) | 0;
13436 mid
= (mid
+ Math
.imul(al5
, bh2
)) | 0;
13437 mid
= (mid
+ Math
.imul(ah5
, bl2
)) | 0;
13438 hi
= (hi
+ Math
.imul(ah5
, bh2
)) | 0;
13439 lo
= (lo
+ Math
.imul(al4
, bl3
)) | 0;
13440 mid
= (mid
+ Math
.imul(al4
, bh3
)) | 0;
13441 mid
= (mid
+ Math
.imul(ah4
, bl3
)) | 0;
13442 hi
= (hi
+ Math
.imul(ah4
, bh3
)) | 0;
13443 lo
= (lo
+ Math
.imul(al3
, bl4
)) | 0;
13444 mid
= (mid
+ Math
.imul(al3
, bh4
)) | 0;
13445 mid
= (mid
+ Math
.imul(ah3
, bl4
)) | 0;
13446 hi
= (hi
+ Math
.imul(ah3
, bh4
)) | 0;
13447 lo
= (lo
+ Math
.imul(al2
, bl5
)) | 0;
13448 mid
= (mid
+ Math
.imul(al2
, bh5
)) | 0;
13449 mid
= (mid
+ Math
.imul(ah2
, bl5
)) | 0;
13450 hi
= (hi
+ Math
.imul(ah2
, bh5
)) | 0;
13451 lo
= (lo
+ Math
.imul(al1
, bl6
)) | 0;
13452 mid
= (mid
+ Math
.imul(al1
, bh6
)) | 0;
13453 mid
= (mid
+ Math
.imul(ah1
, bl6
)) | 0;
13454 hi
= (hi
+ Math
.imul(ah1
, bh6
)) | 0;
13455 lo
= (lo
+ Math
.imul(al0
, bl7
)) | 0;
13456 mid
= (mid
+ Math
.imul(al0
, bh7
)) | 0;
13457 mid
= (mid
+ Math
.imul(ah0
, bl7
)) | 0;
13458 hi
= (hi
+ Math
.imul(ah0
, bh7
)) | 0;
13459 var w7
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13460 c
= (((hi
+ (mid
>>> 13)) | 0) + (w7
>>> 26)) | 0;
13463 lo
= Math
.imul(al8
, bl0
);
13464 mid
= Math
.imul(al8
, bh0
);
13465 mid
= (mid
+ Math
.imul(ah8
, bl0
)) | 0;
13466 hi
= Math
.imul(ah8
, bh0
);
13467 lo
= (lo
+ Math
.imul(al7
, bl1
)) | 0;
13468 mid
= (mid
+ Math
.imul(al7
, bh1
)) | 0;
13469 mid
= (mid
+ Math
.imul(ah7
, bl1
)) | 0;
13470 hi
= (hi
+ Math
.imul(ah7
, bh1
)) | 0;
13471 lo
= (lo
+ Math
.imul(al6
, bl2
)) | 0;
13472 mid
= (mid
+ Math
.imul(al6
, bh2
)) | 0;
13473 mid
= (mid
+ Math
.imul(ah6
, bl2
)) | 0;
13474 hi
= (hi
+ Math
.imul(ah6
, bh2
)) | 0;
13475 lo
= (lo
+ Math
.imul(al5
, bl3
)) | 0;
13476 mid
= (mid
+ Math
.imul(al5
, bh3
)) | 0;
13477 mid
= (mid
+ Math
.imul(ah5
, bl3
)) | 0;
13478 hi
= (hi
+ Math
.imul(ah5
, bh3
)) | 0;
13479 lo
= (lo
+ Math
.imul(al4
, bl4
)) | 0;
13480 mid
= (mid
+ Math
.imul(al4
, bh4
)) | 0;
13481 mid
= (mid
+ Math
.imul(ah4
, bl4
)) | 0;
13482 hi
= (hi
+ Math
.imul(ah4
, bh4
)) | 0;
13483 lo
= (lo
+ Math
.imul(al3
, bl5
)) | 0;
13484 mid
= (mid
+ Math
.imul(al3
, bh5
)) | 0;
13485 mid
= (mid
+ Math
.imul(ah3
, bl5
)) | 0;
13486 hi
= (hi
+ Math
.imul(ah3
, bh5
)) | 0;
13487 lo
= (lo
+ Math
.imul(al2
, bl6
)) | 0;
13488 mid
= (mid
+ Math
.imul(al2
, bh6
)) | 0;
13489 mid
= (mid
+ Math
.imul(ah2
, bl6
)) | 0;
13490 hi
= (hi
+ Math
.imul(ah2
, bh6
)) | 0;
13491 lo
= (lo
+ Math
.imul(al1
, bl7
)) | 0;
13492 mid
= (mid
+ Math
.imul(al1
, bh7
)) | 0;
13493 mid
= (mid
+ Math
.imul(ah1
, bl7
)) | 0;
13494 hi
= (hi
+ Math
.imul(ah1
, bh7
)) | 0;
13495 lo
= (lo
+ Math
.imul(al0
, bl8
)) | 0;
13496 mid
= (mid
+ Math
.imul(al0
, bh8
)) | 0;
13497 mid
= (mid
+ Math
.imul(ah0
, bl8
)) | 0;
13498 hi
= (hi
+ Math
.imul(ah0
, bh8
)) | 0;
13499 var w8
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13500 c
= (((hi
+ (mid
>>> 13)) | 0) + (w8
>>> 26)) | 0;
13503 lo
= Math
.imul(al9
, bl0
);
13504 mid
= Math
.imul(al9
, bh0
);
13505 mid
= (mid
+ Math
.imul(ah9
, bl0
)) | 0;
13506 hi
= Math
.imul(ah9
, bh0
);
13507 lo
= (lo
+ Math
.imul(al8
, bl1
)) | 0;
13508 mid
= (mid
+ Math
.imul(al8
, bh1
)) | 0;
13509 mid
= (mid
+ Math
.imul(ah8
, bl1
)) | 0;
13510 hi
= (hi
+ Math
.imul(ah8
, bh1
)) | 0;
13511 lo
= (lo
+ Math
.imul(al7
, bl2
)) | 0;
13512 mid
= (mid
+ Math
.imul(al7
, bh2
)) | 0;
13513 mid
= (mid
+ Math
.imul(ah7
, bl2
)) | 0;
13514 hi
= (hi
+ Math
.imul(ah7
, bh2
)) | 0;
13515 lo
= (lo
+ Math
.imul(al6
, bl3
)) | 0;
13516 mid
= (mid
+ Math
.imul(al6
, bh3
)) | 0;
13517 mid
= (mid
+ Math
.imul(ah6
, bl3
)) | 0;
13518 hi
= (hi
+ Math
.imul(ah6
, bh3
)) | 0;
13519 lo
= (lo
+ Math
.imul(al5
, bl4
)) | 0;
13520 mid
= (mid
+ Math
.imul(al5
, bh4
)) | 0;
13521 mid
= (mid
+ Math
.imul(ah5
, bl4
)) | 0;
13522 hi
= (hi
+ Math
.imul(ah5
, bh4
)) | 0;
13523 lo
= (lo
+ Math
.imul(al4
, bl5
)) | 0;
13524 mid
= (mid
+ Math
.imul(al4
, bh5
)) | 0;
13525 mid
= (mid
+ Math
.imul(ah4
, bl5
)) | 0;
13526 hi
= (hi
+ Math
.imul(ah4
, bh5
)) | 0;
13527 lo
= (lo
+ Math
.imul(al3
, bl6
)) | 0;
13528 mid
= (mid
+ Math
.imul(al3
, bh6
)) | 0;
13529 mid
= (mid
+ Math
.imul(ah3
, bl6
)) | 0;
13530 hi
= (hi
+ Math
.imul(ah3
, bh6
)) | 0;
13531 lo
= (lo
+ Math
.imul(al2
, bl7
)) | 0;
13532 mid
= (mid
+ Math
.imul(al2
, bh7
)) | 0;
13533 mid
= (mid
+ Math
.imul(ah2
, bl7
)) | 0;
13534 hi
= (hi
+ Math
.imul(ah2
, bh7
)) | 0;
13535 lo
= (lo
+ Math
.imul(al1
, bl8
)) | 0;
13536 mid
= (mid
+ Math
.imul(al1
, bh8
)) | 0;
13537 mid
= (mid
+ Math
.imul(ah1
, bl8
)) | 0;
13538 hi
= (hi
+ Math
.imul(ah1
, bh8
)) | 0;
13539 lo
= (lo
+ Math
.imul(al0
, bl9
)) | 0;
13540 mid
= (mid
+ Math
.imul(al0
, bh9
)) | 0;
13541 mid
= (mid
+ Math
.imul(ah0
, bl9
)) | 0;
13542 hi
= (hi
+ Math
.imul(ah0
, bh9
)) | 0;
13543 var w9
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13544 c
= (((hi
+ (mid
>>> 13)) | 0) + (w9
>>> 26)) | 0;
13547 lo
= Math
.imul(al9
, bl1
);
13548 mid
= Math
.imul(al9
, bh1
);
13549 mid
= (mid
+ Math
.imul(ah9
, bl1
)) | 0;
13550 hi
= Math
.imul(ah9
, bh1
);
13551 lo
= (lo
+ Math
.imul(al8
, bl2
)) | 0;
13552 mid
= (mid
+ Math
.imul(al8
, bh2
)) | 0;
13553 mid
= (mid
+ Math
.imul(ah8
, bl2
)) | 0;
13554 hi
= (hi
+ Math
.imul(ah8
, bh2
)) | 0;
13555 lo
= (lo
+ Math
.imul(al7
, bl3
)) | 0;
13556 mid
= (mid
+ Math
.imul(al7
, bh3
)) | 0;
13557 mid
= (mid
+ Math
.imul(ah7
, bl3
)) | 0;
13558 hi
= (hi
+ Math
.imul(ah7
, bh3
)) | 0;
13559 lo
= (lo
+ Math
.imul(al6
, bl4
)) | 0;
13560 mid
= (mid
+ Math
.imul(al6
, bh4
)) | 0;
13561 mid
= (mid
+ Math
.imul(ah6
, bl4
)) | 0;
13562 hi
= (hi
+ Math
.imul(ah6
, bh4
)) | 0;
13563 lo
= (lo
+ Math
.imul(al5
, bl5
)) | 0;
13564 mid
= (mid
+ Math
.imul(al5
, bh5
)) | 0;
13565 mid
= (mid
+ Math
.imul(ah5
, bl5
)) | 0;
13566 hi
= (hi
+ Math
.imul(ah5
, bh5
)) | 0;
13567 lo
= (lo
+ Math
.imul(al4
, bl6
)) | 0;
13568 mid
= (mid
+ Math
.imul(al4
, bh6
)) | 0;
13569 mid
= (mid
+ Math
.imul(ah4
, bl6
)) | 0;
13570 hi
= (hi
+ Math
.imul(ah4
, bh6
)) | 0;
13571 lo
= (lo
+ Math
.imul(al3
, bl7
)) | 0;
13572 mid
= (mid
+ Math
.imul(al3
, bh7
)) | 0;
13573 mid
= (mid
+ Math
.imul(ah3
, bl7
)) | 0;
13574 hi
= (hi
+ Math
.imul(ah3
, bh7
)) | 0;
13575 lo
= (lo
+ Math
.imul(al2
, bl8
)) | 0;
13576 mid
= (mid
+ Math
.imul(al2
, bh8
)) | 0;
13577 mid
= (mid
+ Math
.imul(ah2
, bl8
)) | 0;
13578 hi
= (hi
+ Math
.imul(ah2
, bh8
)) | 0;
13579 lo
= (lo
+ Math
.imul(al1
, bl9
)) | 0;
13580 mid
= (mid
+ Math
.imul(al1
, bh9
)) | 0;
13581 mid
= (mid
+ Math
.imul(ah1
, bl9
)) | 0;
13582 hi
= (hi
+ Math
.imul(ah1
, bh9
)) | 0;
13583 var w10
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13584 c
= (((hi
+ (mid
>>> 13)) | 0) + (w10
>>> 26)) | 0;
13587 lo
= Math
.imul(al9
, bl2
);
13588 mid
= Math
.imul(al9
, bh2
);
13589 mid
= (mid
+ Math
.imul(ah9
, bl2
)) | 0;
13590 hi
= Math
.imul(ah9
, bh2
);
13591 lo
= (lo
+ Math
.imul(al8
, bl3
)) | 0;
13592 mid
= (mid
+ Math
.imul(al8
, bh3
)) | 0;
13593 mid
= (mid
+ Math
.imul(ah8
, bl3
)) | 0;
13594 hi
= (hi
+ Math
.imul(ah8
, bh3
)) | 0;
13595 lo
= (lo
+ Math
.imul(al7
, bl4
)) | 0;
13596 mid
= (mid
+ Math
.imul(al7
, bh4
)) | 0;
13597 mid
= (mid
+ Math
.imul(ah7
, bl4
)) | 0;
13598 hi
= (hi
+ Math
.imul(ah7
, bh4
)) | 0;
13599 lo
= (lo
+ Math
.imul(al6
, bl5
)) | 0;
13600 mid
= (mid
+ Math
.imul(al6
, bh5
)) | 0;
13601 mid
= (mid
+ Math
.imul(ah6
, bl5
)) | 0;
13602 hi
= (hi
+ Math
.imul(ah6
, bh5
)) | 0;
13603 lo
= (lo
+ Math
.imul(al5
, bl6
)) | 0;
13604 mid
= (mid
+ Math
.imul(al5
, bh6
)) | 0;
13605 mid
= (mid
+ Math
.imul(ah5
, bl6
)) | 0;
13606 hi
= (hi
+ Math
.imul(ah5
, bh6
)) | 0;
13607 lo
= (lo
+ Math
.imul(al4
, bl7
)) | 0;
13608 mid
= (mid
+ Math
.imul(al4
, bh7
)) | 0;
13609 mid
= (mid
+ Math
.imul(ah4
, bl7
)) | 0;
13610 hi
= (hi
+ Math
.imul(ah4
, bh7
)) | 0;
13611 lo
= (lo
+ Math
.imul(al3
, bl8
)) | 0;
13612 mid
= (mid
+ Math
.imul(al3
, bh8
)) | 0;
13613 mid
= (mid
+ Math
.imul(ah3
, bl8
)) | 0;
13614 hi
= (hi
+ Math
.imul(ah3
, bh8
)) | 0;
13615 lo
= (lo
+ Math
.imul(al2
, bl9
)) | 0;
13616 mid
= (mid
+ Math
.imul(al2
, bh9
)) | 0;
13617 mid
= (mid
+ Math
.imul(ah2
, bl9
)) | 0;
13618 hi
= (hi
+ Math
.imul(ah2
, bh9
)) | 0;
13619 var w11
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13620 c
= (((hi
+ (mid
>>> 13)) | 0) + (w11
>>> 26)) | 0;
13623 lo
= Math
.imul(al9
, bl3
);
13624 mid
= Math
.imul(al9
, bh3
);
13625 mid
= (mid
+ Math
.imul(ah9
, bl3
)) | 0;
13626 hi
= Math
.imul(ah9
, bh3
);
13627 lo
= (lo
+ Math
.imul(al8
, bl4
)) | 0;
13628 mid
= (mid
+ Math
.imul(al8
, bh4
)) | 0;
13629 mid
= (mid
+ Math
.imul(ah8
, bl4
)) | 0;
13630 hi
= (hi
+ Math
.imul(ah8
, bh4
)) | 0;
13631 lo
= (lo
+ Math
.imul(al7
, bl5
)) | 0;
13632 mid
= (mid
+ Math
.imul(al7
, bh5
)) | 0;
13633 mid
= (mid
+ Math
.imul(ah7
, bl5
)) | 0;
13634 hi
= (hi
+ Math
.imul(ah7
, bh5
)) | 0;
13635 lo
= (lo
+ Math
.imul(al6
, bl6
)) | 0;
13636 mid
= (mid
+ Math
.imul(al6
, bh6
)) | 0;
13637 mid
= (mid
+ Math
.imul(ah6
, bl6
)) | 0;
13638 hi
= (hi
+ Math
.imul(ah6
, bh6
)) | 0;
13639 lo
= (lo
+ Math
.imul(al5
, bl7
)) | 0;
13640 mid
= (mid
+ Math
.imul(al5
, bh7
)) | 0;
13641 mid
= (mid
+ Math
.imul(ah5
, bl7
)) | 0;
13642 hi
= (hi
+ Math
.imul(ah5
, bh7
)) | 0;
13643 lo
= (lo
+ Math
.imul(al4
, bl8
)) | 0;
13644 mid
= (mid
+ Math
.imul(al4
, bh8
)) | 0;
13645 mid
= (mid
+ Math
.imul(ah4
, bl8
)) | 0;
13646 hi
= (hi
+ Math
.imul(ah4
, bh8
)) | 0;
13647 lo
= (lo
+ Math
.imul(al3
, bl9
)) | 0;
13648 mid
= (mid
+ Math
.imul(al3
, bh9
)) | 0;
13649 mid
= (mid
+ Math
.imul(ah3
, bl9
)) | 0;
13650 hi
= (hi
+ Math
.imul(ah3
, bh9
)) | 0;
13651 var w12
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13652 c
= (((hi
+ (mid
>>> 13)) | 0) + (w12
>>> 26)) | 0;
13655 lo
= Math
.imul(al9
, bl4
);
13656 mid
= Math
.imul(al9
, bh4
);
13657 mid
= (mid
+ Math
.imul(ah9
, bl4
)) | 0;
13658 hi
= Math
.imul(ah9
, bh4
);
13659 lo
= (lo
+ Math
.imul(al8
, bl5
)) | 0;
13660 mid
= (mid
+ Math
.imul(al8
, bh5
)) | 0;
13661 mid
= (mid
+ Math
.imul(ah8
, bl5
)) | 0;
13662 hi
= (hi
+ Math
.imul(ah8
, bh5
)) | 0;
13663 lo
= (lo
+ Math
.imul(al7
, bl6
)) | 0;
13664 mid
= (mid
+ Math
.imul(al7
, bh6
)) | 0;
13665 mid
= (mid
+ Math
.imul(ah7
, bl6
)) | 0;
13666 hi
= (hi
+ Math
.imul(ah7
, bh6
)) | 0;
13667 lo
= (lo
+ Math
.imul(al6
, bl7
)) | 0;
13668 mid
= (mid
+ Math
.imul(al6
, bh7
)) | 0;
13669 mid
= (mid
+ Math
.imul(ah6
, bl7
)) | 0;
13670 hi
= (hi
+ Math
.imul(ah6
, bh7
)) | 0;
13671 lo
= (lo
+ Math
.imul(al5
, bl8
)) | 0;
13672 mid
= (mid
+ Math
.imul(al5
, bh8
)) | 0;
13673 mid
= (mid
+ Math
.imul(ah5
, bl8
)) | 0;
13674 hi
= (hi
+ Math
.imul(ah5
, bh8
)) | 0;
13675 lo
= (lo
+ Math
.imul(al4
, bl9
)) | 0;
13676 mid
= (mid
+ Math
.imul(al4
, bh9
)) | 0;
13677 mid
= (mid
+ Math
.imul(ah4
, bl9
)) | 0;
13678 hi
= (hi
+ Math
.imul(ah4
, bh9
)) | 0;
13679 var w13
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13680 c
= (((hi
+ (mid
>>> 13)) | 0) + (w13
>>> 26)) | 0;
13683 lo
= Math
.imul(al9
, bl5
);
13684 mid
= Math
.imul(al9
, bh5
);
13685 mid
= (mid
+ Math
.imul(ah9
, bl5
)) | 0;
13686 hi
= Math
.imul(ah9
, bh5
);
13687 lo
= (lo
+ Math
.imul(al8
, bl6
)) | 0;
13688 mid
= (mid
+ Math
.imul(al8
, bh6
)) | 0;
13689 mid
= (mid
+ Math
.imul(ah8
, bl6
)) | 0;
13690 hi
= (hi
+ Math
.imul(ah8
, bh6
)) | 0;
13691 lo
= (lo
+ Math
.imul(al7
, bl7
)) | 0;
13692 mid
= (mid
+ Math
.imul(al7
, bh7
)) | 0;
13693 mid
= (mid
+ Math
.imul(ah7
, bl7
)) | 0;
13694 hi
= (hi
+ Math
.imul(ah7
, bh7
)) | 0;
13695 lo
= (lo
+ Math
.imul(al6
, bl8
)) | 0;
13696 mid
= (mid
+ Math
.imul(al6
, bh8
)) | 0;
13697 mid
= (mid
+ Math
.imul(ah6
, bl8
)) | 0;
13698 hi
= (hi
+ Math
.imul(ah6
, bh8
)) | 0;
13699 lo
= (lo
+ Math
.imul(al5
, bl9
)) | 0;
13700 mid
= (mid
+ Math
.imul(al5
, bh9
)) | 0;
13701 mid
= (mid
+ Math
.imul(ah5
, bl9
)) | 0;
13702 hi
= (hi
+ Math
.imul(ah5
, bh9
)) | 0;
13703 var w14
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13704 c
= (((hi
+ (mid
>>> 13)) | 0) + (w14
>>> 26)) | 0;
13707 lo
= Math
.imul(al9
, bl6
);
13708 mid
= Math
.imul(al9
, bh6
);
13709 mid
= (mid
+ Math
.imul(ah9
, bl6
)) | 0;
13710 hi
= Math
.imul(ah9
, bh6
);
13711 lo
= (lo
+ Math
.imul(al8
, bl7
)) | 0;
13712 mid
= (mid
+ Math
.imul(al8
, bh7
)) | 0;
13713 mid
= (mid
+ Math
.imul(ah8
, bl7
)) | 0;
13714 hi
= (hi
+ Math
.imul(ah8
, bh7
)) | 0;
13715 lo
= (lo
+ Math
.imul(al7
, bl8
)) | 0;
13716 mid
= (mid
+ Math
.imul(al7
, bh8
)) | 0;
13717 mid
= (mid
+ Math
.imul(ah7
, bl8
)) | 0;
13718 hi
= (hi
+ Math
.imul(ah7
, bh8
)) | 0;
13719 lo
= (lo
+ Math
.imul(al6
, bl9
)) | 0;
13720 mid
= (mid
+ Math
.imul(al6
, bh9
)) | 0;
13721 mid
= (mid
+ Math
.imul(ah6
, bl9
)) | 0;
13722 hi
= (hi
+ Math
.imul(ah6
, bh9
)) | 0;
13723 var w15
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13724 c
= (((hi
+ (mid
>>> 13)) | 0) + (w15
>>> 26)) | 0;
13727 lo
= Math
.imul(al9
, bl7
);
13728 mid
= Math
.imul(al9
, bh7
);
13729 mid
= (mid
+ Math
.imul(ah9
, bl7
)) | 0;
13730 hi
= Math
.imul(ah9
, bh7
);
13731 lo
= (lo
+ Math
.imul(al8
, bl8
)) | 0;
13732 mid
= (mid
+ Math
.imul(al8
, bh8
)) | 0;
13733 mid
= (mid
+ Math
.imul(ah8
, bl8
)) | 0;
13734 hi
= (hi
+ Math
.imul(ah8
, bh8
)) | 0;
13735 lo
= (lo
+ Math
.imul(al7
, bl9
)) | 0;
13736 mid
= (mid
+ Math
.imul(al7
, bh9
)) | 0;
13737 mid
= (mid
+ Math
.imul(ah7
, bl9
)) | 0;
13738 hi
= (hi
+ Math
.imul(ah7
, bh9
)) | 0;
13739 var w16
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13740 c
= (((hi
+ (mid
>>> 13)) | 0) + (w16
>>> 26)) | 0;
13743 lo
= Math
.imul(al9
, bl8
);
13744 mid
= Math
.imul(al9
, bh8
);
13745 mid
= (mid
+ Math
.imul(ah9
, bl8
)) | 0;
13746 hi
= Math
.imul(ah9
, bh8
);
13747 lo
= (lo
+ Math
.imul(al8
, bl9
)) | 0;
13748 mid
= (mid
+ Math
.imul(al8
, bh9
)) | 0;
13749 mid
= (mid
+ Math
.imul(ah8
, bl9
)) | 0;
13750 hi
= (hi
+ Math
.imul(ah8
, bh9
)) | 0;
13751 var w17
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13752 c
= (((hi
+ (mid
>>> 13)) | 0) + (w17
>>> 26)) | 0;
13755 lo
= Math
.imul(al9
, bl9
);
13756 mid
= Math
.imul(al9
, bh9
);
13757 mid
= (mid
+ Math
.imul(ah9
, bl9
)) | 0;
13758 hi
= Math
.imul(ah9
, bh9
);
13759 var w18
= (((c
+ lo
) | 0) + ((mid
& 0x1fff) << 13)) | 0;
13760 c
= (((hi
+ (mid
>>> 13)) | 0) + (w18
>>> 26)) | 0;
13790 comb10MulTo
= smallMulTo
;
13793 function bigMulTo (self
, num
, out
) {
13794 out
.negative
= num
.negative
^ self
.negative
;
13795 out
.length
= self
.length
+ num
.length
;
13799 for (var k
= 0; k
< out
.length
- 1; k
++) {
13800 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
13801 // note that ncarry could be >= 0x3ffffff
13802 var ncarry
= hncarry
;
13804 var rword
= carry
& 0x3ffffff;
13805 var maxJ
= Math
.min(k
, num
.length
- 1);
13806 for (var j
= Math
.max(0, k
- self
.length
+ 1); j
<= maxJ
; j
++) {
13808 var a
= self
.words
[i
] | 0;
13809 var b
= num
.words
[j
] | 0;
13812 var lo
= r
& 0x3ffffff;
13813 ncarry
= (ncarry
+ ((r
/ 0x4000000) | 0)) | 0;
13814 lo
= (lo
+ rword
) | 0;
13815 rword
= lo
& 0x3ffffff;
13816 ncarry
= (ncarry
+ (lo
>>> 26)) | 0;
13818 hncarry
+= ncarry
>>> 26;
13819 ncarry
&= 0x3ffffff;
13821 out
.words
[k
] = rword
;
13826 out
.words
[k
] = carry
;
13831 return out
.strip();
13834 function jumboMulTo (self
, num
, out
) {
13835 var fftm
= new FFTM();
13836 return fftm
.mulp(self
, num
, out
);
13839 BN
.prototype.mulTo
= function mulTo (num
, out
) {
13841 var len
= this.length
+ num
.length
;
13842 if (this.length
=== 10 && num
.length
=== 10) {
13843 res
= comb10MulTo(this, num
, out
);
13844 } else if (len
< 63) {
13845 res
= smallMulTo(this, num
, out
);
13846 } else if (len
< 1024) {
13847 res
= bigMulTo(this, num
, out
);
13849 res
= jumboMulTo(this, num
, out
);
13855 // Cooley-Tukey algorithm for FFT
13856 // slightly revisited to rely on looping instead of recursion
13858 function FFTM (x
, y
) {
13863 FFTM
.prototype.makeRBT
= function makeRBT (N
) {
13864 var t
= new Array(N
);
13865 var l
= BN
.prototype._countBits(N
) - 1;
13866 for (var i
= 0; i
< N
; i
++) {
13867 t
[i
] = this.revBin(i
, l
, N
);
13873 // Returns binary-reversed representation of `x`
13874 FFTM
.prototype.revBin
= function revBin (x
, l
, N
) {
13875 if (x
=== 0 || x
=== N
- 1) return x
;
13878 for (var i
= 0; i
< l
; i
++) {
13879 rb
|= (x
& 1) << (l
- i
- 1);
13886 // Performs "tweedling" phase, therefore 'emulating'
13887 // behaviour of the recursive algorithm
13888 FFTM
.prototype.permute
= function permute (rbt
, rws
, iws
, rtws
, itws
, N
) {
13889 for (var i
= 0; i
< N
; i
++) {
13890 rtws
[i
] = rws
[rbt
[i
]];
13891 itws
[i
] = iws
[rbt
[i
]];
13895 FFTM
.prototype.transform
= function transform (rws
, iws
, rtws
, itws
, N
, rbt
) {
13896 this.permute(rbt
, rws
, iws
, rtws
, itws
, N
);
13898 for (var s
= 1; s
< N
; s
<<= 1) {
13901 var rtwdf
= Math
.cos(2 * Math
.PI
/ l
);
13902 var itwdf
= Math
.sin(2 * Math
.PI
/ l
);
13904 for (var p
= 0; p
< N
; p
+= l
) {
13905 var rtwdf_
= rtwdf
;
13906 var itwdf_
= itwdf
;
13908 for (var j
= 0; j
< s
; j
++) {
13909 var re
= rtws
[p
+ j
];
13910 var ie
= itws
[p
+ j
];
13912 var ro
= rtws
[p
+ j
+ s
];
13913 var io
= itws
[p
+ j
+ s
];
13915 var rx
= rtwdf_
* ro
- itwdf_
* io
;
13917 io
= rtwdf_
* io
+ itwdf_
* ro
;
13920 rtws
[p
+ j
] = re
+ ro
;
13921 itws
[p
+ j
] = ie
+ io
;
13923 rtws
[p
+ j
+ s
] = re
- ro
;
13924 itws
[p
+ j
+ s
] = ie
- io
;
13926 /* jshint maxdepth : false */
13928 rx
= rtwdf
* rtwdf_
- itwdf
* itwdf_
;
13930 itwdf_
= rtwdf
* itwdf_
+ itwdf
* rtwdf_
;
13938 FFTM
.prototype.guessLen13b
= function guessLen13b (n
, m
) {
13939 var N
= Math
.max(m
, n
) | 1;
13942 for (N
= N
/ 2 | 0; N
; N
= N
>>> 1) {
13946 return 1 << i
+ 1 + odd
;
13949 FFTM
.prototype.conjugate
= function conjugate (rws
, iws
, N
) {
13950 if (N
<= 1) return;
13952 for (var i
= 0; i
< N
/ 2; i
++) {
13955 rws
[i
] = rws
[N
- i
- 1];
13956 rws
[N
- i
- 1] = t
;
13960 iws
[i
] = -iws
[N
- i
- 1];
13961 iws
[N
- i
- 1] = -t
;
13965 FFTM
.prototype.normalize13b
= function normalize13b (ws
, N
) {
13967 for (var i
= 0; i
< N
/ 2; i
++) {
13968 var w
= Math
.round(ws
[2 * i
+ 1] / N
) * 0x2000 +
13969 Math
.round(ws
[2 * i
] / N
) +
13972 ws
[i
] = w
& 0x3ffffff;
13974 if (w
< 0x4000000) {
13977 carry
= w
/ 0x4000000 | 0;
13984 FFTM
.prototype.convert13b
= function convert13b (ws
, len
, rws
, N
) {
13986 for (var i
= 0; i
< len
; i
++) {
13987 carry
= carry
+ (ws
[i
] | 0);
13989 rws
[2 * i
] = carry
& 0x1fff; carry
= carry
>>> 13;
13990 rws
[2 * i
+ 1] = carry
& 0x1fff; carry
= carry
>>> 13;
13994 for (i
= 2 * len
; i
< N
; ++i
) {
13998 assert(carry
=== 0);
13999 assert((carry
& ~0x1fff) === 0);
14002 FFTM
.prototype.stub
= function stub (N
) {
14003 var ph
= new Array(N
);
14004 for (var i
= 0; i
< N
; i
++) {
14011 FFTM
.prototype.mulp
= function mulp (x
, y
, out
) {
14012 var N
= 2 * this.guessLen13b(x
.length
, y
.length
);
14014 var rbt
= this.makeRBT(N
);
14016 var _
= this.stub(N
);
14018 var rws
= new Array(N
);
14019 var rwst
= new Array(N
);
14020 var iwst
= new Array(N
);
14022 var nrws
= new Array(N
);
14023 var nrwst
= new Array(N
);
14024 var niwst
= new Array(N
);
14026 var rmws
= out
.words
;
14029 this.convert13b(x
.words
, x
.length
, rws
, N
);
14030 this.convert13b(y
.words
, y
.length
, nrws
, N
);
14032 this.transform(rws
, _
, rwst
, iwst
, N
, rbt
);
14033 this.transform(nrws
, _
, nrwst
, niwst
, N
, rbt
);
14035 for (var i
= 0; i
< N
; i
++) {
14036 var rx
= rwst
[i
] * nrwst
[i
] - iwst
[i
] * niwst
[i
];
14037 iwst
[i
] = rwst
[i
] * niwst
[i
] + iwst
[i
] * nrwst
[i
];
14041 this.conjugate(rwst
, iwst
, N
);
14042 this.transform(rwst
, iwst
, rmws
, _
, N
, rbt
);
14043 this.conjugate(rmws
, _
, N
);
14044 this.normalize13b(rmws
, N
);
14046 out
.negative
= x
.negative
^ y
.negative
;
14047 out
.length
= x
.length
+ y
.length
;
14048 return out
.strip();
14051 // Multiply `this` by `num`
14052 BN
.prototype.mul
= function mul (num
) {
14053 var out
= new BN(null);
14054 out
.words
= new Array(this.length
+ num
.length
);
14055 return this.mulTo(num
, out
);
14058 // Multiply employing FFT
14059 BN
.prototype.mulf
= function mulf (num
) {
14060 var out
= new BN(null);
14061 out
.words
= new Array(this.length
+ num
.length
);
14062 return jumboMulTo(this, num
, out
);
14065 // In-place Multiplication
14066 BN
.prototype.imul
= function imul (num
) {
14067 return this.clone().mulTo(num
, this);
14070 BN
.prototype.imuln
= function imuln (num
) {
14071 assert(typeof num
=== 'number');
14072 assert(num
< 0x4000000);
14076 for (var i
= 0; i
< this.length
; i
++) {
14077 var w
= (this.words
[i
] | 0) * num
;
14078 var lo
= (w
& 0x3ffffff) + (carry
& 0x3ffffff);
14080 carry
+= (w
/ 0x4000000) | 0;
14081 // NOTE: lo is 27bit maximum
14082 carry
+= lo
>>> 26;
14083 this.words
[i
] = lo
& 0x3ffffff;
14087 this.words
[i
] = carry
;
14094 BN
.prototype.muln
= function muln (num
) {
14095 return this.clone().imuln(num
);
14099 BN
.prototype.sqr
= function sqr () {
14100 return this.mul(this);
14103 // `this` * `this` in-place
14104 BN
.prototype.isqr
= function isqr () {
14105 return this.imul(this.clone());
14108 // Math.pow(`this`, `num`)
14109 BN
.prototype.pow
= function pow (num
) {
14110 var w
= toBitArray(num
);
14111 if (w
.length
=== 0) return new BN(1);
14113 // Skip leading zeroes
14115 for (var i
= 0; i
< w
.length
; i
++, res
= res
.sqr()) {
14116 if (w
[i
] !== 0) break;
14119 if (++i
< w
.length
) {
14120 for (var q
= res
.sqr(); i
< w
.length
; i
++, q
= q
.sqr()) {
14121 if (w
[i
] === 0) continue;
14130 // Shift-left in-place
14131 BN
.prototype.iushln
= function iushln (bits
) {
14132 assert(typeof bits
=== 'number' && bits
>= 0);
14134 var s
= (bits
- r
) / 26;
14135 var carryMask
= (0x3ffffff >>> (26 - r
)) << (26 - r
);
14141 for (i
= 0; i
< this.length
; i
++) {
14142 var newCarry
= this.words
[i
] & carryMask
;
14143 var c
= ((this.words
[i
] | 0) - newCarry
) << r
;
14144 this.words
[i
] = c
| carry
;
14145 carry
= newCarry
>>> (26 - r
);
14149 this.words
[i
] = carry
;
14155 for (i
= this.length
- 1; i
>= 0; i
--) {
14156 this.words
[i
+ s
] = this.words
[i
];
14159 for (i
= 0; i
< s
; i
++) {
14166 return this.strip();
14169 BN
.prototype.ishln
= function ishln (bits
) {
14170 // TODO(indutny): implement me
14171 assert(this.negative
=== 0);
14172 return this.iushln(bits
);
14175 // Shift-right in-place
14176 // NOTE: `hint` is a lowest bit before trailing zeroes
14177 // NOTE: if `extended` is present - it will be filled with destroyed bits
14178 BN
.prototype.iushrn
= function iushrn (bits
, hint
, extended
) {
14179 assert(typeof bits
=== 'number' && bits
>= 0);
14182 h
= (hint
- (hint
% 26)) / 26;
14188 var s
= Math
.min((bits
- r
) / 26, this.length
);
14189 var mask
= 0x3ffffff ^ ((0x3ffffff >>> r
) << r
);
14190 var maskedWords
= extended
;
14193 h
= Math
.max(0, h
);
14195 // Extended mode, copy masked part
14197 for (var i
= 0; i
< s
; i
++) {
14198 maskedWords
.words
[i
] = this.words
[i
];
14200 maskedWords
.length
= s
;
14204 // No-op, we should not move anything at all
14205 } else if (this.length
> s
) {
14207 for (i
= 0; i
< this.length
; i
++) {
14208 this.words
[i
] = this.words
[i
+ s
];
14216 for (i
= this.length
- 1; i
>= 0 && (carry
!== 0 || i
>= h
); i
--) {
14217 var word
= this.words
[i
] | 0;
14218 this.words
[i
] = (carry
<< (26 - r
)) | (word
>>> r
);
14219 carry
= word
& mask
;
14222 // Push carried bits as a mask
14223 if (maskedWords
&& carry
!== 0) {
14224 maskedWords
.words
[maskedWords
.length
++] = carry
;
14227 if (this.length
=== 0) {
14232 return this.strip();
14235 BN
.prototype.ishrn
= function ishrn (bits
, hint
, extended
) {
14236 // TODO(indutny): implement me
14237 assert(this.negative
=== 0);
14238 return this.iushrn(bits
, hint
, extended
);
14242 BN
.prototype.shln
= function shln (bits
) {
14243 return this.clone().ishln(bits
);
14246 BN
.prototype.ushln
= function ushln (bits
) {
14247 return this.clone().iushln(bits
);
14251 BN
.prototype.shrn
= function shrn (bits
) {
14252 return this.clone().ishrn(bits
);
14255 BN
.prototype.ushrn
= function ushrn (bits
) {
14256 return this.clone().iushrn(bits
);
14259 // Test if n bit is set
14260 BN
.prototype.testn
= function testn (bit
) {
14261 assert(typeof bit
=== 'number' && bit
>= 0);
14263 var s
= (bit
- r
) / 26;
14266 // Fast case: bit is much higher than all existing words
14267 if (this.length
<= s
) return false;
14269 // Check bit and return
14270 var w
= this.words
[s
];
14275 // Return only lowers bits of number (in-place)
14276 BN
.prototype.imaskn
= function imaskn (bits
) {
14277 assert(typeof bits
=== 'number' && bits
>= 0);
14279 var s
= (bits
- r
) / 26;
14281 assert(this.negative
=== 0, 'imaskn works only with positive numbers');
14283 if (this.length
<= s
) {
14290 this.length
= Math
.min(s
, this.length
);
14293 var mask
= 0x3ffffff ^ ((0x3ffffff >>> r
) << r
);
14294 this.words
[this.length
- 1] &= mask
;
14297 return this.strip();
14300 // Return only lowers bits of number
14301 BN
.prototype.maskn
= function maskn (bits
) {
14302 return this.clone().imaskn(bits
);
14305 // Add plain number `num` to `this`
14306 BN
.prototype.iaddn
= function iaddn (num
) {
14307 assert(typeof num
=== 'number');
14308 assert(num
< 0x4000000);
14309 if (num
< 0) return this.isubn(-num
);
14311 // Possible sign change
14312 if (this.negative
!== 0) {
14313 if (this.length
=== 1 && (this.words
[0] | 0) < num
) {
14314 this.words
[0] = num
- (this.words
[0] | 0);
14325 // Add without checks
14326 return this._iaddn(num
);
14329 BN
.prototype._iaddn
= function _iaddn (num
) {
14330 this.words
[0] += num
;
14333 for (var i
= 0; i
< this.length
&& this.words
[i
] >= 0x4000000; i
++) {
14334 this.words
[i
] -= 0x4000000;
14335 if (i
=== this.length
- 1) {
14336 this.words
[i
+ 1] = 1;
14338 this.words
[i
+ 1]++;
14341 this.length
= Math
.max(this.length
, i
+ 1);
14346 // Subtract plain number `num` from `this`
14347 BN
.prototype.isubn
= function isubn (num
) {
14348 assert(typeof num
=== 'number');
14349 assert(num
< 0x4000000);
14350 if (num
< 0) return this.iaddn(-num
);
14352 if (this.negative
!== 0) {
14359 this.words
[0] -= num
;
14361 if (this.length
=== 1 && this.words
[0] < 0) {
14362 this.words
[0] = -this.words
[0];
14366 for (var i
= 0; i
< this.length
&& this.words
[i
] < 0; i
++) {
14367 this.words
[i
] += 0x4000000;
14368 this.words
[i
+ 1] -= 1;
14372 return this.strip();
14375 BN
.prototype.addn
= function addn (num
) {
14376 return this.clone().iaddn(num
);
14379 BN
.prototype.subn
= function subn (num
) {
14380 return this.clone().isubn(num
);
14383 BN
.prototype.iabs
= function iabs () {
14389 BN
.prototype.abs
= function abs () {
14390 return this.clone().iabs();
14393 BN
.prototype._ishlnsubmul
= function _ishlnsubmul (num
, mul
, shift
) {
14394 var len
= num
.length
+ shift
;
14401 for (i
= 0; i
< num
.length
; i
++) {
14402 w
= (this.words
[i
+ shift
] | 0) + carry
;
14403 var right
= (num
.words
[i
] | 0) * mul
;
14404 w
-= right
& 0x3ffffff;
14405 carry
= (w
>> 26) - ((right
/ 0x4000000) | 0);
14406 this.words
[i
+ shift
] = w
& 0x3ffffff;
14408 for (; i
< this.length
- shift
; i
++) {
14409 w
= (this.words
[i
+ shift
] | 0) + carry
;
14411 this.words
[i
+ shift
] = w
& 0x3ffffff;
14414 if (carry
=== 0) return this.strip();
14416 // Subtraction overflow
14417 assert(carry
=== -1);
14419 for (i
= 0; i
< this.length
; i
++) {
14420 w
= -(this.words
[i
] | 0) + carry
;
14422 this.words
[i
] = w
& 0x3ffffff;
14426 return this.strip();
14429 BN
.prototype._wordDiv
= function _wordDiv (num
, mode
) {
14430 var shift
= this.length
- num
.length
;
14432 var a
= this.clone();
14436 var bhi
= b
.words
[b
.length
- 1] | 0;
14437 var bhiBits
= this._countBits(bhi
);
14438 shift
= 26 - bhiBits
;
14440 b
= b
.ushln(shift
);
14442 bhi
= b
.words
[b
.length
- 1] | 0;
14445 // Initialize quotient
14446 var m
= a
.length
- b
.length
;
14449 if (mode
!== 'mod') {
14452 q
.words
= new Array(q
.length
);
14453 for (var i
= 0; i
< q
.length
; i
++) {
14458 var diff
= a
.clone()._ishlnsubmul(b
, 1, m
);
14459 if (diff
.negative
=== 0) {
14466 for (var j
= m
- 1; j
>= 0; j
--) {
14467 var qj
= (a
.words
[b
.length
+ j
] | 0) * 0x4000000 +
14468 (a
.words
[b
.length
+ j
- 1] | 0);
14470 // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
14472 qj
= Math
.min((qj
/ bhi
) | 0, 0x3ffffff);
14474 a
._ishlnsubmul(b
, qj
, j
);
14475 while (a
.negative
!== 0) {
14478 a
._ishlnsubmul(b
, 1, j
);
14493 if (mode
!== 'div' && shift
!== 0) {
14503 // NOTE: 1) `mode` can be set to `mod` to request mod only,
14504 // to `div` to request div only, or be absent to
14505 // request both div & mod
14506 // 2) `positive` is true if unsigned mod is requested
14507 BN
.prototype.divmod
= function divmod (num
, mode
, positive
) {
14508 assert(!num
.isZero());
14510 if (this.isZero()) {
14518 if (this.negative
!== 0 && num
.negative
=== 0) {
14519 res
= this.neg().divmod(num
, mode
);
14521 if (mode
!== 'mod') {
14522 div
= res
.div
.neg();
14525 if (mode
!== 'div') {
14526 mod
= res
.mod
.neg();
14527 if (positive
&& mod
.negative
!== 0) {
14538 if (this.negative
=== 0 && num
.negative
!== 0) {
14539 res
= this.divmod(num
.neg(), mode
);
14541 if (mode
!== 'mod') {
14542 div
= res
.div
.neg();
14551 if ((this.negative
& num
.negative
) !== 0) {
14552 res
= this.neg().divmod(num
.neg(), mode
);
14554 if (mode
!== 'div') {
14555 mod
= res
.mod
.neg();
14556 if (positive
&& mod
.negative
!== 0) {
14567 // Both numbers are positive at this point
14569 // Strip both numbers to approximate shift value
14570 if (num
.length
> this.length
|| this.cmp(num
) < 0) {
14577 // Very short reduction
14578 if (num
.length
=== 1) {
14579 if (mode
=== 'div') {
14581 div: this.divn(num
.words
[0]),
14586 if (mode
=== 'mod') {
14589 mod: new BN(this.modn(num
.words
[0]))
14594 div: this.divn(num
.words
[0]),
14595 mod: new BN(this.modn(num
.words
[0]))
14599 return this._wordDiv(num
, mode
);
14602 // Find `this` / `num`
14603 BN
.prototype.div
= function div (num
) {
14604 return this.divmod(num
, 'div', false).div
;
14607 // Find `this` % `num`
14608 BN
.prototype.mod
= function mod (num
) {
14609 return this.divmod(num
, 'mod', false).mod
;
14612 BN
.prototype.umod
= function umod (num
) {
14613 return this.divmod(num
, 'mod', true).mod
;
14616 // Find Round(`this` / `num`)
14617 BN
.prototype.divRound
= function divRound (num
) {
14618 var dm
= this.divmod(num
);
14620 // Fast case - exact division
14621 if (dm
.mod
.isZero()) return dm
.div
;
14623 var mod
= dm
.div
.negative
!== 0 ? dm
.mod
.isub(num
) : dm
.mod
;
14625 var half
= num
.ushrn(1);
14626 var r2
= num
.andln(1);
14627 var cmp
= mod
.cmp(half
);
14630 if (cmp
< 0 || r2
=== 1 && cmp
=== 0) return dm
.div
;
14633 return dm
.div
.negative
!== 0 ? dm
.div
.isubn(1) : dm
.div
.iaddn(1);
14636 BN
.prototype.modn
= function modn (num
) {
14637 assert(num
<= 0x3ffffff);
14638 var p
= (1 << 26) % num
;
14641 for (var i
= this.length
- 1; i
>= 0; i
--) {
14642 acc
= (p
* acc
+ (this.words
[i
] | 0)) % num
;
14648 // In-place division by number
14649 BN
.prototype.idivn
= function idivn (num
) {
14650 assert(num
<= 0x3ffffff);
14653 for (var i
= this.length
- 1; i
>= 0; i
--) {
14654 var w
= (this.words
[i
] | 0) + carry
* 0x4000000;
14655 this.words
[i
] = (w
/ num
) | 0;
14659 return this.strip();
14662 BN
.prototype.divn
= function divn (num
) {
14663 return this.clone().idivn(num
);
14666 BN
.prototype.egcd
= function egcd (p
) {
14667 assert(p
.negative
=== 0);
14668 assert(!p
.isZero());
14673 if (x
.negative
!== 0) {
14679 // A * x + B * y = x
14683 // C * x + D * y = y
14689 while (x
.isEven() && y
.isEven()) {
14695 var yp
= y
.clone();
14696 var xp
= x
.clone();
14698 while (!x
.isZero()) {
14699 for (var i
= 0, im
= 1; (x
.words
[0] & im
) === 0 && i
< 26; ++i
, im
<<= 1);
14703 if (A
.isOdd() || B
.isOdd()) {
14713 for (var j
= 0, jm
= 1; (y
.words
[0] & jm
) === 0 && j
< 26; ++j
, jm
<<= 1);
14717 if (C
.isOdd() || D
.isOdd()) {
14727 if (x
.cmp(y
) >= 0) {
14745 // This is reduced incarnation of the binary EEA
14746 // above, designated to invert members of the
14747 // _prime_ fields F(p) at a maximal speed
14748 BN
.prototype._invmp
= function _invmp (p
) {
14749 assert(p
.negative
=== 0);
14750 assert(!p
.isZero());
14755 if (a
.negative
!== 0) {
14761 var x1
= new BN(1);
14762 var x2
= new BN(0);
14764 var delta
= b
.clone();
14766 while (a
.cmpn(1) > 0 && b
.cmpn(1) > 0) {
14767 for (var i
= 0, im
= 1; (a
.words
[0] & im
) === 0 && i
< 26; ++i
, im
<<= 1);
14779 for (var j
= 0, jm
= 1; (b
.words
[0] & jm
) === 0 && j
< 26; ++j
, jm
<<= 1);
14791 if (a
.cmp(b
) >= 0) {
14801 if (a
.cmpn(1) === 0) {
14807 if (res
.cmpn(0) < 0) {
14814 BN
.prototype.gcd
= function gcd (num
) {
14815 if (this.isZero()) return num
.abs();
14816 if (num
.isZero()) return this.abs();
14818 var a
= this.clone();
14819 var b
= num
.clone();
14823 // Remove common factor of two
14824 for (var shift
= 0; a
.isEven() && b
.isEven(); shift
++) {
14830 while (a
.isEven()) {
14833 while (b
.isEven()) {
14839 // Swap `a` and `b` to make `a` always bigger than `b`
14843 } else if (r
=== 0 || b
.cmpn(1) === 0) {
14850 return b
.iushln(shift
);
14853 // Invert number in the field F(num)
14854 BN
.prototype.invm
= function invm (num
) {
14855 return this.egcd(num
).a
.umod(num
);
14858 BN
.prototype.isEven
= function isEven () {
14859 return (this.words
[0] & 1) === 0;
14862 BN
.prototype.isOdd
= function isOdd () {
14863 return (this.words
[0] & 1) === 1;
14866 // And first word and num
14867 BN
.prototype.andln
= function andln (num
) {
14868 return this.words
[0] & num
;
14871 // Increment at the bit position in-line
14872 BN
.prototype.bincn
= function bincn (bit
) {
14873 assert(typeof bit
=== 'number');
14875 var s
= (bit
- r
) / 26;
14878 // Fast case: bit is much higher than all existing words
14879 if (this.length
<= s
) {
14880 this._expand(s
+ 1);
14881 this.words
[s
] |= q
;
14885 // Add bit and propagate, if needed
14887 for (var i
= s
; carry
!== 0 && i
< this.length
; i
++) {
14888 var w
= this.words
[i
] | 0;
14895 this.words
[i
] = carry
;
14901 BN
.prototype.isZero
= function isZero () {
14902 return this.length
=== 1 && this.words
[0] === 0;
14905 BN
.prototype.cmpn
= function cmpn (num
) {
14906 var negative
= num
< 0;
14908 if (this.negative
!== 0 && !negative
) return -1;
14909 if (this.negative
=== 0 && negative
) return 1;
14914 if (this.length
> 1) {
14921 assert(num
<= 0x3ffffff, 'Number is too big');
14923 var w
= this.words
[0] | 0;
14924 res
= w
=== num
? 0 : w
< num
? -1 : 1;
14926 if (this.negative
!== 0) return -res
| 0;
14930 // Compare two numbers and return:
14931 // 1 - if `this` > `num`
14932 // 0 - if `this` == `num`
14933 // -1 - if `this` < `num`
14934 BN
.prototype.cmp
= function cmp (num
) {
14935 if (this.negative
!== 0 && num
.negative
=== 0) return -1;
14936 if (this.negative
=== 0 && num
.negative
!== 0) return 1;
14938 var res
= this.ucmp(num
);
14939 if (this.negative
!== 0) return -res
| 0;
14943 // Unsigned comparison
14944 BN
.prototype.ucmp
= function ucmp (num
) {
14945 // At this point both numbers have the same sign
14946 if (this.length
> num
.length
) return 1;
14947 if (this.length
< num
.length
) return -1;
14950 for (var i
= this.length
- 1; i
>= 0; i
--) {
14951 var a
= this.words
[i
] | 0;
14952 var b
= num
.words
[i
] | 0;
14954 if (a
=== b
) continue;
14957 } else if (a
> b
) {
14965 BN
.prototype.gtn
= function gtn (num
) {
14966 return this.cmpn(num
) === 1;
14969 BN
.prototype.gt
= function gt (num
) {
14970 return this.cmp(num
) === 1;
14973 BN
.prototype.gten
= function gten (num
) {
14974 return this.cmpn(num
) >= 0;
14977 BN
.prototype.gte
= function gte (num
) {
14978 return this.cmp(num
) >= 0;
14981 BN
.prototype.ltn
= function ltn (num
) {
14982 return this.cmpn(num
) === -1;
14985 BN
.prototype.lt
= function lt (num
) {
14986 return this.cmp(num
) === -1;
14989 BN
.prototype.lten
= function lten (num
) {
14990 return this.cmpn(num
) <= 0;
14993 BN
.prototype.lte
= function lte (num
) {
14994 return this.cmp(num
) <= 0;
14997 BN
.prototype.eqn
= function eqn (num
) {
14998 return this.cmpn(num
) === 0;
15001 BN
.prototype.eq
= function eq (num
) {
15002 return this.cmp(num
) === 0;
15006 // A reduce context, could be using montgomery or something better, depending
15007 // on the `m` itself.
15009 BN
.red
= function red (num
) {
15010 return new Red(num
);
15013 BN
.prototype.toRed
= function toRed (ctx
) {
15014 assert(!this.red
, 'Already a number in reduction context');
15015 assert(this.negative
=== 0, 'red works only with positives');
15016 return ctx
.convertTo(this)._forceRed(ctx
);
15019 BN
.prototype.fromRed
= function fromRed () {
15020 assert(this.red
, 'fromRed works only with numbers in reduction context');
15021 return this.red
.convertFrom(this);
15024 BN
.prototype._forceRed
= function _forceRed (ctx
) {
15029 BN
.prototype.forceRed
= function forceRed (ctx
) {
15030 assert(!this.red
, 'Already a number in reduction context');
15031 return this._forceRed(ctx
);
15034 BN
.prototype.redAdd
= function redAdd (num
) {
15035 assert(this.red
, 'redAdd works only with red numbers');
15036 return this.red
.add(this, num
);
15039 BN
.prototype.redIAdd
= function redIAdd (num
) {
15040 assert(this.red
, 'redIAdd works only with red numbers');
15041 return this.red
.iadd(this, num
);
15044 BN
.prototype.redSub
= function redSub (num
) {
15045 assert(this.red
, 'redSub works only with red numbers');
15046 return this.red
.sub(this, num
);
15049 BN
.prototype.redISub
= function redISub (num
) {
15050 assert(this.red
, 'redISub works only with red numbers');
15051 return this.red
.isub(this, num
);
15054 BN
.prototype.redShl
= function redShl (num
) {
15055 assert(this.red
, 'redShl works only with red numbers');
15056 return this.red
.shl(this, num
);
15059 BN
.prototype.redMul
= function redMul (num
) {
15060 assert(this.red
, 'redMul works only with red numbers');
15061 this.red
._verify2(this, num
);
15062 return this.red
.mul(this, num
);
15065 BN
.prototype.redIMul
= function redIMul (num
) {
15066 assert(this.red
, 'redMul works only with red numbers');
15067 this.red
._verify2(this, num
);
15068 return this.red
.imul(this, num
);
15071 BN
.prototype.redSqr
= function redSqr () {
15072 assert(this.red
, 'redSqr works only with red numbers');
15073 this.red
._verify1(this);
15074 return this.red
.sqr(this);
15077 BN
.prototype.redISqr
= function redISqr () {
15078 assert(this.red
, 'redISqr works only with red numbers');
15079 this.red
._verify1(this);
15080 return this.red
.isqr(this);
15083 // Square root over p
15084 BN
.prototype.redSqrt
= function redSqrt () {
15085 assert(this.red
, 'redSqrt works only with red numbers');
15086 this.red
._verify1(this);
15087 return this.red
.sqrt(this);
15090 BN
.prototype.redInvm
= function redInvm () {
15091 assert(this.red
, 'redInvm works only with red numbers');
15092 this.red
._verify1(this);
15093 return this.red
.invm(this);
15096 // Return negative clone of `this` % `red modulo`
15097 BN
.prototype.redNeg
= function redNeg () {
15098 assert(this.red
, 'redNeg works only with red numbers');
15099 this.red
._verify1(this);
15100 return this.red
.neg(this);
15103 BN
.prototype.redPow
= function redPow (num
) {
15104 assert(this.red
&& !num
.red
, 'redPow(normalNum)');
15105 this.red
._verify1(this);
15106 return this.red
.pow(this, num
);
15109 // Prime numbers with efficient reduction
15117 // Pseudo-Mersenne prime
15118 function MPrime (name
, p
) {
15121 this.p
= new BN(p
, 16);
15122 this.n
= this.p
.bitLength();
15123 this.k
= new BN(1).iushln(this.n
).isub(this.p
);
15125 this.tmp
= this._tmp();
15128 MPrime
.prototype._tmp
= function _tmp () {
15129 var tmp
= new BN(null);
15130 tmp
.words
= new Array(Math
.ceil(this.n
/ 13));
15134 MPrime
.prototype.ireduce
= function ireduce (num
) {
15135 // Assumes that `num` is less than `P^2`
15136 // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
15141 this.split(r
, this.tmp
);
15143 r
= r
.iadd(this.tmp
);
15144 rlen
= r
.bitLength();
15145 } while (rlen
> this.n
);
15147 var cmp
= rlen
< this.n
? -1 : r
.ucmp(this.p
);
15151 } else if (cmp
> 0) {
15160 MPrime
.prototype.split
= function split (input
, out
) {
15161 input
.iushrn(this.n
, 0, out
);
15164 MPrime
.prototype.imulK
= function imulK (num
) {
15165 return num
.imul(this.k
);
15172 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
15174 inherits(K256
, MPrime
);
15176 K256
.prototype.split
= function split (input
, output
) {
15177 // 256 = 9 * 26 + 22
15178 var mask
= 0x3fffff;
15180 var outLen
= Math
.min(input
.length
, 9);
15181 for (var i
= 0; i
< outLen
; i
++) {
15182 output
.words
[i
] = input
.words
[i
];
15184 output
.length
= outLen
;
15186 if (input
.length
<= 9) {
15187 input
.words
[0] = 0;
15192 // Shift by 9 limbs
15193 var prev
= input
.words
[9];
15194 output
.words
[output
.length
++] = prev
& mask
;
15196 for (i
= 10; i
< input
.length
; i
++) {
15197 var next
= input
.words
[i
] | 0;
15198 input
.words
[i
- 10] = ((next
& mask
) << 4) | (prev
>>> 22);
15202 input
.words
[i
- 10] = prev
;
15203 if (prev
=== 0 && input
.length
> 10) {
15204 input
.length
-= 10;
15210 K256
.prototype.imulK
= function imulK (num
) {
15211 // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
15212 num
.words
[num
.length
] = 0;
15213 num
.words
[num
.length
+ 1] = 0;
15216 // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
15218 for (var i
= 0; i
< num
.length
; i
++) {
15219 var w
= num
.words
[i
] | 0;
15221 num
.words
[i
] = lo
& 0x3ffffff;
15222 lo
= w
* 0x40 + ((lo
/ 0x4000000) | 0);
15225 // Fast length reduction
15226 if (num
.words
[num
.length
- 1] === 0) {
15228 if (num
.words
[num
.length
- 1] === 0) {
15239 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
15241 inherits(P224
, MPrime
);
15247 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
15249 inherits(P192
, MPrime
);
15251 function P25519 () {
15256 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
15258 inherits(P25519
, MPrime
);
15260 P25519
.prototype.imulK
= function imulK (num
) {
15263 for (var i
= 0; i
< num
.length
; i
++) {
15264 var hi
= (num
.words
[i
] | 0) * 0x13 + carry
;
15265 var lo
= hi
& 0x3ffffff;
15272 num
.words
[num
.length
++] = carry
;
15277 // Exported mostly for testing purposes, use plain name instead
15278 BN
._prime
= function prime (name
) {
15279 // Cached version of prime
15280 if (primes
[name
]) return primes
[name
];
15283 if (name
=== 'k256') {
15284 prime
= new K256();
15285 } else if (name
=== 'p224') {
15286 prime
= new P224();
15287 } else if (name
=== 'p192') {
15288 prime
= new P192();
15289 } else if (name
=== 'p25519') {
15290 prime
= new P25519();
15292 throw new Error('Unknown prime ' + name
);
15294 primes
[name
] = prime
;
15300 // Base reduction engine
15303 if (typeof m
=== 'string') {
15304 var prime
= BN
._prime(m
);
15306 this.prime
= prime
;
15308 assert(m
.gtn(1), 'modulus must be greater than 1');
15314 Red
.prototype._verify1
= function _verify1 (a
) {
15315 assert(a
.negative
=== 0, 'red works only with positives');
15316 assert(a
.red
, 'red works only with red numbers');
15319 Red
.prototype._verify2
= function _verify2 (a
, b
) {
15320 assert((a
.negative
| b
.negative
) === 0, 'red works only with positives');
15321 assert(a
.red
&& a
.red
=== b
.red
,
15322 'red works only with red numbers');
15325 Red
.prototype.imod
= function imod (a
) {
15326 if (this.prime
) return this.prime
.ireduce(a
)._forceRed(this);
15327 return a
.umod(this.m
)._forceRed(this);
15330 Red
.prototype.neg
= function neg (a
) {
15335 return this.m
.sub(a
)._forceRed(this);
15338 Red
.prototype.add
= function add (a
, b
) {
15339 this._verify2(a
, b
);
15341 var res
= a
.add(b
);
15342 if (res
.cmp(this.m
) >= 0) {
15345 return res
._forceRed(this);
15348 Red
.prototype.iadd
= function iadd (a
, b
) {
15349 this._verify2(a
, b
);
15351 var res
= a
.iadd(b
);
15352 if (res
.cmp(this.m
) >= 0) {
15358 Red
.prototype.sub
= function sub (a
, b
) {
15359 this._verify2(a
, b
);
15361 var res
= a
.sub(b
);
15362 if (res
.cmpn(0) < 0) {
15365 return res
._forceRed(this);
15368 Red
.prototype.isub
= function isub (a
, b
) {
15369 this._verify2(a
, b
);
15371 var res
= a
.isub(b
);
15372 if (res
.cmpn(0) < 0) {
15378 Red
.prototype.shl
= function shl (a
, num
) {
15380 return this.imod(a
.ushln(num
));
15383 Red
.prototype.imul
= function imul (a
, b
) {
15384 this._verify2(a
, b
);
15385 return this.imod(a
.imul(b
));
15388 Red
.prototype.mul
= function mul (a
, b
) {
15389 this._verify2(a
, b
);
15390 return this.imod(a
.mul(b
));
15393 Red
.prototype.isqr
= function isqr (a
) {
15394 return this.imul(a
, a
.clone());
15397 Red
.prototype.sqr
= function sqr (a
) {
15398 return this.mul(a
, a
);
15401 Red
.prototype.sqrt
= function sqrt (a
) {
15402 if (a
.isZero()) return a
.clone();
15404 var mod3
= this.m
.andln(3);
15405 assert(mod3
% 2 === 1);
15409 var pow
= this.m
.add(new BN(1)).iushrn(2);
15410 return this.pow(a
, pow
);
15413 // Tonelli-Shanks algorithm (Totally unoptimized and slow)
15415 // Find Q and S, that Q * 2 ^ S = (P - 1)
15416 var q
= this.m
.subn(1);
15418 while (!q
.isZero() && q
.andln(1) === 0) {
15422 assert(!q
.isZero());
15424 var one
= new BN(1).toRed(this);
15425 var nOne
= one
.redNeg();
15427 // Find quadratic non-residue
15428 // NOTE: Max is such because of generalized Riemann hypothesis.
15429 var lpow
= this.m
.subn(1).iushrn(1);
15430 var z
= this.m
.bitLength();
15431 z
= new BN(2 * z
* z
).toRed(this);
15433 while (this.pow(z
, lpow
).cmp(nOne
) !== 0) {
15437 var c
= this.pow(z
, q
);
15438 var r
= this.pow(a
, q
.addn(1).iushrn(1));
15439 var t
= this.pow(a
, q
);
15441 while (t
.cmp(one
) !== 0) {
15443 for (var i
= 0; tmp
.cmp(one
) !== 0; i
++) {
15444 tmp
= tmp
.redSqr();
15447 var b
= this.pow(c
, new BN(1).iushln(m
- i
- 1));
15458 Red
.prototype.invm
= function invm (a
) {
15459 var inv
= a
._invmp(this.m
);
15460 if (inv
.negative
!== 0) {
15462 return this.imod(inv
).redNeg();
15464 return this.imod(inv
);
15468 Red
.prototype.pow
= function pow (a
, num
) {
15469 if (num
.isZero()) return new BN(1);
15470 if (num
.cmpn(1) === 0) return a
.clone();
15472 var windowSize
= 4;
15473 var wnd
= new Array(1 << windowSize
);
15474 wnd
[0] = new BN(1).toRed(this);
15476 for (var i
= 2; i
< wnd
.length
; i
++) {
15477 wnd
[i
] = this.mul(wnd
[i
- 1], a
);
15482 var currentLen
= 0;
15483 var start
= num
.bitLength() % 26;
15488 for (i
= num
.length
- 1; i
>= 0; i
--) {
15489 var word
= num
.words
[i
];
15490 for (var j
= start
- 1; j
>= 0; j
--) {
15491 var bit
= (word
>> j
) & 1;
15492 if (res
!== wnd
[0]) {
15493 res
= this.sqr(res
);
15496 if (bit
=== 0 && current
=== 0) {
15504 if (currentLen
!== windowSize
&& (i
!== 0 || j
!== 0)) continue;
15506 res
= this.mul(res
, wnd
[current
]);
15516 Red
.prototype.convertTo
= function convertTo (num
) {
15517 var r
= num
.umod(this.m
);
15519 return r
=== num
? r
.clone() : r
;
15522 Red
.prototype.convertFrom
= function convertFrom (num
) {
15523 var res
= num
.clone();
15529 // Montgomery method engine
15532 BN
.mont
= function mont (num
) {
15533 return new Mont(num
);
15536 function Mont (m
) {
15539 this.shift
= this.m
.bitLength();
15540 if (this.shift
% 26 !== 0) {
15541 this.shift
+= 26 - (this.shift
% 26);
15544 this.r
= new BN(1).iushln(this.shift
);
15545 this.r2
= this.imod(this.r
.sqr());
15546 this.rinv
= this.r
._invmp(this.m
);
15548 this.minv
= this.rinv
.mul(this.r
).isubn(1).div(this.m
);
15549 this.minv
= this.minv
.umod(this.r
);
15550 this.minv
= this.r
.sub(this.minv
);
15552 inherits(Mont
, Red
);
15554 Mont
.prototype.convertTo
= function convertTo (num
) {
15555 return this.imod(num
.ushln(this.shift
));
15558 Mont
.prototype.convertFrom
= function convertFrom (num
) {
15559 var r
= this.imod(num
.mul(this.rinv
));
15564 Mont
.prototype.imul
= function imul (a
, b
) {
15565 if (a
.isZero() || b
.isZero()) {
15572 var c
= t
.maskn(this.shift
).mul(this.minv
).imaskn(this.shift
).mul(this.m
);
15573 var u
= t
.isub(c
).iushrn(this.shift
);
15576 if (u
.cmp(this.m
) >= 0) {
15577 res
= u
.isub(this.m
);
15578 } else if (u
.cmpn(0) < 0) {
15579 res
= u
.iadd(this.m
);
15582 return res
._forceRed(this);
15585 Mont
.prototype.mul
= function mul (a
, b
) {
15586 if (a
.isZero() || b
.isZero()) return new BN(0)._forceRed(this);
15589 var c
= t
.maskn(this.shift
).mul(this.minv
).imaskn(this.shift
).mul(this.m
);
15590 var u
= t
.isub(c
).iushrn(this.shift
);
15592 if (u
.cmp(this.m
) >= 0) {
15593 res
= u
.isub(this.m
);
15594 } else if (u
.cmpn(0) < 0) {
15595 res
= u
.iadd(this.m
);
15598 return res
._forceRed(this);
15601 Mont
.prototype.invm
= function invm (a
) {
15602 // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
15603 var res
= this.imod(a
._invmp(this.m
).mul(this.r2
));
15604 return res
._forceRed(this);
15606 })(typeof module
=== 'undefined' || module
, this);
15608 },{}],82:[function(require
,module
,exports
){
15611 module
.exports
= function rand(len
) {
15613 r
= new Rand(null);
15615 return r
.generate(len
);
15618 function Rand(rand
) {
15621 module
.exports
.Rand
= Rand
;
15623 Rand
.prototype.generate
= function generate(len
) {
15624 return this._rand(len
);
15627 // Emulate crypto API using randy
15628 Rand
.prototype._rand
= function _rand(n
) {
15629 if (this.rand
.getBytes
)
15630 return this.rand
.getBytes(n
);
15632 var res
= new Uint8Array(n
);
15633 for (var i
= 0; i
< res
.length
; i
++)
15634 res
[i
] = this.rand
.getByte();
15638 if (typeof self
=== 'object') {
15639 if (self
.crypto
&& self
.crypto
.getRandomValues
) {
15641 Rand
.prototype._rand
= function _rand(n
) {
15642 var arr
= new Uint8Array(n
);
15643 self
.crypto
.getRandomValues(arr
);
15646 } else if (self
.msCrypto
&& self
.msCrypto
.getRandomValues
) {
15648 Rand
.prototype._rand
= function _rand(n
) {
15649 var arr
= new Uint8Array(n
);
15650 self
.msCrypto
.getRandomValues(arr
);
15654 // Safari's WebWorkers do not have `crypto`
15655 } else if (typeof window
=== 'object') {
15657 Rand
.prototype._rand = function() {
15658 throw new Error('Not implemented yet');
15662 // Node.js or Web worker with no crypto support
15664 var crypto
= require('crypto');
15665 if (typeof crypto
.randomBytes
!== 'function')
15666 throw new Error('Not supported');
15668 Rand
.prototype._rand
= function _rand(n
) {
15669 return crypto
.randomBytes(n
);
15675 },{"crypto":3}],83:[function(require
,module
,exports
){
15676 var basex
= require('base-x')
15677 var ALPHABET
= '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
15679 module
.exports
= basex(ALPHABET
)
15681 },{"base-x":35}],84:[function(require
,module
,exports
){
15682 (function (Buffer
){
15685 var base58
= require('bs58')
15687 module
.exports = function (checksumFn
) {
15688 // Encode a buffer as a base58-check encoded string
15689 function encode (payload
) {
15690 var checksum
= checksumFn(payload
)
15692 return base58
.encode(Buffer
.concat([
15695 ], payload
.length
+ 4))
15698 function decodeRaw (buffer
) {
15699 var payload
= buffer
.slice(0, -4)
15700 var checksum
= buffer
.slice(-4)
15701 var newChecksum
= checksumFn(payload
)
15703 if (checksum
[0] ^ newChecksum
[0] |
15704 checksum
[1] ^ newChecksum
[1] |
15705 checksum
[2] ^ newChecksum
[2] |
15706 checksum
[3] ^ newChecksum
[3]) return
15711 // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
15712 function decodeUnsafe (string
) {
15713 var buffer
= base58
.decodeUnsafe(string
)
15714 if (!buffer
) return
15716 return decodeRaw(buffer
)
15719 function decode (string
) {
15720 var buffer
= base58
.decode(string
)
15721 var payload
= decodeRaw(buffer
, checksumFn
)
15722 if (!payload
) throw new Error('Invalid checksum')
15729 decodeUnsafe: decodeUnsafe
15733 }).call(this,require("buffer").Buffer
)
15734 },{"bs58":83,"buffer":5}],85:[function(require
,module
,exports
){
15737 var createHash
= require('create-hash')
15738 var bs58checkBase
= require('./base')
15740 // SHA256(SHA256(buffer))
15741 function sha256x2 (buffer
) {
15742 var tmp
= createHash('sha256').update(buffer
).digest()
15743 return createHash('sha256').update(tmp
).digest()
15746 module
.exports
= bs58checkBase(sha256x2
)
15748 },{"./base":84,"create-hash":87}],86:[function(require
,module
,exports
){
15749 var Buffer
= require('safe-buffer').Buffer
15750 var Transform
= require('stream').Transform
15751 var StringDecoder
= require('string_decoder').StringDecoder
15752 var inherits
= require('inherits')
15754 function CipherBase (hashMode
) {
15755 Transform
.call(this)
15756 this.hashMode
= typeof hashMode
=== 'string'
15757 if (this.hashMode
) {
15758 this[hashMode
] = this._finalOrDigest
15760 this.final
= this._finalOrDigest
15763 this.__final
= this._final
15766 this._decoder
= null
15767 this._encoding
= null
15769 inherits(CipherBase
, Transform
)
15771 CipherBase
.prototype.update = function (data
, inputEnc
, outputEnc
) {
15772 if (typeof data
=== 'string') {
15773 data
= Buffer
.from(data
, inputEnc
)
15776 var outData
= this._update(data
)
15777 if (this.hashMode
) return this
15780 outData
= this._toString(outData
, outputEnc
)
15786 CipherBase
.prototype.setAutoPadding = function () {}
15787 CipherBase
.prototype.getAuthTag = function () {
15788 throw new Error('trying to get auth tag in unsupported state')
15791 CipherBase
.prototype.setAuthTag = function () {
15792 throw new Error('trying to set auth tag in unsupported state')
15795 CipherBase
.prototype.setAAD = function () {
15796 throw new Error('trying to set aad in unsupported state')
15799 CipherBase
.prototype._transform = function (data
, _
, next
) {
15802 if (this.hashMode
) {
15805 this.push(this._update(data
))
15813 CipherBase
.prototype._flush = function (done
) {
15816 this.push(this.__final())
15823 CipherBase
.prototype._finalOrDigest = function (outputEnc
) {
15824 var outData
= this.__final() || Buffer
.alloc(0)
15826 outData
= this._toString(outData
, outputEnc
, true)
15831 CipherBase
.prototype._toString = function (value
, enc
, fin
) {
15832 if (!this._decoder
) {
15833 this._decoder
= new StringDecoder(enc
)
15834 this._encoding
= enc
15837 if (this._encoding
!== enc
) throw new Error('can\'t switch encodings')
15839 var out
= this._decoder
.write(value
)
15841 out
+= this._decoder
.end()
15847 module
.exports
= CipherBase
15849 },{"inherits":121,"safe-buffer":128,"stream":28,"string_decoder":29}],87:[function(require
,module
,exports
){
15850 (function (Buffer
){
15852 var inherits
= require('inherits')
15853 var md5
= require('./md5')
15854 var RIPEMD160
= require('ripemd160')
15855 var sha
= require('sha.js')
15857 var Base
= require('cipher-base')
15859 function HashNoConstructor (hash
) {
15860 Base
.call(this, 'digest')
15866 inherits(HashNoConstructor
, Base
)
15868 HashNoConstructor
.prototype._update = function (data
) {
15869 this.buffers
.push(data
)
15872 HashNoConstructor
.prototype._final = function () {
15873 var buf
= Buffer
.concat(this.buffers
)
15874 var r
= this._hash(buf
)
15875 this.buffers
= null
15880 function Hash (hash
) {
15881 Base
.call(this, 'digest')
15886 inherits(Hash
, Base
)
15888 Hash
.prototype._update = function (data
) {
15889 this._hash
.update(data
)
15892 Hash
.prototype._final = function () {
15893 return this._hash
.digest()
15896 module
.exports
= function createHash (alg
) {
15897 alg
= alg
.toLowerCase()
15898 if (alg
=== 'md5') return new HashNoConstructor(md5
)
15899 if (alg
=== 'rmd160' || alg
=== 'ripemd160') return new Hash(new RIPEMD160())
15901 return new Hash(sha(alg
))
15904 }).call(this,require("buffer").Buffer
)
15905 },{"./md5":89,"buffer":5,"cipher-base":86,"inherits":121,"ripemd160":127,"sha.js":130}],88:[function(require
,module
,exports
){
15906 (function (Buffer
){
15909 var zeroBuffer
= new Buffer(intSize
)
15915 function toArray (buf
) {
15916 if ((buf
.length
% intSize
) !== 0) {
15917 var len
= buf
.length
+ (intSize
- (buf
.length
% intSize
))
15918 buf
= Buffer
.concat([buf
, zeroBuffer
], len
)
15921 var arr
= new Array(buf
.length
>>> 2)
15922 for (var i
= 0, j
= 0; i
< buf
.length
; i
+= intSize
, j
++) {
15923 arr
[j
] = buf
.readInt32LE(i
)
15929 module
.exports
= function hash (buf
, fn
) {
15930 var arr
= fn(toArray(buf
), buf
.length
* charSize
)
15931 buf
= new Buffer(hashSize
)
15932 for (var i
= 0; i
< arr
.length
; i
++) {
15933 buf
.writeInt32LE(arr
[i
], i
<< 2, true)
15938 }).call(this,require("buffer").Buffer
)
15939 },{"buffer":5}],89:[function(require
,module
,exports
){
15942 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
15943 * Digest Algorithm, as defined in RFC 1321.
15944 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
15945 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
15946 * Distributed under the BSD License
15947 * See http://pajhome.org.uk/crypt/md5 for more info.
15950 var makeHash
= require('./make-hash')
15953 * Calculate the MD5 of an array of little-endian words, and a bit length
15955 function core_md5 (x
, len
) {
15956 /* append padding */
15957 x
[len
>> 5] |= 0x80 << ((len
) % 32)
15958 x
[(((len
+ 64) >>> 9) << 4) + 14] = len
15962 var c
= -1732584194
15965 for (var i
= 0; i
< x
.length
; i
+= 16) {
15971 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 0], 7, -680876936)
15972 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 1], 12, -389564586)
15973 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 2], 17, 606105819)
15974 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 3], 22, -1044525330)
15975 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 4], 7, -176418897)
15976 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 5], 12, 1200080426)
15977 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 6], 17, -1473231341)
15978 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 7], 22, -45705983)
15979 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 8], 7, 1770035416)
15980 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 9], 12, -1958414417)
15981 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 10], 17, -42063)
15982 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 11], 22, -1990404162)
15983 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 12], 7, 1804603682)
15984 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 13], 12, -40341101)
15985 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 14], 17, -1502002290)
15986 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 15], 22, 1236535329)
15988 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 1], 5, -165796510)
15989 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 6], 9, -1069501632)
15990 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 11], 14, 643717713)
15991 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 0], 20, -373897302)
15992 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 5], 5, -701558691)
15993 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 10], 9, 38016083)
15994 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 15], 14, -660478335)
15995 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 4], 20, -405537848)
15996 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 9], 5, 568446438)
15997 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 14], 9, -1019803690)
15998 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 3], 14, -187363961)
15999 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 8], 20, 1163531501)
16000 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 13], 5, -1444681467)
16001 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 2], 9, -51403784)
16002 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 7], 14, 1735328473)
16003 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 12], 20, -1926607734)
16005 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 5], 4, -378558)
16006 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 8], 11, -2022574463)
16007 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 11], 16, 1839030562)
16008 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 14], 23, -35309556)
16009 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 1], 4, -1530992060)
16010 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 4], 11, 1272893353)
16011 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 7], 16, -155497632)
16012 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 10], 23, -1094730640)
16013 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 13], 4, 681279174)
16014 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 0], 11, -358537222)
16015 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 3], 16, -722521979)
16016 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 6], 23, 76029189)
16017 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 9], 4, -640364487)
16018 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 12], 11, -421815835)
16019 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 15], 16, 530742520)
16020 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 2], 23, -995338651)
16022 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 0], 6, -198630844)
16023 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 7], 10, 1126891415)
16024 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 14], 15, -1416354905)
16025 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 5], 21, -57434055)
16026 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 12], 6, 1700485571)
16027 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 3], 10, -1894986606)
16028 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 10], 15, -1051523)
16029 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 1], 21, -2054922799)
16030 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 8], 6, 1873313359)
16031 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 15], 10, -30611744)
16032 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 6], 15, -1560198380)
16033 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 13], 21, 1309151649)
16034 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 4], 6, -145523070)
16035 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 11], 10, -1120210379)
16036 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 2], 15, 718787259)
16037 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 9], 21, -343485551)
16039 a
= safe_add(a
, olda
)
16040 b
= safe_add(b
, oldb
)
16041 c
= safe_add(c
, oldc
)
16042 d
= safe_add(d
, oldd
)
16045 return [a
, b
, c
, d
]
16049 * These functions implement the four basic operations the algorithm uses.
16051 function md5_cmn (q
, a
, b
, x
, s
, t
) {
16052 return safe_add(bit_rol(safe_add(safe_add(a
, q
), safe_add(x
, t
)), s
), b
)
16055 function md5_ff (a
, b
, c
, d
, x
, s
, t
) {
16056 return md5_cmn((b
& c
) | ((~b
) & d
), a
, b
, x
, s
, t
)
16059 function md5_gg (a
, b
, c
, d
, x
, s
, t
) {
16060 return md5_cmn((b
& d
) | (c
& (~d
)), a
, b
, x
, s
, t
)
16063 function md5_hh (a
, b
, c
, d
, x
, s
, t
) {
16064 return md5_cmn(b
^ c
^ d
, a
, b
, x
, s
, t
)
16067 function md5_ii (a
, b
, c
, d
, x
, s
, t
) {
16068 return md5_cmn(c
^ (b
| (~d
)), a
, b
, x
, s
, t
)
16072 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
16073 * to work around bugs in some JS interpreters.
16075 function safe_add (x
, y
) {
16076 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF)
16077 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16)
16078 return (msw
<< 16) | (lsw
& 0xFFFF)
16082 * Bitwise rotate a 32-bit number to the left.
16084 function bit_rol (num
, cnt
) {
16085 return (num
<< cnt
) | (num
>>> (32 - cnt
))
16088 module
.exports
= function md5 (buf
) {
16089 return makeHash(buf
, core_md5
)
16092 },{"./make-hash":88}],90:[function(require
,module
,exports
){
16094 var inherits
= require('inherits')
16095 var Legacy
= require('./legacy')
16096 var Base
= require('cipher-base')
16097 var Buffer
= require('safe-buffer').Buffer
16098 var md5
= require('create-hash/md5')
16099 var RIPEMD160
= require('ripemd160')
16101 var sha
= require('sha.js')
16103 var ZEROS
= Buffer
.alloc(128)
16105 function Hmac (alg
, key
) {
16106 Base
.call(this, 'digest')
16107 if (typeof key
=== 'string') {
16108 key
= Buffer
.from(key
)
16111 var blocksize
= (alg
=== 'sha512' || alg
=== 'sha384') ? 128 : 64
16115 if (key
.length
> blocksize
) {
16116 var hash
= alg
=== 'rmd160' ? new RIPEMD160() : sha(alg
)
16117 key
= hash
.update(key
).digest()
16118 } else if (key
.length
< blocksize
) {
16119 key
= Buffer
.concat([key
, ZEROS
], blocksize
)
16122 var ipad
= this._ipad
= Buffer
.allocUnsafe(blocksize
)
16123 var opad
= this._opad
= Buffer
.allocUnsafe(blocksize
)
16125 for (var i
= 0; i
< blocksize
; i
++) {
16126 ipad
[i
] = key
[i
] ^ 0x36
16127 opad
[i
] = key
[i
] ^ 0x5C
16129 this._hash
= alg
=== 'rmd160' ? new RIPEMD160() : sha(alg
)
16130 this._hash
.update(ipad
)
16133 inherits(Hmac
, Base
)
16135 Hmac
.prototype._update = function (data
) {
16136 this._hash
.update(data
)
16139 Hmac
.prototype._final = function () {
16140 var h
= this._hash
.digest()
16141 var hash
= this._alg
=== 'rmd160' ? new RIPEMD160() : sha(this._alg
)
16142 return hash
.update(this._opad
).update(h
).digest()
16145 module
.exports
= function createHmac (alg
, key
) {
16146 alg
= alg
.toLowerCase()
16147 if (alg
=== 'rmd160' || alg
=== 'ripemd160') {
16148 return new Hmac('rmd160', key
)
16150 if (alg
=== 'md5') {
16151 return new Legacy(md5
, key
)
16153 return new Hmac(alg
, key
)
16156 },{"./legacy":91,"cipher-base":86,"create-hash/md5":89,"inherits":121,"ripemd160":127,"safe-buffer":128,"sha.js":130}],91:[function(require
,module
,exports
){
16158 var inherits
= require('inherits')
16159 var Buffer
= require('safe-buffer').Buffer
16161 var Base
= require('cipher-base')
16163 var ZEROS
= Buffer
.alloc(128)
16166 function Hmac (alg
, key
) {
16167 Base
.call(this, 'digest')
16168 if (typeof key
=== 'string') {
16169 key
= Buffer
.from(key
)
16175 if (key
.length
> blocksize
) {
16177 } else if (key
.length
< blocksize
) {
16178 key
= Buffer
.concat([key
, ZEROS
], blocksize
)
16181 var ipad
= this._ipad
= Buffer
.allocUnsafe(blocksize
)
16182 var opad
= this._opad
= Buffer
.allocUnsafe(blocksize
)
16184 for (var i
= 0; i
< blocksize
; i
++) {
16185 ipad
[i
] = key
[i
] ^ 0x36
16186 opad
[i
] = key
[i
] ^ 0x5C
16189 this._hash
= [ipad
]
16192 inherits(Hmac
, Base
)
16194 Hmac
.prototype._update = function (data
) {
16195 this._hash
.push(data
)
16198 Hmac
.prototype._final = function () {
16199 var h
= this._alg(Buffer
.concat(this._hash
))
16200 return this._alg(Buffer
.concat([this._opad
, h
]))
16202 module
.exports
= Hmac
16204 },{"cipher-base":86,"inherits":121,"safe-buffer":128}],92:[function(require
,module
,exports
){
16205 var assert
= require('assert')
16206 var BigInteger
= require('bigi')
16208 var Point
= require('./point')
16210 function Curve (p
, a
, b
, Gx
, Gy
, n
, h
) {
16214 this.G
= Point
.fromAffine(this, Gx
, Gy
)
16218 this.infinity
= new Point(this, null, null, BigInteger
.ZERO
)
16221 this.pOverFour
= p
.add(BigInteger
.ONE
).shiftRight(2)
16223 // determine size of p in bytes
16224 this.pLength
= Math
.floor((this.p
.bitLength() + 7) / 8)
16227 Curve
.prototype.pointFromX = function (isOdd
, x
) {
16228 var alpha
= x
.pow(3).add(this.a
.multiply(x
)).add(this.b
).mod(this.p
)
16229 var beta
= alpha
.modPow(this.pOverFour
, this.p
) // XXX: not compatible with all curves
16232 if (beta
.isEven() ^ !isOdd
) {
16233 y
= this.p
.subtract(y
) // -y % p
16236 return Point
.fromAffine(this, x
, y
)
16239 Curve
.prototype.isInfinity = function (Q
) {
16240 if (Q
=== this.infinity
) return true
16242 return Q
.z
.signum() === 0 && Q
.y
.signum() !== 0
16245 Curve
.prototype.isOnCurve = function (Q
) {
16246 if (this.isInfinity(Q
)) return true
16254 // Check that xQ and yQ are integers in the interval [0, p - 1]
16255 if (x
.signum() < 0 || x
.compareTo(p
) >= 0) return false
16256 if (y
.signum() < 0 || y
.compareTo(p
) >= 0) return false
16258 // and check that y^2 = x^3 + ax + b (mod p)
16259 var lhs
= y
.square().mod(p
)
16260 var rhs
= x
.pow(3).add(a
.multiply(x
)).add(b
).mod(p
)
16261 return lhs
.equals(rhs
)
16265 * Validate an elliptic curve point.
16267 * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
16269 Curve
.prototype.validate = function (Q
) {
16271 assert(!this.isInfinity(Q
), 'Point is at infinity')
16272 assert(this.isOnCurve(Q
), 'Point is not on the curve')
16274 // Check nQ = O (where Q is a scalar multiple of G)
16275 var nQ
= Q
.multiply(this.n
)
16276 assert(this.isInfinity(nQ
), 'Point is not a scalar multiple of G')
16281 module
.exports
= Curve
16283 },{"./point":96,"assert":1,"bigi":39}],93:[function(require
,module
,exports
){
16286 "p": "fffffffdffffffffffffffffffffffff",
16287 "a": "fffffffdfffffffffffffffffffffffc",
16288 "b": "e87579c11079f43dd824993c2cee5ed3",
16289 "n": "fffffffe0000000075a30d1b9038a115",
16291 "Gx": "161ff7528b899b2d0c28607ca52c5b86",
16292 "Gy": "cf5ac8395bafeb13c02da292dded7a83"
16295 "p": "fffffffffffffffffffffffffffffffeffffac73",
16298 "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
16300 "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
16301 "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
16304 "p": "ffffffffffffffffffffffffffffffff7fffffff",
16305 "a": "ffffffffffffffffffffffffffffffff7ffffffc",
16306 "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
16307 "n": "0100000000000000000001f4c8f927aed3ca752257",
16309 "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
16310 "Gy": "23a628553168947d59dcc912042351377ac5fb32"
16313 "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
16316 "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
16318 "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
16319 "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
16322 "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
16323 "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
16324 "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
16325 "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
16327 "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
16328 "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
16331 "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
16334 "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
16336 "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
16337 "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
16340 "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
16341 "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
16342 "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
16343 "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
16345 "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
16346 "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
16350 },{}],94:[function(require
,module
,exports
){
16351 var Point
= require('./point')
16352 var Curve
= require('./curve')
16354 var getCurveByName
= require('./names')
16359 getCurveByName: getCurveByName
16362 },{"./curve":92,"./names":95,"./point":96}],95:[function(require
,module
,exports
){
16363 var BigInteger
= require('bigi')
16365 var curves
= require('./curves.json')
16366 var Curve
= require('./curve')
16368 function getCurveByName (name
) {
16369 var curve
= curves
[name
]
16370 if (!curve
) return null
16372 var p
= new BigInteger(curve
.p
, 16)
16373 var a
= new BigInteger(curve
.a
, 16)
16374 var b
= new BigInteger(curve
.b
, 16)
16375 var n
= new BigInteger(curve
.n
, 16)
16376 var h
= new BigInteger(curve
.h
, 16)
16377 var Gx
= new BigInteger(curve
.Gx
, 16)
16378 var Gy
= new BigInteger(curve
.Gy
, 16)
16380 return new Curve(p
, a
, b
, Gx
, Gy
, n
, h
)
16383 module
.exports
= getCurveByName
16385 },{"./curve":92,"./curves.json":93,"bigi":39}],96:[function(require
,module
,exports
){
16386 (function (Buffer
){
16387 var assert
= require('assert')
16388 var BigInteger
= require('bigi')
16390 var THREE
= BigInteger
.valueOf(3)
16392 function Point (curve
, x
, y
, z
) {
16393 assert
.notStrictEqual(z
, undefined, 'Missing Z coordinate')
16401 this.compressed
= true
16404 Object
.defineProperty(Point
.prototype, 'zInv', {
16406 if (this._zInv
=== null) {
16407 this._zInv
= this.z
.modInverse(this.curve
.p
)
16414 Object
.defineProperty(Point
.prototype, 'affineX', {
16416 return this.x
.multiply(this.zInv
).mod(this.curve
.p
)
16420 Object
.defineProperty(Point
.prototype, 'affineY', {
16422 return this.y
.multiply(this.zInv
).mod(this.curve
.p
)
16426 Point
.fromAffine = function (curve
, x
, y
) {
16427 return new Point(curve
, x
, y
, BigInteger
.ONE
)
16430 Point
.prototype.equals = function (other
) {
16431 if (other
=== this) return true
16432 if (this.curve
.isInfinity(this)) return this.curve
.isInfinity(other
)
16433 if (this.curve
.isInfinity(other
)) return this.curve
.isInfinity(this)
16435 // u = Y2 * Z1 - Y1 * Z2
16436 var u
= other
.y
.multiply(this.z
).subtract(this.y
.multiply(other
.z
)).mod(this.curve
.p
)
16438 if (u
.signum() !== 0) return false
16440 // v = X2 * Z1 - X1 * Z2
16441 var v
= other
.x
.multiply(this.z
).subtract(this.x
.multiply(other
.z
)).mod(this.curve
.p
)
16443 return v
.signum() === 0
16446 Point
.prototype.negate = function () {
16447 var y
= this.curve
.p
.subtract(this.y
)
16449 return new Point(this.curve
, this.x
, y
, this.z
)
16452 Point
.prototype.add = function (b
) {
16453 if (this.curve
.isInfinity(this)) return b
16454 if (this.curve
.isInfinity(b
)) return this
16461 // u = Y2 * Z1 - Y1 * Z2
16462 var u
= y2
.multiply(this.z
).subtract(y1
.multiply(b
.z
)).mod(this.curve
.p
)
16463 // v = X2 * Z1 - X1 * Z2
16464 var v
= x2
.multiply(this.z
).subtract(x1
.multiply(b
.z
)).mod(this.curve
.p
)
16466 if (v
.signum() === 0) {
16467 if (u
.signum() === 0) {
16468 return this.twice() // this == b, so double
16471 return this.curve
.infinity
// this = -b, so infinity
16474 var v2
= v
.square()
16475 var v3
= v2
.multiply(v
)
16476 var x1v2
= x1
.multiply(v2
)
16477 var zu2
= u
.square().multiply(this.z
)
16479 // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
16480 var x3
= zu2
.subtract(x1v2
.shiftLeft(1)).multiply(b
.z
).subtract(v3
).multiply(v
).mod(this.curve
.p
)
16481 // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
16482 var y3
= x1v2
.multiply(THREE
).multiply(u
).subtract(y1
.multiply(v3
)).subtract(zu2
.multiply(u
)).multiply(b
.z
).add(u
.multiply(v3
)).mod(this.curve
.p
)
16483 // z3 = v^3 * z1 * z2
16484 var z3
= v3
.multiply(this.z
).multiply(b
.z
).mod(this.curve
.p
)
16486 return new Point(this.curve
, x3
, y3
, z3
)
16489 Point
.prototype.twice = function () {
16490 if (this.curve
.isInfinity(this)) return this
16491 if (this.y
.signum() === 0) return this.curve
.infinity
16496 var y1z1
= y1
.multiply(this.z
).mod(this.curve
.p
)
16497 var y1sqz1
= y1z1
.multiply(y1
).mod(this.curve
.p
)
16498 var a
= this.curve
.a
16500 // w = 3 * x1^2 + a * z1^2
16501 var w
= x1
.square().multiply(THREE
)
16503 if (a
.signum() !== 0) {
16504 w
= w
.add(this.z
.square().multiply(a
))
16507 w
= w
.mod(this.curve
.p
)
16508 // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
16509 var x3
= w
.square().subtract(x1
.shiftLeft(3).multiply(y1sqz1
)).shiftLeft(1).multiply(y1z1
).mod(this.curve
.p
)
16510 // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
16511 var y3
= w
.multiply(THREE
).multiply(x1
).subtract(y1sqz1
.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1
).subtract(w
.pow(3)).mod(this.curve
.p
)
16512 // z3 = 8 * (y1 * z1)^3
16513 var z3
= y1z1
.pow(3).shiftLeft(3).mod(this.curve
.p
)
16515 return new Point(this.curve
, x3
, y3
, z3
)
16518 // Simple NAF (Non-Adjacent Form) multiplication algorithm
16519 // TODO: modularize the multiplication algorithm
16520 Point
.prototype.multiply = function (k
) {
16521 if (this.curve
.isInfinity(this)) return this
16522 if (k
.signum() === 0) return this.curve
.infinity
16525 var h
= e
.multiply(THREE
)
16527 var neg
= this.negate()
16530 for (var i
= h
.bitLength() - 2; i
> 0; --i
) {
16531 var hBit
= h
.testBit(i
)
16532 var eBit
= e
.testBit(i
)
16536 if (hBit
!== eBit
) {
16537 R
= R
.add(hBit
? this : neg
)
16544 // Compute this*j + x*k (simultaneous multiplication)
16545 Point
.prototype.multiplyTwo = function (j
, x
, k
) {
16546 var i
= Math
.max(j
.bitLength(), k
.bitLength()) - 1
16547 var R
= this.curve
.infinity
16548 var both
= this.add(x
)
16551 var jBit
= j
.testBit(i
)
16552 var kBit
= k
.testBit(i
)
16571 Point
.prototype.getEncoded = function (compressed
) {
16572 if (compressed
== null) compressed
= this.compressed
16573 if (this.curve
.isInfinity(this)) return new Buffer('00', 'hex') // Infinity point encoded is simply '00'
16575 var x
= this.affineX
16576 var y
= this.affineY
16577 var byteLength
= this.curve
.pLength
16582 buffer
= new Buffer(1 + byteLength
)
16583 buffer
.writeUInt8(y
.isEven() ? 0x02 : 0x03, 0)
16587 buffer
= new Buffer(1 + byteLength
+ byteLength
)
16588 buffer
.writeUInt8(0x04, 0)
16590 y
.toBuffer(byteLength
).copy(buffer
, 1 + byteLength
)
16593 x
.toBuffer(byteLength
).copy(buffer
, 1)
16598 Point
.decodeFrom = function (curve
, buffer
) {
16599 var type
= buffer
.readUInt8(0)
16600 var compressed
= (type
!== 4)
16602 var byteLength
= Math
.floor((curve
.p
.bitLength() + 7) / 8)
16603 var x
= BigInteger
.fromBuffer(buffer
.slice(1, 1 + byteLength
))
16607 assert
.equal(buffer
.length
, byteLength
+ 1, 'Invalid sequence length')
16608 assert(type
=== 0x02 || type
=== 0x03, 'Invalid sequence tag')
16610 var isOdd
= (type
=== 0x03)
16611 Q
= curve
.pointFromX(isOdd
, x
)
16613 assert
.equal(buffer
.length
, 1 + byteLength
+ byteLength
, 'Invalid sequence length')
16615 var y
= BigInteger
.fromBuffer(buffer
.slice(1 + byteLength
))
16616 Q
= Point
.fromAffine(curve
, x
, y
)
16619 Q
.compressed
= compressed
16623 Point
.prototype.toString = function () {
16624 if (this.curve
.isInfinity(this)) return '(INFINITY)'
16626 return '(' + this.affineX
.toString() + ',' + this.affineY
.toString() + ')'
16629 module
.exports
= Point
16631 }).call(this,require("buffer").Buffer
)
16632 },{"assert":1,"bigi":39,"buffer":5}],97:[function(require
,module
,exports
){
16635 var elliptic
= exports
;
16637 elliptic
.version
= require('../package.json').version
;
16638 elliptic
.utils
= require('./elliptic/utils');
16639 elliptic
.rand
= require('brorand');
16640 elliptic
.curve
= require('./elliptic/curve');
16641 elliptic
.curves
= require('./elliptic/curves');
16644 elliptic
.ec
= require('./elliptic/ec');
16645 elliptic
.eddsa
= require('./elliptic/eddsa');
16647 },{"../package.json":112,"./elliptic/curve":100,"./elliptic/curves":103,"./elliptic/ec":104,"./elliptic/eddsa":107,"./elliptic/utils":111,"brorand":82}],98:[function(require
,module
,exports
){
16650 var BN
= require('bn.js');
16651 var elliptic
= require('../../elliptic');
16652 var utils
= elliptic
.utils
;
16653 var getNAF
= utils
.getNAF
;
16654 var getJSF
= utils
.getJSF
;
16655 var assert
= utils
.assert
;
16657 function BaseCurve(type
, conf
) {
16659 this.p
= new BN(conf
.p
, 16);
16661 // Use Montgomery, when there is no fast reduction for the prime
16662 this.red
= conf
.prime
? BN
.red(conf
.prime
) : BN
.mont(this.p
);
16664 // Useful for many curves
16665 this.zero
= new BN(0).toRed(this.red
);
16666 this.one
= new BN(1).toRed(this.red
);
16667 this.two
= new BN(2).toRed(this.red
);
16669 // Curve configuration, optional
16670 this.n
= conf
.n
&& new BN(conf
.n
, 16);
16671 this.g
= conf
.g
&& this.pointFromJSON(conf
.g
, conf
.gRed
);
16673 // Temporary arrays
16674 this._wnafT1
= new Array(4);
16675 this._wnafT2
= new Array(4);
16676 this._wnafT3
= new Array(4);
16677 this._wnafT4
= new Array(4);
16679 // Generalized Greg Maxwell's trick
16680 var adjustCount
= this.n
&& this.p
.div(this.n
);
16681 if (!adjustCount
|| adjustCount
.cmpn(100) > 0) {
16684 this._maxwellTrick
= true;
16685 this.redN
= this.n
.toRed(this.red
);
16688 module
.exports
= BaseCurve
;
16690 BaseCurve
.prototype.point
= function point() {
16691 throw new Error('Not implemented');
16694 BaseCurve
.prototype.validate
= function validate() {
16695 throw new Error('Not implemented');
16698 BaseCurve
.prototype._fixedNafMul
= function _fixedNafMul(p
, k
) {
16699 assert(p
.precomputed
);
16700 var doubles
= p
._getDoubles();
16702 var naf
= getNAF(k
, 1);
16703 var I
= (1 << (doubles
.step
+ 1)) - (doubles
.step
% 2 === 0 ? 2 : 1);
16706 // Translate into more windowed form
16708 for (var j
= 0; j
< naf
.length
; j
+= doubles
.step
) {
16710 for (var k
= j
+ doubles
.step
- 1; k
>= j
; k
--)
16711 nafW
= (nafW
<< 1) + naf
[k
];
16715 var a
= this.jpoint(null, null, null);
16716 var b
= this.jpoint(null, null, null);
16717 for (var i
= I
; i
> 0; i
--) {
16718 for (var j
= 0; j
< repr
.length
; j
++) {
16719 var nafW
= repr
[j
];
16721 b
= b
.mixedAdd(doubles
.points
[j
]);
16722 else if (nafW
=== -i
)
16723 b
= b
.mixedAdd(doubles
.points
[j
].neg());
16730 BaseCurve
.prototype._wnafMul
= function _wnafMul(p
, k
) {
16733 // Precompute window
16734 var nafPoints
= p
._getNAFPoints(w
);
16736 var wnd
= nafPoints
.points
;
16739 var naf
= getNAF(k
, w
);
16741 // Add `this`*(N+1) for every w-NAF index
16742 var acc
= this.jpoint(null, null, null);
16743 for (var i
= naf
.length
- 1; i
>= 0; i
--) {
16745 for (var k
= 0; i
>= 0 && naf
[i
] === 0; i
--)
16755 if (p
.type
=== 'affine') {
16758 acc
= acc
.mixedAdd(wnd
[(z
- 1) >> 1]);
16760 acc
= acc
.mixedAdd(wnd
[(-z
- 1) >> 1].neg());
16764 acc
= acc
.add(wnd
[(z
- 1) >> 1]);
16766 acc
= acc
.add(wnd
[(-z
- 1) >> 1].neg());
16769 return p
.type
=== 'affine' ? acc
.toP() : acc
;
16772 BaseCurve
.prototype._wnafMulAdd
= function _wnafMulAdd(defW
,
16777 var wndWidth
= this._wnafT1
;
16778 var wnd
= this._wnafT2
;
16779 var naf
= this._wnafT3
;
16783 for (var i
= 0; i
< len
; i
++) {
16785 var nafPoints
= p
._getNAFPoints(defW
);
16786 wndWidth
[i
] = nafPoints
.wnd
;
16787 wnd
[i
] = nafPoints
.points
;
16790 // Comb small window NAFs
16791 for (var i
= len
- 1; i
>= 1; i
-= 2) {
16794 if (wndWidth
[a
] !== 1 || wndWidth
[b
] !== 1) {
16795 naf
[a
] = getNAF(coeffs
[a
], wndWidth
[a
]);
16796 naf
[b
] = getNAF(coeffs
[b
], wndWidth
[b
]);
16797 max
= Math
.max(naf
[a
].length
, max
);
16798 max
= Math
.max(naf
[b
].length
, max
);
16809 // Try to avoid Projective points, if possible
16810 if (points
[a
].y
.cmp(points
[b
].y
) === 0) {
16811 comb
[1] = points
[a
].add(points
[b
]);
16812 comb
[2] = points
[a
].toJ().mixedAdd(points
[b
].neg());
16813 } else if (points
[a
].y
.cmp(points
[b
].y
.redNeg()) === 0) {
16814 comb
[1] = points
[a
].toJ().mixedAdd(points
[b
]);
16815 comb
[2] = points
[a
].add(points
[b
].neg());
16817 comb
[1] = points
[a
].toJ().mixedAdd(points
[b
]);
16818 comb
[2] = points
[a
].toJ().mixedAdd(points
[b
].neg());
16833 var jsf
= getJSF(coeffs
[a
], coeffs
[b
]);
16834 max
= Math
.max(jsf
[0].length
, max
);
16835 naf
[a
] = new Array(max
);
16836 naf
[b
] = new Array(max
);
16837 for (var j
= 0; j
< max
; j
++) {
16838 var ja
= jsf
[0][j
] | 0;
16839 var jb
= jsf
[1][j
] | 0;
16841 naf
[a
][j
] = index
[(ja
+ 1) * 3 + (jb
+ 1)];
16847 var acc
= this.jpoint(null, null, null);
16848 var tmp
= this._wnafT4
;
16849 for (var i
= max
; i
>= 0; i
--) {
16854 for (var j
= 0; j
< len
; j
++) {
16855 tmp
[j
] = naf
[j
][i
] | 0;
16870 for (var j
= 0; j
< len
; j
++) {
16876 p
= wnd
[j
][(z
- 1) >> 1];
16878 p
= wnd
[j
][(-z
- 1) >> 1].neg();
16880 if (p
.type
=== 'affine')
16881 acc
= acc
.mixedAdd(p
);
16886 // Zeroify references
16887 for (var i
= 0; i
< len
; i
++)
16890 if (jacobianResult
)
16896 function BasePoint(curve
, type
) {
16897 this.curve
= curve
;
16899 this.precomputed
= null;
16901 BaseCurve
.BasePoint
= BasePoint
;
16903 BasePoint
.prototype.eq
= function eq(/*other*/) {
16904 throw new Error('Not implemented');
16907 BasePoint
.prototype.validate
= function validate() {
16908 return this.curve
.validate(this);
16911 BaseCurve
.prototype.decodePoint
= function decodePoint(bytes
, enc
) {
16912 bytes
= utils
.toArray(bytes
, enc
);
16914 var len
= this.p
.byteLength();
16916 // uncompressed, hybrid-odd, hybrid-even
16917 if ((bytes
[0] === 0x04 || bytes
[0] === 0x06 || bytes
[0] === 0x07) &&
16918 bytes
.length
- 1 === 2 * len
) {
16919 if (bytes
[0] === 0x06)
16920 assert(bytes
[bytes
.length
- 1] % 2 === 0);
16921 else if (bytes
[0] === 0x07)
16922 assert(bytes
[bytes
.length
- 1] % 2 === 1);
16924 var res
= this.point(bytes
.slice(1, 1 + len
),
16925 bytes
.slice(1 + len
, 1 + 2 * len
));
16928 } else if ((bytes
[0] === 0x02 || bytes
[0] === 0x03) &&
16929 bytes
.length
- 1 === len
) {
16930 return this.pointFromX(bytes
.slice(1, 1 + len
), bytes
[0] === 0x03);
16932 throw new Error('Unknown point format');
16935 BasePoint
.prototype.encodeCompressed
= function encodeCompressed(enc
) {
16936 return this.encode(enc
, true);
16939 BasePoint
.prototype._encode
= function _encode(compact
) {
16940 var len
= this.curve
.p
.byteLength();
16941 var x
= this.getX().toArray('be', len
);
16944 return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x
);
16946 return [ 0x04 ].concat(x
, this.getY().toArray('be', len
)) ;
16949 BasePoint
.prototype.encode
= function encode(enc
, compact
) {
16950 return utils
.encode(this._encode(compact
), enc
);
16953 BasePoint
.prototype.precompute
= function precompute(power
) {
16954 if (this.precomputed
)
16957 var precomputed
= {
16962 precomputed
.naf
= this._getNAFPoints(8);
16963 precomputed
.doubles
= this._getDoubles(4, power
);
16964 precomputed
.beta
= this._getBeta();
16965 this.precomputed
= precomputed
;
16970 BasePoint
.prototype._hasDoubles
= function _hasDoubles(k
) {
16971 if (!this.precomputed
)
16974 var doubles
= this.precomputed
.doubles
;
16978 return doubles
.points
.length
>= Math
.ceil((k
.bitLength() + 1) / doubles
.step
);
16981 BasePoint
.prototype._getDoubles
= function _getDoubles(step
, power
) {
16982 if (this.precomputed
&& this.precomputed
.doubles
)
16983 return this.precomputed
.doubles
;
16985 var doubles
= [ this ];
16987 for (var i
= 0; i
< power
; i
+= step
) {
16988 for (var j
= 0; j
< step
; j
++)
16998 BasePoint
.prototype._getNAFPoints
= function _getNAFPoints(wnd
) {
16999 if (this.precomputed
&& this.precomputed
.naf
)
17000 return this.precomputed
.naf
;
17002 var res
= [ this ];
17003 var max
= (1 << wnd
) - 1;
17004 var dbl
= max
=== 1 ? null : this.dbl();
17005 for (var i
= 1; i
< max
; i
++)
17006 res
[i
] = res
[i
- 1].add(dbl
);
17013 BasePoint
.prototype._getBeta
= function _getBeta() {
17017 BasePoint
.prototype.dblp
= function dblp(k
) {
17019 for (var i
= 0; i
< k
; i
++)
17024 },{"../../elliptic":97,"bn.js":81}],99:[function(require
,module
,exports
){
17027 var curve
= require('../curve');
17028 var elliptic
= require('../../elliptic');
17029 var BN
= require('bn.js');
17030 var inherits
= require('inherits');
17031 var Base
= curve
.base
;
17033 var assert
= elliptic
.utils
.assert
;
17035 function EdwardsCurve(conf
) {
17036 // NOTE: Important as we are creating point in Base.call()
17037 this.twisted
= (conf
.a
| 0) !== 1;
17038 this.mOneA
= this.twisted
&& (conf
.a
| 0) === -1;
17039 this.extended
= this.mOneA
;
17041 Base
.call(this, 'edwards', conf
);
17043 this.a
= new BN(conf
.a
, 16).umod(this.red
.m
);
17044 this.a
= this.a
.toRed(this.red
);
17045 this.c
= new BN(conf
.c
, 16).toRed(this.red
);
17046 this.c2
= this.c
.redSqr();
17047 this.d
= new BN(conf
.d
, 16).toRed(this.red
);
17048 this.dd
= this.d
.redAdd(this.d
);
17050 assert(!this.twisted
|| this.c
.fromRed().cmpn(1) === 0);
17051 this.oneC
= (conf
.c
| 0) === 1;
17053 inherits(EdwardsCurve
, Base
);
17054 module
.exports
= EdwardsCurve
;
17056 EdwardsCurve
.prototype._mulA
= function _mulA(num
) {
17058 return num
.redNeg();
17060 return this.a
.redMul(num
);
17063 EdwardsCurve
.prototype._mulC
= function _mulC(num
) {
17067 return this.c
.redMul(num
);
17070 // Just for compatibility with Short curve
17071 EdwardsCurve
.prototype.jpoint
= function jpoint(x
, y
, z
, t
) {
17072 return this.point(x
, y
, z
, t
);
17075 EdwardsCurve
.prototype.pointFromX
= function pointFromX(x
, odd
) {
17078 x
= x
.toRed(this.red
);
17080 var x2
= x
.redSqr();
17081 var rhs
= this.c2
.redSub(this.a
.redMul(x2
));
17082 var lhs
= this.one
.redSub(this.c2
.redMul(this.d
).redMul(x2
));
17084 var y2
= rhs
.redMul(lhs
.redInvm());
17085 var y
= y2
.redSqrt();
17086 if (y
.redSqr().redSub(y2
).cmp(this.zero
) !== 0)
17087 throw new Error('invalid point');
17089 var isOdd
= y
.fromRed().isOdd();
17090 if (odd
&& !isOdd
|| !odd
&& isOdd
)
17093 return this.point(x
, y
);
17096 EdwardsCurve
.prototype.pointFromY
= function pointFromY(y
, odd
) {
17099 y
= y
.toRed(this.red
);
17101 // x^2 = (y^2 - 1) / (d y^2 + 1)
17102 var y2
= y
.redSqr();
17103 var lhs
= y2
.redSub(this.one
);
17104 var rhs
= y2
.redMul(this.d
).redAdd(this.one
);
17105 var x2
= lhs
.redMul(rhs
.redInvm());
17107 if (x2
.cmp(this.zero
) === 0) {
17109 throw new Error('invalid point');
17111 return this.point(this.zero
, y
);
17114 var x
= x2
.redSqrt();
17115 if (x
.redSqr().redSub(x2
).cmp(this.zero
) !== 0)
17116 throw new Error('invalid point');
17118 if (x
.isOdd() !== odd
)
17121 return this.point(x
, y
);
17124 EdwardsCurve
.prototype.validate
= function validate(point
) {
17125 if (point
.isInfinity())
17128 // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
17131 var x2
= point
.x
.redSqr();
17132 var y2
= point
.y
.redSqr();
17133 var lhs
= x2
.redMul(this.a
).redAdd(y2
);
17134 var rhs
= this.c2
.redMul(this.one
.redAdd(this.d
.redMul(x2
).redMul(y2
)));
17136 return lhs
.cmp(rhs
) === 0;
17139 function Point(curve
, x
, y
, z
, t
) {
17140 Base
.BasePoint
.call(this, curve
, 'projective');
17141 if (x
=== null && y
=== null && z
=== null) {
17142 this.x
= this.curve
.zero
;
17143 this.y
= this.curve
.one
;
17144 this.z
= this.curve
.one
;
17145 this.t
= this.curve
.zero
;
17148 this.x
= new BN(x
, 16);
17149 this.y
= new BN(y
, 16);
17150 this.z
= z
? new BN(z
, 16) : this.curve
.one
;
17151 this.t
= t
&& new BN(t
, 16);
17153 this.x
= this.x
.toRed(this.curve
.red
);
17155 this.y
= this.y
.toRed(this.curve
.red
);
17157 this.z
= this.z
.toRed(this.curve
.red
);
17158 if (this.t
&& !this.t
.red
)
17159 this.t
= this.t
.toRed(this.curve
.red
);
17160 this.zOne
= this.z
=== this.curve
.one
;
17162 // Use extended coordinates
17163 if (this.curve
.extended
&& !this.t
) {
17164 this.t
= this.x
.redMul(this.y
);
17166 this.t
= this.t
.redMul(this.z
.redInvm());
17170 inherits(Point
, Base
.BasePoint
);
17172 EdwardsCurve
.prototype.pointFromJSON
= function pointFromJSON(obj
) {
17173 return Point
.fromJSON(this, obj
);
17176 EdwardsCurve
.prototype.point
= function point(x
, y
, z
, t
) {
17177 return new Point(this, x
, y
, z
, t
);
17180 Point
.fromJSON
= function fromJSON(curve
, obj
) {
17181 return new Point(curve
, obj
[0], obj
[1], obj
[2]);
17184 Point
.prototype.inspect
= function inspect() {
17185 if (this.isInfinity())
17186 return '<EC Point Infinity>';
17187 return '<EC Point x: ' + this.x
.fromRed().toString(16, 2) +
17188 ' y: ' + this.y
.fromRed().toString(16, 2) +
17189 ' z: ' + this.z
.fromRed().toString(16, 2) + '>';
17192 Point
.prototype.isInfinity
= function isInfinity() {
17193 // XXX This code assumes that zero is always zero in red
17194 return this.x
.cmpn(0) === 0 &&
17195 this.y
.cmp(this.z
) === 0;
17198 Point
.prototype._extDbl
= function _extDbl() {
17199 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
17200 // #doubling-dbl-2008-hwcd
17204 var a
= this.x
.redSqr();
17206 var b
= this.y
.redSqr();
17208 var c
= this.z
.redSqr();
17211 var d
= this.curve
._mulA(a
);
17212 // E = (X1 + Y1)^2 - A - B
17213 var e
= this.x
.redAdd(this.y
).redSqr().redISub(a
).redISub(b
);
17215 var g
= d
.redAdd(b
);
17217 var f
= g
.redSub(c
);
17219 var h
= d
.redSub(b
);
17221 var nx
= e
.redMul(f
);
17223 var ny
= g
.redMul(h
);
17225 var nt
= e
.redMul(h
);
17227 var nz
= f
.redMul(g
);
17228 return this.curve
.point(nx
, ny
, nz
, nt
);
17231 Point
.prototype._projDbl
= function _projDbl() {
17232 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
17233 // #doubling-dbl-2008-bbjlp
17234 // #doubling-dbl-2007-bl
17236 // Generally 3M + 4S or 2M + 4S
17239 var b
= this.x
.redAdd(this.y
).redSqr();
17241 var c
= this.x
.redSqr();
17243 var d
= this.y
.redSqr();
17248 if (this.curve
.twisted
) {
17250 var e
= this.curve
._mulA(c
);
17252 var f
= e
.redAdd(d
);
17254 // X3 = (B - C - D) * (F - 2)
17255 nx
= b
.redSub(c
).redSub(d
).redMul(f
.redSub(this.curve
.two
));
17256 // Y3 = F * (E - D)
17257 ny
= f
.redMul(e
.redSub(d
));
17258 // Z3 = F^2 - 2 * F
17259 nz
= f
.redSqr().redSub(f
).redSub(f
);
17262 var h
= this.z
.redSqr();
17264 var j
= f
.redSub(h
).redISub(h
);
17266 nx
= b
.redSub(c
).redISub(d
).redMul(j
);
17267 // Y3 = F * (E - D)
17268 ny
= f
.redMul(e
.redSub(d
));
17274 var e
= c
.redAdd(d
);
17276 var h
= this.curve
._mulC(this.c
.redMul(this.z
)).redSqr();
17278 var j
= e
.redSub(h
).redSub(h
);
17279 // X3 = c * (B - E) * J
17280 nx
= this.curve
._mulC(b
.redISub(e
)).redMul(j
);
17281 // Y3 = c * E * (C - D)
17282 ny
= this.curve
._mulC(e
).redMul(c
.redISub(d
));
17286 return this.curve
.point(nx
, ny
, nz
);
17289 Point
.prototype.dbl
= function dbl() {
17290 if (this.isInfinity())
17293 // Double in extended coordinates
17294 if (this.curve
.extended
)
17295 return this._extDbl();
17297 return this._projDbl();
17300 Point
.prototype._extAdd
= function _extAdd(p
) {
17301 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
17302 // #addition-add-2008-hwcd-3
17305 // A = (Y1 - X1) * (Y2 - X2)
17306 var a
= this.y
.redSub(this.x
).redMul(p
.y
.redSub(p
.x
));
17307 // B = (Y1 + X1) * (Y2 + X2)
17308 var b
= this.y
.redAdd(this.x
).redMul(p
.y
.redAdd(p
.x
));
17310 var c
= this.t
.redMul(this.curve
.dd
).redMul(p
.t
);
17312 var d
= this.z
.redMul(p
.z
.redAdd(p
.z
));
17314 var e
= b
.redSub(a
);
17316 var f
= d
.redSub(c
);
17318 var g
= d
.redAdd(c
);
17320 var h
= b
.redAdd(a
);
17322 var nx
= e
.redMul(f
);
17324 var ny
= g
.redMul(h
);
17326 var nt
= e
.redMul(h
);
17328 var nz
= f
.redMul(g
);
17329 return this.curve
.point(nx
, ny
, nz
, nt
);
17332 Point
.prototype._projAdd
= function _projAdd(p
) {
17333 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
17334 // #addition-add-2008-bbjlp
17335 // #addition-add-2007-bl
17339 var a
= this.z
.redMul(p
.z
);
17341 var b
= a
.redSqr();
17343 var c
= this.x
.redMul(p
.x
);
17345 var d
= this.y
.redMul(p
.y
);
17347 var e
= this.curve
.d
.redMul(c
).redMul(d
);
17349 var f
= b
.redSub(e
);
17351 var g
= b
.redAdd(e
);
17352 // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
17353 var tmp
= this.x
.redAdd(this.y
).redMul(p
.x
.redAdd(p
.y
)).redISub(c
).redISub(d
);
17354 var nx
= a
.redMul(f
).redMul(tmp
);
17357 if (this.curve
.twisted
) {
17358 // Y3 = A * G * (D - a * C)
17359 ny
= a
.redMul(g
).redMul(d
.redSub(this.curve
._mulA(c
)));
17363 // Y3 = A * G * (D - C)
17364 ny
= a
.redMul(g
).redMul(d
.redSub(c
));
17366 nz
= this.curve
._mulC(f
).redMul(g
);
17368 return this.curve
.point(nx
, ny
, nz
);
17371 Point
.prototype.add
= function add(p
) {
17372 if (this.isInfinity())
17374 if (p
.isInfinity())
17377 if (this.curve
.extended
)
17378 return this._extAdd(p
);
17380 return this._projAdd(p
);
17383 Point
.prototype.mul
= function mul(k
) {
17384 if (this._hasDoubles(k
))
17385 return this.curve
._fixedNafMul(this, k
);
17387 return this.curve
._wnafMul(this, k
);
17390 Point
.prototype.mulAdd
= function mulAdd(k1
, p
, k2
) {
17391 return this.curve
._wnafMulAdd(1, [ this, p
], [ k1
, k2
], 2, false);
17394 Point
.prototype.jmulAdd
= function jmulAdd(k1
, p
, k2
) {
17395 return this.curve
._wnafMulAdd(1, [ this, p
], [ k1
, k2
], 2, true);
17398 Point
.prototype.normalize
= function normalize() {
17402 // Normalize coordinates
17403 var zi
= this.z
.redInvm();
17404 this.x
= this.x
.redMul(zi
);
17405 this.y
= this.y
.redMul(zi
);
17407 this.t
= this.t
.redMul(zi
);
17408 this.z
= this.curve
.one
;
17413 Point
.prototype.neg
= function neg() {
17414 return this.curve
.point(this.x
.redNeg(),
17417 this.t
&& this.t
.redNeg());
17420 Point
.prototype.getX
= function getX() {
17422 return this.x
.fromRed();
17425 Point
.prototype.getY
= function getY() {
17427 return this.y
.fromRed();
17430 Point
.prototype.eq
= function eq(other
) {
17431 return this === other
||
17432 this.getX().cmp(other
.getX()) === 0 &&
17433 this.getY().cmp(other
.getY()) === 0;
17436 Point
.prototype.eqXToP
= function eqXToP(x
) {
17437 var rx
= x
.toRed(this.curve
.red
).redMul(this.z
);
17438 if (this.x
.cmp(rx
) === 0)
17441 var xc
= x
.clone();
17442 var t
= this.curve
.redN
.redMul(this.z
);
17444 xc
.iadd(this.curve
.n
);
17445 if (xc
.cmp(this.curve
.p
) >= 0)
17449 if (this.x
.cmp(rx
) === 0)
17455 // Compatibility with BaseCurve
17456 Point
.prototype.toP
= Point
.prototype.normalize
;
17457 Point
.prototype.mixedAdd
= Point
.prototype.add
;
17459 },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],100:[function(require
,module
,exports
){
17462 var curve
= exports
;
17464 curve
.base
= require('./base');
17465 curve
.short = require('./short');
17466 curve
.mont
= require('./mont');
17467 curve
.edwards
= require('./edwards');
17469 },{"./base":98,"./edwards":99,"./mont":101,"./short":102}],101:[function(require
,module
,exports
){
17472 var curve
= require('../curve');
17473 var BN
= require('bn.js');
17474 var inherits
= require('inherits');
17475 var Base
= curve
.base
;
17477 var elliptic
= require('../../elliptic');
17478 var utils
= elliptic
.utils
;
17480 function MontCurve(conf
) {
17481 Base
.call(this, 'mont', conf
);
17483 this.a
= new BN(conf
.a
, 16).toRed(this.red
);
17484 this.b
= new BN(conf
.b
, 16).toRed(this.red
);
17485 this.i4
= new BN(4).toRed(this.red
).redInvm();
17486 this.two
= new BN(2).toRed(this.red
);
17487 this.a24
= this.i4
.redMul(this.a
.redAdd(this.two
));
17489 inherits(MontCurve
, Base
);
17490 module
.exports
= MontCurve
;
17492 MontCurve
.prototype.validate
= function validate(point
) {
17493 var x
= point
.normalize().x
;
17494 var x2
= x
.redSqr();
17495 var rhs
= x2
.redMul(x
).redAdd(x2
.redMul(this.a
)).redAdd(x
);
17496 var y
= rhs
.redSqrt();
17498 return y
.redSqr().cmp(rhs
) === 0;
17501 function Point(curve
, x
, z
) {
17502 Base
.BasePoint
.call(this, curve
, 'projective');
17503 if (x
=== null && z
=== null) {
17504 this.x
= this.curve
.one
;
17505 this.z
= this.curve
.zero
;
17507 this.x
= new BN(x
, 16);
17508 this.z
= new BN(z
, 16);
17510 this.x
= this.x
.toRed(this.curve
.red
);
17512 this.z
= this.z
.toRed(this.curve
.red
);
17515 inherits(Point
, Base
.BasePoint
);
17517 MontCurve
.prototype.decodePoint
= function decodePoint(bytes
, enc
) {
17518 return this.point(utils
.toArray(bytes
, enc
), 1);
17521 MontCurve
.prototype.point
= function point(x
, z
) {
17522 return new Point(this, x
, z
);
17525 MontCurve
.prototype.pointFromJSON
= function pointFromJSON(obj
) {
17526 return Point
.fromJSON(this, obj
);
17529 Point
.prototype.precompute
= function precompute() {
17533 Point
.prototype._encode
= function _encode() {
17534 return this.getX().toArray('be', this.curve
.p
.byteLength());
17537 Point
.fromJSON
= function fromJSON(curve
, obj
) {
17538 return new Point(curve
, obj
[0], obj
[1] || curve
.one
);
17541 Point
.prototype.inspect
= function inspect() {
17542 if (this.isInfinity())
17543 return '<EC Point Infinity>';
17544 return '<EC Point x: ' + this.x
.fromRed().toString(16, 2) +
17545 ' z: ' + this.z
.fromRed().toString(16, 2) + '>';
17548 Point
.prototype.isInfinity
= function isInfinity() {
17549 // XXX This code assumes that zero is always zero in red
17550 return this.z
.cmpn(0) === 0;
17553 Point
.prototype.dbl
= function dbl() {
17554 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
17558 var a
= this.x
.redAdd(this.z
);
17560 var aa
= a
.redSqr();
17562 var b
= this.x
.redSub(this.z
);
17564 var bb
= b
.redSqr();
17566 var c
= aa
.redSub(bb
);
17568 var nx
= aa
.redMul(bb
);
17569 // Z3 = C * (BB + A24 * C)
17570 var nz
= c
.redMul(bb
.redAdd(this.curve
.a24
.redMul(c
)));
17571 return this.curve
.point(nx
, nz
);
17574 Point
.prototype.add
= function add() {
17575 throw new Error('Not supported on Montgomery curve');
17578 Point
.prototype.diffAdd
= function diffAdd(p
, diff
) {
17579 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
17583 var a
= this.x
.redAdd(this.z
);
17585 var b
= this.x
.redSub(this.z
);
17587 var c
= p
.x
.redAdd(p
.z
);
17589 var d
= p
.x
.redSub(p
.z
);
17591 var da
= d
.redMul(a
);
17593 var cb
= c
.redMul(b
);
17594 // X5 = Z1 * (DA + CB)^2
17595 var nx
= diff
.z
.redMul(da
.redAdd(cb
).redSqr());
17596 // Z5 = X1 * (DA - CB)^2
17597 var nz
= diff
.x
.redMul(da
.redISub(cb
).redSqr());
17598 return this.curve
.point(nx
, nz
);
17601 Point
.prototype.mul
= function mul(k
) {
17603 var a
= this; // (N / 2) * Q + Q
17604 var b
= this.curve
.point(null, null); // (N / 2) * Q
17607 for (var bits
= []; t
.cmpn(0) !== 0; t
.iushrn(1))
17608 bits
.push(t
.andln(1));
17610 for (var i
= bits
.length
- 1; i
>= 0; i
--) {
17611 if (bits
[i
] === 0) {
17612 // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
17613 a
= a
.diffAdd(b
, c
);
17614 // N * Q = 2 * ((N / 2) * Q + Q))
17617 // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
17618 b
= a
.diffAdd(b
, c
);
17619 // N * Q + Q = 2 * ((N / 2) * Q + Q)
17626 Point
.prototype.mulAdd
= function mulAdd() {
17627 throw new Error('Not supported on Montgomery curve');
17630 Point
.prototype.jumlAdd
= function jumlAdd() {
17631 throw new Error('Not supported on Montgomery curve');
17634 Point
.prototype.eq
= function eq(other
) {
17635 return this.getX().cmp(other
.getX()) === 0;
17638 Point
.prototype.normalize
= function normalize() {
17639 this.x
= this.x
.redMul(this.z
.redInvm());
17640 this.z
= this.curve
.one
;
17644 Point
.prototype.getX
= function getX() {
17645 // Normalize coordinates
17648 return this.x
.fromRed();
17651 },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],102:[function(require
,module
,exports
){
17654 var curve
= require('../curve');
17655 var elliptic
= require('../../elliptic');
17656 var BN
= require('bn.js');
17657 var inherits
= require('inherits');
17658 var Base
= curve
.base
;
17660 var assert
= elliptic
.utils
.assert
;
17662 function ShortCurve(conf
) {
17663 Base
.call(this, 'short', conf
);
17665 this.a
= new BN(conf
.a
, 16).toRed(this.red
);
17666 this.b
= new BN(conf
.b
, 16).toRed(this.red
);
17667 this.tinv
= this.two
.redInvm();
17669 this.zeroA
= this.a
.fromRed().cmpn(0) === 0;
17670 this.threeA
= this.a
.fromRed().sub(this.p
).cmpn(-3) === 0;
17672 // If the curve is endomorphic, precalculate beta and lambda
17673 this.endo
= this._getEndomorphism(conf
);
17674 this._endoWnafT1
= new Array(4);
17675 this._endoWnafT2
= new Array(4);
17677 inherits(ShortCurve
, Base
);
17678 module
.exports
= ShortCurve
;
17680 ShortCurve
.prototype._getEndomorphism
= function _getEndomorphism(conf
) {
17681 // No efficient endomorphism
17682 if (!this.zeroA
|| !this.g
|| !this.n
|| this.p
.modn(3) !== 1)
17685 // Compute beta and lambda, that lambda * P = (beta * Px; Py)
17689 beta
= new BN(conf
.beta
, 16).toRed(this.red
);
17691 var betas
= this._getEndoRoots(this.p
);
17692 // Choose the smallest beta
17693 beta
= betas
[0].cmp(betas
[1]) < 0 ? betas
[0] : betas
[1];
17694 beta
= beta
.toRed(this.red
);
17697 lambda
= new BN(conf
.lambda
, 16);
17699 // Choose the lambda that is matching selected beta
17700 var lambdas
= this._getEndoRoots(this.n
);
17701 if (this.g
.mul(lambdas
[0]).x
.cmp(this.g
.x
.redMul(beta
)) === 0) {
17702 lambda
= lambdas
[0];
17704 lambda
= lambdas
[1];
17705 assert(this.g
.mul(lambda
).x
.cmp(this.g
.x
.redMul(beta
)) === 0);
17709 // Get basis vectors, used for balanced length-two representation
17712 basis
= conf
.basis
.map(function(vec
) {
17714 a: new BN(vec
.a
, 16),
17715 b: new BN(vec
.b
, 16)
17719 basis
= this._getEndoBasis(lambda
);
17729 ShortCurve
.prototype._getEndoRoots
= function _getEndoRoots(num
) {
17730 // Find roots of for x^2 + x + 1 in F
17731 // Root = (-1 +- Sqrt(-3)) / 2
17733 var red
= num
=== this.p
? this.red : BN
.mont(num
);
17734 var tinv
= new BN(2).toRed(red
).redInvm();
17735 var ntinv
= tinv
.redNeg();
17737 var s
= new BN(3).toRed(red
).redNeg().redSqrt().redMul(tinv
);
17739 var l1
= ntinv
.redAdd(s
).fromRed();
17740 var l2
= ntinv
.redSub(s
).fromRed();
17744 ShortCurve
.prototype._getEndoBasis
= function _getEndoBasis(lambda
) {
17745 // aprxSqrt >= sqrt(this.n)
17746 var aprxSqrt
= this.n
.ushrn(Math
.floor(this.n
.bitLength() / 2));
17749 // Run EGCD, until r(L + 1) < aprxSqrt
17751 var v
= this.n
.clone();
17752 var x1
= new BN(1);
17753 var y1
= new BN(0);
17754 var x2
= new BN(0);
17755 var y2
= new BN(1);
17757 // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
17771 while (u
.cmpn(0) !== 0) {
17773 r
= v
.sub(q
.mul(u
));
17774 x
= x2
.sub(q
.mul(x1
));
17775 var y
= y2
.sub(q
.mul(y1
));
17777 if (!a1
&& r
.cmp(aprxSqrt
) < 0) {
17782 } else if (a1
&& ++i
=== 2) {
17797 var len1
= a1
.sqr().add(b1
.sqr());
17798 var len2
= a2
.sqr().add(b2
.sqr());
17799 if (len2
.cmp(len1
) >= 0) {
17820 ShortCurve
.prototype._endoSplit
= function _endoSplit(k
) {
17821 var basis
= this.endo
.basis
;
17825 var c1
= v2
.b
.mul(k
).divRound(this.n
);
17826 var c2
= v1
.b
.neg().mul(k
).divRound(this.n
);
17828 var p1
= c1
.mul(v1
.a
);
17829 var p2
= c2
.mul(v2
.a
);
17830 var q1
= c1
.mul(v1
.b
);
17831 var q2
= c2
.mul(v2
.b
);
17833 // Calculate answer
17834 var k1
= k
.sub(p1
).sub(p2
);
17835 var k2
= q1
.add(q2
).neg();
17836 return { k1: k1
, k2: k2
};
17839 ShortCurve
.prototype.pointFromX
= function pointFromX(x
, odd
) {
17842 x
= x
.toRed(this.red
);
17844 var y2
= x
.redSqr().redMul(x
).redIAdd(x
.redMul(this.a
)).redIAdd(this.b
);
17845 var y
= y2
.redSqrt();
17846 if (y
.redSqr().redSub(y2
).cmp(this.zero
) !== 0)
17847 throw new Error('invalid point');
17849 // XXX Is there any way to tell if the number is odd without converting it
17850 // to non-red form?
17851 var isOdd
= y
.fromRed().isOdd();
17852 if (odd
&& !isOdd
|| !odd
&& isOdd
)
17855 return this.point(x
, y
);
17858 ShortCurve
.prototype.validate
= function validate(point
) {
17865 var ax
= this.a
.redMul(x
);
17866 var rhs
= x
.redSqr().redMul(x
).redIAdd(ax
).redIAdd(this.b
);
17867 return y
.redSqr().redISub(rhs
).cmpn(0) === 0;
17870 ShortCurve
.prototype._endoWnafMulAdd
=
17871 function _endoWnafMulAdd(points
, coeffs
, jacobianResult
) {
17872 var npoints
= this._endoWnafT1
;
17873 var ncoeffs
= this._endoWnafT2
;
17874 for (var i
= 0; i
< points
.length
; i
++) {
17875 var split
= this._endoSplit(coeffs
[i
]);
17877 var beta
= p
._getBeta();
17879 if (split
.k1
.negative
) {
17883 if (split
.k2
.negative
) {
17885 beta
= beta
.neg(true);
17888 npoints
[i
* 2] = p
;
17889 npoints
[i
* 2 + 1] = beta
;
17890 ncoeffs
[i
* 2] = split
.k1
;
17891 ncoeffs
[i
* 2 + 1] = split
.k2
;
17893 var res
= this._wnafMulAdd(1, npoints
, ncoeffs
, i
* 2, jacobianResult
);
17895 // Clean-up references to points and coefficients
17896 for (var j
= 0; j
< i
* 2; j
++) {
17903 function Point(curve
, x
, y
, isRed
) {
17904 Base
.BasePoint
.call(this, curve
, 'affine');
17905 if (x
=== null && y
=== null) {
17910 this.x
= new BN(x
, 16);
17911 this.y
= new BN(y
, 16);
17912 // Force redgomery representation when loading from JSON
17914 this.x
.forceRed(this.curve
.red
);
17915 this.y
.forceRed(this.curve
.red
);
17918 this.x
= this.x
.toRed(this.curve
.red
);
17920 this.y
= this.y
.toRed(this.curve
.red
);
17924 inherits(Point
, Base
.BasePoint
);
17926 ShortCurve
.prototype.point
= function point(x
, y
, isRed
) {
17927 return new Point(this, x
, y
, isRed
);
17930 ShortCurve
.prototype.pointFromJSON
= function pointFromJSON(obj
, red
) {
17931 return Point
.fromJSON(this, obj
, red
);
17934 Point
.prototype._getBeta
= function _getBeta() {
17935 if (!this.curve
.endo
)
17938 var pre
= this.precomputed
;
17939 if (pre
&& pre
.beta
)
17942 var beta
= this.curve
.point(this.x
.redMul(this.curve
.endo
.beta
), this.y
);
17944 var curve
= this.curve
;
17945 var endoMul = function(p
) {
17946 return curve
.point(p
.x
.redMul(curve
.endo
.beta
), p
.y
);
17949 beta
.precomputed
= {
17953 points: pre
.naf
.points
.map(endoMul
)
17955 doubles: pre
.doubles
&& {
17956 step: pre
.doubles
.step
,
17957 points: pre
.doubles
.points
.map(endoMul
)
17964 Point
.prototype.toJSON
= function toJSON() {
17965 if (!this.precomputed
)
17966 return [ this.x
, this.y
];
17968 return [ this.x
, this.y
, this.precomputed
&& {
17969 doubles: this.precomputed
.doubles
&& {
17970 step: this.precomputed
.doubles
.step
,
17971 points: this.precomputed
.doubles
.points
.slice(1)
17973 naf: this.precomputed
.naf
&& {
17974 wnd: this.precomputed
.naf
.wnd
,
17975 points: this.precomputed
.naf
.points
.slice(1)
17980 Point
.fromJSON
= function fromJSON(curve
, obj
, red
) {
17981 if (typeof obj
=== 'string')
17982 obj
= JSON
.parse(obj
);
17983 var res
= curve
.point(obj
[0], obj
[1], red
);
17987 function obj2point(obj
) {
17988 return curve
.point(obj
[0], obj
[1], red
);
17992 res
.precomputed
= {
17994 doubles: pre
.doubles
&& {
17995 step: pre
.doubles
.step
,
17996 points: [ res
].concat(pre
.doubles
.points
.map(obj2point
))
18000 points: [ res
].concat(pre
.naf
.points
.map(obj2point
))
18006 Point
.prototype.inspect
= function inspect() {
18007 if (this.isInfinity())
18008 return '<EC Point Infinity>';
18009 return '<EC Point x: ' + this.x
.fromRed().toString(16, 2) +
18010 ' y: ' + this.y
.fromRed().toString(16, 2) + '>';
18013 Point
.prototype.isInfinity
= function isInfinity() {
18017 Point
.prototype.add
= function add(p
) {
18031 if (this.neg().eq(p
))
18032 return this.curve
.point(null, null);
18035 if (this.x
.cmp(p
.x
) === 0)
18036 return this.curve
.point(null, null);
18038 var c
= this.y
.redSub(p
.y
);
18039 if (c
.cmpn(0) !== 0)
18040 c
= c
.redMul(this.x
.redSub(p
.x
).redInvm());
18041 var nx
= c
.redSqr().redISub(this.x
).redISub(p
.x
);
18042 var ny
= c
.redMul(this.x
.redSub(nx
)).redISub(this.y
);
18043 return this.curve
.point(nx
, ny
);
18046 Point
.prototype.dbl
= function dbl() {
18051 var ys1
= this.y
.redAdd(this.y
);
18052 if (ys1
.cmpn(0) === 0)
18053 return this.curve
.point(null, null);
18055 var a
= this.curve
.a
;
18057 var x2
= this.x
.redSqr();
18058 var dyinv
= ys1
.redInvm();
18059 var c
= x2
.redAdd(x2
).redIAdd(x2
).redIAdd(a
).redMul(dyinv
);
18061 var nx
= c
.redSqr().redISub(this.x
.redAdd(this.x
));
18062 var ny
= c
.redMul(this.x
.redSub(nx
)).redISub(this.y
);
18063 return this.curve
.point(nx
, ny
);
18066 Point
.prototype.getX
= function getX() {
18067 return this.x
.fromRed();
18070 Point
.prototype.getY
= function getY() {
18071 return this.y
.fromRed();
18074 Point
.prototype.mul
= function mul(k
) {
18077 if (this._hasDoubles(k
))
18078 return this.curve
._fixedNafMul(this, k
);
18079 else if (this.curve
.endo
)
18080 return this.curve
._endoWnafMulAdd([ this ], [ k
]);
18082 return this.curve
._wnafMul(this, k
);
18085 Point
.prototype.mulAdd
= function mulAdd(k1
, p2
, k2
) {
18086 var points
= [ this, p2
];
18087 var coeffs
= [ k1
, k2
];
18088 if (this.curve
.endo
)
18089 return this.curve
._endoWnafMulAdd(points
, coeffs
);
18091 return this.curve
._wnafMulAdd(1, points
, coeffs
, 2);
18094 Point
.prototype.jmulAdd
= function jmulAdd(k1
, p2
, k2
) {
18095 var points
= [ this, p2
];
18096 var coeffs
= [ k1
, k2
];
18097 if (this.curve
.endo
)
18098 return this.curve
._endoWnafMulAdd(points
, coeffs
, true);
18100 return this.curve
._wnafMulAdd(1, points
, coeffs
, 2, true);
18103 Point
.prototype.eq
= function eq(p
) {
18104 return this === p
||
18105 this.inf
=== p
.inf
&&
18106 (this.inf
|| this.x
.cmp(p
.x
) === 0 && this.y
.cmp(p
.y
) === 0);
18109 Point
.prototype.neg
= function neg(_precompute
) {
18113 var res
= this.curve
.point(this.x
, this.y
.redNeg());
18114 if (_precompute
&& this.precomputed
) {
18115 var pre
= this.precomputed
;
18116 var negate = function(p
) {
18119 res
.precomputed
= {
18122 points: pre
.naf
.points
.map(negate
)
18124 doubles: pre
.doubles
&& {
18125 step: pre
.doubles
.step
,
18126 points: pre
.doubles
.points
.map(negate
)
18133 Point
.prototype.toJ
= function toJ() {
18135 return this.curve
.jpoint(null, null, null);
18137 var res
= this.curve
.jpoint(this.x
, this.y
, this.curve
.one
);
18141 function JPoint(curve
, x
, y
, z
) {
18142 Base
.BasePoint
.call(this, curve
, 'jacobian');
18143 if (x
=== null && y
=== null && z
=== null) {
18144 this.x
= this.curve
.one
;
18145 this.y
= this.curve
.one
;
18146 this.z
= new BN(0);
18148 this.x
= new BN(x
, 16);
18149 this.y
= new BN(y
, 16);
18150 this.z
= new BN(z
, 16);
18153 this.x
= this.x
.toRed(this.curve
.red
);
18155 this.y
= this.y
.toRed(this.curve
.red
);
18157 this.z
= this.z
.toRed(this.curve
.red
);
18159 this.zOne
= this.z
=== this.curve
.one
;
18161 inherits(JPoint
, Base
.BasePoint
);
18163 ShortCurve
.prototype.jpoint
= function jpoint(x
, y
, z
) {
18164 return new JPoint(this, x
, y
, z
);
18167 JPoint
.prototype.toP
= function toP() {
18168 if (this.isInfinity())
18169 return this.curve
.point(null, null);
18171 var zinv
= this.z
.redInvm();
18172 var zinv2
= zinv
.redSqr();
18173 var ax
= this.x
.redMul(zinv2
);
18174 var ay
= this.y
.redMul(zinv2
).redMul(zinv
);
18176 return this.curve
.point(ax
, ay
);
18179 JPoint
.prototype.neg
= function neg() {
18180 return this.curve
.jpoint(this.x
, this.y
.redNeg(), this.z
);
18183 JPoint
.prototype.add
= function add(p
) {
18185 if (this.isInfinity())
18189 if (p
.isInfinity())
18193 var pz2
= p
.z
.redSqr();
18194 var z2
= this.z
.redSqr();
18195 var u1
= this.x
.redMul(pz2
);
18196 var u2
= p
.x
.redMul(z2
);
18197 var s1
= this.y
.redMul(pz2
.redMul(p
.z
));
18198 var s2
= p
.y
.redMul(z2
.redMul(this.z
));
18200 var h
= u1
.redSub(u2
);
18201 var r
= s1
.redSub(s2
);
18202 if (h
.cmpn(0) === 0) {
18203 if (r
.cmpn(0) !== 0)
18204 return this.curve
.jpoint(null, null, null);
18209 var h2
= h
.redSqr();
18210 var h3
= h2
.redMul(h
);
18211 var v
= u1
.redMul(h2
);
18213 var nx
= r
.redSqr().redIAdd(h3
).redISub(v
).redISub(v
);
18214 var ny
= r
.redMul(v
.redISub(nx
)).redISub(s1
.redMul(h3
));
18215 var nz
= this.z
.redMul(p
.z
).redMul(h
);
18217 return this.curve
.jpoint(nx
, ny
, nz
);
18220 JPoint
.prototype.mixedAdd
= function mixedAdd(p
) {
18222 if (this.isInfinity())
18226 if (p
.isInfinity())
18230 var z2
= this.z
.redSqr();
18232 var u2
= p
.x
.redMul(z2
);
18234 var s2
= p
.y
.redMul(z2
).redMul(this.z
);
18236 var h
= u1
.redSub(u2
);
18237 var r
= s1
.redSub(s2
);
18238 if (h
.cmpn(0) === 0) {
18239 if (r
.cmpn(0) !== 0)
18240 return this.curve
.jpoint(null, null, null);
18245 var h2
= h
.redSqr();
18246 var h3
= h2
.redMul(h
);
18247 var v
= u1
.redMul(h2
);
18249 var nx
= r
.redSqr().redIAdd(h3
).redISub(v
).redISub(v
);
18250 var ny
= r
.redMul(v
.redISub(nx
)).redISub(s1
.redMul(h3
));
18251 var nz
= this.z
.redMul(h
);
18253 return this.curve
.jpoint(nx
, ny
, nz
);
18256 JPoint
.prototype.dblp
= function dblp(pow
) {
18259 if (this.isInfinity())
18264 if (this.curve
.zeroA
|| this.curve
.threeA
) {
18266 for (var i
= 0; i
< pow
; i
++)
18271 // 1M + 2S + 1A + N * (4S + 5M + 8A)
18272 // N = 1 => 6M + 6S + 9A
18273 var a
= this.curve
.a
;
18274 var tinv
= this.curve
.tinv
;
18279 var jz4
= jz
.redSqr().redSqr();
18282 var jyd
= jy
.redAdd(jy
);
18283 for (var i
= 0; i
< pow
; i
++) {
18284 var jx2
= jx
.redSqr();
18285 var jyd2
= jyd
.redSqr();
18286 var jyd4
= jyd2
.redSqr();
18287 var c
= jx2
.redAdd(jx2
).redIAdd(jx2
).redIAdd(a
.redMul(jz4
));
18289 var t1
= jx
.redMul(jyd2
);
18290 var nx
= c
.redSqr().redISub(t1
.redAdd(t1
));
18291 var t2
= t1
.redISub(nx
);
18292 var dny
= c
.redMul(t2
);
18293 dny
= dny
.redIAdd(dny
).redISub(jyd4
);
18294 var nz
= jyd
.redMul(jz
);
18296 jz4
= jz4
.redMul(jyd4
);
18303 return this.curve
.jpoint(jx
, jyd
.redMul(tinv
), jz
);
18306 JPoint
.prototype.dbl
= function dbl() {
18307 if (this.isInfinity())
18310 if (this.curve
.zeroA
)
18311 return this._zeroDbl();
18312 else if (this.curve
.threeA
)
18313 return this._threeDbl();
18315 return this._dbl();
18318 JPoint
.prototype._zeroDbl
= function _zeroDbl() {
18324 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
18325 // #doubling-mdbl-2007-bl
18329 var xx
= this.x
.redSqr();
18331 var yy
= this.y
.redSqr();
18333 var yyyy
= yy
.redSqr();
18334 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
18335 var s
= this.x
.redAdd(yy
).redSqr().redISub(xx
).redISub(yyyy
);
18337 // M = 3 * XX + a; a = 0
18338 var m
= xx
.redAdd(xx
).redIAdd(xx
);
18340 var t
= m
.redSqr().redISub(s
).redISub(s
);
18343 var yyyy8
= yyyy
.redIAdd(yyyy
);
18344 yyyy8
= yyyy8
.redIAdd(yyyy8
);
18345 yyyy8
= yyyy8
.redIAdd(yyyy8
);
18349 // Y3 = M * (S - T) - 8 * YYYY
18350 ny
= m
.redMul(s
.redISub(t
)).redISub(yyyy8
);
18352 nz
= this.y
.redAdd(this.y
);
18354 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
18355 // #doubling-dbl-2009-l
18359 var a
= this.x
.redSqr();
18361 var b
= this.y
.redSqr();
18363 var c
= b
.redSqr();
18364 // D = 2 * ((X1 + B)^2 - A - C)
18365 var d
= this.x
.redAdd(b
).redSqr().redISub(a
).redISub(c
);
18368 var e
= a
.redAdd(a
).redIAdd(a
);
18370 var f
= e
.redSqr();
18373 var c8
= c
.redIAdd(c
);
18374 c8
= c8
.redIAdd(c8
);
18375 c8
= c8
.redIAdd(c8
);
18378 nx
= f
.redISub(d
).redISub(d
);
18379 // Y3 = E * (D - X3) - 8 * C
18380 ny
= e
.redMul(d
.redISub(nx
)).redISub(c8
);
18381 // Z3 = 2 * Y1 * Z1
18382 nz
= this.y
.redMul(this.z
);
18383 nz
= nz
.redIAdd(nz
);
18386 return this.curve
.jpoint(nx
, ny
, nz
);
18389 JPoint
.prototype._threeDbl
= function _threeDbl() {
18395 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
18396 // #doubling-mdbl-2007-bl
18400 var xx
= this.x
.redSqr();
18402 var yy
= this.y
.redSqr();
18404 var yyyy
= yy
.redSqr();
18405 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
18406 var s
= this.x
.redAdd(yy
).redSqr().redISub(xx
).redISub(yyyy
);
18409 var m
= xx
.redAdd(xx
).redIAdd(xx
).redIAdd(this.curve
.a
);
18411 var t
= m
.redSqr().redISub(s
).redISub(s
);
18414 // Y3 = M * (S - T) - 8 * YYYY
18415 var yyyy8
= yyyy
.redIAdd(yyyy
);
18416 yyyy8
= yyyy8
.redIAdd(yyyy8
);
18417 yyyy8
= yyyy8
.redIAdd(yyyy8
);
18418 ny
= m
.redMul(s
.redISub(t
)).redISub(yyyy8
);
18420 nz
= this.y
.redAdd(this.y
);
18422 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
18426 var delta
= this.z
.redSqr();
18428 var gamma
= this.y
.redSqr();
18429 // beta = X1 * gamma
18430 var beta
= this.x
.redMul(gamma
);
18431 // alpha = 3 * (X1 - delta) * (X1 + delta)
18432 var alpha
= this.x
.redSub(delta
).redMul(this.x
.redAdd(delta
));
18433 alpha
= alpha
.redAdd(alpha
).redIAdd(alpha
);
18434 // X3 = alpha^2 - 8 * beta
18435 var beta4
= beta
.redIAdd(beta
);
18436 beta4
= beta4
.redIAdd(beta4
);
18437 var beta8
= beta4
.redAdd(beta4
);
18438 nx
= alpha
.redSqr().redISub(beta8
);
18439 // Z3 = (Y1 + Z1)^2 - gamma - delta
18440 nz
= this.y
.redAdd(this.z
).redSqr().redISub(gamma
).redISub(delta
);
18441 // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
18442 var ggamma8
= gamma
.redSqr();
18443 ggamma8
= ggamma8
.redIAdd(ggamma8
);
18444 ggamma8
= ggamma8
.redIAdd(ggamma8
);
18445 ggamma8
= ggamma8
.redIAdd(ggamma8
);
18446 ny
= alpha
.redMul(beta4
.redISub(nx
)).redISub(ggamma8
);
18449 return this.curve
.jpoint(nx
, ny
, nz
);
18452 JPoint
.prototype._dbl
= function _dbl() {
18453 var a
= this.curve
.a
;
18459 var jz4
= jz
.redSqr().redSqr();
18461 var jx2
= jx
.redSqr();
18462 var jy2
= jy
.redSqr();
18464 var c
= jx2
.redAdd(jx2
).redIAdd(jx2
).redIAdd(a
.redMul(jz4
));
18466 var jxd4
= jx
.redAdd(jx
);
18467 jxd4
= jxd4
.redIAdd(jxd4
);
18468 var t1
= jxd4
.redMul(jy2
);
18469 var nx
= c
.redSqr().redISub(t1
.redAdd(t1
));
18470 var t2
= t1
.redISub(nx
);
18472 var jyd8
= jy2
.redSqr();
18473 jyd8
= jyd8
.redIAdd(jyd8
);
18474 jyd8
= jyd8
.redIAdd(jyd8
);
18475 jyd8
= jyd8
.redIAdd(jyd8
);
18476 var ny
= c
.redMul(t2
).redISub(jyd8
);
18477 var nz
= jy
.redAdd(jy
).redMul(jz
);
18479 return this.curve
.jpoint(nx
, ny
, nz
);
18482 JPoint
.prototype.trpl
= function trpl() {
18483 if (!this.curve
.zeroA
)
18484 return this.dbl().add(this);
18486 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
18490 var xx
= this.x
.redSqr();
18492 var yy
= this.y
.redSqr();
18494 var zz
= this.z
.redSqr();
18496 var yyyy
= yy
.redSqr();
18497 // M = 3 * XX + a * ZZ2; a = 0
18498 var m
= xx
.redAdd(xx
).redIAdd(xx
);
18500 var mm
= m
.redSqr();
18501 // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
18502 var e
= this.x
.redAdd(yy
).redSqr().redISub(xx
).redISub(yyyy
);
18504 e
= e
.redAdd(e
).redIAdd(e
);
18507 var ee
= e
.redSqr();
18509 var t
= yyyy
.redIAdd(yyyy
);
18513 // U = (M + E)^2 - MM - EE - T
18514 var u
= m
.redIAdd(e
).redSqr().redISub(mm
).redISub(ee
).redISub(t
);
18515 // X3 = 4 * (X1 * EE - 4 * YY * U)
18516 var yyu4
= yy
.redMul(u
);
18517 yyu4
= yyu4
.redIAdd(yyu4
);
18518 yyu4
= yyu4
.redIAdd(yyu4
);
18519 var nx
= this.x
.redMul(ee
).redISub(yyu4
);
18520 nx
= nx
.redIAdd(nx
);
18521 nx
= nx
.redIAdd(nx
);
18522 // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
18523 var ny
= this.y
.redMul(u
.redMul(t
.redISub(u
)).redISub(e
.redMul(ee
)));
18524 ny
= ny
.redIAdd(ny
);
18525 ny
= ny
.redIAdd(ny
);
18526 ny
= ny
.redIAdd(ny
);
18527 // Z3 = (Z1 + E)^2 - ZZ - EE
18528 var nz
= this.z
.redAdd(e
).redSqr().redISub(zz
).redISub(ee
);
18530 return this.curve
.jpoint(nx
, ny
, nz
);
18533 JPoint
.prototype.mul
= function mul(k
, kbase
) {
18534 k
= new BN(k
, kbase
);
18536 return this.curve
._wnafMul(this, k
);
18539 JPoint
.prototype.eq
= function eq(p
) {
18540 if (p
.type
=== 'affine')
18541 return this.eq(p
.toJ());
18546 // x1 * z2^2 == x2 * z1^2
18547 var z2
= this.z
.redSqr();
18548 var pz2
= p
.z
.redSqr();
18549 if (this.x
.redMul(pz2
).redISub(p
.x
.redMul(z2
)).cmpn(0) !== 0)
18552 // y1 * z2^3 == y2 * z1^3
18553 var z3
= z2
.redMul(this.z
);
18554 var pz3
= pz2
.redMul(p
.z
);
18555 return this.y
.redMul(pz3
).redISub(p
.y
.redMul(z3
)).cmpn(0) === 0;
18558 JPoint
.prototype.eqXToP
= function eqXToP(x
) {
18559 var zs
= this.z
.redSqr();
18560 var rx
= x
.toRed(this.curve
.red
).redMul(zs
);
18561 if (this.x
.cmp(rx
) === 0)
18564 var xc
= x
.clone();
18565 var t
= this.curve
.redN
.redMul(zs
);
18567 xc
.iadd(this.curve
.n
);
18568 if (xc
.cmp(this.curve
.p
) >= 0)
18572 if (this.x
.cmp(rx
) === 0)
18578 JPoint
.prototype.inspect
= function inspect() {
18579 if (this.isInfinity())
18580 return '<EC JPoint Infinity>';
18581 return '<EC JPoint x: ' + this.x
.toString(16, 2) +
18582 ' y: ' + this.y
.toString(16, 2) +
18583 ' z: ' + this.z
.toString(16, 2) + '>';
18586 JPoint
.prototype.isInfinity
= function isInfinity() {
18587 // XXX This code assumes that zero is always zero in red
18588 return this.z
.cmpn(0) === 0;
18591 },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],103:[function(require
,module
,exports
){
18594 var curves
= exports
;
18596 var hash
= require('hash.js');
18597 var elliptic
= require('../elliptic');
18599 var assert
= elliptic
.utils
.assert
;
18601 function PresetCurve(options
) {
18602 if (options
.type
=== 'short')
18603 this.curve
= new elliptic
.curve
.short(options
);
18604 else if (options
.type
=== 'edwards')
18605 this.curve
= new elliptic
.curve
.edwards(options
);
18607 this.curve
= new elliptic
.curve
.mont(options
);
18608 this.g
= this.curve
.g
;
18609 this.n
= this.curve
.n
;
18610 this.hash
= options
.hash
;
18612 assert(this.g
.validate(), 'Invalid curve');
18613 assert(this.g
.mul(this.n
).isInfinity(), 'Invalid curve, G*N != O');
18615 curves
.PresetCurve
= PresetCurve
;
18617 function defineCurve(name
, options
) {
18618 Object
.defineProperty(curves
, name
, {
18619 configurable: true,
18622 var curve
= new PresetCurve(options
);
18623 Object
.defineProperty(curves
, name
, {
18624 configurable: true,
18633 defineCurve('p192', {
18636 p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
18637 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
18638 b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
18639 n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
18643 '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
18644 '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
18648 defineCurve('p224', {
18651 p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
18652 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
18653 b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
18654 n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
18658 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
18659 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
18663 defineCurve('p256', {
18666 p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
18667 a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
18668 b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
18669 n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
18673 '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
18674 '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
18678 defineCurve('p384', {
18681 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18682 'fffffffe ffffffff 00000000 00000000 ffffffff',
18683 a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18684 'fffffffe ffffffff 00000000 00000000 fffffffc',
18685 b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
18686 '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
18687 n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
18688 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
18692 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
18693 '5502f25d bf55296c 3a545e38 72760ab7',
18694 '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
18695 '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
18699 defineCurve('p521', {
18702 p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18703 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18704 'ffffffff ffffffff ffffffff ffffffff ffffffff',
18705 a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18706 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18707 'ffffffff ffffffff ffffffff ffffffff fffffffc',
18708 b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
18709 '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
18710 '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
18711 n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
18712 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
18713 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
18717 '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
18718 '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
18719 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
18720 '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
18721 '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
18722 '3fad0761 353c7086 a272c240 88be9476 9fd16650'
18726 defineCurve('curve25519', {
18729 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
18732 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
18740 defineCurve('ed25519', {
18743 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
18746 // -121665 * (121666^(-1)) (mod P)
18747 d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
18748 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
18752 '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
18755 '6666666666666666666666666666666666666666666666666666666666666658'
18761 pre
= require('./precomputed/secp256k1');
18766 defineCurve('secp256k1', {
18769 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
18772 n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
18776 // Precomputed endomorphism
18777 beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
18778 lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
18781 a: '3086d221a7d46bcde86c90e49284eb15',
18782 b: '-e4437ed6010e88286f547fa90abfe4c3'
18785 a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
18786 b: '3086d221a7d46bcde86c90e49284eb15'
18792 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
18793 '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
18798 },{"../elliptic":97,"./precomputed/secp256k1":110,"hash.js":114}],104:[function(require
,module
,exports
){
18801 var BN
= require('bn.js');
18802 var HmacDRBG
= require('hmac-drbg');
18803 var elliptic
= require('../../elliptic');
18804 var utils
= elliptic
.utils
;
18805 var assert
= utils
.assert
;
18807 var KeyPair
= require('./key');
18808 var Signature
= require('./signature');
18810 function EC(options
) {
18811 if (!(this instanceof EC
))
18812 return new EC(options
);
18814 // Shortcut `elliptic.ec(curve-name)`
18815 if (typeof options
=== 'string') {
18816 assert(elliptic
.curves
.hasOwnProperty(options
), 'Unknown curve ' + options
);
18818 options
= elliptic
.curves
[options
];
18821 // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
18822 if (options
instanceof elliptic
.curves
.PresetCurve
)
18823 options
= { curve: options
};
18825 this.curve
= options
.curve
.curve
;
18826 this.n
= this.curve
.n
;
18827 this.nh
= this.n
.ushrn(1);
18828 this.g
= this.curve
.g
;
18831 this.g
= options
.curve
.g
;
18832 this.g
.precompute(options
.curve
.n
.bitLength() + 1);
18834 // Hash for function for DRBG
18835 this.hash
= options
.hash
|| options
.curve
.hash
;
18837 module
.exports
= EC
;
18839 EC
.prototype.keyPair
= function keyPair(options
) {
18840 return new KeyPair(this, options
);
18843 EC
.prototype.keyFromPrivate
= function keyFromPrivate(priv
, enc
) {
18844 return KeyPair
.fromPrivate(this, priv
, enc
);
18847 EC
.prototype.keyFromPublic
= function keyFromPublic(pub
, enc
) {
18848 return KeyPair
.fromPublic(this, pub
, enc
);
18851 EC
.prototype.genKeyPair
= function genKeyPair(options
) {
18855 // Instantiate Hmac_DRBG
18856 var drbg
= new HmacDRBG({
18858 pers: options
.pers
,
18859 persEnc: options
.persEnc
|| 'utf8',
18860 entropy: options
.entropy
|| elliptic
.rand(this.hash
.hmacStrength
),
18861 entropyEnc: options
.entropy
&& options
.entropyEnc
|| 'utf8',
18862 nonce: this.n
.toArray()
18865 var bytes
= this.n
.byteLength();
18866 var ns2
= this.n
.sub(new BN(2));
18868 var priv
= new BN(drbg
.generate(bytes
));
18869 if (priv
.cmp(ns2
) > 0)
18873 return this.keyFromPrivate(priv
);
18877 EC
.prototype._truncateToN
= function truncateToN(msg
, truncOnly
) {
18878 var delta
= msg
.byteLength() * 8 - this.n
.bitLength();
18880 msg
= msg
.ushrn(delta
);
18881 if (!truncOnly
&& msg
.cmp(this.n
) >= 0)
18882 return msg
.sub(this.n
);
18887 EC
.prototype.sign
= function sign(msg
, key
, enc
, options
) {
18888 if (typeof enc
=== 'object') {
18895 key
= this.keyFromPrivate(key
, enc
);
18896 msg
= this._truncateToN(new BN(msg
, 16));
18898 // Zero-extend key to provide enough entropy
18899 var bytes
= this.n
.byteLength();
18900 var bkey
= key
.getPrivate().toArray('be', bytes
);
18902 // Zero-extend nonce to have the same byte size as N
18903 var nonce
= msg
.toArray('be', bytes
);
18905 // Instantiate Hmac_DRBG
18906 var drbg
= new HmacDRBG({
18910 pers: options
.pers
,
18911 persEnc: options
.persEnc
|| 'utf8'
18914 // Number of bytes to generate
18915 var ns1
= this.n
.sub(new BN(1));
18917 for (var iter
= 0; true; iter
++) {
18918 var k
= options
.k
?
18920 new BN(drbg
.generate(this.n
.byteLength()));
18921 k
= this._truncateToN(k
, true);
18922 if (k
.cmpn(1) <= 0 || k
.cmp(ns1
) >= 0)
18925 var kp
= this.g
.mul(k
);
18926 if (kp
.isInfinity())
18929 var kpX
= kp
.getX();
18930 var r
= kpX
.umod(this.n
);
18931 if (r
.cmpn(0) === 0)
18934 var s
= k
.invm(this.n
).mul(r
.mul(key
.getPrivate()).iadd(msg
));
18935 s
= s
.umod(this.n
);
18936 if (s
.cmpn(0) === 0)
18939 var recoveryParam
= (kp
.getY().isOdd() ? 1 : 0) |
18940 (kpX
.cmp(r
) !== 0 ? 2 : 0);
18942 // Use complement of `s`, if it is > `n / 2`
18943 if (options
.canonical
&& s
.cmp(this.nh
) > 0) {
18945 recoveryParam
^= 1;
18948 return new Signature({ r: r
, s: s
, recoveryParam: recoveryParam
});
18952 EC
.prototype.verify
= function verify(msg
, signature
, key
, enc
) {
18953 msg
= this._truncateToN(new BN(msg
, 16));
18954 key
= this.keyFromPublic(key
, enc
);
18955 signature
= new Signature(signature
, 'hex');
18957 // Perform primitive values validation
18958 var r
= signature
.r
;
18959 var s
= signature
.s
;
18960 if (r
.cmpn(1) < 0 || r
.cmp(this.n
) >= 0)
18962 if (s
.cmpn(1) < 0 || s
.cmp(this.n
) >= 0)
18965 // Validate signature
18966 var sinv
= s
.invm(this.n
);
18967 var u1
= sinv
.mul(msg
).umod(this.n
);
18968 var u2
= sinv
.mul(r
).umod(this.n
);
18970 if (!this.curve
._maxwellTrick
) {
18971 var p
= this.g
.mulAdd(u1
, key
.getPublic(), u2
);
18972 if (p
.isInfinity())
18975 return p
.getX().umod(this.n
).cmp(r
) === 0;
18978 // NOTE: Greg Maxwell's trick, inspired by:
18979 // https://git.io/vad3K
18981 var p
= this.g
.jmulAdd(u1
, key
.getPublic(), u2
);
18982 if (p
.isInfinity())
18985 // Compare `p.x` of Jacobian point with `r`,
18986 // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
18987 // inverse of `p.z^2`
18988 return p
.eqXToP(r
);
18991 EC
.prototype.recoverPubKey = function(msg
, signature
, j
, enc
) {
18992 assert((3 & j
) === j
, 'The recovery param is more than two bits');
18993 signature
= new Signature(signature
, enc
);
18996 var e
= new BN(msg
);
18997 var r
= signature
.r
;
18998 var s
= signature
.s
;
19000 // A set LSB signifies that the y-coordinate is odd
19001 var isYOdd
= j
& 1;
19002 var isSecondKey
= j
>> 1;
19003 if (r
.cmp(this.curve
.p
.umod(this.curve
.n
)) >= 0 && isSecondKey
)
19004 throw new Error('Unable to find sencond key candinate');
19006 // 1.1. Let x = r + jn.
19008 r
= this.curve
.pointFromX(r
.add(this.curve
.n
), isYOdd
);
19010 r
= this.curve
.pointFromX(r
, isYOdd
);
19012 var rInv
= signature
.r
.invm(n
);
19013 var s1
= n
.sub(e
).mul(rInv
).umod(n
);
19014 var s2
= s
.mul(rInv
).umod(n
);
19016 // 1.6.1 Compute Q = r^-1 (sR - eG)
19017 // Q = r^-1 (sR + -eG)
19018 return this.g
.mulAdd(s1
, r
, s2
);
19021 EC
.prototype.getKeyRecoveryParam = function(e
, signature
, Q
, enc
) {
19022 signature
= new Signature(signature
, enc
);
19023 if (signature
.recoveryParam
!== null)
19024 return signature
.recoveryParam
;
19026 for (var i
= 0; i
< 4; i
++) {
19029 Qprime
= this.recoverPubKey(e
, signature
, i
);
19037 throw new Error('Unable to find valid recovery factor');
19040 },{"../../elliptic":97,"./key":105,"./signature":106,"bn.js":81,"hmac-drbg":120}],105:[function(require
,module
,exports
){
19043 var BN
= require('bn.js');
19044 var elliptic
= require('../../elliptic');
19045 var utils
= elliptic
.utils
;
19046 var assert
= utils
.assert
;
19048 function KeyPair(ec
, options
) {
19053 // KeyPair(ec, { priv: ..., pub: ... })
19055 this._importPrivate(options
.priv
, options
.privEnc
);
19057 this._importPublic(options
.pub
, options
.pubEnc
);
19059 module
.exports
= KeyPair
;
19061 KeyPair
.fromPublic
= function fromPublic(ec
, pub
, enc
) {
19062 if (pub
instanceof KeyPair
)
19065 return new KeyPair(ec
, {
19071 KeyPair
.fromPrivate
= function fromPrivate(ec
, priv
, enc
) {
19072 if (priv
instanceof KeyPair
)
19075 return new KeyPair(ec
, {
19081 KeyPair
.prototype.validate
= function validate() {
19082 var pub
= this.getPublic();
19084 if (pub
.isInfinity())
19085 return { result: false, reason: 'Invalid public key' };
19086 if (!pub
.validate())
19087 return { result: false, reason: 'Public key is not a point' };
19088 if (!pub
.mul(this.ec
.curve
.n
).isInfinity())
19089 return { result: false, reason: 'Public key * N != O' };
19091 return { result: true, reason: null };
19094 KeyPair
.prototype.getPublic
= function getPublic(compact
, enc
) {
19095 // compact is optional argument
19096 if (typeof compact
=== 'string') {
19102 this.pub
= this.ec
.g
.mul(this.priv
);
19107 return this.pub
.encode(enc
, compact
);
19110 KeyPair
.prototype.getPrivate
= function getPrivate(enc
) {
19112 return this.priv
.toString(16, 2);
19117 KeyPair
.prototype._importPrivate
= function _importPrivate(key
, enc
) {
19118 this.priv
= new BN(key
, enc
|| 16);
19120 // Ensure that the priv won't be bigger than n, otherwise we may fail
19121 // in fixed multiplication method
19122 this.priv
= this.priv
.umod(this.ec
.curve
.n
);
19125 KeyPair
.prototype._importPublic
= function _importPublic(key
, enc
) {
19126 if (key
.x
|| key
.y
) {
19127 // Montgomery points only have an `x` coordinate.
19128 // Weierstrass/Edwards points on the other hand have both `x` and
19129 // `y` coordinates.
19130 if (this.ec
.curve
.type
=== 'mont') {
19131 assert(key
.x
, 'Need x coordinate');
19132 } else if (this.ec
.curve
.type
=== 'short' ||
19133 this.ec
.curve
.type
=== 'edwards') {
19134 assert(key
.x
&& key
.y
, 'Need both x and y coordinate');
19136 this.pub
= this.ec
.curve
.point(key
.x
, key
.y
);
19139 this.pub
= this.ec
.curve
.decodePoint(key
, enc
);
19143 KeyPair
.prototype.derive
= function derive(pub
) {
19144 return pub
.mul(this.priv
).getX();
19148 KeyPair
.prototype.sign
= function sign(msg
, enc
, options
) {
19149 return this.ec
.sign(msg
, this, enc
, options
);
19152 KeyPair
.prototype.verify
= function verify(msg
, signature
) {
19153 return this.ec
.verify(msg
, signature
, this);
19156 KeyPair
.prototype.inspect
= function inspect() {
19157 return '<Key priv: ' + (this.priv
&& this.priv
.toString(16, 2)) +
19158 ' pub: ' + (this.pub
&& this.pub
.inspect()) + ' >';
19161 },{"../../elliptic":97,"bn.js":81}],106:[function(require
,module
,exports
){
19164 var BN
= require('bn.js');
19166 var elliptic
= require('../../elliptic');
19167 var utils
= elliptic
.utils
;
19168 var assert
= utils
.assert
;
19170 function Signature(options
, enc
) {
19171 if (options
instanceof Signature
)
19174 if (this._importDER(options
, enc
))
19177 assert(options
.r
&& options
.s
, 'Signature without r or s');
19178 this.r
= new BN(options
.r
, 16);
19179 this.s
= new BN(options
.s
, 16);
19180 if (options
.recoveryParam
=== undefined)
19181 this.recoveryParam
= null;
19183 this.recoveryParam
= options
.recoveryParam
;
19185 module
.exports
= Signature
;
19187 function Position() {
19191 function getLength(buf
, p
) {
19192 var initial
= buf
[p
.place
++];
19193 if (!(initial
& 0x80)) {
19196 var octetLen
= initial
& 0xf;
19198 for (var i
= 0, off
= p
.place
; i
< octetLen
; i
++, off
++) {
19206 function rmPadding(buf
) {
19208 var len
= buf
.length
- 1;
19209 while (!buf
[i
] && !(buf
[i
+ 1] & 0x80) && i
< len
) {
19215 return buf
.slice(i
);
19218 Signature
.prototype._importDER
= function _importDER(data
, enc
) {
19219 data
= utils
.toArray(data
, enc
);
19220 var p
= new Position();
19221 if (data
[p
.place
++] !== 0x30) {
19224 var len
= getLength(data
, p
);
19225 if ((len
+ p
.place
) !== data
.length
) {
19228 if (data
[p
.place
++] !== 0x02) {
19231 var rlen
= getLength(data
, p
);
19232 var r
= data
.slice(p
.place
, rlen
+ p
.place
);
19234 if (data
[p
.place
++] !== 0x02) {
19237 var slen
= getLength(data
, p
);
19238 if (data
.length
!== slen
+ p
.place
) {
19241 var s
= data
.slice(p
.place
, slen
+ p
.place
);
19242 if (r
[0] === 0 && (r
[1] & 0x80)) {
19245 if (s
[0] === 0 && (s
[1] & 0x80)) {
19249 this.r
= new BN(r
);
19250 this.s
= new BN(s
);
19251 this.recoveryParam
= null;
19256 function constructLength(arr
, len
) {
19261 var octets
= 1 + (Math
.log(len
) / Math
.LN2
>>> 3);
19262 arr
.push(octets
| 0x80);
19264 arr
.push((len
>>> (octets
<< 3)) & 0xff);
19269 Signature
.prototype.toDER
= function toDER(enc
) {
19270 var r
= this.r
.toArray();
19271 var s
= this.s
.toArray();
19275 r
= [ 0 ].concat(r
);
19278 s
= [ 0 ].concat(s
);
19283 while (!s
[0] && !(s
[1] & 0x80)) {
19286 var arr
= [ 0x02 ];
19287 constructLength(arr
, r
.length
);
19288 arr
= arr
.concat(r
);
19290 constructLength(arr
, s
.length
);
19291 var backHalf
= arr
.concat(s
);
19292 var res
= [ 0x30 ];
19293 constructLength(res
, backHalf
.length
);
19294 res
= res
.concat(backHalf
);
19295 return utils
.encode(res
, enc
);
19298 },{"../../elliptic":97,"bn.js":81}],107:[function(require
,module
,exports
){
19301 var hash
= require('hash.js');
19302 var elliptic
= require('../../elliptic');
19303 var utils
= elliptic
.utils
;
19304 var assert
= utils
.assert
;
19305 var parseBytes
= utils
.parseBytes
;
19306 var KeyPair
= require('./key');
19307 var Signature
= require('./signature');
19309 function EDDSA(curve
) {
19310 assert(curve
=== 'ed25519', 'only tested with ed25519 so far');
19312 if (!(this instanceof EDDSA
))
19313 return new EDDSA(curve
);
19315 var curve
= elliptic
.curves
[curve
].curve
;
19316 this.curve
= curve
;
19318 this.g
.precompute(curve
.n
.bitLength() + 1);
19320 this.pointClass
= curve
.point().constructor;
19321 this.encodingLength
= Math
.ceil(curve
.n
.bitLength() / 8);
19322 this.hash
= hash
.sha512
;
19325 module
.exports
= EDDSA
;
19328 * @param {Array|String} message - message bytes
19329 * @param {Array|String|KeyPair} secret - secret bytes or a keypair
19330 * @returns {Signature} - signature
19332 EDDSA
.prototype.sign
= function sign(message
, secret
) {
19333 message
= parseBytes(message
);
19334 var key
= this.keyFromSecret(secret
);
19335 var r
= this.hashInt(key
.messagePrefix(), message
);
19336 var R
= this.g
.mul(r
);
19337 var Rencoded
= this.encodePoint(R
);
19338 var s_
= this.hashInt(Rencoded
, key
.pubBytes(), message
)
19340 var S
= r
.add(s_
).umod(this.curve
.n
);
19341 return this.makeSignature({ R: R
, S: S
, Rencoded: Rencoded
});
19345 * @param {Array} message - message bytes
19346 * @param {Array|String|Signature} sig - sig bytes
19347 * @param {Array|String|Point|KeyPair} pub - public key
19348 * @returns {Boolean} - true if public key matches sig of message
19350 EDDSA
.prototype.verify
= function verify(message
, sig
, pub
) {
19351 message
= parseBytes(message
);
19352 sig
= this.makeSignature(sig
);
19353 var key
= this.keyFromPublic(pub
);
19354 var h
= this.hashInt(sig
.Rencoded(), key
.pubBytes(), message
);
19355 var SG
= this.g
.mul(sig
.S());
19356 var RplusAh
= sig
.R().add(key
.pub().mul(h
));
19357 return RplusAh
.eq(SG
);
19360 EDDSA
.prototype.hashInt
= function hashInt() {
19361 var hash
= this.hash();
19362 for (var i
= 0; i
< arguments
.length
; i
++)
19363 hash
.update(arguments
[i
]);
19364 return utils
.intFromLE(hash
.digest()).umod(this.curve
.n
);
19367 EDDSA
.prototype.keyFromPublic
= function keyFromPublic(pub
) {
19368 return KeyPair
.fromPublic(this, pub
);
19371 EDDSA
.prototype.keyFromSecret
= function keyFromSecret(secret
) {
19372 return KeyPair
.fromSecret(this, secret
);
19375 EDDSA
.prototype.makeSignature
= function makeSignature(sig
) {
19376 if (sig
instanceof Signature
)
19378 return new Signature(this, sig
);
19382 * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
19384 * EDDSA defines methods for encoding and decoding points and integers. These are
19385 * helper convenience methods, that pass along to utility functions implied
19389 EDDSA
.prototype.encodePoint
= function encodePoint(point
) {
19390 var enc
= point
.getY().toArray('le', this.encodingLength
);
19391 enc
[this.encodingLength
- 1] |= point
.getX().isOdd() ? 0x80 : 0;
19395 EDDSA
.prototype.decodePoint
= function decodePoint(bytes
) {
19396 bytes
= utils
.parseBytes(bytes
);
19398 var lastIx
= bytes
.length
- 1;
19399 var normed
= bytes
.slice(0, lastIx
).concat(bytes
[lastIx
] & ~0x80);
19400 var xIsOdd
= (bytes
[lastIx
] & 0x80) !== 0;
19402 var y
= utils
.intFromLE(normed
);
19403 return this.curve
.pointFromY(y
, xIsOdd
);
19406 EDDSA
.prototype.encodeInt
= function encodeInt(num
) {
19407 return num
.toArray('le', this.encodingLength
);
19410 EDDSA
.prototype.decodeInt
= function decodeInt(bytes
) {
19411 return utils
.intFromLE(bytes
);
19414 EDDSA
.prototype.isPoint
= function isPoint(val
) {
19415 return val
instanceof this.pointClass
;
19418 },{"../../elliptic":97,"./key":108,"./signature":109,"hash.js":114}],108:[function(require
,module
,exports
){
19421 var elliptic
= require('../../elliptic');
19422 var utils
= elliptic
.utils
;
19423 var assert
= utils
.assert
;
19424 var parseBytes
= utils
.parseBytes
;
19425 var cachedProperty
= utils
.cachedProperty
;
19428 * @param {EDDSA} eddsa - instance
19429 * @param {Object} params - public/private key parameters
19431 * @param {Array<Byte>} [params.secret] - secret seed bytes
19432 * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
19433 * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
19436 function KeyPair(eddsa
, params
) {
19437 this.eddsa
= eddsa
;
19438 this._secret
= parseBytes(params
.secret
);
19439 if (eddsa
.isPoint(params
.pub
))
19440 this._pub
= params
.pub
;
19442 this._pubBytes
= parseBytes(params
.pub
);
19445 KeyPair
.fromPublic
= function fromPublic(eddsa
, pub
) {
19446 if (pub
instanceof KeyPair
)
19448 return new KeyPair(eddsa
, { pub: pub
});
19451 KeyPair
.fromSecret
= function fromSecret(eddsa
, secret
) {
19452 if (secret
instanceof KeyPair
)
19454 return new KeyPair(eddsa
, { secret: secret
});
19457 KeyPair
.prototype.secret
= function secret() {
19458 return this._secret
;
19461 cachedProperty(KeyPair
, 'pubBytes', function pubBytes() {
19462 return this.eddsa
.encodePoint(this.pub());
19465 cachedProperty(KeyPair
, 'pub', function pub() {
19466 if (this._pubBytes
)
19467 return this.eddsa
.decodePoint(this._pubBytes
);
19468 return this.eddsa
.g
.mul(this.priv());
19471 cachedProperty(KeyPair
, 'privBytes', function privBytes() {
19472 var eddsa
= this.eddsa
;
19473 var hash
= this.hash();
19474 var lastIx
= eddsa
.encodingLength
- 1;
19476 var a
= hash
.slice(0, eddsa
.encodingLength
);
19484 cachedProperty(KeyPair
, 'priv', function priv() {
19485 return this.eddsa
.decodeInt(this.privBytes());
19488 cachedProperty(KeyPair
, 'hash', function hash() {
19489 return this.eddsa
.hash().update(this.secret()).digest();
19492 cachedProperty(KeyPair
, 'messagePrefix', function messagePrefix() {
19493 return this.hash().slice(this.eddsa
.encodingLength
);
19496 KeyPair
.prototype.sign
= function sign(message
) {
19497 assert(this._secret
, 'KeyPair can only verify');
19498 return this.eddsa
.sign(message
, this);
19501 KeyPair
.prototype.verify
= function verify(message
, sig
) {
19502 return this.eddsa
.verify(message
, sig
, this);
19505 KeyPair
.prototype.getSecret
= function getSecret(enc
) {
19506 assert(this._secret
, 'KeyPair is public only');
19507 return utils
.encode(this.secret(), enc
);
19510 KeyPair
.prototype.getPublic
= function getPublic(enc
) {
19511 return utils
.encode(this.pubBytes(), enc
);
19514 module
.exports
= KeyPair
;
19516 },{"../../elliptic":97}],109:[function(require
,module
,exports
){
19519 var BN
= require('bn.js');
19520 var elliptic
= require('../../elliptic');
19521 var utils
= elliptic
.utils
;
19522 var assert
= utils
.assert
;
19523 var cachedProperty
= utils
.cachedProperty
;
19524 var parseBytes
= utils
.parseBytes
;
19527 * @param {EDDSA} eddsa - eddsa instance
19528 * @param {Array<Bytes>|Object} sig -
19529 * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
19530 * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
19531 * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
19532 * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
19534 function Signature(eddsa
, sig
) {
19535 this.eddsa
= eddsa
;
19537 if (typeof sig
!== 'object')
19538 sig
= parseBytes(sig
);
19540 if (Array
.isArray(sig
)) {
19542 R: sig
.slice(0, eddsa
.encodingLength
),
19543 S: sig
.slice(eddsa
.encodingLength
)
19547 assert(sig
.R
&& sig
.S
, 'Signature without R or S');
19549 if (eddsa
.isPoint(sig
.R
))
19551 if (sig
.S
instanceof BN
)
19554 this._Rencoded
= Array
.isArray(sig
.R
) ? sig
.R : sig
.Rencoded
;
19555 this._Sencoded
= Array
.isArray(sig
.S
) ? sig
.S : sig
.Sencoded
;
19558 cachedProperty(Signature
, 'S', function S() {
19559 return this.eddsa
.decodeInt(this.Sencoded());
19562 cachedProperty(Signature
, 'R', function R() {
19563 return this.eddsa
.decodePoint(this.Rencoded());
19566 cachedProperty(Signature
, 'Rencoded', function Rencoded() {
19567 return this.eddsa
.encodePoint(this.R());
19570 cachedProperty(Signature
, 'Sencoded', function Sencoded() {
19571 return this.eddsa
.encodeInt(this.S());
19574 Signature
.prototype.toBytes
= function toBytes() {
19575 return this.Rencoded().concat(this.Sencoded());
19578 Signature
.prototype.toHex
= function toHex() {
19579 return utils
.encode(this.toBytes(), 'hex').toUpperCase();
19582 module
.exports
= Signature
;
19584 },{"../../elliptic":97,"bn.js":81}],110:[function(require
,module
,exports
){
19590 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
19591 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
19594 '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
19595 '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
19598 '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
19599 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
19602 '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
19603 '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
19606 '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
19607 '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
19610 '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
19611 '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
19614 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
19615 '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
19618 '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
19619 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
19622 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
19623 '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
19626 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
19627 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
19630 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
19631 '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
19634 '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
19635 '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
19638 '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
19639 '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
19642 '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
19643 '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
19646 '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
19647 '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
19650 '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
19651 '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
19654 '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
19655 '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
19658 '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
19659 '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
19662 '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
19663 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
19666 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
19667 '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
19670 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
19671 '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
19674 '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
19675 '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
19678 '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
19679 '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
19682 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
19683 '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
19686 '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
19687 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
19690 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
19691 '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
19694 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
19695 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
19698 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
19699 '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
19702 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
19703 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
19706 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
19707 '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
19710 '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
19711 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
19714 '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
19715 '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
19718 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
19719 '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
19722 '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
19723 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
19726 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
19727 '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
19730 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
19731 '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
19734 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
19735 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
19738 '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
19739 '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
19742 '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
19743 '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
19746 '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
19747 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
19750 '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
19751 '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
19754 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
19755 '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
19758 '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
19759 '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
19762 '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
19763 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
19766 '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
19767 '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
19770 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
19771 '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
19774 '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
19775 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
19778 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
19779 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
19782 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
19783 '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
19786 '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
19787 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
19790 '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
19791 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
19794 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
19795 '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
19798 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
19799 '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
19802 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
19803 '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
19806 '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
19807 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
19810 '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
19811 '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
19814 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
19815 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
19818 '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
19819 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
19822 '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
19823 '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
19826 '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
19827 '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
19830 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
19831 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
19834 '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
19835 '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
19838 '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
19839 '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
19842 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
19843 '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
19846 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
19847 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
19855 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
19856 '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
19859 '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
19860 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
19863 '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
19864 '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
19867 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
19868 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
19871 '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
19872 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
19875 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
19876 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
19879 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
19880 '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
19883 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
19884 '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
19887 '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
19888 '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
19891 '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
19892 '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
19895 '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
19896 '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
19899 '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
19900 '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
19903 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
19904 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
19907 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
19908 '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
19911 '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
19912 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
19915 '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
19916 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
19919 '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
19920 '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
19923 '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
19924 '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
19927 '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
19928 '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
19931 '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
19932 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
19935 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
19936 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
19939 '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
19940 '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
19943 '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
19944 '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
19947 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
19948 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
19951 '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
19952 '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
19955 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
19956 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
19959 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
19960 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
19963 '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
19964 '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
19967 '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
19968 '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
19971 '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
19972 '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
19975 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
19976 '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
19979 '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
19980 '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
19983 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
19984 '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
19987 '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
19988 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
19991 '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
19992 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
19995 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
19996 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
19999 '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
20000 '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
20003 '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
20004 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
20007 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
20008 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
20011 '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
20012 '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
20015 '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
20016 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
20019 '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
20020 '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
20023 '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
20024 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
20027 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
20028 '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
20031 '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
20032 '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
20035 '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
20036 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
20039 '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
20040 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
20043 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
20044 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
20047 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
20048 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
20051 '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
20052 '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
20055 '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
20056 '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
20059 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
20060 '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
20063 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
20064 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
20067 '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
20068 '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
20071 '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
20072 '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
20075 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
20076 '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
20079 '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
20080 '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
20083 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
20084 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
20087 '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
20088 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
20091 '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
20092 '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
20095 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
20096 '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
20099 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
20100 '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
20103 '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
20104 '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
20107 '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
20108 '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
20111 '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
20112 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
20115 '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
20116 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
20119 '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
20120 '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
20123 '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
20124 '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
20127 '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
20128 '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
20131 '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
20132 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
20135 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
20136 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
20139 '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
20140 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
20143 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
20144 '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
20147 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
20148 '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
20151 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
20152 '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
20155 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
20156 '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
20159 '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
20160 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
20163 '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
20164 '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
20167 '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
20168 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
20171 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
20172 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
20175 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
20176 '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
20179 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
20180 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
20183 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
20184 '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
20187 '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
20188 '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
20191 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
20192 '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
20195 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
20196 '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
20199 '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
20200 '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
20203 '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
20204 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
20207 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
20208 '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
20211 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
20212 '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
20215 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
20216 '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
20219 '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
20220 '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
20223 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
20224 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
20227 '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
20228 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
20231 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
20232 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
20235 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
20236 '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
20239 '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
20240 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
20243 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
20244 '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
20247 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
20248 '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
20251 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
20252 '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
20255 '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
20256 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
20259 '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
20260 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
20263 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
20264 '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
20267 '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
20268 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
20271 '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
20272 '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
20275 '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
20276 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
20279 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
20280 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
20283 '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
20284 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
20287 '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
20288 '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
20291 '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
20292 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
20295 '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
20296 '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
20299 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
20300 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
20303 '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
20304 '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
20307 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
20308 '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
20311 '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
20312 '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
20315 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
20316 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
20319 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
20320 '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
20323 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
20324 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
20327 '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
20328 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
20331 '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
20332 '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
20335 '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
20336 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
20339 '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
20340 '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
20343 '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
20344 '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
20347 '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
20348 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
20351 '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
20352 '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
20355 '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
20356 '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
20359 '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
20360 '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
20366 },{}],111:[function(require
,module
,exports
){
20369 var utils
= exports
;
20370 var BN
= require('bn.js');
20371 var minAssert
= require('minimalistic-assert');
20372 var minUtils
= require('minimalistic-crypto-utils');
20374 utils
.assert
= minAssert
;
20375 utils
.toArray
= minUtils
.toArray
;
20376 utils
.zero2
= minUtils
.zero2
;
20377 utils
.toHex
= minUtils
.toHex
;
20378 utils
.encode
= minUtils
.encode
;
20380 // Represent num in a w-NAF form
20381 function getNAF(num
, w
) {
20383 var ws
= 1 << (w
+ 1);
20384 var k
= num
.clone();
20385 while (k
.cmpn(1) >= 0) {
20388 var mod
= k
.andln(ws
- 1);
20389 if (mod
> (ws
>> 1) - 1)
20390 z
= (ws
>> 1) - mod
;
20399 // Optimization, shift by word if possible
20400 var shift
= (k
.cmpn(0) !== 0 && k
.andln(ws
- 1) === 0) ? (w
+ 1) : 1;
20401 for (var i
= 1; i
< shift
; i
++)
20408 utils
.getNAF
= getNAF
;
20410 // Represent k1, k2 in a Joint Sparse Form
20411 function getJSF(k1
, k2
) {
20421 while (k1
.cmpn(-d1
) > 0 || k2
.cmpn(-d2
) > 0) {
20424 var m14
= (k1
.andln(3) + d1
) & 3;
20425 var m24
= (k2
.andln(3) + d2
) & 3;
20431 if ((m14
& 1) === 0) {
20434 var m8
= (k1
.andln(7) + d1
) & 7;
20435 if ((m8
=== 3 || m8
=== 5) && m24
=== 2)
20443 if ((m24
& 1) === 0) {
20446 var m8
= (k2
.andln(7) + d2
) & 7;
20447 if ((m8
=== 3 || m8
=== 5) && m14
=== 2)
20455 if (2 * d1
=== u1
+ 1)
20457 if (2 * d2
=== u2
+ 1)
20465 utils
.getJSF
= getJSF
;
20467 function cachedProperty(obj
, name
, computer
) {
20468 var key
= '_' + name
;
20469 obj
.prototype[name
] = function cachedProperty() {
20470 return this[key
] !== undefined ? this[key
] :
20471 this[key
] = computer
.call(this);
20474 utils
.cachedProperty
= cachedProperty
;
20476 function parseBytes(bytes
) {
20477 return typeof bytes
=== 'string' ? utils
.toArray(bytes
, 'hex') :
20480 utils
.parseBytes
= parseBytes
;
20482 function intFromLE(bytes
) {
20483 return new BN(bytes
, 'hex', 'le');
20485 utils
.intFromLE
= intFromLE
;
20488 },{"bn.js":81,"minimalistic-assert":123,"minimalistic-crypto-utils":124}],112:[function(require
,module
,exports
){
20493 "/home/ian/git/bitcoin/bitcoinjs-lib-browser"
20496 "_from": "elliptic@latest",
20497 "_id": "elliptic@6.4.0",
20499 "_installable": true,
20500 "_location": "/elliptic",
20501 "_nodeVersion": "7.0.0",
20502 "_npmOperationalInternal": {
20503 "host": "packages-18-east.internal.npmjs.com",
20504 "tmp": "tmp/elliptic-6.4.0.tgz_1487798866428_0.30510620190761983"
20507 "email": "fedor@indutny.com",
20510 "_npmVersion": "3.10.8",
20511 "_phantomChildren": {},
20513 "name": "elliptic",
20523 "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz",
20524 "_shasum": "cac9af8762c85836187003c8dfe193e5e2eae5df",
20525 "_shrinkwrap": null,
20526 "_spec": "elliptic",
20527 "_where": "/home/ian/git/bitcoin/bitcoinjs-lib-browser",
20529 "email": "fedor@indutny.com",
20530 "name": "Fedor Indutny"
20533 "url": "https://github.com/indutny/elliptic/issues"
20537 "brorand": "^1.0.1",
20538 "hash.js": "^1.0.0",
20539 "hmac-drbg": "^1.0.0",
20540 "inherits": "^2.0.1",
20541 "minimalistic-assert": "^1.0.0",
20542 "minimalistic-crypto-utils": "^1.0.0"
20544 "description": "EC cryptography",
20545 "devDependencies": {
20547 "coveralls": "^2.11.3",
20549 "grunt-browserify": "^5.0.0",
20550 "grunt-cli": "^1.2.0",
20551 "grunt-contrib-connect": "^1.0.0",
20552 "grunt-contrib-copy": "^1.0.0",
20553 "grunt-contrib-uglify": "^1.0.1",
20554 "grunt-mocha-istanbul": "^3.0.1",
20555 "grunt-saucelabs": "^8.6.2",
20556 "istanbul": "^0.4.2",
20558 "jshint": "^2.6.0",
20563 "shasum": "cac9af8762c85836187003c8dfe193e5e2eae5df",
20564 "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz"
20569 "gitHead": "6b0d2b76caae91471649c8e21f0b1d3ba0f96090",
20570 "homepage": "https://github.com/indutny/elliptic",
20578 "main": "lib/elliptic.js",
20581 "email": "fedor@indutny.com",
20585 "name": "elliptic",
20586 "optionalDependencies": {},
20587 "readme": "ERROR: No README data found!",
20590 "url": "git+ssh://git@github.com/indutny/elliptic.git"
20593 "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
20594 "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
20595 "lint": "npm run jscs && npm run jshint",
20596 "test": "npm run lint && npm run unit",
20597 "unit": "istanbul test _mocha --reporter=spec test/index.js",
20598 "version": "grunt dist && git add dist/"
20603 },{}],113:[function(require
,module
,exports
){
20604 (function (Buffer
){
20606 var Transform
= require('stream').Transform
20607 var inherits
= require('inherits')
20609 function HashBase (blockSize
) {
20610 Transform
.call(this)
20612 this._block
= new Buffer(blockSize
)
20613 this._blockSize
= blockSize
20614 this._blockOffset
= 0
20615 this._length
= [0, 0, 0, 0]
20617 this._finalized
= false
20620 inherits(HashBase
, Transform
)
20622 HashBase
.prototype._transform = function (chunk
, encoding
, callback
) {
20625 if (encoding
!== 'buffer') chunk
= new Buffer(chunk
, encoding
)
20634 HashBase
.prototype._flush = function (callback
) {
20637 this.push(this._digest())
20645 HashBase
.prototype.update = function (data
, encoding
) {
20646 if (!Buffer
.isBuffer(data
) && typeof data
!== 'string') throw new TypeError('Data must be a string or a buffer')
20647 if (this._finalized
) throw new Error('Digest already called')
20648 if (!Buffer
.isBuffer(data
)) data
= new Buffer(data
, encoding
|| 'binary')
20651 var block
= this._block
20653 while (this._blockOffset
+ data
.length
- offset
>= this._blockSize
) {
20654 for (var i
= this._blockOffset
; i
< this._blockSize
;) block
[i
++] = data
[offset
++]
20656 this._blockOffset
= 0
20658 while (offset
< data
.length
) block
[this._blockOffset
++] = data
[offset
++]
20661 for (var j
= 0, carry
= data
.length
* 8; carry
> 0; ++j
) {
20662 this._length
[j
] += carry
20663 carry
= (this._length
[j
] / 0x0100000000) | 0
20664 if (carry
> 0) this._length
[j
] -= 0x0100000000 * carry
20670 HashBase
.prototype._update = function (data
) {
20671 throw new Error('_update is not implemented')
20674 HashBase
.prototype.digest = function (encoding
) {
20675 if (this._finalized
) throw new Error('Digest already called')
20676 this._finalized
= true
20678 var digest
= this._digest()
20679 if (encoding
!== undefined) digest
= digest
.toString(encoding
)
20683 HashBase
.prototype._digest = function () {
20684 throw new Error('_digest is not implemented')
20687 module
.exports
= HashBase
20689 }).call(this,require("buffer").Buffer
)
20690 },{"buffer":5,"inherits":121,"stream":28}],114:[function(require
,module
,exports
){
20691 var hash
= exports
;
20693 hash
.utils
= require('./hash/utils');
20694 hash
.common
= require('./hash/common');
20695 hash
.sha
= require('./hash/sha');
20696 hash
.ripemd
= require('./hash/ripemd');
20697 hash
.hmac
= require('./hash/hmac');
20699 // Proxy hash functions to the main object
20700 hash
.sha1
= hash
.sha
.sha1
;
20701 hash
.sha256
= hash
.sha
.sha256
;
20702 hash
.sha224
= hash
.sha
.sha224
;
20703 hash
.sha384
= hash
.sha
.sha384
;
20704 hash
.sha512
= hash
.sha
.sha512
;
20705 hash
.ripemd160
= hash
.ripemd
.ripemd160
;
20707 },{"./hash/common":115,"./hash/hmac":116,"./hash/ripemd":117,"./hash/sha":118,"./hash/utils":119}],115:[function(require
,module
,exports
){
20708 var hash
= require('../hash');
20709 var utils
= hash
.utils
;
20710 var assert
= utils
.assert
;
20712 function BlockHash() {
20713 this.pending
= null;
20714 this.pendingTotal
= 0;
20715 this.blockSize
= this.constructor.blockSize
;
20716 this.outSize
= this.constructor.outSize
;
20717 this.hmacStrength
= this.constructor.hmacStrength
;
20718 this.padLength
= this.constructor.padLength
/ 8;
20719 this.endian
= 'big';
20721 this._delta8
= this.blockSize
/ 8;
20722 this._delta32
= this.blockSize
/ 32;
20724 exports
.BlockHash
= BlockHash
;
20726 BlockHash
.prototype.update
= function update(msg
, enc
) {
20727 // Convert message to array, pad it, and join into 32bit blocks
20728 msg
= utils
.toArray(msg
, enc
);
20730 this.pending
= msg
;
20732 this.pending
= this.pending
.concat(msg
);
20733 this.pendingTotal
+= msg
.length
;
20735 // Enough data, try updating
20736 if (this.pending
.length
>= this._delta8
) {
20737 msg
= this.pending
;
20739 // Process pending data in blocks
20740 var r
= msg
.length
% this._delta8
;
20741 this.pending
= msg
.slice(msg
.length
- r
, msg
.length
);
20742 if (this.pending
.length
=== 0)
20743 this.pending
= null;
20745 msg
= utils
.join32(msg
, 0, msg
.length
- r
, this.endian
);
20746 for (var i
= 0; i
< msg
.length
; i
+= this._delta32
)
20747 this._update(msg
, i
, i
+ this._delta32
);
20753 BlockHash
.prototype.digest
= function digest(enc
) {
20754 this.update(this._pad());
20755 assert(this.pending
=== null);
20757 return this._digest(enc
);
20760 BlockHash
.prototype._pad
= function pad() {
20761 var len
= this.pendingTotal
;
20762 var bytes
= this._delta8
;
20763 var k
= bytes
- ((len
+ this.padLength
) % bytes
);
20764 var res
= new Array(k
+ this.padLength
);
20766 for (var i
= 1; i
< k
; i
++)
20771 if (this.endian
=== 'big') {
20772 for (var t
= 8; t
< this.padLength
; t
++)
20779 res
[i
++] = (len
>>> 24) & 0xff;
20780 res
[i
++] = (len
>>> 16) & 0xff;
20781 res
[i
++] = (len
>>> 8) & 0xff;
20782 res
[i
++] = len
& 0xff;
20784 res
[i
++] = len
& 0xff;
20785 res
[i
++] = (len
>>> 8) & 0xff;
20786 res
[i
++] = (len
>>> 16) & 0xff;
20787 res
[i
++] = (len
>>> 24) & 0xff;
20793 for (var t
= 8; t
< this.padLength
; t
++)
20800 },{"../hash":114}],116:[function(require
,module
,exports
){
20801 var hmac
= exports
;
20803 var hash
= require('../hash');
20804 var utils
= hash
.utils
;
20805 var assert
= utils
.assert
;
20807 function Hmac(hash
, key
, enc
) {
20808 if (!(this instanceof Hmac
))
20809 return new Hmac(hash
, key
, enc
);
20811 this.blockSize
= hash
.blockSize
/ 8;
20812 this.outSize
= hash
.outSize
/ 8;
20816 this._init(utils
.toArray(key
, enc
));
20818 module
.exports
= Hmac
;
20820 Hmac
.prototype._init
= function init(key
) {
20821 // Shorten key, if needed
20822 if (key
.length
> this.blockSize
)
20823 key
= new this.Hash().update(key
).digest();
20824 assert(key
.length
<= this.blockSize
);
20826 // Add padding to key
20827 for (var i
= key
.length
; i
< this.blockSize
; i
++)
20830 for (var i
= 0; i
< key
.length
; i
++)
20832 this.inner
= new this.Hash().update(key
);
20834 // 0x36 ^ 0x5c = 0x6a
20835 for (var i
= 0; i
< key
.length
; i
++)
20837 this.outer
= new this.Hash().update(key
);
20840 Hmac
.prototype.update
= function update(msg
, enc
) {
20841 this.inner
.update(msg
, enc
);
20845 Hmac
.prototype.digest
= function digest(enc
) {
20846 this.outer
.update(this.inner
.digest());
20847 return this.outer
.digest(enc
);
20850 },{"../hash":114}],117:[function(require
,module
,exports
){
20851 var hash
= require('../hash');
20852 var utils
= hash
.utils
;
20854 var rotl32
= utils
.rotl32
;
20855 var sum32
= utils
.sum32
;
20856 var sum32_3
= utils
.sum32_3
;
20857 var sum32_4
= utils
.sum32_4
;
20858 var BlockHash
= hash
.common
.BlockHash
;
20860 function RIPEMD160() {
20861 if (!(this instanceof RIPEMD160
))
20862 return new RIPEMD160();
20864 BlockHash
.call(this);
20866 this.h
= [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
20867 this.endian
= 'little';
20869 utils
.inherits(RIPEMD160
, BlockHash
);
20870 exports
.ripemd160
= RIPEMD160
;
20872 RIPEMD160
.blockSize
= 512;
20873 RIPEMD160
.outSize
= 160;
20874 RIPEMD160
.hmacStrength
= 192;
20875 RIPEMD160
.padLength
= 64;
20877 RIPEMD160
.prototype._update
= function update(msg
, start
) {
20888 for (var j
= 0; j
< 80; j
++) {
20891 sum32_4(A
, f(j
, B
, C
, D
), msg
[r
[j
] + start
], K(j
)),
20901 sum32_4(Ah
, f(79 - j
, Bh
, Ch
, Dh
), msg
[rh
[j
] + start
], Kh(j
)),
20906 Dh
= rotl32(Ch
, 10);
20910 T
= sum32_3(this.h
[1], C
, Dh
);
20911 this.h
[1] = sum32_3(this.h
[2], D
, Eh
);
20912 this.h
[2] = sum32_3(this.h
[3], E
, Ah
);
20913 this.h
[3] = sum32_3(this.h
[4], A
, Bh
);
20914 this.h
[4] = sum32_3(this.h
[0], B
, Ch
);
20918 RIPEMD160
.prototype._digest
= function digest(enc
) {
20920 return utils
.toHex32(this.h
, 'little');
20922 return utils
.split32(this.h
, 'little');
20925 function f(j
, x
, y
, z
) {
20929 return (x
& y
) | ((~x
) & z
);
20931 return (x
| (~y
)) ^ z
;
20933 return (x
& z
) | (y
& (~z
));
20935 return x
^ (y
| (~z
));
20965 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
20966 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
20967 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
20968 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
20969 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
20973 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
20974 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
20975 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
20976 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
20977 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
20981 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
20982 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
20983 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
20984 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
20985 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
20989 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
20990 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
20991 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
20992 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
20993 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
20996 },{"../hash":114}],118:[function(require
,module
,exports
){
20997 var hash
= require('../hash');
20998 var utils
= hash
.utils
;
20999 var assert
= utils
.assert
;
21001 var rotr32
= utils
.rotr32
;
21002 var rotl32
= utils
.rotl32
;
21003 var sum32
= utils
.sum32
;
21004 var sum32_4
= utils
.sum32_4
;
21005 var sum32_5
= utils
.sum32_5
;
21006 var rotr64_hi
= utils
.rotr64_hi
;
21007 var rotr64_lo
= utils
.rotr64_lo
;
21008 var shr64_hi
= utils
.shr64_hi
;
21009 var shr64_lo
= utils
.shr64_lo
;
21010 var sum64
= utils
.sum64
;
21011 var sum64_hi
= utils
.sum64_hi
;
21012 var sum64_lo
= utils
.sum64_lo
;
21013 var sum64_4_hi
= utils
.sum64_4_hi
;
21014 var sum64_4_lo
= utils
.sum64_4_lo
;
21015 var sum64_5_hi
= utils
.sum64_5_hi
;
21016 var sum64_5_lo
= utils
.sum64_5_lo
;
21017 var BlockHash
= hash
.common
.BlockHash
;
21020 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
21021 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
21022 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
21023 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
21024 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
21025 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
21026 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
21027 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
21028 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
21029 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
21030 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
21031 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
21032 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
21033 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
21034 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
21035 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
21039 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
21040 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
21041 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
21042 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
21043 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
21044 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
21045 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
21046 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
21047 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
21048 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
21049 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
21050 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
21051 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
21052 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
21053 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
21054 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
21055 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
21056 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
21057 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
21058 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
21059 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
21060 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
21061 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
21062 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
21063 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
21064 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
21065 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
21066 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
21067 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
21068 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
21069 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
21070 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
21071 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
21072 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
21073 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
21074 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
21075 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
21076 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
21077 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
21078 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
21082 0x5A827999, 0x6ED9EBA1,
21083 0x8F1BBCDC, 0xCA62C1D6
21086 function SHA256() {
21087 if (!(this instanceof SHA256
))
21088 return new SHA256();
21090 BlockHash
.call(this);
21091 this.h
= [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
21092 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ];
21094 this.W
= new Array(64);
21096 utils
.inherits(SHA256
, BlockHash
);
21097 exports
.sha256
= SHA256
;
21099 SHA256
.blockSize
= 512;
21100 SHA256
.outSize
= 256;
21101 SHA256
.hmacStrength
= 192;
21102 SHA256
.padLength
= 64;
21104 SHA256
.prototype._update
= function _update(msg
, start
) {
21107 for (var i
= 0; i
< 16; i
++)
21108 W
[i
] = msg
[start
+ i
];
21109 for (; i
< W
.length
; i
++)
21110 W
[i
] = sum32_4(g1_256(W
[i
- 2]), W
[i
- 7], g0_256(W
[i
- 15]), W
[i
- 16]);
21121 assert(this.k
.length
=== W
.length
);
21122 for (var i
= 0; i
< W
.length
; i
++) {
21123 var T1
= sum32_5(h
, s1_256(e
), ch32(e
, f
, g
), this.k
[i
], W
[i
]);
21124 var T2
= sum32(s0_256(a
), maj32(a
, b
, c
));
21135 this.h
[0] = sum32(this.h
[0], a
);
21136 this.h
[1] = sum32(this.h
[1], b
);
21137 this.h
[2] = sum32(this.h
[2], c
);
21138 this.h
[3] = sum32(this.h
[3], d
);
21139 this.h
[4] = sum32(this.h
[4], e
);
21140 this.h
[5] = sum32(this.h
[5], f
);
21141 this.h
[6] = sum32(this.h
[6], g
);
21142 this.h
[7] = sum32(this.h
[7], h
);
21145 SHA256
.prototype._digest
= function digest(enc
) {
21147 return utils
.toHex32(this.h
, 'big');
21149 return utils
.split32(this.h
, 'big');
21152 function SHA224() {
21153 if (!(this instanceof SHA224
))
21154 return new SHA224();
21157 this.h
= [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
21158 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
21160 utils
.inherits(SHA224
, SHA256
);
21161 exports
.sha224
= SHA224
;
21163 SHA224
.blockSize
= 512;
21164 SHA224
.outSize
= 224;
21165 SHA224
.hmacStrength
= 192;
21166 SHA224
.padLength
= 64;
21168 SHA224
.prototype._digest
= function digest(enc
) {
21169 // Just truncate output
21171 return utils
.toHex32(this.h
.slice(0, 7), 'big');
21173 return utils
.split32(this.h
.slice(0, 7), 'big');
21176 function SHA512() {
21177 if (!(this instanceof SHA512
))
21178 return new SHA512();
21180 BlockHash
.call(this);
21181 this.h
= [ 0x6a09e667, 0xf3bcc908,
21182 0xbb67ae85, 0x84caa73b,
21183 0x3c6ef372, 0xfe94f82b,
21184 0xa54ff53a, 0x5f1d36f1,
21185 0x510e527f, 0xade682d1,
21186 0x9b05688c, 0x2b3e6c1f,
21187 0x1f83d9ab, 0xfb41bd6b,
21188 0x5be0cd19, 0x137e2179 ];
21190 this.W
= new Array(160);
21192 utils
.inherits(SHA512
, BlockHash
);
21193 exports
.sha512
= SHA512
;
21195 SHA512
.blockSize
= 1024;
21196 SHA512
.outSize
= 512;
21197 SHA512
.hmacStrength
= 192;
21198 SHA512
.padLength
= 128;
21200 SHA512
.prototype._prepareBlock
= function _prepareBlock(msg
, start
) {
21203 // 32 x 32bit words
21204 for (var i
= 0; i
< 32; i
++)
21205 W
[i
] = msg
[start
+ i
];
21206 for (; i
< W
.length
; i
+= 2) {
21207 var c0_hi
= g1_512_hi(W
[i
- 4], W
[i
- 3]); // i - 2
21208 var c0_lo
= g1_512_lo(W
[i
- 4], W
[i
- 3]);
21209 var c1_hi
= W
[i
- 14]; // i - 7
21210 var c1_lo
= W
[i
- 13];
21211 var c2_hi
= g0_512_hi(W
[i
- 30], W
[i
- 29]); // i - 15
21212 var c2_lo
= g0_512_lo(W
[i
- 30], W
[i
- 29]);
21213 var c3_hi
= W
[i
- 32]; // i - 16
21214 var c3_lo
= W
[i
- 31];
21216 W
[i
] = sum64_4_hi(c0_hi
, c0_lo
,
21220 W
[i
+ 1] = sum64_4_lo(c0_hi
, c0_lo
,
21227 SHA512
.prototype._update
= function _update(msg
, start
) {
21228 this._prepareBlock(msg
, start
);
21232 var ah
= this.h
[0];
21233 var al
= this.h
[1];
21234 var bh
= this.h
[2];
21235 var bl
= this.h
[3];
21236 var ch
= this.h
[4];
21237 var cl
= this.h
[5];
21238 var dh
= this.h
[6];
21239 var dl
= this.h
[7];
21240 var eh
= this.h
[8];
21241 var el
= this.h
[9];
21242 var fh
= this.h
[10];
21243 var fl
= this.h
[11];
21244 var gh
= this.h
[12];
21245 var gl
= this.h
[13];
21246 var hh
= this.h
[14];
21247 var hl
= this.h
[15];
21249 assert(this.k
.length
=== W
.length
);
21250 for (var i
= 0; i
< W
.length
; i
+= 2) {
21253 var c1_hi
= s1_512_hi(eh
, el
);
21254 var c1_lo
= s1_512_lo(eh
, el
);
21255 var c2_hi
= ch64_hi(eh
, el
, fh
, fl
, gh
, gl
);
21256 var c2_lo
= ch64_lo(eh
, el
, fh
, fl
, gh
, gl
);
21257 var c3_hi
= this.k
[i
];
21258 var c3_lo
= this.k
[i
+ 1];
21260 var c4_lo
= W
[i
+ 1];
21262 var T1_hi
= sum64_5_hi(c0_hi
, c0_lo
,
21267 var T1_lo
= sum64_5_lo(c0_hi
, c0_lo
,
21273 var c0_hi
= s0_512_hi(ah
, al
);
21274 var c0_lo
= s0_512_lo(ah
, al
);
21275 var c1_hi
= maj64_hi(ah
, al
, bh
, bl
, ch
, cl
);
21276 var c1_lo
= maj64_lo(ah
, al
, bh
, bl
, ch
, cl
);
21278 var T2_hi
= sum64_hi(c0_hi
, c0_lo
, c1_hi
, c1_lo
);
21279 var T2_lo
= sum64_lo(c0_hi
, c0_lo
, c1_hi
, c1_lo
);
21290 eh
= sum64_hi(dh
, dl
, T1_hi
, T1_lo
);
21291 el
= sum64_lo(dl
, dl
, T1_hi
, T1_lo
);
21302 ah
= sum64_hi(T1_hi
, T1_lo
, T2_hi
, T2_lo
);
21303 al
= sum64_lo(T1_hi
, T1_lo
, T2_hi
, T2_lo
);
21306 sum64(this.h
, 0, ah
, al
);
21307 sum64(this.h
, 2, bh
, bl
);
21308 sum64(this.h
, 4, ch
, cl
);
21309 sum64(this.h
, 6, dh
, dl
);
21310 sum64(this.h
, 8, eh
, el
);
21311 sum64(this.h
, 10, fh
, fl
);
21312 sum64(this.h
, 12, gh
, gl
);
21313 sum64(this.h
, 14, hh
, hl
);
21316 SHA512
.prototype._digest
= function digest(enc
) {
21318 return utils
.toHex32(this.h
, 'big');
21320 return utils
.split32(this.h
, 'big');
21323 function SHA384() {
21324 if (!(this instanceof SHA384
))
21325 return new SHA384();
21328 this.h
= [ 0xcbbb9d5d, 0xc1059ed8,
21329 0x629a292a, 0x367cd507,
21330 0x9159015a, 0x3070dd17,
21331 0x152fecd8, 0xf70e5939,
21332 0x67332667, 0xffc00b31,
21333 0x8eb44a87, 0x68581511,
21334 0xdb0c2e0d, 0x64f98fa7,
21335 0x47b5481d, 0xbefa4fa4 ];
21337 utils
.inherits(SHA384
, SHA512
);
21338 exports
.sha384
= SHA384
;
21340 SHA384
.blockSize
= 1024;
21341 SHA384
.outSize
= 384;
21342 SHA384
.hmacStrength
= 192;
21343 SHA384
.padLength
= 128;
21345 SHA384
.prototype._digest
= function digest(enc
) {
21347 return utils
.toHex32(this.h
.slice(0, 12), 'big');
21349 return utils
.split32(this.h
.slice(0, 12), 'big');
21353 if (!(this instanceof SHA1
))
21356 BlockHash
.call(this);
21357 this.h
= [ 0x67452301, 0xefcdab89, 0x98badcfe,
21358 0x10325476, 0xc3d2e1f0 ];
21359 this.W
= new Array(80);
21362 utils
.inherits(SHA1
, BlockHash
);
21363 exports
.sha1
= SHA1
;
21365 SHA1
.blockSize
= 512;
21366 SHA1
.outSize
= 160;
21367 SHA1
.hmacStrength
= 80;
21368 SHA1
.padLength
= 64;
21370 SHA1
.prototype._update
= function _update(msg
, start
) {
21373 for (var i
= 0; i
< 16; i
++)
21374 W
[i
] = msg
[start
+ i
];
21376 for(; i
< W
.length
; i
++)
21377 W
[i
] = rotl32(W
[i
- 3] ^ W
[i
- 8] ^ W
[i
- 14] ^ W
[i
- 16], 1);
21385 for (var i
= 0; i
< W
.length
; i
++) {
21386 var s
= ~~(i
/ 20);
21387 var t
= sum32_5(rotl32(a
, 5), ft_1(s
, b
, c
, d
), e
, W
[i
], sha1_K
[s
]);
21395 this.h
[0] = sum32(this.h
[0], a
);
21396 this.h
[1] = sum32(this.h
[1], b
);
21397 this.h
[2] = sum32(this.h
[2], c
);
21398 this.h
[3] = sum32(this.h
[3], d
);
21399 this.h
[4] = sum32(this.h
[4], e
);
21402 SHA1
.prototype._digest
= function digest(enc
) {
21404 return utils
.toHex32(this.h
, 'big');
21406 return utils
.split32(this.h
, 'big');
21409 function ch32(x
, y
, z
) {
21410 return (x
& y
) ^ ((~x
) & z
);
21413 function maj32(x
, y
, z
) {
21414 return (x
& y
) ^ (x
& z
) ^ (y
& z
);
21417 function p32(x
, y
, z
) {
21421 function s0_256(x
) {
21422 return rotr32(x
, 2) ^ rotr32(x
, 13) ^ rotr32(x
, 22);
21425 function s1_256(x
) {
21426 return rotr32(x
, 6) ^ rotr32(x
, 11) ^ rotr32(x
, 25);
21429 function g0_256(x
) {
21430 return rotr32(x
, 7) ^ rotr32(x
, 18) ^ (x
>>> 3);
21433 function g1_256(x
) {
21434 return rotr32(x
, 17) ^ rotr32(x
, 19) ^ (x
>>> 10);
21437 function ft_1(s
, x
, y
, z
) {
21439 return ch32(x
, y
, z
);
21440 if (s
=== 1 || s
=== 3)
21441 return p32(x
, y
, z
);
21443 return maj32(x
, y
, z
);
21446 function ch64_hi(xh
, xl
, yh
, yl
, zh
, zl
) {
21447 var r
= (xh
& yh
) ^ ((~xh
) & zh
);
21453 function ch64_lo(xh
, xl
, yh
, yl
, zh
, zl
) {
21454 var r
= (xl
& yl
) ^ ((~xl
) & zl
);
21460 function maj64_hi(xh
, xl
, yh
, yl
, zh
, zl
) {
21461 var r
= (xh
& yh
) ^ (xh
& zh
) ^ (yh
& zh
);
21467 function maj64_lo(xh
, xl
, yh
, yl
, zh
, zl
) {
21468 var r
= (xl
& yl
) ^ (xl
& zl
) ^ (yl
& zl
);
21474 function s0_512_hi(xh
, xl
) {
21475 var c0_hi
= rotr64_hi(xh
, xl
, 28);
21476 var c1_hi
= rotr64_hi(xl
, xh
, 2); // 34
21477 var c2_hi
= rotr64_hi(xl
, xh
, 7); // 39
21479 var r
= c0_hi
^ c1_hi
^ c2_hi
;
21485 function s0_512_lo(xh
, xl
) {
21486 var c0_lo
= rotr64_lo(xh
, xl
, 28);
21487 var c1_lo
= rotr64_lo(xl
, xh
, 2); // 34
21488 var c2_lo
= rotr64_lo(xl
, xh
, 7); // 39
21490 var r
= c0_lo
^ c1_lo
^ c2_lo
;
21496 function s1_512_hi(xh
, xl
) {
21497 var c0_hi
= rotr64_hi(xh
, xl
, 14);
21498 var c1_hi
= rotr64_hi(xh
, xl
, 18);
21499 var c2_hi
= rotr64_hi(xl
, xh
, 9); // 41
21501 var r
= c0_hi
^ c1_hi
^ c2_hi
;
21507 function s1_512_lo(xh
, xl
) {
21508 var c0_lo
= rotr64_lo(xh
, xl
, 14);
21509 var c1_lo
= rotr64_lo(xh
, xl
, 18);
21510 var c2_lo
= rotr64_lo(xl
, xh
, 9); // 41
21512 var r
= c0_lo
^ c1_lo
^ c2_lo
;
21518 function g0_512_hi(xh
, xl
) {
21519 var c0_hi
= rotr64_hi(xh
, xl
, 1);
21520 var c1_hi
= rotr64_hi(xh
, xl
, 8);
21521 var c2_hi
= shr64_hi(xh
, xl
, 7);
21523 var r
= c0_hi
^ c1_hi
^ c2_hi
;
21529 function g0_512_lo(xh
, xl
) {
21530 var c0_lo
= rotr64_lo(xh
, xl
, 1);
21531 var c1_lo
= rotr64_lo(xh
, xl
, 8);
21532 var c2_lo
= shr64_lo(xh
, xl
, 7);
21534 var r
= c0_lo
^ c1_lo
^ c2_lo
;
21540 function g1_512_hi(xh
, xl
) {
21541 var c0_hi
= rotr64_hi(xh
, xl
, 19);
21542 var c1_hi
= rotr64_hi(xl
, xh
, 29); // 61
21543 var c2_hi
= shr64_hi(xh
, xl
, 6);
21545 var r
= c0_hi
^ c1_hi
^ c2_hi
;
21551 function g1_512_lo(xh
, xl
) {
21552 var c0_lo
= rotr64_lo(xh
, xl
, 19);
21553 var c1_lo
= rotr64_lo(xl
, xh
, 29); // 61
21554 var c2_lo
= shr64_lo(xh
, xl
, 6);
21556 var r
= c0_lo
^ c1_lo
^ c2_lo
;
21562 },{"../hash":114}],119:[function(require
,module
,exports
){
21563 var utils
= exports
;
21564 var inherits
= require('inherits');
21566 function toArray(msg
, enc
) {
21567 if (Array
.isArray(msg
))
21568 return msg
.slice();
21572 if (typeof msg
=== 'string') {
21574 for (var i
= 0; i
< msg
.length
; i
++) {
21575 var c
= msg
.charCodeAt(i
);
21583 } else if (enc
=== 'hex') {
21584 msg
= msg
.replace(/[^a-z0-9]+/ig, '');
21585 if (msg
.length
% 2 !== 0)
21587 for (var i
= 0; i
< msg
.length
; i
+= 2)
21588 res
.push(parseInt(msg
[i
] + msg
[i
+ 1], 16));
21591 for (var i
= 0; i
< msg
.length
; i
++)
21592 res
[i
] = msg
[i
] | 0;
21596 utils
.toArray
= toArray
;
21598 function toHex(msg
) {
21600 for (var i
= 0; i
< msg
.length
; i
++)
21601 res
+= zero2(msg
[i
].toString(16));
21604 utils
.toHex
= toHex
;
21606 function htonl(w
) {
21607 var res
= (w
>>> 24) |
21608 ((w
>>> 8) & 0xff00) |
21609 ((w
<< 8) & 0xff0000) |
21610 ((w
& 0xff) << 24);
21613 utils
.htonl
= htonl
;
21615 function toHex32(msg
, endian
) {
21617 for (var i
= 0; i
< msg
.length
; i
++) {
21619 if (endian
=== 'little')
21621 res
+= zero8(w
.toString(16));
21625 utils
.toHex32
= toHex32
;
21627 function zero2(word
) {
21628 if (word
.length
=== 1)
21633 utils
.zero2
= zero2
;
21635 function zero8(word
) {
21636 if (word
.length
=== 7)
21638 else if (word
.length
=== 6)
21639 return '00' + word
;
21640 else if (word
.length
=== 5)
21641 return '000' + word
;
21642 else if (word
.length
=== 4)
21643 return '0000' + word
;
21644 else if (word
.length
=== 3)
21645 return '00000' + word
;
21646 else if (word
.length
=== 2)
21647 return '000000' + word
;
21648 else if (word
.length
=== 1)
21649 return '0000000' + word
;
21653 utils
.zero8
= zero8
;
21655 function join32(msg
, start
, end
, endian
) {
21656 var len
= end
- start
;
21657 assert(len
% 4 === 0);
21658 var res
= new Array(len
/ 4);
21659 for (var i
= 0, k
= start
; i
< res
.length
; i
++, k
+= 4) {
21661 if (endian
=== 'big')
21662 w
= (msg
[k
] << 24) | (msg
[k
+ 1] << 16) | (msg
[k
+ 2] << 8) | msg
[k
+ 3];
21664 w
= (msg
[k
+ 3] << 24) | (msg
[k
+ 2] << 16) | (msg
[k
+ 1] << 8) | msg
[k
];
21669 utils
.join32
= join32
;
21671 function split32(msg
, endian
) {
21672 var res
= new Array(msg
.length
* 4);
21673 for (var i
= 0, k
= 0; i
< msg
.length
; i
++, k
+= 4) {
21675 if (endian
=== 'big') {
21677 res
[k
+ 1] = (m
>>> 16) & 0xff;
21678 res
[k
+ 2] = (m
>>> 8) & 0xff;
21679 res
[k
+ 3] = m
& 0xff;
21681 res
[k
+ 3] = m
>>> 24;
21682 res
[k
+ 2] = (m
>>> 16) & 0xff;
21683 res
[k
+ 1] = (m
>>> 8) & 0xff;
21689 utils
.split32
= split32
;
21691 function rotr32(w
, b
) {
21692 return (w
>>> b
) | (w
<< (32 - b
));
21694 utils
.rotr32
= rotr32
;
21696 function rotl32(w
, b
) {
21697 return (w
<< b
) | (w
>>> (32 - b
));
21699 utils
.rotl32
= rotl32
;
21701 function sum32(a
, b
) {
21702 return (a
+ b
) >>> 0;
21704 utils
.sum32
= sum32
;
21706 function sum32_3(a
, b
, c
) {
21707 return (a
+ b
+ c
) >>> 0;
21709 utils
.sum32_3
= sum32_3
;
21711 function sum32_4(a
, b
, c
, d
) {
21712 return (a
+ b
+ c
+ d
) >>> 0;
21714 utils
.sum32_4
= sum32_4
;
21716 function sum32_5(a
, b
, c
, d
, e
) {
21717 return (a
+ b
+ c
+ d
+ e
) >>> 0;
21719 utils
.sum32_5
= sum32_5
;
21721 function assert(cond
, msg
) {
21723 throw new Error(msg
|| 'Assertion failed');
21725 utils
.assert
= assert
;
21727 utils
.inherits
= inherits
;
21729 function sum64(buf
, pos
, ah
, al
) {
21731 var bl
= buf
[pos
+ 1];
21733 var lo
= (al
+ bl
) >>> 0;
21734 var hi
= (lo
< al
? 1 : 0) + ah
+ bh
;
21735 buf
[pos
] = hi
>>> 0;
21738 exports
.sum64
= sum64
;
21740 function sum64_hi(ah
, al
, bh
, bl
) {
21741 var lo
= (al
+ bl
) >>> 0;
21742 var hi
= (lo
< al
? 1 : 0) + ah
+ bh
;
21745 exports
.sum64_hi
= sum64_hi
;
21747 function sum64_lo(ah
, al
, bh
, bl
) {
21751 exports
.sum64_lo
= sum64_lo
;
21753 function sum64_4_hi(ah
, al
, bh
, bl
, ch
, cl
, dh
, dl
) {
21756 lo
= (lo
+ bl
) >>> 0;
21757 carry
+= lo
< al
? 1 : 0;
21758 lo
= (lo
+ cl
) >>> 0;
21759 carry
+= lo
< cl
? 1 : 0;
21760 lo
= (lo
+ dl
) >>> 0;
21761 carry
+= lo
< dl
? 1 : 0;
21763 var hi
= ah
+ bh
+ ch
+ dh
+ carry
;
21766 exports
.sum64_4_hi
= sum64_4_hi
;
21768 function sum64_4_lo(ah
, al
, bh
, bl
, ch
, cl
, dh
, dl
) {
21769 var lo
= al
+ bl
+ cl
+ dl
;
21772 exports
.sum64_4_lo
= sum64_4_lo
;
21774 function sum64_5_hi(ah
, al
, bh
, bl
, ch
, cl
, dh
, dl
, eh
, el
) {
21777 lo
= (lo
+ bl
) >>> 0;
21778 carry
+= lo
< al
? 1 : 0;
21779 lo
= (lo
+ cl
) >>> 0;
21780 carry
+= lo
< cl
? 1 : 0;
21781 lo
= (lo
+ dl
) >>> 0;
21782 carry
+= lo
< dl
? 1 : 0;
21783 lo
= (lo
+ el
) >>> 0;
21784 carry
+= lo
< el
? 1 : 0;
21786 var hi
= ah
+ bh
+ ch
+ dh
+ eh
+ carry
;
21789 exports
.sum64_5_hi
= sum64_5_hi
;
21791 function sum64_5_lo(ah
, al
, bh
, bl
, ch
, cl
, dh
, dl
, eh
, el
) {
21792 var lo
= al
+ bl
+ cl
+ dl
+ el
;
21796 exports
.sum64_5_lo
= sum64_5_lo
;
21798 function rotr64_hi(ah
, al
, num
) {
21799 var r
= (al
<< (32 - num
)) | (ah
>>> num
);
21802 exports
.rotr64_hi
= rotr64_hi
;
21804 function rotr64_lo(ah
, al
, num
) {
21805 var r
= (ah
<< (32 - num
)) | (al
>>> num
);
21808 exports
.rotr64_lo
= rotr64_lo
;
21810 function shr64_hi(ah
, al
, num
) {
21813 exports
.shr64_hi
= shr64_hi
;
21815 function shr64_lo(ah
, al
, num
) {
21816 var r
= (ah
<< (32 - num
)) | (al
>>> num
);
21819 exports
.shr64_lo
= shr64_lo
;
21821 },{"inherits":121}],120:[function(require
,module
,exports
){
21824 var hash
= require('hash.js');
21825 var utils
= require('minimalistic-crypto-utils');
21826 var assert
= require('minimalistic-assert');
21828 function HmacDRBG(options
) {
21829 if (!(this instanceof HmacDRBG
))
21830 return new HmacDRBG(options
);
21831 this.hash
= options
.hash
;
21832 this.predResist
= !!options
.predResist
;
21834 this.outLen
= this.hash
.outSize
;
21835 this.minEntropy
= options
.minEntropy
|| this.hash
.hmacStrength
;
21837 this._reseed
= null;
21838 this.reseedInterval
= null;
21842 var entropy
= utils
.toArray(options
.entropy
, options
.entropyEnc
|| 'hex');
21843 var nonce
= utils
.toArray(options
.nonce
, options
.nonceEnc
|| 'hex');
21844 var pers
= utils
.toArray(options
.pers
, options
.persEnc
|| 'hex');
21845 assert(entropy
.length
>= (this.minEntropy
/ 8),
21846 'Not enough entropy. Minimum is: ' + this.minEntropy
+ ' bits');
21847 this._init(entropy
, nonce
, pers
);
21849 module
.exports
= HmacDRBG
;
21851 HmacDRBG
.prototype._init
= function init(entropy
, nonce
, pers
) {
21852 var seed
= entropy
.concat(nonce
).concat(pers
);
21854 this.K
= new Array(this.outLen
/ 8);
21855 this.V
= new Array(this.outLen
/ 8);
21856 for (var i
= 0; i
< this.V
.length
; i
++) {
21861 this._update(seed
);
21863 this.reseedInterval
= 0x1000000000000; // 2^48
21866 HmacDRBG
.prototype._hmac
= function hmac() {
21867 return new hash
.hmac(this.hash
, this.K
);
21870 HmacDRBG
.prototype._update
= function update(seed
) {
21871 var kmac
= this._hmac()
21875 kmac
= kmac
.update(seed
);
21876 this.K
= kmac
.digest();
21877 this.V
= this._hmac().update(this.V
).digest();
21881 this.K
= this._hmac()
21886 this.V
= this._hmac().update(this.V
).digest();
21889 HmacDRBG
.prototype.reseed
= function reseed(entropy
, entropyEnc
, add
, addEnc
) {
21890 // Optional entropy enc
21891 if (typeof entropyEnc
!== 'string') {
21897 entropy
= utils
.toArray(entropy
, entropyEnc
);
21898 add
= utils
.toArray(add
, addEnc
);
21900 assert(entropy
.length
>= (this.minEntropy
/ 8),
21901 'Not enough entropy. Minimum is: ' + this.minEntropy
+ ' bits');
21903 this._update(entropy
.concat(add
|| []));
21907 HmacDRBG
.prototype.generate
= function generate(len
, enc
, add
, addEnc
) {
21908 if (this._reseed
> this.reseedInterval
)
21909 throw new Error('Reseed is required');
21911 // Optional encoding
21912 if (typeof enc
!== 'string') {
21918 // Optional additional data
21920 add
= utils
.toArray(add
, addEnc
|| 'hex');
21925 while (temp
.length
< len
) {
21926 this.V
= this._hmac().update(this.V
).digest();
21927 temp
= temp
.concat(this.V
);
21930 var res
= temp
.slice(0, len
);
21933 return utils
.encode(res
, enc
);
21936 },{"hash.js":114,"minimalistic-assert":123,"minimalistic-crypto-utils":124}],121:[function(require
,module
,exports
){
21937 arguments
[4][9][0].apply(exports
,arguments
)
21938 },{"dup":9}],122:[function(require
,module
,exports
){
21939 (function (Buffer
){
21940 // constant-space merkle root calculation algorithm
21941 module
.exports
= function fastRoot (values
, digestFn
) {
21942 if (!Array
.isArray(values
)) throw TypeError('Expected values Array')
21943 if (typeof digestFn
!== 'function') throw TypeError('Expected digest Function')
21945 var length
= values
.length
21946 var results
= values
.concat()
21948 while (length
> 1) {
21951 for (var i
= 0; i
< length
; i
+= 2, ++j
) {
21952 var left
= results
[i
]
21953 var right
= i
+ 1 === length
? left : results
[i
+ 1]
21954 var data
= Buffer
.concat([left
, right
])
21956 results
[j
] = digestFn(data
)
21965 }).call(this,require("buffer").Buffer
)
21966 },{"buffer":5}],123:[function(require
,module
,exports
){
21967 module
.exports
= assert
;
21969 function assert(val
, msg
) {
21971 throw new Error(msg
|| 'Assertion failed');
21974 assert
.equal
= function assertEqual(l
, r
, msg
) {
21976 throw new Error(msg
|| ('Assertion failed: ' + l
+ ' != ' + r
));
21979 },{}],124:[function(require
,module
,exports
){
21982 var utils
= exports
;
21984 function toArray(msg
, enc
) {
21985 if (Array
.isArray(msg
))
21986 return msg
.slice();
21990 if (typeof msg
!== 'string') {
21991 for (var i
= 0; i
< msg
.length
; i
++)
21992 res
[i
] = msg
[i
] | 0;
21995 if (enc
=== 'hex') {
21996 msg
= msg
.replace(/[^a-z0-9]+/ig, '');
21997 if (msg
.length
% 2 !== 0)
21999 for (var i
= 0; i
< msg
.length
; i
+= 2)
22000 res
.push(parseInt(msg
[i
] + msg
[i
+ 1], 16));
22002 for (var i
= 0; i
< msg
.length
; i
++) {
22003 var c
= msg
.charCodeAt(i
);
22014 utils
.toArray
= toArray
;
22016 function zero2(word
) {
22017 if (word
.length
=== 1)
22022 utils
.zero2
= zero2
;
22024 function toHex(msg
) {
22026 for (var i
= 0; i
< msg
.length
; i
++)
22027 res
+= zero2(msg
[i
].toString(16));
22030 utils
.toHex
= toHex
;
22032 utils
.encode
= function encode(arr
, enc
) {
22039 },{}],125:[function(require
,module
,exports
){
22040 var OPS
= require('bitcoin-ops')
22042 function encodingLength (i
) {
22043 return i
< OPS
.OP_PUSHDATA1
? 1
22049 function encode (buffer
, number
, offset
) {
22050 var size
= encodingLength(number
)
22054 buffer
.writeUInt8(number
, offset
)
22057 } else if (size
=== 2) {
22058 buffer
.writeUInt8(OPS
.OP_PUSHDATA1
, offset
)
22059 buffer
.writeUInt8(number
, offset
+ 1)
22062 } else if (size
=== 3) {
22063 buffer
.writeUInt8(OPS
.OP_PUSHDATA2
, offset
)
22064 buffer
.writeUInt16LE(number
, offset
+ 1)
22068 buffer
.writeUInt8(OPS
.OP_PUSHDATA4
, offset
)
22069 buffer
.writeUInt32LE(number
, offset
+ 1)
22075 function decode (buffer
, offset
) {
22076 var opcode
= buffer
.readUInt8(offset
)
22080 if (opcode
< OPS
.OP_PUSHDATA1
) {
22085 } else if (opcode
=== OPS
.OP_PUSHDATA1
) {
22086 if (offset
+ 2 > buffer
.length
) return null
22087 number
= buffer
.readUInt8(offset
+ 1)
22091 } else if (opcode
=== OPS
.OP_PUSHDATA2
) {
22092 if (offset
+ 3 > buffer
.length
) return null
22093 number
= buffer
.readUInt16LE(offset
+ 1)
22098 if (offset
+ 5 > buffer
.length
) return null
22099 if (opcode
!== OPS
.OP_PUSHDATA4
) throw new Error('Unexpected opcode')
22101 number
= buffer
.readUInt32LE(offset
+ 1)
22113 encodingLength: encodingLength
,
22118 },{"bitcoin-ops":42}],126:[function(require
,module
,exports
){
22119 (function (process
,global
){
22122 function oldBrowser () {
22123 throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
22126 var Buffer
= require('safe-buffer').Buffer
22127 var crypto
= global
.crypto
|| global
.msCrypto
22129 if (crypto
&& crypto
.getRandomValues
) {
22130 module
.exports
= randomBytes
22132 module
.exports
= oldBrowser
22135 function randomBytes (size
, cb
) {
22136 // phantomjs needs to throw
22137 if (size
> 65536) throw new Error('requested too many random bytes')
22138 // in case browserify isn't using the Uint8Array version
22139 var rawBytes
= new global
.Uint8Array(size
)
22141 // This will not work in older browsers.
22142 // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
22143 if (size
> 0) { // getRandomValues fails on IE if size == 0
22144 crypto
.getRandomValues(rawBytes
)
22147 // XXX: phantomjs doesn't like a buffer being passed here
22148 var bytes
= Buffer
.from(rawBytes
.buffer
)
22150 if (typeof cb
=== 'function') {
22151 return process
.nextTick(function () {
22159 }).call(this,require('_process'),typeof global
!== "undefined" ? global : typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
22160 },{"_process":13,"safe-buffer":128}],127:[function(require
,module
,exports
){
22161 (function (Buffer
){
22163 var inherits
= require('inherits')
22164 var HashBase
= require('hash-base')
22166 function RIPEMD160 () {
22167 HashBase
.call(this, 64)
22170 this._a
= 0x67452301
22171 this._b
= 0xefcdab89
22172 this._c
= 0x98badcfe
22173 this._d
= 0x10325476
22174 this._e
= 0xc3d2e1f0
22177 inherits(RIPEMD160
, HashBase
)
22179 RIPEMD160
.prototype._update = function () {
22180 var m
= new Array(16)
22181 for (var i
= 0; i
< 16; ++i
) m
[i
] = this._block
.readInt32LE(i
* 4)
22189 // Mj = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
22191 // Sj = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
22192 al
= fn1(al
, bl
, cl
, dl
, el
, m
[0], 0x00000000, 11); cl
= rotl(cl
, 10)
22193 el
= fn1(el
, al
, bl
, cl
, dl
, m
[1], 0x00000000, 14); bl
= rotl(bl
, 10)
22194 dl
= fn1(dl
, el
, al
, bl
, cl
, m
[2], 0x00000000, 15); al
= rotl(al
, 10)
22195 cl
= fn1(cl
, dl
, el
, al
, bl
, m
[3], 0x00000000, 12); el
= rotl(el
, 10)
22196 bl
= fn1(bl
, cl
, dl
, el
, al
, m
[4], 0x00000000, 5); dl
= rotl(dl
, 10)
22197 al
= fn1(al
, bl
, cl
, dl
, el
, m
[5], 0x00000000, 8); cl
= rotl(cl
, 10)
22198 el
= fn1(el
, al
, bl
, cl
, dl
, m
[6], 0x00000000, 7); bl
= rotl(bl
, 10)
22199 dl
= fn1(dl
, el
, al
, bl
, cl
, m
[7], 0x00000000, 9); al
= rotl(al
, 10)
22200 cl
= fn1(cl
, dl
, el
, al
, bl
, m
[8], 0x00000000, 11); el
= rotl(el
, 10)
22201 bl
= fn1(bl
, cl
, dl
, el
, al
, m
[9], 0x00000000, 13); dl
= rotl(dl
, 10)
22202 al
= fn1(al
, bl
, cl
, dl
, el
, m
[10], 0x00000000, 14); cl
= rotl(cl
, 10)
22203 el
= fn1(el
, al
, bl
, cl
, dl
, m
[11], 0x00000000, 15); bl
= rotl(bl
, 10)
22204 dl
= fn1(dl
, el
, al
, bl
, cl
, m
[12], 0x00000000, 6); al
= rotl(al
, 10)
22205 cl
= fn1(cl
, dl
, el
, al
, bl
, m
[13], 0x00000000, 7); el
= rotl(el
, 10)
22206 bl
= fn1(bl
, cl
, dl
, el
, al
, m
[14], 0x00000000, 9); dl
= rotl(dl
, 10)
22207 al
= fn1(al
, bl
, cl
, dl
, el
, m
[15], 0x00000000, 8); cl
= rotl(cl
, 10)
22209 // Mj = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
22211 // Sj = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
22212 el
= fn2(el
, al
, bl
, cl
, dl
, m
[7], 0x5a827999, 7); bl
= rotl(bl
, 10)
22213 dl
= fn2(dl
, el
, al
, bl
, cl
, m
[4], 0x5a827999, 6); al
= rotl(al
, 10)
22214 cl
= fn2(cl
, dl
, el
, al
, bl
, m
[13], 0x5a827999, 8); el
= rotl(el
, 10)
22215 bl
= fn2(bl
, cl
, dl
, el
, al
, m
[1], 0x5a827999, 13); dl
= rotl(dl
, 10)
22216 al
= fn2(al
, bl
, cl
, dl
, el
, m
[10], 0x5a827999, 11); cl
= rotl(cl
, 10)
22217 el
= fn2(el
, al
, bl
, cl
, dl
, m
[6], 0x5a827999, 9); bl
= rotl(bl
, 10)
22218 dl
= fn2(dl
, el
, al
, bl
, cl
, m
[15], 0x5a827999, 7); al
= rotl(al
, 10)
22219 cl
= fn2(cl
, dl
, el
, al
, bl
, m
[3], 0x5a827999, 15); el
= rotl(el
, 10)
22220 bl
= fn2(bl
, cl
, dl
, el
, al
, m
[12], 0x5a827999, 7); dl
= rotl(dl
, 10)
22221 al
= fn2(al
, bl
, cl
, dl
, el
, m
[0], 0x5a827999, 12); cl
= rotl(cl
, 10)
22222 el
= fn2(el
, al
, bl
, cl
, dl
, m
[9], 0x5a827999, 15); bl
= rotl(bl
, 10)
22223 dl
= fn2(dl
, el
, al
, bl
, cl
, m
[5], 0x5a827999, 9); al
= rotl(al
, 10)
22224 cl
= fn2(cl
, dl
, el
, al
, bl
, m
[2], 0x5a827999, 11); el
= rotl(el
, 10)
22225 bl
= fn2(bl
, cl
, dl
, el
, al
, m
[14], 0x5a827999, 7); dl
= rotl(dl
, 10)
22226 al
= fn2(al
, bl
, cl
, dl
, el
, m
[11], 0x5a827999, 13); cl
= rotl(cl
, 10)
22227 el
= fn2(el
, al
, bl
, cl
, dl
, m
[8], 0x5a827999, 12); bl
= rotl(bl
, 10)
22229 // Mj = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
22231 // Sj = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
22232 dl
= fn3(dl
, el
, al
, bl
, cl
, m
[3], 0x6ed9eba1, 11); al
= rotl(al
, 10)
22233 cl
= fn3(cl
, dl
, el
, al
, bl
, m
[10], 0x6ed9eba1, 13); el
= rotl(el
, 10)
22234 bl
= fn3(bl
, cl
, dl
, el
, al
, m
[14], 0x6ed9eba1, 6); dl
= rotl(dl
, 10)
22235 al
= fn3(al
, bl
, cl
, dl
, el
, m
[4], 0x6ed9eba1, 7); cl
= rotl(cl
, 10)
22236 el
= fn3(el
, al
, bl
, cl
, dl
, m
[9], 0x6ed9eba1, 14); bl
= rotl(bl
, 10)
22237 dl
= fn3(dl
, el
, al
, bl
, cl
, m
[15], 0x6ed9eba1, 9); al
= rotl(al
, 10)
22238 cl
= fn3(cl
, dl
, el
, al
, bl
, m
[8], 0x6ed9eba1, 13); el
= rotl(el
, 10)
22239 bl
= fn3(bl
, cl
, dl
, el
, al
, m
[1], 0x6ed9eba1, 15); dl
= rotl(dl
, 10)
22240 al
= fn3(al
, bl
, cl
, dl
, el
, m
[2], 0x6ed9eba1, 14); cl
= rotl(cl
, 10)
22241 el
= fn3(el
, al
, bl
, cl
, dl
, m
[7], 0x6ed9eba1, 8); bl
= rotl(bl
, 10)
22242 dl
= fn3(dl
, el
, al
, bl
, cl
, m
[0], 0x6ed9eba1, 13); al
= rotl(al
, 10)
22243 cl
= fn3(cl
, dl
, el
, al
, bl
, m
[6], 0x6ed9eba1, 6); el
= rotl(el
, 10)
22244 bl
= fn3(bl
, cl
, dl
, el
, al
, m
[13], 0x6ed9eba1, 5); dl
= rotl(dl
, 10)
22245 al
= fn3(al
, bl
, cl
, dl
, el
, m
[11], 0x6ed9eba1, 12); cl
= rotl(cl
, 10)
22246 el
= fn3(el
, al
, bl
, cl
, dl
, m
[5], 0x6ed9eba1, 7); bl
= rotl(bl
, 10)
22247 dl
= fn3(dl
, el
, al
, bl
, cl
, m
[12], 0x6ed9eba1, 5); al
= rotl(al
, 10)
22249 // Mj = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
22251 // Sj = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
22252 cl
= fn4(cl
, dl
, el
, al
, bl
, m
[1], 0x8f1bbcdc, 11); el
= rotl(el
, 10)
22253 bl
= fn4(bl
, cl
, dl
, el
, al
, m
[9], 0x8f1bbcdc, 12); dl
= rotl(dl
, 10)
22254 al
= fn4(al
, bl
, cl
, dl
, el
, m
[11], 0x8f1bbcdc, 14); cl
= rotl(cl
, 10)
22255 el
= fn4(el
, al
, bl
, cl
, dl
, m
[10], 0x8f1bbcdc, 15); bl
= rotl(bl
, 10)
22256 dl
= fn4(dl
, el
, al
, bl
, cl
, m
[0], 0x8f1bbcdc, 14); al
= rotl(al
, 10)
22257 cl
= fn4(cl
, dl
, el
, al
, bl
, m
[8], 0x8f1bbcdc, 15); el
= rotl(el
, 10)
22258 bl
= fn4(bl
, cl
, dl
, el
, al
, m
[12], 0x8f1bbcdc, 9); dl
= rotl(dl
, 10)
22259 al
= fn4(al
, bl
, cl
, dl
, el
, m
[4], 0x8f1bbcdc, 8); cl
= rotl(cl
, 10)
22260 el
= fn4(el
, al
, bl
, cl
, dl
, m
[13], 0x8f1bbcdc, 9); bl
= rotl(bl
, 10)
22261 dl
= fn4(dl
, el
, al
, bl
, cl
, m
[3], 0x8f1bbcdc, 14); al
= rotl(al
, 10)
22262 cl
= fn4(cl
, dl
, el
, al
, bl
, m
[7], 0x8f1bbcdc, 5); el
= rotl(el
, 10)
22263 bl
= fn4(bl
, cl
, dl
, el
, al
, m
[15], 0x8f1bbcdc, 6); dl
= rotl(dl
, 10)
22264 al
= fn4(al
, bl
, cl
, dl
, el
, m
[14], 0x8f1bbcdc, 8); cl
= rotl(cl
, 10)
22265 el
= fn4(el
, al
, bl
, cl
, dl
, m
[5], 0x8f1bbcdc, 6); bl
= rotl(bl
, 10)
22266 dl
= fn4(dl
, el
, al
, bl
, cl
, m
[6], 0x8f1bbcdc, 5); al
= rotl(al
, 10)
22267 cl
= fn4(cl
, dl
, el
, al
, bl
, m
[2], 0x8f1bbcdc, 12); el
= rotl(el
, 10)
22269 // Mj = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
22271 // Sj = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
22272 bl
= fn5(bl
, cl
, dl
, el
, al
, m
[4], 0xa953fd4e, 9); dl
= rotl(dl
, 10)
22273 al
= fn5(al
, bl
, cl
, dl
, el
, m
[0], 0xa953fd4e, 15); cl
= rotl(cl
, 10)
22274 el
= fn5(el
, al
, bl
, cl
, dl
, m
[5], 0xa953fd4e, 5); bl
= rotl(bl
, 10)
22275 dl
= fn5(dl
, el
, al
, bl
, cl
, m
[9], 0xa953fd4e, 11); al
= rotl(al
, 10)
22276 cl
= fn5(cl
, dl
, el
, al
, bl
, m
[7], 0xa953fd4e, 6); el
= rotl(el
, 10)
22277 bl
= fn5(bl
, cl
, dl
, el
, al
, m
[12], 0xa953fd4e, 8); dl
= rotl(dl
, 10)
22278 al
= fn5(al
, bl
, cl
, dl
, el
, m
[2], 0xa953fd4e, 13); cl
= rotl(cl
, 10)
22279 el
= fn5(el
, al
, bl
, cl
, dl
, m
[10], 0xa953fd4e, 12); bl
= rotl(bl
, 10)
22280 dl
= fn5(dl
, el
, al
, bl
, cl
, m
[14], 0xa953fd4e, 5); al
= rotl(al
, 10)
22281 cl
= fn5(cl
, dl
, el
, al
, bl
, m
[1], 0xa953fd4e, 12); el
= rotl(el
, 10)
22282 bl
= fn5(bl
, cl
, dl
, el
, al
, m
[3], 0xa953fd4e, 13); dl
= rotl(dl
, 10)
22283 al
= fn5(al
, bl
, cl
, dl
, el
, m
[8], 0xa953fd4e, 14); cl
= rotl(cl
, 10)
22284 el
= fn5(el
, al
, bl
, cl
, dl
, m
[11], 0xa953fd4e, 11); bl
= rotl(bl
, 10)
22285 dl
= fn5(dl
, el
, al
, bl
, cl
, m
[6], 0xa953fd4e, 8); al
= rotl(al
, 10)
22286 cl
= fn5(cl
, dl
, el
, al
, bl
, m
[15], 0xa953fd4e, 5); el
= rotl(el
, 10)
22287 bl
= fn5(bl
, cl
, dl
, el
, al
, m
[13], 0xa953fd4e, 6); dl
= rotl(dl
, 10)
22295 // M'j = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
22297 // S'j = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
22298 ar
= fn5(ar
, br
, cr
, dr
, er
, m
[5], 0x50a28be6, 8); cr
= rotl(cr
, 10)
22299 er
= fn5(er
, ar
, br
, cr
, dr
, m
[14], 0x50a28be6, 9); br
= rotl(br
, 10)
22300 dr
= fn5(dr
, er
, ar
, br
, cr
, m
[7], 0x50a28be6, 9); ar
= rotl(ar
, 10)
22301 cr
= fn5(cr
, dr
, er
, ar
, br
, m
[0], 0x50a28be6, 11); er
= rotl(er
, 10)
22302 br
= fn5(br
, cr
, dr
, er
, ar
, m
[9], 0x50a28be6, 13); dr
= rotl(dr
, 10)
22303 ar
= fn5(ar
, br
, cr
, dr
, er
, m
[2], 0x50a28be6, 15); cr
= rotl(cr
, 10)
22304 er
= fn5(er
, ar
, br
, cr
, dr
, m
[11], 0x50a28be6, 15); br
= rotl(br
, 10)
22305 dr
= fn5(dr
, er
, ar
, br
, cr
, m
[4], 0x50a28be6, 5); ar
= rotl(ar
, 10)
22306 cr
= fn5(cr
, dr
, er
, ar
, br
, m
[13], 0x50a28be6, 7); er
= rotl(er
, 10)
22307 br
= fn5(br
, cr
, dr
, er
, ar
, m
[6], 0x50a28be6, 7); dr
= rotl(dr
, 10)
22308 ar
= fn5(ar
, br
, cr
, dr
, er
, m
[15], 0x50a28be6, 8); cr
= rotl(cr
, 10)
22309 er
= fn5(er
, ar
, br
, cr
, dr
, m
[8], 0x50a28be6, 11); br
= rotl(br
, 10)
22310 dr
= fn5(dr
, er
, ar
, br
, cr
, m
[1], 0x50a28be6, 14); ar
= rotl(ar
, 10)
22311 cr
= fn5(cr
, dr
, er
, ar
, br
, m
[10], 0x50a28be6, 14); er
= rotl(er
, 10)
22312 br
= fn5(br
, cr
, dr
, er
, ar
, m
[3], 0x50a28be6, 12); dr
= rotl(dr
, 10)
22313 ar
= fn5(ar
, br
, cr
, dr
, er
, m
[12], 0x50a28be6, 6); cr
= rotl(cr
, 10)
22315 // M'j = 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
22317 // S'j = 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
22318 er
= fn4(er
, ar
, br
, cr
, dr
, m
[6], 0x5c4dd124, 9); br
= rotl(br
, 10)
22319 dr
= fn4(dr
, er
, ar
, br
, cr
, m
[11], 0x5c4dd124, 13); ar
= rotl(ar
, 10)
22320 cr
= fn4(cr
, dr
, er
, ar
, br
, m
[3], 0x5c4dd124, 15); er
= rotl(er
, 10)
22321 br
= fn4(br
, cr
, dr
, er
, ar
, m
[7], 0x5c4dd124, 7); dr
= rotl(dr
, 10)
22322 ar
= fn4(ar
, br
, cr
, dr
, er
, m
[0], 0x5c4dd124, 12); cr
= rotl(cr
, 10)
22323 er
= fn4(er
, ar
, br
, cr
, dr
, m
[13], 0x5c4dd124, 8); br
= rotl(br
, 10)
22324 dr
= fn4(dr
, er
, ar
, br
, cr
, m
[5], 0x5c4dd124, 9); ar
= rotl(ar
, 10)
22325 cr
= fn4(cr
, dr
, er
, ar
, br
, m
[10], 0x5c4dd124, 11); er
= rotl(er
, 10)
22326 br
= fn4(br
, cr
, dr
, er
, ar
, m
[14], 0x5c4dd124, 7); dr
= rotl(dr
, 10)
22327 ar
= fn4(ar
, br
, cr
, dr
, er
, m
[15], 0x5c4dd124, 7); cr
= rotl(cr
, 10)
22328 er
= fn4(er
, ar
, br
, cr
, dr
, m
[8], 0x5c4dd124, 12); br
= rotl(br
, 10)
22329 dr
= fn4(dr
, er
, ar
, br
, cr
, m
[12], 0x5c4dd124, 7); ar
= rotl(ar
, 10)
22330 cr
= fn4(cr
, dr
, er
, ar
, br
, m
[4], 0x5c4dd124, 6); er
= rotl(er
, 10)
22331 br
= fn4(br
, cr
, dr
, er
, ar
, m
[9], 0x5c4dd124, 15); dr
= rotl(dr
, 10)
22332 ar
= fn4(ar
, br
, cr
, dr
, er
, m
[1], 0x5c4dd124, 13); cr
= rotl(cr
, 10)
22333 er
= fn4(er
, ar
, br
, cr
, dr
, m
[2], 0x5c4dd124, 11); br
= rotl(br
, 10)
22335 // M'j = 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
22337 // S'j = 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
22338 dr
= fn3(dr
, er
, ar
, br
, cr
, m
[15], 0x6d703ef3, 9); ar
= rotl(ar
, 10)
22339 cr
= fn3(cr
, dr
, er
, ar
, br
, m
[5], 0x6d703ef3, 7); er
= rotl(er
, 10)
22340 br
= fn3(br
, cr
, dr
, er
, ar
, m
[1], 0x6d703ef3, 15); dr
= rotl(dr
, 10)
22341 ar
= fn3(ar
, br
, cr
, dr
, er
, m
[3], 0x6d703ef3, 11); cr
= rotl(cr
, 10)
22342 er
= fn3(er
, ar
, br
, cr
, dr
, m
[7], 0x6d703ef3, 8); br
= rotl(br
, 10)
22343 dr
= fn3(dr
, er
, ar
, br
, cr
, m
[14], 0x6d703ef3, 6); ar
= rotl(ar
, 10)
22344 cr
= fn3(cr
, dr
, er
, ar
, br
, m
[6], 0x6d703ef3, 6); er
= rotl(er
, 10)
22345 br
= fn3(br
, cr
, dr
, er
, ar
, m
[9], 0x6d703ef3, 14); dr
= rotl(dr
, 10)
22346 ar
= fn3(ar
, br
, cr
, dr
, er
, m
[11], 0x6d703ef3, 12); cr
= rotl(cr
, 10)
22347 er
= fn3(er
, ar
, br
, cr
, dr
, m
[8], 0x6d703ef3, 13); br
= rotl(br
, 10)
22348 dr
= fn3(dr
, er
, ar
, br
, cr
, m
[12], 0x6d703ef3, 5); ar
= rotl(ar
, 10)
22349 cr
= fn3(cr
, dr
, er
, ar
, br
, m
[2], 0x6d703ef3, 14); er
= rotl(er
, 10)
22350 br
= fn3(br
, cr
, dr
, er
, ar
, m
[10], 0x6d703ef3, 13); dr
= rotl(dr
, 10)
22351 ar
= fn3(ar
, br
, cr
, dr
, er
, m
[0], 0x6d703ef3, 13); cr
= rotl(cr
, 10)
22352 er
= fn3(er
, ar
, br
, cr
, dr
, m
[4], 0x6d703ef3, 7); br
= rotl(br
, 10)
22353 dr
= fn3(dr
, er
, ar
, br
, cr
, m
[13], 0x6d703ef3, 5); ar
= rotl(ar
, 10)
22355 // M'j = 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
22357 // S'j = 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
22358 cr
= fn2(cr
, dr
, er
, ar
, br
, m
[8], 0x7a6d76e9, 15); er
= rotl(er
, 10)
22359 br
= fn2(br
, cr
, dr
, er
, ar
, m
[6], 0x7a6d76e9, 5); dr
= rotl(dr
, 10)
22360 ar
= fn2(ar
, br
, cr
, dr
, er
, m
[4], 0x7a6d76e9, 8); cr
= rotl(cr
, 10)
22361 er
= fn2(er
, ar
, br
, cr
, dr
, m
[1], 0x7a6d76e9, 11); br
= rotl(br
, 10)
22362 dr
= fn2(dr
, er
, ar
, br
, cr
, m
[3], 0x7a6d76e9, 14); ar
= rotl(ar
, 10)
22363 cr
= fn2(cr
, dr
, er
, ar
, br
, m
[11], 0x7a6d76e9, 14); er
= rotl(er
, 10)
22364 br
= fn2(br
, cr
, dr
, er
, ar
, m
[15], 0x7a6d76e9, 6); dr
= rotl(dr
, 10)
22365 ar
= fn2(ar
, br
, cr
, dr
, er
, m
[0], 0x7a6d76e9, 14); cr
= rotl(cr
, 10)
22366 er
= fn2(er
, ar
, br
, cr
, dr
, m
[5], 0x7a6d76e9, 6); br
= rotl(br
, 10)
22367 dr
= fn2(dr
, er
, ar
, br
, cr
, m
[12], 0x7a6d76e9, 9); ar
= rotl(ar
, 10)
22368 cr
= fn2(cr
, dr
, er
, ar
, br
, m
[2], 0x7a6d76e9, 12); er
= rotl(er
, 10)
22369 br
= fn2(br
, cr
, dr
, er
, ar
, m
[13], 0x7a6d76e9, 9); dr
= rotl(dr
, 10)
22370 ar
= fn2(ar
, br
, cr
, dr
, er
, m
[9], 0x7a6d76e9, 12); cr
= rotl(cr
, 10)
22371 er
= fn2(er
, ar
, br
, cr
, dr
, m
[7], 0x7a6d76e9, 5); br
= rotl(br
, 10)
22372 dr
= fn2(dr
, er
, ar
, br
, cr
, m
[10], 0x7a6d76e9, 15); ar
= rotl(ar
, 10)
22373 cr
= fn2(cr
, dr
, er
, ar
, br
, m
[14], 0x7a6d76e9, 8); er
= rotl(er
, 10)
22375 // M'j = 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
22377 // S'j = 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
22378 br
= fn1(br
, cr
, dr
, er
, ar
, m
[12], 0x00000000, 8); dr
= rotl(dr
, 10)
22379 ar
= fn1(ar
, br
, cr
, dr
, er
, m
[15], 0x00000000, 5); cr
= rotl(cr
, 10)
22380 er
= fn1(er
, ar
, br
, cr
, dr
, m
[10], 0x00000000, 12); br
= rotl(br
, 10)
22381 dr
= fn1(dr
, er
, ar
, br
, cr
, m
[4], 0x00000000, 9); ar
= rotl(ar
, 10)
22382 cr
= fn1(cr
, dr
, er
, ar
, br
, m
[1], 0x00000000, 12); er
= rotl(er
, 10)
22383 br
= fn1(br
, cr
, dr
, er
, ar
, m
[5], 0x00000000, 5); dr
= rotl(dr
, 10)
22384 ar
= fn1(ar
, br
, cr
, dr
, er
, m
[8], 0x00000000, 14); cr
= rotl(cr
, 10)
22385 er
= fn1(er
, ar
, br
, cr
, dr
, m
[7], 0x00000000, 6); br
= rotl(br
, 10)
22386 dr
= fn1(dr
, er
, ar
, br
, cr
, m
[6], 0x00000000, 8); ar
= rotl(ar
, 10)
22387 cr
= fn1(cr
, dr
, er
, ar
, br
, m
[2], 0x00000000, 13); er
= rotl(er
, 10)
22388 br
= fn1(br
, cr
, dr
, er
, ar
, m
[13], 0x00000000, 6); dr
= rotl(dr
, 10)
22389 ar
= fn1(ar
, br
, cr
, dr
, er
, m
[14], 0x00000000, 5); cr
= rotl(cr
, 10)
22390 er
= fn1(er
, ar
, br
, cr
, dr
, m
[0], 0x00000000, 15); br
= rotl(br
, 10)
22391 dr
= fn1(dr
, er
, ar
, br
, cr
, m
[3], 0x00000000, 13); ar
= rotl(ar
, 10)
22392 cr
= fn1(cr
, dr
, er
, ar
, br
, m
[9], 0x00000000, 11); er
= rotl(er
, 10)
22393 br
= fn1(br
, cr
, dr
, er
, ar
, m
[11], 0x00000000, 11); dr
= rotl(dr
, 10)
22396 var t
= (this._b
+ cl
+ dr
) | 0
22397 this._b
= (this._c
+ dl
+ er
) | 0
22398 this._c
= (this._d
+ el
+ ar
) | 0
22399 this._d
= (this._e
+ al
+ br
) | 0
22400 this._e
= (this._a
+ bl
+ cr
) | 0
22404 RIPEMD160
.prototype._digest = function () {
22405 // create padding and handle blocks
22406 this._block
[this._blockOffset
++] = 0x80
22407 if (this._blockOffset
> 56) {
22408 this._block
.fill(0, this._blockOffset
, 64)
22410 this._blockOffset
= 0
22413 this._block
.fill(0, this._blockOffset
, 56)
22414 this._block
.writeUInt32LE(this._length
[0], 56)
22415 this._block
.writeUInt32LE(this._length
[1], 60)
22419 var buffer
= new Buffer(20)
22420 buffer
.writeInt32LE(this._a
, 0)
22421 buffer
.writeInt32LE(this._b
, 4)
22422 buffer
.writeInt32LE(this._c
, 8)
22423 buffer
.writeInt32LE(this._d
, 12)
22424 buffer
.writeInt32LE(this._e
, 16)
22428 function rotl (x
, n
) {
22429 return (x
<< n
) | (x
>>> (32 - n
))
22432 function fn1 (a
, b
, c
, d
, e
, m
, k
, s
) {
22433 return (rotl((a
+ (b
^ c
^ d
) + m
+ k
) | 0, s
) + e
) | 0
22436 function fn2 (a
, b
, c
, d
, e
, m
, k
, s
) {
22437 return (rotl((a
+ ((b
& c
) | ((~b
) & d
)) + m
+ k
) | 0, s
) + e
) | 0
22440 function fn3 (a
, b
, c
, d
, e
, m
, k
, s
) {
22441 return (rotl((a
+ ((b
| (~c
)) ^ d
) + m
+ k
) | 0, s
) + e
) | 0
22444 function fn4 (a
, b
, c
, d
, e
, m
, k
, s
) {
22445 return (rotl((a
+ ((b
& d
) | (c
& (~d
))) + m
+ k
) | 0, s
) + e
) | 0
22448 function fn5 (a
, b
, c
, d
, e
, m
, k
, s
) {
22449 return (rotl((a
+ (b
^ (c
| (~d
))) + m
+ k
) | 0, s
) + e
) | 0
22452 module
.exports
= RIPEMD160
22454 }).call(this,require("buffer").Buffer
)
22455 },{"buffer":5,"hash-base":113,"inherits":121}],128:[function(require
,module
,exports
){
22456 /* eslint-disable node/no-deprecated-api */
22457 var buffer
= require('buffer')
22458 var Buffer
= buffer
.Buffer
22460 // alternative to using Object.keys for old browsers
22461 function copyProps (src
, dst
) {
22462 for (var key
in src
) {
22463 dst
[key
] = src
[key
]
22466 if (Buffer
.from && Buffer
.alloc
&& Buffer
.allocUnsafe
&& Buffer
.allocUnsafeSlow
) {
22467 module
.exports
= buffer
22469 // Copy properties from require('buffer')
22470 copyProps(buffer
, exports
)
22471 exports
.Buffer
= SafeBuffer
22474 function SafeBuffer (arg
, encodingOrOffset
, length
) {
22475 return Buffer(arg
, encodingOrOffset
, length
)
22478 // Copy static methods from Buffer
22479 copyProps(Buffer
, SafeBuffer
)
22481 SafeBuffer
.from = function (arg
, encodingOrOffset
, length
) {
22482 if (typeof arg
=== 'number') {
22483 throw new TypeError('Argument must not be a number')
22485 return Buffer(arg
, encodingOrOffset
, length
)
22488 SafeBuffer
.alloc = function (size
, fill
, encoding
) {
22489 if (typeof size
!== 'number') {
22490 throw new TypeError('Argument must be a number')
22492 var buf
= Buffer(size
)
22493 if (fill
!== undefined) {
22494 if (typeof encoding
=== 'string') {
22495 buf
.fill(fill
, encoding
)
22505 SafeBuffer
.allocUnsafe = function (size
) {
22506 if (typeof size
!== 'number') {
22507 throw new TypeError('Argument must be a number')
22509 return Buffer(size
)
22512 SafeBuffer
.allocUnsafeSlow = function (size
) {
22513 if (typeof size
!== 'number') {
22514 throw new TypeError('Argument must be a number')
22516 return buffer
.SlowBuffer(size
)
22519 },{"buffer":5}],129:[function(require
,module
,exports
){
22520 var Buffer
= require('safe-buffer').Buffer
22522 // prototype class for hash functions
22523 function Hash (blockSize
, finalSize
) {
22524 this._block
= Buffer
.alloc(blockSize
)
22525 this._finalSize
= finalSize
22526 this._blockSize
= blockSize
22530 Hash
.prototype.update = function (data
, enc
) {
22531 if (typeof data
=== 'string') {
22532 enc
= enc
|| 'utf8'
22533 data
= Buffer
.from(data
, enc
)
22536 var block
= this._block
22537 var blockSize
= this._blockSize
22538 var length
= data
.length
22539 var accum
= this._len
22541 for (var offset
= 0; offset
< length
;) {
22542 var assigned
= accum
% blockSize
22543 var remainder
= Math
.min(length
- offset
, blockSize
- assigned
)
22545 for (var i
= 0; i
< remainder
; i
++) {
22546 block
[assigned
+ i
] = data
[offset
+ i
]
22550 offset
+= remainder
22552 if ((accum
% blockSize
) === 0) {
22553 this._update(block
)
22557 this._len
+= length
22561 Hash
.prototype.digest = function (enc
) {
22562 var rem
= this._len
% this._blockSize
22564 this._block
[rem
] = 0x80
22566 // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
22567 // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
22568 this._block
.fill(0, rem
+ 1)
22570 if (rem
>= this._finalSize
) {
22571 this._update(this._block
)
22572 this._block
.fill(0)
22575 var bits
= this._len
* 8
22578 if (bits
<= 0xffffffff) {
22579 this._block
.writeUInt32BE(bits
, this._blockSize
- 4)
22583 var lowBits
= bits
& 0xffffffff
22584 var highBits
= (bits
- lowBits
) / 0x100000000
22586 this._block
.writeUInt32BE(highBits
, this._blockSize
- 8)
22587 this._block
.writeUInt32BE(lowBits
, this._blockSize
- 4)
22590 this._update(this._block
)
22591 var hash
= this._hash()
22593 return enc
? hash
.toString(enc
) : hash
22596 Hash
.prototype._update = function () {
22597 throw new Error('_update must be implemented by subclass')
22600 module
.exports
= Hash
22602 },{"safe-buffer":128}],130:[function(require
,module
,exports
){
22603 var exports
= module
.exports
= function SHA (algorithm
) {
22604 algorithm
= algorithm
.toLowerCase()
22606 var Algorithm
= exports
[algorithm
]
22607 if (!Algorithm
) throw new Error(algorithm
+ ' is not supported (we accept pull requests)')
22609 return new Algorithm()
22612 exports
.sha
= require('./sha')
22613 exports
.sha1
= require('./sha1')
22614 exports
.sha224
= require('./sha224')
22615 exports
.sha256
= require('./sha256')
22616 exports
.sha384
= require('./sha384')
22617 exports
.sha512
= require('./sha512')
22619 },{"./sha":131,"./sha1":132,"./sha224":133,"./sha256":134,"./sha384":135,"./sha512":136}],131:[function(require
,module
,exports
){
22621 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
22622 * in FIPS PUB 180-1
22623 * This source code is derived from sha1.js of the same repository.
22624 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
22625 * operation was added.
22628 var inherits
= require('inherits')
22629 var Hash
= require('./hash')
22630 var Buffer
= require('safe-buffer').Buffer
22633 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
22636 var W
= new Array(80)
22642 Hash
.call(this, 64, 56)
22645 inherits(Sha
, Hash
)
22647 Sha
.prototype.init = function () {
22648 this._a
= 0x67452301
22649 this._b
= 0xefcdab89
22650 this._c
= 0x98badcfe
22651 this._d
= 0x10325476
22652 this._e
= 0xc3d2e1f0
22657 function rotl5 (num
) {
22658 return (num
<< 5) | (num
>>> 27)
22661 function rotl30 (num
) {
22662 return (num
<< 30) | (num
>>> 2)
22665 function ft (s
, b
, c
, d
) {
22666 if (s
=== 0) return (b
& c
) | ((~b
) & d
)
22667 if (s
=== 2) return (b
& c
) | (b
& d
) | (c
& d
)
22671 Sha
.prototype._update = function (M
) {
22674 var a
= this._a
| 0
22675 var b
= this._b
| 0
22676 var c
= this._c
| 0
22677 var d
= this._d
| 0
22678 var e
= this._e
| 0
22680 for (var i
= 0; i
< 16; ++i
) W
[i
] = M
.readInt32BE(i
* 4)
22681 for (; i
< 80; ++i
) W
[i
] = W
[i
- 3] ^ W
[i
- 8] ^ W
[i
- 14] ^ W
[i
- 16]
22683 for (var j
= 0; j
< 80; ++j
) {
22685 var t
= (rotl5(a
) + ft(s
, b
, c
, d
) + e
+ W
[j
] + K
[s
]) | 0
22694 this._a
= (a
+ this._a
) | 0
22695 this._b
= (b
+ this._b
) | 0
22696 this._c
= (c
+ this._c
) | 0
22697 this._d
= (d
+ this._d
) | 0
22698 this._e
= (e
+ this._e
) | 0
22701 Sha
.prototype._hash = function () {
22702 var H
= Buffer
.allocUnsafe(20)
22704 H
.writeInt32BE(this._a
| 0, 0)
22705 H
.writeInt32BE(this._b
| 0, 4)
22706 H
.writeInt32BE(this._c
| 0, 8)
22707 H
.writeInt32BE(this._d
| 0, 12)
22708 H
.writeInt32BE(this._e
| 0, 16)
22713 module
.exports
= Sha
22715 },{"./hash":129,"inherits":121,"safe-buffer":128}],132:[function(require
,module
,exports
){
22717 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
22718 * in FIPS PUB 180-1
22719 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
22720 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
22721 * Distributed under the BSD License
22722 * See http://pajhome.org.uk/crypt/md5 for details.
22725 var inherits
= require('inherits')
22726 var Hash
= require('./hash')
22727 var Buffer
= require('safe-buffer').Buffer
22730 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
22733 var W
= new Array(80)
22739 Hash
.call(this, 64, 56)
22742 inherits(Sha1
, Hash
)
22744 Sha1
.prototype.init = function () {
22745 this._a
= 0x67452301
22746 this._b
= 0xefcdab89
22747 this._c
= 0x98badcfe
22748 this._d
= 0x10325476
22749 this._e
= 0xc3d2e1f0
22754 function rotl1 (num
) {
22755 return (num
<< 1) | (num
>>> 31)
22758 function rotl5 (num
) {
22759 return (num
<< 5) | (num
>>> 27)
22762 function rotl30 (num
) {
22763 return (num
<< 30) | (num
>>> 2)
22766 function ft (s
, b
, c
, d
) {
22767 if (s
=== 0) return (b
& c
) | ((~b
) & d
)
22768 if (s
=== 2) return (b
& c
) | (b
& d
) | (c
& d
)
22772 Sha1
.prototype._update = function (M
) {
22775 var a
= this._a
| 0
22776 var b
= this._b
| 0
22777 var c
= this._c
| 0
22778 var d
= this._d
| 0
22779 var e
= this._e
| 0
22781 for (var i
= 0; i
< 16; ++i
) W
[i
] = M
.readInt32BE(i
* 4)
22782 for (; i
< 80; ++i
) W
[i
] = rotl1(W
[i
- 3] ^ W
[i
- 8] ^ W
[i
- 14] ^ W
[i
- 16])
22784 for (var j
= 0; j
< 80; ++j
) {
22786 var t
= (rotl5(a
) + ft(s
, b
, c
, d
) + e
+ W
[j
] + K
[s
]) | 0
22795 this._a
= (a
+ this._a
) | 0
22796 this._b
= (b
+ this._b
) | 0
22797 this._c
= (c
+ this._c
) | 0
22798 this._d
= (d
+ this._d
) | 0
22799 this._e
= (e
+ this._e
) | 0
22802 Sha1
.prototype._hash = function () {
22803 var H
= Buffer
.allocUnsafe(20)
22805 H
.writeInt32BE(this._a
| 0, 0)
22806 H
.writeInt32BE(this._b
| 0, 4)
22807 H
.writeInt32BE(this._c
| 0, 8)
22808 H
.writeInt32BE(this._d
| 0, 12)
22809 H
.writeInt32BE(this._e
| 0, 16)
22814 module
.exports
= Sha1
22816 },{"./hash":129,"inherits":121,"safe-buffer":128}],133:[function(require
,module
,exports
){
22818 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
22820 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
22821 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
22825 var inherits
= require('inherits')
22826 var Sha256
= require('./sha256')
22827 var Hash
= require('./hash')
22828 var Buffer
= require('safe-buffer').Buffer
22830 var W
= new Array(64)
22832 function Sha224 () {
22835 this._w
= W
// new Array(64)
22837 Hash
.call(this, 64, 56)
22840 inherits(Sha224
, Sha256
)
22842 Sha224
.prototype.init = function () {
22843 this._a
= 0xc1059ed8
22844 this._b
= 0x367cd507
22845 this._c
= 0x3070dd17
22846 this._d
= 0xf70e5939
22847 this._e
= 0xffc00b31
22848 this._f
= 0x68581511
22849 this._g
= 0x64f98fa7
22850 this._h
= 0xbefa4fa4
22855 Sha224
.prototype._hash = function () {
22856 var H
= Buffer
.allocUnsafe(28)
22858 H
.writeInt32BE(this._a
, 0)
22859 H
.writeInt32BE(this._b
, 4)
22860 H
.writeInt32BE(this._c
, 8)
22861 H
.writeInt32BE(this._d
, 12)
22862 H
.writeInt32BE(this._e
, 16)
22863 H
.writeInt32BE(this._f
, 20)
22864 H
.writeInt32BE(this._g
, 24)
22869 module
.exports
= Sha224
22871 },{"./hash":129,"./sha256":134,"inherits":121,"safe-buffer":128}],134:[function(require
,module
,exports
){
22873 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
22875 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
22876 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
22880 var inherits
= require('inherits')
22881 var Hash
= require('./hash')
22882 var Buffer
= require('safe-buffer').Buffer
22885 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
22886 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
22887 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
22888 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
22889 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
22890 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
22891 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
22892 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
22893 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
22894 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
22895 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
22896 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
22897 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
22898 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
22899 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
22900 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
22903 var W
= new Array(64)
22905 function Sha256 () {
22908 this._w
= W
// new Array(64)
22910 Hash
.call(this, 64, 56)
22913 inherits(Sha256
, Hash
)
22915 Sha256
.prototype.init = function () {
22916 this._a
= 0x6a09e667
22917 this._b
= 0xbb67ae85
22918 this._c
= 0x3c6ef372
22919 this._d
= 0xa54ff53a
22920 this._e
= 0x510e527f
22921 this._f
= 0x9b05688c
22922 this._g
= 0x1f83d9ab
22923 this._h
= 0x5be0cd19
22928 function ch (x
, y
, z
) {
22929 return z
^ (x
& (y
^ z
))
22932 function maj (x
, y
, z
) {
22933 return (x
& y
) | (z
& (x
| y
))
22936 function sigma0 (x
) {
22937 return (x
>>> 2 | x
<< 30) ^ (x
>>> 13 | x
<< 19) ^ (x
>>> 22 | x
<< 10)
22940 function sigma1 (x
) {
22941 return (x
>>> 6 | x
<< 26) ^ (x
>>> 11 | x
<< 21) ^ (x
>>> 25 | x
<< 7)
22944 function gamma0 (x
) {
22945 return (x
>>> 7 | x
<< 25) ^ (x
>>> 18 | x
<< 14) ^ (x
>>> 3)
22948 function gamma1 (x
) {
22949 return (x
>>> 17 | x
<< 15) ^ (x
>>> 19 | x
<< 13) ^ (x
>>> 10)
22952 Sha256
.prototype._update = function (M
) {
22955 var a
= this._a
| 0
22956 var b
= this._b
| 0
22957 var c
= this._c
| 0
22958 var d
= this._d
| 0
22959 var e
= this._e
| 0
22960 var f
= this._f
| 0
22961 var g
= this._g
| 0
22962 var h
= this._h
| 0
22964 for (var i
= 0; i
< 16; ++i
) W
[i
] = M
.readInt32BE(i
* 4)
22965 for (; i
< 64; ++i
) W
[i
] = (gamma1(W
[i
- 2]) + W
[i
- 7] + gamma0(W
[i
- 15]) + W
[i
- 16]) | 0
22967 for (var j
= 0; j
< 64; ++j
) {
22968 var T1
= (h
+ sigma1(e
) + ch(e
, f
, g
) + K
[j
] + W
[j
]) | 0
22969 var T2
= (sigma0(a
) + maj(a
, b
, c
)) | 0
22981 this._a
= (a
+ this._a
) | 0
22982 this._b
= (b
+ this._b
) | 0
22983 this._c
= (c
+ this._c
) | 0
22984 this._d
= (d
+ this._d
) | 0
22985 this._e
= (e
+ this._e
) | 0
22986 this._f
= (f
+ this._f
) | 0
22987 this._g
= (g
+ this._g
) | 0
22988 this._h
= (h
+ this._h
) | 0
22991 Sha256
.prototype._hash = function () {
22992 var H
= Buffer
.allocUnsafe(32)
22994 H
.writeInt32BE(this._a
, 0)
22995 H
.writeInt32BE(this._b
, 4)
22996 H
.writeInt32BE(this._c
, 8)
22997 H
.writeInt32BE(this._d
, 12)
22998 H
.writeInt32BE(this._e
, 16)
22999 H
.writeInt32BE(this._f
, 20)
23000 H
.writeInt32BE(this._g
, 24)
23001 H
.writeInt32BE(this._h
, 28)
23006 module
.exports
= Sha256
23008 },{"./hash":129,"inherits":121,"safe-buffer":128}],135:[function(require
,module
,exports
){
23009 var inherits
= require('inherits')
23010 var SHA512
= require('./sha512')
23011 var Hash
= require('./hash')
23012 var Buffer
= require('safe-buffer').Buffer
23014 var W
= new Array(160)
23016 function Sha384 () {
23020 Hash
.call(this, 128, 112)
23023 inherits(Sha384
, SHA512
)
23025 Sha384
.prototype.init = function () {
23026 this._ah
= 0xcbbb9d5d
23027 this._bh
= 0x629a292a
23028 this._ch
= 0x9159015a
23029 this._dh
= 0x152fecd8
23030 this._eh
= 0x67332667
23031 this._fh
= 0x8eb44a87
23032 this._gh
= 0xdb0c2e0d
23033 this._hh
= 0x47b5481d
23035 this._al
= 0xc1059ed8
23036 this._bl
= 0x367cd507
23037 this._cl
= 0x3070dd17
23038 this._dl
= 0xf70e5939
23039 this._el
= 0xffc00b31
23040 this._fl
= 0x68581511
23041 this._gl
= 0x64f98fa7
23042 this._hl
= 0xbefa4fa4
23047 Sha384
.prototype._hash = function () {
23048 var H
= Buffer
.allocUnsafe(48)
23050 function writeInt64BE (h
, l
, offset
) {
23051 H
.writeInt32BE(h
, offset
)
23052 H
.writeInt32BE(l
, offset
+ 4)
23055 writeInt64BE(this._ah
, this._al
, 0)
23056 writeInt64BE(this._bh
, this._bl
, 8)
23057 writeInt64BE(this._ch
, this._cl
, 16)
23058 writeInt64BE(this._dh
, this._dl
, 24)
23059 writeInt64BE(this._eh
, this._el
, 32)
23060 writeInt64BE(this._fh
, this._fl
, 40)
23065 module
.exports
= Sha384
23067 },{"./hash":129,"./sha512":136,"inherits":121,"safe-buffer":128}],136:[function(require
,module
,exports
){
23068 var inherits
= require('inherits')
23069 var Hash
= require('./hash')
23070 var Buffer
= require('safe-buffer').Buffer
23073 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
23074 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
23075 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
23076 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
23077 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
23078 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
23079 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
23080 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
23081 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
23082 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
23083 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
23084 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
23085 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
23086 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
23087 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
23088 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
23089 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
23090 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
23091 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
23092 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
23093 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
23094 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
23095 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
23096 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
23097 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
23098 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
23099 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
23100 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
23101 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
23102 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
23103 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
23104 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
23105 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
23106 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
23107 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
23108 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
23109 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
23110 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
23111 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
23112 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
23115 var W
= new Array(160)
23117 function Sha512 () {
23121 Hash
.call(this, 128, 112)
23124 inherits(Sha512
, Hash
)
23126 Sha512
.prototype.init = function () {
23127 this._ah
= 0x6a09e667
23128 this._bh
= 0xbb67ae85
23129 this._ch
= 0x3c6ef372
23130 this._dh
= 0xa54ff53a
23131 this._eh
= 0x510e527f
23132 this._fh
= 0x9b05688c
23133 this._gh
= 0x1f83d9ab
23134 this._hh
= 0x5be0cd19
23136 this._al
= 0xf3bcc908
23137 this._bl
= 0x84caa73b
23138 this._cl
= 0xfe94f82b
23139 this._dl
= 0x5f1d36f1
23140 this._el
= 0xade682d1
23141 this._fl
= 0x2b3e6c1f
23142 this._gl
= 0xfb41bd6b
23143 this._hl
= 0x137e2179
23148 function Ch (x
, y
, z
) {
23149 return z
^ (x
& (y
^ z
))
23152 function maj (x
, y
, z
) {
23153 return (x
& y
) | (z
& (x
| y
))
23156 function sigma0 (x
, xl
) {
23157 return (x
>>> 28 | xl
<< 4) ^ (xl
>>> 2 | x
<< 30) ^ (xl
>>> 7 | x
<< 25)
23160 function sigma1 (x
, xl
) {
23161 return (x
>>> 14 | xl
<< 18) ^ (x
>>> 18 | xl
<< 14) ^ (xl
>>> 9 | x
<< 23)
23164 function Gamma0 (x
, xl
) {
23165 return (x
>>> 1 | xl
<< 31) ^ (x
>>> 8 | xl
<< 24) ^ (x
>>> 7)
23168 function Gamma0l (x
, xl
) {
23169 return (x
>>> 1 | xl
<< 31) ^ (x
>>> 8 | xl
<< 24) ^ (x
>>> 7 | xl
<< 25)
23172 function Gamma1 (x
, xl
) {
23173 return (x
>>> 19 | xl
<< 13) ^ (xl
>>> 29 | x
<< 3) ^ (x
>>> 6)
23176 function Gamma1l (x
, xl
) {
23177 return (x
>>> 19 | xl
<< 13) ^ (xl
>>> 29 | x
<< 3) ^ (x
>>> 6 | xl
<< 26)
23180 function getCarry (a
, b
) {
23181 return (a
>>> 0) < (b
>>> 0) ? 1 : 0
23184 Sha512
.prototype._update = function (M
) {
23187 var ah
= this._ah
| 0
23188 var bh
= this._bh
| 0
23189 var ch
= this._ch
| 0
23190 var dh
= this._dh
| 0
23191 var eh
= this._eh
| 0
23192 var fh
= this._fh
| 0
23193 var gh
= this._gh
| 0
23194 var hh
= this._hh
| 0
23196 var al
= this._al
| 0
23197 var bl
= this._bl
| 0
23198 var cl
= this._cl
| 0
23199 var dl
= this._dl
| 0
23200 var el
= this._el
| 0
23201 var fl
= this._fl
| 0
23202 var gl
= this._gl
| 0
23203 var hl
= this._hl
| 0
23205 for (var i
= 0; i
< 32; i
+= 2) {
23206 W
[i
] = M
.readInt32BE(i
* 4)
23207 W
[i
+ 1] = M
.readInt32BE(i
* 4 + 4)
23209 for (; i
< 160; i
+= 2) {
23210 var xh
= W
[i
- 15 * 2]
23211 var xl
= W
[i
- 15 * 2 + 1]
23212 var gamma0
= Gamma0(xh
, xl
)
23213 var gamma0l
= Gamma0l(xl
, xh
)
23216 xl
= W
[i
- 2 * 2 + 1]
23217 var gamma1
= Gamma1(xh
, xl
)
23218 var gamma1l
= Gamma1l(xl
, xh
)
23220 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
23221 var Wi7h
= W
[i
- 7 * 2]
23222 var Wi7l
= W
[i
- 7 * 2 + 1]
23224 var Wi16h
= W
[i
- 16 * 2]
23225 var Wi16l
= W
[i
- 16 * 2 + 1]
23227 var Wil
= (gamma0l
+ Wi7l
) | 0
23228 var Wih
= (gamma0
+ Wi7h
+ getCarry(Wil
, gamma0l
)) | 0
23229 Wil
= (Wil
+ gamma1l
) | 0
23230 Wih
= (Wih
+ gamma1
+ getCarry(Wil
, gamma1l
)) | 0
23231 Wil
= (Wil
+ Wi16l
) | 0
23232 Wih
= (Wih
+ Wi16h
+ getCarry(Wil
, Wi16l
)) | 0
23238 for (var j
= 0; j
< 160; j
+= 2) {
23242 var majh
= maj(ah
, bh
, ch
)
23243 var majl
= maj(al
, bl
, cl
)
23245 var sigma0h
= sigma0(ah
, al
)
23246 var sigma0l
= sigma0(al
, ah
)
23247 var sigma1h
= sigma1(eh
, el
)
23248 var sigma1l
= sigma1(el
, eh
)
23250 // t1 = h + sigma1 + ch + K[j] + W[j]
23254 var chh
= Ch(eh
, fh
, gh
)
23255 var chl
= Ch(el
, fl
, gl
)
23257 var t1l
= (hl
+ sigma1l
) | 0
23258 var t1h
= (hh
+ sigma1h
+ getCarry(t1l
, hl
)) | 0
23259 t1l
= (t1l
+ chl
) | 0
23260 t1h
= (t1h
+ chh
+ getCarry(t1l
, chl
)) | 0
23261 t1l
= (t1l
+ Kil
) | 0
23262 t1h
= (t1h
+ Kih
+ getCarry(t1l
, Kil
)) | 0
23263 t1l
= (t1l
+ Wil
) | 0
23264 t1h
= (t1h
+ Wih
+ getCarry(t1l
, Wil
)) | 0
23266 // t2 = sigma0 + maj
23267 var t2l
= (sigma0l
+ majl
) | 0
23268 var t2h
= (sigma0h
+ majh
+ getCarry(t2l
, sigma0l
)) | 0
23276 el
= (dl
+ t1l
) | 0
23277 eh
= (dh
+ t1h
+ getCarry(el
, dl
)) | 0
23284 al
= (t1l
+ t2l
) | 0
23285 ah
= (t1h
+ t2h
+ getCarry(al
, t1l
)) | 0
23288 this._al
= (this._al
+ al
) | 0
23289 this._bl
= (this._bl
+ bl
) | 0
23290 this._cl
= (this._cl
+ cl
) | 0
23291 this._dl
= (this._dl
+ dl
) | 0
23292 this._el
= (this._el
+ el
) | 0
23293 this._fl
= (this._fl
+ fl
) | 0
23294 this._gl
= (this._gl
+ gl
) | 0
23295 this._hl
= (this._hl
+ hl
) | 0
23297 this._ah
= (this._ah
+ ah
+ getCarry(this._al
, al
)) | 0
23298 this._bh
= (this._bh
+ bh
+ getCarry(this._bl
, bl
)) | 0
23299 this._ch
= (this._ch
+ ch
+ getCarry(this._cl
, cl
)) | 0
23300 this._dh
= (this._dh
+ dh
+ getCarry(this._dl
, dl
)) | 0
23301 this._eh
= (this._eh
+ eh
+ getCarry(this._el
, el
)) | 0
23302 this._fh
= (this._fh
+ fh
+ getCarry(this._fl
, fl
)) | 0
23303 this._gh
= (this._gh
+ gh
+ getCarry(this._gl
, gl
)) | 0
23304 this._hh
= (this._hh
+ hh
+ getCarry(this._hl
, hl
)) | 0
23307 Sha512
.prototype._hash = function () {
23308 var H
= Buffer
.allocUnsafe(64)
23310 function writeInt64BE (h
, l
, offset
) {
23311 H
.writeInt32BE(h
, offset
)
23312 H
.writeInt32BE(l
, offset
+ 4)
23315 writeInt64BE(this._ah
, this._al
, 0)
23316 writeInt64BE(this._bh
, this._bl
, 8)
23317 writeInt64BE(this._ch
, this._cl
, 16)
23318 writeInt64BE(this._dh
, this._dl
, 24)
23319 writeInt64BE(this._eh
, this._el
, 32)
23320 writeInt64BE(this._fh
, this._fl
, 40)
23321 writeInt64BE(this._gh
, this._gl
, 48)
23322 writeInt64BE(this._hh
, this._hl
, 56)
23327 module
.exports
= Sha512
23329 },{"./hash":129,"inherits":121,"safe-buffer":128}],137:[function(require
,module
,exports
){
23330 var native = require('./native')
23332 function getTypeName (fn
) {
23333 return fn
.name
|| fn
.toString().match(/function (.*?)\s
*\(/)[1]
23336 function getValueTypeName (value
) {
23337 return native.Nil(value
) ? '' : getTypeName(value
.constructor)
23340 function getValue (value
) {
23341 if (native.Function(value
)) return ''
23342 if (native.String(value
)) return JSON
.stringify(value
)
23343 if (value
&& native.Object(value
)) return ''
23347 function tfJSON (type
) {
23348 if (native.Function(type
)) return type
.toJSON
? type
.toJSON() : getTypeName(type
)
23349 if (native.Array(type
)) return 'Array'
23350 if (type
&& native.Object(type
)) return 'Object'
23352 return type
!== undefined ? type : ''
23355 function tfErrorString (type
, value
, valueTypeName
) {
23356 var valueJson
= getValue(value
)
23358 return 'Expected ' + tfJSON(type
) + ', got' +
23359 (valueTypeName
!== '' ? ' ' + valueTypeName : '') +
23360 (valueJson
!== '' ? ' ' + valueJson : '')
23363 function TfTypeError (type
, value
, valueTypeName
) {
23364 valueTypeName
= valueTypeName
|| getValueTypeName(value
)
23365 this.message
= tfErrorString(type
, value
, valueTypeName
)
23367 Error
.captureStackTrace(this, TfTypeError
)
23369 this.__value
= value
23370 this.__valueTypeName
= valueTypeName
23373 TfTypeError
.prototype = Object
.create(Error
.prototype)
23374 TfTypeError
.prototype.constructor = TfTypeError
23376 function tfPropertyErrorString (type
, label
, name
, value
, valueTypeName
) {
23377 var description
= '" of type '
23378 if (label
=== 'key') description
= '" with key type '
23380 return tfErrorString('property "' + tfJSON(name
) + description
+ tfJSON(type
), value
, valueTypeName
)
23383 function TfPropertyTypeError (type
, property
, label
, value
, valueTypeName
) {
23385 valueTypeName
= valueTypeName
|| getValueTypeName(value
)
23386 this.message
= tfPropertyErrorString(type
, label
, property
, value
, valueTypeName
)
23388 this.message
= 'Unexpected property "' + property
+ '"'
23391 Error
.captureStackTrace(this, TfTypeError
)
23392 this.__label
= label
23393 this.__property
= property
23395 this.__value
= value
23396 this.__valueTypeName
= valueTypeName
23399 TfPropertyTypeError
.prototype = Object
.create(Error
.prototype)
23400 TfPropertyTypeError
.prototype.constructor = TfTypeError
23402 function tfCustomError (expected
, actual
) {
23403 return new TfTypeError(expected
, {}, actual
)
23406 function tfSubError (e
, property
, label
) {
23408 if (e
instanceof TfPropertyTypeError
) {
23409 property
= property
+ '.' + e
.__property
23411 e
= new TfPropertyTypeError(
23412 e
.__type
, property
, e
.__label
, e
.__value
, e
.__valueTypeName
23416 } else if (e
instanceof TfTypeError
) {
23417 e
= new TfPropertyTypeError(
23418 e
.__type
, property
, label
, e
.__value
, e
.__valueTypeName
23422 Error
.captureStackTrace(e
)
23427 TfTypeError: TfTypeError
,
23428 TfPropertyTypeError: TfPropertyTypeError
,
23429 tfCustomError: tfCustomError
,
23430 tfSubError: tfSubError
,
23432 getValueTypeName: getValueTypeName
23435 },{"./native":140}],138:[function(require
,module
,exports
){
23436 (function (Buffer
){
23437 var NATIVE
= require('./native')
23438 var ERRORS
= require('./errors')
23440 function _Buffer (value
) {
23441 return Buffer
.isBuffer(value
)
23444 function Hex (value
) {
23445 return typeof value
=== 'string' && /^([0-9a-f]{2})+$/i.test(value
)
23448 function _LengthN (type
, length
) {
23449 var name
= type
.toJSON()
23451 function Length (value
) {
23452 if (!type(value
)) return false
23453 if (value
.length
=== length
) return true
23455 throw ERRORS
.tfCustomError(name
+ '(Length: ' + length
+ ')', name
+ '(Length: ' + value
.length
+ ')')
23457 Length
.toJSON = function () { return name
}
23462 var _ArrayN
= _LengthN
.bind(null, NATIVE
.Array
)
23463 var _BufferN
= _LengthN
.bind(null, _Buffer
)
23464 var _HexN
= _LengthN
.bind(null, Hex
)
23465 var _StringN
= _LengthN
.bind(null, NATIVE
.String
)
23467 var UINT53_MAX
= Math
.pow(2, 53) - 1
23469 function Finite (value
) {
23470 return typeof value
=== 'number' && isFinite(value
)
23472 function Int8 (value
) { return ((value
<< 24) >> 24) === value
}
23473 function Int16 (value
) { return ((value
<< 16) >> 16) === value
}
23474 function Int32 (value
) { return (value
| 0) === value
}
23475 function UInt8 (value
) { return (value
& 0xff) === value
}
23476 function UInt16 (value
) { return (value
& 0xffff) === value
}
23477 function UInt32 (value
) { return (value
>>> 0) === value
}
23478 function UInt53 (value
) {
23479 return typeof value
=== 'number' &&
23481 value
<= UINT53_MAX
&&
23482 Math
.floor(value
) === value
23502 for (var typeName
in types
) {
23503 types
[typeName
].toJSON = function (t
) {
23505 }.bind(null, typeName
)
23508 module
.exports
= types
23510 }).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
23511 },{"../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10,"./errors":137,"./native":140}],139:[function(require
,module
,exports
){
23512 var ERRORS
= require('./errors')
23513 var NATIVE
= require('./native')
23516 var tfJSON
= ERRORS
.tfJSON
23517 var TfTypeError
= ERRORS
.TfTypeError
23518 var TfPropertyTypeError
= ERRORS
.TfPropertyTypeError
23519 var tfSubError
= ERRORS
.tfSubError
23520 var getValueTypeName
= ERRORS
.getValueTypeName
23523 arrayOf: function arrayOf (type
) {
23524 type
= compile(type
)
23526 function _arrayOf (array
, strict
) {
23527 if (!NATIVE
.Array(array
)) return false
23528 if (NATIVE
.Nil(array
)) return false
23530 return array
.every(function (value
, i
) {
23532 return typeforce(type
, value
, strict
)
23534 throw tfSubError(e
, i
)
23538 _arrayOf
.toJSON = function () { return '[' + tfJSON(type
) + ']' }
23543 maybe: function maybe (type
) {
23544 type
= compile(type
)
23546 function _maybe (value
, strict
) {
23547 return NATIVE
.Nil(value
) || type(value
, strict
, maybe
)
23549 _maybe
.toJSON = function () { return '?' + tfJSON(type
) }
23554 map: function map (propertyType
, propertyKeyType
) {
23555 propertyType
= compile(propertyType
)
23556 if (propertyKeyType
) propertyKeyType
= compile(propertyKeyType
)
23558 function _map (value
, strict
) {
23559 if (!NATIVE
.Object(value
)) return false
23560 if (NATIVE
.Nil(value
)) return false
23562 for (var propertyName
in value
) {
23564 if (propertyKeyType
) {
23565 typeforce(propertyKeyType
, propertyName
, strict
)
23568 throw tfSubError(e
, propertyName
, 'key')
23572 var propertyValue
= value
[propertyName
]
23573 typeforce(propertyType
, propertyValue
, strict
)
23575 throw tfSubError(e
, propertyName
)
23582 if (propertyKeyType
) {
23583 _map
.toJSON = function () {
23584 return '{' + tfJSON(propertyKeyType
) + ': ' + tfJSON(propertyType
) + '}'
23587 _map
.toJSON = function () { return '{' + tfJSON(propertyType
) + '}' }
23593 object: function object (uncompiled
) {
23596 for (var typePropertyName
in uncompiled
) {
23597 type
[typePropertyName
] = compile(uncompiled
[typePropertyName
])
23600 function _object (value
, strict
) {
23601 if (!NATIVE
.Object(value
)) return false
23602 if (NATIVE
.Nil(value
)) return false
23607 for (propertyName
in type
) {
23608 var propertyType
= type
[propertyName
]
23609 var propertyValue
= value
[propertyName
]
23611 typeforce(propertyType
, propertyValue
, strict
)
23614 throw tfSubError(e
, propertyName
)
23618 for (propertyName
in value
) {
23619 if (type
[propertyName
]) continue
23621 throw new TfPropertyTypeError(undefined, propertyName
)
23627 _object
.toJSON = function () { return tfJSON(type
) }
23632 oneOf: function oneOf () {
23633 var types
= [].slice
.call(arguments
).map(compile
)
23635 function _oneOf (value
, strict
) {
23636 return types
.some(function (type
) {
23638 return typeforce(type
, value
, strict
)
23644 _oneOf
.toJSON = function () { return types
.map(tfJSON
).join('|') }
23649 quacksLike: function quacksLike (type
) {
23650 function _quacksLike (value
) {
23651 return type
=== getValueTypeName(value
)
23653 _quacksLike
.toJSON = function () { return type
}
23658 tuple: function tuple () {
23659 var types
= [].slice
.call(arguments
).map(compile
)
23661 function _tuple (values
, strict
) {
23662 if (NATIVE
.Nil(values
)) return false
23663 if (NATIVE
.Nil(values
.length
)) return false
23664 if (strict
&& (values
.length
!== types
.length
)) return false
23666 return types
.every(function (type
, i
) {
23668 return typeforce(type
, values
[i
], strict
)
23670 throw tfSubError(e
, i
)
23674 _tuple
.toJSON = function () { return '(' + types
.map(tfJSON
).join(', ') + ')' }
23679 value: function value (expected
) {
23680 function _value (actual
) {
23681 return actual
=== expected
23683 _value
.toJSON = function () { return expected
}
23689 function compile (type
) {
23690 if (NATIVE
.String(type
)) {
23691 if (type
[0] === '?') return TYPES
.maybe(type
.slice(1))
23693 return NATIVE
[type
] || TYPES
.quacksLike(type
)
23694 } else if (type
&& NATIVE
.Object(type
)) {
23695 if (NATIVE
.Array(type
)) return TYPES
.arrayOf(type
[0])
23697 return TYPES
.object(type
)
23698 } else if (NATIVE
.Function(type
)) {
23702 return TYPES
.value(type
)
23705 function typeforce (type
, value
, strict
, surrogate
) {
23706 if (NATIVE
.Function(type
)) {
23707 if (type(value
, strict
)) return true
23709 throw new TfTypeError(surrogate
|| type
, value
)
23713 return typeforce(compile(type
), value
, strict
)
23716 // assign types to typeforce function
23717 for (var typeName
in NATIVE
) {
23718 typeforce
[typeName
] = NATIVE
[typeName
]
23721 for (typeName
in TYPES
) {
23722 typeforce
[typeName
] = TYPES
[typeName
]
23725 var EXTRA
= require('./extra')
23726 for (typeName
in EXTRA
) {
23727 typeforce
[typeName
] = EXTRA
[typeName
]
23731 function __async (type
, value
, strict
, callback
) {
23732 // default to falsy strict if using shorthand overload
23733 if (typeof strict
=== 'function') return __async(type
, value
, false, strict
)
23736 typeforce(type
, value
, strict
)
23744 typeforce
.async
= __async
23745 typeforce
.compile
= compile
23746 typeforce
.TfTypeError
= TfTypeError
23747 typeforce
.TfPropertyTypeError
= TfPropertyTypeError
23749 module
.exports
= typeforce
23751 },{"./errors":137,"./extra":138,"./native":140}],140:[function(require
,module
,exports
){
23753 Array: function (value
) { return value
!== null && value
!== undefined && value
.constructor === Array
},
23754 Boolean: function (value
) { return typeof value
=== 'boolean' },
23755 Function: function (value
) { return typeof value
=== 'function' },
23756 Nil: function (value
) { return value
=== undefined || value
=== null },
23757 Number: function (value
) { return typeof value
=== 'number' },
23758 Object: function (value
) { return typeof value
=== 'object' },
23759 String: function (value
) { return typeof value
=== 'string' },
23760 '': function () { return true }
23764 types
.Null
= types
.Nil
23766 for (var typeName
in types
) {
23767 types
[typeName
].toJSON = function (t
) {
23769 }.bind(null, typeName
)
23772 module
.exports
= types
23774 },{}],141:[function(require
,module
,exports
){
23775 (function (Buffer
){
23778 // Number.MAX_SAFE_INTEGER
23779 var MAX_SAFE_INTEGER
= 9007199254740991
23781 function checkUInt53 (n
) {
23782 if (n
< 0 || n
> MAX_SAFE_INTEGER
|| n
% 1 !== 0) throw new RangeError('value out of range')
23785 function encode (number
, buffer
, offset
) {
23786 checkUInt53(number
)
23788 if (!buffer
) buffer
= new Buffer(encodingLength(number
))
23789 if (!Buffer
.isBuffer(buffer
)) throw new TypeError('buffer must be a Buffer instance')
23790 if (!offset
) offset
= 0
23793 if (number
< 0xfd) {
23794 buffer
.writeUInt8(number
, offset
)
23798 } else if (number
<= 0xffff) {
23799 buffer
.writeUInt8(0xfd, offset
)
23800 buffer
.writeUInt16LE(number
, offset
+ 1)
23804 } else if (number
<= 0xffffffff) {
23805 buffer
.writeUInt8(0xfe, offset
)
23806 buffer
.writeUInt32LE(number
, offset
+ 1)
23811 buffer
.writeUInt8(0xff, offset
)
23812 buffer
.writeUInt32LE(number
>>> 0, offset
+ 1)
23813 buffer
.writeUInt32LE((number
/ 0x100000000) | 0, offset
+ 5)
23820 function decode (buffer
, offset
) {
23821 if (!Buffer
.isBuffer(buffer
)) throw new TypeError('buffer must be a Buffer instance')
23822 if (!offset
) offset
= 0
23824 var first
= buffer
.readUInt8(offset
)
23827 if (first
< 0xfd) {
23832 } else if (first
=== 0xfd) {
23834 return buffer
.readUInt16LE(offset
+ 1)
23837 } else if (first
=== 0xfe) {
23839 return buffer
.readUInt32LE(offset
+ 1)
23844 var lo
= buffer
.readUInt32LE(offset
+ 1)
23845 var hi
= buffer
.readUInt32LE(offset
+ 5)
23846 var number
= hi
* 0x0100000000 + lo
23847 checkUInt53(number
)
23853 function encodingLength (number
) {
23854 checkUInt53(number
)
23858 : number
<= 0xffff ? 3
23859 : number
<= 0xffffffff ? 5
23864 module
.exports
= { encode: encode
, decode: decode
, encodingLength: encodingLength
}
23866 }).call(this,require("buffer").Buffer
)
23867 },{"buffer":5}],142:[function(require
,module
,exports
){
23868 (function (Buffer
){
23869 var bs58check
= require('bs58check')
23871 function decodeRaw (buffer
, version
) {
23872 // check version only if defined
23873 if (version
!== undefined && buffer
[0] !== version
) throw new Error('Invalid network version')
23876 if (buffer
.length
=== 33) {
23878 version: buffer
[0],
23879 privateKey: buffer
.slice(1, 33),
23885 if (buffer
.length
!== 34) throw new Error('Invalid WIF length')
23887 // invalid compression flag
23888 if (buffer
[33] !== 0x01) throw new Error('Invalid compression flag')
23891 version: buffer
[0],
23892 privateKey: buffer
.slice(1, 33),
23897 function encodeRaw (version
, privateKey
, compressed
) {
23898 var result
= new Buffer(compressed
? 34 : 33)
23900 result
.writeUInt8(version
, 0)
23901 privateKey
.copy(result
, 1)
23910 function decode (string
, version
) {
23911 return decodeRaw(bs58check
.decode(string
), version
)
23914 function encode (version
, privateKey
, compressed
) {
23915 if (typeof version
=== 'number') return bs58check
.encode(encodeRaw(version
, privateKey
, compressed
))
23917 return bs58check
.encode(
23920 version
.privateKey
,
23928 decodeRaw: decodeRaw
,
23930 encodeRaw: encodeRaw
23933 }).call(this,require("buffer").Buffer
)
23934 },{"bs58check":85,"buffer":5}]},{},[34])(34)