diff options
-rw-r--r-- | bip39-standalone.html | 11787 | ||||
-rw-r--r-- | changelog.md | 7 | ||||
-rw-r--r-- | src/index.html | 2 |
3 files changed, 10494 insertions, 1302 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index 1df8fde..e019036 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -118,7 +118,7 @@ | |||
118 | <div class="container"> | 118 | <div class="container"> |
119 | 119 | ||
120 | <h1 class="text-center">Mnemonic Code Converter</h1> | 120 | <h1 class="text-center">Mnemonic Code Converter</h1> |
121 | <p class="version">v0.2.9</p> | 121 | <p class="version">v0.3.0</p> |
122 | <hr> | 122 | <hr> |
123 | <div class="row"> | 123 | <div class="row"> |
124 | <div class="col-md-12"> | 124 | <div class="col-md-12"> |
@@ -281,7 +281,7 @@ | |||
281 | <label for="litecoin-use-ltub" class="col-sm-2 control-label">Prefixes</label> | 281 | <label for="litecoin-use-ltub" class="col-sm-2 control-label">Prefixes</label> |
282 | <div class="col-sm-10 checkbox"> | 282 | <div class="col-sm-10 checkbox"> |
283 | <label> | 283 | <label> |
284 | <input type="checkbox" id="litecoin-use-ltub" class="litecoin-use-ltub"> | 284 | <input type="checkbox" id="litecoin-use-ltub" class="litecoin-use-ltub" checked="checked"> |
285 | Use <code>Ltpv / Ltub</code> instead of <code>xprv / xpub</code> | 285 | Use <code>Ltpv / Ltub</code> instead of <code>xprv / xpub</code> |
286 | </label> | 286 | </label> |
287 | </div> | 287 | </div> |
@@ -305,6 +305,9 @@ | |||
305 | <li id="bip49-tab"> | 305 | <li id="bip49-tab"> |
306 | <a href="#bip49" role="tab" data-toggle="tab">BIP49</a> | 306 | <a href="#bip49" role="tab" data-toggle="tab">BIP49</a> |
307 | </li> | 307 | </li> |
308 | <li id="bip141-tab"> | ||
309 | <a href="#bip141" role="tab" data-toggle="tab">BIP141</a> | ||
310 | </li> | ||
308 | </ul> | 311 | </ul> |
309 | <div class="derivation-type tab-content"> | 312 | <div class="derivation-type tab-content"> |
310 | <div id="bip44" class="tab-pane active"> | 313 | <div id="bip44" class="tab-pane active"> |
@@ -420,13 +423,6 @@ | |||
420 | </label> | 423 | </label> |
421 | </div> | 424 | </div> |
422 | <div class="form-group"> | 425 | <div class="form-group"> |
423 | <div class="col-sm-2"></div> | ||
424 | <label class="col-sm-10"> | ||
425 | <input class="p2wpkh-nested-in-p2sh" type="checkbox"> | ||
426 | <span>Use SegWit addresses (ie P2WPKH Nested In P2SH)</span> | ||
427 | </label> | ||
428 | </div> | ||
429 | <div class="form-group"> | ||
430 | <label for="core-path" class="col-sm-2 control-label">Bitcoin Core</label> | 426 | <label for="core-path" class="col-sm-2 control-label">Bitcoin Core</label> |
431 | <div class="col-sm-10"> | 427 | <div class="col-sm-10"> |
432 | <p class="form-control no-border"> | 428 | <p class="form-control no-border"> |
@@ -555,6 +551,43 @@ | |||
555 | </div> | 551 | </div> |
556 | </form> | 552 | </form> |
557 | </div> | 553 | </div> |
554 | <div id="bip141" class="tab-pane"> | ||
555 | <form class="form-horizontal" role="form"> | ||
556 | <br> | ||
557 | <div class="unavailable hidden"> | ||
558 | <div class="form-group"> | ||
559 | <div class="col-sm-2"></div> | ||
560 | <div class="col-sm-10"> | ||
561 | <p>BIP141 is unavailable for this coin.</p> | ||
562 | </div> | ||
563 | </div> | ||
564 | </div> | ||
565 | <div class="available"> | ||
566 | <div class="col-sm-2"></div> | ||
567 | <div class="col-sm-10"> | ||
568 | <p> | ||
569 | For more info see the | ||
570 | <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" target="_blank">BIP141 spec</a> | ||
571 | </p> | ||
572 | </div> | ||
573 | <div class="form-group"> | ||
574 | <label for="bip141-path" class="col-sm-2 control-label">BIP32 Derivation Path</label> | ||
575 | <div class="col-sm-10"> | ||
576 | <input id="bip141-path" type="text" class="bip141-path form-control" value="m/0"> | ||
577 | </div> | ||
578 | </div> | ||
579 | <div class="form-group"> | ||
580 | <label class="col-sm-2 control-label">Script Semantics</label> | ||
581 | <div class="col-sm-10"> | ||
582 | <select class="form-control bip141-semantics"> | ||
583 | <option value="p2wpkh">P2WPKH</option> | ||
584 | <option value="p2wpkh-p2sh" selected>P2WPKH nested in P2SH</option> | ||
585 | </select> | ||
586 | </div> | ||
587 | </div> | ||
588 | </div> | ||
589 | </form> | ||
590 | </div> | ||
558 | </div> | 591 | </div> |
559 | <form class="form-horizontal" role="form"> | 592 | <form class="form-horizontal" role="form"> |
560 | <div class="form-group"> | 593 | <div class="form-group"> |
@@ -7825,7 +7858,7 @@ var objectKeys = Object.keys || function (obj) { | |||
7825 | }; | 7858 | }; |
7826 | 7859 | ||
7827 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | 7860 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
7828 | },{"util/":32}],2:[function(require,module,exports){ | 7861 | },{"util/":33}],2:[function(require,module,exports){ |
7829 | 'use strict' | 7862 | 'use strict' |
7830 | 7863 | ||
7831 | exports.byteLength = byteLength | 7864 | exports.byteLength = byteLength |
@@ -7861,22 +7894,22 @@ function placeHoldersCount (b64) { | |||
7861 | 7894 | ||
7862 | function byteLength (b64) { | 7895 | function byteLength (b64) { |
7863 | // base64 is 4/3 + up to two characters of the original data | 7896 | // base64 is 4/3 + up to two characters of the original data |
7864 | return (b64.length * 3 / 4) - placeHoldersCount(b64) | 7897 | return b64.length * 3 / 4 - placeHoldersCount(b64) |
7865 | } | 7898 | } |
7866 | 7899 | ||
7867 | function toByteArray (b64) { | 7900 | function toByteArray (b64) { |
7868 | var i, l, tmp, placeHolders, arr | 7901 | var i, j, l, tmp, placeHolders, arr |
7869 | var len = b64.length | 7902 | var len = b64.length |
7870 | placeHolders = placeHoldersCount(b64) | 7903 | placeHolders = placeHoldersCount(b64) |
7871 | 7904 | ||
7872 | arr = new Arr((len * 3 / 4) - placeHolders) | 7905 | arr = new Arr(len * 3 / 4 - placeHolders) |
7873 | 7906 | ||
7874 | // if there are placeholders, only get up to the last complete 4 chars | 7907 | // if there are placeholders, only get up to the last complete 4 chars |
7875 | l = placeHolders > 0 ? len - 4 : len | 7908 | l = placeHolders > 0 ? len - 4 : len |
7876 | 7909 | ||
7877 | var L = 0 | 7910 | var L = 0 |
7878 | 7911 | ||
7879 | for (i = 0; i < l; i += 4) { | 7912 | for (i = 0, j = 0; i < l; i += 4, j += 3) { |
7880 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] | 7913 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] |
7881 | arr[L++] = (tmp >> 16) & 0xFF | 7914 | arr[L++] = (tmp >> 16) & 0xFF |
7882 | arr[L++] = (tmp >> 8) & 0xFF | 7915 | arr[L++] = (tmp >> 8) & 0xFF |
@@ -7944,6 +7977,118 @@ function fromByteArray (uint8) { | |||
7944 | },{}],3:[function(require,module,exports){ | 7977 | },{}],3:[function(require,module,exports){ |
7945 | 7978 | ||
7946 | },{}],4:[function(require,module,exports){ | 7979 | },{}],4:[function(require,module,exports){ |
7980 | (function (global){ | ||
7981 | 'use strict'; | ||
7982 | |||
7983 | var buffer = require('buffer'); | ||
7984 | var Buffer = buffer.Buffer; | ||
7985 | var SlowBuffer = buffer.SlowBuffer; | ||
7986 | var MAX_LEN = buffer.kMaxLength || 2147483647; | ||
7987 | exports.alloc = function alloc(size, fill, encoding) { | ||
7988 | if (typeof Buffer.alloc === 'function') { | ||
7989 | return Buffer.alloc(size, fill, encoding); | ||
7990 | } | ||
7991 | if (typeof encoding === 'number') { | ||
7992 | throw new TypeError('encoding must not be number'); | ||
7993 | } | ||
7994 | if (typeof size !== 'number') { | ||
7995 | throw new TypeError('size must be a number'); | ||
7996 | } | ||
7997 | if (size > MAX_LEN) { | ||
7998 | throw new RangeError('size is too large'); | ||
7999 | } | ||
8000 | var enc = encoding; | ||
8001 | var _fill = fill; | ||
8002 | if (_fill === undefined) { | ||
8003 | enc = undefined; | ||
8004 | _fill = 0; | ||
8005 | } | ||
8006 | var buf = new Buffer(size); | ||
8007 | if (typeof _fill === 'string') { | ||
8008 | var fillBuf = new Buffer(_fill, enc); | ||
8009 | var flen = fillBuf.length; | ||
8010 | var i = -1; | ||
8011 | while (++i < size) { | ||
8012 | buf[i] = fillBuf[i % flen]; | ||
8013 | } | ||
8014 | } else { | ||
8015 | buf.fill(_fill); | ||
8016 | } | ||
8017 | return buf; | ||
8018 | } | ||
8019 | exports.allocUnsafe = function allocUnsafe(size) { | ||
8020 | if (typeof Buffer.allocUnsafe === 'function') { | ||
8021 | return Buffer.allocUnsafe(size); | ||
8022 | } | ||
8023 | if (typeof size !== 'number') { | ||
8024 | throw new TypeError('size must be a number'); | ||
8025 | } | ||
8026 | if (size > MAX_LEN) { | ||
8027 | throw new RangeError('size is too large'); | ||
8028 | } | ||
8029 | return new Buffer(size); | ||
8030 | } | ||
8031 | exports.from = function from(value, encodingOrOffset, length) { | ||
8032 | if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { | ||
8033 | return Buffer.from(value, encodingOrOffset, length); | ||
8034 | } | ||
8035 | if (typeof value === 'number') { | ||
8036 | throw new TypeError('"value" argument must not be a number'); | ||
8037 | } | ||
8038 | if (typeof value === 'string') { | ||
8039 | return new Buffer(value, encodingOrOffset); | ||
8040 | } | ||
8041 | if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { | ||
8042 | var offset = encodingOrOffset; | ||
8043 | if (arguments.length === 1) { | ||
8044 | return new Buffer(value); | ||
8045 | } | ||
8046 | if (typeof offset === 'undefined') { | ||
8047 | offset = 0; | ||
8048 | } | ||
8049 | var len = length; | ||
8050 | if (typeof len === 'undefined') { | ||
8051 | len = value.byteLength - offset; | ||
8052 | } | ||
8053 | if (offset >= value.byteLength) { | ||
8054 | throw new RangeError('\'offset\' is out of bounds'); | ||
8055 | } | ||
8056 | if (len > value.byteLength - offset) { | ||
8057 | throw new RangeError('\'length\' is out of bounds'); | ||
8058 | } | ||
8059 | return new Buffer(value.slice(offset, offset + len)); | ||
8060 | } | ||
8061 | if (Buffer.isBuffer(value)) { | ||
8062 | var out = new Buffer(value.length); | ||
8063 | value.copy(out, 0, 0, value.length); | ||
8064 | return out; | ||
8065 | } | ||
8066 | if (value) { | ||
8067 | if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { | ||
8068 | return new Buffer(value); | ||
8069 | } | ||
8070 | if (value.type === 'Buffer' && Array.isArray(value.data)) { | ||
8071 | return new Buffer(value.data); | ||
8072 | } | ||
8073 | } | ||
8074 | |||
8075 | throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); | ||
8076 | } | ||
8077 | exports.allocUnsafeSlow = function allocUnsafeSlow(size) { | ||
8078 | if (typeof Buffer.allocUnsafeSlow === 'function') { | ||
8079 | return Buffer.allocUnsafeSlow(size); | ||
8080 | } | ||
8081 | if (typeof size !== 'number') { | ||
8082 | throw new TypeError('size must be a number'); | ||
8083 | } | ||
8084 | if (size >= MAX_LEN) { | ||
8085 | throw new RangeError('size is too large'); | ||
8086 | } | ||
8087 | return new SlowBuffer(size); | ||
8088 | } | ||
8089 | |||
8090 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
8091 | },{"buffer":5}],5:[function(require,module,exports){ | ||
7947 | /*! | 8092 | /*! |
7948 | * The buffer module from node.js, for the browser. | 8093 | * The buffer module from node.js, for the browser. |
7949 | * | 8094 | * |
@@ -9651,7 +9796,7 @@ function numberIsNaN (obj) { | |||
9651 | return obj !== obj // eslint-disable-line no-self-compare | 9796 | return obj !== obj // eslint-disable-line no-self-compare |
9652 | } | 9797 | } |
9653 | 9798 | ||
9654 | },{"base64-js":2,"ieee754":7}],5:[function(require,module,exports){ | 9799 | },{"base64-js":2,"ieee754":8}],6:[function(require,module,exports){ |
9655 | (function (Buffer){ | 9800 | (function (Buffer){ |
9656 | // Copyright Joyent, Inc. and other Node contributors. | 9801 | // Copyright Joyent, Inc. and other Node contributors. |
9657 | // | 9802 | // |
@@ -9762,7 +9907,7 @@ function objectToString(o) { | |||
9762 | } | 9907 | } |
9763 | 9908 | ||
9764 | }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) | 9909 | }).call(this,{"isBuffer":require("../../is-buffer/index.js")}) |
9765 | },{"../../is-buffer/index.js":9}],6:[function(require,module,exports){ | 9910 | },{"../../is-buffer/index.js":10}],7:[function(require,module,exports){ |
9766 | // Copyright Joyent, Inc. and other Node contributors. | 9911 | // Copyright Joyent, Inc. and other Node contributors. |
9767 | // | 9912 | // |
9768 | // Permission is hereby granted, free of charge, to any person obtaining a | 9913 | // Permission is hereby granted, free of charge, to any person obtaining a |
@@ -10066,7 +10211,7 @@ function isUndefined(arg) { | |||
10066 | return arg === void 0; | 10211 | return arg === void 0; |
10067 | } | 10212 | } |
10068 | 10213 | ||
10069 | },{}],7:[function(require,module,exports){ | 10214 | },{}],8:[function(require,module,exports){ |
10070 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { | 10215 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { |
10071 | var e, m | 10216 | var e, m |
10072 | var eLen = nBytes * 8 - mLen - 1 | 10217 | var eLen = nBytes * 8 - mLen - 1 |
@@ -10152,7 +10297,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | |||
10152 | buffer[offset + i - d] |= s * 128 | 10297 | buffer[offset + i - d] |= s * 128 |
10153 | } | 10298 | } |
10154 | 10299 | ||
10155 | },{}],8:[function(require,module,exports){ | 10300 | },{}],9:[function(require,module,exports){ |
10156 | if (typeof Object.create === 'function') { | 10301 | if (typeof Object.create === 'function') { |
10157 | // implementation from standard node.js 'util' module | 10302 | // implementation from standard node.js 'util' module |
10158 | module.exports = function inherits(ctor, superCtor) { | 10303 | module.exports = function inherits(ctor, superCtor) { |
@@ -10177,7 +10322,7 @@ if (typeof Object.create === 'function') { | |||
10177 | } | 10322 | } |
10178 | } | 10323 | } |
10179 | 10324 | ||
10180 | },{}],9:[function(require,module,exports){ | 10325 | },{}],10:[function(require,module,exports){ |
10181 | /*! | 10326 | /*! |
10182 | * Determine if an object is a Buffer | 10327 | * Determine if an object is a Buffer |
10183 | * | 10328 | * |
@@ -10200,14 +10345,14 @@ function isSlowBuffer (obj) { | |||
10200 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) | 10345 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) |
10201 | } | 10346 | } |
10202 | 10347 | ||
10203 | },{}],10:[function(require,module,exports){ | 10348 | },{}],11:[function(require,module,exports){ |
10204 | var toString = {}.toString; | 10349 | var toString = {}.toString; |
10205 | 10350 | ||
10206 | module.exports = Array.isArray || function (arr) { | 10351 | module.exports = Array.isArray || function (arr) { |
10207 | return toString.call(arr) == '[object Array]'; | 10352 | return toString.call(arr) == '[object Array]'; |
10208 | }; | 10353 | }; |
10209 | 10354 | ||
10210 | },{}],11:[function(require,module,exports){ | 10355 | },{}],12:[function(require,module,exports){ |
10211 | (function (process){ | 10356 | (function (process){ |
10212 | 'use strict'; | 10357 | 'use strict'; |
10213 | 10358 | ||
@@ -10254,7 +10399,7 @@ function nextTick(fn, arg1, arg2, arg3) { | |||
10254 | } | 10399 | } |
10255 | 10400 | ||
10256 | }).call(this,require('_process')) | 10401 | }).call(this,require('_process')) |
10257 | },{"_process":12}],12:[function(require,module,exports){ | 10402 | },{"_process":13}],13:[function(require,module,exports){ |
10258 | // shim for using process in browser | 10403 | // shim for using process in browser |
10259 | var process = module.exports = {}; | 10404 | var process = module.exports = {}; |
10260 | 10405 | ||
@@ -10440,31 +10585,10 @@ process.chdir = function (dir) { | |||
10440 | }; | 10585 | }; |
10441 | process.umask = function() { return 0; }; | 10586 | process.umask = function() { return 0; }; |
10442 | 10587 | ||
10443 | },{}],13:[function(require,module,exports){ | 10588 | },{}],14:[function(require,module,exports){ |
10444 | module.exports = require('./lib/_stream_duplex.js'); | 10589 | module.exports = require('./lib/_stream_duplex.js'); |
10445 | 10590 | ||
10446 | },{"./lib/_stream_duplex.js":14}],14:[function(require,module,exports){ | 10591 | },{"./lib/_stream_duplex.js":15}],15:[function(require,module,exports){ |
10447 | // Copyright Joyent, Inc. and other Node contributors. | ||
10448 | // | ||
10449 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
10450 | // copy of this software and associated documentation files (the | ||
10451 | // "Software"), to deal in the Software without restriction, including | ||
10452 | // without limitation the rights to use, copy, modify, merge, publish, | ||
10453 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
10454 | // persons to whom the Software is furnished to do so, subject to the | ||
10455 | // following conditions: | ||
10456 | // | ||
10457 | // The above copyright notice and this permission notice shall be included | ||
10458 | // in all copies or substantial portions of the Software. | ||
10459 | // | ||
10460 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
10461 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
10462 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
10463 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
10464 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
10465 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
10466 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
10467 | |||
10468 | // a duplex stream is just a stream that is both readable and writable. | 10592 | // a duplex stream is just a stream that is both readable and writable. |
10469 | // Since JS doesn't have multiple prototypal inheritance, this class | 10593 | // Since JS doesn't have multiple prototypal inheritance, this class |
10470 | // prototypally inherits from Readable, and then parasitically from | 10594 | // prototypally inherits from Readable, and then parasitically from |
@@ -10474,10 +10598,6 @@ module.exports = require('./lib/_stream_duplex.js'); | |||
10474 | 10598 | ||
10475 | /*<replacement>*/ | 10599 | /*<replacement>*/ |
10476 | 10600 | ||
10477 | var processNextTick = require('process-nextick-args'); | ||
10478 | /*</replacement>*/ | ||
10479 | |||
10480 | /*<replacement>*/ | ||
10481 | var objectKeys = Object.keys || function (obj) { | 10601 | var objectKeys = Object.keys || function (obj) { |
10482 | var keys = []; | 10602 | var keys = []; |
10483 | for (var key in obj) { | 10603 | for (var key in obj) { |
@@ -10489,6 +10609,10 @@ var objectKeys = Object.keys || function (obj) { | |||
10489 | module.exports = Duplex; | 10609 | module.exports = Duplex; |
10490 | 10610 | ||
10491 | /*<replacement>*/ | 10611 | /*<replacement>*/ |
10612 | var processNextTick = require('process-nextick-args'); | ||
10613 | /*</replacement>*/ | ||
10614 | |||
10615 | /*<replacement>*/ | ||
10492 | var util = require('core-util-is'); | 10616 | var util = require('core-util-is'); |
10493 | util.inherits = require('inherits'); | 10617 | util.inherits = require('inherits'); |
10494 | /*</replacement>*/ | 10618 | /*</replacement>*/ |
@@ -10535,61 +10659,12 @@ function onEndNT(self) { | |||
10535 | self.end(); | 10659 | self.end(); |
10536 | } | 10660 | } |
10537 | 10661 | ||
10538 | Object.defineProperty(Duplex.prototype, 'destroyed', { | ||
10539 | get: function () { | ||
10540 | if (this._readableState === undefined || this._writableState === undefined) { | ||
10541 | return false; | ||
10542 | } | ||
10543 | return this._readableState.destroyed && this._writableState.destroyed; | ||
10544 | }, | ||
10545 | set: function (value) { | ||
10546 | // we ignore the value if the stream | ||
10547 | // has not been initialized yet | ||
10548 | if (this._readableState === undefined || this._writableState === undefined) { | ||
10549 | return; | ||
10550 | } | ||
10551 | |||
10552 | // backward compatibility, the user is explicitly | ||
10553 | // managing destroyed | ||
10554 | this._readableState.destroyed = value; | ||
10555 | this._writableState.destroyed = value; | ||
10556 | } | ||
10557 | }); | ||
10558 | |||
10559 | Duplex.prototype._destroy = function (err, cb) { | ||
10560 | this.push(null); | ||
10561 | this.end(); | ||
10562 | |||
10563 | processNextTick(cb, err); | ||
10564 | }; | ||
10565 | |||
10566 | function forEach(xs, f) { | 10662 | function forEach(xs, f) { |
10567 | for (var i = 0, l = xs.length; i < l; i++) { | 10663 | for (var i = 0, l = xs.length; i < l; i++) { |
10568 | f(xs[i], i); | 10664 | f(xs[i], i); |
10569 | } | 10665 | } |
10570 | } | 10666 | } |
10571 | },{"./_stream_readable":16,"./_stream_writable":18,"core-util-is":5,"inherits":8,"process-nextick-args":11}],15:[function(require,module,exports){ | 10667 | },{"./_stream_readable":17,"./_stream_writable":19,"core-util-is":6,"inherits":9,"process-nextick-args":12}],16:[function(require,module,exports){ |
10572 | // Copyright Joyent, Inc. and other Node contributors. | ||
10573 | // | ||
10574 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
10575 | // copy of this software and associated documentation files (the | ||
10576 | // "Software"), to deal in the Software without restriction, including | ||
10577 | // without limitation the rights to use, copy, modify, merge, publish, | ||
10578 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
10579 | // persons to whom the Software is furnished to do so, subject to the | ||
10580 | // following conditions: | ||
10581 | // | ||
10582 | // The above copyright notice and this permission notice shall be included | ||
10583 | // in all copies or substantial portions of the Software. | ||
10584 | // | ||
10585 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
10586 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
10587 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
10588 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
10589 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
10590 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
10591 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
10592 | |||
10593 | // a passthrough stream. | 10668 | // a passthrough stream. |
10594 | // basically just the most minimal sort of Transform stream. | 10669 | // basically just the most minimal sort of Transform stream. |
10595 | // Every written chunk gets output as-is. | 10670 | // Every written chunk gets output as-is. |
@@ -10616,38 +10691,16 @@ function PassThrough(options) { | |||
10616 | PassThrough.prototype._transform = function (chunk, encoding, cb) { | 10691 | PassThrough.prototype._transform = function (chunk, encoding, cb) { |
10617 | cb(null, chunk); | 10692 | cb(null, chunk); |
10618 | }; | 10693 | }; |
10619 | },{"./_stream_transform":17,"core-util-is":5,"inherits":8}],16:[function(require,module,exports){ | 10694 | },{"./_stream_transform":18,"core-util-is":6,"inherits":9}],17:[function(require,module,exports){ |
10620 | (function (process,global){ | 10695 | (function (process){ |
10621 | // Copyright Joyent, Inc. and other Node contributors. | ||
10622 | // | ||
10623 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
10624 | // copy of this software and associated documentation files (the | ||
10625 | // "Software"), to deal in the Software without restriction, including | ||
10626 | // without limitation the rights to use, copy, modify, merge, publish, | ||
10627 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
10628 | // persons to whom the Software is furnished to do so, subject to the | ||
10629 | // following conditions: | ||
10630 | // | ||
10631 | // The above copyright notice and this permission notice shall be included | ||
10632 | // in all copies or substantial portions of the Software. | ||
10633 | // | ||
10634 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
10635 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
10636 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
10637 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
10638 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
10639 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
10640 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
10641 | |||
10642 | 'use strict'; | 10696 | 'use strict'; |
10643 | 10697 | ||
10644 | /*<replacement>*/ | 10698 | module.exports = Readable; |
10645 | 10699 | ||
10700 | /*<replacement>*/ | ||
10646 | var processNextTick = require('process-nextick-args'); | 10701 | var processNextTick = require('process-nextick-args'); |
10647 | /*</replacement>*/ | 10702 | /*</replacement>*/ |
10648 | 10703 | ||
10649 | module.exports = Readable; | ||
10650 | |||
10651 | /*<replacement>*/ | 10704 | /*<replacement>*/ |
10652 | var isArray = require('isarray'); | 10705 | var isArray = require('isarray'); |
10653 | /*</replacement>*/ | 10706 | /*</replacement>*/ |
@@ -10670,17 +10723,9 @@ var EElistenerCount = function (emitter, type) { | |||
10670 | var Stream = require('./internal/streams/stream'); | 10723 | var Stream = require('./internal/streams/stream'); |
10671 | /*</replacement>*/ | 10724 | /*</replacement>*/ |
10672 | 10725 | ||
10673 | // TODO(bmeurer): Change this back to const once hole checks are | 10726 | var Buffer = require('buffer').Buffer; |
10674 | // properly optimized away early in Ignition+TurboFan. | ||
10675 | /*<replacement>*/ | 10727 | /*<replacement>*/ |
10676 | var Buffer = require('safe-buffer').Buffer; | 10728 | var bufferShim = require('buffer-shims'); |
10677 | var OurUint8Array = global.Uint8Array || function () {}; | ||
10678 | function _uint8ArrayToBuffer(chunk) { | ||
10679 | return Buffer.from(chunk); | ||
10680 | } | ||
10681 | function _isUint8Array(obj) { | ||
10682 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; | ||
10683 | } | ||
10684 | /*</replacement>*/ | 10729 | /*</replacement>*/ |
10685 | 10730 | ||
10686 | /*<replacement>*/ | 10731 | /*<replacement>*/ |
@@ -10699,7 +10744,6 @@ if (debugUtil && debugUtil.debuglog) { | |||
10699 | /*</replacement>*/ | 10744 | /*</replacement>*/ |
10700 | 10745 | ||
10701 | var BufferList = require('./internal/streams/BufferList'); | 10746 | var BufferList = require('./internal/streams/BufferList'); |
10702 | var destroyImpl = require('./internal/streams/destroy'); | ||
10703 | var StringDecoder; | 10747 | var StringDecoder; |
10704 | 10748 | ||
10705 | util.inherits(Readable, Stream); | 10749 | util.inherits(Readable, Stream); |
@@ -10738,7 +10782,7 @@ function ReadableState(options, stream) { | |||
10738 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | 10782 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; |
10739 | 10783 | ||
10740 | // cast to ints. | 10784 | // cast to ints. |
10741 | this.highWaterMark = Math.floor(this.highWaterMark); | 10785 | this.highWaterMark = ~~this.highWaterMark; |
10742 | 10786 | ||
10743 | // A linked list is used to store data chunks instead of an array because the | 10787 | // A linked list is used to store data chunks instead of an array because the |
10744 | // linked list can remove elements from the beginning faster than | 10788 | // linked list can remove elements from the beginning faster than |
@@ -10752,10 +10796,10 @@ function ReadableState(options, stream) { | |||
10752 | this.endEmitted = false; | 10796 | this.endEmitted = false; |
10753 | this.reading = false; | 10797 | this.reading = false; |
10754 | 10798 | ||
10755 | // a flag to be able to tell if the event 'readable'/'data' is emitted | 10799 | // a flag to be able to tell if the onwrite cb is called immediately, |
10756 | // immediately, or on a later tick. We set this to true at first, because | 10800 | // or on a later tick. We set this to true at first, because any |
10757 | // any actions that shouldn't happen until "later" should generally also | 10801 | // actions that shouldn't happen until "later" should generally also |
10758 | // not happen before the first read call. | 10802 | // not happen before the first write call. |
10759 | this.sync = true; | 10803 | this.sync = true; |
10760 | 10804 | ||
10761 | // whenever we return null, then we set a flag to say | 10805 | // whenever we return null, then we set a flag to say |
@@ -10765,14 +10809,15 @@ function ReadableState(options, stream) { | |||
10765 | this.readableListening = false; | 10809 | this.readableListening = false; |
10766 | this.resumeScheduled = false; | 10810 | this.resumeScheduled = false; |
10767 | 10811 | ||
10768 | // has it been destroyed | ||
10769 | this.destroyed = false; | ||
10770 | |||
10771 | // Crypto is kind of old and crusty. Historically, its default string | 10812 | // Crypto is kind of old and crusty. Historically, its default string |
10772 | // encoding is 'binary' so we have to make this configurable. | 10813 | // encoding is 'binary' so we have to make this configurable. |
10773 | // Everything else in the universe uses 'utf8', though. | 10814 | // Everything else in the universe uses 'utf8', though. |
10774 | this.defaultEncoding = options.defaultEncoding || 'utf8'; | 10815 | this.defaultEncoding = options.defaultEncoding || 'utf8'; |
10775 | 10816 | ||
10817 | // when piping, we only care about 'readable' events that happen | ||
10818 | // after read()ing all the bytes and not getting any pushback. | ||
10819 | this.ranOut = false; | ||
10820 | |||
10776 | // the number of writers that are awaiting a drain event in .pipe()s | 10821 | // the number of writers that are awaiting a drain event in .pipe()s |
10777 | this.awaitDrain = 0; | 10822 | this.awaitDrain = 0; |
10778 | 10823 | ||
@@ -10798,129 +10843,87 @@ function Readable(options) { | |||
10798 | // legacy | 10843 | // legacy |
10799 | this.readable = true; | 10844 | this.readable = true; |
10800 | 10845 | ||
10801 | if (options) { | 10846 | if (options && typeof options.read === 'function') this._read = options.read; |
10802 | if (typeof options.read === 'function') this._read = options.read; | ||
10803 | |||
10804 | if (typeof options.destroy === 'function') this._destroy = options.destroy; | ||
10805 | } | ||
10806 | 10847 | ||
10807 | Stream.call(this); | 10848 | Stream.call(this); |
10808 | } | 10849 | } |
10809 | 10850 | ||
10810 | Object.defineProperty(Readable.prototype, 'destroyed', { | ||
10811 | get: function () { | ||
10812 | if (this._readableState === undefined) { | ||
10813 | return false; | ||
10814 | } | ||
10815 | return this._readableState.destroyed; | ||
10816 | }, | ||
10817 | set: function (value) { | ||
10818 | // we ignore the value if the stream | ||
10819 | // has not been initialized yet | ||
10820 | if (!this._readableState) { | ||
10821 | return; | ||
10822 | } | ||
10823 | |||
10824 | // backward compatibility, the user is explicitly | ||
10825 | // managing destroyed | ||
10826 | this._readableState.destroyed = value; | ||
10827 | } | ||
10828 | }); | ||
10829 | |||
10830 | Readable.prototype.destroy = destroyImpl.destroy; | ||
10831 | Readable.prototype._undestroy = destroyImpl.undestroy; | ||
10832 | Readable.prototype._destroy = function (err, cb) { | ||
10833 | this.push(null); | ||
10834 | cb(err); | ||
10835 | }; | ||
10836 | |||
10837 | // Manually shove something into the read() buffer. | 10851 | // Manually shove something into the read() buffer. |
10838 | // This returns true if the highWaterMark has not been hit yet, | 10852 | // This returns true if the highWaterMark has not been hit yet, |
10839 | // similar to how Writable.write() returns true if you should | 10853 | // similar to how Writable.write() returns true if you should |
10840 | // write() some more. | 10854 | // write() some more. |
10841 | Readable.prototype.push = function (chunk, encoding) { | 10855 | Readable.prototype.push = function (chunk, encoding) { |
10842 | var state = this._readableState; | 10856 | var state = this._readableState; |
10843 | var skipChunkCheck; | ||
10844 | 10857 | ||
10845 | if (!state.objectMode) { | 10858 | if (!state.objectMode && typeof chunk === 'string') { |
10846 | if (typeof chunk === 'string') { | 10859 | encoding = encoding || state.defaultEncoding; |
10847 | encoding = encoding || state.defaultEncoding; | 10860 | if (encoding !== state.encoding) { |
10848 | if (encoding !== state.encoding) { | 10861 | chunk = bufferShim.from(chunk, encoding); |
10849 | chunk = Buffer.from(chunk, encoding); | 10862 | encoding = ''; |
10850 | encoding = ''; | ||
10851 | } | ||
10852 | skipChunkCheck = true; | ||
10853 | } | 10863 | } |
10854 | } else { | ||
10855 | skipChunkCheck = true; | ||
10856 | } | 10864 | } |
10857 | 10865 | ||
10858 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); | 10866 | return readableAddChunk(this, state, chunk, encoding, false); |
10859 | }; | 10867 | }; |
10860 | 10868 | ||
10861 | // Unshift should *always* be something directly out of read() | 10869 | // Unshift should *always* be something directly out of read() |
10862 | Readable.prototype.unshift = function (chunk) { | 10870 | Readable.prototype.unshift = function (chunk) { |
10863 | return readableAddChunk(this, chunk, null, true, false); | 10871 | var state = this._readableState; |
10872 | return readableAddChunk(this, state, chunk, '', true); | ||
10864 | }; | 10873 | }; |
10865 | 10874 | ||
10866 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { | 10875 | Readable.prototype.isPaused = function () { |
10867 | var state = stream._readableState; | 10876 | return this._readableState.flowing === false; |
10868 | if (chunk === null) { | 10877 | }; |
10878 | |||
10879 | function readableAddChunk(stream, state, chunk, encoding, addToFront) { | ||
10880 | var er = chunkInvalid(state, chunk); | ||
10881 | if (er) { | ||
10882 | stream.emit('error', er); | ||
10883 | } else if (chunk === null) { | ||
10869 | state.reading = false; | 10884 | state.reading = false; |
10870 | onEofChunk(stream, state); | 10885 | onEofChunk(stream, state); |
10871 | } else { | 10886 | } else if (state.objectMode || chunk && chunk.length > 0) { |
10872 | var er; | 10887 | if (state.ended && !addToFront) { |
10873 | if (!skipChunkCheck) er = chunkInvalid(state, chunk); | 10888 | var e = new Error('stream.push() after EOF'); |
10874 | if (er) { | 10889 | stream.emit('error', e); |
10875 | stream.emit('error', er); | 10890 | } else if (state.endEmitted && addToFront) { |
10876 | } else if (state.objectMode || chunk && chunk.length > 0) { | 10891 | var _e = new Error('stream.unshift() after end event'); |
10877 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { | 10892 | stream.emit('error', _e); |
10878 | chunk = _uint8ArrayToBuffer(chunk); | 10893 | } else { |
10879 | } | 10894 | var skipAdd; |
10880 | 10895 | if (state.decoder && !addToFront && !encoding) { | |
10881 | if (addToFront) { | 10896 | chunk = state.decoder.write(chunk); |
10882 | if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true); | 10897 | skipAdd = !state.objectMode && chunk.length === 0; |
10883 | } else if (state.ended) { | 10898 | } |
10884 | stream.emit('error', new Error('stream.push() after EOF')); | 10899 | |
10885 | } else { | 10900 | if (!addToFront) state.reading = false; |
10886 | state.reading = false; | 10901 | |
10887 | if (state.decoder && !encoding) { | 10902 | // Don't add to the buffer if we've decoded to an empty string chunk and |
10888 | chunk = state.decoder.write(chunk); | 10903 | // we're not in object mode |
10889 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); | 10904 | if (!skipAdd) { |
10905 | // if we want the data now, just emit it. | ||
10906 | if (state.flowing && state.length === 0 && !state.sync) { | ||
10907 | stream.emit('data', chunk); | ||
10908 | stream.read(0); | ||
10890 | } else { | 10909 | } else { |
10891 | addChunk(stream, state, chunk, false); | 10910 | // update the buffer info. |
10911 | state.length += state.objectMode ? 1 : chunk.length; | ||
10912 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); | ||
10913 | |||
10914 | if (state.needReadable) emitReadable(stream); | ||
10892 | } | 10915 | } |
10893 | } | 10916 | } |
10894 | } else if (!addToFront) { | 10917 | |
10895 | state.reading = false; | 10918 | maybeReadMore(stream, state); |
10896 | } | 10919 | } |
10920 | } else if (!addToFront) { | ||
10921 | state.reading = false; | ||
10897 | } | 10922 | } |
10898 | 10923 | ||
10899 | return needMoreData(state); | 10924 | return needMoreData(state); |
10900 | } | 10925 | } |
10901 | 10926 | ||
10902 | function addChunk(stream, state, chunk, addToFront) { | ||
10903 | if (state.flowing && state.length === 0 && !state.sync) { | ||
10904 | stream.emit('data', chunk); | ||
10905 | stream.read(0); | ||
10906 | } else { | ||
10907 | // update the buffer info. | ||
10908 | state.length += state.objectMode ? 1 : chunk.length; | ||
10909 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); | ||
10910 | |||
10911 | if (state.needReadable) emitReadable(stream); | ||
10912 | } | ||
10913 | maybeReadMore(stream, state); | ||
10914 | } | ||
10915 | |||
10916 | function chunkInvalid(state, chunk) { | ||
10917 | var er; | ||
10918 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { | ||
10919 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
10920 | } | ||
10921 | return er; | ||
10922 | } | ||
10923 | |||
10924 | // if it's past the high water mark, we can push in some more. | 10927 | // if it's past the high water mark, we can push in some more. |
10925 | // Also, if we have no data yet, we can stand some | 10928 | // Also, if we have no data yet, we can stand some |
10926 | // more bytes. This is to work around cases where hwm=0, | 10929 | // more bytes. This is to work around cases where hwm=0, |
@@ -10932,10 +10935,6 @@ function needMoreData(state) { | |||
10932 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); | 10935 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); |
10933 | } | 10936 | } |
10934 | 10937 | ||
10935 | Readable.prototype.isPaused = function () { | ||
10936 | return this._readableState.flowing === false; | ||
10937 | }; | ||
10938 | |||
10939 | // backwards compatibility. | 10938 | // backwards compatibility. |
10940 | Readable.prototype.setEncoding = function (enc) { | 10939 | Readable.prototype.setEncoding = function (enc) { |
10941 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | 10940 | if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; |
@@ -11084,6 +11083,14 @@ Readable.prototype.read = function (n) { | |||
11084 | return ret; | 11083 | return ret; |
11085 | }; | 11084 | }; |
11086 | 11085 | ||
11086 | function chunkInvalid(state, chunk) { | ||
11087 | var er = null; | ||
11088 | if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { | ||
11089 | er = new TypeError('Invalid non-string/buffer chunk'); | ||
11090 | } | ||
11091 | return er; | ||
11092 | } | ||
11093 | |||
11087 | function onEofChunk(stream, state) { | 11094 | function onEofChunk(stream, state) { |
11088 | if (state.ended) return; | 11095 | if (state.ended) return; |
11089 | if (state.decoder) { | 11096 | if (state.decoder) { |
@@ -11171,17 +11178,14 @@ Readable.prototype.pipe = function (dest, pipeOpts) { | |||
11171 | 11178 | ||
11172 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; | 11179 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; |
11173 | 11180 | ||
11174 | var endFn = doEnd ? onend : unpipe; | 11181 | var endFn = doEnd ? onend : cleanup; |
11175 | if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); | 11182 | if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); |
11176 | 11183 | ||
11177 | dest.on('unpipe', onunpipe); | 11184 | dest.on('unpipe', onunpipe); |
11178 | function onunpipe(readable, unpipeInfo) { | 11185 | function onunpipe(readable) { |
11179 | debug('onunpipe'); | 11186 | debug('onunpipe'); |
11180 | if (readable === src) { | 11187 | if (readable === src) { |
11181 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) { | 11188 | cleanup(); |
11182 | unpipeInfo.hasUnpiped = true; | ||
11183 | cleanup(); | ||
11184 | } | ||
11185 | } | 11189 | } |
11186 | } | 11190 | } |
11187 | 11191 | ||
@@ -11207,7 +11211,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) { | |||
11207 | dest.removeListener('error', onerror); | 11211 | dest.removeListener('error', onerror); |
11208 | dest.removeListener('unpipe', onunpipe); | 11212 | dest.removeListener('unpipe', onunpipe); |
11209 | src.removeListener('end', onend); | 11213 | src.removeListener('end', onend); |
11210 | src.removeListener('end', unpipe); | 11214 | src.removeListener('end', cleanup); |
11211 | src.removeListener('data', ondata); | 11215 | src.removeListener('data', ondata); |
11212 | 11216 | ||
11213 | cleanedUp = true; | 11217 | cleanedUp = true; |
@@ -11300,7 +11304,6 @@ function pipeOnDrain(src) { | |||
11300 | 11304 | ||
11301 | Readable.prototype.unpipe = function (dest) { | 11305 | Readable.prototype.unpipe = function (dest) { |
11302 | var state = this._readableState; | 11306 | var state = this._readableState; |
11303 | var unpipeInfo = { hasUnpiped: false }; | ||
11304 | 11307 | ||
11305 | // if we're not piping anywhere, then do nothing. | 11308 | // if we're not piping anywhere, then do nothing. |
11306 | if (state.pipesCount === 0) return this; | 11309 | if (state.pipesCount === 0) return this; |
@@ -11316,7 +11319,7 @@ Readable.prototype.unpipe = function (dest) { | |||
11316 | state.pipes = null; | 11319 | state.pipes = null; |
11317 | state.pipesCount = 0; | 11320 | state.pipesCount = 0; |
11318 | state.flowing = false; | 11321 | state.flowing = false; |
11319 | if (dest) dest.emit('unpipe', this, unpipeInfo); | 11322 | if (dest) dest.emit('unpipe', this); |
11320 | return this; | 11323 | return this; |
11321 | } | 11324 | } |
11322 | 11325 | ||
@@ -11331,7 +11334,7 @@ Readable.prototype.unpipe = function (dest) { | |||
11331 | state.flowing = false; | 11334 | state.flowing = false; |
11332 | 11335 | ||
11333 | for (var i = 0; i < len; i++) { | 11336 | for (var i = 0; i < len; i++) { |
11334 | dests[i].emit('unpipe', this, unpipeInfo); | 11337 | dests[i].emit('unpipe', this); |
11335 | }return this; | 11338 | }return this; |
11336 | } | 11339 | } |
11337 | 11340 | ||
@@ -11343,7 +11346,7 @@ Readable.prototype.unpipe = function (dest) { | |||
11343 | state.pipesCount -= 1; | 11346 | state.pipesCount -= 1; |
11344 | if (state.pipesCount === 1) state.pipes = state.pipes[0]; | 11347 | if (state.pipesCount === 1) state.pipes = state.pipes[0]; |
11345 | 11348 | ||
11346 | dest.emit('unpipe', this, unpipeInfo); | 11349 | dest.emit('unpipe', this); |
11347 | 11350 | ||
11348 | return this; | 11351 | return this; |
11349 | }; | 11352 | }; |
@@ -11364,7 +11367,7 @@ Readable.prototype.on = function (ev, fn) { | |||
11364 | if (!state.reading) { | 11367 | if (!state.reading) { |
11365 | processNextTick(nReadingNextTick, this); | 11368 | processNextTick(nReadingNextTick, this); |
11366 | } else if (state.length) { | 11369 | } else if (state.length) { |
11367 | emitReadable(this); | 11370 | emitReadable(this, state); |
11368 | } | 11371 | } |
11369 | } | 11372 | } |
11370 | } | 11373 | } |
@@ -11565,7 +11568,7 @@ function copyFromBufferString(n, list) { | |||
11565 | // This function is designed to be inlinable, so please take care when making | 11568 | // This function is designed to be inlinable, so please take care when making |
11566 | // changes to the function body. | 11569 | // changes to the function body. |
11567 | function copyFromBuffer(n, list) { | 11570 | function copyFromBuffer(n, list) { |
11568 | var ret = Buffer.allocUnsafe(n); | 11571 | var ret = bufferShim.allocUnsafe(n); |
11569 | var p = list.head; | 11572 | var p = list.head; |
11570 | var c = 1; | 11573 | var c = 1; |
11571 | p.data.copy(ret); | 11574 | p.data.copy(ret); |
@@ -11625,29 +11628,8 @@ function indexOf(xs, x) { | |||
11625 | } | 11628 | } |
11626 | return -1; | 11629 | return -1; |
11627 | } | 11630 | } |
11628 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | 11631 | }).call(this,require('_process')) |
11629 | },{"./_stream_duplex":14,"./internal/streams/BufferList":19,"./internal/streams/destroy":20,"./internal/streams/stream":21,"_process":12,"core-util-is":5,"events":6,"inherits":8,"isarray":10,"process-nextick-args":11,"safe-buffer":26,"string_decoder/":28,"util":3}],17:[function(require,module,exports){ | 11632 | },{"./_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){ |
11630 | // Copyright Joyent, Inc. and other Node contributors. | ||
11631 | // | ||
11632 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
11633 | // copy of this software and associated documentation files (the | ||
11634 | // "Software"), to deal in the Software without restriction, including | ||
11635 | // without limitation the rights to use, copy, modify, merge, publish, | ||
11636 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
11637 | // persons to whom the Software is furnished to do so, subject to the | ||
11638 | // following conditions: | ||
11639 | // | ||
11640 | // The above copyright notice and this permission notice shall be included | ||
11641 | // in all copies or substantial portions of the Software. | ||
11642 | // | ||
11643 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
11644 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11645 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
11646 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
11647 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
11648 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
11649 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
11650 | |||
11651 | // a transform stream is a readable/writable stream where you do | 11633 | // a transform stream is a readable/writable stream where you do |
11652 | // something with the data. Sometimes it's called a "filter", | 11634 | // something with the data. Sometimes it's called a "filter", |
11653 | // but that's not a great name for it, since that implies a thing where | 11635 | // but that's not a great name for it, since that implies a thing where |
@@ -11721,9 +11703,7 @@ function afterTransform(stream, er, data) { | |||
11721 | 11703 | ||
11722 | var cb = ts.writecb; | 11704 | var cb = ts.writecb; |
11723 | 11705 | ||
11724 | if (!cb) { | 11706 | if (!cb) return stream.emit('error', new Error('no writecb in Transform class')); |
11725 | return stream.emit('error', new Error('write callback called multiple times')); | ||
11726 | } | ||
11727 | 11707 | ||
11728 | ts.writechunk = null; | 11708 | ts.writechunk = null; |
11729 | ts.writecb = null; | 11709 | ts.writecb = null; |
@@ -11816,15 +11796,6 @@ Transform.prototype._read = function (n) { | |||
11816 | } | 11796 | } |
11817 | }; | 11797 | }; |
11818 | 11798 | ||
11819 | Transform.prototype._destroy = function (err, cb) { | ||
11820 | var _this = this; | ||
11821 | |||
11822 | Duplex.prototype._destroy.call(this, err, function (err2) { | ||
11823 | cb(err2); | ||
11824 | _this.emit('close'); | ||
11825 | }); | ||
11826 | }; | ||
11827 | |||
11828 | function done(stream, er, data) { | 11799 | function done(stream, er, data) { |
11829 | if (er) return stream.emit('error', er); | 11800 | if (er) return stream.emit('error', er); |
11830 | 11801 | ||
@@ -11841,63 +11812,20 @@ function done(stream, er, data) { | |||
11841 | 11812 | ||
11842 | return stream.push(null); | 11813 | return stream.push(null); |
11843 | } | 11814 | } |
11844 | },{"./_stream_duplex":14,"core-util-is":5,"inherits":8}],18:[function(require,module,exports){ | 11815 | },{"./_stream_duplex":15,"core-util-is":6,"inherits":9}],19:[function(require,module,exports){ |
11845 | (function (process,global){ | 11816 | (function (process){ |
11846 | // Copyright Joyent, Inc. and other Node contributors. | ||
11847 | // | ||
11848 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
11849 | // copy of this software and associated documentation files (the | ||
11850 | // "Software"), to deal in the Software without restriction, including | ||
11851 | // without limitation the rights to use, copy, modify, merge, publish, | ||
11852 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
11853 | // persons to whom the Software is furnished to do so, subject to the | ||
11854 | // following conditions: | ||
11855 | // | ||
11856 | // The above copyright notice and this permission notice shall be included | ||
11857 | // in all copies or substantial portions of the Software. | ||
11858 | // | ||
11859 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
11860 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
11861 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
11862 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
11863 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
11864 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
11865 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
11866 | |||
11867 | // A bit simpler than readable streams. | 11817 | // A bit simpler than readable streams. |
11868 | // Implement an async ._write(chunk, encoding, cb), and it'll handle all | 11818 | // Implement an async ._write(chunk, encoding, cb), and it'll handle all |
11869 | // the drain event emission and buffering. | 11819 | // the drain event emission and buffering. |
11870 | 11820 | ||
11871 | 'use strict'; | 11821 | 'use strict'; |
11872 | 11822 | ||
11873 | /*<replacement>*/ | 11823 | module.exports = Writable; |
11874 | 11824 | ||
11825 | /*<replacement>*/ | ||
11875 | var processNextTick = require('process-nextick-args'); | 11826 | var processNextTick = require('process-nextick-args'); |
11876 | /*</replacement>*/ | 11827 | /*</replacement>*/ |
11877 | 11828 | ||
11878 | module.exports = Writable; | ||
11879 | |||
11880 | /* <replacement> */ | ||
11881 | function WriteReq(chunk, encoding, cb) { | ||
11882 | this.chunk = chunk; | ||
11883 | this.encoding = encoding; | ||
11884 | this.callback = cb; | ||
11885 | this.next = null; | ||
11886 | } | ||
11887 | |||
11888 | // It seems a linked list but it is not | ||
11889 | // there will be only 2 of these for each stream | ||
11890 | function CorkedRequest(state) { | ||
11891 | var _this = this; | ||
11892 | |||
11893 | this.next = null; | ||
11894 | this.entry = null; | ||
11895 | this.finish = function () { | ||
11896 | onCorkedFinish(_this, state); | ||
11897 | }; | ||
11898 | } | ||
11899 | /* </replacement> */ | ||
11900 | |||
11901 | /*<replacement>*/ | 11829 | /*<replacement>*/ |
11902 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; | 11830 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; |
11903 | /*</replacement>*/ | 11831 | /*</replacement>*/ |
@@ -11923,23 +11851,22 @@ var internalUtil = { | |||
11923 | var Stream = require('./internal/streams/stream'); | 11851 | var Stream = require('./internal/streams/stream'); |
11924 | /*</replacement>*/ | 11852 | /*</replacement>*/ |
11925 | 11853 | ||
11854 | var Buffer = require('buffer').Buffer; | ||
11926 | /*<replacement>*/ | 11855 | /*<replacement>*/ |
11927 | var Buffer = require('safe-buffer').Buffer; | 11856 | var bufferShim = require('buffer-shims'); |
11928 | var OurUint8Array = global.Uint8Array || function () {}; | ||
11929 | function _uint8ArrayToBuffer(chunk) { | ||
11930 | return Buffer.from(chunk); | ||
11931 | } | ||
11932 | function _isUint8Array(obj) { | ||
11933 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; | ||
11934 | } | ||
11935 | /*</replacement>*/ | 11857 | /*</replacement>*/ |
11936 | 11858 | ||
11937 | var destroyImpl = require('./internal/streams/destroy'); | ||
11938 | |||
11939 | util.inherits(Writable, Stream); | 11859 | util.inherits(Writable, Stream); |
11940 | 11860 | ||
11941 | function nop() {} | 11861 | function nop() {} |
11942 | 11862 | ||
11863 | function WriteReq(chunk, encoding, cb) { | ||
11864 | this.chunk = chunk; | ||
11865 | this.encoding = encoding; | ||
11866 | this.callback = cb; | ||
11867 | this.next = null; | ||
11868 | } | ||
11869 | |||
11943 | function WritableState(options, stream) { | 11870 | function WritableState(options, stream) { |
11944 | Duplex = Duplex || require('./_stream_duplex'); | 11871 | Duplex = Duplex || require('./_stream_duplex'); |
11945 | 11872 | ||
@@ -11959,10 +11886,7 @@ function WritableState(options, stream) { | |||
11959 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; | 11886 | this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; |
11960 | 11887 | ||
11961 | // cast to ints. | 11888 | // cast to ints. |
11962 | this.highWaterMark = Math.floor(this.highWaterMark); | 11889 | this.highWaterMark = ~~this.highWaterMark; |
11963 | |||
11964 | // if _final has been called | ||
11965 | this.finalCalled = false; | ||
11966 | 11890 | ||
11967 | // drain event flag. | 11891 | // drain event flag. |
11968 | this.needDrain = false; | 11892 | this.needDrain = false; |
@@ -11973,9 +11897,6 @@ function WritableState(options, stream) { | |||
11973 | // when 'finish' is emitted | 11897 | // when 'finish' is emitted |
11974 | this.finished = false; | 11898 | this.finished = false; |
11975 | 11899 | ||
11976 | // has it been destroyed | ||
11977 | this.destroyed = false; | ||
11978 | |||
11979 | // should we decode strings into buffers before passing to _write? | 11900 | // should we decode strings into buffers before passing to _write? |
11980 | // this is here so that some node-core streams can optimize string | 11901 | // this is here so that some node-core streams can optimize string |
11981 | // handling at a lower level. | 11902 | // handling at a lower level. |
@@ -12057,7 +11978,7 @@ WritableState.prototype.getBuffer = function getBuffer() { | |||
12057 | Object.defineProperty(WritableState.prototype, 'buffer', { | 11978 | Object.defineProperty(WritableState.prototype, 'buffer', { |
12058 | get: internalUtil.deprecate(function () { | 11979 | get: internalUtil.deprecate(function () { |
12059 | return this.getBuffer(); | 11980 | return this.getBuffer(); |
12060 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003') | 11981 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') |
12061 | }); | 11982 | }); |
12062 | } catch (_) {} | 11983 | } catch (_) {} |
12063 | })(); | 11984 | })(); |
@@ -12103,10 +12024,6 @@ function Writable(options) { | |||
12103 | if (typeof options.write === 'function') this._write = options.write; | 12024 | if (typeof options.write === 'function') this._write = options.write; |
12104 | 12025 | ||
12105 | if (typeof options.writev === 'function') this._writev = options.writev; | 12026 | if (typeof options.writev === 'function') this._writev = options.writev; |
12106 | |||
12107 | if (typeof options.destroy === 'function') this._destroy = options.destroy; | ||
12108 | |||
12109 | if (typeof options.final === 'function') this._final = options.final; | ||
12110 | } | 12027 | } |
12111 | 12028 | ||
12112 | Stream.call(this); | 12029 | Stream.call(this); |
@@ -12147,11 +12064,7 @@ function validChunk(stream, state, chunk, cb) { | |||
12147 | Writable.prototype.write = function (chunk, encoding, cb) { | 12064 | Writable.prototype.write = function (chunk, encoding, cb) { |
12148 | var state = this._writableState; | 12065 | var state = this._writableState; |
12149 | var ret = false; | 12066 | var ret = false; |
12150 | var isBuf = _isUint8Array(chunk) && !state.objectMode; | 12067 | var isBuf = Buffer.isBuffer(chunk); |
12151 | |||
12152 | if (isBuf && !Buffer.isBuffer(chunk)) { | ||
12153 | chunk = _uint8ArrayToBuffer(chunk); | ||
12154 | } | ||
12155 | 12068 | ||
12156 | if (typeof encoding === 'function') { | 12069 | if (typeof encoding === 'function') { |
12157 | cb = encoding; | 12070 | cb = encoding; |
@@ -12196,7 +12109,7 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { | |||
12196 | 12109 | ||
12197 | function decodeChunk(state, chunk, encoding) { | 12110 | function decodeChunk(state, chunk, encoding) { |
12198 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { | 12111 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { |
12199 | chunk = Buffer.from(chunk, encoding); | 12112 | chunk = bufferShim.from(chunk, encoding); |
12200 | } | 12113 | } |
12201 | return chunk; | 12114 | return chunk; |
12202 | } | 12115 | } |
@@ -12206,12 +12119,8 @@ function decodeChunk(state, chunk, encoding) { | |||
12206 | // If we return false, then we need a drain event, so set that flag. | 12119 | // If we return false, then we need a drain event, so set that flag. |
12207 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { | 12120 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { |
12208 | if (!isBuf) { | 12121 | if (!isBuf) { |
12209 | var newChunk = decodeChunk(state, chunk, encoding); | 12122 | chunk = decodeChunk(state, chunk, encoding); |
12210 | if (chunk !== newChunk) { | 12123 | if (Buffer.isBuffer(chunk)) encoding = 'buffer'; |
12211 | isBuf = true; | ||
12212 | encoding = 'buffer'; | ||
12213 | chunk = newChunk; | ||
12214 | } | ||
12215 | } | 12124 | } |
12216 | var len = state.objectMode ? 1 : chunk.length; | 12125 | var len = state.objectMode ? 1 : chunk.length; |
12217 | 12126 | ||
@@ -12223,13 +12132,7 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { | |||
12223 | 12132 | ||
12224 | if (state.writing || state.corked) { | 12133 | if (state.writing || state.corked) { |
12225 | var last = state.lastBufferedRequest; | 12134 | var last = state.lastBufferedRequest; |
12226 | state.lastBufferedRequest = { | 12135 | state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); |
12227 | chunk: chunk, | ||
12228 | encoding: encoding, | ||
12229 | isBuf: isBuf, | ||
12230 | callback: cb, | ||
12231 | next: null | ||
12232 | }; | ||
12233 | if (last) { | 12136 | if (last) { |
12234 | last.next = state.lastBufferedRequest; | 12137 | last.next = state.lastBufferedRequest; |
12235 | } else { | 12138 | } else { |
@@ -12254,26 +12157,10 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) { | |||
12254 | 12157 | ||
12255 | function onwriteError(stream, state, sync, er, cb) { | 12158 | function onwriteError(stream, state, sync, er, cb) { |
12256 | --state.pendingcb; | 12159 | --state.pendingcb; |
12160 | if (sync) processNextTick(cb, er);else cb(er); | ||
12257 | 12161 | ||
12258 | if (sync) { | 12162 | stream._writableState.errorEmitted = true; |
12259 | // defer the callback if we are being called synchronously | 12163 | stream.emit('error', er); |
12260 | // to avoid piling up things on the stack | ||
12261 | processNextTick(cb, er); | ||
12262 | // this can emit finish, and it will always happen | ||
12263 | // after error | ||
12264 | processNextTick(finishMaybe, stream, state); | ||
12265 | stream._writableState.errorEmitted = true; | ||
12266 | stream.emit('error', er); | ||
12267 | } else { | ||
12268 | // the caller expect this to happen before if | ||
12269 | // it is async | ||
12270 | cb(er); | ||
12271 | stream._writableState.errorEmitted = true; | ||
12272 | stream.emit('error', er); | ||
12273 | // this can emit finish, but finish must | ||
12274 | // always follow error | ||
12275 | finishMaybe(stream, state); | ||
12276 | } | ||
12277 | } | 12164 | } |
12278 | 12165 | ||
12279 | function onwriteStateUpdate(state) { | 12166 | function onwriteStateUpdate(state) { |
@@ -12338,14 +12225,11 @@ function clearBuffer(stream, state) { | |||
12338 | holder.entry = entry; | 12225 | holder.entry = entry; |
12339 | 12226 | ||
12340 | var count = 0; | 12227 | var count = 0; |
12341 | var allBuffers = true; | ||
12342 | while (entry) { | 12228 | while (entry) { |
12343 | buffer[count] = entry; | 12229 | buffer[count] = entry; |
12344 | if (!entry.isBuf) allBuffers = false; | ||
12345 | entry = entry.next; | 12230 | entry = entry.next; |
12346 | count += 1; | 12231 | count += 1; |
12347 | } | 12232 | } |
12348 | buffer.allBuffers = allBuffers; | ||
12349 | 12233 | ||
12350 | doWrite(stream, state, true, state.length, buffer, '', holder.finish); | 12234 | doWrite(stream, state, true, state.length, buffer, '', holder.finish); |
12351 | 12235 | ||
@@ -12419,37 +12303,23 @@ Writable.prototype.end = function (chunk, encoding, cb) { | |||
12419 | function needFinish(state) { | 12303 | function needFinish(state) { |
12420 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; | 12304 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; |
12421 | } | 12305 | } |
12422 | function callFinal(stream, state) { | 12306 | |
12423 | stream._final(function (err) { | 12307 | function prefinish(stream, state) { |
12424 | state.pendingcb--; | 12308 | if (!state.prefinished) { |
12425 | if (err) { | ||
12426 | stream.emit('error', err); | ||
12427 | } | ||
12428 | state.prefinished = true; | 12309 | state.prefinished = true; |
12429 | stream.emit('prefinish'); | 12310 | stream.emit('prefinish'); |
12430 | finishMaybe(stream, state); | ||
12431 | }); | ||
12432 | } | ||
12433 | function prefinish(stream, state) { | ||
12434 | if (!state.prefinished && !state.finalCalled) { | ||
12435 | if (typeof stream._final === 'function') { | ||
12436 | state.pendingcb++; | ||
12437 | state.finalCalled = true; | ||
12438 | processNextTick(callFinal, stream, state); | ||
12439 | } else { | ||
12440 | state.prefinished = true; | ||
12441 | stream.emit('prefinish'); | ||
12442 | } | ||
12443 | } | 12311 | } |
12444 | } | 12312 | } |
12445 | 12313 | ||
12446 | function finishMaybe(stream, state) { | 12314 | function finishMaybe(stream, state) { |
12447 | var need = needFinish(state); | 12315 | var need = needFinish(state); |
12448 | if (need) { | 12316 | if (need) { |
12449 | prefinish(stream, state); | ||
12450 | if (state.pendingcb === 0) { | 12317 | if (state.pendingcb === 0) { |
12318 | prefinish(stream, state); | ||
12451 | state.finished = true; | 12319 | state.finished = true; |
12452 | stream.emit('finish'); | 12320 | stream.emit('finish'); |
12321 | } else { | ||
12322 | prefinish(stream, state); | ||
12453 | } | 12323 | } |
12454 | } | 12324 | } |
12455 | return need; | 12325 | return need; |
@@ -12465,412 +12335,99 @@ function endWritable(stream, state, cb) { | |||
12465 | stream.writable = false; | 12335 | stream.writable = false; |
12466 | } | 12336 | } |
12467 | 12337 | ||
12468 | function onCorkedFinish(corkReq, state, err) { | 12338 | // It seems a linked list but it is not |
12469 | var entry = corkReq.entry; | 12339 | // there will be only 2 of these for each stream |
12470 | corkReq.entry = null; | 12340 | function CorkedRequest(state) { |
12471 | while (entry) { | 12341 | var _this = this; |
12472 | var cb = entry.callback; | ||
12473 | state.pendingcb--; | ||
12474 | cb(err); | ||
12475 | entry = entry.next; | ||
12476 | } | ||
12477 | if (state.corkedRequestsFree) { | ||
12478 | state.corkedRequestsFree.next = corkReq; | ||
12479 | } else { | ||
12480 | state.corkedRequestsFree = corkReq; | ||
12481 | } | ||
12482 | } | ||
12483 | 12342 | ||
12484 | Object.defineProperty(Writable.prototype, 'destroyed', { | 12343 | this.next = null; |
12485 | get: function () { | 12344 | this.entry = null; |
12486 | if (this._writableState === undefined) { | 12345 | this.finish = function (err) { |
12487 | return false; | 12346 | var entry = _this.entry; |
12488 | } | 12347 | _this.entry = null; |
12489 | return this._writableState.destroyed; | 12348 | while (entry) { |
12490 | }, | 12349 | var cb = entry.callback; |
12491 | set: function (value) { | 12350 | state.pendingcb--; |
12492 | // we ignore the value if the stream | 12351 | cb(err); |
12493 | // has not been initialized yet | 12352 | entry = entry.next; |
12494 | if (!this._writableState) { | ||
12495 | return; | ||
12496 | } | 12353 | } |
12497 | 12354 | if (state.corkedRequestsFree) { | |
12498 | // backward compatibility, the user is explicitly | 12355 | state.corkedRequestsFree.next = _this; |
12499 | // managing destroyed | 12356 | } else { |
12500 | this._writableState.destroyed = value; | 12357 | state.corkedRequestsFree = _this; |
12501 | } | ||
12502 | }); | ||
12503 | |||
12504 | Writable.prototype.destroy = destroyImpl.destroy; | ||
12505 | Writable.prototype._undestroy = destroyImpl.undestroy; | ||
12506 | Writable.prototype._destroy = function (err, cb) { | ||
12507 | this.end(); | ||
12508 | cb(err); | ||
12509 | }; | ||
12510 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
12511 | },{"./_stream_duplex":14,"./internal/streams/destroy":20,"./internal/streams/stream":21,"_process":12,"core-util-is":5,"inherits":8,"process-nextick-args":11,"safe-buffer":26,"util-deprecate":29}],19:[function(require,module,exports){ | ||
12512 | 'use strict'; | ||
12513 | |||
12514 | /*<replacement>*/ | ||
12515 | |||
12516 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
12517 | |||
12518 | var Buffer = require('safe-buffer').Buffer; | ||
12519 | /*</replacement>*/ | ||
12520 | |||
12521 | function copyBuffer(src, target, offset) { | ||
12522 | src.copy(target, offset); | ||
12523 | } | ||
12524 | |||
12525 | module.exports = function () { | ||
12526 | function BufferList() { | ||
12527 | _classCallCheck(this, BufferList); | ||
12528 | |||
12529 | this.head = null; | ||
12530 | this.tail = null; | ||
12531 | this.length = 0; | ||
12532 | } | ||
12533 | |||
12534 | BufferList.prototype.push = function push(v) { | ||
12535 | var entry = { data: v, next: null }; | ||
12536 | if (this.length > 0) this.tail.next = entry;else this.head = entry; | ||
12537 | this.tail = entry; | ||
12538 | ++this.length; | ||
12539 | }; | ||
12540 | |||
12541 | BufferList.prototype.unshift = function unshift(v) { | ||
12542 | var entry = { data: v, next: this.head }; | ||
12543 | if (this.length === 0) this.tail = entry; | ||
12544 | this.head = entry; | ||
12545 | ++this.length; | ||
12546 | }; | ||
12547 | |||
12548 | BufferList.prototype.shift = function shift() { | ||
12549 | if (this.length === 0) return; | ||
12550 | var ret = this.head.data; | ||
12551 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
12552 | --this.length; | ||
12553 | return ret; | ||
12554 | }; | ||
12555 | |||
12556 | BufferList.prototype.clear = function clear() { | ||
12557 | this.head = this.tail = null; | ||
12558 | this.length = 0; | ||
12559 | }; | ||
12560 | |||
12561 | BufferList.prototype.join = function join(s) { | ||
12562 | if (this.length === 0) return ''; | ||
12563 | var p = this.head; | ||
12564 | var ret = '' + p.data; | ||
12565 | while (p = p.next) { | ||
12566 | ret += s + p.data; | ||
12567 | }return ret; | ||
12568 | }; | ||
12569 | |||
12570 | BufferList.prototype.concat = function concat(n) { | ||
12571 | if (this.length === 0) return Buffer.alloc(0); | ||
12572 | if (this.length === 1) return this.head.data; | ||
12573 | var ret = Buffer.allocUnsafe(n >>> 0); | ||
12574 | var p = this.head; | ||
12575 | var i = 0; | ||
12576 | while (p) { | ||
12577 | copyBuffer(p.data, ret, i); | ||
12578 | i += p.data.length; | ||
12579 | p = p.next; | ||
12580 | } | 12358 | } |
12581 | return ret; | ||
12582 | }; | 12359 | }; |
12583 | 12360 | } | |
12584 | return BufferList; | 12361 | }).call(this,require('_process')) |
12585 | }(); | 12362 | },{"./_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){ |
12586 | },{"safe-buffer":26}],20:[function(require,module,exports){ | ||
12587 | 'use strict'; | 12363 | 'use strict'; |
12588 | 12364 | ||
12365 | var Buffer = require('buffer').Buffer; | ||
12589 | /*<replacement>*/ | 12366 | /*<replacement>*/ |
12590 | 12367 | var bufferShim = require('buffer-shims'); | |
12591 | var processNextTick = require('process-nextick-args'); | ||
12592 | /*</replacement>*/ | 12368 | /*</replacement>*/ |
12593 | 12369 | ||
12594 | // undocumented cb() API, needed for core, not for public API | 12370 | module.exports = BufferList; |
12595 | function destroy(err, cb) { | ||
12596 | var _this = this; | ||
12597 | |||
12598 | var readableDestroyed = this._readableState && this._readableState.destroyed; | ||
12599 | var writableDestroyed = this._writableState && this._writableState.destroyed; | ||
12600 | |||
12601 | if (readableDestroyed || writableDestroyed) { | ||
12602 | if (cb) { | ||
12603 | cb(err); | ||
12604 | } else if (err && (!this._writableState || !this._writableState.errorEmitted)) { | ||
12605 | processNextTick(emitErrorNT, this, err); | ||
12606 | } | ||
12607 | return; | ||
12608 | } | ||
12609 | |||
12610 | // we set destroyed to true before firing error callbacks in order | ||
12611 | // to make it re-entrance safe in case destroy() is called within callbacks | ||
12612 | |||
12613 | if (this._readableState) { | ||
12614 | this._readableState.destroyed = true; | ||
12615 | } | ||
12616 | |||
12617 | // if this is a duplex stream mark the writable part as destroyed as well | ||
12618 | if (this._writableState) { | ||
12619 | this._writableState.destroyed = true; | ||
12620 | } | ||
12621 | |||
12622 | this._destroy(err || null, function (err) { | ||
12623 | if (!cb && err) { | ||
12624 | processNextTick(emitErrorNT, _this, err); | ||
12625 | if (_this._writableState) { | ||
12626 | _this._writableState.errorEmitted = true; | ||
12627 | } | ||
12628 | } else if (cb) { | ||
12629 | cb(err); | ||
12630 | } | ||
12631 | }); | ||
12632 | } | ||
12633 | |||
12634 | function undestroy() { | ||
12635 | if (this._readableState) { | ||
12636 | this._readableState.destroyed = false; | ||
12637 | this._readableState.reading = false; | ||
12638 | this._readableState.ended = false; | ||
12639 | this._readableState.endEmitted = false; | ||
12640 | } | ||
12641 | |||
12642 | if (this._writableState) { | ||
12643 | this._writableState.destroyed = false; | ||
12644 | this._writableState.ended = false; | ||
12645 | this._writableState.ending = false; | ||
12646 | this._writableState.finished = false; | ||
12647 | this._writableState.errorEmitted = false; | ||
12648 | } | ||
12649 | } | ||
12650 | 12371 | ||
12651 | function emitErrorNT(self, err) { | 12372 | function BufferList() { |
12652 | self.emit('error', err); | 12373 | this.head = null; |
12374 | this.tail = null; | ||
12375 | this.length = 0; | ||
12653 | } | 12376 | } |
12654 | 12377 | ||
12655 | module.exports = { | 12378 | BufferList.prototype.push = function (v) { |
12656 | destroy: destroy, | 12379 | var entry = { data: v, next: null }; |
12657 | undestroy: undestroy | 12380 | if (this.length > 0) this.tail.next = entry;else this.head = entry; |
12381 | this.tail = entry; | ||
12382 | ++this.length; | ||
12658 | }; | 12383 | }; |
12659 | },{"process-nextick-args":11}],21:[function(require,module,exports){ | ||
12660 | module.exports = require('events').EventEmitter; | ||
12661 | |||
12662 | },{"events":6}],22:[function(require,module,exports){ | ||
12663 | module.exports = require('./readable').PassThrough | ||
12664 | |||
12665 | },{"./readable":23}],23:[function(require,module,exports){ | ||
12666 | exports = module.exports = require('./lib/_stream_readable.js'); | ||
12667 | exports.Stream = exports; | ||
12668 | exports.Readable = exports; | ||
12669 | exports.Writable = require('./lib/_stream_writable.js'); | ||
12670 | exports.Duplex = require('./lib/_stream_duplex.js'); | ||
12671 | exports.Transform = require('./lib/_stream_transform.js'); | ||
12672 | exports.PassThrough = require('./lib/_stream_passthrough.js'); | ||
12673 | |||
12674 | },{"./lib/_stream_duplex.js":14,"./lib/_stream_passthrough.js":15,"./lib/_stream_readable.js":16,"./lib/_stream_transform.js":17,"./lib/_stream_writable.js":18}],24:[function(require,module,exports){ | ||
12675 | module.exports = require('./readable').Transform | ||
12676 | |||
12677 | },{"./readable":23}],25:[function(require,module,exports){ | ||
12678 | module.exports = require('./lib/_stream_writable.js'); | ||
12679 | 12384 | ||
12680 | },{"./lib/_stream_writable.js":18}],26:[function(require,module,exports){ | 12385 | BufferList.prototype.unshift = function (v) { |
12681 | /* eslint-disable node/no-deprecated-api */ | 12386 | var entry = { data: v, next: this.head }; |
12682 | var buffer = require('buffer') | 12387 | if (this.length === 0) this.tail = entry; |
12683 | var Buffer = buffer.Buffer | 12388 | this.head = entry; |
12684 | 12389 | ++this.length; | |
12685 | // alternative to using Object.keys for old browsers | 12390 | }; |
12686 | function copyProps (src, dst) { | ||
12687 | for (var key in src) { | ||
12688 | dst[key] = src[key] | ||
12689 | } | ||
12690 | } | ||
12691 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { | ||
12692 | module.exports = buffer | ||
12693 | } else { | ||
12694 | // Copy properties from require('buffer') | ||
12695 | copyProps(buffer, exports) | ||
12696 | exports.Buffer = SafeBuffer | ||
12697 | } | ||
12698 | |||
12699 | function SafeBuffer (arg, encodingOrOffset, length) { | ||
12700 | return Buffer(arg, encodingOrOffset, length) | ||
12701 | } | ||
12702 | |||
12703 | // Copy static methods from Buffer | ||
12704 | copyProps(Buffer, SafeBuffer) | ||
12705 | |||
12706 | SafeBuffer.from = function (arg, encodingOrOffset, length) { | ||
12707 | if (typeof arg === 'number') { | ||
12708 | throw new TypeError('Argument must not be a number') | ||
12709 | } | ||
12710 | return Buffer(arg, encodingOrOffset, length) | ||
12711 | } | ||
12712 | |||
12713 | SafeBuffer.alloc = function (size, fill, encoding) { | ||
12714 | if (typeof size !== 'number') { | ||
12715 | throw new TypeError('Argument must be a number') | ||
12716 | } | ||
12717 | var buf = Buffer(size) | ||
12718 | if (fill !== undefined) { | ||
12719 | if (typeof encoding === 'string') { | ||
12720 | buf.fill(fill, encoding) | ||
12721 | } else { | ||
12722 | buf.fill(fill) | ||
12723 | } | ||
12724 | } else { | ||
12725 | buf.fill(0) | ||
12726 | } | ||
12727 | return buf | ||
12728 | } | ||
12729 | |||
12730 | SafeBuffer.allocUnsafe = function (size) { | ||
12731 | if (typeof size !== 'number') { | ||
12732 | throw new TypeError('Argument must be a number') | ||
12733 | } | ||
12734 | return Buffer(size) | ||
12735 | } | ||
12736 | |||
12737 | SafeBuffer.allocUnsafeSlow = function (size) { | ||
12738 | if (typeof size !== 'number') { | ||
12739 | throw new TypeError('Argument must be a number') | ||
12740 | } | ||
12741 | return buffer.SlowBuffer(size) | ||
12742 | } | ||
12743 | |||
12744 | },{"buffer":4}],27:[function(require,module,exports){ | ||
12745 | // Copyright Joyent, Inc. and other Node contributors. | ||
12746 | // | ||
12747 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
12748 | // copy of this software and associated documentation files (the | ||
12749 | // "Software"), to deal in the Software without restriction, including | ||
12750 | // without limitation the rights to use, copy, modify, merge, publish, | ||
12751 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
12752 | // persons to whom the Software is furnished to do so, subject to the | ||
12753 | // following conditions: | ||
12754 | // | ||
12755 | // The above copyright notice and this permission notice shall be included | ||
12756 | // in all copies or substantial portions of the Software. | ||
12757 | // | ||
12758 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
12759 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
12760 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
12761 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
12762 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
12763 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
12764 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
12765 | |||
12766 | module.exports = Stream; | ||
12767 | |||
12768 | var EE = require('events').EventEmitter; | ||
12769 | var inherits = require('inherits'); | ||
12770 | |||
12771 | inherits(Stream, EE); | ||
12772 | Stream.Readable = require('readable-stream/readable.js'); | ||
12773 | Stream.Writable = require('readable-stream/writable.js'); | ||
12774 | Stream.Duplex = require('readable-stream/duplex.js'); | ||
12775 | Stream.Transform = require('readable-stream/transform.js'); | ||
12776 | Stream.PassThrough = require('readable-stream/passthrough.js'); | ||
12777 | |||
12778 | // Backwards-compat with node 0.4.x | ||
12779 | Stream.Stream = Stream; | ||
12780 | |||
12781 | |||
12782 | |||
12783 | // old-style streams. Note that the pipe method (the only relevant | ||
12784 | // part of this class) is overridden in the Readable class. | ||
12785 | |||
12786 | function Stream() { | ||
12787 | EE.call(this); | ||
12788 | } | ||
12789 | |||
12790 | Stream.prototype.pipe = function(dest, options) { | ||
12791 | var source = this; | ||
12792 | |||
12793 | function ondata(chunk) { | ||
12794 | if (dest.writable) { | ||
12795 | if (false === dest.write(chunk) && source.pause) { | ||
12796 | source.pause(); | ||
12797 | } | ||
12798 | } | ||
12799 | } | ||
12800 | |||
12801 | source.on('data', ondata); | ||
12802 | |||
12803 | function ondrain() { | ||
12804 | if (source.readable && source.resume) { | ||
12805 | source.resume(); | ||
12806 | } | ||
12807 | } | ||
12808 | |||
12809 | dest.on('drain', ondrain); | ||
12810 | |||
12811 | // If the 'end' option is not supplied, dest.end() will be called when | ||
12812 | // source gets the 'end' or 'close' events. Only dest.end() once. | ||
12813 | if (!dest._isStdio && (!options || options.end !== false)) { | ||
12814 | source.on('end', onend); | ||
12815 | source.on('close', onclose); | ||
12816 | } | ||
12817 | |||
12818 | var didOnEnd = false; | ||
12819 | function onend() { | ||
12820 | if (didOnEnd) return; | ||
12821 | didOnEnd = true; | ||
12822 | |||
12823 | dest.end(); | ||
12824 | } | ||
12825 | |||
12826 | |||
12827 | function onclose() { | ||
12828 | if (didOnEnd) return; | ||
12829 | didOnEnd = true; | ||
12830 | |||
12831 | if (typeof dest.destroy === 'function') dest.destroy(); | ||
12832 | } | ||
12833 | |||
12834 | // don't leave dangling pipes when there are errors. | ||
12835 | function onerror(er) { | ||
12836 | cleanup(); | ||
12837 | if (EE.listenerCount(this, 'error') === 0) { | ||
12838 | throw er; // Unhandled stream error in pipe. | ||
12839 | } | ||
12840 | } | ||
12841 | |||
12842 | source.on('error', onerror); | ||
12843 | dest.on('error', onerror); | ||
12844 | |||
12845 | // remove all the event listeners that were added. | ||
12846 | function cleanup() { | ||
12847 | source.removeListener('data', ondata); | ||
12848 | dest.removeListener('drain', ondrain); | ||
12849 | 12391 | ||
12850 | source.removeListener('end', onend); | 12392 | BufferList.prototype.shift = function () { |
12851 | source.removeListener('close', onclose); | 12393 | if (this.length === 0) return; |
12394 | var ret = this.head.data; | ||
12395 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
12396 | --this.length; | ||
12397 | return ret; | ||
12398 | }; | ||
12852 | 12399 | ||
12853 | source.removeListener('error', onerror); | 12400 | BufferList.prototype.clear = function () { |
12854 | dest.removeListener('error', onerror); | 12401 | this.head = this.tail = null; |
12402 | this.length = 0; | ||
12403 | }; | ||
12855 | 12404 | ||
12856 | source.removeListener('end', cleanup); | 12405 | BufferList.prototype.join = function (s) { |
12857 | source.removeListener('close', cleanup); | 12406 | if (this.length === 0) return ''; |
12407 | var p = this.head; | ||
12408 | var ret = '' + p.data; | ||
12409 | while (p = p.next) { | ||
12410 | ret += s + p.data; | ||
12411 | }return ret; | ||
12412 | }; | ||
12858 | 12413 | ||
12859 | dest.removeListener('close', cleanup); | 12414 | BufferList.prototype.concat = function (n) { |
12415 | if (this.length === 0) return bufferShim.alloc(0); | ||
12416 | if (this.length === 1) return this.head.data; | ||
12417 | var ret = bufferShim.allocUnsafe(n >>> 0); | ||
12418 | var p = this.head; | ||
12419 | var i = 0; | ||
12420 | while (p) { | ||
12421 | p.data.copy(ret, i); | ||
12422 | i += p.data.length; | ||
12423 | p = p.next; | ||
12860 | } | 12424 | } |
12861 | 12425 | return ret; | |
12862 | source.on('end', cleanup); | ||
12863 | source.on('close', cleanup); | ||
12864 | |||
12865 | dest.on('close', cleanup); | ||
12866 | |||
12867 | dest.emit('pipe', source); | ||
12868 | |||
12869 | // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
12870 | return dest; | ||
12871 | }; | 12426 | }; |
12427 | },{"buffer":5,"buffer-shims":4}],21:[function(require,module,exports){ | ||
12428 | module.exports = require('events').EventEmitter; | ||
12872 | 12429 | ||
12873 | },{"events":6,"inherits":8,"readable-stream/duplex.js":13,"readable-stream/passthrough.js":22,"readable-stream/readable.js":23,"readable-stream/transform.js":24,"readable-stream/writable.js":25}],28:[function(require,module,exports){ | 12430 | },{"events":7}],22:[function(require,module,exports){ |
12874 | 'use strict'; | 12431 | 'use strict'; |
12875 | 12432 | ||
12876 | var Buffer = require('safe-buffer').Buffer; | 12433 | var Buffer = require('safe-buffer').Buffer; |
@@ -13143,7 +12700,380 @@ function simpleWrite(buf) { | |||
13143 | function simpleEnd(buf) { | 12700 | function simpleEnd(buf) { |
13144 | return buf && buf.length ? this.write(buf) : ''; | 12701 | return buf && buf.length ? this.write(buf) : ''; |
13145 | } | 12702 | } |
13146 | },{"safe-buffer":26}],29:[function(require,module,exports){ | 12703 | },{"safe-buffer":27}],23:[function(require,module,exports){ |
12704 | module.exports = require('./readable').PassThrough | ||
12705 | |||
12706 | },{"./readable":24}],24:[function(require,module,exports){ | ||
12707 | exports = module.exports = require('./lib/_stream_readable.js'); | ||
12708 | exports.Stream = exports; | ||
12709 | exports.Readable = exports; | ||
12710 | exports.Writable = require('./lib/_stream_writable.js'); | ||
12711 | exports.Duplex = require('./lib/_stream_duplex.js'); | ||
12712 | exports.Transform = require('./lib/_stream_transform.js'); | ||
12713 | exports.PassThrough = require('./lib/_stream_passthrough.js'); | ||
12714 | |||
12715 | },{"./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){ | ||
12716 | module.exports = require('./readable').Transform | ||
12717 | |||
12718 | },{"./readable":24}],26:[function(require,module,exports){ | ||
12719 | module.exports = require('./lib/_stream_writable.js'); | ||
12720 | |||
12721 | },{"./lib/_stream_writable.js":19}],27:[function(require,module,exports){ | ||
12722 | module.exports = require('buffer') | ||
12723 | |||
12724 | },{"buffer":5}],28:[function(require,module,exports){ | ||
12725 | // Copyright Joyent, Inc. and other Node contributors. | ||
12726 | // | ||
12727 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
12728 | // copy of this software and associated documentation files (the | ||
12729 | // "Software"), to deal in the Software without restriction, including | ||
12730 | // without limitation the rights to use, copy, modify, merge, publish, | ||
12731 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
12732 | // persons to whom the Software is furnished to do so, subject to the | ||
12733 | // following conditions: | ||
12734 | // | ||
12735 | // The above copyright notice and this permission notice shall be included | ||
12736 | // in all copies or substantial portions of the Software. | ||
12737 | // | ||
12738 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
12739 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
12740 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
12741 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
12742 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
12743 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
12744 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
12745 | |||
12746 | module.exports = Stream; | ||
12747 | |||
12748 | var EE = require('events').EventEmitter; | ||
12749 | var inherits = require('inherits'); | ||
12750 | |||
12751 | inherits(Stream, EE); | ||
12752 | Stream.Readable = require('readable-stream/readable.js'); | ||
12753 | Stream.Writable = require('readable-stream/writable.js'); | ||
12754 | Stream.Duplex = require('readable-stream/duplex.js'); | ||
12755 | Stream.Transform = require('readable-stream/transform.js'); | ||
12756 | Stream.PassThrough = require('readable-stream/passthrough.js'); | ||
12757 | |||
12758 | // Backwards-compat with node 0.4.x | ||
12759 | Stream.Stream = Stream; | ||
12760 | |||
12761 | |||
12762 | |||
12763 | // old-style streams. Note that the pipe method (the only relevant | ||
12764 | // part of this class) is overridden in the Readable class. | ||
12765 | |||
12766 | function Stream() { | ||
12767 | EE.call(this); | ||
12768 | } | ||
12769 | |||
12770 | Stream.prototype.pipe = function(dest, options) { | ||
12771 | var source = this; | ||
12772 | |||
12773 | function ondata(chunk) { | ||
12774 | if (dest.writable) { | ||
12775 | if (false === dest.write(chunk) && source.pause) { | ||
12776 | source.pause(); | ||
12777 | } | ||
12778 | } | ||
12779 | } | ||
12780 | |||
12781 | source.on('data', ondata); | ||
12782 | |||
12783 | function ondrain() { | ||
12784 | if (source.readable && source.resume) { | ||
12785 | source.resume(); | ||
12786 | } | ||
12787 | } | ||
12788 | |||
12789 | dest.on('drain', ondrain); | ||
12790 | |||
12791 | // If the 'end' option is not supplied, dest.end() will be called when | ||
12792 | // source gets the 'end' or 'close' events. Only dest.end() once. | ||
12793 | if (!dest._isStdio && (!options || options.end !== false)) { | ||
12794 | source.on('end', onend); | ||
12795 | source.on('close', onclose); | ||
12796 | } | ||
12797 | |||
12798 | var didOnEnd = false; | ||
12799 | function onend() { | ||
12800 | if (didOnEnd) return; | ||
12801 | didOnEnd = true; | ||
12802 | |||
12803 | dest.end(); | ||
12804 | } | ||
12805 | |||
12806 | |||
12807 | function onclose() { | ||
12808 | if (didOnEnd) return; | ||
12809 | didOnEnd = true; | ||
12810 | |||
12811 | if (typeof dest.destroy === 'function') dest.destroy(); | ||
12812 | } | ||
12813 | |||
12814 | // don't leave dangling pipes when there are errors. | ||
12815 | function onerror(er) { | ||
12816 | cleanup(); | ||
12817 | if (EE.listenerCount(this, 'error') === 0) { | ||
12818 | throw er; // Unhandled stream error in pipe. | ||
12819 | } | ||
12820 | } | ||
12821 | |||
12822 | source.on('error', onerror); | ||
12823 | dest.on('error', onerror); | ||
12824 | |||
12825 | // remove all the event listeners that were added. | ||
12826 | function cleanup() { | ||
12827 | source.removeListener('data', ondata); | ||
12828 | dest.removeListener('drain', ondrain); | ||
12829 | |||
12830 | source.removeListener('end', onend); | ||
12831 | source.removeListener('close', onclose); | ||
12832 | |||
12833 | source.removeListener('error', onerror); | ||
12834 | dest.removeListener('error', onerror); | ||
12835 | |||
12836 | source.removeListener('end', cleanup); | ||
12837 | source.removeListener('close', cleanup); | ||
12838 | |||
12839 | dest.removeListener('close', cleanup); | ||
12840 | } | ||
12841 | |||
12842 | source.on('end', cleanup); | ||
12843 | source.on('close', cleanup); | ||
12844 | |||
12845 | dest.on('close', cleanup); | ||
12846 | |||
12847 | dest.emit('pipe', source); | ||
12848 | |||
12849 | // Allow for unix-like usage: A.pipe(B).pipe(C) | ||
12850 | return dest; | ||
12851 | }; | ||
12852 | |||
12853 | },{"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){ | ||
12854 | // Copyright Joyent, Inc. and other Node contributors. | ||
12855 | // | ||
12856 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
12857 | // copy of this software and associated documentation files (the | ||
12858 | // "Software"), to deal in the Software without restriction, including | ||
12859 | // without limitation the rights to use, copy, modify, merge, publish, | ||
12860 | // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
12861 | // persons to whom the Software is furnished to do so, subject to the | ||
12862 | // following conditions: | ||
12863 | // | ||
12864 | // The above copyright notice and this permission notice shall be included | ||
12865 | // in all copies or substantial portions of the Software. | ||
12866 | // | ||
12867 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
12868 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
12869 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
12870 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
12871 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
12872 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
12873 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
12874 | |||
12875 | var Buffer = require('buffer').Buffer; | ||
12876 | |||
12877 | var isBufferEncoding = Buffer.isEncoding | ||
12878 | || function(encoding) { | ||
12879 | switch (encoding && encoding.toLowerCase()) { | ||
12880 | 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; | ||
12881 | default: return false; | ||
12882 | } | ||
12883 | } | ||
12884 | |||
12885 | |||
12886 | function assertEncoding(encoding) { | ||
12887 | if (encoding && !isBufferEncoding(encoding)) { | ||
12888 | throw new Error('Unknown encoding: ' + encoding); | ||
12889 | } | ||
12890 | } | ||
12891 | |||
12892 | // StringDecoder provides an interface for efficiently splitting a series of | ||
12893 | // buffers into a series of JS strings without breaking apart multi-byte | ||
12894 | // characters. CESU-8 is handled as part of the UTF-8 encoding. | ||
12895 | // | ||
12896 | // @TODO Handling all encodings inside a single object makes it very difficult | ||
12897 | // to reason about this code, so it should be split up in the future. | ||
12898 | // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code | ||
12899 | // points as used by CESU-8. | ||
12900 | var StringDecoder = exports.StringDecoder = function(encoding) { | ||
12901 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); | ||
12902 | assertEncoding(encoding); | ||
12903 | switch (this.encoding) { | ||
12904 | case 'utf8': | ||
12905 | // CESU-8 represents each of Surrogate Pair by 3-bytes | ||
12906 | this.surrogateSize = 3; | ||
12907 | break; | ||
12908 | case 'ucs2': | ||
12909 | case 'utf16le': | ||
12910 | // UTF-16 represents each of Surrogate Pair by 2-bytes | ||
12911 | this.surrogateSize = 2; | ||
12912 | this.detectIncompleteChar = utf16DetectIncompleteChar; | ||
12913 | break; | ||
12914 | case 'base64': | ||
12915 | // Base-64 stores 3 bytes in 4 chars, and pads the remainder. | ||
12916 | this.surrogateSize = 3; | ||
12917 | this.detectIncompleteChar = base64DetectIncompleteChar; | ||
12918 | break; | ||
12919 | default: | ||
12920 | this.write = passThroughWrite; | ||
12921 | return; | ||
12922 | } | ||
12923 | |||
12924 | // Enough space to store all bytes of a single character. UTF-8 needs 4 | ||
12925 | // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate). | ||
12926 | this.charBuffer = new Buffer(6); | ||
12927 | // Number of bytes received for the current incomplete multi-byte character. | ||
12928 | this.charReceived = 0; | ||
12929 | // Number of bytes expected for the current incomplete multi-byte character. | ||
12930 | this.charLength = 0; | ||
12931 | }; | ||
12932 | |||
12933 | |||
12934 | // write decodes the given buffer and returns it as JS string that is | ||
12935 | // guaranteed to not contain any partial multi-byte characters. Any partial | ||
12936 | // character found at the end of the buffer is buffered up, and will be | ||
12937 | // returned when calling write again with the remaining bytes. | ||
12938 | // | ||
12939 | // Note: Converting a Buffer containing an orphan surrogate to a String | ||
12940 | // currently works, but converting a String to a Buffer (via `new Buffer`, or | ||
12941 | // Buffer#write) will replace incomplete surrogates with the unicode | ||
12942 | // replacement character. See https://codereview.chromium.org/121173009/ . | ||
12943 | StringDecoder.prototype.write = function(buffer) { | ||
12944 | var charStr = ''; | ||
12945 | // if our last write ended with an incomplete multibyte character | ||
12946 | while (this.charLength) { | ||
12947 | // determine how many remaining bytes this buffer has to offer for this char | ||
12948 | var available = (buffer.length >= this.charLength - this.charReceived) ? | ||
12949 | this.charLength - this.charReceived : | ||
12950 | buffer.length; | ||
12951 | |||
12952 | // add the new bytes to the char buffer | ||
12953 | buffer.copy(this.charBuffer, this.charReceived, 0, available); | ||
12954 | this.charReceived += available; | ||
12955 | |||
12956 | if (this.charReceived < this.charLength) { | ||
12957 | // still not enough chars in this buffer? wait for more ... | ||
12958 | return ''; | ||
12959 | } | ||
12960 | |||
12961 | // remove bytes belonging to the current character from the buffer | ||
12962 | buffer = buffer.slice(available, buffer.length); | ||
12963 | |||
12964 | // get the character that was split | ||
12965 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); | ||
12966 | |||
12967 | // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character | ||
12968 | var charCode = charStr.charCodeAt(charStr.length - 1); | ||
12969 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { | ||
12970 | this.charLength += this.surrogateSize; | ||
12971 | charStr = ''; | ||
12972 | continue; | ||
12973 | } | ||
12974 | this.charReceived = this.charLength = 0; | ||
12975 | |||
12976 | // if there are no more bytes in this buffer, just emit our char | ||
12977 | if (buffer.length === 0) { | ||
12978 | return charStr; | ||
12979 | } | ||
12980 | break; | ||
12981 | } | ||
12982 | |||
12983 | // determine and set charLength / charReceived | ||
12984 | this.detectIncompleteChar(buffer); | ||
12985 | |||
12986 | var end = buffer.length; | ||
12987 | if (this.charLength) { | ||
12988 | // buffer the incomplete character bytes we got | ||
12989 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); | ||
12990 | end -= this.charReceived; | ||
12991 | } | ||
12992 | |||
12993 | charStr += buffer.toString(this.encoding, 0, end); | ||
12994 | |||
12995 | var end = charStr.length - 1; | ||
12996 | var charCode = charStr.charCodeAt(end); | ||
12997 | // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character | ||
12998 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { | ||
12999 | var size = this.surrogateSize; | ||
13000 | this.charLength += size; | ||
13001 | this.charReceived += size; | ||
13002 | this.charBuffer.copy(this.charBuffer, size, 0, size); | ||
13003 | buffer.copy(this.charBuffer, 0, 0, size); | ||
13004 | return charStr.substring(0, end); | ||
13005 | } | ||
13006 | |||
13007 | // or just emit the charStr | ||
13008 | return charStr; | ||
13009 | }; | ||
13010 | |||
13011 | // detectIncompleteChar determines if there is an incomplete UTF-8 character at | ||
13012 | // the end of the given buffer. If so, it sets this.charLength to the byte | ||
13013 | // length that character, and sets this.charReceived to the number of bytes | ||
13014 | // that are available for this character. | ||
13015 | StringDecoder.prototype.detectIncompleteChar = function(buffer) { | ||
13016 | // determine how many bytes we have to check at the end of this buffer | ||
13017 | var i = (buffer.length >= 3) ? 3 : buffer.length; | ||
13018 | |||
13019 | // Figure out if one of the last i bytes of our buffer announces an | ||
13020 | // incomplete char. | ||
13021 | for (; i > 0; i--) { | ||
13022 | var c = buffer[buffer.length - i]; | ||
13023 | |||
13024 | // See http://en.wikipedia.org/wiki/UTF-8#Description | ||
13025 | |||
13026 | // 110XXXXX | ||
13027 | if (i == 1 && c >> 5 == 0x06) { | ||
13028 | this.charLength = 2; | ||
13029 | break; | ||
13030 | } | ||
13031 | |||
13032 | // 1110XXXX | ||
13033 | if (i <= 2 && c >> 4 == 0x0E) { | ||
13034 | this.charLength = 3; | ||
13035 | break; | ||
13036 | } | ||
13037 | |||
13038 | // 11110XXX | ||
13039 | if (i <= 3 && c >> 3 == 0x1E) { | ||
13040 | this.charLength = 4; | ||
13041 | break; | ||
13042 | } | ||
13043 | } | ||
13044 | this.charReceived = i; | ||
13045 | }; | ||
13046 | |||
13047 | StringDecoder.prototype.end = function(buffer) { | ||
13048 | var res = ''; | ||
13049 | if (buffer && buffer.length) | ||
13050 | res = this.write(buffer); | ||
13051 | |||
13052 | if (this.charReceived) { | ||
13053 | var cr = this.charReceived; | ||
13054 | var buf = this.charBuffer; | ||
13055 | var enc = this.encoding; | ||
13056 | res += buf.slice(0, cr).toString(enc); | ||
13057 | } | ||
13058 | |||
13059 | return res; | ||
13060 | }; | ||
13061 | |||
13062 | function passThroughWrite(buffer) { | ||
13063 | return buffer.toString(this.encoding); | ||
13064 | } | ||
13065 | |||
13066 | function utf16DetectIncompleteChar(buffer) { | ||
13067 | this.charReceived = buffer.length % 2; | ||
13068 | this.charLength = this.charReceived ? 2 : 0; | ||
13069 | } | ||
13070 | |||
13071 | function base64DetectIncompleteChar(buffer) { | ||
13072 | this.charReceived = buffer.length % 3; | ||
13073 | this.charLength = this.charReceived ? 3 : 0; | ||
13074 | } | ||
13075 | |||
13076 | },{"buffer":5}],30:[function(require,module,exports){ | ||
13147 | (function (global){ | 13077 | (function (global){ |
13148 | 13078 | ||
13149 | /** | 13079 | /** |
@@ -13214,16 +13144,16 @@ function config (name) { | |||
13214 | } | 13144 | } |
13215 | 13145 | ||
13216 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | 13146 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
13217 | },{}],30:[function(require,module,exports){ | 13147 | },{}],31:[function(require,module,exports){ |
13218 | arguments[4][8][0].apply(exports,arguments) | 13148 | arguments[4][9][0].apply(exports,arguments) |
13219 | },{"dup":8}],31:[function(require,module,exports){ | 13149 | },{"dup":9}],32:[function(require,module,exports){ |
13220 | module.exports = function isBuffer(arg) { | 13150 | module.exports = function isBuffer(arg) { |
13221 | return arg && typeof arg === 'object' | 13151 | return arg && typeof arg === 'object' |
13222 | && typeof arg.copy === 'function' | 13152 | && typeof arg.copy === 'function' |
13223 | && typeof arg.fill === 'function' | 13153 | && typeof arg.fill === 'function' |
13224 | && typeof arg.readUInt8 === 'function'; | 13154 | && typeof arg.readUInt8 === 'function'; |
13225 | } | 13155 | } |
13226 | },{}],32:[function(require,module,exports){ | 13156 | },{}],33:[function(require,module,exports){ |
13227 | (function (process,global){ | 13157 | (function (process,global){ |
13228 | // Copyright Joyent, Inc. and other Node contributors. | 13158 | // Copyright Joyent, Inc. and other Node contributors. |
13229 | // | 13159 | // |
@@ -13813,15 +13743,20 @@ function hasOwnProperty(obj, prop) { | |||
13813 | } | 13743 | } |
13814 | 13744 | ||
13815 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | 13745 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
13816 | },{"./support/isBuffer":31,"_process":12,"inherits":30}],33:[function(require,module,exports){ | 13746 | },{"./support/isBuffer":32,"_process":13,"inherits":31}],34:[function(require,module,exports){ |
13817 | module.exports = { | 13747 | bitcoin = { |
13818 | base58: require('bs58'), | 13748 | base58: require('bs58'), |
13819 | bitcoin: require('bitcoinjs-lib'), | 13749 | bitcoin: require('bitcoinjs-lib'), |
13820 | ecurve: require('ecurve'), | 13750 | ecurve: require('ecurve'), |
13821 | BigInteger: require('bigi') | 13751 | BigInteger: require('bigi'), |
13752 | Buffer: require('buffer'), | ||
13753 | elliptic: require('elliptic'), | ||
13754 | bs58check: require('bs58check'), | ||
13822 | } | 13755 | } |
13823 | 13756 | ||
13824 | },{"bigi":37,"bitcoinjs-lib":50,"bs58":79,"ecurve":89}],34:[function(require,module,exports){ | 13757 | module.exports = bitcoin; |
13758 | |||
13759 | },{"bigi":39,"bitcoinjs-lib":52,"bs58":83,"bs58check":85,"buffer":5,"ecurve":94,"elliptic":97}],35:[function(require,module,exports){ | ||
13825 | // base-x encoding | 13760 | // base-x encoding |
13826 | // Forked from https://github.com/cryptocoinjs/bs58 | 13761 | // Forked from https://github.com/cryptocoinjs/bs58 |
13827 | // Originally written by Mike Hearn for BitcoinJ | 13762 | // Originally written by Mike Hearn for BitcoinJ |
@@ -13914,7 +13849,148 @@ module.exports = function base (ALPHABET) { | |||
13914 | } | 13849 | } |
13915 | } | 13850 | } |
13916 | 13851 | ||
13917 | },{"safe-buffer":98}],35:[function(require,module,exports){ | 13852 | },{"safe-buffer":128}],36:[function(require,module,exports){ |
13853 | 'use strict' | ||
13854 | let ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l' | ||
13855 | |||
13856 | // pre-compute lookup table | ||
13857 | let ALPHABET_MAP = {} | ||
13858 | for (let z = 0; z < ALPHABET.length; z++) { | ||
13859 | let x = ALPHABET.charAt(z) | ||
13860 | |||
13861 | if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous') | ||
13862 | ALPHABET_MAP[x] = z | ||
13863 | } | ||
13864 | |||
13865 | function polymodStep (pre) { | ||
13866 | let b = pre >> 25 | ||
13867 | return ((pre & 0x1FFFFFF) << 5) ^ | ||
13868 | (-((b >> 0) & 1) & 0x3b6a57b2) ^ | ||
13869 | (-((b >> 1) & 1) & 0x26508e6d) ^ | ||
13870 | (-((b >> 2) & 1) & 0x1ea119fa) ^ | ||
13871 | (-((b >> 3) & 1) & 0x3d4233dd) ^ | ||
13872 | (-((b >> 4) & 1) & 0x2a1462b3) | ||
13873 | } | ||
13874 | |||
13875 | function prefixChk (prefix) { | ||
13876 | let chk = 1 | ||
13877 | for (let i = 0; i < prefix.length; ++i) { | ||
13878 | let c = prefix.charCodeAt(i) | ||
13879 | if (c < 33 || c > 126) throw new Error('Invalid prefix (' + prefix + ')') | ||
13880 | |||
13881 | chk = polymodStep(chk) ^ (c >> 5) | ||
13882 | } | ||
13883 | chk = polymodStep(chk) | ||
13884 | |||
13885 | for (let i = 0; i < prefix.length; ++i) { | ||
13886 | let v = prefix.charCodeAt(i) | ||
13887 | chk = polymodStep(chk) ^ (v & 0x1f) | ||
13888 | } | ||
13889 | return chk | ||
13890 | } | ||
13891 | |||
13892 | function encode (prefix, words) { | ||
13893 | // too long? | ||
13894 | if ((prefix.length + 7 + words.length) > 90) throw new TypeError('Exceeds Bech32 maximum length') | ||
13895 | prefix = prefix.toLowerCase() | ||
13896 | |||
13897 | // determine chk mod | ||
13898 | let chk = prefixChk(prefix) | ||
13899 | let result = prefix + '1' | ||
13900 | for (let i = 0; i < words.length; ++i) { | ||
13901 | let x = words[i] | ||
13902 | if ((x >> 5) !== 0) throw new Error('Non 5-bit word') | ||
13903 | |||
13904 | chk = polymodStep(chk) ^ x | ||
13905 | result += ALPHABET.charAt(x) | ||
13906 | } | ||
13907 | |||
13908 | for (let i = 0; i < 6; ++i) { | ||
13909 | chk = polymodStep(chk) | ||
13910 | } | ||
13911 | chk ^= 1 | ||
13912 | |||
13913 | for (let i = 0; i < 6; ++i) { | ||
13914 | let v = (chk >> ((5 - i) * 5)) & 0x1f | ||
13915 | result += ALPHABET.charAt(v) | ||
13916 | } | ||
13917 | |||
13918 | return result | ||
13919 | } | ||
13920 | |||
13921 | function decode (str) { | ||
13922 | if (str.length < 8) throw new TypeError(str + ' too short') | ||
13923 | if (str.length > 90) throw new TypeError(str + ' too long') | ||
13924 | |||
13925 | // don't allow mixed case | ||
13926 | let lowered = str.toLowerCase() | ||
13927 | let uppered = str.toUpperCase() | ||
13928 | if (str !== lowered && str !== uppered) throw new Error('Mixed-case string ' + str) | ||
13929 | str = lowered | ||
13930 | |||
13931 | let split = str.lastIndexOf('1') | ||
13932 | if (split === 0) throw new Error('Missing prefix for ' + str) | ||
13933 | |||
13934 | let prefix = str.slice(0, split) | ||
13935 | let wordChars = str.slice(split + 1) | ||
13936 | if (wordChars.length < 6) throw new Error('Data too short') | ||
13937 | |||
13938 | let chk = prefixChk(prefix) | ||
13939 | let words = [] | ||
13940 | for (let i = 0; i < wordChars.length; ++i) { | ||
13941 | let c = wordChars.charAt(i) | ||
13942 | let v = ALPHABET_MAP[c] | ||
13943 | if (v === undefined) throw new Error('Unknown character ' + c) | ||
13944 | chk = polymodStep(chk) ^ v | ||
13945 | |||
13946 | // not in the checksum? | ||
13947 | if (i + 6 >= wordChars.length) continue | ||
13948 | words.push(v) | ||
13949 | } | ||
13950 | |||
13951 | if (chk !== 1) throw new Error('Invalid checksum for ' + str) | ||
13952 | return { prefix, words } | ||
13953 | } | ||
13954 | |||
13955 | function convert (data, inBits, outBits, pad) { | ||
13956 | let value = 0 | ||
13957 | let bits = 0 | ||
13958 | let maxV = (1 << outBits) - 1 | ||
13959 | |||
13960 | let result = [] | ||
13961 | for (let i = 0; i < data.length; ++i) { | ||
13962 | value = (value << inBits) | data[i] | ||
13963 | bits += inBits | ||
13964 | |||
13965 | while (bits >= outBits) { | ||
13966 | bits -= outBits | ||
13967 | result.push((value >> bits) & maxV) | ||
13968 | } | ||
13969 | } | ||
13970 | |||
13971 | if (pad) { | ||
13972 | if (bits > 0) { | ||
13973 | result.push((value << (outBits - bits)) & maxV) | ||
13974 | } | ||
13975 | } else { | ||
13976 | if (bits >= inBits) throw new Error('Excess padding') | ||
13977 | if ((value << (outBits - bits)) & maxV) throw new Error('Non-zero padding') | ||
13978 | } | ||
13979 | |||
13980 | return result | ||
13981 | } | ||
13982 | |||
13983 | function toWords (bytes) { | ||
13984 | return convert(bytes, 8, 5, true) | ||
13985 | } | ||
13986 | |||
13987 | function fromWords (words) { | ||
13988 | return convert(words, 5, 8, false) | ||
13989 | } | ||
13990 | |||
13991 | module.exports = { decode, encode, toWords, fromWords } | ||
13992 | |||
13993 | },{}],37:[function(require,module,exports){ | ||
13918 | // (public) Constructor | 13994 | // (public) Constructor |
13919 | function BigInteger(a, b, c) { | 13995 | function BigInteger(a, b, c) { |
13920 | if (!(this instanceof BigInteger)) | 13996 | if (!(this instanceof BigInteger)) |
@@ -15425,7 +15501,7 @@ BigInteger.valueOf = nbv | |||
15425 | 15501 | ||
15426 | module.exports = BigInteger | 15502 | module.exports = BigInteger |
15427 | 15503 | ||
15428 | },{"../package.json":38}],36:[function(require,module,exports){ | 15504 | },{"../package.json":40}],38:[function(require,module,exports){ |
15429 | (function (Buffer){ | 15505 | (function (Buffer){ |
15430 | // FIXME: Kind of a weird way to throw exceptions, consider removing | 15506 | // FIXME: Kind of a weird way to throw exceptions, consider removing |
15431 | var assert = require('assert') | 15507 | var assert = require('assert') |
@@ -15520,14 +15596,14 @@ BigInteger.prototype.toHex = function(size) { | |||
15520 | } | 15596 | } |
15521 | 15597 | ||
15522 | }).call(this,require("buffer").Buffer) | 15598 | }).call(this,require("buffer").Buffer) |
15523 | },{"./bigi":35,"assert":1,"buffer":4}],37:[function(require,module,exports){ | 15599 | },{"./bigi":37,"assert":1,"buffer":5}],39:[function(require,module,exports){ |
15524 | var BigInteger = require('./bigi') | 15600 | var BigInteger = require('./bigi') |
15525 | 15601 | ||
15526 | //addons | 15602 | //addons |
15527 | require('./convert') | 15603 | require('./convert') |
15528 | 15604 | ||
15529 | module.exports = BigInteger | 15605 | module.exports = BigInteger |
15530 | },{"./bigi":35,"./convert":36}],38:[function(require,module,exports){ | 15606 | },{"./bigi":37,"./convert":38}],40:[function(require,module,exports){ |
15531 | module.exports={ | 15607 | module.exports={ |
15532 | "_args": [ | 15608 | "_args": [ |
15533 | [ | 15609 | [ |
@@ -15654,7 +15730,7 @@ module.exports={ | |||
15654 | "version": "1.4.2" | 15730 | "version": "1.4.2" |
15655 | } | 15731 | } |
15656 | 15732 | ||
15657 | },{}],39:[function(require,module,exports){ | 15733 | },{}],41:[function(require,module,exports){ |
15658 | // Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki | 15734 | // Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki |
15659 | // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] | 15735 | // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] |
15660 | // NOTE: SIGHASH byte ignored AND restricted, truncate before use | 15736 | // NOTE: SIGHASH byte ignored AND restricted, truncate before use |
@@ -15769,7 +15845,7 @@ module.exports = { | |||
15769 | encode: encode | 15845 | encode: encode |
15770 | } | 15846 | } |
15771 | 15847 | ||
15772 | },{"safe-buffer":98}],40:[function(require,module,exports){ | 15848 | },{"safe-buffer":128}],42:[function(require,module,exports){ |
15773 | module.exports={ | 15849 | module.exports={ |
15774 | "OP_FALSE": 0, | 15850 | "OP_FALSE": 0, |
15775 | "OP_0": 0, | 15851 | "OP_0": 0, |
@@ -15901,7 +15977,7 @@ module.exports={ | |||
15901 | "OP_INVALIDOPCODE": 255 | 15977 | "OP_INVALIDOPCODE": 255 |
15902 | } | 15978 | } |
15903 | 15979 | ||
15904 | },{}],41:[function(require,module,exports){ | 15980 | },{}],43:[function(require,module,exports){ |
15905 | var OPS = require('./index.json') | 15981 | var OPS = require('./index.json') |
15906 | 15982 | ||
15907 | var map = {} | 15983 | var map = {} |
@@ -15912,23 +15988,38 @@ for (var op in OPS) { | |||
15912 | 15988 | ||
15913 | module.exports = map | 15989 | module.exports = map |
15914 | 15990 | ||
15915 | },{"./index.json":40}],42:[function(require,module,exports){ | 15991 | },{"./index.json":42}],44:[function(require,module,exports){ |
15916 | var Buffer = require('safe-buffer').Buffer | 15992 | var Buffer = require('safe-buffer').Buffer |
15993 | var bech32 = require('bech32') | ||
15917 | var bs58check = require('bs58check') | 15994 | var bs58check = require('bs58check') |
15918 | var bscript = require('./script') | 15995 | var bscript = require('./script') |
15996 | var btemplates = require('./templates') | ||
15919 | var networks = require('./networks') | 15997 | var networks = require('./networks') |
15920 | var typeforce = require('typeforce') | 15998 | var typeforce = require('typeforce') |
15921 | var types = require('./types') | 15999 | var types = require('./types') |
15922 | 16000 | ||
15923 | function fromBase58Check (address) { | 16001 | function fromBase58Check (address) { |
15924 | var payload = bs58check.decode(address) | 16002 | var payload = bs58check.decode(address) |
16003 | |||
16004 | // TODO: 4.0.0, move to "toOutputScript" | ||
15925 | if (payload.length < 21) throw new TypeError(address + ' is too short') | 16005 | if (payload.length < 21) throw new TypeError(address + ' is too short') |
15926 | if (payload.length > 21) throw new TypeError(address + ' is too long') | 16006 | if (payload.length > 21) throw new TypeError(address + ' is too long') |
15927 | 16007 | ||
15928 | var version = payload.readUInt8(0) | 16008 | var version = payload.readUInt8(0) |
15929 | var hash = payload.slice(1) | 16009 | var hash = payload.slice(1) |
15930 | 16010 | ||
15931 | return { hash: hash, version: version } | 16011 | return { version: version, hash: hash } |
16012 | } | ||
16013 | |||
16014 | function fromBech32 (address) { | ||
16015 | var result = bech32.decode(address) | ||
16016 | var data = bech32.fromWords(result.words.slice(1)) | ||
16017 | |||
16018 | return { | ||
16019 | version: result.words[0], | ||
16020 | prefix: result.prefix, | ||
16021 | data: Buffer.from(data) | ||
16022 | } | ||
15932 | } | 16023 | } |
15933 | 16024 | ||
15934 | function toBase58Check (hash, version) { | 16025 | function toBase58Check (hash, version) { |
@@ -15941,11 +16032,20 @@ function toBase58Check (hash, version) { | |||
15941 | return bs58check.encode(payload) | 16032 | return bs58check.encode(payload) |
15942 | } | 16033 | } |
15943 | 16034 | ||
16035 | function toBech32 (data, version, prefix) { | ||
16036 | var words = bech32.toWords(data) | ||
16037 | words.unshift(version) | ||
16038 | |||
16039 | return bech32.encode(prefix, words) | ||
16040 | } | ||
16041 | |||
15944 | function fromOutputScript (outputScript, network) { | 16042 | function fromOutputScript (outputScript, network) { |
15945 | network = network || networks.bitcoin | 16043 | network = network || networks.bitcoin |
15946 | 16044 | ||
15947 | if (bscript.pubKeyHash.output.check(outputScript)) return toBase58Check(bscript.compile(outputScript).slice(3, 23), network.pubKeyHash) | 16045 | if (btemplates.pubKeyHash.output.check(outputScript)) return toBase58Check(bscript.compile(outputScript).slice(3, 23), network.pubKeyHash) |
15948 | if (bscript.scriptHash.output.check(outputScript)) return toBase58Check(bscript.compile(outputScript).slice(2, 22), network.scriptHash) | 16046 | if (btemplates.scriptHash.output.check(outputScript)) return toBase58Check(bscript.compile(outputScript).slice(2, 22), network.scriptHash) |
16047 | if (btemplates.witnessPubKeyHash.output.check(outputScript)) return toBech32(bscript.compile(outputScript).slice(2, 22), 0, network.bech32) | ||
16048 | if (btemplates.witnessScriptHash.output.check(outputScript)) return toBech32(bscript.compile(outputScript).slice(2, 34), 0, network.bech32) | ||
15949 | 16049 | ||
15950 | throw new Error(bscript.toASM(outputScript) + ' has no matching Address') | 16050 | throw new Error(bscript.toASM(outputScript) + ' has no matching Address') |
15951 | } | 16051 | } |
@@ -15953,21 +16053,41 @@ function fromOutputScript (outputScript, network) { | |||
15953 | function toOutputScript (address, network) { | 16053 | function toOutputScript (address, network) { |
15954 | network = network || networks.bitcoin | 16054 | network = network || networks.bitcoin |
15955 | 16055 | ||
15956 | var decode = fromBase58Check(address) | 16056 | var decode |
15957 | if (decode.version === network.pubKeyHash) return bscript.pubKeyHash.output.encode(decode.hash) | 16057 | try { |
15958 | if (decode.version === network.scriptHash) return bscript.scriptHash.output.encode(decode.hash) | 16058 | decode = fromBase58Check(address) |
16059 | } catch (e) {} | ||
16060 | |||
16061 | if (decode) { | ||
16062 | if (decode.version === network.pubKeyHash) return btemplates.pubKeyHash.output.encode(decode.hash) | ||
16063 | if (decode.version === network.scriptHash) return btemplates.scriptHash.output.encode(decode.hash) | ||
16064 | } else { | ||
16065 | try { | ||
16066 | decode = fromBech32(address) | ||
16067 | } catch (e) {} | ||
16068 | |||
16069 | if (decode) { | ||
16070 | if (decode.prefix !== network.bech32) throw new Error(address + ' has an invalid prefix') | ||
16071 | if (decode.version === 0) { | ||
16072 | if (decode.data.length === 20) return btemplates.witnessPubKeyHash.output.encode(decode.data) | ||
16073 | if (decode.data.length === 32) return btemplates.witnessScriptHash.output.encode(decode.data) | ||
16074 | } | ||
16075 | } | ||
16076 | } | ||
15959 | 16077 | ||
15960 | throw new Error(address + ' has no matching Script') | 16078 | throw new Error(address + ' has no matching Script') |
15961 | } | 16079 | } |
15962 | 16080 | ||
15963 | module.exports = { | 16081 | module.exports = { |
15964 | fromBase58Check: fromBase58Check, | 16082 | fromBase58Check: fromBase58Check, |
16083 | fromBech32: fromBech32, | ||
15965 | fromOutputScript: fromOutputScript, | 16084 | fromOutputScript: fromOutputScript, |
15966 | toBase58Check: toBase58Check, | 16085 | toBase58Check: toBase58Check, |
16086 | toBech32: toBech32, | ||
15967 | toOutputScript: toOutputScript | 16087 | toOutputScript: toOutputScript |
15968 | } | 16088 | } |
15969 | 16089 | ||
15970 | },{"./networks":51,"./script":52,"./types":78,"bs58check":80,"safe-buffer":98,"typeforce":109}],43:[function(require,module,exports){ | 16090 | },{"./networks":53,"./script":54,"./templates":56,"./types":80,"bech32":36,"bs58check":85,"safe-buffer":128,"typeforce":139}],45:[function(require,module,exports){ |
15971 | var Buffer = require('safe-buffer').Buffer | 16091 | var Buffer = require('safe-buffer').Buffer |
15972 | var bcrypto = require('./crypto') | 16092 | var bcrypto = require('./crypto') |
15973 | var fastMerkleRoot = require('merkle-lib/fastRoot') | 16093 | var fastMerkleRoot = require('merkle-lib/fastRoot') |
@@ -16146,7 +16266,7 @@ Block.prototype.checkProofOfWork = function () { | |||
16146 | 16266 | ||
16147 | module.exports = Block | 16267 | module.exports = Block |
16148 | 16268 | ||
16149 | },{"./crypto":45,"./transaction":76,"./types":78,"merkle-lib/fastRoot":94,"safe-buffer":98,"typeforce":109,"varuint-bitcoin":111}],44:[function(require,module,exports){ | 16269 | },{"./crypto":47,"./transaction":78,"./types":80,"merkle-lib/fastRoot":122,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],46:[function(require,module,exports){ |
16150 | var pushdata = require('pushdata-bitcoin') | 16270 | var pushdata = require('pushdata-bitcoin') |
16151 | var varuint = require('varuint-bitcoin') | 16271 | var varuint = require('varuint-bitcoin') |
16152 | 16272 | ||
@@ -16204,7 +16324,7 @@ module.exports = { | |||
16204 | writeVarInt: writeVarInt | 16324 | writeVarInt: writeVarInt |
16205 | } | 16325 | } |
16206 | 16326 | ||
16207 | },{"pushdata-bitcoin":95,"varuint-bitcoin":111}],45:[function(require,module,exports){ | 16327 | },{"pushdata-bitcoin":125,"varuint-bitcoin":141}],47:[function(require,module,exports){ |
16208 | var createHash = require('create-hash') | 16328 | var createHash = require('create-hash') |
16209 | 16329 | ||
16210 | function ripemd160 (buffer) { | 16330 | function ripemd160 (buffer) { |
@@ -16235,7 +16355,7 @@ module.exports = { | |||
16235 | sha256: sha256 | 16355 | sha256: sha256 |
16236 | } | 16356 | } |
16237 | 16357 | ||
16238 | },{"create-hash":82}],46:[function(require,module,exports){ | 16358 | },{"create-hash":87}],48:[function(require,module,exports){ |
16239 | var Buffer = require('safe-buffer').Buffer | 16359 | var Buffer = require('safe-buffer').Buffer |
16240 | var createHmac = require('create-hmac') | 16360 | var createHmac = require('create-hmac') |
16241 | var typeforce = require('typeforce') | 16361 | var typeforce = require('typeforce') |
@@ -16398,7 +16518,7 @@ module.exports = { | |||
16398 | __curve: secp256k1 | 16518 | __curve: secp256k1 |
16399 | } | 16519 | } |
16400 | 16520 | ||
16401 | },{"./ecsignature":48,"./types":78,"bigi":37,"create-hmac":85,"ecurve":89,"safe-buffer":98,"typeforce":109}],47:[function(require,module,exports){ | 16521 | },{"./ecsignature":50,"./types":80,"bigi":39,"create-hmac":90,"ecurve":94,"safe-buffer":128,"typeforce":139}],49:[function(require,module,exports){ |
16402 | var baddress = require('./address') | 16522 | var baddress = require('./address') |
16403 | var bcrypto = require('./crypto') | 16523 | var bcrypto = require('./crypto') |
16404 | var ecdsa = require('./ecdsa') | 16524 | var ecdsa = require('./ecdsa') |
@@ -16531,7 +16651,7 @@ ECPair.prototype.verify = function (hash, signature) { | |||
16531 | 16651 | ||
16532 | module.exports = ECPair | 16652 | module.exports = ECPair |
16533 | 16653 | ||
16534 | },{"./address":42,"./crypto":45,"./ecdsa":46,"./networks":51,"./types":78,"bigi":37,"ecurve":89,"randombytes":96,"typeforce":109,"wif":112}],48:[function(require,module,exports){ | 16654 | },{"./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){ |
16535 | (function (Buffer){ | 16655 | (function (Buffer){ |
16536 | var bip66 = require('bip66') | 16656 | var bip66 = require('bip66') |
16537 | var typeforce = require('typeforce') | 16657 | var typeforce = require('typeforce') |
@@ -16547,24 +16667,30 @@ function ECSignature (r, s) { | |||
16547 | } | 16667 | } |
16548 | 16668 | ||
16549 | ECSignature.parseCompact = function (buffer) { | 16669 | ECSignature.parseCompact = function (buffer) { |
16550 | if (buffer.length !== 65) throw new Error('Invalid signature length') | 16670 | typeforce(types.BufferN(65), buffer) |
16551 | 16671 | ||
16552 | var flagByte = buffer.readUInt8(0) - 27 | 16672 | var flagByte = buffer.readUInt8(0) - 27 |
16553 | if (flagByte !== (flagByte & 7)) throw new Error('Invalid signature parameter') | 16673 | if (flagByte !== (flagByte & 7)) throw new Error('Invalid signature parameter') |
16554 | 16674 | ||
16555 | var compressed = !!(flagByte & 4) | 16675 | var compressed = !!(flagByte & 4) |
16556 | var recoveryParam = flagByte & 3 | 16676 | var recoveryParam = flagByte & 3 |
16557 | 16677 | var signature = ECSignature.fromRSBuffer(buffer.slice(1)) | |
16558 | var r = BigInteger.fromBuffer(buffer.slice(1, 33)) | ||
16559 | var s = BigInteger.fromBuffer(buffer.slice(33)) | ||
16560 | 16678 | ||
16561 | return { | 16679 | return { |
16562 | compressed: compressed, | 16680 | compressed: compressed, |
16563 | i: recoveryParam, | 16681 | i: recoveryParam, |
16564 | signature: new ECSignature(r, s) | 16682 | signature: signature |
16565 | } | 16683 | } |
16566 | } | 16684 | } |
16567 | 16685 | ||
16686 | ECSignature.fromRSBuffer = function (buffer) { | ||
16687 | typeforce(types.BufferN(64), buffer) | ||
16688 | |||
16689 | var r = BigInteger.fromBuffer(buffer.slice(0, 32)) | ||
16690 | var s = BigInteger.fromBuffer(buffer.slice(32, 64)) | ||
16691 | return new ECSignature(r, s) | ||
16692 | } | ||
16693 | |||
16568 | ECSignature.fromDER = function (buffer) { | 16694 | ECSignature.fromDER = function (buffer) { |
16569 | var decode = bip66.decode(buffer) | 16695 | var decode = bip66.decode(buffer) |
16570 | var r = BigInteger.fromDERInteger(decode.r) | 16696 | var r = BigInteger.fromDERInteger(decode.r) |
@@ -16595,9 +16721,7 @@ ECSignature.prototype.toCompact = function (i, compressed) { | |||
16595 | 16721 | ||
16596 | var buffer = Buffer.alloc(65) | 16722 | var buffer = Buffer.alloc(65) |
16597 | buffer.writeUInt8(i, 0) | 16723 | buffer.writeUInt8(i, 0) |
16598 | this.r.toBuffer(32).copy(buffer, 1) | 16724 | this.toRSBuffer(buffer, 1) |
16599 | this.s.toBuffer(32).copy(buffer, 33) | ||
16600 | |||
16601 | return buffer | 16725 | return buffer |
16602 | } | 16726 | } |
16603 | 16727 | ||
@@ -16608,6 +16732,13 @@ ECSignature.prototype.toDER = function () { | |||
16608 | return bip66.encode(r, s) | 16732 | return bip66.encode(r, s) |
16609 | } | 16733 | } |
16610 | 16734 | ||
16735 | ECSignature.prototype.toRSBuffer = function (buffer, offset) { | ||
16736 | buffer = buffer || Buffer.alloc(64) | ||
16737 | this.r.toBuffer(32).copy(buffer, offset) | ||
16738 | this.s.toBuffer(32).copy(buffer, offset + 32) | ||
16739 | return buffer | ||
16740 | } | ||
16741 | |||
16611 | ECSignature.prototype.toScriptSignature = function (hashType) { | 16742 | ECSignature.prototype.toScriptSignature = function (hashType) { |
16612 | var hashTypeMod = hashType & ~0x80 | 16743 | var hashTypeMod = hashType & ~0x80 |
16613 | if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType) | 16744 | if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType) |
@@ -16621,7 +16752,7 @@ ECSignature.prototype.toScriptSignature = function (hashType) { | |||
16621 | module.exports = ECSignature | 16752 | module.exports = ECSignature |
16622 | 16753 | ||
16623 | }).call(this,require("buffer").Buffer) | 16754 | }).call(this,require("buffer").Buffer) |
16624 | },{"./types":78,"bigi":37,"bip66":39,"buffer":4,"typeforce":109}],49:[function(require,module,exports){ | 16755 | },{"./types":80,"bigi":39,"bip66":41,"buffer":5,"typeforce":139}],51:[function(require,module,exports){ |
16625 | var Buffer = require('safe-buffer').Buffer | 16756 | var Buffer = require('safe-buffer').Buffer |
16626 | var base58check = require('bs58check') | 16757 | var base58check = require('bs58check') |
16627 | var bcrypto = require('./crypto') | 16758 | var bcrypto = require('./crypto') |
@@ -16939,8 +17070,17 @@ HDNode.prototype.derivePath = function (path) { | |||
16939 | 17070 | ||
16940 | module.exports = HDNode | 17071 | module.exports = HDNode |
16941 | 17072 | ||
16942 | },{"./crypto":45,"./ecpair":47,"./networks":51,"./types":78,"bigi":37,"bs58check":80,"create-hmac":85,"ecurve":89,"safe-buffer":98,"typeforce":109}],50:[function(require,module,exports){ | 17073 | },{"./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){ |
17074 | var script = require('./script') | ||
17075 | |||
17076 | var templates = require('./templates') | ||
17077 | for (var key in templates) { | ||
17078 | script[key] = templates[key] | ||
17079 | } | ||
17080 | |||
16943 | module.exports = { | 17081 | module.exports = { |
17082 | bufferutils: require('./bufferutils'), // TODO: remove in 4.0.0 | ||
17083 | |||
16944 | Block: require('./block'), | 17084 | Block: require('./block'), |
16945 | ECPair: require('./ecpair'), | 17085 | ECPair: require('./ecpair'), |
16946 | ECSignature: require('./ecsignature'), | 17086 | ECSignature: require('./ecsignature'), |
@@ -16949,20 +17089,20 @@ module.exports = { | |||
16949 | TransactionBuilder: require('./transaction_builder'), | 17089 | TransactionBuilder: require('./transaction_builder'), |
16950 | 17090 | ||
16951 | address: require('./address'), | 17091 | address: require('./address'), |
16952 | bufferutils: require('./bufferutils'), // TODO: remove in 4.0.0 | ||
16953 | crypto: require('./crypto'), | 17092 | crypto: require('./crypto'), |
16954 | networks: require('./networks'), | 17093 | networks: require('./networks'), |
16955 | opcodes: require('bitcoin-ops'), | 17094 | opcodes: require('bitcoin-ops'), |
16956 | script: require('./script') | 17095 | script: script |
16957 | } | 17096 | } |
16958 | 17097 | ||
16959 | },{"./address":42,"./block":43,"./bufferutils":44,"./crypto":45,"./ecpair":47,"./ecsignature":48,"./hdnode":49,"./networks":51,"./script":52,"./transaction":76,"./transaction_builder":77,"bitcoin-ops":40}],51:[function(require,module,exports){ | 17098 | },{"./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){ |
16960 | // https://en.bitcoin.it/wiki/List_of_address_prefixes | 17099 | // https://en.bitcoin.it/wiki/List_of_address_prefixes |
16961 | // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731 | 17100 | // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731 |
16962 | 17101 | ||
16963 | module.exports = { | 17102 | module.exports = { |
16964 | bitcoin: { | 17103 | bitcoin: { |
16965 | messagePrefix: '\x18Bitcoin Signed Message:\n', | 17104 | messagePrefix: '\x18Bitcoin Signed Message:\n', |
17105 | bech32: 'bc', | ||
16966 | bip32: { | 17106 | bip32: { |
16967 | public: 0x0488b21e, | 17107 | public: 0x0488b21e, |
16968 | private: 0x0488ade4 | 17108 | private: 0x0488ade4 |
@@ -16973,6 +17113,7 @@ module.exports = { | |||
16973 | }, | 17113 | }, |
16974 | testnet: { | 17114 | testnet: { |
16975 | messagePrefix: '\x18Bitcoin Signed Message:\n', | 17115 | messagePrefix: '\x18Bitcoin Signed Message:\n', |
17116 | bech32: 'tb', | ||
16976 | bip32: { | 17117 | bip32: { |
16977 | public: 0x043587cf, | 17118 | public: 0x043587cf, |
16978 | private: 0x04358394 | 17119 | private: 0x04358394 |
@@ -16984,16 +17125,6 @@ module.exports = { | |||
16984 | litecoin: { | 17125 | litecoin: { |
16985 | messagePrefix: '\x19Litecoin Signed Message:\n', | 17126 | messagePrefix: '\x19Litecoin Signed Message:\n', |
16986 | bip32: { | 17127 | bip32: { |
16987 | public: 0x0488b21e, | ||
16988 | private: 0x0488ade4, | ||
16989 | }, | ||
16990 | pubKeyHash: 0x30, | ||
16991 | scriptHash: 0x32, | ||
16992 | wif: 0xb0 | ||
16993 | }, | ||
16994 | litecoinLtub: { | ||
16995 | messagePrefix: '\x19Litecoin Signed Message:\n', | ||
16996 | bip32: { | ||
16997 | public: 0x019da462, | 17128 | public: 0x019da462, |
16998 | private: 0x019d9cfe | 17129 | private: 0x019d9cfe |
16999 | }, | 17130 | }, |
@@ -17003,7 +17134,7 @@ module.exports = { | |||
17003 | } | 17134 | } |
17004 | } | 17135 | } |
17005 | 17136 | ||
17006 | },{}],52:[function(require,module,exports){ | 17137 | },{}],54:[function(require,module,exports){ |
17007 | var Buffer = require('safe-buffer').Buffer | 17138 | var Buffer = require('safe-buffer').Buffer |
17008 | var bip66 = require('bip66') | 17139 | var bip66 = require('bip66') |
17009 | var pushdata = require('pushdata-bitcoin') | 17140 | var pushdata = require('pushdata-bitcoin') |
@@ -17030,6 +17161,13 @@ function isPushOnly (value) { | |||
17030 | return types.Array(value) && value.every(isPushOnlyChunk) | 17161 | return types.Array(value) && value.every(isPushOnlyChunk) |
17031 | } | 17162 | } |
17032 | 17163 | ||
17164 | function asMinimalOP (buffer) { | ||
17165 | if (buffer.length === 0) return OPS.OP_0 | ||
17166 | if (buffer.length !== 1) return | ||
17167 | if (buffer[0] >= 1 && buffer[0] <= 16) return OP_INT_BASE + buffer[0] | ||
17168 | if (buffer[0] === 0x81) return OPS.OP_1NEGATE | ||
17169 | } | ||
17170 | |||
17033 | function compile (chunks) { | 17171 | function compile (chunks) { |
17034 | // TODO: remove me | 17172 | // TODO: remove me |
17035 | if (Buffer.isBuffer(chunks)) return chunks | 17173 | if (Buffer.isBuffer(chunks)) return chunks |
@@ -17040,7 +17178,7 @@ function compile (chunks) { | |||
17040 | // data chunk | 17178 | // data chunk |
17041 | if (Buffer.isBuffer(chunk)) { | 17179 | if (Buffer.isBuffer(chunk)) { |
17042 | // adhere to BIP62.3, minimal push policy | 17180 | // adhere to BIP62.3, minimal push policy |
17043 | if (chunk.length === 1 && (chunk[0] === 0x81 || (chunk[0] >= 1 && chunk[0] <= 16))) { | 17181 | if (chunk.length === 1 && asMinimalOP(chunk) !== undefined) { |
17044 | return accum + 1 | 17182 | return accum + 1 |
17045 | } | 17183 | } |
17046 | 17184 | ||
@@ -17058,21 +17196,14 @@ function compile (chunks) { | |||
17058 | // data chunk | 17196 | // data chunk |
17059 | if (Buffer.isBuffer(chunk)) { | 17197 | if (Buffer.isBuffer(chunk)) { |
17060 | // adhere to BIP62.3, minimal push policy | 17198 | // adhere to BIP62.3, minimal push policy |
17061 | if (chunk.length === 1 && chunk[0] >= 1 && chunk[0] <= 16) { | 17199 | var opcode = asMinimalOP(chunk) |
17062 | var opcode = OP_INT_BASE + chunk[0] | 17200 | if (opcode !== undefined) { |
17063 | buffer.writeUInt8(opcode, offset) | 17201 | buffer.writeUInt8(opcode, offset) |
17064 | offset += 1 | 17202 | offset += 1 |
17065 | return | 17203 | return |
17066 | } | 17204 | } |
17067 | 17205 | ||
17068 | if (chunk.length === 1 && chunk[0] === 0x81) { | ||
17069 | buffer.writeUInt8(OPS.OP_1NEGATE, offset) | ||
17070 | offset += 1 | ||
17071 | return | ||
17072 | } | ||
17073 | |||
17074 | offset += pushdata.encode(buffer, chunk.length, offset) | 17206 | offset += pushdata.encode(buffer, chunk.length, offset) |
17075 | |||
17076 | chunk.copy(buffer, offset) | 17207 | chunk.copy(buffer, offset) |
17077 | offset += chunk.length | 17208 | offset += chunk.length |
17078 | 17209 | ||
@@ -17113,7 +17244,13 @@ function decompile (buffer) { | |||
17113 | var data = buffer.slice(i, i + d.number) | 17244 | var data = buffer.slice(i, i + d.number) |
17114 | i += d.number | 17245 | i += d.number |
17115 | 17246 | ||
17116 | chunks.push(data) | 17247 | // decompile minimally |
17248 | var op = asMinimalOP(data) | ||
17249 | if (op !== undefined) { | ||
17250 | chunks.push(op) | ||
17251 | } else { | ||
17252 | chunks.push(data) | ||
17253 | } | ||
17117 | 17254 | ||
17118 | // opcode | 17255 | // opcode |
17119 | } else { | 17256 | } else { |
@@ -17133,7 +17270,11 @@ function toASM (chunks) { | |||
17133 | 17270 | ||
17134 | return chunks.map(function (chunk) { | 17271 | return chunks.map(function (chunk) { |
17135 | // data? | 17272 | // data? |
17136 | if (Buffer.isBuffer(chunk)) return chunk.toString('hex') | 17273 | if (Buffer.isBuffer(chunk)) { |
17274 | var op = asMinimalOP(chunk) | ||
17275 | if (op === undefined) return chunk.toString('hex') | ||
17276 | chunk = op | ||
17277 | } | ||
17137 | 17278 | ||
17138 | // opcode! | 17279 | // opcode! |
17139 | return REVERSE_OPS[chunk] | 17280 | return REVERSE_OPS[chunk] |
@@ -17209,12 +17350,7 @@ module.exports = { | |||
17209 | isDefinedHashType: isDefinedHashType | 17350 | isDefinedHashType: isDefinedHashType |
17210 | } | 17351 | } |
17211 | 17352 | ||
17212 | var templates = require('./templates') | 17353 | },{"./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){ |
17213 | for (var key in templates) { | ||
17214 | module.exports[key] = templates[key] | ||
17215 | } | ||
17216 | |||
17217 | },{"./script_number":53,"./templates":54,"./types":78,"bip66":39,"bitcoin-ops":40,"bitcoin-ops/map":41,"pushdata-bitcoin":95,"safe-buffer":98,"typeforce":109}],53:[function(require,module,exports){ | ||
17218 | var Buffer = require('safe-buffer').Buffer | 17354 | var Buffer = require('safe-buffer').Buffer |
17219 | 17355 | ||
17220 | function decode (buffer, maxLength, minimal) { | 17356 | function decode (buffer, maxLength, minimal) { |
@@ -17284,7 +17420,7 @@ module.exports = { | |||
17284 | encode: encode | 17420 | encode: encode |
17285 | } | 17421 | } |
17286 | 17422 | ||
17287 | },{"safe-buffer":98}],54:[function(require,module,exports){ | 17423 | },{"safe-buffer":128}],56:[function(require,module,exports){ |
17288 | var decompile = require('../script').decompile | 17424 | var decompile = require('../script').decompile |
17289 | var multisig = require('./multisig') | 17425 | var multisig = require('./multisig') |
17290 | var nullData = require('./nulldata') | 17426 | var nullData = require('./nulldata') |
@@ -17360,17 +17496,18 @@ module.exports = { | |||
17360 | types: types | 17496 | types: types |
17361 | } | 17497 | } |
17362 | 17498 | ||
17363 | },{"../script":52,"./multisig":55,"./nulldata":58,"./pubkey":59,"./pubkeyhash":62,"./scripthash":65,"./witnesscommitment":68,"./witnesspubkeyhash":70,"./witnessscripthash":73}],55:[function(require,module,exports){ | 17499 | },{"../script":54,"./multisig":57,"./nulldata":60,"./pubkey":61,"./pubkeyhash":64,"./scripthash":67,"./witnesscommitment":70,"./witnesspubkeyhash":72,"./witnessscripthash":75}],57:[function(require,module,exports){ |
17364 | module.exports = { | 17500 | module.exports = { |
17365 | input: require('./input'), | 17501 | input: require('./input'), |
17366 | output: require('./output') | 17502 | output: require('./output') |
17367 | } | 17503 | } |
17368 | 17504 | ||
17369 | },{"./input":56,"./output":57}],56:[function(require,module,exports){ | 17505 | },{"./input":58,"./output":59}],58:[function(require,module,exports){ |
17370 | // OP_0 [signatures ...] | 17506 | // OP_0 [signatures ...] |
17371 | 17507 | ||
17372 | var Buffer = require('safe-buffer').Buffer | 17508 | var Buffer = require('safe-buffer').Buffer |
17373 | var bscript = require('../../script') | 17509 | var bscript = require('../../script') |
17510 | var p2mso = require('./output') | ||
17374 | var typeforce = require('typeforce') | 17511 | var typeforce = require('typeforce') |
17375 | var OPS = require('bitcoin-ops') | 17512 | var OPS = require('bitcoin-ops') |
17376 | 17513 | ||
@@ -17397,7 +17534,7 @@ function encodeStack (signatures, scriptPubKey) { | |||
17397 | typeforce([partialSignature], signatures) | 17534 | typeforce([partialSignature], signatures) |
17398 | 17535 | ||
17399 | if (scriptPubKey) { | 17536 | if (scriptPubKey) { |
17400 | var scriptData = bscript.multisig.output.decode(scriptPubKey) | 17537 | var scriptData = p2mso.decode(scriptPubKey) |
17401 | 17538 | ||
17402 | if (signatures.length < scriptData.m) { | 17539 | if (signatures.length < scriptData.m) { |
17403 | throw new TypeError('Not enough signatures provided') | 17540 | throw new TypeError('Not enough signatures provided') |
@@ -17408,7 +17545,12 @@ function encodeStack (signatures, scriptPubKey) { | |||
17408 | } | 17545 | } |
17409 | } | 17546 | } |
17410 | 17547 | ||
17411 | return [].concat(EMPTY_BUFFER, signatures) | 17548 | return [].concat(EMPTY_BUFFER, signatures.map(function (sig) { |
17549 | if (sig === OPS.OP_0) { | ||
17550 | return EMPTY_BUFFER | ||
17551 | } | ||
17552 | return sig | ||
17553 | })) | ||
17412 | } | 17554 | } |
17413 | 17555 | ||
17414 | function encode (signatures, scriptPubKey) { | 17556 | function encode (signatures, scriptPubKey) { |
@@ -17433,7 +17575,7 @@ module.exports = { | |||
17433 | encodeStack: encodeStack | 17575 | encodeStack: encodeStack |
17434 | } | 17576 | } |
17435 | 17577 | ||
17436 | },{"../../script":52,"bitcoin-ops":40,"safe-buffer":98,"typeforce":109}],57:[function(require,module,exports){ | 17578 | },{"../../script":54,"./output":59,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],59:[function(require,module,exports){ |
17437 | // m [pubKeys ...] n OP_CHECKMULTISIG | 17579 | // m [pubKeys ...] n OP_CHECKMULTISIG |
17438 | 17580 | ||
17439 | var bscript = require('../../script') | 17581 | var bscript = require('../../script') |
@@ -17499,7 +17641,7 @@ module.exports = { | |||
17499 | encode: encode | 17641 | encode: encode |
17500 | } | 17642 | } |
17501 | 17643 | ||
17502 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"typeforce":109}],58:[function(require,module,exports){ | 17644 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],60:[function(require,module,exports){ |
17503 | // OP_RETURN {data} | 17645 | // OP_RETURN {data} |
17504 | 17646 | ||
17505 | var bscript = require('../script') | 17647 | var bscript = require('../script') |
@@ -17535,13 +17677,12 @@ module.exports = { | |||
17535 | } | 17677 | } |
17536 | } | 17678 | } |
17537 | 17679 | ||
17538 | },{"../script":52,"../types":78,"bitcoin-ops":40,"typeforce":109}],59:[function(require,module,exports){ | 17680 | },{"../script":54,"../types":80,"bitcoin-ops":42,"typeforce":139}],61:[function(require,module,exports){ |
17539 | arguments[4][55][0].apply(exports,arguments) | 17681 | arguments[4][57][0].apply(exports,arguments) |
17540 | },{"./input":60,"./output":61,"dup":55}],60:[function(require,module,exports){ | 17682 | },{"./input":62,"./output":63,"dup":57}],62:[function(require,module,exports){ |
17541 | // {signature} | 17683 | // {signature} |
17542 | 17684 | ||
17543 | var bscript = require('../../script') | 17685 | var bscript = require('../../script') |
17544 | var types = require('../../types') | ||
17545 | var typeforce = require('typeforce') | 17686 | var typeforce = require('typeforce') |
17546 | 17687 | ||
17547 | function check (script) { | 17688 | function check (script) { |
@@ -17553,7 +17694,7 @@ function check (script) { | |||
17553 | check.toJSON = function () { return 'pubKey input' } | 17694 | check.toJSON = function () { return 'pubKey input' } |
17554 | 17695 | ||
17555 | function encodeStack (signature) { | 17696 | function encodeStack (signature) { |
17556 | typeforce(types.Buffer, signature) | 17697 | typeforce(bscript.isCanonicalSignature, signature) |
17557 | return [signature] | 17698 | return [signature] |
17558 | } | 17699 | } |
17559 | 17700 | ||
@@ -17579,7 +17720,7 @@ module.exports = { | |||
17579 | encodeStack: encodeStack | 17720 | encodeStack: encodeStack |
17580 | } | 17721 | } |
17581 | 17722 | ||
17582 | },{"../../script":52,"../../types":78,"typeforce":109}],61:[function(require,module,exports){ | 17723 | },{"../../script":54,"typeforce":139}],63:[function(require,module,exports){ |
17583 | // {pubKey} OP_CHECKSIG | 17724 | // {pubKey} OP_CHECKSIG |
17584 | 17725 | ||
17585 | var bscript = require('../../script') | 17726 | var bscript = require('../../script') |
@@ -17614,13 +17755,12 @@ module.exports = { | |||
17614 | encode: encode | 17755 | encode: encode |
17615 | } | 17756 | } |
17616 | 17757 | ||
17617 | },{"../../script":52,"bitcoin-ops":40,"typeforce":109}],62:[function(require,module,exports){ | 17758 | },{"../../script":54,"bitcoin-ops":42,"typeforce":139}],64:[function(require,module,exports){ |
17618 | arguments[4][55][0].apply(exports,arguments) | 17759 | arguments[4][57][0].apply(exports,arguments) |
17619 | },{"./input":63,"./output":64,"dup":55}],63:[function(require,module,exports){ | 17760 | },{"./input":65,"./output":66,"dup":57}],65:[function(require,module,exports){ |
17620 | // {signature} {pubKey} | 17761 | // {signature} {pubKey} |
17621 | 17762 | ||
17622 | var bscript = require('../../script') | 17763 | var bscript = require('../../script') |
17623 | var types = require('../../types') | ||
17624 | var typeforce = require('typeforce') | 17764 | var typeforce = require('typeforce') |
17625 | 17765 | ||
17626 | function check (script) { | 17766 | function check (script) { |
@@ -17634,9 +17774,11 @@ check.toJSON = function () { return 'pubKeyHash input' } | |||
17634 | 17774 | ||
17635 | function encodeStack (signature, pubKey) { | 17775 | function encodeStack (signature, pubKey) { |
17636 | typeforce({ | 17776 | typeforce({ |
17637 | signature: types.Buffer, pubKey: types.Buffer | 17777 | signature: bscript.isCanonicalSignature, |
17778 | pubKey: bscript.isCanonicalPubKey | ||
17638 | }, { | 17779 | }, { |
17639 | signature: signature, pubKey: pubKey | 17780 | signature: signature, |
17781 | pubKey: pubKey | ||
17640 | }) | 17782 | }) |
17641 | 17783 | ||
17642 | return [signature, pubKey] | 17784 | return [signature, pubKey] |
@@ -17668,7 +17810,7 @@ module.exports = { | |||
17668 | encodeStack: encodeStack | 17810 | encodeStack: encodeStack |
17669 | } | 17811 | } |
17670 | 17812 | ||
17671 | },{"../../script":52,"../../types":78,"typeforce":109}],64:[function(require,module,exports){ | 17813 | },{"../../script":54,"typeforce":139}],66:[function(require,module,exports){ |
17672 | // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG | 17814 | // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG |
17673 | 17815 | ||
17674 | var bscript = require('../../script') | 17816 | var bscript = require('../../script') |
@@ -17712,15 +17854,21 @@ module.exports = { | |||
17712 | encode: encode | 17854 | encode: encode |
17713 | } | 17855 | } |
17714 | 17856 | ||
17715 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"typeforce":109}],65:[function(require,module,exports){ | 17857 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],67:[function(require,module,exports){ |
17716 | arguments[4][55][0].apply(exports,arguments) | 17858 | arguments[4][57][0].apply(exports,arguments) |
17717 | },{"./input":66,"./output":67,"dup":55}],66:[function(require,module,exports){ | 17859 | },{"./input":68,"./output":69,"dup":57}],68:[function(require,module,exports){ |
17718 | // <scriptSig> {serialized scriptPubKey script} | 17860 | // <scriptSig> {serialized scriptPubKey script} |
17719 | 17861 | ||
17720 | var Buffer = require('safe-buffer').Buffer | 17862 | var Buffer = require('safe-buffer').Buffer |
17721 | var bscript = require('../../script') | 17863 | var bscript = require('../../script') |
17722 | var typeforce = require('typeforce') | 17864 | var typeforce = require('typeforce') |
17723 | 17865 | ||
17866 | var p2ms = require('../multisig/') | ||
17867 | var p2pk = require('../pubkey/') | ||
17868 | var p2pkh = require('../pubkeyhash/') | ||
17869 | var p2wpkho = require('../witnesspubkeyhash/output') | ||
17870 | var p2wsho = require('../witnessscripthash/output') | ||
17871 | |||
17724 | function check (script, allowIncomplete) { | 17872 | function check (script, allowIncomplete) { |
17725 | var chunks = bscript.decompile(script) | 17873 | var chunks = bscript.decompile(script) |
17726 | if (chunks.length < 1) return false | 17874 | if (chunks.length < 1) return false |
@@ -17737,12 +17885,23 @@ function check (script, allowIncomplete) { | |||
17737 | // is redeemScriptSig push only? | 17885 | // is redeemScriptSig push only? |
17738 | if (!bscript.isPushOnly(scriptSigChunks)) return false | 17886 | if (!bscript.isPushOnly(scriptSigChunks)) return false |
17739 | 17887 | ||
17740 | var inputType = bscript.classifyInput(scriptSigChunks, allowIncomplete) | 17888 | // is witness? |
17741 | var outputType = bscript.classifyOutput(redeemScriptChunks) | ||
17742 | if (chunks.length === 1) { | 17889 | if (chunks.length === 1) { |
17743 | return outputType === bscript.types.P2WSH || outputType === bscript.types.P2WPKH | 17890 | return p2wsho.check(redeemScriptChunks) || |
17891 | p2wpkho.check(redeemScriptChunks) | ||
17744 | } | 17892 | } |
17745 | return inputType === outputType | 17893 | |
17894 | // match types | ||
17895 | if (p2pkh.input.check(scriptSigChunks) && | ||
17896 | p2pkh.output.check(redeemScriptChunks)) return true | ||
17897 | |||
17898 | if (p2ms.input.check(scriptSigChunks, allowIncomplete) && | ||
17899 | p2ms.output.check(redeemScriptChunks)) return true | ||
17900 | |||
17901 | if (p2pk.input.check(scriptSigChunks) && | ||
17902 | p2pk.output.check(redeemScriptChunks)) return true | ||
17903 | |||
17904 | return false | ||
17746 | } | 17905 | } |
17747 | check.toJSON = function () { return 'scriptHash input' } | 17906 | check.toJSON = function () { return 'scriptHash input' } |
17748 | 17907 | ||
@@ -17783,7 +17942,7 @@ module.exports = { | |||
17783 | encodeStack: encodeStack | 17942 | encodeStack: encodeStack |
17784 | } | 17943 | } |
17785 | 17944 | ||
17786 | },{"../../script":52,"safe-buffer":98,"typeforce":109}],67:[function(require,module,exports){ | 17945 | },{"../../script":54,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"../witnesspubkeyhash/output":74,"../witnessscripthash/output":77,"safe-buffer":128,"typeforce":139}],69:[function(require,module,exports){ |
17787 | // OP_HASH160 {scriptHash} OP_EQUAL | 17946 | // OP_HASH160 {scriptHash} OP_EQUAL |
17788 | 17947 | ||
17789 | var bscript = require('../../script') | 17948 | var bscript = require('../../script') |
@@ -17819,12 +17978,12 @@ module.exports = { | |||
17819 | encode: encode | 17978 | encode: encode |
17820 | } | 17979 | } |
17821 | 17980 | ||
17822 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"typeforce":109}],68:[function(require,module,exports){ | 17981 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],70:[function(require,module,exports){ |
17823 | module.exports = { | 17982 | module.exports = { |
17824 | output: require('./output') | 17983 | output: require('./output') |
17825 | } | 17984 | } |
17826 | 17985 | ||
17827 | },{"./output":69}],69:[function(require,module,exports){ | 17986 | },{"./output":71}],71:[function(require,module,exports){ |
17828 | // OP_RETURN {aa21a9ed} {commitment} | 17987 | // OP_RETURN {aa21a9ed} {commitment} |
17829 | 17988 | ||
17830 | var Buffer = require('safe-buffer').Buffer | 17989 | var Buffer = require('safe-buffer').Buffer |
@@ -17868,20 +18027,55 @@ module.exports = { | |||
17868 | encode: encode | 18027 | encode: encode |
17869 | } | 18028 | } |
17870 | 18029 | ||
17871 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"safe-buffer":98,"typeforce":109}],70:[function(require,module,exports){ | 18030 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],72:[function(require,module,exports){ |
17872 | arguments[4][55][0].apply(exports,arguments) | 18031 | arguments[4][57][0].apply(exports,arguments) |
17873 | },{"./input":71,"./output":72,"dup":55}],71:[function(require,module,exports){ | 18032 | },{"./input":73,"./output":74,"dup":57}],73:[function(require,module,exports){ |
17874 | // {signature} {pubKey} | 18033 | // {signature} {pubKey} |
17875 | 18034 | ||
17876 | var pkh = require('../pubkeyhash/input') | 18035 | var bscript = require('../../script') |
18036 | var typeforce = require('typeforce') | ||
18037 | |||
18038 | function isCompressedCanonicalPubKey (pubKey) { | ||
18039 | return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33 | ||
18040 | } | ||
18041 | |||
18042 | function check (script) { | ||
18043 | var chunks = bscript.decompile(script) | ||
18044 | |||
18045 | return chunks.length === 2 && | ||
18046 | bscript.isCanonicalSignature(chunks[0]) && | ||
18047 | isCompressedCanonicalPubKey(chunks[1]) | ||
18048 | } | ||
18049 | check.toJSON = function () { return 'witnessPubKeyHash input' } | ||
18050 | |||
18051 | function encodeStack (signature, pubKey) { | ||
18052 | typeforce({ | ||
18053 | signature: bscript.isCanonicalSignature, | ||
18054 | pubKey: isCompressedCanonicalPubKey | ||
18055 | }, { | ||
18056 | signature: signature, | ||
18057 | pubKey: pubKey | ||
18058 | }) | ||
18059 | |||
18060 | return [signature, pubKey] | ||
18061 | } | ||
18062 | |||
18063 | function decodeStack (stack) { | ||
18064 | typeforce(check, stack) | ||
18065 | |||
18066 | return { | ||
18067 | signature: stack[0], | ||
18068 | pubKey: stack[1] | ||
18069 | } | ||
18070 | } | ||
17877 | 18071 | ||
17878 | module.exports = { | 18072 | module.exports = { |
17879 | check: pkh.check, | 18073 | check: check, |
17880 | decodeStack: pkh.decodeStack, | 18074 | decodeStack: decodeStack, |
17881 | encodeStack: pkh.encodeStack | 18075 | encodeStack: encodeStack |
17882 | } | 18076 | } |
17883 | 18077 | ||
17884 | },{"../pubkeyhash/input":63}],72:[function(require,module,exports){ | 18078 | },{"../../script":54,"typeforce":139}],74:[function(require,module,exports){ |
17885 | // OP_0 {pubKeyHash} | 18079 | // OP_0 {pubKeyHash} |
17886 | 18080 | ||
17887 | var bscript = require('../../script') | 18081 | var bscript = require('../../script') |
@@ -17916,20 +18110,76 @@ module.exports = { | |||
17916 | encode: encode | 18110 | encode: encode |
17917 | } | 18111 | } |
17918 | 18112 | ||
17919 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"typeforce":109}],73:[function(require,module,exports){ | 18113 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],75:[function(require,module,exports){ |
17920 | arguments[4][55][0].apply(exports,arguments) | 18114 | arguments[4][57][0].apply(exports,arguments) |
17921 | },{"./input":74,"./output":75,"dup":55}],74:[function(require,module,exports){ | 18115 | },{"./input":76,"./output":77,"dup":57}],76:[function(require,module,exports){ |
17922 | // {signature} {pubKey} | 18116 | (function (Buffer){ |
18117 | // <scriptSig> {serialized scriptPubKey script} | ||
18118 | |||
18119 | var bscript = require('../../script') | ||
18120 | var types = require('../../types') | ||
18121 | var typeforce = require('typeforce') | ||
17923 | 18122 | ||
17924 | var p2sh = require('../scripthash/input') | 18123 | var p2ms = require('../multisig/') |
18124 | var p2pk = require('../pubkey/') | ||
18125 | var p2pkh = require('../pubkeyhash/') | ||
18126 | |||
18127 | function check (chunks, allowIncomplete) { | ||
18128 | typeforce(types.Array, chunks) | ||
18129 | if (chunks.length < 1) return false | ||
18130 | |||
18131 | var witnessScript = chunks[chunks.length - 1] | ||
18132 | if (!Buffer.isBuffer(witnessScript)) return false | ||
18133 | |||
18134 | var witnessScriptChunks = bscript.decompile(witnessScript) | ||
18135 | |||
18136 | // is witnessScript a valid script? | ||
18137 | if (witnessScriptChunks.length === 0) return false | ||
18138 | |||
18139 | var witnessRawScriptSig = bscript.compile(chunks.slice(0, -1)) | ||
18140 | |||
18141 | // match types | ||
18142 | if (p2pkh.input.check(witnessRawScriptSig) && | ||
18143 | p2pkh.output.check(witnessScriptChunks)) return true | ||
18144 | |||
18145 | if (p2ms.input.check(witnessRawScriptSig, allowIncomplete) && | ||
18146 | p2ms.output.check(witnessScriptChunks)) return true | ||
18147 | |||
18148 | if (p2pk.input.check(witnessRawScriptSig) && | ||
18149 | p2pk.output.check(witnessScriptChunks)) return true | ||
18150 | |||
18151 | return false | ||
18152 | } | ||
18153 | check.toJSON = function () { return 'witnessScriptHash input' } | ||
18154 | |||
18155 | function encodeStack (witnessData, witnessScript) { | ||
18156 | typeforce({ | ||
18157 | witnessData: [types.Buffer], | ||
18158 | witnessScript: types.Buffer | ||
18159 | }, { | ||
18160 | witnessData: witnessData, | ||
18161 | witnessScript: witnessScript | ||
18162 | }) | ||
18163 | |||
18164 | return [].concat(witnessData, witnessScript) | ||
18165 | } | ||
18166 | |||
18167 | function decodeStack (chunks) { | ||
18168 | typeforce(check, chunks) | ||
18169 | return { | ||
18170 | witnessData: chunks.slice(0, -1), | ||
18171 | witnessScript: chunks[chunks.length - 1] | ||
18172 | } | ||
18173 | } | ||
17925 | 18174 | ||
17926 | module.exports = { | 18175 | module.exports = { |
17927 | check: p2sh.check, | 18176 | check: check, |
17928 | decodeStack: p2sh.decodeStack, | 18177 | decodeStack: decodeStack, |
17929 | encodeStack: p2sh.encodeStack | 18178 | encodeStack: encodeStack |
17930 | } | 18179 | } |
17931 | 18180 | ||
17932 | },{"../scripthash/input":66}],75:[function(require,module,exports){ | 18181 | }).call(this,{"isBuffer":require("../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) |
18182 | },{"../../../../../../../../.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){ | ||
17933 | // OP_0 {scriptHash} | 18183 | // OP_0 {scriptHash} |
17934 | 18184 | ||
17935 | var bscript = require('../../script') | 18185 | var bscript = require('../../script') |
@@ -17964,7 +18214,7 @@ module.exports = { | |||
17964 | encode: encode | 18214 | encode: encode |
17965 | } | 18215 | } |
17966 | 18216 | ||
17967 | },{"../../script":52,"../../types":78,"bitcoin-ops":40,"typeforce":109}],76:[function(require,module,exports){ | 18217 | },{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],78:[function(require,module,exports){ |
17968 | var Buffer = require('safe-buffer').Buffer | 18218 | var Buffer = require('safe-buffer').Buffer |
17969 | var bcrypto = require('./crypto') | 18219 | var bcrypto = require('./crypto') |
17970 | var bscript = require('./script') | 18220 | var bscript = require('./script') |
@@ -18458,23 +18708,32 @@ Transaction.prototype.setWitness = function (index, witness) { | |||
18458 | 18708 | ||
18459 | module.exports = Transaction | 18709 | module.exports = Transaction |
18460 | 18710 | ||
18461 | },{"./bufferutils":44,"./crypto":45,"./script":52,"./types":78,"bitcoin-ops":40,"safe-buffer":98,"typeforce":109,"varuint-bitcoin":111}],77:[function(require,module,exports){ | 18711 | },{"./bufferutils":46,"./crypto":47,"./script":54,"./types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],79:[function(require,module,exports){ |
18462 | var Buffer = require('safe-buffer').Buffer | 18712 | var Buffer = require('safe-buffer').Buffer |
18463 | var baddress = require('./address') | 18713 | var baddress = require('./address') |
18464 | var bcrypto = require('./crypto') | 18714 | var bcrypto = require('./crypto') |
18465 | var bscript = require('./script') | 18715 | var bscript = require('./script') |
18716 | var btemplates = require('./templates') | ||
18466 | var networks = require('./networks') | 18717 | var networks = require('./networks') |
18467 | var ops = require('bitcoin-ops') | 18718 | var ops = require('bitcoin-ops') |
18468 | var typeforce = require('typeforce') | 18719 | var typeforce = require('typeforce') |
18469 | var types = require('./types') | 18720 | var types = require('./types') |
18470 | var scriptTypes = bscript.types | 18721 | var scriptTypes = btemplates.types |
18471 | var SIGNABLE = [bscript.types.P2PKH, bscript.types.P2PK, bscript.types.MULTISIG] | 18722 | var SIGNABLE = [btemplates.types.P2PKH, btemplates.types.P2PK, btemplates.types.MULTISIG] |
18472 | var P2SH = SIGNABLE.concat([bscript.types.P2WPKH, bscript.types.P2WSH]) | 18723 | var P2SH = SIGNABLE.concat([btemplates.types.P2WPKH, btemplates.types.P2WSH]) |
18473 | 18724 | ||
18474 | var ECPair = require('./ecpair') | 18725 | var ECPair = require('./ecpair') |
18475 | var ECSignature = require('./ecsignature') | 18726 | var ECSignature = require('./ecsignature') |
18476 | var Transaction = require('./transaction') | 18727 | var Transaction = require('./transaction') |
18477 | 18728 | ||
18729 | function supportedType (type) { | ||
18730 | return SIGNABLE.indexOf(type) !== -1 | ||
18731 | } | ||
18732 | |||
18733 | function supportedP2SHType (type) { | ||
18734 | return P2SH.indexOf(type) !== -1 | ||
18735 | } | ||
18736 | |||
18478 | function extractChunks (type, chunks, script) { | 18737 | function extractChunks (type, chunks, script) { |
18479 | var pubKeys = [] | 18738 | var pubKeys = [] |
18480 | var signatures = [] | 18739 | var signatures = [] |
@@ -18486,13 +18745,13 @@ function extractChunks (type, chunks, script) { | |||
18486 | break | 18745 | break |
18487 | 18746 | ||
18488 | case scriptTypes.P2PK: | 18747 | case scriptTypes.P2PK: |
18489 | pubKeys[0] = script ? bscript.pubKey.output.decode(script) : undefined | 18748 | pubKeys[0] = script ? btemplates.pubKey.output.decode(script) : undefined |
18490 | signatures = chunks.slice(0, 1) | 18749 | signatures = chunks.slice(0, 1) |
18491 | break | 18750 | break |
18492 | 18751 | ||
18493 | case scriptTypes.MULTISIG: | 18752 | case scriptTypes.MULTISIG: |
18494 | if (script) { | 18753 | if (script) { |
18495 | var multisig = bscript.multisig.output.decode(script) | 18754 | var multisig = btemplates.multisig.output.decode(script) |
18496 | pubKeys = multisig.pubKeys | 18755 | pubKeys = multisig.pubKeys |
18497 | } | 18756 | } |
18498 | 18757 | ||
@@ -18525,25 +18784,26 @@ function expandInput (scriptSig, witnessStack) { | |||
18525 | var chunks | 18784 | var chunks |
18526 | 18785 | ||
18527 | var scriptSigChunks = bscript.decompile(scriptSig) | 18786 | var scriptSigChunks = bscript.decompile(scriptSig) |
18528 | var sigType = bscript.classifyInput(scriptSigChunks, true) | 18787 | var sigType = btemplates.classifyInput(scriptSigChunks, true) |
18529 | if (sigType === scriptTypes.P2SH) { | 18788 | if (sigType === scriptTypes.P2SH) { |
18530 | p2sh = true | 18789 | p2sh = true |
18531 | redeemScript = scriptSigChunks[scriptSigChunks.length - 1] | 18790 | redeemScript = scriptSigChunks[scriptSigChunks.length - 1] |
18532 | redeemScriptType = bscript.classifyOutput(redeemScript) | 18791 | redeemScriptType = btemplates.classifyOutput(redeemScript) |
18533 | prevOutScript = bscript.scriptHash.output.encode(bcrypto.hash160(redeemScript)) | 18792 | prevOutScript = btemplates.scriptHash.output.encode(bcrypto.hash160(redeemScript)) |
18534 | prevOutType = scriptTypes.P2SH | 18793 | prevOutType = scriptTypes.P2SH |
18535 | script = redeemScript | 18794 | script = redeemScript |
18536 | } | 18795 | } |
18537 | 18796 | ||
18538 | var classifyWitness = bscript.classifyWitness(witnessStack) | 18797 | var classifyWitness = btemplates.classifyWitness(witnessStack, true) |
18539 | if (classifyWitness === scriptTypes.P2WSH) { | 18798 | if (classifyWitness === scriptTypes.P2WSH) { |
18540 | witnessScript = witnessStack[witnessStack.length - 1] | 18799 | witnessScript = witnessStack[witnessStack.length - 1] |
18541 | witnessScriptType = bscript.classifyOutput(witnessScript) | 18800 | witnessScriptType = btemplates.classifyOutput(witnessScript) |
18542 | p2wsh = true | 18801 | p2wsh = true |
18802 | witness = true | ||
18543 | if (scriptSig.length === 0) { | 18803 | if (scriptSig.length === 0) { |
18544 | prevOutScript = bscript.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript)) | 18804 | prevOutScript = btemplates.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript)) |
18545 | prevOutType = scriptTypes.P2WSH | 18805 | prevOutType = scriptTypes.P2WSH |
18546 | if (typeof redeemScript !== 'undefined') { | 18806 | if (redeemScript !== undefined) { |
18547 | throw new Error('Redeem script given when unnecessary') | 18807 | throw new Error('Redeem script given when unnecessary') |
18548 | } | 18808 | } |
18549 | // bare witness | 18809 | // bare witness |
@@ -18551,23 +18811,25 @@ function expandInput (scriptSig, witnessStack) { | |||
18551 | if (!redeemScript) { | 18811 | if (!redeemScript) { |
18552 | throw new Error('No redeemScript provided for P2WSH, but scriptSig non-empty') | 18812 | throw new Error('No redeemScript provided for P2WSH, but scriptSig non-empty') |
18553 | } | 18813 | } |
18554 | witnessProgram = bscript.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript)) | 18814 | witnessProgram = btemplates.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript)) |
18555 | if (!redeemScript.equals(witnessProgram)) { | 18815 | if (!redeemScript.equals(witnessProgram)) { |
18556 | throw new Error('Redeem script didn\'t match witnessScript') | 18816 | throw new Error('Redeem script didn\'t match witnessScript') |
18557 | } | 18817 | } |
18558 | } | 18818 | } |
18559 | 18819 | ||
18560 | if (SIGNABLE.indexOf(bscript.classifyOutput(witnessScript)) === -1) { | 18820 | if (!supportedType(btemplates.classifyOutput(witnessScript))) { |
18561 | throw new Error('unsupported witness script') | 18821 | throw new Error('unsupported witness script') |
18562 | } | 18822 | } |
18823 | |||
18563 | script = witnessScript | 18824 | script = witnessScript |
18564 | scriptType = witnessScriptType | 18825 | scriptType = witnessScriptType |
18565 | chunks = witnessStack.slice(0, -1) | 18826 | chunks = witnessStack.slice(0, -1) |
18566 | } else if (classifyWitness === scriptTypes.P2WPKH) { | 18827 | } else if (classifyWitness === scriptTypes.P2WPKH) { |
18828 | witness = true | ||
18567 | var key = witnessStack[witnessStack.length - 1] | 18829 | var key = witnessStack[witnessStack.length - 1] |
18568 | var keyHash = bcrypto.hash160(key) | 18830 | var keyHash = bcrypto.hash160(key) |
18569 | if (scriptSig.length === 0) { | 18831 | if (scriptSig.length === 0) { |
18570 | prevOutScript = bscript.witnessPubKeyHash.output.encode(keyHash) | 18832 | prevOutScript = btemplates.witnessPubKeyHash.output.encode(keyHash) |
18571 | prevOutType = scriptTypes.P2WPKH | 18833 | prevOutType = scriptTypes.P2WPKH |
18572 | if (typeof redeemScript !== 'undefined') { | 18834 | if (typeof redeemScript !== 'undefined') { |
18573 | throw new Error('Redeem script given when unnecessary') | 18835 | throw new Error('Redeem script given when unnecessary') |
@@ -18576,7 +18838,7 @@ function expandInput (scriptSig, witnessStack) { | |||
18576 | if (!redeemScript) { | 18838 | if (!redeemScript) { |
18577 | throw new Error('No redeemScript provided for P2WPKH, but scriptSig wasn\'t empty') | 18839 | throw new Error('No redeemScript provided for P2WPKH, but scriptSig wasn\'t empty') |
18578 | } | 18840 | } |
18579 | witnessProgram = bscript.witnessPubKeyHash.output.encode(keyHash) | 18841 | witnessProgram = btemplates.witnessPubKeyHash.output.encode(keyHash) |
18580 | if (!redeemScript.equals(witnessProgram)) { | 18842 | if (!redeemScript.equals(witnessProgram)) { |
18581 | throw new Error('Redeem script did not have the right witness program') | 18843 | throw new Error('Redeem script did not have the right witness program') |
18582 | } | 18844 | } |
@@ -18585,7 +18847,7 @@ function expandInput (scriptSig, witnessStack) { | |||
18585 | scriptType = scriptTypes.P2PKH | 18847 | scriptType = scriptTypes.P2PKH |
18586 | chunks = witnessStack | 18848 | chunks = witnessStack |
18587 | } else if (redeemScript) { | 18849 | } else if (redeemScript) { |
18588 | if (P2SH.indexOf(redeemScriptType) === -1) { | 18850 | if (!supportedP2SHType(redeemScriptType)) { |
18589 | throw new Error('Bad redeemscript!') | 18851 | throw new Error('Bad redeemscript!') |
18590 | } | 18852 | } |
18591 | 18853 | ||
@@ -18593,7 +18855,7 @@ function expandInput (scriptSig, witnessStack) { | |||
18593 | scriptType = redeemScriptType | 18855 | scriptType = redeemScriptType |
18594 | chunks = scriptSigChunks.slice(0, -1) | 18856 | chunks = scriptSigChunks.slice(0, -1) |
18595 | } else { | 18857 | } else { |
18596 | prevOutType = scriptType = bscript.classifyInput(scriptSig) | 18858 | prevOutType = scriptType = btemplates.classifyInput(scriptSig) |
18597 | chunks = scriptSigChunks | 18859 | chunks = scriptSigChunks |
18598 | } | 18860 | } |
18599 | 18861 | ||
@@ -18661,7 +18923,7 @@ function expandOutput (script, scriptType, ourPubKey) { | |||
18661 | 18923 | ||
18662 | var scriptChunks = bscript.decompile(script) | 18924 | var scriptChunks = bscript.decompile(script) |
18663 | if (!scriptType) { | 18925 | if (!scriptType) { |
18664 | scriptType = bscript.classifyOutput(script) | 18926 | scriptType = btemplates.classifyOutput(script) |
18665 | } | 18927 | } |
18666 | 18928 | ||
18667 | var pubKeys = [] | 18929 | var pubKeys = [] |
@@ -18703,7 +18965,7 @@ function expandOutput (script, scriptType, ourPubKey) { | |||
18703 | } | 18965 | } |
18704 | } | 18966 | } |
18705 | 18967 | ||
18706 | function checkP2shInput (input, redeemScriptHash) { | 18968 | function checkP2SHInput (input, redeemScriptHash) { |
18707 | if (input.prevOutType) { | 18969 | if (input.prevOutType) { |
18708 | if (input.prevOutType !== scriptTypes.P2SH) throw new Error('PrevOutScript must be P2SH') | 18970 | if (input.prevOutType !== scriptTypes.P2SH) throw new Error('PrevOutScript must be P2SH') |
18709 | 18971 | ||
@@ -18741,31 +19003,32 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip | |||
18741 | if (redeemScript && witnessScript) { | 19003 | if (redeemScript && witnessScript) { |
18742 | redeemScriptHash = bcrypto.hash160(redeemScript) | 19004 | redeemScriptHash = bcrypto.hash160(redeemScript) |
18743 | witnessScriptHash = bcrypto.sha256(witnessScript) | 19005 | witnessScriptHash = bcrypto.sha256(witnessScript) |
18744 | checkP2shInput(input, redeemScriptHash) | 19006 | checkP2SHInput(input, redeemScriptHash) |
18745 | 19007 | ||
18746 | if (!redeemScript.equals(bscript.witnessScriptHash.output.encode(witnessScriptHash))) throw new Error('Witness script inconsistent with redeem script') | 19008 | if (!redeemScript.equals(btemplates.witnessScriptHash.output.encode(witnessScriptHash))) throw new Error('Witness script inconsistent with redeem script') |
18747 | 19009 | ||
18748 | expanded = expandOutput(witnessScript, undefined, kpPubKey) | 19010 | expanded = expandOutput(witnessScript, undefined, kpPubKey) |
18749 | if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"') | 19011 | if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"') |
18750 | prevOutType = bscript.types.P2SH | 19012 | |
18751 | prevOutScript = bscript.scriptHash.output.encode(redeemScriptHash) | 19013 | prevOutType = btemplates.types.P2SH |
19014 | prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash) | ||
18752 | p2sh = witness = p2wsh = true | 19015 | p2sh = witness = p2wsh = true |
18753 | p2shType = bscript.types.P2WSH | 19016 | p2shType = btemplates.types.P2WSH |
18754 | signType = witnessType = expanded.scriptType | 19017 | signType = witnessType = expanded.scriptType |
18755 | signScript = witnessScript | 19018 | signScript = witnessScript |
18756 | } else if (redeemScript) { | 19019 | } else if (redeemScript) { |
18757 | redeemScriptHash = bcrypto.hash160(redeemScript) | 19020 | redeemScriptHash = bcrypto.hash160(redeemScript) |
18758 | checkP2shInput(input, redeemScriptHash) | 19021 | checkP2SHInput(input, redeemScriptHash) |
18759 | 19022 | ||
18760 | expanded = expandOutput(redeemScript, undefined, kpPubKey) | 19023 | expanded = expandOutput(redeemScript, undefined, kpPubKey) |
18761 | if (!expanded.pubKeys) throw new Error('RedeemScript not supported "' + bscript.toASM(redeemScript) + '"') | 19024 | if (!expanded.pubKeys) throw new Error('RedeemScript not supported "' + bscript.toASM(redeemScript) + '"') |
18762 | 19025 | ||
18763 | prevOutType = bscript.types.P2SH | 19026 | prevOutType = btemplates.types.P2SH |
18764 | prevOutScript = bscript.scriptHash.output.encode(redeemScriptHash) | 19027 | prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash) |
18765 | p2sh = true | 19028 | p2sh = true |
18766 | signType = p2shType = expanded.scriptType | 19029 | signType = p2shType = expanded.scriptType |
18767 | signScript = redeemScript | 19030 | signScript = redeemScript |
18768 | witness = signType === bscript.types.P2WPKH | 19031 | witness = signType === btemplates.types.P2WPKH |
18769 | } else if (witnessScript) { | 19032 | } else if (witnessScript) { |
18770 | witnessScriptHash = bcrypto.sha256(witnessScript) | 19033 | witnessScriptHash = bcrypto.sha256(witnessScript) |
18771 | checkP2WSHInput(input, witnessScriptHash) | 19034 | checkP2WSHInput(input, witnessScriptHash) |
@@ -18773,8 +19036,8 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip | |||
18773 | expanded = expandOutput(witnessScript, undefined, kpPubKey) | 19036 | expanded = expandOutput(witnessScript, undefined, kpPubKey) |
18774 | if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"') | 19037 | if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"') |
18775 | 19038 | ||
18776 | prevOutType = bscript.types.P2WSH | 19039 | prevOutType = btemplates.types.P2WSH |
18777 | prevOutScript = bscript.witnessScriptHash.output.encode(witnessScriptHash) | 19040 | prevOutScript = btemplates.witnessScriptHash.output.encode(witnessScriptHash) |
18778 | witness = p2wsh = true | 19041 | witness = p2wsh = true |
18779 | signType = witnessType = expanded.scriptType | 19042 | signType = witnessType = expanded.scriptType |
18780 | signScript = witnessScript | 19043 | signScript = witnessScript |
@@ -18794,20 +19057,17 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip | |||
18794 | signType = prevOutType | 19057 | signType = prevOutType |
18795 | signScript = prevOutScript | 19058 | signScript = prevOutScript |
18796 | } else { | 19059 | } else { |
18797 | prevOutScript = bscript.pubKeyHash.output.encode(bcrypto.hash160(kpPubKey)) | 19060 | prevOutScript = btemplates.pubKeyHash.output.encode(bcrypto.hash160(kpPubKey)) |
18798 | expanded = expandOutput(prevOutScript, scriptTypes.P2PKH, kpPubKey) | 19061 | expanded = expandOutput(prevOutScript, scriptTypes.P2PKH, kpPubKey) |
19062 | |||
18799 | prevOutType = scriptTypes.P2PKH | 19063 | prevOutType = scriptTypes.P2PKH |
18800 | witness = false | 19064 | witness = false |
18801 | signType = prevOutType | 19065 | signType = prevOutType |
18802 | signScript = prevOutScript | 19066 | signScript = prevOutScript |
18803 | } | 19067 | } |
18804 | 19068 | ||
18805 | if (witness && !types.Satoshi(witnessValue)) { | ||
18806 | throw new Error('Input was witness but not given witness value') | ||
18807 | } | ||
18808 | |||
18809 | if (signType === scriptTypes.P2WPKH) { | 19069 | if (signType === scriptTypes.P2WPKH) { |
18810 | signScript = bscript.pubKeyHash.output.encode(bscript.witnessPubKeyHash.output.decode(signScript)) | 19070 | signScript = btemplates.pubKeyHash.output.encode(btemplates.witnessPubKeyHash.output.decode(signScript)) |
18811 | } | 19071 | } |
18812 | 19072 | ||
18813 | if (p2sh) { | 19073 | if (p2sh) { |
@@ -18831,9 +19091,9 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip | |||
18831 | 19091 | ||
18832 | function buildStack (type, signatures, pubKeys, allowIncomplete) { | 19092 | function buildStack (type, signatures, pubKeys, allowIncomplete) { |
18833 | if (type === scriptTypes.P2PKH) { | 19093 | if (type === scriptTypes.P2PKH) { |
18834 | if (signatures.length === 1 && Buffer.isBuffer(signatures[0]) && pubKeys.length === 1) return bscript.pubKeyHash.input.encodeStack(signatures[0], pubKeys[0]) | 19094 | if (signatures.length === 1 && Buffer.isBuffer(signatures[0]) && pubKeys.length === 1) return btemplates.pubKeyHash.input.encodeStack(signatures[0], pubKeys[0]) |
18835 | } else if (type === scriptTypes.P2PK) { | 19095 | } else if (type === scriptTypes.P2PK) { |
18836 | if (signatures.length === 1 && Buffer.isBuffer(signatures[0])) return bscript.pubKey.input.encodeStack(signatures[0]) | 19096 | if (signatures.length === 1 && Buffer.isBuffer(signatures[0])) return btemplates.pubKey.input.encodeStack(signatures[0]) |
18837 | } else if (type === scriptTypes.MULTISIG) { | 19097 | } else if (type === scriptTypes.MULTISIG) { |
18838 | if (signatures.length > 0) { | 19098 | if (signatures.length > 0) { |
18839 | signatures = signatures.map(function (signature) { | 19099 | signatures = signatures.map(function (signature) { |
@@ -18844,14 +19104,13 @@ function buildStack (type, signatures, pubKeys, allowIncomplete) { | |||
18844 | signatures = signatures.filter(function (x) { return x !== ops.OP_0 }) | 19104 | signatures = signatures.filter(function (x) { return x !== ops.OP_0 }) |
18845 | } | 19105 | } |
18846 | 19106 | ||
18847 | return bscript.multisig.input.encodeStack(signatures /* see if it's necessary first */) | 19107 | return btemplates.multisig.input.encodeStack(signatures) |
18848 | } | 19108 | } |
18849 | } else { | 19109 | } else { |
18850 | throw new Error('Not yet supported') | 19110 | throw new Error('Not yet supported') |
18851 | } | 19111 | } |
18852 | 19112 | ||
18853 | if (!allowIncomplete) throw new Error('Not enough signatures provided') | 19113 | if (!allowIncomplete) throw new Error('Not enough signatures provided') |
18854 | |||
18855 | return [] | 19114 | return [] |
18856 | } | 19115 | } |
18857 | 19116 | ||
@@ -18859,40 +19118,49 @@ function buildInput (input, allowIncomplete) { | |||
18859 | var scriptType = input.prevOutType | 19118 | var scriptType = input.prevOutType |
18860 | var sig = [] | 19119 | var sig = [] |
18861 | var witness = [] | 19120 | var witness = [] |
18862 | if (SIGNABLE.indexOf(scriptType) !== -1) { | 19121 | |
19122 | if (supportedType(scriptType)) { | ||
18863 | sig = buildStack(scriptType, input.signatures, input.pubKeys, allowIncomplete) | 19123 | sig = buildStack(scriptType, input.signatures, input.pubKeys, allowIncomplete) |
18864 | } | 19124 | } |
18865 | 19125 | ||
18866 | var p2sh = false | 19126 | var p2sh = false |
18867 | if (scriptType === bscript.types.P2SH) { | 19127 | if (scriptType === btemplates.types.P2SH) { |
18868 | // We can remove this error later when we have a guarantee prepareInput | 19128 | // We can remove this error later when we have a guarantee prepareInput |
18869 | // rejects unsignable scripts - it MUST be signable at this point. | 19129 | // rejects unsignable scripts - it MUST be signable at this point. |
18870 | if (P2SH.indexOf(input.redeemScriptType) === -1) { | 19130 | if (!allowIncomplete && !supportedP2SHType(input.redeemScriptType)) { |
18871 | throw new Error('Impossible to sign this type') | 19131 | throw new Error('Impossible to sign this type') |
18872 | } | 19132 | } |
18873 | p2sh = true | 19133 | |
18874 | if (SIGNABLE.indexOf(input.redeemScriptType) !== -1) { | 19134 | if (supportedType(input.redeemScriptType)) { |
18875 | sig = buildStack(input.redeemScriptType, input.signatures, input.pubKeys, allowIncomplete) | 19135 | sig = buildStack(input.redeemScriptType, input.signatures, input.pubKeys, allowIncomplete) |
18876 | } | 19136 | } |
19137 | |||
18877 | // If it wasn't SIGNABLE, it's witness, defer to that | 19138 | // If it wasn't SIGNABLE, it's witness, defer to that |
18878 | scriptType = input.redeemScriptType | 19139 | if (input.redeemScriptType) { |
19140 | p2sh = true | ||
19141 | scriptType = input.redeemScriptType | ||
19142 | } | ||
18879 | } | 19143 | } |
18880 | 19144 | ||
18881 | if (scriptType === bscript.types.P2WPKH) { | 19145 | switch (scriptType) { |
18882 | // P2WPKH is a special case of P2PKH | 19146 | // P2WPKH is a special case of P2PKH |
18883 | witness = buildStack(bscript.types.P2PKH, input.signatures, input.pubKeys, allowIncomplete) | 19147 | case btemplates.types.P2WPKH: |
18884 | } else if (scriptType === bscript.types.P2WSH) { | 19148 | witness = buildStack(btemplates.types.P2PKH, input.signatures, input.pubKeys, allowIncomplete) |
18885 | // We can remove this check later | 19149 | break |
18886 | if (SIGNABLE.indexOf(input.witnessScriptType) !== -1) { | 19150 | |
18887 | witness = buildStack(input.witnessScriptType, input.signatures, input.pubKeys, allowIncomplete) | 19151 | case btemplates.types.P2WSH: |
18888 | witness.push(input.witnessScript) | 19152 | // We can remove this check later |
18889 | } else { | 19153 | if (!allowIncomplete && !supportedType(input.witnessScriptType)) { |
18890 | // We can remove this error later when we have a guarantee prepareInput | 19154 | throw new Error('Impossible to sign this type') |
18891 | // rejects unsignble scripts - it MUST be signable at this point. | 19155 | } |
18892 | throw new Error() | 19156 | |
18893 | } | 19157 | if (supportedType(input.witnessScriptType)) { |
19158 | witness = buildStack(input.witnessScriptType, input.signatures, input.pubKeys, allowIncomplete) | ||
19159 | witness.push(input.witnessScript) | ||
19160 | scriptType = input.witnessScriptType | ||
19161 | } | ||
18894 | 19162 | ||
18895 | scriptType = input.witnessScriptType | 19163 | break |
18896 | } | 19164 | } |
18897 | 19165 | ||
18898 | // append redeemScript if necessary | 19166 | // append redeemScript if necessary |
@@ -19033,13 +19301,12 @@ TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options) | |||
19033 | } | 19301 | } |
19034 | 19302 | ||
19035 | input.prevOutScript = options.prevOutScript | 19303 | input.prevOutScript = options.prevOutScript |
19036 | input.prevOutType = prevOutType || bscript.classifyOutput(options.prevOutScript) | 19304 | input.prevOutType = prevOutType || btemplates.classifyOutput(options.prevOutScript) |
19037 | } | 19305 | } |
19038 | 19306 | ||
19039 | var vin = this.tx.addInput(txHash, vout, options.sequence, options.scriptSig) | 19307 | var vin = this.tx.addInput(txHash, vout, options.sequence, options.scriptSig) |
19040 | this.inputs[vin] = input | 19308 | this.inputs[vin] = input |
19041 | this.prevTxMap[prevTxOut] = vin | 19309 | this.prevTxMap[prevTxOut] = vin |
19042 | |||
19043 | return vin | 19310 | return vin |
19044 | } | 19311 | } |
19045 | 19312 | ||
@@ -19078,7 +19345,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) { | |||
19078 | 19345 | ||
19079 | // skip if no result | 19346 | // skip if no result |
19080 | if (!allowIncomplete) { | 19347 | if (!allowIncomplete) { |
19081 | if (SIGNABLE.indexOf(result.type) === -1 && result.type !== bscript.types.P2WPKH) { | 19348 | if (!supportedType(result.type) && result.type !== btemplates.types.P2WPKH) { |
19082 | throw new Error(result.type + ' not supported') | 19349 | throw new Error(result.type + ' not supported') |
19083 | } | 19350 | } |
19084 | } | 19351 | } |
@@ -19089,7 +19356,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) { | |||
19089 | 19356 | ||
19090 | if (!allowIncomplete) { | 19357 | if (!allowIncomplete) { |
19091 | // do not rely on this, its merely a last resort | 19358 | // do not rely on this, its merely a last resort |
19092 | if (this.__overMaximumFees(tx.byteLength())) { | 19359 | if (this.__overMaximumFees(tx.virtualSize())) { |
19093 | throw new Error('Transaction has absurd fees') | 19360 | throw new Error('Transaction has absurd fees') |
19094 | } | 19361 | } |
19095 | } | 19362 | } |
@@ -19104,11 +19371,15 @@ function canSign (input) { | |||
19104 | input.signatures !== undefined && | 19371 | input.signatures !== undefined && |
19105 | input.signatures.length === input.pubKeys.length && | 19372 | input.signatures.length === input.pubKeys.length && |
19106 | input.pubKeys.length > 0 && | 19373 | input.pubKeys.length > 0 && |
19107 | input.witness !== undefined | 19374 | ( |
19375 | input.witness === false || | ||
19376 | (input.witness === true && input.value !== undefined) | ||
19377 | ) | ||
19108 | } | 19378 | } |
19109 | 19379 | ||
19110 | TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue, witnessScript) { | 19380 | TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue, witnessScript) { |
19111 | if (keyPair.network !== this.network) throw new Error('Inconsistent network') | 19381 | // TODO: remove keyPair.network matching in 4.0.0 |
19382 | if (keyPair.network && keyPair.network !== this.network) throw new TypeError('Inconsistent network') | ||
19112 | if (!this.inputs[vin]) throw new Error('No input at index: ' + vin) | 19383 | if (!this.inputs[vin]) throw new Error('No input at index: ' + vin) |
19113 | hashType = hashType || Transaction.SIGHASH_ALL | 19384 | hashType = hashType || Transaction.SIGHASH_ALL |
19114 | 19385 | ||
@@ -19121,25 +19392,37 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy | |||
19121 | throw new Error('Inconsistent redeemScript') | 19392 | throw new Error('Inconsistent redeemScript') |
19122 | } | 19393 | } |
19123 | 19394 | ||
19124 | var kpPubKey = keyPair.getPublicKeyBuffer() | 19395 | var kpPubKey = keyPair.publicKey || keyPair.getPublicKeyBuffer() |
19125 | if (!canSign(input)) { | 19396 | if (!canSign(input)) { |
19126 | prepareInput(input, kpPubKey, redeemScript, witnessValue, witnessScript) | 19397 | if (witnessValue !== undefined) { |
19398 | if (input.value !== undefined && input.value !== witnessValue) throw new Error('Input didn\'t match witnessValue') | ||
19399 | typeforce(types.Satoshi, witnessValue) | ||
19400 | input.value = witnessValue | ||
19401 | } | ||
19402 | |||
19403 | if (!canSign(input)) prepareInput(input, kpPubKey, redeemScript, witnessValue, witnessScript) | ||
19127 | if (!canSign(input)) throw Error(input.prevOutType + ' not supported') | 19404 | if (!canSign(input)) throw Error(input.prevOutType + ' not supported') |
19128 | } | 19405 | } |
19129 | 19406 | ||
19130 | // ready to sign | 19407 | // ready to sign |
19131 | var signatureHash | 19408 | var signatureHash |
19132 | if (input.witness) { | 19409 | if (input.witness) { |
19133 | signatureHash = this.tx.hashForWitnessV0(vin, input.signScript, witnessValue, hashType) | 19410 | signatureHash = this.tx.hashForWitnessV0(vin, input.signScript, input.value, hashType) |
19134 | } else { | 19411 | } else { |
19135 | signatureHash = this.tx.hashForSignature(vin, input.signScript, hashType) | 19412 | signatureHash = this.tx.hashForSignature(vin, input.signScript, hashType) |
19136 | } | 19413 | } |
19414 | |||
19137 | // enforce in order signing of public keys | 19415 | // enforce in order signing of public keys |
19138 | var signed = input.pubKeys.some(function (pubKey, i) { | 19416 | var signed = input.pubKeys.some(function (pubKey, i) { |
19139 | if (!kpPubKey.equals(pubKey)) return false | 19417 | if (!kpPubKey.equals(pubKey)) return false |
19140 | if (input.signatures[i]) throw new Error('Signature already exists') | 19418 | if (input.signatures[i]) throw new Error('Signature already exists') |
19419 | if (kpPubKey.length !== 33 && | ||
19420 | input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH') | ||
19421 | |||
19422 | var signature = keyPair.sign(signatureHash) | ||
19423 | if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature) | ||
19141 | 19424 | ||
19142 | input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType) | 19425 | input.signatures[i] = signature.toScriptSignature(hashType) |
19143 | return true | 19426 | return true |
19144 | }) | 19427 | }) |
19145 | 19428 | ||
@@ -19204,7 +19487,7 @@ TransactionBuilder.prototype.__overMaximumFees = function (bytes) { | |||
19204 | 19487 | ||
19205 | module.exports = TransactionBuilder | 19488 | module.exports = TransactionBuilder |
19206 | 19489 | ||
19207 | },{"./address":42,"./crypto":45,"./ecpair":47,"./ecsignature":48,"./networks":51,"./script":52,"./transaction":76,"./types":78,"bitcoin-ops":40,"safe-buffer":98,"typeforce":109}],78:[function(require,module,exports){ | 19490 | },{"./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){ |
19208 | var typeforce = require('typeforce') | 19491 | var typeforce = require('typeforce') |
19209 | 19492 | ||
19210 | var UINT31_MAX = Math.pow(2, 31) - 1 | 19493 | var UINT31_MAX = Math.pow(2, 31) - 1 |
@@ -19259,71 +19542,3576 @@ for (var typeName in typeforce) { | |||
19259 | 19542 | ||
19260 | module.exports = types | 19543 | module.exports = types |
19261 | 19544 | ||
19262 | },{"typeforce":109}],79:[function(require,module,exports){ | 19545 | },{"typeforce":139}],81:[function(require,module,exports){ |
19546 | (function (module, exports) { | ||
19547 | 'use strict'; | ||
19548 | |||
19549 | // Utils | ||
19550 | function assert (val, msg) { | ||
19551 | if (!val) throw new Error(msg || 'Assertion failed'); | ||
19552 | } | ||
19553 | |||
19554 | // Could use `inherits` module, but don't want to move from single file | ||
19555 | // architecture yet. | ||
19556 | function inherits (ctor, superCtor) { | ||
19557 | ctor.super_ = superCtor; | ||
19558 | var TempCtor = function () {}; | ||
19559 | TempCtor.prototype = superCtor.prototype; | ||
19560 | ctor.prototype = new TempCtor(); | ||
19561 | ctor.prototype.constructor = ctor; | ||
19562 | } | ||
19563 | |||
19564 | // BN | ||
19565 | |||
19566 | function BN (number, base, endian) { | ||
19567 | if (BN.isBN(number)) { | ||
19568 | return number; | ||
19569 | } | ||
19570 | |||
19571 | this.negative = 0; | ||
19572 | this.words = null; | ||
19573 | this.length = 0; | ||
19574 | |||
19575 | // Reduction context | ||
19576 | this.red = null; | ||
19577 | |||
19578 | if (number !== null) { | ||
19579 | if (base === 'le' || base === 'be') { | ||
19580 | endian = base; | ||
19581 | base = 10; | ||
19582 | } | ||
19583 | |||
19584 | this._init(number || 0, base || 10, endian || 'be'); | ||
19585 | } | ||
19586 | } | ||
19587 | if (typeof module === 'object') { | ||
19588 | module.exports = BN; | ||
19589 | } else { | ||
19590 | exports.BN = BN; | ||
19591 | } | ||
19592 | |||
19593 | BN.BN = BN; | ||
19594 | BN.wordSize = 26; | ||
19595 | |||
19596 | var Buffer; | ||
19597 | try { | ||
19598 | Buffer = require('buf' + 'fer').Buffer; | ||
19599 | } catch (e) { | ||
19600 | } | ||
19601 | |||
19602 | BN.isBN = function isBN (num) { | ||
19603 | if (num instanceof BN) { | ||
19604 | return true; | ||
19605 | } | ||
19606 | |||
19607 | return num !== null && typeof num === 'object' && | ||
19608 | num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); | ||
19609 | }; | ||
19610 | |||
19611 | BN.max = function max (left, right) { | ||
19612 | if (left.cmp(right) > 0) return left; | ||
19613 | return right; | ||
19614 | }; | ||
19615 | |||
19616 | BN.min = function min (left, right) { | ||
19617 | if (left.cmp(right) < 0) return left; | ||
19618 | return right; | ||
19619 | }; | ||
19620 | |||
19621 | BN.prototype._init = function init (number, base, endian) { | ||
19622 | if (typeof number === 'number') { | ||
19623 | return this._initNumber(number, base, endian); | ||
19624 | } | ||
19625 | |||
19626 | if (typeof number === 'object') { | ||
19627 | return this._initArray(number, base, endian); | ||
19628 | } | ||
19629 | |||
19630 | if (base === 'hex') { | ||
19631 | base = 16; | ||
19632 | } | ||
19633 | assert(base === (base | 0) && base >= 2 && base <= 36); | ||
19634 | |||
19635 | number = number.toString().replace(/\s+/g, ''); | ||
19636 | var start = 0; | ||
19637 | if (number[0] === '-') { | ||
19638 | start++; | ||
19639 | } | ||
19640 | |||
19641 | if (base === 16) { | ||
19642 | this._parseHex(number, start); | ||
19643 | } else { | ||
19644 | this._parseBase(number, base, start); | ||
19645 | } | ||
19646 | |||
19647 | if (number[0] === '-') { | ||
19648 | this.negative = 1; | ||
19649 | } | ||
19650 | |||
19651 | this.strip(); | ||
19652 | |||
19653 | if (endian !== 'le') return; | ||
19654 | |||
19655 | this._initArray(this.toArray(), base, endian); | ||
19656 | }; | ||
19657 | |||
19658 | BN.prototype._initNumber = function _initNumber (number, base, endian) { | ||
19659 | if (number < 0) { | ||
19660 | this.negative = 1; | ||
19661 | number = -number; | ||
19662 | } | ||
19663 | if (number < 0x4000000) { | ||
19664 | this.words = [ number & 0x3ffffff ]; | ||
19665 | this.length = 1; | ||
19666 | } else if (number < 0x10000000000000) { | ||
19667 | this.words = [ | ||
19668 | number & 0x3ffffff, | ||
19669 | (number / 0x4000000) & 0x3ffffff | ||
19670 | ]; | ||
19671 | this.length = 2; | ||
19672 | } else { | ||
19673 | assert(number < 0x20000000000000); // 2 ^ 53 (unsafe) | ||
19674 | this.words = [ | ||
19675 | number & 0x3ffffff, | ||
19676 | (number / 0x4000000) & 0x3ffffff, | ||
19677 | 1 | ||
19678 | ]; | ||
19679 | this.length = 3; | ||
19680 | } | ||
19681 | |||
19682 | if (endian !== 'le') return; | ||
19683 | |||
19684 | // Reverse the bytes | ||
19685 | this._initArray(this.toArray(), base, endian); | ||
19686 | }; | ||
19687 | |||
19688 | BN.prototype._initArray = function _initArray (number, base, endian) { | ||
19689 | // Perhaps a Uint8Array | ||
19690 | assert(typeof number.length === 'number'); | ||
19691 | if (number.length <= 0) { | ||
19692 | this.words = [ 0 ]; | ||
19693 | this.length = 1; | ||
19694 | return this; | ||
19695 | } | ||
19696 | |||
19697 | this.length = Math.ceil(number.length / 3); | ||
19698 | this.words = new Array(this.length); | ||
19699 | for (var i = 0; i < this.length; i++) { | ||
19700 | this.words[i] = 0; | ||
19701 | } | ||
19702 | |||
19703 | var j, w; | ||
19704 | var off = 0; | ||
19705 | if (endian === 'be') { | ||
19706 | for (i = number.length - 1, j = 0; i >= 0; i -= 3) { | ||
19707 | w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16); | ||
19708 | this.words[j] |= (w << off) & 0x3ffffff; | ||
19709 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; | ||
19710 | off += 24; | ||
19711 | if (off >= 26) { | ||
19712 | off -= 26; | ||
19713 | j++; | ||
19714 | } | ||
19715 | } | ||
19716 | } else if (endian === 'le') { | ||
19717 | for (i = 0, j = 0; i < number.length; i += 3) { | ||
19718 | w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16); | ||
19719 | this.words[j] |= (w << off) & 0x3ffffff; | ||
19720 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; | ||
19721 | off += 24; | ||
19722 | if (off >= 26) { | ||
19723 | off -= 26; | ||
19724 | j++; | ||
19725 | } | ||
19726 | } | ||
19727 | } | ||
19728 | return this.strip(); | ||
19729 | }; | ||
19730 | |||
19731 | function parseHex (str, start, end) { | ||
19732 | var r = 0; | ||
19733 | var len = Math.min(str.length, end); | ||
19734 | for (var i = start; i < len; i++) { | ||
19735 | var c = str.charCodeAt(i) - 48; | ||
19736 | |||
19737 | r <<= 4; | ||
19738 | |||
19739 | // 'a' - 'f' | ||
19740 | if (c >= 49 && c <= 54) { | ||
19741 | r |= c - 49 + 0xa; | ||
19742 | |||
19743 | // 'A' - 'F' | ||
19744 | } else if (c >= 17 && c <= 22) { | ||
19745 | r |= c - 17 + 0xa; | ||
19746 | |||
19747 | // '0' - '9' | ||
19748 | } else { | ||
19749 | r |= c & 0xf; | ||
19750 | } | ||
19751 | } | ||
19752 | return r; | ||
19753 | } | ||
19754 | |||
19755 | BN.prototype._parseHex = function _parseHex (number, start) { | ||
19756 | // Create possibly bigger array to ensure that it fits the number | ||
19757 | this.length = Math.ceil((number.length - start) / 6); | ||
19758 | this.words = new Array(this.length); | ||
19759 | for (var i = 0; i < this.length; i++) { | ||
19760 | this.words[i] = 0; | ||
19761 | } | ||
19762 | |||
19763 | var j, w; | ||
19764 | // Scan 24-bit chunks and add them to the number | ||
19765 | var off = 0; | ||
19766 | for (i = number.length - 6, j = 0; i >= start; i -= 6) { | ||
19767 | w = parseHex(number, i, i + 6); | ||
19768 | this.words[j] |= (w << off) & 0x3ffffff; | ||
19769 | // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb | ||
19770 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; | ||
19771 | off += 24; | ||
19772 | if (off >= 26) { | ||
19773 | off -= 26; | ||
19774 | j++; | ||
19775 | } | ||
19776 | } | ||
19777 | if (i + 6 !== start) { | ||
19778 | w = parseHex(number, start, i + 6); | ||
19779 | this.words[j] |= (w << off) & 0x3ffffff; | ||
19780 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; | ||
19781 | } | ||
19782 | this.strip(); | ||
19783 | }; | ||
19784 | |||
19785 | function parseBase (str, start, end, mul) { | ||
19786 | var r = 0; | ||
19787 | var len = Math.min(str.length, end); | ||
19788 | for (var i = start; i < len; i++) { | ||
19789 | var c = str.charCodeAt(i) - 48; | ||
19790 | |||
19791 | r *= mul; | ||
19792 | |||
19793 | // 'a' | ||
19794 | if (c >= 49) { | ||
19795 | r += c - 49 + 0xa; | ||
19796 | |||
19797 | // 'A' | ||
19798 | } else if (c >= 17) { | ||
19799 | r += c - 17 + 0xa; | ||
19800 | |||
19801 | // '0' - '9' | ||
19802 | } else { | ||
19803 | r += c; | ||
19804 | } | ||
19805 | } | ||
19806 | return r; | ||
19807 | } | ||
19808 | |||
19809 | BN.prototype._parseBase = function _parseBase (number, base, start) { | ||
19810 | // Initialize as zero | ||
19811 | this.words = [ 0 ]; | ||
19812 | this.length = 1; | ||
19813 | |||
19814 | // Find length of limb in base | ||
19815 | for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) { | ||
19816 | limbLen++; | ||
19817 | } | ||
19818 | limbLen--; | ||
19819 | limbPow = (limbPow / base) | 0; | ||
19820 | |||
19821 | var total = number.length - start; | ||
19822 | var mod = total % limbLen; | ||
19823 | var end = Math.min(total, total - mod) + start; | ||
19824 | |||
19825 | var word = 0; | ||
19826 | for (var i = start; i < end; i += limbLen) { | ||
19827 | word = parseBase(number, i, i + limbLen, base); | ||
19828 | |||
19829 | this.imuln(limbPow); | ||
19830 | if (this.words[0] + word < 0x4000000) { | ||
19831 | this.words[0] += word; | ||
19832 | } else { | ||
19833 | this._iaddn(word); | ||
19834 | } | ||
19835 | } | ||
19836 | |||
19837 | if (mod !== 0) { | ||
19838 | var pow = 1; | ||
19839 | word = parseBase(number, i, number.length, base); | ||
19840 | |||
19841 | for (i = 0; i < mod; i++) { | ||
19842 | pow *= base; | ||
19843 | } | ||
19844 | |||
19845 | this.imuln(pow); | ||
19846 | if (this.words[0] + word < 0x4000000) { | ||
19847 | this.words[0] += word; | ||
19848 | } else { | ||
19849 | this._iaddn(word); | ||
19850 | } | ||
19851 | } | ||
19852 | }; | ||
19853 | |||
19854 | BN.prototype.copy = function copy (dest) { | ||
19855 | dest.words = new Array(this.length); | ||
19856 | for (var i = 0; i < this.length; i++) { | ||
19857 | dest.words[i] = this.words[i]; | ||
19858 | } | ||
19859 | dest.length = this.length; | ||
19860 | dest.negative = this.negative; | ||
19861 | dest.red = this.red; | ||
19862 | }; | ||
19863 | |||
19864 | BN.prototype.clone = function clone () { | ||
19865 | var r = new BN(null); | ||
19866 | this.copy(r); | ||
19867 | return r; | ||
19868 | }; | ||
19869 | |||
19870 | BN.prototype._expand = function _expand (size) { | ||
19871 | while (this.length < size) { | ||
19872 | this.words[this.length++] = 0; | ||
19873 | } | ||
19874 | return this; | ||
19875 | }; | ||
19876 | |||
19877 | // Remove leading `0` from `this` | ||
19878 | BN.prototype.strip = function strip () { | ||
19879 | while (this.length > 1 && this.words[this.length - 1] === 0) { | ||
19880 | this.length--; | ||
19881 | } | ||
19882 | return this._normSign(); | ||
19883 | }; | ||
19884 | |||
19885 | BN.prototype._normSign = function _normSign () { | ||
19886 | // -0 = 0 | ||
19887 | if (this.length === 1 && this.words[0] === 0) { | ||
19888 | this.negative = 0; | ||
19889 | } | ||
19890 | return this; | ||
19891 | }; | ||
19892 | |||
19893 | BN.prototype.inspect = function inspect () { | ||
19894 | return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>'; | ||
19895 | }; | ||
19896 | |||
19897 | /* | ||
19898 | |||
19899 | var zeros = []; | ||
19900 | var groupSizes = []; | ||
19901 | var groupBases = []; | ||
19902 | |||
19903 | var s = ''; | ||
19904 | var i = -1; | ||
19905 | while (++i < BN.wordSize) { | ||
19906 | zeros[i] = s; | ||
19907 | s += '0'; | ||
19908 | } | ||
19909 | groupSizes[0] = 0; | ||
19910 | groupSizes[1] = 0; | ||
19911 | groupBases[0] = 0; | ||
19912 | groupBases[1] = 0; | ||
19913 | var base = 2 - 1; | ||
19914 | while (++base < 36 + 1) { | ||
19915 | var groupSize = 0; | ||
19916 | var groupBase = 1; | ||
19917 | while (groupBase < (1 << BN.wordSize) / base) { | ||
19918 | groupBase *= base; | ||
19919 | groupSize += 1; | ||
19920 | } | ||
19921 | groupSizes[base] = groupSize; | ||
19922 | groupBases[base] = groupBase; | ||
19923 | } | ||
19924 | |||
19925 | */ | ||
19926 | |||
19927 | var zeros = [ | ||
19928 | '', | ||
19929 | '0', | ||
19930 | '00', | ||
19931 | '000', | ||
19932 | '0000', | ||
19933 | '00000', | ||
19934 | '000000', | ||
19935 | '0000000', | ||
19936 | '00000000', | ||
19937 | '000000000', | ||
19938 | '0000000000', | ||
19939 | '00000000000', | ||
19940 | '000000000000', | ||
19941 | '0000000000000', | ||
19942 | '00000000000000', | ||
19943 | '000000000000000', | ||
19944 | '0000000000000000', | ||
19945 | '00000000000000000', | ||
19946 | '000000000000000000', | ||
19947 | '0000000000000000000', | ||
19948 | '00000000000000000000', | ||
19949 | '000000000000000000000', | ||
19950 | '0000000000000000000000', | ||
19951 | '00000000000000000000000', | ||
19952 | '000000000000000000000000', | ||
19953 | '0000000000000000000000000' | ||
19954 | ]; | ||
19955 | |||
19956 | var groupSizes = [ | ||
19957 | 0, 0, | ||
19958 | 25, 16, 12, 11, 10, 9, 8, | ||
19959 | 8, 7, 7, 7, 7, 6, 6, | ||
19960 | 6, 6, 6, 6, 6, 5, 5, | ||
19961 | 5, 5, 5, 5, 5, 5, 5, | ||
19962 | 5, 5, 5, 5, 5, 5, 5 | ||
19963 | ]; | ||
19964 | |||
19965 | var groupBases = [ | ||
19966 | 0, 0, | ||
19967 | 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, | ||
19968 | 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, | ||
19969 | 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, | ||
19970 | 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, | ||
19971 | 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176 | ||
19972 | ]; | ||
19973 | |||
19974 | BN.prototype.toString = function toString (base, padding) { | ||
19975 | base = base || 10; | ||
19976 | padding = padding | 0 || 1; | ||
19977 | |||
19978 | var out; | ||
19979 | if (base === 16 || base === 'hex') { | ||
19980 | out = ''; | ||
19981 | var off = 0; | ||
19982 | var carry = 0; | ||
19983 | for (var i = 0; i < this.length; i++) { | ||
19984 | var w = this.words[i]; | ||
19985 | var word = (((w << off) | carry) & 0xffffff).toString(16); | ||
19986 | carry = (w >>> (24 - off)) & 0xffffff; | ||
19987 | if (carry !== 0 || i !== this.length - 1) { | ||
19988 | out = zeros[6 - word.length] + word + out; | ||
19989 | } else { | ||
19990 | out = word + out; | ||
19991 | } | ||
19992 | off += 2; | ||
19993 | if (off >= 26) { | ||
19994 | off -= 26; | ||
19995 | i--; | ||
19996 | } | ||
19997 | } | ||
19998 | if (carry !== 0) { | ||
19999 | out = carry.toString(16) + out; | ||
20000 | } | ||
20001 | while (out.length % padding !== 0) { | ||
20002 | out = '0' + out; | ||
20003 | } | ||
20004 | if (this.negative !== 0) { | ||
20005 | out = '-' + out; | ||
20006 | } | ||
20007 | return out; | ||
20008 | } | ||
20009 | |||
20010 | if (base === (base | 0) && base >= 2 && base <= 36) { | ||
20011 | // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); | ||
20012 | var groupSize = groupSizes[base]; | ||
20013 | // var groupBase = Math.pow(base, groupSize); | ||
20014 | var groupBase = groupBases[base]; | ||
20015 | out = ''; | ||
20016 | var c = this.clone(); | ||
20017 | c.negative = 0; | ||
20018 | while (!c.isZero()) { | ||
20019 | var r = c.modn(groupBase).toString(base); | ||
20020 | c = c.idivn(groupBase); | ||
20021 | |||
20022 | if (!c.isZero()) { | ||
20023 | out = zeros[groupSize - r.length] + r + out; | ||
20024 | } else { | ||
20025 | out = r + out; | ||
20026 | } | ||
20027 | } | ||
20028 | if (this.isZero()) { | ||
20029 | out = '0' + out; | ||
20030 | } | ||
20031 | while (out.length % padding !== 0) { | ||
20032 | out = '0' + out; | ||
20033 | } | ||
20034 | if (this.negative !== 0) { | ||
20035 | out = '-' + out; | ||
20036 | } | ||
20037 | return out; | ||
20038 | } | ||
20039 | |||
20040 | assert(false, 'Base should be between 2 and 36'); | ||
20041 | }; | ||
20042 | |||
20043 | BN.prototype.toNumber = function toNumber () { | ||
20044 | var ret = this.words[0]; | ||
20045 | if (this.length === 2) { | ||
20046 | ret += this.words[1] * 0x4000000; | ||
20047 | } else if (this.length === 3 && this.words[2] === 0x01) { | ||
20048 | // NOTE: at this stage it is known that the top bit is set | ||
20049 | ret += 0x10000000000000 + (this.words[1] * 0x4000000); | ||
20050 | } else if (this.length > 2) { | ||
20051 | assert(false, 'Number can only safely store up to 53 bits'); | ||
20052 | } | ||
20053 | return (this.negative !== 0) ? -ret : ret; | ||
20054 | }; | ||
20055 | |||
20056 | BN.prototype.toJSON = function toJSON () { | ||
20057 | return this.toString(16); | ||
20058 | }; | ||
20059 | |||
20060 | BN.prototype.toBuffer = function toBuffer (endian, length) { | ||
20061 | assert(typeof Buffer !== 'undefined'); | ||
20062 | return this.toArrayLike(Buffer, endian, length); | ||
20063 | }; | ||
20064 | |||
20065 | BN.prototype.toArray = function toArray (endian, length) { | ||
20066 | return this.toArrayLike(Array, endian, length); | ||
20067 | }; | ||
20068 | |||
20069 | BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) { | ||
20070 | var byteLength = this.byteLength(); | ||
20071 | var reqLength = length || Math.max(1, byteLength); | ||
20072 | assert(byteLength <= reqLength, 'byte array longer than desired length'); | ||
20073 | assert(reqLength > 0, 'Requested array length <= 0'); | ||
20074 | |||
20075 | this.strip(); | ||
20076 | var littleEndian = endian === 'le'; | ||
20077 | var res = new ArrayType(reqLength); | ||
20078 | |||
20079 | var b, i; | ||
20080 | var q = this.clone(); | ||
20081 | if (!littleEndian) { | ||
20082 | // Assume big-endian | ||
20083 | for (i = 0; i < reqLength - byteLength; i++) { | ||
20084 | res[i] = 0; | ||
20085 | } | ||
20086 | |||
20087 | for (i = 0; !q.isZero(); i++) { | ||
20088 | b = q.andln(0xff); | ||
20089 | q.iushrn(8); | ||
20090 | |||
20091 | res[reqLength - i - 1] = b; | ||
20092 | } | ||
20093 | } else { | ||
20094 | for (i = 0; !q.isZero(); i++) { | ||
20095 | b = q.andln(0xff); | ||
20096 | q.iushrn(8); | ||
20097 | |||
20098 | res[i] = b; | ||
20099 | } | ||
20100 | |||
20101 | for (; i < reqLength; i++) { | ||
20102 | res[i] = 0; | ||
20103 | } | ||
20104 | } | ||
20105 | |||
20106 | return res; | ||
20107 | }; | ||
20108 | |||
20109 | if (Math.clz32) { | ||
20110 | BN.prototype._countBits = function _countBits (w) { | ||
20111 | return 32 - Math.clz32(w); | ||
20112 | }; | ||
20113 | } else { | ||
20114 | BN.prototype._countBits = function _countBits (w) { | ||
20115 | var t = w; | ||
20116 | var r = 0; | ||
20117 | if (t >= 0x1000) { | ||
20118 | r += 13; | ||
20119 | t >>>= 13; | ||
20120 | } | ||
20121 | if (t >= 0x40) { | ||
20122 | r += 7; | ||
20123 | t >>>= 7; | ||
20124 | } | ||
20125 | if (t >= 0x8) { | ||
20126 | r += 4; | ||
20127 | t >>>= 4; | ||
20128 | } | ||
20129 | if (t >= 0x02) { | ||
20130 | r += 2; | ||
20131 | t >>>= 2; | ||
20132 | } | ||
20133 | return r + t; | ||
20134 | }; | ||
20135 | } | ||
20136 | |||
20137 | BN.prototype._zeroBits = function _zeroBits (w) { | ||
20138 | // Short-cut | ||
20139 | if (w === 0) return 26; | ||
20140 | |||
20141 | var t = w; | ||
20142 | var r = 0; | ||
20143 | if ((t & 0x1fff) === 0) { | ||
20144 | r += 13; | ||
20145 | t >>>= 13; | ||
20146 | } | ||
20147 | if ((t & 0x7f) === 0) { | ||
20148 | r += 7; | ||
20149 | t >>>= 7; | ||
20150 | } | ||
20151 | if ((t & 0xf) === 0) { | ||
20152 | r += 4; | ||
20153 | t >>>= 4; | ||
20154 | } | ||
20155 | if ((t & 0x3) === 0) { | ||
20156 | r += 2; | ||
20157 | t >>>= 2; | ||
20158 | } | ||
20159 | if ((t & 0x1) === 0) { | ||
20160 | r++; | ||
20161 | } | ||
20162 | return r; | ||
20163 | }; | ||
20164 | |||
20165 | // Return number of used bits in a BN | ||
20166 | BN.prototype.bitLength = function bitLength () { | ||
20167 | var w = this.words[this.length - 1]; | ||
20168 | var hi = this._countBits(w); | ||
20169 | return (this.length - 1) * 26 + hi; | ||
20170 | }; | ||
20171 | |||
20172 | function toBitArray (num) { | ||
20173 | var w = new Array(num.bitLength()); | ||
20174 | |||
20175 | for (var bit = 0; bit < w.length; bit++) { | ||
20176 | var off = (bit / 26) | 0; | ||
20177 | var wbit = bit % 26; | ||
20178 | |||
20179 | w[bit] = (num.words[off] & (1 << wbit)) >>> wbit; | ||
20180 | } | ||
20181 | |||
20182 | return w; | ||
20183 | } | ||
20184 | |||
20185 | // Number of trailing zero bits | ||
20186 | BN.prototype.zeroBits = function zeroBits () { | ||
20187 | if (this.isZero()) return 0; | ||
20188 | |||
20189 | var r = 0; | ||
20190 | for (var i = 0; i < this.length; i++) { | ||
20191 | var b = this._zeroBits(this.words[i]); | ||
20192 | r += b; | ||
20193 | if (b !== 26) break; | ||
20194 | } | ||
20195 | return r; | ||
20196 | }; | ||
20197 | |||
20198 | BN.prototype.byteLength = function byteLength () { | ||
20199 | return Math.ceil(this.bitLength() / 8); | ||
20200 | }; | ||
20201 | |||
20202 | BN.prototype.toTwos = function toTwos (width) { | ||
20203 | if (this.negative !== 0) { | ||
20204 | return this.abs().inotn(width).iaddn(1); | ||
20205 | } | ||
20206 | return this.clone(); | ||
20207 | }; | ||
20208 | |||
20209 | BN.prototype.fromTwos = function fromTwos (width) { | ||
20210 | if (this.testn(width - 1)) { | ||
20211 | return this.notn(width).iaddn(1).ineg(); | ||
20212 | } | ||
20213 | return this.clone(); | ||
20214 | }; | ||
20215 | |||
20216 | BN.prototype.isNeg = function isNeg () { | ||
20217 | return this.negative !== 0; | ||
20218 | }; | ||
20219 | |||
20220 | // Return negative clone of `this` | ||
20221 | BN.prototype.neg = function neg () { | ||
20222 | return this.clone().ineg(); | ||
20223 | }; | ||
20224 | |||
20225 | BN.prototype.ineg = function ineg () { | ||
20226 | if (!this.isZero()) { | ||
20227 | this.negative ^= 1; | ||
20228 | } | ||
20229 | |||
20230 | return this; | ||
20231 | }; | ||
20232 | |||
20233 | // Or `num` with `this` in-place | ||
20234 | BN.prototype.iuor = function iuor (num) { | ||
20235 | while (this.length < num.length) { | ||
20236 | this.words[this.length++] = 0; | ||
20237 | } | ||
20238 | |||
20239 | for (var i = 0; i < num.length; i++) { | ||
20240 | this.words[i] = this.words[i] | num.words[i]; | ||
20241 | } | ||
20242 | |||
20243 | return this.strip(); | ||
20244 | }; | ||
20245 | |||
20246 | BN.prototype.ior = function ior (num) { | ||
20247 | assert((this.negative | num.negative) === 0); | ||
20248 | return this.iuor(num); | ||
20249 | }; | ||
20250 | |||
20251 | // Or `num` with `this` | ||
20252 | BN.prototype.or = function or (num) { | ||
20253 | if (this.length > num.length) return this.clone().ior(num); | ||
20254 | return num.clone().ior(this); | ||
20255 | }; | ||
20256 | |||
20257 | BN.prototype.uor = function uor (num) { | ||
20258 | if (this.length > num.length) return this.clone().iuor(num); | ||
20259 | return num.clone().iuor(this); | ||
20260 | }; | ||
20261 | |||
20262 | // And `num` with `this` in-place | ||
20263 | BN.prototype.iuand = function iuand (num) { | ||
20264 | // b = min-length(num, this) | ||
20265 | var b; | ||
20266 | if (this.length > num.length) { | ||
20267 | b = num; | ||
20268 | } else { | ||
20269 | b = this; | ||
20270 | } | ||
20271 | |||
20272 | for (var i = 0; i < b.length; i++) { | ||
20273 | this.words[i] = this.words[i] & num.words[i]; | ||
20274 | } | ||
20275 | |||
20276 | this.length = b.length; | ||
20277 | |||
20278 | return this.strip(); | ||
20279 | }; | ||
20280 | |||
20281 | BN.prototype.iand = function iand (num) { | ||
20282 | assert((this.negative | num.negative) === 0); | ||
20283 | return this.iuand(num); | ||
20284 | }; | ||
20285 | |||
20286 | // And `num` with `this` | ||
20287 | BN.prototype.and = function and (num) { | ||
20288 | if (this.length > num.length) return this.clone().iand(num); | ||
20289 | return num.clone().iand(this); | ||
20290 | }; | ||
20291 | |||
20292 | BN.prototype.uand = function uand (num) { | ||
20293 | if (this.length > num.length) return this.clone().iuand(num); | ||
20294 | return num.clone().iuand(this); | ||
20295 | }; | ||
20296 | |||
20297 | // Xor `num` with `this` in-place | ||
20298 | BN.prototype.iuxor = function iuxor (num) { | ||
20299 | // a.length > b.length | ||
20300 | var a; | ||
20301 | var b; | ||
20302 | if (this.length > num.length) { | ||
20303 | a = this; | ||
20304 | b = num; | ||
20305 | } else { | ||
20306 | a = num; | ||
20307 | b = this; | ||
20308 | } | ||
20309 | |||
20310 | for (var i = 0; i < b.length; i++) { | ||
20311 | this.words[i] = a.words[i] ^ b.words[i]; | ||
20312 | } | ||
20313 | |||
20314 | if (this !== a) { | ||
20315 | for (; i < a.length; i++) { | ||
20316 | this.words[i] = a.words[i]; | ||
20317 | } | ||
20318 | } | ||
20319 | |||
20320 | this.length = a.length; | ||
20321 | |||
20322 | return this.strip(); | ||
20323 | }; | ||
20324 | |||
20325 | BN.prototype.ixor = function ixor (num) { | ||
20326 | assert((this.negative | num.negative) === 0); | ||
20327 | return this.iuxor(num); | ||
20328 | }; | ||
20329 | |||
20330 | // Xor `num` with `this` | ||
20331 | BN.prototype.xor = function xor (num) { | ||
20332 | if (this.length > num.length) return this.clone().ixor(num); | ||
20333 | return num.clone().ixor(this); | ||
20334 | }; | ||
20335 | |||
20336 | BN.prototype.uxor = function uxor (num) { | ||
20337 | if (this.length > num.length) return this.clone().iuxor(num); | ||
20338 | return num.clone().iuxor(this); | ||
20339 | }; | ||
20340 | |||
20341 | // Not ``this`` with ``width`` bitwidth | ||
20342 | BN.prototype.inotn = function inotn (width) { | ||
20343 | assert(typeof width === 'number' && width >= 0); | ||
20344 | |||
20345 | var bytesNeeded = Math.ceil(width / 26) | 0; | ||
20346 | var bitsLeft = width % 26; | ||
20347 | |||
20348 | // Extend the buffer with leading zeroes | ||
20349 | this._expand(bytesNeeded); | ||
20350 | |||
20351 | if (bitsLeft > 0) { | ||
20352 | bytesNeeded--; | ||
20353 | } | ||
20354 | |||
20355 | // Handle complete words | ||
20356 | for (var i = 0; i < bytesNeeded; i++) { | ||
20357 | this.words[i] = ~this.words[i] & 0x3ffffff; | ||
20358 | } | ||
20359 | |||
20360 | // Handle the residue | ||
20361 | if (bitsLeft > 0) { | ||
20362 | this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft)); | ||
20363 | } | ||
20364 | |||
20365 | // And remove leading zeroes | ||
20366 | return this.strip(); | ||
20367 | }; | ||
20368 | |||
20369 | BN.prototype.notn = function notn (width) { | ||
20370 | return this.clone().inotn(width); | ||
20371 | }; | ||
20372 | |||
20373 | // Set `bit` of `this` | ||
20374 | BN.prototype.setn = function setn (bit, val) { | ||
20375 | assert(typeof bit === 'number' && bit >= 0); | ||
20376 | |||
20377 | var off = (bit / 26) | 0; | ||
20378 | var wbit = bit % 26; | ||
20379 | |||
20380 | this._expand(off + 1); | ||
20381 | |||
20382 | if (val) { | ||
20383 | this.words[off] = this.words[off] | (1 << wbit); | ||
20384 | } else { | ||
20385 | this.words[off] = this.words[off] & ~(1 << wbit); | ||
20386 | } | ||
20387 | |||
20388 | return this.strip(); | ||
20389 | }; | ||
20390 | |||
20391 | // Add `num` to `this` in-place | ||
20392 | BN.prototype.iadd = function iadd (num) { | ||
20393 | var r; | ||
20394 | |||
20395 | // negative + positive | ||
20396 | if (this.negative !== 0 && num.negative === 0) { | ||
20397 | this.negative = 0; | ||
20398 | r = this.isub(num); | ||
20399 | this.negative ^= 1; | ||
20400 | return this._normSign(); | ||
20401 | |||
20402 | // positive + negative | ||
20403 | } else if (this.negative === 0 && num.negative !== 0) { | ||
20404 | num.negative = 0; | ||
20405 | r = this.isub(num); | ||
20406 | num.negative = 1; | ||
20407 | return r._normSign(); | ||
20408 | } | ||
20409 | |||
20410 | // a.length > b.length | ||
20411 | var a, b; | ||
20412 | if (this.length > num.length) { | ||
20413 | a = this; | ||
20414 | b = num; | ||
20415 | } else { | ||
20416 | a = num; | ||
20417 | b = this; | ||
20418 | } | ||
20419 | |||
20420 | var carry = 0; | ||
20421 | for (var i = 0; i < b.length; i++) { | ||
20422 | r = (a.words[i] | 0) + (b.words[i] | 0) + carry; | ||
20423 | this.words[i] = r & 0x3ffffff; | ||
20424 | carry = r >>> 26; | ||
20425 | } | ||
20426 | for (; carry !== 0 && i < a.length; i++) { | ||
20427 | r = (a.words[i] | 0) + carry; | ||
20428 | this.words[i] = r & 0x3ffffff; | ||
20429 | carry = r >>> 26; | ||
20430 | } | ||
20431 | |||
20432 | this.length = a.length; | ||
20433 | if (carry !== 0) { | ||
20434 | this.words[this.length] = carry; | ||
20435 | this.length++; | ||
20436 | // Copy the rest of the words | ||
20437 | } else if (a !== this) { | ||
20438 | for (; i < a.length; i++) { | ||
20439 | this.words[i] = a.words[i]; | ||
20440 | } | ||
20441 | } | ||
20442 | |||
20443 | return this; | ||
20444 | }; | ||
20445 | |||
20446 | // Add `num` to `this` | ||
20447 | BN.prototype.add = function add (num) { | ||
20448 | var res; | ||
20449 | if (num.negative !== 0 && this.negative === 0) { | ||
20450 | num.negative = 0; | ||
20451 | res = this.sub(num); | ||
20452 | num.negative ^= 1; | ||
20453 | return res; | ||
20454 | } else if (num.negative === 0 && this.negative !== 0) { | ||
20455 | this.negative = 0; | ||
20456 | res = num.sub(this); | ||
20457 | this.negative = 1; | ||
20458 | return res; | ||
20459 | } | ||
20460 | |||
20461 | if (this.length > num.length) return this.clone().iadd(num); | ||
20462 | |||
20463 | return num.clone().iadd(this); | ||
20464 | }; | ||
20465 | |||
20466 | // Subtract `num` from `this` in-place | ||
20467 | BN.prototype.isub = function isub (num) { | ||
20468 | // this - (-num) = this + num | ||
20469 | if (num.negative !== 0) { | ||
20470 | num.negative = 0; | ||
20471 | var r = this.iadd(num); | ||
20472 | num.negative = 1; | ||
20473 | return r._normSign(); | ||
20474 | |||
20475 | // -this - num = -(this + num) | ||
20476 | } else if (this.negative !== 0) { | ||
20477 | this.negative = 0; | ||
20478 | this.iadd(num); | ||
20479 | this.negative = 1; | ||
20480 | return this._normSign(); | ||
20481 | } | ||
20482 | |||
20483 | // At this point both numbers are positive | ||
20484 | var cmp = this.cmp(num); | ||
20485 | |||
20486 | // Optimization - zeroify | ||
20487 | if (cmp === 0) { | ||
20488 | this.negative = 0; | ||
20489 | this.length = 1; | ||
20490 | this.words[0] = 0; | ||
20491 | return this; | ||
20492 | } | ||
20493 | |||
20494 | // a > b | ||
20495 | var a, b; | ||
20496 | if (cmp > 0) { | ||
20497 | a = this; | ||
20498 | b = num; | ||
20499 | } else { | ||
20500 | a = num; | ||
20501 | b = this; | ||
20502 | } | ||
20503 | |||
20504 | var carry = 0; | ||
20505 | for (var i = 0; i < b.length; i++) { | ||
20506 | r = (a.words[i] | 0) - (b.words[i] | 0) + carry; | ||
20507 | carry = r >> 26; | ||
20508 | this.words[i] = r & 0x3ffffff; | ||
20509 | } | ||
20510 | for (; carry !== 0 && i < a.length; i++) { | ||
20511 | r = (a.words[i] | 0) + carry; | ||
20512 | carry = r >> 26; | ||
20513 | this.words[i] = r & 0x3ffffff; | ||
20514 | } | ||
20515 | |||
20516 | // Copy rest of the words | ||
20517 | if (carry === 0 && i < a.length && a !== this) { | ||
20518 | for (; i < a.length; i++) { | ||
20519 | this.words[i] = a.words[i]; | ||
20520 | } | ||
20521 | } | ||
20522 | |||
20523 | this.length = Math.max(this.length, i); | ||
20524 | |||
20525 | if (a !== this) { | ||
20526 | this.negative = 1; | ||
20527 | } | ||
20528 | |||
20529 | return this.strip(); | ||
20530 | }; | ||
20531 | |||
20532 | // Subtract `num` from `this` | ||
20533 | BN.prototype.sub = function sub (num) { | ||
20534 | return this.clone().isub(num); | ||
20535 | }; | ||
20536 | |||
20537 | function smallMulTo (self, num, out) { | ||
20538 | out.negative = num.negative ^ self.negative; | ||
20539 | var len = (self.length + num.length) | 0; | ||
20540 | out.length = len; | ||
20541 | len = (len - 1) | 0; | ||
20542 | |||
20543 | // Peel one iteration (compiler can't do it, because of code complexity) | ||
20544 | var a = self.words[0] | 0; | ||
20545 | var b = num.words[0] | 0; | ||
20546 | var r = a * b; | ||
20547 | |||
20548 | var lo = r & 0x3ffffff; | ||
20549 | var carry = (r / 0x4000000) | 0; | ||
20550 | out.words[0] = lo; | ||
20551 | |||
20552 | for (var k = 1; k < len; k++) { | ||
20553 | // Sum all words with the same `i + j = k` and accumulate `ncarry`, | ||
20554 | // note that ncarry could be >= 0x3ffffff | ||
20555 | var ncarry = carry >>> 26; | ||
20556 | var rword = carry & 0x3ffffff; | ||
20557 | var maxJ = Math.min(k, num.length - 1); | ||
20558 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { | ||
20559 | var i = (k - j) | 0; | ||
20560 | a = self.words[i] | 0; | ||
20561 | b = num.words[j] | 0; | ||
20562 | r = a * b + rword; | ||
20563 | ncarry += (r / 0x4000000) | 0; | ||
20564 | rword = r & 0x3ffffff; | ||
20565 | } | ||
20566 | out.words[k] = rword | 0; | ||
20567 | carry = ncarry | 0; | ||
20568 | } | ||
20569 | if (carry !== 0) { | ||
20570 | out.words[k] = carry | 0; | ||
20571 | } else { | ||
20572 | out.length--; | ||
20573 | } | ||
20574 | |||
20575 | return out.strip(); | ||
20576 | } | ||
20577 | |||
20578 | // TODO(indutny): it may be reasonable to omit it for users who don't need | ||
20579 | // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit | ||
20580 | // multiplication (like elliptic secp256k1). | ||
20581 | var comb10MulTo = function comb10MulTo (self, num, out) { | ||
20582 | var a = self.words; | ||
20583 | var b = num.words; | ||
20584 | var o = out.words; | ||
20585 | var c = 0; | ||
20586 | var lo; | ||
20587 | var mid; | ||
20588 | var hi; | ||
20589 | var a0 = a[0] | 0; | ||
20590 | var al0 = a0 & 0x1fff; | ||
20591 | var ah0 = a0 >>> 13; | ||
20592 | var a1 = a[1] | 0; | ||
20593 | var al1 = a1 & 0x1fff; | ||
20594 | var ah1 = a1 >>> 13; | ||
20595 | var a2 = a[2] | 0; | ||
20596 | var al2 = a2 & 0x1fff; | ||
20597 | var ah2 = a2 >>> 13; | ||
20598 | var a3 = a[3] | 0; | ||
20599 | var al3 = a3 & 0x1fff; | ||
20600 | var ah3 = a3 >>> 13; | ||
20601 | var a4 = a[4] | 0; | ||
20602 | var al4 = a4 & 0x1fff; | ||
20603 | var ah4 = a4 >>> 13; | ||
20604 | var a5 = a[5] | 0; | ||
20605 | var al5 = a5 & 0x1fff; | ||
20606 | var ah5 = a5 >>> 13; | ||
20607 | var a6 = a[6] | 0; | ||
20608 | var al6 = a6 & 0x1fff; | ||
20609 | var ah6 = a6 >>> 13; | ||
20610 | var a7 = a[7] | 0; | ||
20611 | var al7 = a7 & 0x1fff; | ||
20612 | var ah7 = a7 >>> 13; | ||
20613 | var a8 = a[8] | 0; | ||
20614 | var al8 = a8 & 0x1fff; | ||
20615 | var ah8 = a8 >>> 13; | ||
20616 | var a9 = a[9] | 0; | ||
20617 | var al9 = a9 & 0x1fff; | ||
20618 | var ah9 = a9 >>> 13; | ||
20619 | var b0 = b[0] | 0; | ||
20620 | var bl0 = b0 & 0x1fff; | ||
20621 | var bh0 = b0 >>> 13; | ||
20622 | var b1 = b[1] | 0; | ||
20623 | var bl1 = b1 & 0x1fff; | ||
20624 | var bh1 = b1 >>> 13; | ||
20625 | var b2 = b[2] | 0; | ||
20626 | var bl2 = b2 & 0x1fff; | ||
20627 | var bh2 = b2 >>> 13; | ||
20628 | var b3 = b[3] | 0; | ||
20629 | var bl3 = b3 & 0x1fff; | ||
20630 | var bh3 = b3 >>> 13; | ||
20631 | var b4 = b[4] | 0; | ||
20632 | var bl4 = b4 & 0x1fff; | ||
20633 | var bh4 = b4 >>> 13; | ||
20634 | var b5 = b[5] | 0; | ||
20635 | var bl5 = b5 & 0x1fff; | ||
20636 | var bh5 = b5 >>> 13; | ||
20637 | var b6 = b[6] | 0; | ||
20638 | var bl6 = b6 & 0x1fff; | ||
20639 | var bh6 = b6 >>> 13; | ||
20640 | var b7 = b[7] | 0; | ||
20641 | var bl7 = b7 & 0x1fff; | ||
20642 | var bh7 = b7 >>> 13; | ||
20643 | var b8 = b[8] | 0; | ||
20644 | var bl8 = b8 & 0x1fff; | ||
20645 | var bh8 = b8 >>> 13; | ||
20646 | var b9 = b[9] | 0; | ||
20647 | var bl9 = b9 & 0x1fff; | ||
20648 | var bh9 = b9 >>> 13; | ||
20649 | |||
20650 | out.negative = self.negative ^ num.negative; | ||
20651 | out.length = 19; | ||
20652 | /* k = 0 */ | ||
20653 | lo = Math.imul(al0, bl0); | ||
20654 | mid = Math.imul(al0, bh0); | ||
20655 | mid = (mid + Math.imul(ah0, bl0)) | 0; | ||
20656 | hi = Math.imul(ah0, bh0); | ||
20657 | var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20658 | c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0; | ||
20659 | w0 &= 0x3ffffff; | ||
20660 | /* k = 1 */ | ||
20661 | lo = Math.imul(al1, bl0); | ||
20662 | mid = Math.imul(al1, bh0); | ||
20663 | mid = (mid + Math.imul(ah1, bl0)) | 0; | ||
20664 | hi = Math.imul(ah1, bh0); | ||
20665 | lo = (lo + Math.imul(al0, bl1)) | 0; | ||
20666 | mid = (mid + Math.imul(al0, bh1)) | 0; | ||
20667 | mid = (mid + Math.imul(ah0, bl1)) | 0; | ||
20668 | hi = (hi + Math.imul(ah0, bh1)) | 0; | ||
20669 | var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20670 | c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0; | ||
20671 | w1 &= 0x3ffffff; | ||
20672 | /* k = 2 */ | ||
20673 | lo = Math.imul(al2, bl0); | ||
20674 | mid = Math.imul(al2, bh0); | ||
20675 | mid = (mid + Math.imul(ah2, bl0)) | 0; | ||
20676 | hi = Math.imul(ah2, bh0); | ||
20677 | lo = (lo + Math.imul(al1, bl1)) | 0; | ||
20678 | mid = (mid + Math.imul(al1, bh1)) | 0; | ||
20679 | mid = (mid + Math.imul(ah1, bl1)) | 0; | ||
20680 | hi = (hi + Math.imul(ah1, bh1)) | 0; | ||
20681 | lo = (lo + Math.imul(al0, bl2)) | 0; | ||
20682 | mid = (mid + Math.imul(al0, bh2)) | 0; | ||
20683 | mid = (mid + Math.imul(ah0, bl2)) | 0; | ||
20684 | hi = (hi + Math.imul(ah0, bh2)) | 0; | ||
20685 | var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20686 | c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0; | ||
20687 | w2 &= 0x3ffffff; | ||
20688 | /* k = 3 */ | ||
20689 | lo = Math.imul(al3, bl0); | ||
20690 | mid = Math.imul(al3, bh0); | ||
20691 | mid = (mid + Math.imul(ah3, bl0)) | 0; | ||
20692 | hi = Math.imul(ah3, bh0); | ||
20693 | lo = (lo + Math.imul(al2, bl1)) | 0; | ||
20694 | mid = (mid + Math.imul(al2, bh1)) | 0; | ||
20695 | mid = (mid + Math.imul(ah2, bl1)) | 0; | ||
20696 | hi = (hi + Math.imul(ah2, bh1)) | 0; | ||
20697 | lo = (lo + Math.imul(al1, bl2)) | 0; | ||
20698 | mid = (mid + Math.imul(al1, bh2)) | 0; | ||
20699 | mid = (mid + Math.imul(ah1, bl2)) | 0; | ||
20700 | hi = (hi + Math.imul(ah1, bh2)) | 0; | ||
20701 | lo = (lo + Math.imul(al0, bl3)) | 0; | ||
20702 | mid = (mid + Math.imul(al0, bh3)) | 0; | ||
20703 | mid = (mid + Math.imul(ah0, bl3)) | 0; | ||
20704 | hi = (hi + Math.imul(ah0, bh3)) | 0; | ||
20705 | var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20706 | c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0; | ||
20707 | w3 &= 0x3ffffff; | ||
20708 | /* k = 4 */ | ||
20709 | lo = Math.imul(al4, bl0); | ||
20710 | mid = Math.imul(al4, bh0); | ||
20711 | mid = (mid + Math.imul(ah4, bl0)) | 0; | ||
20712 | hi = Math.imul(ah4, bh0); | ||
20713 | lo = (lo + Math.imul(al3, bl1)) | 0; | ||
20714 | mid = (mid + Math.imul(al3, bh1)) | 0; | ||
20715 | mid = (mid + Math.imul(ah3, bl1)) | 0; | ||
20716 | hi = (hi + Math.imul(ah3, bh1)) | 0; | ||
20717 | lo = (lo + Math.imul(al2, bl2)) | 0; | ||
20718 | mid = (mid + Math.imul(al2, bh2)) | 0; | ||
20719 | mid = (mid + Math.imul(ah2, bl2)) | 0; | ||
20720 | hi = (hi + Math.imul(ah2, bh2)) | 0; | ||
20721 | lo = (lo + Math.imul(al1, bl3)) | 0; | ||
20722 | mid = (mid + Math.imul(al1, bh3)) | 0; | ||
20723 | mid = (mid + Math.imul(ah1, bl3)) | 0; | ||
20724 | hi = (hi + Math.imul(ah1, bh3)) | 0; | ||
20725 | lo = (lo + Math.imul(al0, bl4)) | 0; | ||
20726 | mid = (mid + Math.imul(al0, bh4)) | 0; | ||
20727 | mid = (mid + Math.imul(ah0, bl4)) | 0; | ||
20728 | hi = (hi + Math.imul(ah0, bh4)) | 0; | ||
20729 | var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20730 | c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0; | ||
20731 | w4 &= 0x3ffffff; | ||
20732 | /* k = 5 */ | ||
20733 | lo = Math.imul(al5, bl0); | ||
20734 | mid = Math.imul(al5, bh0); | ||
20735 | mid = (mid + Math.imul(ah5, bl0)) | 0; | ||
20736 | hi = Math.imul(ah5, bh0); | ||
20737 | lo = (lo + Math.imul(al4, bl1)) | 0; | ||
20738 | mid = (mid + Math.imul(al4, bh1)) | 0; | ||
20739 | mid = (mid + Math.imul(ah4, bl1)) | 0; | ||
20740 | hi = (hi + Math.imul(ah4, bh1)) | 0; | ||
20741 | lo = (lo + Math.imul(al3, bl2)) | 0; | ||
20742 | mid = (mid + Math.imul(al3, bh2)) | 0; | ||
20743 | mid = (mid + Math.imul(ah3, bl2)) | 0; | ||
20744 | hi = (hi + Math.imul(ah3, bh2)) | 0; | ||
20745 | lo = (lo + Math.imul(al2, bl3)) | 0; | ||
20746 | mid = (mid + Math.imul(al2, bh3)) | 0; | ||
20747 | mid = (mid + Math.imul(ah2, bl3)) | 0; | ||
20748 | hi = (hi + Math.imul(ah2, bh3)) | 0; | ||
20749 | lo = (lo + Math.imul(al1, bl4)) | 0; | ||
20750 | mid = (mid + Math.imul(al1, bh4)) | 0; | ||
20751 | mid = (mid + Math.imul(ah1, bl4)) | 0; | ||
20752 | hi = (hi + Math.imul(ah1, bh4)) | 0; | ||
20753 | lo = (lo + Math.imul(al0, bl5)) | 0; | ||
20754 | mid = (mid + Math.imul(al0, bh5)) | 0; | ||
20755 | mid = (mid + Math.imul(ah0, bl5)) | 0; | ||
20756 | hi = (hi + Math.imul(ah0, bh5)) | 0; | ||
20757 | var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20758 | c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0; | ||
20759 | w5 &= 0x3ffffff; | ||
20760 | /* k = 6 */ | ||
20761 | lo = Math.imul(al6, bl0); | ||
20762 | mid = Math.imul(al6, bh0); | ||
20763 | mid = (mid + Math.imul(ah6, bl0)) | 0; | ||
20764 | hi = Math.imul(ah6, bh0); | ||
20765 | lo = (lo + Math.imul(al5, bl1)) | 0; | ||
20766 | mid = (mid + Math.imul(al5, bh1)) | 0; | ||
20767 | mid = (mid + Math.imul(ah5, bl1)) | 0; | ||
20768 | hi = (hi + Math.imul(ah5, bh1)) | 0; | ||
20769 | lo = (lo + Math.imul(al4, bl2)) | 0; | ||
20770 | mid = (mid + Math.imul(al4, bh2)) | 0; | ||
20771 | mid = (mid + Math.imul(ah4, bl2)) | 0; | ||
20772 | hi = (hi + Math.imul(ah4, bh2)) | 0; | ||
20773 | lo = (lo + Math.imul(al3, bl3)) | 0; | ||
20774 | mid = (mid + Math.imul(al3, bh3)) | 0; | ||
20775 | mid = (mid + Math.imul(ah3, bl3)) | 0; | ||
20776 | hi = (hi + Math.imul(ah3, bh3)) | 0; | ||
20777 | lo = (lo + Math.imul(al2, bl4)) | 0; | ||
20778 | mid = (mid + Math.imul(al2, bh4)) | 0; | ||
20779 | mid = (mid + Math.imul(ah2, bl4)) | 0; | ||
20780 | hi = (hi + Math.imul(ah2, bh4)) | 0; | ||
20781 | lo = (lo + Math.imul(al1, bl5)) | 0; | ||
20782 | mid = (mid + Math.imul(al1, bh5)) | 0; | ||
20783 | mid = (mid + Math.imul(ah1, bl5)) | 0; | ||
20784 | hi = (hi + Math.imul(ah1, bh5)) | 0; | ||
20785 | lo = (lo + Math.imul(al0, bl6)) | 0; | ||
20786 | mid = (mid + Math.imul(al0, bh6)) | 0; | ||
20787 | mid = (mid + Math.imul(ah0, bl6)) | 0; | ||
20788 | hi = (hi + Math.imul(ah0, bh6)) | 0; | ||
20789 | var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20790 | c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0; | ||
20791 | w6 &= 0x3ffffff; | ||
20792 | /* k = 7 */ | ||
20793 | lo = Math.imul(al7, bl0); | ||
20794 | mid = Math.imul(al7, bh0); | ||
20795 | mid = (mid + Math.imul(ah7, bl0)) | 0; | ||
20796 | hi = Math.imul(ah7, bh0); | ||
20797 | lo = (lo + Math.imul(al6, bl1)) | 0; | ||
20798 | mid = (mid + Math.imul(al6, bh1)) | 0; | ||
20799 | mid = (mid + Math.imul(ah6, bl1)) | 0; | ||
20800 | hi = (hi + Math.imul(ah6, bh1)) | 0; | ||
20801 | lo = (lo + Math.imul(al5, bl2)) | 0; | ||
20802 | mid = (mid + Math.imul(al5, bh2)) | 0; | ||
20803 | mid = (mid + Math.imul(ah5, bl2)) | 0; | ||
20804 | hi = (hi + Math.imul(ah5, bh2)) | 0; | ||
20805 | lo = (lo + Math.imul(al4, bl3)) | 0; | ||
20806 | mid = (mid + Math.imul(al4, bh3)) | 0; | ||
20807 | mid = (mid + Math.imul(ah4, bl3)) | 0; | ||
20808 | hi = (hi + Math.imul(ah4, bh3)) | 0; | ||
20809 | lo = (lo + Math.imul(al3, bl4)) | 0; | ||
20810 | mid = (mid + Math.imul(al3, bh4)) | 0; | ||
20811 | mid = (mid + Math.imul(ah3, bl4)) | 0; | ||
20812 | hi = (hi + Math.imul(ah3, bh4)) | 0; | ||
20813 | lo = (lo + Math.imul(al2, bl5)) | 0; | ||
20814 | mid = (mid + Math.imul(al2, bh5)) | 0; | ||
20815 | mid = (mid + Math.imul(ah2, bl5)) | 0; | ||
20816 | hi = (hi + Math.imul(ah2, bh5)) | 0; | ||
20817 | lo = (lo + Math.imul(al1, bl6)) | 0; | ||
20818 | mid = (mid + Math.imul(al1, bh6)) | 0; | ||
20819 | mid = (mid + Math.imul(ah1, bl6)) | 0; | ||
20820 | hi = (hi + Math.imul(ah1, bh6)) | 0; | ||
20821 | lo = (lo + Math.imul(al0, bl7)) | 0; | ||
20822 | mid = (mid + Math.imul(al0, bh7)) | 0; | ||
20823 | mid = (mid + Math.imul(ah0, bl7)) | 0; | ||
20824 | hi = (hi + Math.imul(ah0, bh7)) | 0; | ||
20825 | var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20826 | c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0; | ||
20827 | w7 &= 0x3ffffff; | ||
20828 | /* k = 8 */ | ||
20829 | lo = Math.imul(al8, bl0); | ||
20830 | mid = Math.imul(al8, bh0); | ||
20831 | mid = (mid + Math.imul(ah8, bl0)) | 0; | ||
20832 | hi = Math.imul(ah8, bh0); | ||
20833 | lo = (lo + Math.imul(al7, bl1)) | 0; | ||
20834 | mid = (mid + Math.imul(al7, bh1)) | 0; | ||
20835 | mid = (mid + Math.imul(ah7, bl1)) | 0; | ||
20836 | hi = (hi + Math.imul(ah7, bh1)) | 0; | ||
20837 | lo = (lo + Math.imul(al6, bl2)) | 0; | ||
20838 | mid = (mid + Math.imul(al6, bh2)) | 0; | ||
20839 | mid = (mid + Math.imul(ah6, bl2)) | 0; | ||
20840 | hi = (hi + Math.imul(ah6, bh2)) | 0; | ||
20841 | lo = (lo + Math.imul(al5, bl3)) | 0; | ||
20842 | mid = (mid + Math.imul(al5, bh3)) | 0; | ||
20843 | mid = (mid + Math.imul(ah5, bl3)) | 0; | ||
20844 | hi = (hi + Math.imul(ah5, bh3)) | 0; | ||
20845 | lo = (lo + Math.imul(al4, bl4)) | 0; | ||
20846 | mid = (mid + Math.imul(al4, bh4)) | 0; | ||
20847 | mid = (mid + Math.imul(ah4, bl4)) | 0; | ||
20848 | hi = (hi + Math.imul(ah4, bh4)) | 0; | ||
20849 | lo = (lo + Math.imul(al3, bl5)) | 0; | ||
20850 | mid = (mid + Math.imul(al3, bh5)) | 0; | ||
20851 | mid = (mid + Math.imul(ah3, bl5)) | 0; | ||
20852 | hi = (hi + Math.imul(ah3, bh5)) | 0; | ||
20853 | lo = (lo + Math.imul(al2, bl6)) | 0; | ||
20854 | mid = (mid + Math.imul(al2, bh6)) | 0; | ||
20855 | mid = (mid + Math.imul(ah2, bl6)) | 0; | ||
20856 | hi = (hi + Math.imul(ah2, bh6)) | 0; | ||
20857 | lo = (lo + Math.imul(al1, bl7)) | 0; | ||
20858 | mid = (mid + Math.imul(al1, bh7)) | 0; | ||
20859 | mid = (mid + Math.imul(ah1, bl7)) | 0; | ||
20860 | hi = (hi + Math.imul(ah1, bh7)) | 0; | ||
20861 | lo = (lo + Math.imul(al0, bl8)) | 0; | ||
20862 | mid = (mid + Math.imul(al0, bh8)) | 0; | ||
20863 | mid = (mid + Math.imul(ah0, bl8)) | 0; | ||
20864 | hi = (hi + Math.imul(ah0, bh8)) | 0; | ||
20865 | var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20866 | c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0; | ||
20867 | w8 &= 0x3ffffff; | ||
20868 | /* k = 9 */ | ||
20869 | lo = Math.imul(al9, bl0); | ||
20870 | mid = Math.imul(al9, bh0); | ||
20871 | mid = (mid + Math.imul(ah9, bl0)) | 0; | ||
20872 | hi = Math.imul(ah9, bh0); | ||
20873 | lo = (lo + Math.imul(al8, bl1)) | 0; | ||
20874 | mid = (mid + Math.imul(al8, bh1)) | 0; | ||
20875 | mid = (mid + Math.imul(ah8, bl1)) | 0; | ||
20876 | hi = (hi + Math.imul(ah8, bh1)) | 0; | ||
20877 | lo = (lo + Math.imul(al7, bl2)) | 0; | ||
20878 | mid = (mid + Math.imul(al7, bh2)) | 0; | ||
20879 | mid = (mid + Math.imul(ah7, bl2)) | 0; | ||
20880 | hi = (hi + Math.imul(ah7, bh2)) | 0; | ||
20881 | lo = (lo + Math.imul(al6, bl3)) | 0; | ||
20882 | mid = (mid + Math.imul(al6, bh3)) | 0; | ||
20883 | mid = (mid + Math.imul(ah6, bl3)) | 0; | ||
20884 | hi = (hi + Math.imul(ah6, bh3)) | 0; | ||
20885 | lo = (lo + Math.imul(al5, bl4)) | 0; | ||
20886 | mid = (mid + Math.imul(al5, bh4)) | 0; | ||
20887 | mid = (mid + Math.imul(ah5, bl4)) | 0; | ||
20888 | hi = (hi + Math.imul(ah5, bh4)) | 0; | ||
20889 | lo = (lo + Math.imul(al4, bl5)) | 0; | ||
20890 | mid = (mid + Math.imul(al4, bh5)) | 0; | ||
20891 | mid = (mid + Math.imul(ah4, bl5)) | 0; | ||
20892 | hi = (hi + Math.imul(ah4, bh5)) | 0; | ||
20893 | lo = (lo + Math.imul(al3, bl6)) | 0; | ||
20894 | mid = (mid + Math.imul(al3, bh6)) | 0; | ||
20895 | mid = (mid + Math.imul(ah3, bl6)) | 0; | ||
20896 | hi = (hi + Math.imul(ah3, bh6)) | 0; | ||
20897 | lo = (lo + Math.imul(al2, bl7)) | 0; | ||
20898 | mid = (mid + Math.imul(al2, bh7)) | 0; | ||
20899 | mid = (mid + Math.imul(ah2, bl7)) | 0; | ||
20900 | hi = (hi + Math.imul(ah2, bh7)) | 0; | ||
20901 | lo = (lo + Math.imul(al1, bl8)) | 0; | ||
20902 | mid = (mid + Math.imul(al1, bh8)) | 0; | ||
20903 | mid = (mid + Math.imul(ah1, bl8)) | 0; | ||
20904 | hi = (hi + Math.imul(ah1, bh8)) | 0; | ||
20905 | lo = (lo + Math.imul(al0, bl9)) | 0; | ||
20906 | mid = (mid + Math.imul(al0, bh9)) | 0; | ||
20907 | mid = (mid + Math.imul(ah0, bl9)) | 0; | ||
20908 | hi = (hi + Math.imul(ah0, bh9)) | 0; | ||
20909 | var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20910 | c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0; | ||
20911 | w9 &= 0x3ffffff; | ||
20912 | /* k = 10 */ | ||
20913 | lo = Math.imul(al9, bl1); | ||
20914 | mid = Math.imul(al9, bh1); | ||
20915 | mid = (mid + Math.imul(ah9, bl1)) | 0; | ||
20916 | hi = Math.imul(ah9, bh1); | ||
20917 | lo = (lo + Math.imul(al8, bl2)) | 0; | ||
20918 | mid = (mid + Math.imul(al8, bh2)) | 0; | ||
20919 | mid = (mid + Math.imul(ah8, bl2)) | 0; | ||
20920 | hi = (hi + Math.imul(ah8, bh2)) | 0; | ||
20921 | lo = (lo + Math.imul(al7, bl3)) | 0; | ||
20922 | mid = (mid + Math.imul(al7, bh3)) | 0; | ||
20923 | mid = (mid + Math.imul(ah7, bl3)) | 0; | ||
20924 | hi = (hi + Math.imul(ah7, bh3)) | 0; | ||
20925 | lo = (lo + Math.imul(al6, bl4)) | 0; | ||
20926 | mid = (mid + Math.imul(al6, bh4)) | 0; | ||
20927 | mid = (mid + Math.imul(ah6, bl4)) | 0; | ||
20928 | hi = (hi + Math.imul(ah6, bh4)) | 0; | ||
20929 | lo = (lo + Math.imul(al5, bl5)) | 0; | ||
20930 | mid = (mid + Math.imul(al5, bh5)) | 0; | ||
20931 | mid = (mid + Math.imul(ah5, bl5)) | 0; | ||
20932 | hi = (hi + Math.imul(ah5, bh5)) | 0; | ||
20933 | lo = (lo + Math.imul(al4, bl6)) | 0; | ||
20934 | mid = (mid + Math.imul(al4, bh6)) | 0; | ||
20935 | mid = (mid + Math.imul(ah4, bl6)) | 0; | ||
20936 | hi = (hi + Math.imul(ah4, bh6)) | 0; | ||
20937 | lo = (lo + Math.imul(al3, bl7)) | 0; | ||
20938 | mid = (mid + Math.imul(al3, bh7)) | 0; | ||
20939 | mid = (mid + Math.imul(ah3, bl7)) | 0; | ||
20940 | hi = (hi + Math.imul(ah3, bh7)) | 0; | ||
20941 | lo = (lo + Math.imul(al2, bl8)) | 0; | ||
20942 | mid = (mid + Math.imul(al2, bh8)) | 0; | ||
20943 | mid = (mid + Math.imul(ah2, bl8)) | 0; | ||
20944 | hi = (hi + Math.imul(ah2, bh8)) | 0; | ||
20945 | lo = (lo + Math.imul(al1, bl9)) | 0; | ||
20946 | mid = (mid + Math.imul(al1, bh9)) | 0; | ||
20947 | mid = (mid + Math.imul(ah1, bl9)) | 0; | ||
20948 | hi = (hi + Math.imul(ah1, bh9)) | 0; | ||
20949 | var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20950 | c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0; | ||
20951 | w10 &= 0x3ffffff; | ||
20952 | /* k = 11 */ | ||
20953 | lo = Math.imul(al9, bl2); | ||
20954 | mid = Math.imul(al9, bh2); | ||
20955 | mid = (mid + Math.imul(ah9, bl2)) | 0; | ||
20956 | hi = Math.imul(ah9, bh2); | ||
20957 | lo = (lo + Math.imul(al8, bl3)) | 0; | ||
20958 | mid = (mid + Math.imul(al8, bh3)) | 0; | ||
20959 | mid = (mid + Math.imul(ah8, bl3)) | 0; | ||
20960 | hi = (hi + Math.imul(ah8, bh3)) | 0; | ||
20961 | lo = (lo + Math.imul(al7, bl4)) | 0; | ||
20962 | mid = (mid + Math.imul(al7, bh4)) | 0; | ||
20963 | mid = (mid + Math.imul(ah7, bl4)) | 0; | ||
20964 | hi = (hi + Math.imul(ah7, bh4)) | 0; | ||
20965 | lo = (lo + Math.imul(al6, bl5)) | 0; | ||
20966 | mid = (mid + Math.imul(al6, bh5)) | 0; | ||
20967 | mid = (mid + Math.imul(ah6, bl5)) | 0; | ||
20968 | hi = (hi + Math.imul(ah6, bh5)) | 0; | ||
20969 | lo = (lo + Math.imul(al5, bl6)) | 0; | ||
20970 | mid = (mid + Math.imul(al5, bh6)) | 0; | ||
20971 | mid = (mid + Math.imul(ah5, bl6)) | 0; | ||
20972 | hi = (hi + Math.imul(ah5, bh6)) | 0; | ||
20973 | lo = (lo + Math.imul(al4, bl7)) | 0; | ||
20974 | mid = (mid + Math.imul(al4, bh7)) | 0; | ||
20975 | mid = (mid + Math.imul(ah4, bl7)) | 0; | ||
20976 | hi = (hi + Math.imul(ah4, bh7)) | 0; | ||
20977 | lo = (lo + Math.imul(al3, bl8)) | 0; | ||
20978 | mid = (mid + Math.imul(al3, bh8)) | 0; | ||
20979 | mid = (mid + Math.imul(ah3, bl8)) | 0; | ||
20980 | hi = (hi + Math.imul(ah3, bh8)) | 0; | ||
20981 | lo = (lo + Math.imul(al2, bl9)) | 0; | ||
20982 | mid = (mid + Math.imul(al2, bh9)) | 0; | ||
20983 | mid = (mid + Math.imul(ah2, bl9)) | 0; | ||
20984 | hi = (hi + Math.imul(ah2, bh9)) | 0; | ||
20985 | var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
20986 | c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0; | ||
20987 | w11 &= 0x3ffffff; | ||
20988 | /* k = 12 */ | ||
20989 | lo = Math.imul(al9, bl3); | ||
20990 | mid = Math.imul(al9, bh3); | ||
20991 | mid = (mid + Math.imul(ah9, bl3)) | 0; | ||
20992 | hi = Math.imul(ah9, bh3); | ||
20993 | lo = (lo + Math.imul(al8, bl4)) | 0; | ||
20994 | mid = (mid + Math.imul(al8, bh4)) | 0; | ||
20995 | mid = (mid + Math.imul(ah8, bl4)) | 0; | ||
20996 | hi = (hi + Math.imul(ah8, bh4)) | 0; | ||
20997 | lo = (lo + Math.imul(al7, bl5)) | 0; | ||
20998 | mid = (mid + Math.imul(al7, bh5)) | 0; | ||
20999 | mid = (mid + Math.imul(ah7, bl5)) | 0; | ||
21000 | hi = (hi + Math.imul(ah7, bh5)) | 0; | ||
21001 | lo = (lo + Math.imul(al6, bl6)) | 0; | ||
21002 | mid = (mid + Math.imul(al6, bh6)) | 0; | ||
21003 | mid = (mid + Math.imul(ah6, bl6)) | 0; | ||
21004 | hi = (hi + Math.imul(ah6, bh6)) | 0; | ||
21005 | lo = (lo + Math.imul(al5, bl7)) | 0; | ||
21006 | mid = (mid + Math.imul(al5, bh7)) | 0; | ||
21007 | mid = (mid + Math.imul(ah5, bl7)) | 0; | ||
21008 | hi = (hi + Math.imul(ah5, bh7)) | 0; | ||
21009 | lo = (lo + Math.imul(al4, bl8)) | 0; | ||
21010 | mid = (mid + Math.imul(al4, bh8)) | 0; | ||
21011 | mid = (mid + Math.imul(ah4, bl8)) | 0; | ||
21012 | hi = (hi + Math.imul(ah4, bh8)) | 0; | ||
21013 | lo = (lo + Math.imul(al3, bl9)) | 0; | ||
21014 | mid = (mid + Math.imul(al3, bh9)) | 0; | ||
21015 | mid = (mid + Math.imul(ah3, bl9)) | 0; | ||
21016 | hi = (hi + Math.imul(ah3, bh9)) | 0; | ||
21017 | var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21018 | c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0; | ||
21019 | w12 &= 0x3ffffff; | ||
21020 | /* k = 13 */ | ||
21021 | lo = Math.imul(al9, bl4); | ||
21022 | mid = Math.imul(al9, bh4); | ||
21023 | mid = (mid + Math.imul(ah9, bl4)) | 0; | ||
21024 | hi = Math.imul(ah9, bh4); | ||
21025 | lo = (lo + Math.imul(al8, bl5)) | 0; | ||
21026 | mid = (mid + Math.imul(al8, bh5)) | 0; | ||
21027 | mid = (mid + Math.imul(ah8, bl5)) | 0; | ||
21028 | hi = (hi + Math.imul(ah8, bh5)) | 0; | ||
21029 | lo = (lo + Math.imul(al7, bl6)) | 0; | ||
21030 | mid = (mid + Math.imul(al7, bh6)) | 0; | ||
21031 | mid = (mid + Math.imul(ah7, bl6)) | 0; | ||
21032 | hi = (hi + Math.imul(ah7, bh6)) | 0; | ||
21033 | lo = (lo + Math.imul(al6, bl7)) | 0; | ||
21034 | mid = (mid + Math.imul(al6, bh7)) | 0; | ||
21035 | mid = (mid + Math.imul(ah6, bl7)) | 0; | ||
21036 | hi = (hi + Math.imul(ah6, bh7)) | 0; | ||
21037 | lo = (lo + Math.imul(al5, bl8)) | 0; | ||
21038 | mid = (mid + Math.imul(al5, bh8)) | 0; | ||
21039 | mid = (mid + Math.imul(ah5, bl8)) | 0; | ||
21040 | hi = (hi + Math.imul(ah5, bh8)) | 0; | ||
21041 | lo = (lo + Math.imul(al4, bl9)) | 0; | ||
21042 | mid = (mid + Math.imul(al4, bh9)) | 0; | ||
21043 | mid = (mid + Math.imul(ah4, bl9)) | 0; | ||
21044 | hi = (hi + Math.imul(ah4, bh9)) | 0; | ||
21045 | var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21046 | c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0; | ||
21047 | w13 &= 0x3ffffff; | ||
21048 | /* k = 14 */ | ||
21049 | lo = Math.imul(al9, bl5); | ||
21050 | mid = Math.imul(al9, bh5); | ||
21051 | mid = (mid + Math.imul(ah9, bl5)) | 0; | ||
21052 | hi = Math.imul(ah9, bh5); | ||
21053 | lo = (lo + Math.imul(al8, bl6)) | 0; | ||
21054 | mid = (mid + Math.imul(al8, bh6)) | 0; | ||
21055 | mid = (mid + Math.imul(ah8, bl6)) | 0; | ||
21056 | hi = (hi + Math.imul(ah8, bh6)) | 0; | ||
21057 | lo = (lo + Math.imul(al7, bl7)) | 0; | ||
21058 | mid = (mid + Math.imul(al7, bh7)) | 0; | ||
21059 | mid = (mid + Math.imul(ah7, bl7)) | 0; | ||
21060 | hi = (hi + Math.imul(ah7, bh7)) | 0; | ||
21061 | lo = (lo + Math.imul(al6, bl8)) | 0; | ||
21062 | mid = (mid + Math.imul(al6, bh8)) | 0; | ||
21063 | mid = (mid + Math.imul(ah6, bl8)) | 0; | ||
21064 | hi = (hi + Math.imul(ah6, bh8)) | 0; | ||
21065 | lo = (lo + Math.imul(al5, bl9)) | 0; | ||
21066 | mid = (mid + Math.imul(al5, bh9)) | 0; | ||
21067 | mid = (mid + Math.imul(ah5, bl9)) | 0; | ||
21068 | hi = (hi + Math.imul(ah5, bh9)) | 0; | ||
21069 | var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21070 | c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0; | ||
21071 | w14 &= 0x3ffffff; | ||
21072 | /* k = 15 */ | ||
21073 | lo = Math.imul(al9, bl6); | ||
21074 | mid = Math.imul(al9, bh6); | ||
21075 | mid = (mid + Math.imul(ah9, bl6)) | 0; | ||
21076 | hi = Math.imul(ah9, bh6); | ||
21077 | lo = (lo + Math.imul(al8, bl7)) | 0; | ||
21078 | mid = (mid + Math.imul(al8, bh7)) | 0; | ||
21079 | mid = (mid + Math.imul(ah8, bl7)) | 0; | ||
21080 | hi = (hi + Math.imul(ah8, bh7)) | 0; | ||
21081 | lo = (lo + Math.imul(al7, bl8)) | 0; | ||
21082 | mid = (mid + Math.imul(al7, bh8)) | 0; | ||
21083 | mid = (mid + Math.imul(ah7, bl8)) | 0; | ||
21084 | hi = (hi + Math.imul(ah7, bh8)) | 0; | ||
21085 | lo = (lo + Math.imul(al6, bl9)) | 0; | ||
21086 | mid = (mid + Math.imul(al6, bh9)) | 0; | ||
21087 | mid = (mid + Math.imul(ah6, bl9)) | 0; | ||
21088 | hi = (hi + Math.imul(ah6, bh9)) | 0; | ||
21089 | var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21090 | c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0; | ||
21091 | w15 &= 0x3ffffff; | ||
21092 | /* k = 16 */ | ||
21093 | lo = Math.imul(al9, bl7); | ||
21094 | mid = Math.imul(al9, bh7); | ||
21095 | mid = (mid + Math.imul(ah9, bl7)) | 0; | ||
21096 | hi = Math.imul(ah9, bh7); | ||
21097 | lo = (lo + Math.imul(al8, bl8)) | 0; | ||
21098 | mid = (mid + Math.imul(al8, bh8)) | 0; | ||
21099 | mid = (mid + Math.imul(ah8, bl8)) | 0; | ||
21100 | hi = (hi + Math.imul(ah8, bh8)) | 0; | ||
21101 | lo = (lo + Math.imul(al7, bl9)) | 0; | ||
21102 | mid = (mid + Math.imul(al7, bh9)) | 0; | ||
21103 | mid = (mid + Math.imul(ah7, bl9)) | 0; | ||
21104 | hi = (hi + Math.imul(ah7, bh9)) | 0; | ||
21105 | var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21106 | c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0; | ||
21107 | w16 &= 0x3ffffff; | ||
21108 | /* k = 17 */ | ||
21109 | lo = Math.imul(al9, bl8); | ||
21110 | mid = Math.imul(al9, bh8); | ||
21111 | mid = (mid + Math.imul(ah9, bl8)) | 0; | ||
21112 | hi = Math.imul(ah9, bh8); | ||
21113 | lo = (lo + Math.imul(al8, bl9)) | 0; | ||
21114 | mid = (mid + Math.imul(al8, bh9)) | 0; | ||
21115 | mid = (mid + Math.imul(ah8, bl9)) | 0; | ||
21116 | hi = (hi + Math.imul(ah8, bh9)) | 0; | ||
21117 | var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21118 | c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0; | ||
21119 | w17 &= 0x3ffffff; | ||
21120 | /* k = 18 */ | ||
21121 | lo = Math.imul(al9, bl9); | ||
21122 | mid = Math.imul(al9, bh9); | ||
21123 | mid = (mid + Math.imul(ah9, bl9)) | 0; | ||
21124 | hi = Math.imul(ah9, bh9); | ||
21125 | var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; | ||
21126 | c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0; | ||
21127 | w18 &= 0x3ffffff; | ||
21128 | o[0] = w0; | ||
21129 | o[1] = w1; | ||
21130 | o[2] = w2; | ||
21131 | o[3] = w3; | ||
21132 | o[4] = w4; | ||
21133 | o[5] = w5; | ||
21134 | o[6] = w6; | ||
21135 | o[7] = w7; | ||
21136 | o[8] = w8; | ||
21137 | o[9] = w9; | ||
21138 | o[10] = w10; | ||
21139 | o[11] = w11; | ||
21140 | o[12] = w12; | ||
21141 | o[13] = w13; | ||
21142 | o[14] = w14; | ||
21143 | o[15] = w15; | ||
21144 | o[16] = w16; | ||
21145 | o[17] = w17; | ||
21146 | o[18] = w18; | ||
21147 | if (c !== 0) { | ||
21148 | o[19] = c; | ||
21149 | out.length++; | ||
21150 | } | ||
21151 | return out; | ||
21152 | }; | ||
21153 | |||
21154 | // Polyfill comb | ||
21155 | if (!Math.imul) { | ||
21156 | comb10MulTo = smallMulTo; | ||
21157 | } | ||
21158 | |||
21159 | function bigMulTo (self, num, out) { | ||
21160 | out.negative = num.negative ^ self.negative; | ||
21161 | out.length = self.length + num.length; | ||
21162 | |||
21163 | var carry = 0; | ||
21164 | var hncarry = 0; | ||
21165 | for (var k = 0; k < out.length - 1; k++) { | ||
21166 | // Sum all words with the same `i + j = k` and accumulate `ncarry`, | ||
21167 | // note that ncarry could be >= 0x3ffffff | ||
21168 | var ncarry = hncarry; | ||
21169 | hncarry = 0; | ||
21170 | var rword = carry & 0x3ffffff; | ||
21171 | var maxJ = Math.min(k, num.length - 1); | ||
21172 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { | ||
21173 | var i = k - j; | ||
21174 | var a = self.words[i] | 0; | ||
21175 | var b = num.words[j] | 0; | ||
21176 | var r = a * b; | ||
21177 | |||
21178 | var lo = r & 0x3ffffff; | ||
21179 | ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0; | ||
21180 | lo = (lo + rword) | 0; | ||
21181 | rword = lo & 0x3ffffff; | ||
21182 | ncarry = (ncarry + (lo >>> 26)) | 0; | ||
21183 | |||
21184 | hncarry += ncarry >>> 26; | ||
21185 | ncarry &= 0x3ffffff; | ||
21186 | } | ||
21187 | out.words[k] = rword; | ||
21188 | carry = ncarry; | ||
21189 | ncarry = hncarry; | ||
21190 | } | ||
21191 | if (carry !== 0) { | ||
21192 | out.words[k] = carry; | ||
21193 | } else { | ||
21194 | out.length--; | ||
21195 | } | ||
21196 | |||
21197 | return out.strip(); | ||
21198 | } | ||
21199 | |||
21200 | function jumboMulTo (self, num, out) { | ||
21201 | var fftm = new FFTM(); | ||
21202 | return fftm.mulp(self, num, out); | ||
21203 | } | ||
21204 | |||
21205 | BN.prototype.mulTo = function mulTo (num, out) { | ||
21206 | var res; | ||
21207 | var len = this.length + num.length; | ||
21208 | if (this.length === 10 && num.length === 10) { | ||
21209 | res = comb10MulTo(this, num, out); | ||
21210 | } else if (len < 63) { | ||
21211 | res = smallMulTo(this, num, out); | ||
21212 | } else if (len < 1024) { | ||
21213 | res = bigMulTo(this, num, out); | ||
21214 | } else { | ||
21215 | res = jumboMulTo(this, num, out); | ||
21216 | } | ||
21217 | |||
21218 | return res; | ||
21219 | }; | ||
21220 | |||
21221 | // Cooley-Tukey algorithm for FFT | ||
21222 | // slightly revisited to rely on looping instead of recursion | ||
21223 | |||
21224 | function FFTM (x, y) { | ||
21225 | this.x = x; | ||
21226 | this.y = y; | ||
21227 | } | ||
21228 | |||
21229 | FFTM.prototype.makeRBT = function makeRBT (N) { | ||
21230 | var t = new Array(N); | ||
21231 | var l = BN.prototype._countBits(N) - 1; | ||
21232 | for (var i = 0; i < N; i++) { | ||
21233 | t[i] = this.revBin(i, l, N); | ||
21234 | } | ||
21235 | |||
21236 | return t; | ||
21237 | }; | ||
21238 | |||
21239 | // Returns binary-reversed representation of `x` | ||
21240 | FFTM.prototype.revBin = function revBin (x, l, N) { | ||
21241 | if (x === 0 || x === N - 1) return x; | ||
21242 | |||
21243 | var rb = 0; | ||
21244 | for (var i = 0; i < l; i++) { | ||
21245 | rb |= (x & 1) << (l - i - 1); | ||
21246 | x >>= 1; | ||
21247 | } | ||
21248 | |||
21249 | return rb; | ||
21250 | }; | ||
21251 | |||
21252 | // Performs "tweedling" phase, therefore 'emulating' | ||
21253 | // behaviour of the recursive algorithm | ||
21254 | FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) { | ||
21255 | for (var i = 0; i < N; i++) { | ||
21256 | rtws[i] = rws[rbt[i]]; | ||
21257 | itws[i] = iws[rbt[i]]; | ||
21258 | } | ||
21259 | }; | ||
21260 | |||
21261 | FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) { | ||
21262 | this.permute(rbt, rws, iws, rtws, itws, N); | ||
21263 | |||
21264 | for (var s = 1; s < N; s <<= 1) { | ||
21265 | var l = s << 1; | ||
21266 | |||
21267 | var rtwdf = Math.cos(2 * Math.PI / l); | ||
21268 | var itwdf = Math.sin(2 * Math.PI / l); | ||
21269 | |||
21270 | for (var p = 0; p < N; p += l) { | ||
21271 | var rtwdf_ = rtwdf; | ||
21272 | var itwdf_ = itwdf; | ||
21273 | |||
21274 | for (var j = 0; j < s; j++) { | ||
21275 | var re = rtws[p + j]; | ||
21276 | var ie = itws[p + j]; | ||
21277 | |||
21278 | var ro = rtws[p + j + s]; | ||
21279 | var io = itws[p + j + s]; | ||
21280 | |||
21281 | var rx = rtwdf_ * ro - itwdf_ * io; | ||
21282 | |||
21283 | io = rtwdf_ * io + itwdf_ * ro; | ||
21284 | ro = rx; | ||
21285 | |||
21286 | rtws[p + j] = re + ro; | ||
21287 | itws[p + j] = ie + io; | ||
21288 | |||
21289 | rtws[p + j + s] = re - ro; | ||
21290 | itws[p + j + s] = ie - io; | ||
21291 | |||
21292 | /* jshint maxdepth : false */ | ||
21293 | if (j !== l) { | ||
21294 | rx = rtwdf * rtwdf_ - itwdf * itwdf_; | ||
21295 | |||
21296 | itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; | ||
21297 | rtwdf_ = rx; | ||
21298 | } | ||
21299 | } | ||
21300 | } | ||
21301 | } | ||
21302 | }; | ||
21303 | |||
21304 | FFTM.prototype.guessLen13b = function guessLen13b (n, m) { | ||
21305 | var N = Math.max(m, n) | 1; | ||
21306 | var odd = N & 1; | ||
21307 | var i = 0; | ||
21308 | for (N = N / 2 | 0; N; N = N >>> 1) { | ||
21309 | i++; | ||
21310 | } | ||
21311 | |||
21312 | return 1 << i + 1 + odd; | ||
21313 | }; | ||
21314 | |||
21315 | FFTM.prototype.conjugate = function conjugate (rws, iws, N) { | ||
21316 | if (N <= 1) return; | ||
21317 | |||
21318 | for (var i = 0; i < N / 2; i++) { | ||
21319 | var t = rws[i]; | ||
21320 | |||
21321 | rws[i] = rws[N - i - 1]; | ||
21322 | rws[N - i - 1] = t; | ||
21323 | |||
21324 | t = iws[i]; | ||
21325 | |||
21326 | iws[i] = -iws[N - i - 1]; | ||
21327 | iws[N - i - 1] = -t; | ||
21328 | } | ||
21329 | }; | ||
21330 | |||
21331 | FFTM.prototype.normalize13b = function normalize13b (ws, N) { | ||
21332 | var carry = 0; | ||
21333 | for (var i = 0; i < N / 2; i++) { | ||
21334 | var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + | ||
21335 | Math.round(ws[2 * i] / N) + | ||
21336 | carry; | ||
21337 | |||
21338 | ws[i] = w & 0x3ffffff; | ||
21339 | |||
21340 | if (w < 0x4000000) { | ||
21341 | carry = 0; | ||
21342 | } else { | ||
21343 | carry = w / 0x4000000 | 0; | ||
21344 | } | ||
21345 | } | ||
21346 | |||
21347 | return ws; | ||
21348 | }; | ||
21349 | |||
21350 | FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) { | ||
21351 | var carry = 0; | ||
21352 | for (var i = 0; i < len; i++) { | ||
21353 | carry = carry + (ws[i] | 0); | ||
21354 | |||
21355 | rws[2 * i] = carry & 0x1fff; carry = carry >>> 13; | ||
21356 | rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13; | ||
21357 | } | ||
21358 | |||
21359 | // Pad with zeroes | ||
21360 | for (i = 2 * len; i < N; ++i) { | ||
21361 | rws[i] = 0; | ||
21362 | } | ||
21363 | |||
21364 | assert(carry === 0); | ||
21365 | assert((carry & ~0x1fff) === 0); | ||
21366 | }; | ||
21367 | |||
21368 | FFTM.prototype.stub = function stub (N) { | ||
21369 | var ph = new Array(N); | ||
21370 | for (var i = 0; i < N; i++) { | ||
21371 | ph[i] = 0; | ||
21372 | } | ||
21373 | |||
21374 | return ph; | ||
21375 | }; | ||
21376 | |||
21377 | FFTM.prototype.mulp = function mulp (x, y, out) { | ||
21378 | var N = 2 * this.guessLen13b(x.length, y.length); | ||
21379 | |||
21380 | var rbt = this.makeRBT(N); | ||
21381 | |||
21382 | var _ = this.stub(N); | ||
21383 | |||
21384 | var rws = new Array(N); | ||
21385 | var rwst = new Array(N); | ||
21386 | var iwst = new Array(N); | ||
21387 | |||
21388 | var nrws = new Array(N); | ||
21389 | var nrwst = new Array(N); | ||
21390 | var niwst = new Array(N); | ||
21391 | |||
21392 | var rmws = out.words; | ||
21393 | rmws.length = N; | ||
21394 | |||
21395 | this.convert13b(x.words, x.length, rws, N); | ||
21396 | this.convert13b(y.words, y.length, nrws, N); | ||
21397 | |||
21398 | this.transform(rws, _, rwst, iwst, N, rbt); | ||
21399 | this.transform(nrws, _, nrwst, niwst, N, rbt); | ||
21400 | |||
21401 | for (var i = 0; i < N; i++) { | ||
21402 | var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; | ||
21403 | iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; | ||
21404 | rwst[i] = rx; | ||
21405 | } | ||
21406 | |||
21407 | this.conjugate(rwst, iwst, N); | ||
21408 | this.transform(rwst, iwst, rmws, _, N, rbt); | ||
21409 | this.conjugate(rmws, _, N); | ||
21410 | this.normalize13b(rmws, N); | ||
21411 | |||
21412 | out.negative = x.negative ^ y.negative; | ||
21413 | out.length = x.length + y.length; | ||
21414 | return out.strip(); | ||
21415 | }; | ||
21416 | |||
21417 | // Multiply `this` by `num` | ||
21418 | BN.prototype.mul = function mul (num) { | ||
21419 | var out = new BN(null); | ||
21420 | out.words = new Array(this.length + num.length); | ||
21421 | return this.mulTo(num, out); | ||
21422 | }; | ||
21423 | |||
21424 | // Multiply employing FFT | ||
21425 | BN.prototype.mulf = function mulf (num) { | ||
21426 | var out = new BN(null); | ||
21427 | out.words = new Array(this.length + num.length); | ||
21428 | return jumboMulTo(this, num, out); | ||
21429 | }; | ||
21430 | |||
21431 | // In-place Multiplication | ||
21432 | BN.prototype.imul = function imul (num) { | ||
21433 | return this.clone().mulTo(num, this); | ||
21434 | }; | ||
21435 | |||
21436 | BN.prototype.imuln = function imuln (num) { | ||
21437 | assert(typeof num === 'number'); | ||
21438 | assert(num < 0x4000000); | ||
21439 | |||
21440 | // Carry | ||
21441 | var carry = 0; | ||
21442 | for (var i = 0; i < this.length; i++) { | ||
21443 | var w = (this.words[i] | 0) * num; | ||
21444 | var lo = (w & 0x3ffffff) + (carry & 0x3ffffff); | ||
21445 | carry >>= 26; | ||
21446 | carry += (w / 0x4000000) | 0; | ||
21447 | // NOTE: lo is 27bit maximum | ||
21448 | carry += lo >>> 26; | ||
21449 | this.words[i] = lo & 0x3ffffff; | ||
21450 | } | ||
21451 | |||
21452 | if (carry !== 0) { | ||
21453 | this.words[i] = carry; | ||
21454 | this.length++; | ||
21455 | } | ||
21456 | |||
21457 | return this; | ||
21458 | }; | ||
21459 | |||
21460 | BN.prototype.muln = function muln (num) { | ||
21461 | return this.clone().imuln(num); | ||
21462 | }; | ||
21463 | |||
21464 | // `this` * `this` | ||
21465 | BN.prototype.sqr = function sqr () { | ||
21466 | return this.mul(this); | ||
21467 | }; | ||
21468 | |||
21469 | // `this` * `this` in-place | ||
21470 | BN.prototype.isqr = function isqr () { | ||
21471 | return this.imul(this.clone()); | ||
21472 | }; | ||
21473 | |||
21474 | // Math.pow(`this`, `num`) | ||
21475 | BN.prototype.pow = function pow (num) { | ||
21476 | var w = toBitArray(num); | ||
21477 | if (w.length === 0) return new BN(1); | ||
21478 | |||
21479 | // Skip leading zeroes | ||
21480 | var res = this; | ||
21481 | for (var i = 0; i < w.length; i++, res = res.sqr()) { | ||
21482 | if (w[i] !== 0) break; | ||
21483 | } | ||
21484 | |||
21485 | if (++i < w.length) { | ||
21486 | for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { | ||
21487 | if (w[i] === 0) continue; | ||
21488 | |||
21489 | res = res.mul(q); | ||
21490 | } | ||
21491 | } | ||
21492 | |||
21493 | return res; | ||
21494 | }; | ||
21495 | |||
21496 | // Shift-left in-place | ||
21497 | BN.prototype.iushln = function iushln (bits) { | ||
21498 | assert(typeof bits === 'number' && bits >= 0); | ||
21499 | var r = bits % 26; | ||
21500 | var s = (bits - r) / 26; | ||
21501 | var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r); | ||
21502 | var i; | ||
21503 | |||
21504 | if (r !== 0) { | ||
21505 | var carry = 0; | ||
21506 | |||
21507 | for (i = 0; i < this.length; i++) { | ||
21508 | var newCarry = this.words[i] & carryMask; | ||
21509 | var c = ((this.words[i] | 0) - newCarry) << r; | ||
21510 | this.words[i] = c | carry; | ||
21511 | carry = newCarry >>> (26 - r); | ||
21512 | } | ||
21513 | |||
21514 | if (carry) { | ||
21515 | this.words[i] = carry; | ||
21516 | this.length++; | ||
21517 | } | ||
21518 | } | ||
21519 | |||
21520 | if (s !== 0) { | ||
21521 | for (i = this.length - 1; i >= 0; i--) { | ||
21522 | this.words[i + s] = this.words[i]; | ||
21523 | } | ||
21524 | |||
21525 | for (i = 0; i < s; i++) { | ||
21526 | this.words[i] = 0; | ||
21527 | } | ||
21528 | |||
21529 | this.length += s; | ||
21530 | } | ||
21531 | |||
21532 | return this.strip(); | ||
21533 | }; | ||
21534 | |||
21535 | BN.prototype.ishln = function ishln (bits) { | ||
21536 | // TODO(indutny): implement me | ||
21537 | assert(this.negative === 0); | ||
21538 | return this.iushln(bits); | ||
21539 | }; | ||
21540 | |||
21541 | // Shift-right in-place | ||
21542 | // NOTE: `hint` is a lowest bit before trailing zeroes | ||
21543 | // NOTE: if `extended` is present - it will be filled with destroyed bits | ||
21544 | BN.prototype.iushrn = function iushrn (bits, hint, extended) { | ||
21545 | assert(typeof bits === 'number' && bits >= 0); | ||
21546 | var h; | ||
21547 | if (hint) { | ||
21548 | h = (hint - (hint % 26)) / 26; | ||
21549 | } else { | ||
21550 | h = 0; | ||
21551 | } | ||
21552 | |||
21553 | var r = bits % 26; | ||
21554 | var s = Math.min((bits - r) / 26, this.length); | ||
21555 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); | ||
21556 | var maskedWords = extended; | ||
21557 | |||
21558 | h -= s; | ||
21559 | h = Math.max(0, h); | ||
21560 | |||
21561 | // Extended mode, copy masked part | ||
21562 | if (maskedWords) { | ||
21563 | for (var i = 0; i < s; i++) { | ||
21564 | maskedWords.words[i] = this.words[i]; | ||
21565 | } | ||
21566 | maskedWords.length = s; | ||
21567 | } | ||
21568 | |||
21569 | if (s === 0) { | ||
21570 | // No-op, we should not move anything at all | ||
21571 | } else if (this.length > s) { | ||
21572 | this.length -= s; | ||
21573 | for (i = 0; i < this.length; i++) { | ||
21574 | this.words[i] = this.words[i + s]; | ||
21575 | } | ||
21576 | } else { | ||
21577 | this.words[0] = 0; | ||
21578 | this.length = 1; | ||
21579 | } | ||
21580 | |||
21581 | var carry = 0; | ||
21582 | for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { | ||
21583 | var word = this.words[i] | 0; | ||
21584 | this.words[i] = (carry << (26 - r)) | (word >>> r); | ||
21585 | carry = word & mask; | ||
21586 | } | ||
21587 | |||
21588 | // Push carried bits as a mask | ||
21589 | if (maskedWords && carry !== 0) { | ||
21590 | maskedWords.words[maskedWords.length++] = carry; | ||
21591 | } | ||
21592 | |||
21593 | if (this.length === 0) { | ||
21594 | this.words[0] = 0; | ||
21595 | this.length = 1; | ||
21596 | } | ||
21597 | |||
21598 | return this.strip(); | ||
21599 | }; | ||
21600 | |||
21601 | BN.prototype.ishrn = function ishrn (bits, hint, extended) { | ||
21602 | // TODO(indutny): implement me | ||
21603 | assert(this.negative === 0); | ||
21604 | return this.iushrn(bits, hint, extended); | ||
21605 | }; | ||
21606 | |||
21607 | // Shift-left | ||
21608 | BN.prototype.shln = function shln (bits) { | ||
21609 | return this.clone().ishln(bits); | ||
21610 | }; | ||
21611 | |||
21612 | BN.prototype.ushln = function ushln (bits) { | ||
21613 | return this.clone().iushln(bits); | ||
21614 | }; | ||
21615 | |||
21616 | // Shift-right | ||
21617 | BN.prototype.shrn = function shrn (bits) { | ||
21618 | return this.clone().ishrn(bits); | ||
21619 | }; | ||
21620 | |||
21621 | BN.prototype.ushrn = function ushrn (bits) { | ||
21622 | return this.clone().iushrn(bits); | ||
21623 | }; | ||
21624 | |||
21625 | // Test if n bit is set | ||
21626 | BN.prototype.testn = function testn (bit) { | ||
21627 | assert(typeof bit === 'number' && bit >= 0); | ||
21628 | var r = bit % 26; | ||
21629 | var s = (bit - r) / 26; | ||
21630 | var q = 1 << r; | ||
21631 | |||
21632 | // Fast case: bit is much higher than all existing words | ||
21633 | if (this.length <= s) return false; | ||
21634 | |||
21635 | // Check bit and return | ||
21636 | var w = this.words[s]; | ||
21637 | |||
21638 | return !!(w & q); | ||
21639 | }; | ||
21640 | |||
21641 | // Return only lowers bits of number (in-place) | ||
21642 | BN.prototype.imaskn = function imaskn (bits) { | ||
21643 | assert(typeof bits === 'number' && bits >= 0); | ||
21644 | var r = bits % 26; | ||
21645 | var s = (bits - r) / 26; | ||
21646 | |||
21647 | assert(this.negative === 0, 'imaskn works only with positive numbers'); | ||
21648 | |||
21649 | if (this.length <= s) { | ||
21650 | return this; | ||
21651 | } | ||
21652 | |||
21653 | if (r !== 0) { | ||
21654 | s++; | ||
21655 | } | ||
21656 | this.length = Math.min(s, this.length); | ||
21657 | |||
21658 | if (r !== 0) { | ||
21659 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); | ||
21660 | this.words[this.length - 1] &= mask; | ||
21661 | } | ||
21662 | |||
21663 | return this.strip(); | ||
21664 | }; | ||
21665 | |||
21666 | // Return only lowers bits of number | ||
21667 | BN.prototype.maskn = function maskn (bits) { | ||
21668 | return this.clone().imaskn(bits); | ||
21669 | }; | ||
21670 | |||
21671 | // Add plain number `num` to `this` | ||
21672 | BN.prototype.iaddn = function iaddn (num) { | ||
21673 | assert(typeof num === 'number'); | ||
21674 | assert(num < 0x4000000); | ||
21675 | if (num < 0) return this.isubn(-num); | ||
21676 | |||
21677 | // Possible sign change | ||
21678 | if (this.negative !== 0) { | ||
21679 | if (this.length === 1 && (this.words[0] | 0) < num) { | ||
21680 | this.words[0] = num - (this.words[0] | 0); | ||
21681 | this.negative = 0; | ||
21682 | return this; | ||
21683 | } | ||
21684 | |||
21685 | this.negative = 0; | ||
21686 | this.isubn(num); | ||
21687 | this.negative = 1; | ||
21688 | return this; | ||
21689 | } | ||
21690 | |||
21691 | // Add without checks | ||
21692 | return this._iaddn(num); | ||
21693 | }; | ||
21694 | |||
21695 | BN.prototype._iaddn = function _iaddn (num) { | ||
21696 | this.words[0] += num; | ||
21697 | |||
21698 | // Carry | ||
21699 | for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) { | ||
21700 | this.words[i] -= 0x4000000; | ||
21701 | if (i === this.length - 1) { | ||
21702 | this.words[i + 1] = 1; | ||
21703 | } else { | ||
21704 | this.words[i + 1]++; | ||
21705 | } | ||
21706 | } | ||
21707 | this.length = Math.max(this.length, i + 1); | ||
21708 | |||
21709 | return this; | ||
21710 | }; | ||
21711 | |||
21712 | // Subtract plain number `num` from `this` | ||
21713 | BN.prototype.isubn = function isubn (num) { | ||
21714 | assert(typeof num === 'number'); | ||
21715 | assert(num < 0x4000000); | ||
21716 | if (num < 0) return this.iaddn(-num); | ||
21717 | |||
21718 | if (this.negative !== 0) { | ||
21719 | this.negative = 0; | ||
21720 | this.iaddn(num); | ||
21721 | this.negative = 1; | ||
21722 | return this; | ||
21723 | } | ||
21724 | |||
21725 | this.words[0] -= num; | ||
21726 | |||
21727 | if (this.length === 1 && this.words[0] < 0) { | ||
21728 | this.words[0] = -this.words[0]; | ||
21729 | this.negative = 1; | ||
21730 | } else { | ||
21731 | // Carry | ||
21732 | for (var i = 0; i < this.length && this.words[i] < 0; i++) { | ||
21733 | this.words[i] += 0x4000000; | ||
21734 | this.words[i + 1] -= 1; | ||
21735 | } | ||
21736 | } | ||
21737 | |||
21738 | return this.strip(); | ||
21739 | }; | ||
21740 | |||
21741 | BN.prototype.addn = function addn (num) { | ||
21742 | return this.clone().iaddn(num); | ||
21743 | }; | ||
21744 | |||
21745 | BN.prototype.subn = function subn (num) { | ||
21746 | return this.clone().isubn(num); | ||
21747 | }; | ||
21748 | |||
21749 | BN.prototype.iabs = function iabs () { | ||
21750 | this.negative = 0; | ||
21751 | |||
21752 | return this; | ||
21753 | }; | ||
21754 | |||
21755 | BN.prototype.abs = function abs () { | ||
21756 | return this.clone().iabs(); | ||
21757 | }; | ||
21758 | |||
21759 | BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) { | ||
21760 | var len = num.length + shift; | ||
21761 | var i; | ||
21762 | |||
21763 | this._expand(len); | ||
21764 | |||
21765 | var w; | ||
21766 | var carry = 0; | ||
21767 | for (i = 0; i < num.length; i++) { | ||
21768 | w = (this.words[i + shift] | 0) + carry; | ||
21769 | var right = (num.words[i] | 0) * mul; | ||
21770 | w -= right & 0x3ffffff; | ||
21771 | carry = (w >> 26) - ((right / 0x4000000) | 0); | ||
21772 | this.words[i + shift] = w & 0x3ffffff; | ||
21773 | } | ||
21774 | for (; i < this.length - shift; i++) { | ||
21775 | w = (this.words[i + shift] | 0) + carry; | ||
21776 | carry = w >> 26; | ||
21777 | this.words[i + shift] = w & 0x3ffffff; | ||
21778 | } | ||
21779 | |||
21780 | if (carry === 0) return this.strip(); | ||
21781 | |||
21782 | // Subtraction overflow | ||
21783 | assert(carry === -1); | ||
21784 | carry = 0; | ||
21785 | for (i = 0; i < this.length; i++) { | ||
21786 | w = -(this.words[i] | 0) + carry; | ||
21787 | carry = w >> 26; | ||
21788 | this.words[i] = w & 0x3ffffff; | ||
21789 | } | ||
21790 | this.negative = 1; | ||
21791 | |||
21792 | return this.strip(); | ||
21793 | }; | ||
21794 | |||
21795 | BN.prototype._wordDiv = function _wordDiv (num, mode) { | ||
21796 | var shift = this.length - num.length; | ||
21797 | |||
21798 | var a = this.clone(); | ||
21799 | var b = num; | ||
21800 | |||
21801 | // Normalize | ||
21802 | var bhi = b.words[b.length - 1] | 0; | ||
21803 | var bhiBits = this._countBits(bhi); | ||
21804 | shift = 26 - bhiBits; | ||
21805 | if (shift !== 0) { | ||
21806 | b = b.ushln(shift); | ||
21807 | a.iushln(shift); | ||
21808 | bhi = b.words[b.length - 1] | 0; | ||
21809 | } | ||
21810 | |||
21811 | // Initialize quotient | ||
21812 | var m = a.length - b.length; | ||
21813 | var q; | ||
21814 | |||
21815 | if (mode !== 'mod') { | ||
21816 | q = new BN(null); | ||
21817 | q.length = m + 1; | ||
21818 | q.words = new Array(q.length); | ||
21819 | for (var i = 0; i < q.length; i++) { | ||
21820 | q.words[i] = 0; | ||
21821 | } | ||
21822 | } | ||
21823 | |||
21824 | var diff = a.clone()._ishlnsubmul(b, 1, m); | ||
21825 | if (diff.negative === 0) { | ||
21826 | a = diff; | ||
21827 | if (q) { | ||
21828 | q.words[m] = 1; | ||
21829 | } | ||
21830 | } | ||
21831 | |||
21832 | for (var j = m - 1; j >= 0; j--) { | ||
21833 | var qj = (a.words[b.length + j] | 0) * 0x4000000 + | ||
21834 | (a.words[b.length + j - 1] | 0); | ||
21835 | |||
21836 | // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max | ||
21837 | // (0x7ffffff) | ||
21838 | qj = Math.min((qj / bhi) | 0, 0x3ffffff); | ||
21839 | |||
21840 | a._ishlnsubmul(b, qj, j); | ||
21841 | while (a.negative !== 0) { | ||
21842 | qj--; | ||
21843 | a.negative = 0; | ||
21844 | a._ishlnsubmul(b, 1, j); | ||
21845 | if (!a.isZero()) { | ||
21846 | a.negative ^= 1; | ||
21847 | } | ||
21848 | } | ||
21849 | if (q) { | ||
21850 | q.words[j] = qj; | ||
21851 | } | ||
21852 | } | ||
21853 | if (q) { | ||
21854 | q.strip(); | ||
21855 | } | ||
21856 | a.strip(); | ||
21857 | |||
21858 | // Denormalize | ||
21859 | if (mode !== 'div' && shift !== 0) { | ||
21860 | a.iushrn(shift); | ||
21861 | } | ||
21862 | |||
21863 | return { | ||
21864 | div: q || null, | ||
21865 | mod: a | ||
21866 | }; | ||
21867 | }; | ||
21868 | |||
21869 | // NOTE: 1) `mode` can be set to `mod` to request mod only, | ||
21870 | // to `div` to request div only, or be absent to | ||
21871 | // request both div & mod | ||
21872 | // 2) `positive` is true if unsigned mod is requested | ||
21873 | BN.prototype.divmod = function divmod (num, mode, positive) { | ||
21874 | assert(!num.isZero()); | ||
21875 | |||
21876 | if (this.isZero()) { | ||
21877 | return { | ||
21878 | div: new BN(0), | ||
21879 | mod: new BN(0) | ||
21880 | }; | ||
21881 | } | ||
21882 | |||
21883 | var div, mod, res; | ||
21884 | if (this.negative !== 0 && num.negative === 0) { | ||
21885 | res = this.neg().divmod(num, mode); | ||
21886 | |||
21887 | if (mode !== 'mod') { | ||
21888 | div = res.div.neg(); | ||
21889 | } | ||
21890 | |||
21891 | if (mode !== 'div') { | ||
21892 | mod = res.mod.neg(); | ||
21893 | if (positive && mod.negative !== 0) { | ||
21894 | mod.iadd(num); | ||
21895 | } | ||
21896 | } | ||
21897 | |||
21898 | return { | ||
21899 | div: div, | ||
21900 | mod: mod | ||
21901 | }; | ||
21902 | } | ||
21903 | |||
21904 | if (this.negative === 0 && num.negative !== 0) { | ||
21905 | res = this.divmod(num.neg(), mode); | ||
21906 | |||
21907 | if (mode !== 'mod') { | ||
21908 | div = res.div.neg(); | ||
21909 | } | ||
21910 | |||
21911 | return { | ||
21912 | div: div, | ||
21913 | mod: res.mod | ||
21914 | }; | ||
21915 | } | ||
21916 | |||
21917 | if ((this.negative & num.negative) !== 0) { | ||
21918 | res = this.neg().divmod(num.neg(), mode); | ||
21919 | |||
21920 | if (mode !== 'div') { | ||
21921 | mod = res.mod.neg(); | ||
21922 | if (positive && mod.negative !== 0) { | ||
21923 | mod.isub(num); | ||
21924 | } | ||
21925 | } | ||
21926 | |||
21927 | return { | ||
21928 | div: res.div, | ||
21929 | mod: mod | ||
21930 | }; | ||
21931 | } | ||
21932 | |||
21933 | // Both numbers are positive at this point | ||
21934 | |||
21935 | // Strip both numbers to approximate shift value | ||
21936 | if (num.length > this.length || this.cmp(num) < 0) { | ||
21937 | return { | ||
21938 | div: new BN(0), | ||
21939 | mod: this | ||
21940 | }; | ||
21941 | } | ||
21942 | |||
21943 | // Very short reduction | ||
21944 | if (num.length === 1) { | ||
21945 | if (mode === 'div') { | ||
21946 | return { | ||
21947 | div: this.divn(num.words[0]), | ||
21948 | mod: null | ||
21949 | }; | ||
21950 | } | ||
21951 | |||
21952 | if (mode === 'mod') { | ||
21953 | return { | ||
21954 | div: null, | ||
21955 | mod: new BN(this.modn(num.words[0])) | ||
21956 | }; | ||
21957 | } | ||
21958 | |||
21959 | return { | ||
21960 | div: this.divn(num.words[0]), | ||
21961 | mod: new BN(this.modn(num.words[0])) | ||
21962 | }; | ||
21963 | } | ||
21964 | |||
21965 | return this._wordDiv(num, mode); | ||
21966 | }; | ||
21967 | |||
21968 | // Find `this` / `num` | ||
21969 | BN.prototype.div = function div (num) { | ||
21970 | return this.divmod(num, 'div', false).div; | ||
21971 | }; | ||
21972 | |||
21973 | // Find `this` % `num` | ||
21974 | BN.prototype.mod = function mod (num) { | ||
21975 | return this.divmod(num, 'mod', false).mod; | ||
21976 | }; | ||
21977 | |||
21978 | BN.prototype.umod = function umod (num) { | ||
21979 | return this.divmod(num, 'mod', true).mod; | ||
21980 | }; | ||
21981 | |||
21982 | // Find Round(`this` / `num`) | ||
21983 | BN.prototype.divRound = function divRound (num) { | ||
21984 | var dm = this.divmod(num); | ||
21985 | |||
21986 | // Fast case - exact division | ||
21987 | if (dm.mod.isZero()) return dm.div; | ||
21988 | |||
21989 | var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; | ||
21990 | |||
21991 | var half = num.ushrn(1); | ||
21992 | var r2 = num.andln(1); | ||
21993 | var cmp = mod.cmp(half); | ||
21994 | |||
21995 | // Round down | ||
21996 | if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; | ||
21997 | |||
21998 | // Round up | ||
21999 | return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); | ||
22000 | }; | ||
22001 | |||
22002 | BN.prototype.modn = function modn (num) { | ||
22003 | assert(num <= 0x3ffffff); | ||
22004 | var p = (1 << 26) % num; | ||
22005 | |||
22006 | var acc = 0; | ||
22007 | for (var i = this.length - 1; i >= 0; i--) { | ||
22008 | acc = (p * acc + (this.words[i] | 0)) % num; | ||
22009 | } | ||
22010 | |||
22011 | return acc; | ||
22012 | }; | ||
22013 | |||
22014 | // In-place division by number | ||
22015 | BN.prototype.idivn = function idivn (num) { | ||
22016 | assert(num <= 0x3ffffff); | ||
22017 | |||
22018 | var carry = 0; | ||
22019 | for (var i = this.length - 1; i >= 0; i--) { | ||
22020 | var w = (this.words[i] | 0) + carry * 0x4000000; | ||
22021 | this.words[i] = (w / num) | 0; | ||
22022 | carry = w % num; | ||
22023 | } | ||
22024 | |||
22025 | return this.strip(); | ||
22026 | }; | ||
22027 | |||
22028 | BN.prototype.divn = function divn (num) { | ||
22029 | return this.clone().idivn(num); | ||
22030 | }; | ||
22031 | |||
22032 | BN.prototype.egcd = function egcd (p) { | ||
22033 | assert(p.negative === 0); | ||
22034 | assert(!p.isZero()); | ||
22035 | |||
22036 | var x = this; | ||
22037 | var y = p.clone(); | ||
22038 | |||
22039 | if (x.negative !== 0) { | ||
22040 | x = x.umod(p); | ||
22041 | } else { | ||
22042 | x = x.clone(); | ||
22043 | } | ||
22044 | |||
22045 | // A * x + B * y = x | ||
22046 | var A = new BN(1); | ||
22047 | var B = new BN(0); | ||
22048 | |||
22049 | // C * x + D * y = y | ||
22050 | var C = new BN(0); | ||
22051 | var D = new BN(1); | ||
22052 | |||
22053 | var g = 0; | ||
22054 | |||
22055 | while (x.isEven() && y.isEven()) { | ||
22056 | x.iushrn(1); | ||
22057 | y.iushrn(1); | ||
22058 | ++g; | ||
22059 | } | ||
22060 | |||
22061 | var yp = y.clone(); | ||
22062 | var xp = x.clone(); | ||
22063 | |||
22064 | while (!x.isZero()) { | ||
22065 | for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); | ||
22066 | if (i > 0) { | ||
22067 | x.iushrn(i); | ||
22068 | while (i-- > 0) { | ||
22069 | if (A.isOdd() || B.isOdd()) { | ||
22070 | A.iadd(yp); | ||
22071 | B.isub(xp); | ||
22072 | } | ||
22073 | |||
22074 | A.iushrn(1); | ||
22075 | B.iushrn(1); | ||
22076 | } | ||
22077 | } | ||
22078 | |||
22079 | for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); | ||
22080 | if (j > 0) { | ||
22081 | y.iushrn(j); | ||
22082 | while (j-- > 0) { | ||
22083 | if (C.isOdd() || D.isOdd()) { | ||
22084 | C.iadd(yp); | ||
22085 | D.isub(xp); | ||
22086 | } | ||
22087 | |||
22088 | C.iushrn(1); | ||
22089 | D.iushrn(1); | ||
22090 | } | ||
22091 | } | ||
22092 | |||
22093 | if (x.cmp(y) >= 0) { | ||
22094 | x.isub(y); | ||
22095 | A.isub(C); | ||
22096 | B.isub(D); | ||
22097 | } else { | ||
22098 | y.isub(x); | ||
22099 | C.isub(A); | ||
22100 | D.isub(B); | ||
22101 | } | ||
22102 | } | ||
22103 | |||
22104 | return { | ||
22105 | a: C, | ||
22106 | b: D, | ||
22107 | gcd: y.iushln(g) | ||
22108 | }; | ||
22109 | }; | ||
22110 | |||
22111 | // This is reduced incarnation of the binary EEA | ||
22112 | // above, designated to invert members of the | ||
22113 | // _prime_ fields F(p) at a maximal speed | ||
22114 | BN.prototype._invmp = function _invmp (p) { | ||
22115 | assert(p.negative === 0); | ||
22116 | assert(!p.isZero()); | ||
22117 | |||
22118 | var a = this; | ||
22119 | var b = p.clone(); | ||
22120 | |||
22121 | if (a.negative !== 0) { | ||
22122 | a = a.umod(p); | ||
22123 | } else { | ||
22124 | a = a.clone(); | ||
22125 | } | ||
22126 | |||
22127 | var x1 = new BN(1); | ||
22128 | var x2 = new BN(0); | ||
22129 | |||
22130 | var delta = b.clone(); | ||
22131 | |||
22132 | while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { | ||
22133 | for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); | ||
22134 | if (i > 0) { | ||
22135 | a.iushrn(i); | ||
22136 | while (i-- > 0) { | ||
22137 | if (x1.isOdd()) { | ||
22138 | x1.iadd(delta); | ||
22139 | } | ||
22140 | |||
22141 | x1.iushrn(1); | ||
22142 | } | ||
22143 | } | ||
22144 | |||
22145 | for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); | ||
22146 | if (j > 0) { | ||
22147 | b.iushrn(j); | ||
22148 | while (j-- > 0) { | ||
22149 | if (x2.isOdd()) { | ||
22150 | x2.iadd(delta); | ||
22151 | } | ||
22152 | |||
22153 | x2.iushrn(1); | ||
22154 | } | ||
22155 | } | ||
22156 | |||
22157 | if (a.cmp(b) >= 0) { | ||
22158 | a.isub(b); | ||
22159 | x1.isub(x2); | ||
22160 | } else { | ||
22161 | b.isub(a); | ||
22162 | x2.isub(x1); | ||
22163 | } | ||
22164 | } | ||
22165 | |||
22166 | var res; | ||
22167 | if (a.cmpn(1) === 0) { | ||
22168 | res = x1; | ||
22169 | } else { | ||
22170 | res = x2; | ||
22171 | } | ||
22172 | |||
22173 | if (res.cmpn(0) < 0) { | ||
22174 | res.iadd(p); | ||
22175 | } | ||
22176 | |||
22177 | return res; | ||
22178 | }; | ||
22179 | |||
22180 | BN.prototype.gcd = function gcd (num) { | ||
22181 | if (this.isZero()) return num.abs(); | ||
22182 | if (num.isZero()) return this.abs(); | ||
22183 | |||
22184 | var a = this.clone(); | ||
22185 | var b = num.clone(); | ||
22186 | a.negative = 0; | ||
22187 | b.negative = 0; | ||
22188 | |||
22189 | // Remove common factor of two | ||
22190 | for (var shift = 0; a.isEven() && b.isEven(); shift++) { | ||
22191 | a.iushrn(1); | ||
22192 | b.iushrn(1); | ||
22193 | } | ||
22194 | |||
22195 | do { | ||
22196 | while (a.isEven()) { | ||
22197 | a.iushrn(1); | ||
22198 | } | ||
22199 | while (b.isEven()) { | ||
22200 | b.iushrn(1); | ||
22201 | } | ||
22202 | |||
22203 | var r = a.cmp(b); | ||
22204 | if (r < 0) { | ||
22205 | // Swap `a` and `b` to make `a` always bigger than `b` | ||
22206 | var t = a; | ||
22207 | a = b; | ||
22208 | b = t; | ||
22209 | } else if (r === 0 || b.cmpn(1) === 0) { | ||
22210 | break; | ||
22211 | } | ||
22212 | |||
22213 | a.isub(b); | ||
22214 | } while (true); | ||
22215 | |||
22216 | return b.iushln(shift); | ||
22217 | }; | ||
22218 | |||
22219 | // Invert number in the field F(num) | ||
22220 | BN.prototype.invm = function invm (num) { | ||
22221 | return this.egcd(num).a.umod(num); | ||
22222 | }; | ||
22223 | |||
22224 | BN.prototype.isEven = function isEven () { | ||
22225 | return (this.words[0] & 1) === 0; | ||
22226 | }; | ||
22227 | |||
22228 | BN.prototype.isOdd = function isOdd () { | ||
22229 | return (this.words[0] & 1) === 1; | ||
22230 | }; | ||
22231 | |||
22232 | // And first word and num | ||
22233 | BN.prototype.andln = function andln (num) { | ||
22234 | return this.words[0] & num; | ||
22235 | }; | ||
22236 | |||
22237 | // Increment at the bit position in-line | ||
22238 | BN.prototype.bincn = function bincn (bit) { | ||
22239 | assert(typeof bit === 'number'); | ||
22240 | var r = bit % 26; | ||
22241 | var s = (bit - r) / 26; | ||
22242 | var q = 1 << r; | ||
22243 | |||
22244 | // Fast case: bit is much higher than all existing words | ||
22245 | if (this.length <= s) { | ||
22246 | this._expand(s + 1); | ||
22247 | this.words[s] |= q; | ||
22248 | return this; | ||
22249 | } | ||
22250 | |||
22251 | // Add bit and propagate, if needed | ||
22252 | var carry = q; | ||
22253 | for (var i = s; carry !== 0 && i < this.length; i++) { | ||
22254 | var w = this.words[i] | 0; | ||
22255 | w += carry; | ||
22256 | carry = w >>> 26; | ||
22257 | w &= 0x3ffffff; | ||
22258 | this.words[i] = w; | ||
22259 | } | ||
22260 | if (carry !== 0) { | ||
22261 | this.words[i] = carry; | ||
22262 | this.length++; | ||
22263 | } | ||
22264 | return this; | ||
22265 | }; | ||
22266 | |||
22267 | BN.prototype.isZero = function isZero () { | ||
22268 | return this.length === 1 && this.words[0] === 0; | ||
22269 | }; | ||
22270 | |||
22271 | BN.prototype.cmpn = function cmpn (num) { | ||
22272 | var negative = num < 0; | ||
22273 | |||
22274 | if (this.negative !== 0 && !negative) return -1; | ||
22275 | if (this.negative === 0 && negative) return 1; | ||
22276 | |||
22277 | this.strip(); | ||
22278 | |||
22279 | var res; | ||
22280 | if (this.length > 1) { | ||
22281 | res = 1; | ||
22282 | } else { | ||
22283 | if (negative) { | ||
22284 | num = -num; | ||
22285 | } | ||
22286 | |||
22287 | assert(num <= 0x3ffffff, 'Number is too big'); | ||
22288 | |||
22289 | var w = this.words[0] | 0; | ||
22290 | res = w === num ? 0 : w < num ? -1 : 1; | ||
22291 | } | ||
22292 | if (this.negative !== 0) return -res | 0; | ||
22293 | return res; | ||
22294 | }; | ||
22295 | |||
22296 | // Compare two numbers and return: | ||
22297 | // 1 - if `this` > `num` | ||
22298 | // 0 - if `this` == `num` | ||
22299 | // -1 - if `this` < `num` | ||
22300 | BN.prototype.cmp = function cmp (num) { | ||
22301 | if (this.negative !== 0 && num.negative === 0) return -1; | ||
22302 | if (this.negative === 0 && num.negative !== 0) return 1; | ||
22303 | |||
22304 | var res = this.ucmp(num); | ||
22305 | if (this.negative !== 0) return -res | 0; | ||
22306 | return res; | ||
22307 | }; | ||
22308 | |||
22309 | // Unsigned comparison | ||
22310 | BN.prototype.ucmp = function ucmp (num) { | ||
22311 | // At this point both numbers have the same sign | ||
22312 | if (this.length > num.length) return 1; | ||
22313 | if (this.length < num.length) return -1; | ||
22314 | |||
22315 | var res = 0; | ||
22316 | for (var i = this.length - 1; i >= 0; i--) { | ||
22317 | var a = this.words[i] | 0; | ||
22318 | var b = num.words[i] | 0; | ||
22319 | |||
22320 | if (a === b) continue; | ||
22321 | if (a < b) { | ||
22322 | res = -1; | ||
22323 | } else if (a > b) { | ||
22324 | res = 1; | ||
22325 | } | ||
22326 | break; | ||
22327 | } | ||
22328 | return res; | ||
22329 | }; | ||
22330 | |||
22331 | BN.prototype.gtn = function gtn (num) { | ||
22332 | return this.cmpn(num) === 1; | ||
22333 | }; | ||
22334 | |||
22335 | BN.prototype.gt = function gt (num) { | ||
22336 | return this.cmp(num) === 1; | ||
22337 | }; | ||
22338 | |||
22339 | BN.prototype.gten = function gten (num) { | ||
22340 | return this.cmpn(num) >= 0; | ||
22341 | }; | ||
22342 | |||
22343 | BN.prototype.gte = function gte (num) { | ||
22344 | return this.cmp(num) >= 0; | ||
22345 | }; | ||
22346 | |||
22347 | BN.prototype.ltn = function ltn (num) { | ||
22348 | return this.cmpn(num) === -1; | ||
22349 | }; | ||
22350 | |||
22351 | BN.prototype.lt = function lt (num) { | ||
22352 | return this.cmp(num) === -1; | ||
22353 | }; | ||
22354 | |||
22355 | BN.prototype.lten = function lten (num) { | ||
22356 | return this.cmpn(num) <= 0; | ||
22357 | }; | ||
22358 | |||
22359 | BN.prototype.lte = function lte (num) { | ||
22360 | return this.cmp(num) <= 0; | ||
22361 | }; | ||
22362 | |||
22363 | BN.prototype.eqn = function eqn (num) { | ||
22364 | return this.cmpn(num) === 0; | ||
22365 | }; | ||
22366 | |||
22367 | BN.prototype.eq = function eq (num) { | ||
22368 | return this.cmp(num) === 0; | ||
22369 | }; | ||
22370 | |||
22371 | // | ||
22372 | // A reduce context, could be using montgomery or something better, depending | ||
22373 | // on the `m` itself. | ||
22374 | // | ||
22375 | BN.red = function red (num) { | ||
22376 | return new Red(num); | ||
22377 | }; | ||
22378 | |||
22379 | BN.prototype.toRed = function toRed (ctx) { | ||
22380 | assert(!this.red, 'Already a number in reduction context'); | ||
22381 | assert(this.negative === 0, 'red works only with positives'); | ||
22382 | return ctx.convertTo(this)._forceRed(ctx); | ||
22383 | }; | ||
22384 | |||
22385 | BN.prototype.fromRed = function fromRed () { | ||
22386 | assert(this.red, 'fromRed works only with numbers in reduction context'); | ||
22387 | return this.red.convertFrom(this); | ||
22388 | }; | ||
22389 | |||
22390 | BN.prototype._forceRed = function _forceRed (ctx) { | ||
22391 | this.red = ctx; | ||
22392 | return this; | ||
22393 | }; | ||
22394 | |||
22395 | BN.prototype.forceRed = function forceRed (ctx) { | ||
22396 | assert(!this.red, 'Already a number in reduction context'); | ||
22397 | return this._forceRed(ctx); | ||
22398 | }; | ||
22399 | |||
22400 | BN.prototype.redAdd = function redAdd (num) { | ||
22401 | assert(this.red, 'redAdd works only with red numbers'); | ||
22402 | return this.red.add(this, num); | ||
22403 | }; | ||
22404 | |||
22405 | BN.prototype.redIAdd = function redIAdd (num) { | ||
22406 | assert(this.red, 'redIAdd works only with red numbers'); | ||
22407 | return this.red.iadd(this, num); | ||
22408 | }; | ||
22409 | |||
22410 | BN.prototype.redSub = function redSub (num) { | ||
22411 | assert(this.red, 'redSub works only with red numbers'); | ||
22412 | return this.red.sub(this, num); | ||
22413 | }; | ||
22414 | |||
22415 | BN.prototype.redISub = function redISub (num) { | ||
22416 | assert(this.red, 'redISub works only with red numbers'); | ||
22417 | return this.red.isub(this, num); | ||
22418 | }; | ||
22419 | |||
22420 | BN.prototype.redShl = function redShl (num) { | ||
22421 | assert(this.red, 'redShl works only with red numbers'); | ||
22422 | return this.red.shl(this, num); | ||
22423 | }; | ||
22424 | |||
22425 | BN.prototype.redMul = function redMul (num) { | ||
22426 | assert(this.red, 'redMul works only with red numbers'); | ||
22427 | this.red._verify2(this, num); | ||
22428 | return this.red.mul(this, num); | ||
22429 | }; | ||
22430 | |||
22431 | BN.prototype.redIMul = function redIMul (num) { | ||
22432 | assert(this.red, 'redMul works only with red numbers'); | ||
22433 | this.red._verify2(this, num); | ||
22434 | return this.red.imul(this, num); | ||
22435 | }; | ||
22436 | |||
22437 | BN.prototype.redSqr = function redSqr () { | ||
22438 | assert(this.red, 'redSqr works only with red numbers'); | ||
22439 | this.red._verify1(this); | ||
22440 | return this.red.sqr(this); | ||
22441 | }; | ||
22442 | |||
22443 | BN.prototype.redISqr = function redISqr () { | ||
22444 | assert(this.red, 'redISqr works only with red numbers'); | ||
22445 | this.red._verify1(this); | ||
22446 | return this.red.isqr(this); | ||
22447 | }; | ||
22448 | |||
22449 | // Square root over p | ||
22450 | BN.prototype.redSqrt = function redSqrt () { | ||
22451 | assert(this.red, 'redSqrt works only with red numbers'); | ||
22452 | this.red._verify1(this); | ||
22453 | return this.red.sqrt(this); | ||
22454 | }; | ||
22455 | |||
22456 | BN.prototype.redInvm = function redInvm () { | ||
22457 | assert(this.red, 'redInvm works only with red numbers'); | ||
22458 | this.red._verify1(this); | ||
22459 | return this.red.invm(this); | ||
22460 | }; | ||
22461 | |||
22462 | // Return negative clone of `this` % `red modulo` | ||
22463 | BN.prototype.redNeg = function redNeg () { | ||
22464 | assert(this.red, 'redNeg works only with red numbers'); | ||
22465 | this.red._verify1(this); | ||
22466 | return this.red.neg(this); | ||
22467 | }; | ||
22468 | |||
22469 | BN.prototype.redPow = function redPow (num) { | ||
22470 | assert(this.red && !num.red, 'redPow(normalNum)'); | ||
22471 | this.red._verify1(this); | ||
22472 | return this.red.pow(this, num); | ||
22473 | }; | ||
22474 | |||
22475 | // Prime numbers with efficient reduction | ||
22476 | var primes = { | ||
22477 | k256: null, | ||
22478 | p224: null, | ||
22479 | p192: null, | ||
22480 | p25519: null | ||
22481 | }; | ||
22482 | |||
22483 | // Pseudo-Mersenne prime | ||
22484 | function MPrime (name, p) { | ||
22485 | // P = 2 ^ N - K | ||
22486 | this.name = name; | ||
22487 | this.p = new BN(p, 16); | ||
22488 | this.n = this.p.bitLength(); | ||
22489 | this.k = new BN(1).iushln(this.n).isub(this.p); | ||
22490 | |||
22491 | this.tmp = this._tmp(); | ||
22492 | } | ||
22493 | |||
22494 | MPrime.prototype._tmp = function _tmp () { | ||
22495 | var tmp = new BN(null); | ||
22496 | tmp.words = new Array(Math.ceil(this.n / 13)); | ||
22497 | return tmp; | ||
22498 | }; | ||
22499 | |||
22500 | MPrime.prototype.ireduce = function ireduce (num) { | ||
22501 | // Assumes that `num` is less than `P^2` | ||
22502 | // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) | ||
22503 | var r = num; | ||
22504 | var rlen; | ||
22505 | |||
22506 | do { | ||
22507 | this.split(r, this.tmp); | ||
22508 | r = this.imulK(r); | ||
22509 | r = r.iadd(this.tmp); | ||
22510 | rlen = r.bitLength(); | ||
22511 | } while (rlen > this.n); | ||
22512 | |||
22513 | var cmp = rlen < this.n ? -1 : r.ucmp(this.p); | ||
22514 | if (cmp === 0) { | ||
22515 | r.words[0] = 0; | ||
22516 | r.length = 1; | ||
22517 | } else if (cmp > 0) { | ||
22518 | r.isub(this.p); | ||
22519 | } else { | ||
22520 | r.strip(); | ||
22521 | } | ||
22522 | |||
22523 | return r; | ||
22524 | }; | ||
22525 | |||
22526 | MPrime.prototype.split = function split (input, out) { | ||
22527 | input.iushrn(this.n, 0, out); | ||
22528 | }; | ||
22529 | |||
22530 | MPrime.prototype.imulK = function imulK (num) { | ||
22531 | return num.imul(this.k); | ||
22532 | }; | ||
22533 | |||
22534 | function K256 () { | ||
22535 | MPrime.call( | ||
22536 | this, | ||
22537 | 'k256', | ||
22538 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f'); | ||
22539 | } | ||
22540 | inherits(K256, MPrime); | ||
22541 | |||
22542 | K256.prototype.split = function split (input, output) { | ||
22543 | // 256 = 9 * 26 + 22 | ||
22544 | var mask = 0x3fffff; | ||
22545 | |||
22546 | var outLen = Math.min(input.length, 9); | ||
22547 | for (var i = 0; i < outLen; i++) { | ||
22548 | output.words[i] = input.words[i]; | ||
22549 | } | ||
22550 | output.length = outLen; | ||
22551 | |||
22552 | if (input.length <= 9) { | ||
22553 | input.words[0] = 0; | ||
22554 | input.length = 1; | ||
22555 | return; | ||
22556 | } | ||
22557 | |||
22558 | // Shift by 9 limbs | ||
22559 | var prev = input.words[9]; | ||
22560 | output.words[output.length++] = prev & mask; | ||
22561 | |||
22562 | for (i = 10; i < input.length; i++) { | ||
22563 | var next = input.words[i] | 0; | ||
22564 | input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22); | ||
22565 | prev = next; | ||
22566 | } | ||
22567 | prev >>>= 22; | ||
22568 | input.words[i - 10] = prev; | ||
22569 | if (prev === 0 && input.length > 10) { | ||
22570 | input.length -= 10; | ||
22571 | } else { | ||
22572 | input.length -= 9; | ||
22573 | } | ||
22574 | }; | ||
22575 | |||
22576 | K256.prototype.imulK = function imulK (num) { | ||
22577 | // K = 0x1000003d1 = [ 0x40, 0x3d1 ] | ||
22578 | num.words[num.length] = 0; | ||
22579 | num.words[num.length + 1] = 0; | ||
22580 | num.length += 2; | ||
22581 | |||
22582 | // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 | ||
22583 | var lo = 0; | ||
22584 | for (var i = 0; i < num.length; i++) { | ||
22585 | var w = num.words[i] | 0; | ||
22586 | lo += w * 0x3d1; | ||
22587 | num.words[i] = lo & 0x3ffffff; | ||
22588 | lo = w * 0x40 + ((lo / 0x4000000) | 0); | ||
22589 | } | ||
22590 | |||
22591 | // Fast length reduction | ||
22592 | if (num.words[num.length - 1] === 0) { | ||
22593 | num.length--; | ||
22594 | if (num.words[num.length - 1] === 0) { | ||
22595 | num.length--; | ||
22596 | } | ||
22597 | } | ||
22598 | return num; | ||
22599 | }; | ||
22600 | |||
22601 | function P224 () { | ||
22602 | MPrime.call( | ||
22603 | this, | ||
22604 | 'p224', | ||
22605 | 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001'); | ||
22606 | } | ||
22607 | inherits(P224, MPrime); | ||
22608 | |||
22609 | function P192 () { | ||
22610 | MPrime.call( | ||
22611 | this, | ||
22612 | 'p192', | ||
22613 | 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff'); | ||
22614 | } | ||
22615 | inherits(P192, MPrime); | ||
22616 | |||
22617 | function P25519 () { | ||
22618 | // 2 ^ 255 - 19 | ||
22619 | MPrime.call( | ||
22620 | this, | ||
22621 | '25519', | ||
22622 | '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed'); | ||
22623 | } | ||
22624 | inherits(P25519, MPrime); | ||
22625 | |||
22626 | P25519.prototype.imulK = function imulK (num) { | ||
22627 | // K = 0x13 | ||
22628 | var carry = 0; | ||
22629 | for (var i = 0; i < num.length; i++) { | ||
22630 | var hi = (num.words[i] | 0) * 0x13 + carry; | ||
22631 | var lo = hi & 0x3ffffff; | ||
22632 | hi >>>= 26; | ||
22633 | |||
22634 | num.words[i] = lo; | ||
22635 | carry = hi; | ||
22636 | } | ||
22637 | if (carry !== 0) { | ||
22638 | num.words[num.length++] = carry; | ||
22639 | } | ||
22640 | return num; | ||
22641 | }; | ||
22642 | |||
22643 | // Exported mostly for testing purposes, use plain name instead | ||
22644 | BN._prime = function prime (name) { | ||
22645 | // Cached version of prime | ||
22646 | if (primes[name]) return primes[name]; | ||
22647 | |||
22648 | var prime; | ||
22649 | if (name === 'k256') { | ||
22650 | prime = new K256(); | ||
22651 | } else if (name === 'p224') { | ||
22652 | prime = new P224(); | ||
22653 | } else if (name === 'p192') { | ||
22654 | prime = new P192(); | ||
22655 | } else if (name === 'p25519') { | ||
22656 | prime = new P25519(); | ||
22657 | } else { | ||
22658 | throw new Error('Unknown prime ' + name); | ||
22659 | } | ||
22660 | primes[name] = prime; | ||
22661 | |||
22662 | return prime; | ||
22663 | }; | ||
22664 | |||
22665 | // | ||
22666 | // Base reduction engine | ||
22667 | // | ||
22668 | function Red (m) { | ||
22669 | if (typeof m === 'string') { | ||
22670 | var prime = BN._prime(m); | ||
22671 | this.m = prime.p; | ||
22672 | this.prime = prime; | ||
22673 | } else { | ||
22674 | assert(m.gtn(1), 'modulus must be greater than 1'); | ||
22675 | this.m = m; | ||
22676 | this.prime = null; | ||
22677 | } | ||
22678 | } | ||
22679 | |||
22680 | Red.prototype._verify1 = function _verify1 (a) { | ||
22681 | assert(a.negative === 0, 'red works only with positives'); | ||
22682 | assert(a.red, 'red works only with red numbers'); | ||
22683 | }; | ||
22684 | |||
22685 | Red.prototype._verify2 = function _verify2 (a, b) { | ||
22686 | assert((a.negative | b.negative) === 0, 'red works only with positives'); | ||
22687 | assert(a.red && a.red === b.red, | ||
22688 | 'red works only with red numbers'); | ||
22689 | }; | ||
22690 | |||
22691 | Red.prototype.imod = function imod (a) { | ||
22692 | if (this.prime) return this.prime.ireduce(a)._forceRed(this); | ||
22693 | return a.umod(this.m)._forceRed(this); | ||
22694 | }; | ||
22695 | |||
22696 | Red.prototype.neg = function neg (a) { | ||
22697 | if (a.isZero()) { | ||
22698 | return a.clone(); | ||
22699 | } | ||
22700 | |||
22701 | return this.m.sub(a)._forceRed(this); | ||
22702 | }; | ||
22703 | |||
22704 | Red.prototype.add = function add (a, b) { | ||
22705 | this._verify2(a, b); | ||
22706 | |||
22707 | var res = a.add(b); | ||
22708 | if (res.cmp(this.m) >= 0) { | ||
22709 | res.isub(this.m); | ||
22710 | } | ||
22711 | return res._forceRed(this); | ||
22712 | }; | ||
22713 | |||
22714 | Red.prototype.iadd = function iadd (a, b) { | ||
22715 | this._verify2(a, b); | ||
22716 | |||
22717 | var res = a.iadd(b); | ||
22718 | if (res.cmp(this.m) >= 0) { | ||
22719 | res.isub(this.m); | ||
22720 | } | ||
22721 | return res; | ||
22722 | }; | ||
22723 | |||
22724 | Red.prototype.sub = function sub (a, b) { | ||
22725 | this._verify2(a, b); | ||
22726 | |||
22727 | var res = a.sub(b); | ||
22728 | if (res.cmpn(0) < 0) { | ||
22729 | res.iadd(this.m); | ||
22730 | } | ||
22731 | return res._forceRed(this); | ||
22732 | }; | ||
22733 | |||
22734 | Red.prototype.isub = function isub (a, b) { | ||
22735 | this._verify2(a, b); | ||
22736 | |||
22737 | var res = a.isub(b); | ||
22738 | if (res.cmpn(0) < 0) { | ||
22739 | res.iadd(this.m); | ||
22740 | } | ||
22741 | return res; | ||
22742 | }; | ||
22743 | |||
22744 | Red.prototype.shl = function shl (a, num) { | ||
22745 | this._verify1(a); | ||
22746 | return this.imod(a.ushln(num)); | ||
22747 | }; | ||
22748 | |||
22749 | Red.prototype.imul = function imul (a, b) { | ||
22750 | this._verify2(a, b); | ||
22751 | return this.imod(a.imul(b)); | ||
22752 | }; | ||
22753 | |||
22754 | Red.prototype.mul = function mul (a, b) { | ||
22755 | this._verify2(a, b); | ||
22756 | return this.imod(a.mul(b)); | ||
22757 | }; | ||
22758 | |||
22759 | Red.prototype.isqr = function isqr (a) { | ||
22760 | return this.imul(a, a.clone()); | ||
22761 | }; | ||
22762 | |||
22763 | Red.prototype.sqr = function sqr (a) { | ||
22764 | return this.mul(a, a); | ||
22765 | }; | ||
22766 | |||
22767 | Red.prototype.sqrt = function sqrt (a) { | ||
22768 | if (a.isZero()) return a.clone(); | ||
22769 | |||
22770 | var mod3 = this.m.andln(3); | ||
22771 | assert(mod3 % 2 === 1); | ||
22772 | |||
22773 | // Fast case | ||
22774 | if (mod3 === 3) { | ||
22775 | var pow = this.m.add(new BN(1)).iushrn(2); | ||
22776 | return this.pow(a, pow); | ||
22777 | } | ||
22778 | |||
22779 | // Tonelli-Shanks algorithm (Totally unoptimized and slow) | ||
22780 | // | ||
22781 | // Find Q and S, that Q * 2 ^ S = (P - 1) | ||
22782 | var q = this.m.subn(1); | ||
22783 | var s = 0; | ||
22784 | while (!q.isZero() && q.andln(1) === 0) { | ||
22785 | s++; | ||
22786 | q.iushrn(1); | ||
22787 | } | ||
22788 | assert(!q.isZero()); | ||
22789 | |||
22790 | var one = new BN(1).toRed(this); | ||
22791 | var nOne = one.redNeg(); | ||
22792 | |||
22793 | // Find quadratic non-residue | ||
22794 | // NOTE: Max is such because of generalized Riemann hypothesis. | ||
22795 | var lpow = this.m.subn(1).iushrn(1); | ||
22796 | var z = this.m.bitLength(); | ||
22797 | z = new BN(2 * z * z).toRed(this); | ||
22798 | |||
22799 | while (this.pow(z, lpow).cmp(nOne) !== 0) { | ||
22800 | z.redIAdd(nOne); | ||
22801 | } | ||
22802 | |||
22803 | var c = this.pow(z, q); | ||
22804 | var r = this.pow(a, q.addn(1).iushrn(1)); | ||
22805 | var t = this.pow(a, q); | ||
22806 | var m = s; | ||
22807 | while (t.cmp(one) !== 0) { | ||
22808 | var tmp = t; | ||
22809 | for (var i = 0; tmp.cmp(one) !== 0; i++) { | ||
22810 | tmp = tmp.redSqr(); | ||
22811 | } | ||
22812 | assert(i < m); | ||
22813 | var b = this.pow(c, new BN(1).iushln(m - i - 1)); | ||
22814 | |||
22815 | r = r.redMul(b); | ||
22816 | c = b.redSqr(); | ||
22817 | t = t.redMul(c); | ||
22818 | m = i; | ||
22819 | } | ||
22820 | |||
22821 | return r; | ||
22822 | }; | ||
22823 | |||
22824 | Red.prototype.invm = function invm (a) { | ||
22825 | var inv = a._invmp(this.m); | ||
22826 | if (inv.negative !== 0) { | ||
22827 | inv.negative = 0; | ||
22828 | return this.imod(inv).redNeg(); | ||
22829 | } else { | ||
22830 | return this.imod(inv); | ||
22831 | } | ||
22832 | }; | ||
22833 | |||
22834 | Red.prototype.pow = function pow (a, num) { | ||
22835 | if (num.isZero()) return new BN(1); | ||
22836 | if (num.cmpn(1) === 0) return a.clone(); | ||
22837 | |||
22838 | var windowSize = 4; | ||
22839 | var wnd = new Array(1 << windowSize); | ||
22840 | wnd[0] = new BN(1).toRed(this); | ||
22841 | wnd[1] = a; | ||
22842 | for (var i = 2; i < wnd.length; i++) { | ||
22843 | wnd[i] = this.mul(wnd[i - 1], a); | ||
22844 | } | ||
22845 | |||
22846 | var res = wnd[0]; | ||
22847 | var current = 0; | ||
22848 | var currentLen = 0; | ||
22849 | var start = num.bitLength() % 26; | ||
22850 | if (start === 0) { | ||
22851 | start = 26; | ||
22852 | } | ||
22853 | |||
22854 | for (i = num.length - 1; i >= 0; i--) { | ||
22855 | var word = num.words[i]; | ||
22856 | for (var j = start - 1; j >= 0; j--) { | ||
22857 | var bit = (word >> j) & 1; | ||
22858 | if (res !== wnd[0]) { | ||
22859 | res = this.sqr(res); | ||
22860 | } | ||
22861 | |||
22862 | if (bit === 0 && current === 0) { | ||
22863 | currentLen = 0; | ||
22864 | continue; | ||
22865 | } | ||
22866 | |||
22867 | current <<= 1; | ||
22868 | current |= bit; | ||
22869 | currentLen++; | ||
22870 | if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; | ||
22871 | |||
22872 | res = this.mul(res, wnd[current]); | ||
22873 | currentLen = 0; | ||
22874 | current = 0; | ||
22875 | } | ||
22876 | start = 26; | ||
22877 | } | ||
22878 | |||
22879 | return res; | ||
22880 | }; | ||
22881 | |||
22882 | Red.prototype.convertTo = function convertTo (num) { | ||
22883 | var r = num.umod(this.m); | ||
22884 | |||
22885 | return r === num ? r.clone() : r; | ||
22886 | }; | ||
22887 | |||
22888 | Red.prototype.convertFrom = function convertFrom (num) { | ||
22889 | var res = num.clone(); | ||
22890 | res.red = null; | ||
22891 | return res; | ||
22892 | }; | ||
22893 | |||
22894 | // | ||
22895 | // Montgomery method engine | ||
22896 | // | ||
22897 | |||
22898 | BN.mont = function mont (num) { | ||
22899 | return new Mont(num); | ||
22900 | }; | ||
22901 | |||
22902 | function Mont (m) { | ||
22903 | Red.call(this, m); | ||
22904 | |||
22905 | this.shift = this.m.bitLength(); | ||
22906 | if (this.shift % 26 !== 0) { | ||
22907 | this.shift += 26 - (this.shift % 26); | ||
22908 | } | ||
22909 | |||
22910 | this.r = new BN(1).iushln(this.shift); | ||
22911 | this.r2 = this.imod(this.r.sqr()); | ||
22912 | this.rinv = this.r._invmp(this.m); | ||
22913 | |||
22914 | this.minv = this.rinv.mul(this.r).isubn(1).div(this.m); | ||
22915 | this.minv = this.minv.umod(this.r); | ||
22916 | this.minv = this.r.sub(this.minv); | ||
22917 | } | ||
22918 | inherits(Mont, Red); | ||
22919 | |||
22920 | Mont.prototype.convertTo = function convertTo (num) { | ||
22921 | return this.imod(num.ushln(this.shift)); | ||
22922 | }; | ||
22923 | |||
22924 | Mont.prototype.convertFrom = function convertFrom (num) { | ||
22925 | var r = this.imod(num.mul(this.rinv)); | ||
22926 | r.red = null; | ||
22927 | return r; | ||
22928 | }; | ||
22929 | |||
22930 | Mont.prototype.imul = function imul (a, b) { | ||
22931 | if (a.isZero() || b.isZero()) { | ||
22932 | a.words[0] = 0; | ||
22933 | a.length = 1; | ||
22934 | return a; | ||
22935 | } | ||
22936 | |||
22937 | var t = a.imul(b); | ||
22938 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); | ||
22939 | var u = t.isub(c).iushrn(this.shift); | ||
22940 | var res = u; | ||
22941 | |||
22942 | if (u.cmp(this.m) >= 0) { | ||
22943 | res = u.isub(this.m); | ||
22944 | } else if (u.cmpn(0) < 0) { | ||
22945 | res = u.iadd(this.m); | ||
22946 | } | ||
22947 | |||
22948 | return res._forceRed(this); | ||
22949 | }; | ||
22950 | |||
22951 | Mont.prototype.mul = function mul (a, b) { | ||
22952 | if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this); | ||
22953 | |||
22954 | var t = a.mul(b); | ||
22955 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); | ||
22956 | var u = t.isub(c).iushrn(this.shift); | ||
22957 | var res = u; | ||
22958 | if (u.cmp(this.m) >= 0) { | ||
22959 | res = u.isub(this.m); | ||
22960 | } else if (u.cmpn(0) < 0) { | ||
22961 | res = u.iadd(this.m); | ||
22962 | } | ||
22963 | |||
22964 | return res._forceRed(this); | ||
22965 | }; | ||
22966 | |||
22967 | Mont.prototype.invm = function invm (a) { | ||
22968 | // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R | ||
22969 | var res = this.imod(a._invmp(this.m).mul(this.r2)); | ||
22970 | return res._forceRed(this); | ||
22971 | }; | ||
22972 | })(typeof module === 'undefined' || module, this); | ||
22973 | |||
22974 | },{}],82:[function(require,module,exports){ | ||
22975 | var r; | ||
22976 | |||
22977 | module.exports = function rand(len) { | ||
22978 | if (!r) | ||
22979 | r = new Rand(null); | ||
22980 | |||
22981 | return r.generate(len); | ||
22982 | }; | ||
22983 | |||
22984 | function Rand(rand) { | ||
22985 | this.rand = rand; | ||
22986 | } | ||
22987 | module.exports.Rand = Rand; | ||
22988 | |||
22989 | Rand.prototype.generate = function generate(len) { | ||
22990 | return this._rand(len); | ||
22991 | }; | ||
22992 | |||
22993 | // Emulate crypto API using randy | ||
22994 | Rand.prototype._rand = function _rand(n) { | ||
22995 | if (this.rand.getBytes) | ||
22996 | return this.rand.getBytes(n); | ||
22997 | |||
22998 | var res = new Uint8Array(n); | ||
22999 | for (var i = 0; i < res.length; i++) | ||
23000 | res[i] = this.rand.getByte(); | ||
23001 | return res; | ||
23002 | }; | ||
23003 | |||
23004 | if (typeof self === 'object') { | ||
23005 | if (self.crypto && self.crypto.getRandomValues) { | ||
23006 | // Modern browsers | ||
23007 | Rand.prototype._rand = function _rand(n) { | ||
23008 | var arr = new Uint8Array(n); | ||
23009 | self.crypto.getRandomValues(arr); | ||
23010 | return arr; | ||
23011 | }; | ||
23012 | } else if (self.msCrypto && self.msCrypto.getRandomValues) { | ||
23013 | // IE | ||
23014 | Rand.prototype._rand = function _rand(n) { | ||
23015 | var arr = new Uint8Array(n); | ||
23016 | self.msCrypto.getRandomValues(arr); | ||
23017 | return arr; | ||
23018 | }; | ||
23019 | |||
23020 | // Safari's WebWorkers do not have `crypto` | ||
23021 | } else if (typeof window === 'object') { | ||
23022 | // Old junk | ||
23023 | Rand.prototype._rand = function() { | ||
23024 | throw new Error('Not implemented yet'); | ||
23025 | }; | ||
23026 | } | ||
23027 | } else { | ||
23028 | // Node.js or Web worker with no crypto support | ||
23029 | try { | ||
23030 | var crypto = require('crypto'); | ||
23031 | if (typeof crypto.randomBytes !== 'function') | ||
23032 | throw new Error('Not supported'); | ||
23033 | |||
23034 | Rand.prototype._rand = function _rand(n) { | ||
23035 | return crypto.randomBytes(n); | ||
23036 | }; | ||
23037 | } catch (e) { | ||
23038 | } | ||
23039 | } | ||
23040 | |||
23041 | },{"crypto":3}],83:[function(require,module,exports){ | ||
19263 | var basex = require('base-x') | 23042 | var basex = require('base-x') |
19264 | var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | 23043 | var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
19265 | 23044 | ||
19266 | module.exports = basex(ALPHABET) | 23045 | module.exports = basex(ALPHABET) |
19267 | 23046 | ||
19268 | },{"base-x":34}],80:[function(require,module,exports){ | 23047 | },{"base-x":35}],84:[function(require,module,exports){ |
19269 | (function (Buffer){ | 23048 | (function (Buffer){ |
19270 | 'use strict' | 23049 | 'use strict' |
19271 | 23050 | ||
19272 | var base58 = require('bs58') | 23051 | var base58 = require('bs58') |
19273 | var createHash = require('create-hash') | ||
19274 | 23052 | ||
19275 | // SHA256(SHA256(buffer)) | 23053 | module.exports = function (checksumFn) { |
19276 | function sha256x2 (buffer) { | 23054 | // Encode a buffer as a base58-check encoded string |
19277 | var tmp = createHash('sha256').update(buffer).digest() | 23055 | function encode (payload) { |
19278 | return createHash('sha256').update(tmp).digest() | 23056 | var checksum = checksumFn(payload) |
19279 | } | ||
19280 | 23057 | ||
19281 | // Encode a buffer as a base58-check encoded string | 23058 | return base58.encode(Buffer.concat([ |
19282 | function encode (payload) { | 23059 | payload, |
19283 | var checksum = sha256x2(payload) | 23060 | checksum |
23061 | ], payload.length + 4)) | ||
23062 | } | ||
19284 | 23063 | ||
19285 | return base58.encode(Buffer.concat([ | 23064 | function decodeRaw (buffer) { |
19286 | payload, | 23065 | var payload = buffer.slice(0, -4) |
19287 | checksum | 23066 | var checksum = buffer.slice(-4) |
19288 | ], payload.length + 4)) | 23067 | var newChecksum = checksumFn(payload) |
19289 | } | ||
19290 | 23068 | ||
19291 | function decodeRaw (buffer) { | 23069 | if (checksum[0] ^ newChecksum[0] | |
19292 | var payload = buffer.slice(0, -4) | 23070 | checksum[1] ^ newChecksum[1] | |
19293 | var checksum = buffer.slice(-4) | 23071 | checksum[2] ^ newChecksum[2] | |
19294 | var newChecksum = sha256x2(payload) | 23072 | checksum[3] ^ newChecksum[3]) return |
19295 | 23073 | ||
19296 | if (checksum[0] ^ newChecksum[0] | | 23074 | return payload |
19297 | checksum[1] ^ newChecksum[1] | | 23075 | } |
19298 | checksum[2] ^ newChecksum[2] | | ||
19299 | checksum[3] ^ newChecksum[3]) return | ||
19300 | 23076 | ||
19301 | return payload | 23077 | // Decode a base58-check encoded string to a buffer, no result if checksum is wrong |
19302 | } | 23078 | function decodeUnsafe (string) { |
23079 | var buffer = base58.decodeUnsafe(string) | ||
23080 | if (!buffer) return | ||
19303 | 23081 | ||
19304 | // Decode a base58-check encoded string to a buffer, no result if checksum is wrong | 23082 | return decodeRaw(buffer) |
19305 | function decodeUnsafe (string) { | 23083 | } |
19306 | var buffer = base58.decodeUnsafe(string) | ||
19307 | if (!buffer) return | ||
19308 | 23084 | ||
19309 | return decodeRaw(buffer) | 23085 | function decode (string) { |
19310 | } | 23086 | var buffer = base58.decode(string) |
23087 | var payload = decodeRaw(buffer, checksumFn) | ||
23088 | if (!payload) throw new Error('Invalid checksum') | ||
23089 | return payload | ||
23090 | } | ||
19311 | 23091 | ||
19312 | function decode (string) { | 23092 | return { |
19313 | var buffer = base58.decode(string) | 23093 | encode: encode, |
19314 | var payload = decodeRaw(buffer) | 23094 | decode: decode, |
19315 | if (!payload) throw new Error('Invalid checksum') | 23095 | decodeUnsafe: decodeUnsafe |
19316 | return payload | 23096 | } |
19317 | } | 23097 | } |
19318 | 23098 | ||
19319 | module.exports = { | 23099 | }).call(this,require("buffer").Buffer) |
19320 | encode: encode, | 23100 | },{"bs58":83,"buffer":5}],85:[function(require,module,exports){ |
19321 | decode: decode, | 23101 | 'use strict' |
19322 | decodeUnsafe: decodeUnsafe | 23102 | |
23103 | var createHash = require('create-hash') | ||
23104 | var bs58checkBase = require('./base') | ||
23105 | |||
23106 | // SHA256(SHA256(buffer)) | ||
23107 | function sha256x2 (buffer) { | ||
23108 | var tmp = createHash('sha256').update(buffer).digest() | ||
23109 | return createHash('sha256').update(tmp).digest() | ||
19323 | } | 23110 | } |
19324 | 23111 | ||
19325 | }).call(this,require("buffer").Buffer) | 23112 | module.exports = bs58checkBase(sha256x2) |
19326 | },{"bs58":79,"buffer":4,"create-hash":82}],81:[function(require,module,exports){ | 23113 | |
23114 | },{"./base":84,"create-hash":87}],86:[function(require,module,exports){ | ||
19327 | var Buffer = require('safe-buffer').Buffer | 23115 | var Buffer = require('safe-buffer').Buffer |
19328 | var Transform = require('stream').Transform | 23116 | var Transform = require('stream').Transform |
19329 | var StringDecoder = require('string_decoder').StringDecoder | 23117 | var StringDecoder = require('string_decoder').StringDecoder |
@@ -19424,7 +23212,7 @@ CipherBase.prototype._toString = function (value, enc, fin) { | |||
19424 | 23212 | ||
19425 | module.exports = CipherBase | 23213 | module.exports = CipherBase |
19426 | 23214 | ||
19427 | },{"inherits":93,"safe-buffer":98,"stream":27,"string_decoder":28}],82:[function(require,module,exports){ | 23215 | },{"inherits":121,"safe-buffer":128,"stream":28,"string_decoder":29}],87:[function(require,module,exports){ |
19428 | (function (Buffer){ | 23216 | (function (Buffer){ |
19429 | 'use strict' | 23217 | 'use strict' |
19430 | var inherits = require('inherits') | 23218 | var inherits = require('inherits') |
@@ -19480,7 +23268,7 @@ module.exports = function createHash (alg) { | |||
19480 | } | 23268 | } |
19481 | 23269 | ||
19482 | }).call(this,require("buffer").Buffer) | 23270 | }).call(this,require("buffer").Buffer) |
19483 | },{"./md5":84,"buffer":4,"cipher-base":81,"inherits":93,"ripemd160":97,"sha.js":100}],83:[function(require,module,exports){ | 23271 | },{"./md5":89,"buffer":5,"cipher-base":86,"inherits":121,"ripemd160":127,"sha.js":130}],88:[function(require,module,exports){ |
19484 | (function (Buffer){ | 23272 | (function (Buffer){ |
19485 | 'use strict' | 23273 | 'use strict' |
19486 | var intSize = 4 | 23274 | var intSize = 4 |
@@ -19514,7 +23302,7 @@ module.exports = function hash (buf, fn) { | |||
19514 | } | 23302 | } |
19515 | 23303 | ||
19516 | }).call(this,require("buffer").Buffer) | 23304 | }).call(this,require("buffer").Buffer) |
19517 | },{"buffer":4}],84:[function(require,module,exports){ | 23305 | },{"buffer":5}],89:[function(require,module,exports){ |
19518 | 'use strict' | 23306 | 'use strict' |
19519 | /* | 23307 | /* |
19520 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message | 23308 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message |
@@ -19667,7 +23455,7 @@ module.exports = function md5 (buf) { | |||
19667 | return makeHash(buf, core_md5) | 23455 | return makeHash(buf, core_md5) |
19668 | } | 23456 | } |
19669 | 23457 | ||
19670 | },{"./make-hash":83}],85:[function(require,module,exports){ | 23458 | },{"./make-hash":88}],90:[function(require,module,exports){ |
19671 | 'use strict' | 23459 | 'use strict' |
19672 | var inherits = require('inherits') | 23460 | var inherits = require('inherits') |
19673 | var Legacy = require('./legacy') | 23461 | var Legacy = require('./legacy') |
@@ -19731,7 +23519,7 @@ module.exports = function createHmac (alg, key) { | |||
19731 | return new Hmac(alg, key) | 23519 | return new Hmac(alg, key) |
19732 | } | 23520 | } |
19733 | 23521 | ||
19734 | },{"./legacy":86,"cipher-base":81,"create-hash/md5":84,"inherits":93,"ripemd160":97,"safe-buffer":98,"sha.js":100}],86:[function(require,module,exports){ | 23522 | },{"./legacy":91,"cipher-base":86,"create-hash/md5":89,"inherits":121,"ripemd160":127,"safe-buffer":128,"sha.js":130}],91:[function(require,module,exports){ |
19735 | 'use strict' | 23523 | 'use strict' |
19736 | var inherits = require('inherits') | 23524 | var inherits = require('inherits') |
19737 | var Buffer = require('safe-buffer').Buffer | 23525 | var Buffer = require('safe-buffer').Buffer |
@@ -19779,7 +23567,7 @@ Hmac.prototype._final = function () { | |||
19779 | } | 23567 | } |
19780 | module.exports = Hmac | 23568 | module.exports = Hmac |
19781 | 23569 | ||
19782 | },{"cipher-base":81,"inherits":93,"safe-buffer":98}],87:[function(require,module,exports){ | 23570 | },{"cipher-base":86,"inherits":121,"safe-buffer":128}],92:[function(require,module,exports){ |
19783 | var assert = require('assert') | 23571 | var assert = require('assert') |
19784 | var BigInteger = require('bigi') | 23572 | var BigInteger = require('bigi') |
19785 | 23573 | ||
@@ -19858,7 +23646,7 @@ Curve.prototype.validate = function (Q) { | |||
19858 | 23646 | ||
19859 | module.exports = Curve | 23647 | module.exports = Curve |
19860 | 23648 | ||
19861 | },{"./point":91,"assert":1,"bigi":37}],88:[function(require,module,exports){ | 23649 | },{"./point":96,"assert":1,"bigi":39}],93:[function(require,module,exports){ |
19862 | module.exports={ | 23650 | module.exports={ |
19863 | "secp128r1": { | 23651 | "secp128r1": { |
19864 | "p": "fffffffdffffffffffffffffffffffff", | 23652 | "p": "fffffffdffffffffffffffffffffffff", |
@@ -19925,7 +23713,7 @@ module.exports={ | |||
19925 | } | 23713 | } |
19926 | } | 23714 | } |
19927 | 23715 | ||
19928 | },{}],89:[function(require,module,exports){ | 23716 | },{}],94:[function(require,module,exports){ |
19929 | var Point = require('./point') | 23717 | var Point = require('./point') |
19930 | var Curve = require('./curve') | 23718 | var Curve = require('./curve') |
19931 | 23719 | ||
@@ -19937,7 +23725,7 @@ module.exports = { | |||
19937 | getCurveByName: getCurveByName | 23725 | getCurveByName: getCurveByName |
19938 | } | 23726 | } |
19939 | 23727 | ||
19940 | },{"./curve":87,"./names":90,"./point":91}],90:[function(require,module,exports){ | 23728 | },{"./curve":92,"./names":95,"./point":96}],95:[function(require,module,exports){ |
19941 | var BigInteger = require('bigi') | 23729 | var BigInteger = require('bigi') |
19942 | 23730 | ||
19943 | var curves = require('./curves.json') | 23731 | var curves = require('./curves.json') |
@@ -19960,7 +23748,7 @@ function getCurveByName (name) { | |||
19960 | 23748 | ||
19961 | module.exports = getCurveByName | 23749 | module.exports = getCurveByName |
19962 | 23750 | ||
19963 | },{"./curve":87,"./curves.json":88,"bigi":37}],91:[function(require,module,exports){ | 23751 | },{"./curve":92,"./curves.json":93,"bigi":39}],96:[function(require,module,exports){ |
19964 | (function (Buffer){ | 23752 | (function (Buffer){ |
19965 | var assert = require('assert') | 23753 | var assert = require('assert') |
19966 | var BigInteger = require('bigi') | 23754 | var BigInteger = require('bigi') |
@@ -20207,7 +23995,3978 @@ Point.prototype.toString = function () { | |||
20207 | module.exports = Point | 23995 | module.exports = Point |
20208 | 23996 | ||
20209 | }).call(this,require("buffer").Buffer) | 23997 | }).call(this,require("buffer").Buffer) |
20210 | },{"assert":1,"bigi":37,"buffer":4}],92:[function(require,module,exports){ | 23998 | },{"assert":1,"bigi":39,"buffer":5}],97:[function(require,module,exports){ |
23999 | 'use strict'; | ||
24000 | |||
24001 | var elliptic = exports; | ||
24002 | |||
24003 | elliptic.version = require('../package.json').version; | ||
24004 | elliptic.utils = require('./elliptic/utils'); | ||
24005 | elliptic.rand = require('brorand'); | ||
24006 | elliptic.curve = require('./elliptic/curve'); | ||
24007 | elliptic.curves = require('./elliptic/curves'); | ||
24008 | |||
24009 | // Protocols | ||
24010 | elliptic.ec = require('./elliptic/ec'); | ||
24011 | elliptic.eddsa = require('./elliptic/eddsa'); | ||
24012 | |||
24013 | },{"../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){ | ||
24014 | 'use strict'; | ||
24015 | |||
24016 | var BN = require('bn.js'); | ||
24017 | var elliptic = require('../../elliptic'); | ||
24018 | var utils = elliptic.utils; | ||
24019 | var getNAF = utils.getNAF; | ||
24020 | var getJSF = utils.getJSF; | ||
24021 | var assert = utils.assert; | ||
24022 | |||
24023 | function BaseCurve(type, conf) { | ||
24024 | this.type = type; | ||
24025 | this.p = new BN(conf.p, 16); | ||
24026 | |||
24027 | // Use Montgomery, when there is no fast reduction for the prime | ||
24028 | this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); | ||
24029 | |||
24030 | // Useful for many curves | ||
24031 | this.zero = new BN(0).toRed(this.red); | ||
24032 | this.one = new BN(1).toRed(this.red); | ||
24033 | this.two = new BN(2).toRed(this.red); | ||
24034 | |||
24035 | // Curve configuration, optional | ||
24036 | this.n = conf.n && new BN(conf.n, 16); | ||
24037 | this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); | ||
24038 | |||
24039 | // Temporary arrays | ||
24040 | this._wnafT1 = new Array(4); | ||
24041 | this._wnafT2 = new Array(4); | ||
24042 | this._wnafT3 = new Array(4); | ||
24043 | this._wnafT4 = new Array(4); | ||
24044 | |||
24045 | // Generalized Greg Maxwell's trick | ||
24046 | var adjustCount = this.n && this.p.div(this.n); | ||
24047 | if (!adjustCount || adjustCount.cmpn(100) > 0) { | ||
24048 | this.redN = null; | ||
24049 | } else { | ||
24050 | this._maxwellTrick = true; | ||
24051 | this.redN = this.n.toRed(this.red); | ||
24052 | } | ||
24053 | } | ||
24054 | module.exports = BaseCurve; | ||
24055 | |||
24056 | BaseCurve.prototype.point = function point() { | ||
24057 | throw new Error('Not implemented'); | ||
24058 | }; | ||
24059 | |||
24060 | BaseCurve.prototype.validate = function validate() { | ||
24061 | throw new Error('Not implemented'); | ||
24062 | }; | ||
24063 | |||
24064 | BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) { | ||
24065 | assert(p.precomputed); | ||
24066 | var doubles = p._getDoubles(); | ||
24067 | |||
24068 | var naf = getNAF(k, 1); | ||
24069 | var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1); | ||
24070 | I /= 3; | ||
24071 | |||
24072 | // Translate into more windowed form | ||
24073 | var repr = []; | ||
24074 | for (var j = 0; j < naf.length; j += doubles.step) { | ||
24075 | var nafW = 0; | ||
24076 | for (var k = j + doubles.step - 1; k >= j; k--) | ||
24077 | nafW = (nafW << 1) + naf[k]; | ||
24078 | repr.push(nafW); | ||
24079 | } | ||
24080 | |||
24081 | var a = this.jpoint(null, null, null); | ||
24082 | var b = this.jpoint(null, null, null); | ||
24083 | for (var i = I; i > 0; i--) { | ||
24084 | for (var j = 0; j < repr.length; j++) { | ||
24085 | var nafW = repr[j]; | ||
24086 | if (nafW === i) | ||
24087 | b = b.mixedAdd(doubles.points[j]); | ||
24088 | else if (nafW === -i) | ||
24089 | b = b.mixedAdd(doubles.points[j].neg()); | ||
24090 | } | ||
24091 | a = a.add(b); | ||
24092 | } | ||
24093 | return a.toP(); | ||
24094 | }; | ||
24095 | |||
24096 | BaseCurve.prototype._wnafMul = function _wnafMul(p, k) { | ||
24097 | var w = 4; | ||
24098 | |||
24099 | // Precompute window | ||
24100 | var nafPoints = p._getNAFPoints(w); | ||
24101 | w = nafPoints.wnd; | ||
24102 | var wnd = nafPoints.points; | ||
24103 | |||
24104 | // Get NAF form | ||
24105 | var naf = getNAF(k, w); | ||
24106 | |||
24107 | // Add `this`*(N+1) for every w-NAF index | ||
24108 | var acc = this.jpoint(null, null, null); | ||
24109 | for (var i = naf.length - 1; i >= 0; i--) { | ||
24110 | // Count zeroes | ||
24111 | for (var k = 0; i >= 0 && naf[i] === 0; i--) | ||
24112 | k++; | ||
24113 | if (i >= 0) | ||
24114 | k++; | ||
24115 | acc = acc.dblp(k); | ||
24116 | |||
24117 | if (i < 0) | ||
24118 | break; | ||
24119 | var z = naf[i]; | ||
24120 | assert(z !== 0); | ||
24121 | if (p.type === 'affine') { | ||
24122 | // J +- P | ||
24123 | if (z > 0) | ||
24124 | acc = acc.mixedAdd(wnd[(z - 1) >> 1]); | ||
24125 | else | ||
24126 | acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg()); | ||
24127 | } else { | ||
24128 | // J +- J | ||
24129 | if (z > 0) | ||
24130 | acc = acc.add(wnd[(z - 1) >> 1]); | ||
24131 | else | ||
24132 | acc = acc.add(wnd[(-z - 1) >> 1].neg()); | ||
24133 | } | ||
24134 | } | ||
24135 | return p.type === 'affine' ? acc.toP() : acc; | ||
24136 | }; | ||
24137 | |||
24138 | BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, | ||
24139 | points, | ||
24140 | coeffs, | ||
24141 | len, | ||
24142 | jacobianResult) { | ||
24143 | var wndWidth = this._wnafT1; | ||
24144 | var wnd = this._wnafT2; | ||
24145 | var naf = this._wnafT3; | ||
24146 | |||
24147 | // Fill all arrays | ||
24148 | var max = 0; | ||
24149 | for (var i = 0; i < len; i++) { | ||
24150 | var p = points[i]; | ||
24151 | var nafPoints = p._getNAFPoints(defW); | ||
24152 | wndWidth[i] = nafPoints.wnd; | ||
24153 | wnd[i] = nafPoints.points; | ||
24154 | } | ||
24155 | |||
24156 | // Comb small window NAFs | ||
24157 | for (var i = len - 1; i >= 1; i -= 2) { | ||
24158 | var a = i - 1; | ||
24159 | var b = i; | ||
24160 | if (wndWidth[a] !== 1 || wndWidth[b] !== 1) { | ||
24161 | naf[a] = getNAF(coeffs[a], wndWidth[a]); | ||
24162 | naf[b] = getNAF(coeffs[b], wndWidth[b]); | ||
24163 | max = Math.max(naf[a].length, max); | ||
24164 | max = Math.max(naf[b].length, max); | ||
24165 | continue; | ||
24166 | } | ||
24167 | |||
24168 | var comb = [ | ||
24169 | points[a], /* 1 */ | ||
24170 | null, /* 3 */ | ||
24171 | null, /* 5 */ | ||
24172 | points[b] /* 7 */ | ||
24173 | ]; | ||
24174 | |||
24175 | // Try to avoid Projective points, if possible | ||
24176 | if (points[a].y.cmp(points[b].y) === 0) { | ||
24177 | comb[1] = points[a].add(points[b]); | ||
24178 | comb[2] = points[a].toJ().mixedAdd(points[b].neg()); | ||
24179 | } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) { | ||
24180 | comb[1] = points[a].toJ().mixedAdd(points[b]); | ||
24181 | comb[2] = points[a].add(points[b].neg()); | ||
24182 | } else { | ||
24183 | comb[1] = points[a].toJ().mixedAdd(points[b]); | ||
24184 | comb[2] = points[a].toJ().mixedAdd(points[b].neg()); | ||
24185 | } | ||
24186 | |||
24187 | var index = [ | ||
24188 | -3, /* -1 -1 */ | ||
24189 | -1, /* -1 0 */ | ||
24190 | -5, /* -1 1 */ | ||
24191 | -7, /* 0 -1 */ | ||
24192 | 0, /* 0 0 */ | ||
24193 | 7, /* 0 1 */ | ||
24194 | 5, /* 1 -1 */ | ||
24195 | 1, /* 1 0 */ | ||
24196 | 3 /* 1 1 */ | ||
24197 | ]; | ||
24198 | |||
24199 | var jsf = getJSF(coeffs[a], coeffs[b]); | ||
24200 | max = Math.max(jsf[0].length, max); | ||
24201 | naf[a] = new Array(max); | ||
24202 | naf[b] = new Array(max); | ||
24203 | for (var j = 0; j < max; j++) { | ||
24204 | var ja = jsf[0][j] | 0; | ||
24205 | var jb = jsf[1][j] | 0; | ||
24206 | |||
24207 | naf[a][j] = index[(ja + 1) * 3 + (jb + 1)]; | ||
24208 | naf[b][j] = 0; | ||
24209 | wnd[a] = comb; | ||
24210 | } | ||
24211 | } | ||
24212 | |||
24213 | var acc = this.jpoint(null, null, null); | ||
24214 | var tmp = this._wnafT4; | ||
24215 | for (var i = max; i >= 0; i--) { | ||
24216 | var k = 0; | ||
24217 | |||
24218 | while (i >= 0) { | ||
24219 | var zero = true; | ||
24220 | for (var j = 0; j < len; j++) { | ||
24221 | tmp[j] = naf[j][i] | 0; | ||
24222 | if (tmp[j] !== 0) | ||
24223 | zero = false; | ||
24224 | } | ||
24225 | if (!zero) | ||
24226 | break; | ||
24227 | k++; | ||
24228 | i--; | ||
24229 | } | ||
24230 | if (i >= 0) | ||
24231 | k++; | ||
24232 | acc = acc.dblp(k); | ||
24233 | if (i < 0) | ||
24234 | break; | ||
24235 | |||
24236 | for (var j = 0; j < len; j++) { | ||
24237 | var z = tmp[j]; | ||
24238 | var p; | ||
24239 | if (z === 0) | ||
24240 | continue; | ||
24241 | else if (z > 0) | ||
24242 | p = wnd[j][(z - 1) >> 1]; | ||
24243 | else if (z < 0) | ||
24244 | p = wnd[j][(-z - 1) >> 1].neg(); | ||
24245 | |||
24246 | if (p.type === 'affine') | ||
24247 | acc = acc.mixedAdd(p); | ||
24248 | else | ||
24249 | acc = acc.add(p); | ||
24250 | } | ||
24251 | } | ||
24252 | // Zeroify references | ||
24253 | for (var i = 0; i < len; i++) | ||
24254 | wnd[i] = null; | ||
24255 | |||
24256 | if (jacobianResult) | ||
24257 | return acc; | ||
24258 | else | ||
24259 | return acc.toP(); | ||
24260 | }; | ||
24261 | |||
24262 | function BasePoint(curve, type) { | ||
24263 | this.curve = curve; | ||
24264 | this.type = type; | ||
24265 | this.precomputed = null; | ||
24266 | } | ||
24267 | BaseCurve.BasePoint = BasePoint; | ||
24268 | |||
24269 | BasePoint.prototype.eq = function eq(/*other*/) { | ||
24270 | throw new Error('Not implemented'); | ||
24271 | }; | ||
24272 | |||
24273 | BasePoint.prototype.validate = function validate() { | ||
24274 | return this.curve.validate(this); | ||
24275 | }; | ||
24276 | |||
24277 | BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) { | ||
24278 | bytes = utils.toArray(bytes, enc); | ||
24279 | |||
24280 | var len = this.p.byteLength(); | ||
24281 | |||
24282 | // uncompressed, hybrid-odd, hybrid-even | ||
24283 | if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && | ||
24284 | bytes.length - 1 === 2 * len) { | ||
24285 | if (bytes[0] === 0x06) | ||
24286 | assert(bytes[bytes.length - 1] % 2 === 0); | ||
24287 | else if (bytes[0] === 0x07) | ||
24288 | assert(bytes[bytes.length - 1] % 2 === 1); | ||
24289 | |||
24290 | var res = this.point(bytes.slice(1, 1 + len), | ||
24291 | bytes.slice(1 + len, 1 + 2 * len)); | ||
24292 | |||
24293 | return res; | ||
24294 | } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && | ||
24295 | bytes.length - 1 === len) { | ||
24296 | return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03); | ||
24297 | } | ||
24298 | throw new Error('Unknown point format'); | ||
24299 | }; | ||
24300 | |||
24301 | BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) { | ||
24302 | return this.encode(enc, true); | ||
24303 | }; | ||
24304 | |||
24305 | BasePoint.prototype._encode = function _encode(compact) { | ||
24306 | var len = this.curve.p.byteLength(); | ||
24307 | var x = this.getX().toArray('be', len); | ||
24308 | |||
24309 | if (compact) | ||
24310 | return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x); | ||
24311 | |||
24312 | return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ; | ||
24313 | }; | ||
24314 | |||
24315 | BasePoint.prototype.encode = function encode(enc, compact) { | ||
24316 | return utils.encode(this._encode(compact), enc); | ||
24317 | }; | ||
24318 | |||
24319 | BasePoint.prototype.precompute = function precompute(power) { | ||
24320 | if (this.precomputed) | ||
24321 | return this; | ||
24322 | |||
24323 | var precomputed = { | ||
24324 | doubles: null, | ||
24325 | naf: null, | ||
24326 | beta: null | ||
24327 | }; | ||
24328 | precomputed.naf = this._getNAFPoints(8); | ||
24329 | precomputed.doubles = this._getDoubles(4, power); | ||
24330 | precomputed.beta = this._getBeta(); | ||
24331 | this.precomputed = precomputed; | ||
24332 | |||
24333 | return this; | ||
24334 | }; | ||
24335 | |||
24336 | BasePoint.prototype._hasDoubles = function _hasDoubles(k) { | ||
24337 | if (!this.precomputed) | ||
24338 | return false; | ||
24339 | |||
24340 | var doubles = this.precomputed.doubles; | ||
24341 | if (!doubles) | ||
24342 | return false; | ||
24343 | |||
24344 | return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step); | ||
24345 | }; | ||
24346 | |||
24347 | BasePoint.prototype._getDoubles = function _getDoubles(step, power) { | ||
24348 | if (this.precomputed && this.precomputed.doubles) | ||
24349 | return this.precomputed.doubles; | ||
24350 | |||
24351 | var doubles = [ this ]; | ||
24352 | var acc = this; | ||
24353 | for (var i = 0; i < power; i += step) { | ||
24354 | for (var j = 0; j < step; j++) | ||
24355 | acc = acc.dbl(); | ||
24356 | doubles.push(acc); | ||
24357 | } | ||
24358 | return { | ||
24359 | step: step, | ||
24360 | points: doubles | ||
24361 | }; | ||
24362 | }; | ||
24363 | |||
24364 | BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) { | ||
24365 | if (this.precomputed && this.precomputed.naf) | ||
24366 | return this.precomputed.naf; | ||
24367 | |||
24368 | var res = [ this ]; | ||
24369 | var max = (1 << wnd) - 1; | ||
24370 | var dbl = max === 1 ? null : this.dbl(); | ||
24371 | for (var i = 1; i < max; i++) | ||
24372 | res[i] = res[i - 1].add(dbl); | ||
24373 | return { | ||
24374 | wnd: wnd, | ||
24375 | points: res | ||
24376 | }; | ||
24377 | }; | ||
24378 | |||
24379 | BasePoint.prototype._getBeta = function _getBeta() { | ||
24380 | return null; | ||
24381 | }; | ||
24382 | |||
24383 | BasePoint.prototype.dblp = function dblp(k) { | ||
24384 | var r = this; | ||
24385 | for (var i = 0; i < k; i++) | ||
24386 | r = r.dbl(); | ||
24387 | return r; | ||
24388 | }; | ||
24389 | |||
24390 | },{"../../elliptic":97,"bn.js":81}],99:[function(require,module,exports){ | ||
24391 | 'use strict'; | ||
24392 | |||
24393 | var curve = require('../curve'); | ||
24394 | var elliptic = require('../../elliptic'); | ||
24395 | var BN = require('bn.js'); | ||
24396 | var inherits = require('inherits'); | ||
24397 | var Base = curve.base; | ||
24398 | |||
24399 | var assert = elliptic.utils.assert; | ||
24400 | |||
24401 | function EdwardsCurve(conf) { | ||
24402 | // NOTE: Important as we are creating point in Base.call() | ||
24403 | this.twisted = (conf.a | 0) !== 1; | ||
24404 | this.mOneA = this.twisted && (conf.a | 0) === -1; | ||
24405 | this.extended = this.mOneA; | ||
24406 | |||
24407 | Base.call(this, 'edwards', conf); | ||
24408 | |||
24409 | this.a = new BN(conf.a, 16).umod(this.red.m); | ||
24410 | this.a = this.a.toRed(this.red); | ||
24411 | this.c = new BN(conf.c, 16).toRed(this.red); | ||
24412 | this.c2 = this.c.redSqr(); | ||
24413 | this.d = new BN(conf.d, 16).toRed(this.red); | ||
24414 | this.dd = this.d.redAdd(this.d); | ||
24415 | |||
24416 | assert(!this.twisted || this.c.fromRed().cmpn(1) === 0); | ||
24417 | this.oneC = (conf.c | 0) === 1; | ||
24418 | } | ||
24419 | inherits(EdwardsCurve, Base); | ||
24420 | module.exports = EdwardsCurve; | ||
24421 | |||
24422 | EdwardsCurve.prototype._mulA = function _mulA(num) { | ||
24423 | if (this.mOneA) | ||
24424 | return num.redNeg(); | ||
24425 | else | ||
24426 | return this.a.redMul(num); | ||
24427 | }; | ||
24428 | |||
24429 | EdwardsCurve.prototype._mulC = function _mulC(num) { | ||
24430 | if (this.oneC) | ||
24431 | return num; | ||
24432 | else | ||
24433 | return this.c.redMul(num); | ||
24434 | }; | ||
24435 | |||
24436 | // Just for compatibility with Short curve | ||
24437 | EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) { | ||
24438 | return this.point(x, y, z, t); | ||
24439 | }; | ||
24440 | |||
24441 | EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
24442 | x = new BN(x, 16); | ||
24443 | if (!x.red) | ||
24444 | x = x.toRed(this.red); | ||
24445 | |||
24446 | var x2 = x.redSqr(); | ||
24447 | var rhs = this.c2.redSub(this.a.redMul(x2)); | ||
24448 | var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2)); | ||
24449 | |||
24450 | var y2 = rhs.redMul(lhs.redInvm()); | ||
24451 | var y = y2.redSqrt(); | ||
24452 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) | ||
24453 | throw new Error('invalid point'); | ||
24454 | |||
24455 | var isOdd = y.fromRed().isOdd(); | ||
24456 | if (odd && !isOdd || !odd && isOdd) | ||
24457 | y = y.redNeg(); | ||
24458 | |||
24459 | return this.point(x, y); | ||
24460 | }; | ||
24461 | |||
24462 | EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { | ||
24463 | y = new BN(y, 16); | ||
24464 | if (!y.red) | ||
24465 | y = y.toRed(this.red); | ||
24466 | |||
24467 | // x^2 = (y^2 - 1) / (d y^2 + 1) | ||
24468 | var y2 = y.redSqr(); | ||
24469 | var lhs = y2.redSub(this.one); | ||
24470 | var rhs = y2.redMul(this.d).redAdd(this.one); | ||
24471 | var x2 = lhs.redMul(rhs.redInvm()); | ||
24472 | |||
24473 | if (x2.cmp(this.zero) === 0) { | ||
24474 | if (odd) | ||
24475 | throw new Error('invalid point'); | ||
24476 | else | ||
24477 | return this.point(this.zero, y); | ||
24478 | } | ||
24479 | |||
24480 | var x = x2.redSqrt(); | ||
24481 | if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) | ||
24482 | throw new Error('invalid point'); | ||
24483 | |||
24484 | if (x.isOdd() !== odd) | ||
24485 | x = x.redNeg(); | ||
24486 | |||
24487 | return this.point(x, y); | ||
24488 | }; | ||
24489 | |||
24490 | EdwardsCurve.prototype.validate = function validate(point) { | ||
24491 | if (point.isInfinity()) | ||
24492 | return true; | ||
24493 | |||
24494 | // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2) | ||
24495 | point.normalize(); | ||
24496 | |||
24497 | var x2 = point.x.redSqr(); | ||
24498 | var y2 = point.y.redSqr(); | ||
24499 | var lhs = x2.redMul(this.a).redAdd(y2); | ||
24500 | var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2))); | ||
24501 | |||
24502 | return lhs.cmp(rhs) === 0; | ||
24503 | }; | ||
24504 | |||
24505 | function Point(curve, x, y, z, t) { | ||
24506 | Base.BasePoint.call(this, curve, 'projective'); | ||
24507 | if (x === null && y === null && z === null) { | ||
24508 | this.x = this.curve.zero; | ||
24509 | this.y = this.curve.one; | ||
24510 | this.z = this.curve.one; | ||
24511 | this.t = this.curve.zero; | ||
24512 | this.zOne = true; | ||
24513 | } else { | ||
24514 | this.x = new BN(x, 16); | ||
24515 | this.y = new BN(y, 16); | ||
24516 | this.z = z ? new BN(z, 16) : this.curve.one; | ||
24517 | this.t = t && new BN(t, 16); | ||
24518 | if (!this.x.red) | ||
24519 | this.x = this.x.toRed(this.curve.red); | ||
24520 | if (!this.y.red) | ||
24521 | this.y = this.y.toRed(this.curve.red); | ||
24522 | if (!this.z.red) | ||
24523 | this.z = this.z.toRed(this.curve.red); | ||
24524 | if (this.t && !this.t.red) | ||
24525 | this.t = this.t.toRed(this.curve.red); | ||
24526 | this.zOne = this.z === this.curve.one; | ||
24527 | |||
24528 | // Use extended coordinates | ||
24529 | if (this.curve.extended && !this.t) { | ||
24530 | this.t = this.x.redMul(this.y); | ||
24531 | if (!this.zOne) | ||
24532 | this.t = this.t.redMul(this.z.redInvm()); | ||
24533 | } | ||
24534 | } | ||
24535 | } | ||
24536 | inherits(Point, Base.BasePoint); | ||
24537 | |||
24538 | EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) { | ||
24539 | return Point.fromJSON(this, obj); | ||
24540 | }; | ||
24541 | |||
24542 | EdwardsCurve.prototype.point = function point(x, y, z, t) { | ||
24543 | return new Point(this, x, y, z, t); | ||
24544 | }; | ||
24545 | |||
24546 | Point.fromJSON = function fromJSON(curve, obj) { | ||
24547 | return new Point(curve, obj[0], obj[1], obj[2]); | ||
24548 | }; | ||
24549 | |||
24550 | Point.prototype.inspect = function inspect() { | ||
24551 | if (this.isInfinity()) | ||
24552 | return '<EC Point Infinity>'; | ||
24553 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
24554 | ' y: ' + this.y.fromRed().toString(16, 2) + | ||
24555 | ' z: ' + this.z.fromRed().toString(16, 2) + '>'; | ||
24556 | }; | ||
24557 | |||
24558 | Point.prototype.isInfinity = function isInfinity() { | ||
24559 | // XXX This code assumes that zero is always zero in red | ||
24560 | return this.x.cmpn(0) === 0 && | ||
24561 | this.y.cmp(this.z) === 0; | ||
24562 | }; | ||
24563 | |||
24564 | Point.prototype._extDbl = function _extDbl() { | ||
24565 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html | ||
24566 | // #doubling-dbl-2008-hwcd | ||
24567 | // 4M + 4S | ||
24568 | |||
24569 | // A = X1^2 | ||
24570 | var a = this.x.redSqr(); | ||
24571 | // B = Y1^2 | ||
24572 | var b = this.y.redSqr(); | ||
24573 | // C = 2 * Z1^2 | ||
24574 | var c = this.z.redSqr(); | ||
24575 | c = c.redIAdd(c); | ||
24576 | // D = a * A | ||
24577 | var d = this.curve._mulA(a); | ||
24578 | // E = (X1 + Y1)^2 - A - B | ||
24579 | var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); | ||
24580 | // G = D + B | ||
24581 | var g = d.redAdd(b); | ||
24582 | // F = G - C | ||
24583 | var f = g.redSub(c); | ||
24584 | // H = D - B | ||
24585 | var h = d.redSub(b); | ||
24586 | // X3 = E * F | ||
24587 | var nx = e.redMul(f); | ||
24588 | // Y3 = G * H | ||
24589 | var ny = g.redMul(h); | ||
24590 | // T3 = E * H | ||
24591 | var nt = e.redMul(h); | ||
24592 | // Z3 = F * G | ||
24593 | var nz = f.redMul(g); | ||
24594 | return this.curve.point(nx, ny, nz, nt); | ||
24595 | }; | ||
24596 | |||
24597 | Point.prototype._projDbl = function _projDbl() { | ||
24598 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html | ||
24599 | // #doubling-dbl-2008-bbjlp | ||
24600 | // #doubling-dbl-2007-bl | ||
24601 | // and others | ||
24602 | // Generally 3M + 4S or 2M + 4S | ||
24603 | |||
24604 | // B = (X1 + Y1)^2 | ||
24605 | var b = this.x.redAdd(this.y).redSqr(); | ||
24606 | // C = X1^2 | ||
24607 | var c = this.x.redSqr(); | ||
24608 | // D = Y1^2 | ||
24609 | var d = this.y.redSqr(); | ||
24610 | |||
24611 | var nx; | ||
24612 | var ny; | ||
24613 | var nz; | ||
24614 | if (this.curve.twisted) { | ||
24615 | // E = a * C | ||
24616 | var e = this.curve._mulA(c); | ||
24617 | // F = E + D | ||
24618 | var f = e.redAdd(d); | ||
24619 | if (this.zOne) { | ||
24620 | // X3 = (B - C - D) * (F - 2) | ||
24621 | nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); | ||
24622 | // Y3 = F * (E - D) | ||
24623 | ny = f.redMul(e.redSub(d)); | ||
24624 | // Z3 = F^2 - 2 * F | ||
24625 | nz = f.redSqr().redSub(f).redSub(f); | ||
24626 | } else { | ||
24627 | // H = Z1^2 | ||
24628 | var h = this.z.redSqr(); | ||
24629 | // J = F - 2 * H | ||
24630 | var j = f.redSub(h).redISub(h); | ||
24631 | // X3 = (B-C-D)*J | ||
24632 | nx = b.redSub(c).redISub(d).redMul(j); | ||
24633 | // Y3 = F * (E - D) | ||
24634 | ny = f.redMul(e.redSub(d)); | ||
24635 | // Z3 = F * J | ||
24636 | nz = f.redMul(j); | ||
24637 | } | ||
24638 | } else { | ||
24639 | // E = C + D | ||
24640 | var e = c.redAdd(d); | ||
24641 | // H = (c * Z1)^2 | ||
24642 | var h = this.curve._mulC(this.c.redMul(this.z)).redSqr(); | ||
24643 | // J = E - 2 * H | ||
24644 | var j = e.redSub(h).redSub(h); | ||
24645 | // X3 = c * (B - E) * J | ||
24646 | nx = this.curve._mulC(b.redISub(e)).redMul(j); | ||
24647 | // Y3 = c * E * (C - D) | ||
24648 | ny = this.curve._mulC(e).redMul(c.redISub(d)); | ||
24649 | // Z3 = E * J | ||
24650 | nz = e.redMul(j); | ||
24651 | } | ||
24652 | return this.curve.point(nx, ny, nz); | ||
24653 | }; | ||
24654 | |||
24655 | Point.prototype.dbl = function dbl() { | ||
24656 | if (this.isInfinity()) | ||
24657 | return this; | ||
24658 | |||
24659 | // Double in extended coordinates | ||
24660 | if (this.curve.extended) | ||
24661 | return this._extDbl(); | ||
24662 | else | ||
24663 | return this._projDbl(); | ||
24664 | }; | ||
24665 | |||
24666 | Point.prototype._extAdd = function _extAdd(p) { | ||
24667 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html | ||
24668 | // #addition-add-2008-hwcd-3 | ||
24669 | // 8M | ||
24670 | |||
24671 | // A = (Y1 - X1) * (Y2 - X2) | ||
24672 | var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); | ||
24673 | // B = (Y1 + X1) * (Y2 + X2) | ||
24674 | var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); | ||
24675 | // C = T1 * k * T2 | ||
24676 | var c = this.t.redMul(this.curve.dd).redMul(p.t); | ||
24677 | // D = Z1 * 2 * Z2 | ||
24678 | var d = this.z.redMul(p.z.redAdd(p.z)); | ||
24679 | // E = B - A | ||
24680 | var e = b.redSub(a); | ||
24681 | // F = D - C | ||
24682 | var f = d.redSub(c); | ||
24683 | // G = D + C | ||
24684 | var g = d.redAdd(c); | ||
24685 | // H = B + A | ||
24686 | var h = b.redAdd(a); | ||
24687 | // X3 = E * F | ||
24688 | var nx = e.redMul(f); | ||
24689 | // Y3 = G * H | ||
24690 | var ny = g.redMul(h); | ||
24691 | // T3 = E * H | ||
24692 | var nt = e.redMul(h); | ||
24693 | // Z3 = F * G | ||
24694 | var nz = f.redMul(g); | ||
24695 | return this.curve.point(nx, ny, nz, nt); | ||
24696 | }; | ||
24697 | |||
24698 | Point.prototype._projAdd = function _projAdd(p) { | ||
24699 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html | ||
24700 | // #addition-add-2008-bbjlp | ||
24701 | // #addition-add-2007-bl | ||
24702 | // 10M + 1S | ||
24703 | |||
24704 | // A = Z1 * Z2 | ||
24705 | var a = this.z.redMul(p.z); | ||
24706 | // B = A^2 | ||
24707 | var b = a.redSqr(); | ||
24708 | // C = X1 * X2 | ||
24709 | var c = this.x.redMul(p.x); | ||
24710 | // D = Y1 * Y2 | ||
24711 | var d = this.y.redMul(p.y); | ||
24712 | // E = d * C * D | ||
24713 | var e = this.curve.d.redMul(c).redMul(d); | ||
24714 | // F = B - E | ||
24715 | var f = b.redSub(e); | ||
24716 | // G = B + E | ||
24717 | var g = b.redAdd(e); | ||
24718 | // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D) | ||
24719 | var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d); | ||
24720 | var nx = a.redMul(f).redMul(tmp); | ||
24721 | var ny; | ||
24722 | var nz; | ||
24723 | if (this.curve.twisted) { | ||
24724 | // Y3 = A * G * (D - a * C) | ||
24725 | ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); | ||
24726 | // Z3 = F * G | ||
24727 | nz = f.redMul(g); | ||
24728 | } else { | ||
24729 | // Y3 = A * G * (D - C) | ||
24730 | ny = a.redMul(g).redMul(d.redSub(c)); | ||
24731 | // Z3 = c * F * G | ||
24732 | nz = this.curve._mulC(f).redMul(g); | ||
24733 | } | ||
24734 | return this.curve.point(nx, ny, nz); | ||
24735 | }; | ||
24736 | |||
24737 | Point.prototype.add = function add(p) { | ||
24738 | if (this.isInfinity()) | ||
24739 | return p; | ||
24740 | if (p.isInfinity()) | ||
24741 | return this; | ||
24742 | |||
24743 | if (this.curve.extended) | ||
24744 | return this._extAdd(p); | ||
24745 | else | ||
24746 | return this._projAdd(p); | ||
24747 | }; | ||
24748 | |||
24749 | Point.prototype.mul = function mul(k) { | ||
24750 | if (this._hasDoubles(k)) | ||
24751 | return this.curve._fixedNafMul(this, k); | ||
24752 | else | ||
24753 | return this.curve._wnafMul(this, k); | ||
24754 | }; | ||
24755 | |||
24756 | Point.prototype.mulAdd = function mulAdd(k1, p, k2) { | ||
24757 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false); | ||
24758 | }; | ||
24759 | |||
24760 | Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) { | ||
24761 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true); | ||
24762 | }; | ||
24763 | |||
24764 | Point.prototype.normalize = function normalize() { | ||
24765 | if (this.zOne) | ||
24766 | return this; | ||
24767 | |||
24768 | // Normalize coordinates | ||
24769 | var zi = this.z.redInvm(); | ||
24770 | this.x = this.x.redMul(zi); | ||
24771 | this.y = this.y.redMul(zi); | ||
24772 | if (this.t) | ||
24773 | this.t = this.t.redMul(zi); | ||
24774 | this.z = this.curve.one; | ||
24775 | this.zOne = true; | ||
24776 | return this; | ||
24777 | }; | ||
24778 | |||
24779 | Point.prototype.neg = function neg() { | ||
24780 | return this.curve.point(this.x.redNeg(), | ||
24781 | this.y, | ||
24782 | this.z, | ||
24783 | this.t && this.t.redNeg()); | ||
24784 | }; | ||
24785 | |||
24786 | Point.prototype.getX = function getX() { | ||
24787 | this.normalize(); | ||
24788 | return this.x.fromRed(); | ||
24789 | }; | ||
24790 | |||
24791 | Point.prototype.getY = function getY() { | ||
24792 | this.normalize(); | ||
24793 | return this.y.fromRed(); | ||
24794 | }; | ||
24795 | |||
24796 | Point.prototype.eq = function eq(other) { | ||
24797 | return this === other || | ||
24798 | this.getX().cmp(other.getX()) === 0 && | ||
24799 | this.getY().cmp(other.getY()) === 0; | ||
24800 | }; | ||
24801 | |||
24802 | Point.prototype.eqXToP = function eqXToP(x) { | ||
24803 | var rx = x.toRed(this.curve.red).redMul(this.z); | ||
24804 | if (this.x.cmp(rx) === 0) | ||
24805 | return true; | ||
24806 | |||
24807 | var xc = x.clone(); | ||
24808 | var t = this.curve.redN.redMul(this.z); | ||
24809 | for (;;) { | ||
24810 | xc.iadd(this.curve.n); | ||
24811 | if (xc.cmp(this.curve.p) >= 0) | ||
24812 | return false; | ||
24813 | |||
24814 | rx.redIAdd(t); | ||
24815 | if (this.x.cmp(rx) === 0) | ||
24816 | return true; | ||
24817 | } | ||
24818 | return false; | ||
24819 | }; | ||
24820 | |||
24821 | // Compatibility with BaseCurve | ||
24822 | Point.prototype.toP = Point.prototype.normalize; | ||
24823 | Point.prototype.mixedAdd = Point.prototype.add; | ||
24824 | |||
24825 | },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],100:[function(require,module,exports){ | ||
24826 | 'use strict'; | ||
24827 | |||
24828 | var curve = exports; | ||
24829 | |||
24830 | curve.base = require('./base'); | ||
24831 | curve.short = require('./short'); | ||
24832 | curve.mont = require('./mont'); | ||
24833 | curve.edwards = require('./edwards'); | ||
24834 | |||
24835 | },{"./base":98,"./edwards":99,"./mont":101,"./short":102}],101:[function(require,module,exports){ | ||
24836 | 'use strict'; | ||
24837 | |||
24838 | var curve = require('../curve'); | ||
24839 | var BN = require('bn.js'); | ||
24840 | var inherits = require('inherits'); | ||
24841 | var Base = curve.base; | ||
24842 | |||
24843 | var elliptic = require('../../elliptic'); | ||
24844 | var utils = elliptic.utils; | ||
24845 | |||
24846 | function MontCurve(conf) { | ||
24847 | Base.call(this, 'mont', conf); | ||
24848 | |||
24849 | this.a = new BN(conf.a, 16).toRed(this.red); | ||
24850 | this.b = new BN(conf.b, 16).toRed(this.red); | ||
24851 | this.i4 = new BN(4).toRed(this.red).redInvm(); | ||
24852 | this.two = new BN(2).toRed(this.red); | ||
24853 | this.a24 = this.i4.redMul(this.a.redAdd(this.two)); | ||
24854 | } | ||
24855 | inherits(MontCurve, Base); | ||
24856 | module.exports = MontCurve; | ||
24857 | |||
24858 | MontCurve.prototype.validate = function validate(point) { | ||
24859 | var x = point.normalize().x; | ||
24860 | var x2 = x.redSqr(); | ||
24861 | var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x); | ||
24862 | var y = rhs.redSqrt(); | ||
24863 | |||
24864 | return y.redSqr().cmp(rhs) === 0; | ||
24865 | }; | ||
24866 | |||
24867 | function Point(curve, x, z) { | ||
24868 | Base.BasePoint.call(this, curve, 'projective'); | ||
24869 | if (x === null && z === null) { | ||
24870 | this.x = this.curve.one; | ||
24871 | this.z = this.curve.zero; | ||
24872 | } else { | ||
24873 | this.x = new BN(x, 16); | ||
24874 | this.z = new BN(z, 16); | ||
24875 | if (!this.x.red) | ||
24876 | this.x = this.x.toRed(this.curve.red); | ||
24877 | if (!this.z.red) | ||
24878 | this.z = this.z.toRed(this.curve.red); | ||
24879 | } | ||
24880 | } | ||
24881 | inherits(Point, Base.BasePoint); | ||
24882 | |||
24883 | MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) { | ||
24884 | return this.point(utils.toArray(bytes, enc), 1); | ||
24885 | }; | ||
24886 | |||
24887 | MontCurve.prototype.point = function point(x, z) { | ||
24888 | return new Point(this, x, z); | ||
24889 | }; | ||
24890 | |||
24891 | MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) { | ||
24892 | return Point.fromJSON(this, obj); | ||
24893 | }; | ||
24894 | |||
24895 | Point.prototype.precompute = function precompute() { | ||
24896 | // No-op | ||
24897 | }; | ||
24898 | |||
24899 | Point.prototype._encode = function _encode() { | ||
24900 | return this.getX().toArray('be', this.curve.p.byteLength()); | ||
24901 | }; | ||
24902 | |||
24903 | Point.fromJSON = function fromJSON(curve, obj) { | ||
24904 | return new Point(curve, obj[0], obj[1] || curve.one); | ||
24905 | }; | ||
24906 | |||
24907 | Point.prototype.inspect = function inspect() { | ||
24908 | if (this.isInfinity()) | ||
24909 | return '<EC Point Infinity>'; | ||
24910 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
24911 | ' z: ' + this.z.fromRed().toString(16, 2) + '>'; | ||
24912 | }; | ||
24913 | |||
24914 | Point.prototype.isInfinity = function isInfinity() { | ||
24915 | // XXX This code assumes that zero is always zero in red | ||
24916 | return this.z.cmpn(0) === 0; | ||
24917 | }; | ||
24918 | |||
24919 | Point.prototype.dbl = function dbl() { | ||
24920 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3 | ||
24921 | // 2M + 2S + 4A | ||
24922 | |||
24923 | // A = X1 + Z1 | ||
24924 | var a = this.x.redAdd(this.z); | ||
24925 | // AA = A^2 | ||
24926 | var aa = a.redSqr(); | ||
24927 | // B = X1 - Z1 | ||
24928 | var b = this.x.redSub(this.z); | ||
24929 | // BB = B^2 | ||
24930 | var bb = b.redSqr(); | ||
24931 | // C = AA - BB | ||
24932 | var c = aa.redSub(bb); | ||
24933 | // X3 = AA * BB | ||
24934 | var nx = aa.redMul(bb); | ||
24935 | // Z3 = C * (BB + A24 * C) | ||
24936 | var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c))); | ||
24937 | return this.curve.point(nx, nz); | ||
24938 | }; | ||
24939 | |||
24940 | Point.prototype.add = function add() { | ||
24941 | throw new Error('Not supported on Montgomery curve'); | ||
24942 | }; | ||
24943 | |||
24944 | Point.prototype.diffAdd = function diffAdd(p, diff) { | ||
24945 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3 | ||
24946 | // 4M + 2S + 6A | ||
24947 | |||
24948 | // A = X2 + Z2 | ||
24949 | var a = this.x.redAdd(this.z); | ||
24950 | // B = X2 - Z2 | ||
24951 | var b = this.x.redSub(this.z); | ||
24952 | // C = X3 + Z3 | ||
24953 | var c = p.x.redAdd(p.z); | ||
24954 | // D = X3 - Z3 | ||
24955 | var d = p.x.redSub(p.z); | ||
24956 | // DA = D * A | ||
24957 | var da = d.redMul(a); | ||
24958 | // CB = C * B | ||
24959 | var cb = c.redMul(b); | ||
24960 | // X5 = Z1 * (DA + CB)^2 | ||
24961 | var nx = diff.z.redMul(da.redAdd(cb).redSqr()); | ||
24962 | // Z5 = X1 * (DA - CB)^2 | ||
24963 | var nz = diff.x.redMul(da.redISub(cb).redSqr()); | ||
24964 | return this.curve.point(nx, nz); | ||
24965 | }; | ||
24966 | |||
24967 | Point.prototype.mul = function mul(k) { | ||
24968 | var t = k.clone(); | ||
24969 | var a = this; // (N / 2) * Q + Q | ||
24970 | var b = this.curve.point(null, null); // (N / 2) * Q | ||
24971 | var c = this; // Q | ||
24972 | |||
24973 | for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) | ||
24974 | bits.push(t.andln(1)); | ||
24975 | |||
24976 | for (var i = bits.length - 1; i >= 0; i--) { | ||
24977 | if (bits[i] === 0) { | ||
24978 | // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q | ||
24979 | a = a.diffAdd(b, c); | ||
24980 | // N * Q = 2 * ((N / 2) * Q + Q)) | ||
24981 | b = b.dbl(); | ||
24982 | } else { | ||
24983 | // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q) | ||
24984 | b = a.diffAdd(b, c); | ||
24985 | // N * Q + Q = 2 * ((N / 2) * Q + Q) | ||
24986 | a = a.dbl(); | ||
24987 | } | ||
24988 | } | ||
24989 | return b; | ||
24990 | }; | ||
24991 | |||
24992 | Point.prototype.mulAdd = function mulAdd() { | ||
24993 | throw new Error('Not supported on Montgomery curve'); | ||
24994 | }; | ||
24995 | |||
24996 | Point.prototype.jumlAdd = function jumlAdd() { | ||
24997 | throw new Error('Not supported on Montgomery curve'); | ||
24998 | }; | ||
24999 | |||
25000 | Point.prototype.eq = function eq(other) { | ||
25001 | return this.getX().cmp(other.getX()) === 0; | ||
25002 | }; | ||
25003 | |||
25004 | Point.prototype.normalize = function normalize() { | ||
25005 | this.x = this.x.redMul(this.z.redInvm()); | ||
25006 | this.z = this.curve.one; | ||
25007 | return this; | ||
25008 | }; | ||
25009 | |||
25010 | Point.prototype.getX = function getX() { | ||
25011 | // Normalize coordinates | ||
25012 | this.normalize(); | ||
25013 | |||
25014 | return this.x.fromRed(); | ||
25015 | }; | ||
25016 | |||
25017 | },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],102:[function(require,module,exports){ | ||
25018 | 'use strict'; | ||
25019 | |||
25020 | var curve = require('../curve'); | ||
25021 | var elliptic = require('../../elliptic'); | ||
25022 | var BN = require('bn.js'); | ||
25023 | var inherits = require('inherits'); | ||
25024 | var Base = curve.base; | ||
25025 | |||
25026 | var assert = elliptic.utils.assert; | ||
25027 | |||
25028 | function ShortCurve(conf) { | ||
25029 | Base.call(this, 'short', conf); | ||
25030 | |||
25031 | this.a = new BN(conf.a, 16).toRed(this.red); | ||
25032 | this.b = new BN(conf.b, 16).toRed(this.red); | ||
25033 | this.tinv = this.two.redInvm(); | ||
25034 | |||
25035 | this.zeroA = this.a.fromRed().cmpn(0) === 0; | ||
25036 | this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; | ||
25037 | |||
25038 | // If the curve is endomorphic, precalculate beta and lambda | ||
25039 | this.endo = this._getEndomorphism(conf); | ||
25040 | this._endoWnafT1 = new Array(4); | ||
25041 | this._endoWnafT2 = new Array(4); | ||
25042 | } | ||
25043 | inherits(ShortCurve, Base); | ||
25044 | module.exports = ShortCurve; | ||
25045 | |||
25046 | ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) { | ||
25047 | // No efficient endomorphism | ||
25048 | if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) | ||
25049 | return; | ||
25050 | |||
25051 | // Compute beta and lambda, that lambda * P = (beta * Px; Py) | ||
25052 | var beta; | ||
25053 | var lambda; | ||
25054 | if (conf.beta) { | ||
25055 | beta = new BN(conf.beta, 16).toRed(this.red); | ||
25056 | } else { | ||
25057 | var betas = this._getEndoRoots(this.p); | ||
25058 | // Choose the smallest beta | ||
25059 | beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1]; | ||
25060 | beta = beta.toRed(this.red); | ||
25061 | } | ||
25062 | if (conf.lambda) { | ||
25063 | lambda = new BN(conf.lambda, 16); | ||
25064 | } else { | ||
25065 | // Choose the lambda that is matching selected beta | ||
25066 | var lambdas = this._getEndoRoots(this.n); | ||
25067 | if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) { | ||
25068 | lambda = lambdas[0]; | ||
25069 | } else { | ||
25070 | lambda = lambdas[1]; | ||
25071 | assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0); | ||
25072 | } | ||
25073 | } | ||
25074 | |||
25075 | // Get basis vectors, used for balanced length-two representation | ||
25076 | var basis; | ||
25077 | if (conf.basis) { | ||
25078 | basis = conf.basis.map(function(vec) { | ||
25079 | return { | ||
25080 | a: new BN(vec.a, 16), | ||
25081 | b: new BN(vec.b, 16) | ||
25082 | }; | ||
25083 | }); | ||
25084 | } else { | ||
25085 | basis = this._getEndoBasis(lambda); | ||
25086 | } | ||
25087 | |||
25088 | return { | ||
25089 | beta: beta, | ||
25090 | lambda: lambda, | ||
25091 | basis: basis | ||
25092 | }; | ||
25093 | }; | ||
25094 | |||
25095 | ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) { | ||
25096 | // Find roots of for x^2 + x + 1 in F | ||
25097 | // Root = (-1 +- Sqrt(-3)) / 2 | ||
25098 | // | ||
25099 | var red = num === this.p ? this.red : BN.mont(num); | ||
25100 | var tinv = new BN(2).toRed(red).redInvm(); | ||
25101 | var ntinv = tinv.redNeg(); | ||
25102 | |||
25103 | var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv); | ||
25104 | |||
25105 | var l1 = ntinv.redAdd(s).fromRed(); | ||
25106 | var l2 = ntinv.redSub(s).fromRed(); | ||
25107 | return [ l1, l2 ]; | ||
25108 | }; | ||
25109 | |||
25110 | ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) { | ||
25111 | // aprxSqrt >= sqrt(this.n) | ||
25112 | var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); | ||
25113 | |||
25114 | // 3.74 | ||
25115 | // Run EGCD, until r(L + 1) < aprxSqrt | ||
25116 | var u = lambda; | ||
25117 | var v = this.n.clone(); | ||
25118 | var x1 = new BN(1); | ||
25119 | var y1 = new BN(0); | ||
25120 | var x2 = new BN(0); | ||
25121 | var y2 = new BN(1); | ||
25122 | |||
25123 | // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) | ||
25124 | var a0; | ||
25125 | var b0; | ||
25126 | // First vector | ||
25127 | var a1; | ||
25128 | var b1; | ||
25129 | // Second vector | ||
25130 | var a2; | ||
25131 | var b2; | ||
25132 | |||
25133 | var prevR; | ||
25134 | var i = 0; | ||
25135 | var r; | ||
25136 | var x; | ||
25137 | while (u.cmpn(0) !== 0) { | ||
25138 | var q = v.div(u); | ||
25139 | r = v.sub(q.mul(u)); | ||
25140 | x = x2.sub(q.mul(x1)); | ||
25141 | var y = y2.sub(q.mul(y1)); | ||
25142 | |||
25143 | if (!a1 && r.cmp(aprxSqrt) < 0) { | ||
25144 | a0 = prevR.neg(); | ||
25145 | b0 = x1; | ||
25146 | a1 = r.neg(); | ||
25147 | b1 = x; | ||
25148 | } else if (a1 && ++i === 2) { | ||
25149 | break; | ||
25150 | } | ||
25151 | prevR = r; | ||
25152 | |||
25153 | v = u; | ||
25154 | u = r; | ||
25155 | x2 = x1; | ||
25156 | x1 = x; | ||
25157 | y2 = y1; | ||
25158 | y1 = y; | ||
25159 | } | ||
25160 | a2 = r.neg(); | ||
25161 | b2 = x; | ||
25162 | |||
25163 | var len1 = a1.sqr().add(b1.sqr()); | ||
25164 | var len2 = a2.sqr().add(b2.sqr()); | ||
25165 | if (len2.cmp(len1) >= 0) { | ||
25166 | a2 = a0; | ||
25167 | b2 = b0; | ||
25168 | } | ||
25169 | |||
25170 | // Normalize signs | ||
25171 | if (a1.negative) { | ||
25172 | a1 = a1.neg(); | ||
25173 | b1 = b1.neg(); | ||
25174 | } | ||
25175 | if (a2.negative) { | ||
25176 | a2 = a2.neg(); | ||
25177 | b2 = b2.neg(); | ||
25178 | } | ||
25179 | |||
25180 | return [ | ||
25181 | { a: a1, b: b1 }, | ||
25182 | { a: a2, b: b2 } | ||
25183 | ]; | ||
25184 | }; | ||
25185 | |||
25186 | ShortCurve.prototype._endoSplit = function _endoSplit(k) { | ||
25187 | var basis = this.endo.basis; | ||
25188 | var v1 = basis[0]; | ||
25189 | var v2 = basis[1]; | ||
25190 | |||
25191 | var c1 = v2.b.mul(k).divRound(this.n); | ||
25192 | var c2 = v1.b.neg().mul(k).divRound(this.n); | ||
25193 | |||
25194 | var p1 = c1.mul(v1.a); | ||
25195 | var p2 = c2.mul(v2.a); | ||
25196 | var q1 = c1.mul(v1.b); | ||
25197 | var q2 = c2.mul(v2.b); | ||
25198 | |||
25199 | // Calculate answer | ||
25200 | var k1 = k.sub(p1).sub(p2); | ||
25201 | var k2 = q1.add(q2).neg(); | ||
25202 | return { k1: k1, k2: k2 }; | ||
25203 | }; | ||
25204 | |||
25205 | ShortCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
25206 | x = new BN(x, 16); | ||
25207 | if (!x.red) | ||
25208 | x = x.toRed(this.red); | ||
25209 | |||
25210 | var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b); | ||
25211 | var y = y2.redSqrt(); | ||
25212 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) | ||
25213 | throw new Error('invalid point'); | ||
25214 | |||
25215 | // XXX Is there any way to tell if the number is odd without converting it | ||
25216 | // to non-red form? | ||
25217 | var isOdd = y.fromRed().isOdd(); | ||
25218 | if (odd && !isOdd || !odd && isOdd) | ||
25219 | y = y.redNeg(); | ||
25220 | |||
25221 | return this.point(x, y); | ||
25222 | }; | ||
25223 | |||
25224 | ShortCurve.prototype.validate = function validate(point) { | ||
25225 | if (point.inf) | ||
25226 | return true; | ||
25227 | |||
25228 | var x = point.x; | ||
25229 | var y = point.y; | ||
25230 | |||
25231 | var ax = this.a.redMul(x); | ||
25232 | var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b); | ||
25233 | return y.redSqr().redISub(rhs).cmpn(0) === 0; | ||
25234 | }; | ||
25235 | |||
25236 | ShortCurve.prototype._endoWnafMulAdd = | ||
25237 | function _endoWnafMulAdd(points, coeffs, jacobianResult) { | ||
25238 | var npoints = this._endoWnafT1; | ||
25239 | var ncoeffs = this._endoWnafT2; | ||
25240 | for (var i = 0; i < points.length; i++) { | ||
25241 | var split = this._endoSplit(coeffs[i]); | ||
25242 | var p = points[i]; | ||
25243 | var beta = p._getBeta(); | ||
25244 | |||
25245 | if (split.k1.negative) { | ||
25246 | split.k1.ineg(); | ||
25247 | p = p.neg(true); | ||
25248 | } | ||
25249 | if (split.k2.negative) { | ||
25250 | split.k2.ineg(); | ||
25251 | beta = beta.neg(true); | ||
25252 | } | ||
25253 | |||
25254 | npoints[i * 2] = p; | ||
25255 | npoints[i * 2 + 1] = beta; | ||
25256 | ncoeffs[i * 2] = split.k1; | ||
25257 | ncoeffs[i * 2 + 1] = split.k2; | ||
25258 | } | ||
25259 | var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); | ||
25260 | |||
25261 | // Clean-up references to points and coefficients | ||
25262 | for (var j = 0; j < i * 2; j++) { | ||
25263 | npoints[j] = null; | ||
25264 | ncoeffs[j] = null; | ||
25265 | } | ||
25266 | return res; | ||
25267 | }; | ||
25268 | |||
25269 | function Point(curve, x, y, isRed) { | ||
25270 | Base.BasePoint.call(this, curve, 'affine'); | ||
25271 | if (x === null && y === null) { | ||
25272 | this.x = null; | ||
25273 | this.y = null; | ||
25274 | this.inf = true; | ||
25275 | } else { | ||
25276 | this.x = new BN(x, 16); | ||
25277 | this.y = new BN(y, 16); | ||
25278 | // Force redgomery representation when loading from JSON | ||
25279 | if (isRed) { | ||
25280 | this.x.forceRed(this.curve.red); | ||
25281 | this.y.forceRed(this.curve.red); | ||
25282 | } | ||
25283 | if (!this.x.red) | ||
25284 | this.x = this.x.toRed(this.curve.red); | ||
25285 | if (!this.y.red) | ||
25286 | this.y = this.y.toRed(this.curve.red); | ||
25287 | this.inf = false; | ||
25288 | } | ||
25289 | } | ||
25290 | inherits(Point, Base.BasePoint); | ||
25291 | |||
25292 | ShortCurve.prototype.point = function point(x, y, isRed) { | ||
25293 | return new Point(this, x, y, isRed); | ||
25294 | }; | ||
25295 | |||
25296 | ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) { | ||
25297 | return Point.fromJSON(this, obj, red); | ||
25298 | }; | ||
25299 | |||
25300 | Point.prototype._getBeta = function _getBeta() { | ||
25301 | if (!this.curve.endo) | ||
25302 | return; | ||
25303 | |||
25304 | var pre = this.precomputed; | ||
25305 | if (pre && pre.beta) | ||
25306 | return pre.beta; | ||
25307 | |||
25308 | var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y); | ||
25309 | if (pre) { | ||
25310 | var curve = this.curve; | ||
25311 | var endoMul = function(p) { | ||
25312 | return curve.point(p.x.redMul(curve.endo.beta), p.y); | ||
25313 | }; | ||
25314 | pre.beta = beta; | ||
25315 | beta.precomputed = { | ||
25316 | beta: null, | ||
25317 | naf: pre.naf && { | ||
25318 | wnd: pre.naf.wnd, | ||
25319 | points: pre.naf.points.map(endoMul) | ||
25320 | }, | ||
25321 | doubles: pre.doubles && { | ||
25322 | step: pre.doubles.step, | ||
25323 | points: pre.doubles.points.map(endoMul) | ||
25324 | } | ||
25325 | }; | ||
25326 | } | ||
25327 | return beta; | ||
25328 | }; | ||
25329 | |||
25330 | Point.prototype.toJSON = function toJSON() { | ||
25331 | if (!this.precomputed) | ||
25332 | return [ this.x, this.y ]; | ||
25333 | |||
25334 | return [ this.x, this.y, this.precomputed && { | ||
25335 | doubles: this.precomputed.doubles && { | ||
25336 | step: this.precomputed.doubles.step, | ||
25337 | points: this.precomputed.doubles.points.slice(1) | ||
25338 | }, | ||
25339 | naf: this.precomputed.naf && { | ||
25340 | wnd: this.precomputed.naf.wnd, | ||
25341 | points: this.precomputed.naf.points.slice(1) | ||
25342 | } | ||
25343 | } ]; | ||
25344 | }; | ||
25345 | |||
25346 | Point.fromJSON = function fromJSON(curve, obj, red) { | ||
25347 | if (typeof obj === 'string') | ||
25348 | obj = JSON.parse(obj); | ||
25349 | var res = curve.point(obj[0], obj[1], red); | ||
25350 | if (!obj[2]) | ||
25351 | return res; | ||
25352 | |||
25353 | function obj2point(obj) { | ||
25354 | return curve.point(obj[0], obj[1], red); | ||
25355 | } | ||
25356 | |||
25357 | var pre = obj[2]; | ||
25358 | res.precomputed = { | ||
25359 | beta: null, | ||
25360 | doubles: pre.doubles && { | ||
25361 | step: pre.doubles.step, | ||
25362 | points: [ res ].concat(pre.doubles.points.map(obj2point)) | ||
25363 | }, | ||
25364 | naf: pre.naf && { | ||
25365 | wnd: pre.naf.wnd, | ||
25366 | points: [ res ].concat(pre.naf.points.map(obj2point)) | ||
25367 | } | ||
25368 | }; | ||
25369 | return res; | ||
25370 | }; | ||
25371 | |||
25372 | Point.prototype.inspect = function inspect() { | ||
25373 | if (this.isInfinity()) | ||
25374 | return '<EC Point Infinity>'; | ||
25375 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + | ||
25376 | ' y: ' + this.y.fromRed().toString(16, 2) + '>'; | ||
25377 | }; | ||
25378 | |||
25379 | Point.prototype.isInfinity = function isInfinity() { | ||
25380 | return this.inf; | ||
25381 | }; | ||
25382 | |||
25383 | Point.prototype.add = function add(p) { | ||
25384 | // O + P = P | ||
25385 | if (this.inf) | ||
25386 | return p; | ||
25387 | |||
25388 | // P + O = P | ||
25389 | if (p.inf) | ||
25390 | return this; | ||
25391 | |||
25392 | // P + P = 2P | ||
25393 | if (this.eq(p)) | ||
25394 | return this.dbl(); | ||
25395 | |||
25396 | // P + (-P) = O | ||
25397 | if (this.neg().eq(p)) | ||
25398 | return this.curve.point(null, null); | ||
25399 | |||
25400 | // P + Q = O | ||
25401 | if (this.x.cmp(p.x) === 0) | ||
25402 | return this.curve.point(null, null); | ||
25403 | |||
25404 | var c = this.y.redSub(p.y); | ||
25405 | if (c.cmpn(0) !== 0) | ||
25406 | c = c.redMul(this.x.redSub(p.x).redInvm()); | ||
25407 | var nx = c.redSqr().redISub(this.x).redISub(p.x); | ||
25408 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); | ||
25409 | return this.curve.point(nx, ny); | ||
25410 | }; | ||
25411 | |||
25412 | Point.prototype.dbl = function dbl() { | ||
25413 | if (this.inf) | ||
25414 | return this; | ||
25415 | |||
25416 | // 2P = O | ||
25417 | var ys1 = this.y.redAdd(this.y); | ||
25418 | if (ys1.cmpn(0) === 0) | ||
25419 | return this.curve.point(null, null); | ||
25420 | |||
25421 | var a = this.curve.a; | ||
25422 | |||
25423 | var x2 = this.x.redSqr(); | ||
25424 | var dyinv = ys1.redInvm(); | ||
25425 | var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv); | ||
25426 | |||
25427 | var nx = c.redSqr().redISub(this.x.redAdd(this.x)); | ||
25428 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); | ||
25429 | return this.curve.point(nx, ny); | ||
25430 | }; | ||
25431 | |||
25432 | Point.prototype.getX = function getX() { | ||
25433 | return this.x.fromRed(); | ||
25434 | }; | ||
25435 | |||
25436 | Point.prototype.getY = function getY() { | ||
25437 | return this.y.fromRed(); | ||
25438 | }; | ||
25439 | |||
25440 | Point.prototype.mul = function mul(k) { | ||
25441 | k = new BN(k, 16); | ||
25442 | |||
25443 | if (this._hasDoubles(k)) | ||
25444 | return this.curve._fixedNafMul(this, k); | ||
25445 | else if (this.curve.endo) | ||
25446 | return this.curve._endoWnafMulAdd([ this ], [ k ]); | ||
25447 | else | ||
25448 | return this.curve._wnafMul(this, k); | ||
25449 | }; | ||
25450 | |||
25451 | Point.prototype.mulAdd = function mulAdd(k1, p2, k2) { | ||
25452 | var points = [ this, p2 ]; | ||
25453 | var coeffs = [ k1, k2 ]; | ||
25454 | if (this.curve.endo) | ||
25455 | return this.curve._endoWnafMulAdd(points, coeffs); | ||
25456 | else | ||
25457 | return this.curve._wnafMulAdd(1, points, coeffs, 2); | ||
25458 | }; | ||
25459 | |||
25460 | Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) { | ||
25461 | var points = [ this, p2 ]; | ||
25462 | var coeffs = [ k1, k2 ]; | ||
25463 | if (this.curve.endo) | ||
25464 | return this.curve._endoWnafMulAdd(points, coeffs, true); | ||
25465 | else | ||
25466 | return this.curve._wnafMulAdd(1, points, coeffs, 2, true); | ||
25467 | }; | ||
25468 | |||
25469 | Point.prototype.eq = function eq(p) { | ||
25470 | return this === p || | ||
25471 | this.inf === p.inf && | ||
25472 | (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0); | ||
25473 | }; | ||
25474 | |||
25475 | Point.prototype.neg = function neg(_precompute) { | ||
25476 | if (this.inf) | ||
25477 | return this; | ||
25478 | |||
25479 | var res = this.curve.point(this.x, this.y.redNeg()); | ||
25480 | if (_precompute && this.precomputed) { | ||
25481 | var pre = this.precomputed; | ||
25482 | var negate = function(p) { | ||
25483 | return p.neg(); | ||
25484 | }; | ||
25485 | res.precomputed = { | ||
25486 | naf: pre.naf && { | ||
25487 | wnd: pre.naf.wnd, | ||
25488 | points: pre.naf.points.map(negate) | ||
25489 | }, | ||
25490 | doubles: pre.doubles && { | ||
25491 | step: pre.doubles.step, | ||
25492 | points: pre.doubles.points.map(negate) | ||
25493 | } | ||
25494 | }; | ||
25495 | } | ||
25496 | return res; | ||
25497 | }; | ||
25498 | |||
25499 | Point.prototype.toJ = function toJ() { | ||
25500 | if (this.inf) | ||
25501 | return this.curve.jpoint(null, null, null); | ||
25502 | |||
25503 | var res = this.curve.jpoint(this.x, this.y, this.curve.one); | ||
25504 | return res; | ||
25505 | }; | ||
25506 | |||
25507 | function JPoint(curve, x, y, z) { | ||
25508 | Base.BasePoint.call(this, curve, 'jacobian'); | ||
25509 | if (x === null && y === null && z === null) { | ||
25510 | this.x = this.curve.one; | ||
25511 | this.y = this.curve.one; | ||
25512 | this.z = new BN(0); | ||
25513 | } else { | ||
25514 | this.x = new BN(x, 16); | ||
25515 | this.y = new BN(y, 16); | ||
25516 | this.z = new BN(z, 16); | ||
25517 | } | ||
25518 | if (!this.x.red) | ||
25519 | this.x = this.x.toRed(this.curve.red); | ||
25520 | if (!this.y.red) | ||
25521 | this.y = this.y.toRed(this.curve.red); | ||
25522 | if (!this.z.red) | ||
25523 | this.z = this.z.toRed(this.curve.red); | ||
25524 | |||
25525 | this.zOne = this.z === this.curve.one; | ||
25526 | } | ||
25527 | inherits(JPoint, Base.BasePoint); | ||
25528 | |||
25529 | ShortCurve.prototype.jpoint = function jpoint(x, y, z) { | ||
25530 | return new JPoint(this, x, y, z); | ||
25531 | }; | ||
25532 | |||
25533 | JPoint.prototype.toP = function toP() { | ||
25534 | if (this.isInfinity()) | ||
25535 | return this.curve.point(null, null); | ||
25536 | |||
25537 | var zinv = this.z.redInvm(); | ||
25538 | var zinv2 = zinv.redSqr(); | ||
25539 | var ax = this.x.redMul(zinv2); | ||
25540 | var ay = this.y.redMul(zinv2).redMul(zinv); | ||
25541 | |||
25542 | return this.curve.point(ax, ay); | ||
25543 | }; | ||
25544 | |||
25545 | JPoint.prototype.neg = function neg() { | ||
25546 | return this.curve.jpoint(this.x, this.y.redNeg(), this.z); | ||
25547 | }; | ||
25548 | |||
25549 | JPoint.prototype.add = function add(p) { | ||
25550 | // O + P = P | ||
25551 | if (this.isInfinity()) | ||
25552 | return p; | ||
25553 | |||
25554 | // P + O = P | ||
25555 | if (p.isInfinity()) | ||
25556 | return this; | ||
25557 | |||
25558 | // 12M + 4S + 7A | ||
25559 | var pz2 = p.z.redSqr(); | ||
25560 | var z2 = this.z.redSqr(); | ||
25561 | var u1 = this.x.redMul(pz2); | ||
25562 | var u2 = p.x.redMul(z2); | ||
25563 | var s1 = this.y.redMul(pz2.redMul(p.z)); | ||
25564 | var s2 = p.y.redMul(z2.redMul(this.z)); | ||
25565 | |||
25566 | var h = u1.redSub(u2); | ||
25567 | var r = s1.redSub(s2); | ||
25568 | if (h.cmpn(0) === 0) { | ||
25569 | if (r.cmpn(0) !== 0) | ||
25570 | return this.curve.jpoint(null, null, null); | ||
25571 | else | ||
25572 | return this.dbl(); | ||
25573 | } | ||
25574 | |||
25575 | var h2 = h.redSqr(); | ||
25576 | var h3 = h2.redMul(h); | ||
25577 | var v = u1.redMul(h2); | ||
25578 | |||
25579 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); | ||
25580 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); | ||
25581 | var nz = this.z.redMul(p.z).redMul(h); | ||
25582 | |||
25583 | return this.curve.jpoint(nx, ny, nz); | ||
25584 | }; | ||
25585 | |||
25586 | JPoint.prototype.mixedAdd = function mixedAdd(p) { | ||
25587 | // O + P = P | ||
25588 | if (this.isInfinity()) | ||
25589 | return p.toJ(); | ||
25590 | |||
25591 | // P + O = P | ||
25592 | if (p.isInfinity()) | ||
25593 | return this; | ||
25594 | |||
25595 | // 8M + 3S + 7A | ||
25596 | var z2 = this.z.redSqr(); | ||
25597 | var u1 = this.x; | ||
25598 | var u2 = p.x.redMul(z2); | ||
25599 | var s1 = this.y; | ||
25600 | var s2 = p.y.redMul(z2).redMul(this.z); | ||
25601 | |||
25602 | var h = u1.redSub(u2); | ||
25603 | var r = s1.redSub(s2); | ||
25604 | if (h.cmpn(0) === 0) { | ||
25605 | if (r.cmpn(0) !== 0) | ||
25606 | return this.curve.jpoint(null, null, null); | ||
25607 | else | ||
25608 | return this.dbl(); | ||
25609 | } | ||
25610 | |||
25611 | var h2 = h.redSqr(); | ||
25612 | var h3 = h2.redMul(h); | ||
25613 | var v = u1.redMul(h2); | ||
25614 | |||
25615 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); | ||
25616 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); | ||
25617 | var nz = this.z.redMul(h); | ||
25618 | |||
25619 | return this.curve.jpoint(nx, ny, nz); | ||
25620 | }; | ||
25621 | |||
25622 | JPoint.prototype.dblp = function dblp(pow) { | ||
25623 | if (pow === 0) | ||
25624 | return this; | ||
25625 | if (this.isInfinity()) | ||
25626 | return this; | ||
25627 | if (!pow) | ||
25628 | return this.dbl(); | ||
25629 | |||
25630 | if (this.curve.zeroA || this.curve.threeA) { | ||
25631 | var r = this; | ||
25632 | for (var i = 0; i < pow; i++) | ||
25633 | r = r.dbl(); | ||
25634 | return r; | ||
25635 | } | ||
25636 | |||
25637 | // 1M + 2S + 1A + N * (4S + 5M + 8A) | ||
25638 | // N = 1 => 6M + 6S + 9A | ||
25639 | var a = this.curve.a; | ||
25640 | var tinv = this.curve.tinv; | ||
25641 | |||
25642 | var jx = this.x; | ||
25643 | var jy = this.y; | ||
25644 | var jz = this.z; | ||
25645 | var jz4 = jz.redSqr().redSqr(); | ||
25646 | |||
25647 | // Reuse results | ||
25648 | var jyd = jy.redAdd(jy); | ||
25649 | for (var i = 0; i < pow; i++) { | ||
25650 | var jx2 = jx.redSqr(); | ||
25651 | var jyd2 = jyd.redSqr(); | ||
25652 | var jyd4 = jyd2.redSqr(); | ||
25653 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); | ||
25654 | |||
25655 | var t1 = jx.redMul(jyd2); | ||
25656 | var nx = c.redSqr().redISub(t1.redAdd(t1)); | ||
25657 | var t2 = t1.redISub(nx); | ||
25658 | var dny = c.redMul(t2); | ||
25659 | dny = dny.redIAdd(dny).redISub(jyd4); | ||
25660 | var nz = jyd.redMul(jz); | ||
25661 | if (i + 1 < pow) | ||
25662 | jz4 = jz4.redMul(jyd4); | ||
25663 | |||
25664 | jx = nx; | ||
25665 | jz = nz; | ||
25666 | jyd = dny; | ||
25667 | } | ||
25668 | |||
25669 | return this.curve.jpoint(jx, jyd.redMul(tinv), jz); | ||
25670 | }; | ||
25671 | |||
25672 | JPoint.prototype.dbl = function dbl() { | ||
25673 | if (this.isInfinity()) | ||
25674 | return this; | ||
25675 | |||
25676 | if (this.curve.zeroA) | ||
25677 | return this._zeroDbl(); | ||
25678 | else if (this.curve.threeA) | ||
25679 | return this._threeDbl(); | ||
25680 | else | ||
25681 | return this._dbl(); | ||
25682 | }; | ||
25683 | |||
25684 | JPoint.prototype._zeroDbl = function _zeroDbl() { | ||
25685 | var nx; | ||
25686 | var ny; | ||
25687 | var nz; | ||
25688 | // Z = 1 | ||
25689 | if (this.zOne) { | ||
25690 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html | ||
25691 | // #doubling-mdbl-2007-bl | ||
25692 | // 1M + 5S + 14A | ||
25693 | |||
25694 | // XX = X1^2 | ||
25695 | var xx = this.x.redSqr(); | ||
25696 | // YY = Y1^2 | ||
25697 | var yy = this.y.redSqr(); | ||
25698 | // YYYY = YY^2 | ||
25699 | var yyyy = yy.redSqr(); | ||
25700 | // S = 2 * ((X1 + YY)^2 - XX - YYYY) | ||
25701 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
25702 | s = s.redIAdd(s); | ||
25703 | // M = 3 * XX + a; a = 0 | ||
25704 | var m = xx.redAdd(xx).redIAdd(xx); | ||
25705 | // T = M ^ 2 - 2*S | ||
25706 | var t = m.redSqr().redISub(s).redISub(s); | ||
25707 | |||
25708 | // 8 * YYYY | ||
25709 | var yyyy8 = yyyy.redIAdd(yyyy); | ||
25710 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
25711 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
25712 | |||
25713 | // X3 = T | ||
25714 | nx = t; | ||
25715 | // Y3 = M * (S - T) - 8 * YYYY | ||
25716 | ny = m.redMul(s.redISub(t)).redISub(yyyy8); | ||
25717 | // Z3 = 2*Y1 | ||
25718 | nz = this.y.redAdd(this.y); | ||
25719 | } else { | ||
25720 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html | ||
25721 | // #doubling-dbl-2009-l | ||
25722 | // 2M + 5S + 13A | ||
25723 | |||
25724 | // A = X1^2 | ||
25725 | var a = this.x.redSqr(); | ||
25726 | // B = Y1^2 | ||
25727 | var b = this.y.redSqr(); | ||
25728 | // C = B^2 | ||
25729 | var c = b.redSqr(); | ||
25730 | // D = 2 * ((X1 + B)^2 - A - C) | ||
25731 | var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c); | ||
25732 | d = d.redIAdd(d); | ||
25733 | // E = 3 * A | ||
25734 | var e = a.redAdd(a).redIAdd(a); | ||
25735 | // F = E^2 | ||
25736 | var f = e.redSqr(); | ||
25737 | |||
25738 | // 8 * C | ||
25739 | var c8 = c.redIAdd(c); | ||
25740 | c8 = c8.redIAdd(c8); | ||
25741 | c8 = c8.redIAdd(c8); | ||
25742 | |||
25743 | // X3 = F - 2 * D | ||
25744 | nx = f.redISub(d).redISub(d); | ||
25745 | // Y3 = E * (D - X3) - 8 * C | ||
25746 | ny = e.redMul(d.redISub(nx)).redISub(c8); | ||
25747 | // Z3 = 2 * Y1 * Z1 | ||
25748 | nz = this.y.redMul(this.z); | ||
25749 | nz = nz.redIAdd(nz); | ||
25750 | } | ||
25751 | |||
25752 | return this.curve.jpoint(nx, ny, nz); | ||
25753 | }; | ||
25754 | |||
25755 | JPoint.prototype._threeDbl = function _threeDbl() { | ||
25756 | var nx; | ||
25757 | var ny; | ||
25758 | var nz; | ||
25759 | // Z = 1 | ||
25760 | if (this.zOne) { | ||
25761 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html | ||
25762 | // #doubling-mdbl-2007-bl | ||
25763 | // 1M + 5S + 15A | ||
25764 | |||
25765 | // XX = X1^2 | ||
25766 | var xx = this.x.redSqr(); | ||
25767 | // YY = Y1^2 | ||
25768 | var yy = this.y.redSqr(); | ||
25769 | // YYYY = YY^2 | ||
25770 | var yyyy = yy.redSqr(); | ||
25771 | // S = 2 * ((X1 + YY)^2 - XX - YYYY) | ||
25772 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
25773 | s = s.redIAdd(s); | ||
25774 | // M = 3 * XX + a | ||
25775 | var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); | ||
25776 | // T = M^2 - 2 * S | ||
25777 | var t = m.redSqr().redISub(s).redISub(s); | ||
25778 | // X3 = T | ||
25779 | nx = t; | ||
25780 | // Y3 = M * (S - T) - 8 * YYYY | ||
25781 | var yyyy8 = yyyy.redIAdd(yyyy); | ||
25782 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
25783 | yyyy8 = yyyy8.redIAdd(yyyy8); | ||
25784 | ny = m.redMul(s.redISub(t)).redISub(yyyy8); | ||
25785 | // Z3 = 2 * Y1 | ||
25786 | nz = this.y.redAdd(this.y); | ||
25787 | } else { | ||
25788 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b | ||
25789 | // 3M + 5S | ||
25790 | |||
25791 | // delta = Z1^2 | ||
25792 | var delta = this.z.redSqr(); | ||
25793 | // gamma = Y1^2 | ||
25794 | var gamma = this.y.redSqr(); | ||
25795 | // beta = X1 * gamma | ||
25796 | var beta = this.x.redMul(gamma); | ||
25797 | // alpha = 3 * (X1 - delta) * (X1 + delta) | ||
25798 | var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta)); | ||
25799 | alpha = alpha.redAdd(alpha).redIAdd(alpha); | ||
25800 | // X3 = alpha^2 - 8 * beta | ||
25801 | var beta4 = beta.redIAdd(beta); | ||
25802 | beta4 = beta4.redIAdd(beta4); | ||
25803 | var beta8 = beta4.redAdd(beta4); | ||
25804 | nx = alpha.redSqr().redISub(beta8); | ||
25805 | // Z3 = (Y1 + Z1)^2 - gamma - delta | ||
25806 | nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); | ||
25807 | // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2 | ||
25808 | var ggamma8 = gamma.redSqr(); | ||
25809 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
25810 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
25811 | ggamma8 = ggamma8.redIAdd(ggamma8); | ||
25812 | ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8); | ||
25813 | } | ||
25814 | |||
25815 | return this.curve.jpoint(nx, ny, nz); | ||
25816 | }; | ||
25817 | |||
25818 | JPoint.prototype._dbl = function _dbl() { | ||
25819 | var a = this.curve.a; | ||
25820 | |||
25821 | // 4M + 6S + 10A | ||
25822 | var jx = this.x; | ||
25823 | var jy = this.y; | ||
25824 | var jz = this.z; | ||
25825 | var jz4 = jz.redSqr().redSqr(); | ||
25826 | |||
25827 | var jx2 = jx.redSqr(); | ||
25828 | var jy2 = jy.redSqr(); | ||
25829 | |||
25830 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); | ||
25831 | |||
25832 | var jxd4 = jx.redAdd(jx); | ||
25833 | jxd4 = jxd4.redIAdd(jxd4); | ||
25834 | var t1 = jxd4.redMul(jy2); | ||
25835 | var nx = c.redSqr().redISub(t1.redAdd(t1)); | ||
25836 | var t2 = t1.redISub(nx); | ||
25837 | |||
25838 | var jyd8 = jy2.redSqr(); | ||
25839 | jyd8 = jyd8.redIAdd(jyd8); | ||
25840 | jyd8 = jyd8.redIAdd(jyd8); | ||
25841 | jyd8 = jyd8.redIAdd(jyd8); | ||
25842 | var ny = c.redMul(t2).redISub(jyd8); | ||
25843 | var nz = jy.redAdd(jy).redMul(jz); | ||
25844 | |||
25845 | return this.curve.jpoint(nx, ny, nz); | ||
25846 | }; | ||
25847 | |||
25848 | JPoint.prototype.trpl = function trpl() { | ||
25849 | if (!this.curve.zeroA) | ||
25850 | return this.dbl().add(this); | ||
25851 | |||
25852 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl | ||
25853 | // 5M + 10S + ... | ||
25854 | |||
25855 | // XX = X1^2 | ||
25856 | var xx = this.x.redSqr(); | ||
25857 | // YY = Y1^2 | ||
25858 | var yy = this.y.redSqr(); | ||
25859 | // ZZ = Z1^2 | ||
25860 | var zz = this.z.redSqr(); | ||
25861 | // YYYY = YY^2 | ||
25862 | var yyyy = yy.redSqr(); | ||
25863 | // M = 3 * XX + a * ZZ2; a = 0 | ||
25864 | var m = xx.redAdd(xx).redIAdd(xx); | ||
25865 | // MM = M^2 | ||
25866 | var mm = m.redSqr(); | ||
25867 | // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM | ||
25868 | var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); | ||
25869 | e = e.redIAdd(e); | ||
25870 | e = e.redAdd(e).redIAdd(e); | ||
25871 | e = e.redISub(mm); | ||
25872 | // EE = E^2 | ||
25873 | var ee = e.redSqr(); | ||
25874 | // T = 16*YYYY | ||
25875 | var t = yyyy.redIAdd(yyyy); | ||
25876 | t = t.redIAdd(t); | ||
25877 | t = t.redIAdd(t); | ||
25878 | t = t.redIAdd(t); | ||
25879 | // U = (M + E)^2 - MM - EE - T | ||
25880 | var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); | ||
25881 | // X3 = 4 * (X1 * EE - 4 * YY * U) | ||
25882 | var yyu4 = yy.redMul(u); | ||
25883 | yyu4 = yyu4.redIAdd(yyu4); | ||
25884 | yyu4 = yyu4.redIAdd(yyu4); | ||
25885 | var nx = this.x.redMul(ee).redISub(yyu4); | ||
25886 | nx = nx.redIAdd(nx); | ||
25887 | nx = nx.redIAdd(nx); | ||
25888 | // Y3 = 8 * Y1 * (U * (T - U) - E * EE) | ||
25889 | var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee))); | ||
25890 | ny = ny.redIAdd(ny); | ||
25891 | ny = ny.redIAdd(ny); | ||
25892 | ny = ny.redIAdd(ny); | ||
25893 | // Z3 = (Z1 + E)^2 - ZZ - EE | ||
25894 | var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee); | ||
25895 | |||
25896 | return this.curve.jpoint(nx, ny, nz); | ||
25897 | }; | ||
25898 | |||
25899 | JPoint.prototype.mul = function mul(k, kbase) { | ||
25900 | k = new BN(k, kbase); | ||
25901 | |||
25902 | return this.curve._wnafMul(this, k); | ||
25903 | }; | ||
25904 | |||
25905 | JPoint.prototype.eq = function eq(p) { | ||
25906 | if (p.type === 'affine') | ||
25907 | return this.eq(p.toJ()); | ||
25908 | |||
25909 | if (this === p) | ||
25910 | return true; | ||
25911 | |||
25912 | // x1 * z2^2 == x2 * z1^2 | ||
25913 | var z2 = this.z.redSqr(); | ||
25914 | var pz2 = p.z.redSqr(); | ||
25915 | if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) | ||
25916 | return false; | ||
25917 | |||
25918 | // y1 * z2^3 == y2 * z1^3 | ||
25919 | var z3 = z2.redMul(this.z); | ||
25920 | var pz3 = pz2.redMul(p.z); | ||
25921 | return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0; | ||
25922 | }; | ||
25923 | |||
25924 | JPoint.prototype.eqXToP = function eqXToP(x) { | ||
25925 | var zs = this.z.redSqr(); | ||
25926 | var rx = x.toRed(this.curve.red).redMul(zs); | ||
25927 | if (this.x.cmp(rx) === 0) | ||
25928 | return true; | ||
25929 | |||
25930 | var xc = x.clone(); | ||
25931 | var t = this.curve.redN.redMul(zs); | ||
25932 | for (;;) { | ||
25933 | xc.iadd(this.curve.n); | ||
25934 | if (xc.cmp(this.curve.p) >= 0) | ||
25935 | return false; | ||
25936 | |||
25937 | rx.redIAdd(t); | ||
25938 | if (this.x.cmp(rx) === 0) | ||
25939 | return true; | ||
25940 | } | ||
25941 | return false; | ||
25942 | }; | ||
25943 | |||
25944 | JPoint.prototype.inspect = function inspect() { | ||
25945 | if (this.isInfinity()) | ||
25946 | return '<EC JPoint Infinity>'; | ||
25947 | return '<EC JPoint x: ' + this.x.toString(16, 2) + | ||
25948 | ' y: ' + this.y.toString(16, 2) + | ||
25949 | ' z: ' + this.z.toString(16, 2) + '>'; | ||
25950 | }; | ||
25951 | |||
25952 | JPoint.prototype.isInfinity = function isInfinity() { | ||
25953 | // XXX This code assumes that zero is always zero in red | ||
25954 | return this.z.cmpn(0) === 0; | ||
25955 | }; | ||
25956 | |||
25957 | },{"../../elliptic":97,"../curve":100,"bn.js":81,"inherits":121}],103:[function(require,module,exports){ | ||
25958 | 'use strict'; | ||
25959 | |||
25960 | var curves = exports; | ||
25961 | |||
25962 | var hash = require('hash.js'); | ||
25963 | var elliptic = require('../elliptic'); | ||
25964 | |||
25965 | var assert = elliptic.utils.assert; | ||
25966 | |||
25967 | function PresetCurve(options) { | ||
25968 | if (options.type === 'short') | ||
25969 | this.curve = new elliptic.curve.short(options); | ||
25970 | else if (options.type === 'edwards') | ||
25971 | this.curve = new elliptic.curve.edwards(options); | ||
25972 | else | ||
25973 | this.curve = new elliptic.curve.mont(options); | ||
25974 | this.g = this.curve.g; | ||
25975 | this.n = this.curve.n; | ||
25976 | this.hash = options.hash; | ||
25977 | |||
25978 | assert(this.g.validate(), 'Invalid curve'); | ||
25979 | assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O'); | ||
25980 | } | ||
25981 | curves.PresetCurve = PresetCurve; | ||
25982 | |||
25983 | function defineCurve(name, options) { | ||
25984 | Object.defineProperty(curves, name, { | ||
25985 | configurable: true, | ||
25986 | enumerable: true, | ||
25987 | get: function() { | ||
25988 | var curve = new PresetCurve(options); | ||
25989 | Object.defineProperty(curves, name, { | ||
25990 | configurable: true, | ||
25991 | enumerable: true, | ||
25992 | value: curve | ||
25993 | }); | ||
25994 | return curve; | ||
25995 | } | ||
25996 | }); | ||
25997 | } | ||
25998 | |||
25999 | defineCurve('p192', { | ||
26000 | type: 'short', | ||
26001 | prime: 'p192', | ||
26002 | p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff', | ||
26003 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc', | ||
26004 | b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1', | ||
26005 | n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831', | ||
26006 | hash: hash.sha256, | ||
26007 | gRed: false, | ||
26008 | g: [ | ||
26009 | '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', | ||
26010 | '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811' | ||
26011 | ] | ||
26012 | }); | ||
26013 | |||
26014 | defineCurve('p224', { | ||
26015 | type: 'short', | ||
26016 | prime: 'p224', | ||
26017 | p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001', | ||
26018 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe', | ||
26019 | b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4', | ||
26020 | n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d', | ||
26021 | hash: hash.sha256, | ||
26022 | gRed: false, | ||
26023 | g: [ | ||
26024 | 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', | ||
26025 | 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34' | ||
26026 | ] | ||
26027 | }); | ||
26028 | |||
26029 | defineCurve('p256', { | ||
26030 | type: 'short', | ||
26031 | prime: null, | ||
26032 | p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff', | ||
26033 | a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc', | ||
26034 | b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b', | ||
26035 | n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551', | ||
26036 | hash: hash.sha256, | ||
26037 | gRed: false, | ||
26038 | g: [ | ||
26039 | '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', | ||
26040 | '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5' | ||
26041 | ] | ||
26042 | }); | ||
26043 | |||
26044 | defineCurve('p384', { | ||
26045 | type: 'short', | ||
26046 | prime: null, | ||
26047 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26048 | 'fffffffe ffffffff 00000000 00000000 ffffffff', | ||
26049 | a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26050 | 'fffffffe ffffffff 00000000 00000000 fffffffc', | ||
26051 | b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + | ||
26052 | '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef', | ||
26053 | n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + | ||
26054 | 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973', | ||
26055 | hash: hash.sha384, | ||
26056 | gRed: false, | ||
26057 | g: [ | ||
26058 | 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' + | ||
26059 | '5502f25d bf55296c 3a545e38 72760ab7', | ||
26060 | '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' + | ||
26061 | '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f' | ||
26062 | ] | ||
26063 | }); | ||
26064 | |||
26065 | defineCurve('p521', { | ||
26066 | type: 'short', | ||
26067 | prime: null, | ||
26068 | p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26069 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26070 | 'ffffffff ffffffff ffffffff ffffffff ffffffff', | ||
26071 | a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26072 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26073 | 'ffffffff ffffffff ffffffff ffffffff fffffffc', | ||
26074 | b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + | ||
26075 | '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + | ||
26076 | '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00', | ||
26077 | n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + | ||
26078 | 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + | ||
26079 | 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409', | ||
26080 | hash: hash.sha512, | ||
26081 | gRed: false, | ||
26082 | g: [ | ||
26083 | '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' + | ||
26084 | '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' + | ||
26085 | 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66', | ||
26086 | '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' + | ||
26087 | '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' + | ||
26088 | '3fad0761 353c7086 a272c240 88be9476 9fd16650' | ||
26089 | ] | ||
26090 | }); | ||
26091 | |||
26092 | defineCurve('curve25519', { | ||
26093 | type: 'mont', | ||
26094 | prime: 'p25519', | ||
26095 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed', | ||
26096 | a: '76d06', | ||
26097 | b: '1', | ||
26098 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed', | ||
26099 | hash: hash.sha256, | ||
26100 | gRed: false, | ||
26101 | g: [ | ||
26102 | '9' | ||
26103 | ] | ||
26104 | }); | ||
26105 | |||
26106 | defineCurve('ed25519', { | ||
26107 | type: 'edwards', | ||
26108 | prime: 'p25519', | ||
26109 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed', | ||
26110 | a: '-1', | ||
26111 | c: '1', | ||
26112 | // -121665 * (121666^(-1)) (mod P) | ||
26113 | d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3', | ||
26114 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed', | ||
26115 | hash: hash.sha256, | ||
26116 | gRed: false, | ||
26117 | g: [ | ||
26118 | '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a', | ||
26119 | |||
26120 | // 4/5 | ||
26121 | '6666666666666666666666666666666666666666666666666666666666666658' | ||
26122 | ] | ||
26123 | }); | ||
26124 | |||
26125 | var pre; | ||
26126 | try { | ||
26127 | pre = require('./precomputed/secp256k1'); | ||
26128 | } catch (e) { | ||
26129 | pre = undefined; | ||
26130 | } | ||
26131 | |||
26132 | defineCurve('secp256k1', { | ||
26133 | type: 'short', | ||
26134 | prime: 'k256', | ||
26135 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f', | ||
26136 | a: '0', | ||
26137 | b: '7', | ||
26138 | n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141', | ||
26139 | h: '1', | ||
26140 | hash: hash.sha256, | ||
26141 | |||
26142 | // Precomputed endomorphism | ||
26143 | beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee', | ||
26144 | lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72', | ||
26145 | basis: [ | ||
26146 | { | ||
26147 | a: '3086d221a7d46bcde86c90e49284eb15', | ||
26148 | b: '-e4437ed6010e88286f547fa90abfe4c3' | ||
26149 | }, | ||
26150 | { | ||
26151 | a: '114ca50f7a8e2f3f657c1108d9d44cfd8', | ||
26152 | b: '3086d221a7d46bcde86c90e49284eb15' | ||
26153 | } | ||
26154 | ], | ||
26155 | |||
26156 | gRed: false, | ||
26157 | g: [ | ||
26158 | '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', | ||
26159 | '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', | ||
26160 | pre | ||
26161 | ] | ||
26162 | }); | ||
26163 | |||
26164 | },{"../elliptic":97,"./precomputed/secp256k1":110,"hash.js":114}],104:[function(require,module,exports){ | ||
26165 | 'use strict'; | ||
26166 | |||
26167 | var BN = require('bn.js'); | ||
26168 | var HmacDRBG = require('hmac-drbg'); | ||
26169 | var elliptic = require('../../elliptic'); | ||
26170 | var utils = elliptic.utils; | ||
26171 | var assert = utils.assert; | ||
26172 | |||
26173 | var KeyPair = require('./key'); | ||
26174 | var Signature = require('./signature'); | ||
26175 | |||
26176 | function EC(options) { | ||
26177 | if (!(this instanceof EC)) | ||
26178 | return new EC(options); | ||
26179 | |||
26180 | // Shortcut `elliptic.ec(curve-name)` | ||
26181 | if (typeof options === 'string') { | ||
26182 | assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options); | ||
26183 | |||
26184 | options = elliptic.curves[options]; | ||
26185 | } | ||
26186 | |||
26187 | // Shortcut for `elliptic.ec(elliptic.curves.curveName)` | ||
26188 | if (options instanceof elliptic.curves.PresetCurve) | ||
26189 | options = { curve: options }; | ||
26190 | |||
26191 | this.curve = options.curve.curve; | ||
26192 | this.n = this.curve.n; | ||
26193 | this.nh = this.n.ushrn(1); | ||
26194 | this.g = this.curve.g; | ||
26195 | |||
26196 | // Point on curve | ||
26197 | this.g = options.curve.g; | ||
26198 | this.g.precompute(options.curve.n.bitLength() + 1); | ||
26199 | |||
26200 | // Hash for function for DRBG | ||
26201 | this.hash = options.hash || options.curve.hash; | ||
26202 | } | ||
26203 | module.exports = EC; | ||
26204 | |||
26205 | EC.prototype.keyPair = function keyPair(options) { | ||
26206 | return new KeyPair(this, options); | ||
26207 | }; | ||
26208 | |||
26209 | EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) { | ||
26210 | return KeyPair.fromPrivate(this, priv, enc); | ||
26211 | }; | ||
26212 | |||
26213 | EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) { | ||
26214 | return KeyPair.fromPublic(this, pub, enc); | ||
26215 | }; | ||
26216 | |||
26217 | EC.prototype.genKeyPair = function genKeyPair(options) { | ||
26218 | if (!options) | ||
26219 | options = {}; | ||
26220 | |||
26221 | // Instantiate Hmac_DRBG | ||
26222 | var drbg = new HmacDRBG({ | ||
26223 | hash: this.hash, | ||
26224 | pers: options.pers, | ||
26225 | persEnc: options.persEnc || 'utf8', | ||
26226 | entropy: options.entropy || elliptic.rand(this.hash.hmacStrength), | ||
26227 | entropyEnc: options.entropy && options.entropyEnc || 'utf8', | ||
26228 | nonce: this.n.toArray() | ||
26229 | }); | ||
26230 | |||
26231 | var bytes = this.n.byteLength(); | ||
26232 | var ns2 = this.n.sub(new BN(2)); | ||
26233 | do { | ||
26234 | var priv = new BN(drbg.generate(bytes)); | ||
26235 | if (priv.cmp(ns2) > 0) | ||
26236 | continue; | ||
26237 | |||
26238 | priv.iaddn(1); | ||
26239 | return this.keyFromPrivate(priv); | ||
26240 | } while (true); | ||
26241 | }; | ||
26242 | |||
26243 | EC.prototype._truncateToN = function truncateToN(msg, truncOnly) { | ||
26244 | var delta = msg.byteLength() * 8 - this.n.bitLength(); | ||
26245 | if (delta > 0) | ||
26246 | msg = msg.ushrn(delta); | ||
26247 | if (!truncOnly && msg.cmp(this.n) >= 0) | ||
26248 | return msg.sub(this.n); | ||
26249 | else | ||
26250 | return msg; | ||
26251 | }; | ||
26252 | |||
26253 | EC.prototype.sign = function sign(msg, key, enc, options) { | ||
26254 | if (typeof enc === 'object') { | ||
26255 | options = enc; | ||
26256 | enc = null; | ||
26257 | } | ||
26258 | if (!options) | ||
26259 | options = {}; | ||
26260 | |||
26261 | key = this.keyFromPrivate(key, enc); | ||
26262 | msg = this._truncateToN(new BN(msg, 16)); | ||
26263 | |||
26264 | // Zero-extend key to provide enough entropy | ||
26265 | var bytes = this.n.byteLength(); | ||
26266 | var bkey = key.getPrivate().toArray('be', bytes); | ||
26267 | |||
26268 | // Zero-extend nonce to have the same byte size as N | ||
26269 | var nonce = msg.toArray('be', bytes); | ||
26270 | |||
26271 | // Instantiate Hmac_DRBG | ||
26272 | var drbg = new HmacDRBG({ | ||
26273 | hash: this.hash, | ||
26274 | entropy: bkey, | ||
26275 | nonce: nonce, | ||
26276 | pers: options.pers, | ||
26277 | persEnc: options.persEnc || 'utf8' | ||
26278 | }); | ||
26279 | |||
26280 | // Number of bytes to generate | ||
26281 | var ns1 = this.n.sub(new BN(1)); | ||
26282 | |||
26283 | for (var iter = 0; true; iter++) { | ||
26284 | var k = options.k ? | ||
26285 | options.k(iter) : | ||
26286 | new BN(drbg.generate(this.n.byteLength())); | ||
26287 | k = this._truncateToN(k, true); | ||
26288 | if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) | ||
26289 | continue; | ||
26290 | |||
26291 | var kp = this.g.mul(k); | ||
26292 | if (kp.isInfinity()) | ||
26293 | continue; | ||
26294 | |||
26295 | var kpX = kp.getX(); | ||
26296 | var r = kpX.umod(this.n); | ||
26297 | if (r.cmpn(0) === 0) | ||
26298 | continue; | ||
26299 | |||
26300 | var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg)); | ||
26301 | s = s.umod(this.n); | ||
26302 | if (s.cmpn(0) === 0) | ||
26303 | continue; | ||
26304 | |||
26305 | var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | | ||
26306 | (kpX.cmp(r) !== 0 ? 2 : 0); | ||
26307 | |||
26308 | // Use complement of `s`, if it is > `n / 2` | ||
26309 | if (options.canonical && s.cmp(this.nh) > 0) { | ||
26310 | s = this.n.sub(s); | ||
26311 | recoveryParam ^= 1; | ||
26312 | } | ||
26313 | |||
26314 | return new Signature({ r: r, s: s, recoveryParam: recoveryParam }); | ||
26315 | } | ||
26316 | }; | ||
26317 | |||
26318 | EC.prototype.verify = function verify(msg, signature, key, enc) { | ||
26319 | msg = this._truncateToN(new BN(msg, 16)); | ||
26320 | key = this.keyFromPublic(key, enc); | ||
26321 | signature = new Signature(signature, 'hex'); | ||
26322 | |||
26323 | // Perform primitive values validation | ||
26324 | var r = signature.r; | ||
26325 | var s = signature.s; | ||
26326 | if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) | ||
26327 | return false; | ||
26328 | if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) | ||
26329 | return false; | ||
26330 | |||
26331 | // Validate signature | ||
26332 | var sinv = s.invm(this.n); | ||
26333 | var u1 = sinv.mul(msg).umod(this.n); | ||
26334 | var u2 = sinv.mul(r).umod(this.n); | ||
26335 | |||
26336 | if (!this.curve._maxwellTrick) { | ||
26337 | var p = this.g.mulAdd(u1, key.getPublic(), u2); | ||
26338 | if (p.isInfinity()) | ||
26339 | return false; | ||
26340 | |||
26341 | return p.getX().umod(this.n).cmp(r) === 0; | ||
26342 | } | ||
26343 | |||
26344 | // NOTE: Greg Maxwell's trick, inspired by: | ||
26345 | // https://git.io/vad3K | ||
26346 | |||
26347 | var p = this.g.jmulAdd(u1, key.getPublic(), u2); | ||
26348 | if (p.isInfinity()) | ||
26349 | return false; | ||
26350 | |||
26351 | // Compare `p.x` of Jacobian point with `r`, | ||
26352 | // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the | ||
26353 | // inverse of `p.z^2` | ||
26354 | return p.eqXToP(r); | ||
26355 | }; | ||
26356 | |||
26357 | EC.prototype.recoverPubKey = function(msg, signature, j, enc) { | ||
26358 | assert((3 & j) === j, 'The recovery param is more than two bits'); | ||
26359 | signature = new Signature(signature, enc); | ||
26360 | |||
26361 | var n = this.n; | ||
26362 | var e = new BN(msg); | ||
26363 | var r = signature.r; | ||
26364 | var s = signature.s; | ||
26365 | |||
26366 | // A set LSB signifies that the y-coordinate is odd | ||
26367 | var isYOdd = j & 1; | ||
26368 | var isSecondKey = j >> 1; | ||
26369 | if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) | ||
26370 | throw new Error('Unable to find sencond key candinate'); | ||
26371 | |||
26372 | // 1.1. Let x = r + jn. | ||
26373 | if (isSecondKey) | ||
26374 | r = this.curve.pointFromX(r.add(this.curve.n), isYOdd); | ||
26375 | else | ||
26376 | r = this.curve.pointFromX(r, isYOdd); | ||
26377 | |||
26378 | var rInv = signature.r.invm(n); | ||
26379 | var s1 = n.sub(e).mul(rInv).umod(n); | ||
26380 | var s2 = s.mul(rInv).umod(n); | ||
26381 | |||
26382 | // 1.6.1 Compute Q = r^-1 (sR - eG) | ||
26383 | // Q = r^-1 (sR + -eG) | ||
26384 | return this.g.mulAdd(s1, r, s2); | ||
26385 | }; | ||
26386 | |||
26387 | EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { | ||
26388 | signature = new Signature(signature, enc); | ||
26389 | if (signature.recoveryParam !== null) | ||
26390 | return signature.recoveryParam; | ||
26391 | |||
26392 | for (var i = 0; i < 4; i++) { | ||
26393 | var Qprime; | ||
26394 | try { | ||
26395 | Qprime = this.recoverPubKey(e, signature, i); | ||
26396 | } catch (e) { | ||
26397 | continue; | ||
26398 | } | ||
26399 | |||
26400 | if (Qprime.eq(Q)) | ||
26401 | return i; | ||
26402 | } | ||
26403 | throw new Error('Unable to find valid recovery factor'); | ||
26404 | }; | ||
26405 | |||
26406 | },{"../../elliptic":97,"./key":105,"./signature":106,"bn.js":81,"hmac-drbg":120}],105:[function(require,module,exports){ | ||
26407 | 'use strict'; | ||
26408 | |||
26409 | var BN = require('bn.js'); | ||
26410 | var elliptic = require('../../elliptic'); | ||
26411 | var utils = elliptic.utils; | ||
26412 | var assert = utils.assert; | ||
26413 | |||
26414 | function KeyPair(ec, options) { | ||
26415 | this.ec = ec; | ||
26416 | this.priv = null; | ||
26417 | this.pub = null; | ||
26418 | |||
26419 | // KeyPair(ec, { priv: ..., pub: ... }) | ||
26420 | if (options.priv) | ||
26421 | this._importPrivate(options.priv, options.privEnc); | ||
26422 | if (options.pub) | ||
26423 | this._importPublic(options.pub, options.pubEnc); | ||
26424 | } | ||
26425 | module.exports = KeyPair; | ||
26426 | |||
26427 | KeyPair.fromPublic = function fromPublic(ec, pub, enc) { | ||
26428 | if (pub instanceof KeyPair) | ||
26429 | return pub; | ||
26430 | |||
26431 | return new KeyPair(ec, { | ||
26432 | pub: pub, | ||
26433 | pubEnc: enc | ||
26434 | }); | ||
26435 | }; | ||
26436 | |||
26437 | KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) { | ||
26438 | if (priv instanceof KeyPair) | ||
26439 | return priv; | ||
26440 | |||
26441 | return new KeyPair(ec, { | ||
26442 | priv: priv, | ||
26443 | privEnc: enc | ||
26444 | }); | ||
26445 | }; | ||
26446 | |||
26447 | KeyPair.prototype.validate = function validate() { | ||
26448 | var pub = this.getPublic(); | ||
26449 | |||
26450 | if (pub.isInfinity()) | ||
26451 | return { result: false, reason: 'Invalid public key' }; | ||
26452 | if (!pub.validate()) | ||
26453 | return { result: false, reason: 'Public key is not a point' }; | ||
26454 | if (!pub.mul(this.ec.curve.n).isInfinity()) | ||
26455 | return { result: false, reason: 'Public key * N != O' }; | ||
26456 | |||
26457 | return { result: true, reason: null }; | ||
26458 | }; | ||
26459 | |||
26460 | KeyPair.prototype.getPublic = function getPublic(compact, enc) { | ||
26461 | // compact is optional argument | ||
26462 | if (typeof compact === 'string') { | ||
26463 | enc = compact; | ||
26464 | compact = null; | ||
26465 | } | ||
26466 | |||
26467 | if (!this.pub) | ||
26468 | this.pub = this.ec.g.mul(this.priv); | ||
26469 | |||
26470 | if (!enc) | ||
26471 | return this.pub; | ||
26472 | |||
26473 | return this.pub.encode(enc, compact); | ||
26474 | }; | ||
26475 | |||
26476 | KeyPair.prototype.getPrivate = function getPrivate(enc) { | ||
26477 | if (enc === 'hex') | ||
26478 | return this.priv.toString(16, 2); | ||
26479 | else | ||
26480 | return this.priv; | ||
26481 | }; | ||
26482 | |||
26483 | KeyPair.prototype._importPrivate = function _importPrivate(key, enc) { | ||
26484 | this.priv = new BN(key, enc || 16); | ||
26485 | |||
26486 | // Ensure that the priv won't be bigger than n, otherwise we may fail | ||
26487 | // in fixed multiplication method | ||
26488 | this.priv = this.priv.umod(this.ec.curve.n); | ||
26489 | }; | ||
26490 | |||
26491 | KeyPair.prototype._importPublic = function _importPublic(key, enc) { | ||
26492 | if (key.x || key.y) { | ||
26493 | // Montgomery points only have an `x` coordinate. | ||
26494 | // Weierstrass/Edwards points on the other hand have both `x` and | ||
26495 | // `y` coordinates. | ||
26496 | if (this.ec.curve.type === 'mont') { | ||
26497 | assert(key.x, 'Need x coordinate'); | ||
26498 | } else if (this.ec.curve.type === 'short' || | ||
26499 | this.ec.curve.type === 'edwards') { | ||
26500 | assert(key.x && key.y, 'Need both x and y coordinate'); | ||
26501 | } | ||
26502 | this.pub = this.ec.curve.point(key.x, key.y); | ||
26503 | return; | ||
26504 | } | ||
26505 | this.pub = this.ec.curve.decodePoint(key, enc); | ||
26506 | }; | ||
26507 | |||
26508 | // ECDH | ||
26509 | KeyPair.prototype.derive = function derive(pub) { | ||
26510 | return pub.mul(this.priv).getX(); | ||
26511 | }; | ||
26512 | |||
26513 | // ECDSA | ||
26514 | KeyPair.prototype.sign = function sign(msg, enc, options) { | ||
26515 | return this.ec.sign(msg, this, enc, options); | ||
26516 | }; | ||
26517 | |||
26518 | KeyPair.prototype.verify = function verify(msg, signature) { | ||
26519 | return this.ec.verify(msg, signature, this); | ||
26520 | }; | ||
26521 | |||
26522 | KeyPair.prototype.inspect = function inspect() { | ||
26523 | return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + | ||
26524 | ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; | ||
26525 | }; | ||
26526 | |||
26527 | },{"../../elliptic":97,"bn.js":81}],106:[function(require,module,exports){ | ||
26528 | 'use strict'; | ||
26529 | |||
26530 | var BN = require('bn.js'); | ||
26531 | |||
26532 | var elliptic = require('../../elliptic'); | ||
26533 | var utils = elliptic.utils; | ||
26534 | var assert = utils.assert; | ||
26535 | |||
26536 | function Signature(options, enc) { | ||
26537 | if (options instanceof Signature) | ||
26538 | return options; | ||
26539 | |||
26540 | if (this._importDER(options, enc)) | ||
26541 | return; | ||
26542 | |||
26543 | assert(options.r && options.s, 'Signature without r or s'); | ||
26544 | this.r = new BN(options.r, 16); | ||
26545 | this.s = new BN(options.s, 16); | ||
26546 | if (options.recoveryParam === undefined) | ||
26547 | this.recoveryParam = null; | ||
26548 | else | ||
26549 | this.recoveryParam = options.recoveryParam; | ||
26550 | } | ||
26551 | module.exports = Signature; | ||
26552 | |||
26553 | function Position() { | ||
26554 | this.place = 0; | ||
26555 | } | ||
26556 | |||
26557 | function getLength(buf, p) { | ||
26558 | var initial = buf[p.place++]; | ||
26559 | if (!(initial & 0x80)) { | ||
26560 | return initial; | ||
26561 | } | ||
26562 | var octetLen = initial & 0xf; | ||
26563 | var val = 0; | ||
26564 | for (var i = 0, off = p.place; i < octetLen; i++, off++) { | ||
26565 | val <<= 8; | ||
26566 | val |= buf[off]; | ||
26567 | } | ||
26568 | p.place = off; | ||
26569 | return val; | ||
26570 | } | ||
26571 | |||
26572 | function rmPadding(buf) { | ||
26573 | var i = 0; | ||
26574 | var len = buf.length - 1; | ||
26575 | while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) { | ||
26576 | i++; | ||
26577 | } | ||
26578 | if (i === 0) { | ||
26579 | return buf; | ||
26580 | } | ||
26581 | return buf.slice(i); | ||
26582 | } | ||
26583 | |||
26584 | Signature.prototype._importDER = function _importDER(data, enc) { | ||
26585 | data = utils.toArray(data, enc); | ||
26586 | var p = new Position(); | ||
26587 | if (data[p.place++] !== 0x30) { | ||
26588 | return false; | ||
26589 | } | ||
26590 | var len = getLength(data, p); | ||
26591 | if ((len + p.place) !== data.length) { | ||
26592 | return false; | ||
26593 | } | ||
26594 | if (data[p.place++] !== 0x02) { | ||
26595 | return false; | ||
26596 | } | ||
26597 | var rlen = getLength(data, p); | ||
26598 | var r = data.slice(p.place, rlen + p.place); | ||
26599 | p.place += rlen; | ||
26600 | if (data[p.place++] !== 0x02) { | ||
26601 | return false; | ||
26602 | } | ||
26603 | var slen = getLength(data, p); | ||
26604 | if (data.length !== slen + p.place) { | ||
26605 | return false; | ||
26606 | } | ||
26607 | var s = data.slice(p.place, slen + p.place); | ||
26608 | if (r[0] === 0 && (r[1] & 0x80)) { | ||
26609 | r = r.slice(1); | ||
26610 | } | ||
26611 | if (s[0] === 0 && (s[1] & 0x80)) { | ||
26612 | s = s.slice(1); | ||
26613 | } | ||
26614 | |||
26615 | this.r = new BN(r); | ||
26616 | this.s = new BN(s); | ||
26617 | this.recoveryParam = null; | ||
26618 | |||
26619 | return true; | ||
26620 | }; | ||
26621 | |||
26622 | function constructLength(arr, len) { | ||
26623 | if (len < 0x80) { | ||
26624 | arr.push(len); | ||
26625 | return; | ||
26626 | } | ||
26627 | var octets = 1 + (Math.log(len) / Math.LN2 >>> 3); | ||
26628 | arr.push(octets | 0x80); | ||
26629 | while (--octets) { | ||
26630 | arr.push((len >>> (octets << 3)) & 0xff); | ||
26631 | } | ||
26632 | arr.push(len); | ||
26633 | } | ||
26634 | |||
26635 | Signature.prototype.toDER = function toDER(enc) { | ||
26636 | var r = this.r.toArray(); | ||
26637 | var s = this.s.toArray(); | ||
26638 | |||
26639 | // Pad values | ||
26640 | if (r[0] & 0x80) | ||
26641 | r = [ 0 ].concat(r); | ||
26642 | // Pad values | ||
26643 | if (s[0] & 0x80) | ||
26644 | s = [ 0 ].concat(s); | ||
26645 | |||
26646 | r = rmPadding(r); | ||
26647 | s = rmPadding(s); | ||
26648 | |||
26649 | while (!s[0] && !(s[1] & 0x80)) { | ||
26650 | s = s.slice(1); | ||
26651 | } | ||
26652 | var arr = [ 0x02 ]; | ||
26653 | constructLength(arr, r.length); | ||
26654 | arr = arr.concat(r); | ||
26655 | arr.push(0x02); | ||
26656 | constructLength(arr, s.length); | ||
26657 | var backHalf = arr.concat(s); | ||
26658 | var res = [ 0x30 ]; | ||
26659 | constructLength(res, backHalf.length); | ||
26660 | res = res.concat(backHalf); | ||
26661 | return utils.encode(res, enc); | ||
26662 | }; | ||
26663 | |||
26664 | },{"../../elliptic":97,"bn.js":81}],107:[function(require,module,exports){ | ||
26665 | 'use strict'; | ||
26666 | |||
26667 | var hash = require('hash.js'); | ||
26668 | var elliptic = require('../../elliptic'); | ||
26669 | var utils = elliptic.utils; | ||
26670 | var assert = utils.assert; | ||
26671 | var parseBytes = utils.parseBytes; | ||
26672 | var KeyPair = require('./key'); | ||
26673 | var Signature = require('./signature'); | ||
26674 | |||
26675 | function EDDSA(curve) { | ||
26676 | assert(curve === 'ed25519', 'only tested with ed25519 so far'); | ||
26677 | |||
26678 | if (!(this instanceof EDDSA)) | ||
26679 | return new EDDSA(curve); | ||
26680 | |||
26681 | var curve = elliptic.curves[curve].curve; | ||
26682 | this.curve = curve; | ||
26683 | this.g = curve.g; | ||
26684 | this.g.precompute(curve.n.bitLength() + 1); | ||
26685 | |||
26686 | this.pointClass = curve.point().constructor; | ||
26687 | this.encodingLength = Math.ceil(curve.n.bitLength() / 8); | ||
26688 | this.hash = hash.sha512; | ||
26689 | } | ||
26690 | |||
26691 | module.exports = EDDSA; | ||
26692 | |||
26693 | /** | ||
26694 | * @param {Array|String} message - message bytes | ||
26695 | * @param {Array|String|KeyPair} secret - secret bytes or a keypair | ||
26696 | * @returns {Signature} - signature | ||
26697 | */ | ||
26698 | EDDSA.prototype.sign = function sign(message, secret) { | ||
26699 | message = parseBytes(message); | ||
26700 | var key = this.keyFromSecret(secret); | ||
26701 | var r = this.hashInt(key.messagePrefix(), message); | ||
26702 | var R = this.g.mul(r); | ||
26703 | var Rencoded = this.encodePoint(R); | ||
26704 | var s_ = this.hashInt(Rencoded, key.pubBytes(), message) | ||
26705 | .mul(key.priv()); | ||
26706 | var S = r.add(s_).umod(this.curve.n); | ||
26707 | return this.makeSignature({ R: R, S: S, Rencoded: Rencoded }); | ||
26708 | }; | ||
26709 | |||
26710 | /** | ||
26711 | * @param {Array} message - message bytes | ||
26712 | * @param {Array|String|Signature} sig - sig bytes | ||
26713 | * @param {Array|String|Point|KeyPair} pub - public key | ||
26714 | * @returns {Boolean} - true if public key matches sig of message | ||
26715 | */ | ||
26716 | EDDSA.prototype.verify = function verify(message, sig, pub) { | ||
26717 | message = parseBytes(message); | ||
26718 | sig = this.makeSignature(sig); | ||
26719 | var key = this.keyFromPublic(pub); | ||
26720 | var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message); | ||
26721 | var SG = this.g.mul(sig.S()); | ||
26722 | var RplusAh = sig.R().add(key.pub().mul(h)); | ||
26723 | return RplusAh.eq(SG); | ||
26724 | }; | ||
26725 | |||
26726 | EDDSA.prototype.hashInt = function hashInt() { | ||
26727 | var hash = this.hash(); | ||
26728 | for (var i = 0; i < arguments.length; i++) | ||
26729 | hash.update(arguments[i]); | ||
26730 | return utils.intFromLE(hash.digest()).umod(this.curve.n); | ||
26731 | }; | ||
26732 | |||
26733 | EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) { | ||
26734 | return KeyPair.fromPublic(this, pub); | ||
26735 | }; | ||
26736 | |||
26737 | EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) { | ||
26738 | return KeyPair.fromSecret(this, secret); | ||
26739 | }; | ||
26740 | |||
26741 | EDDSA.prototype.makeSignature = function makeSignature(sig) { | ||
26742 | if (sig instanceof Signature) | ||
26743 | return sig; | ||
26744 | return new Signature(this, sig); | ||
26745 | }; | ||
26746 | |||
26747 | /** | ||
26748 | * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2 | ||
26749 | * | ||
26750 | * EDDSA defines methods for encoding and decoding points and integers. These are | ||
26751 | * helper convenience methods, that pass along to utility functions implied | ||
26752 | * parameters. | ||
26753 | * | ||
26754 | */ | ||
26755 | EDDSA.prototype.encodePoint = function encodePoint(point) { | ||
26756 | var enc = point.getY().toArray('le', this.encodingLength); | ||
26757 | enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0; | ||
26758 | return enc; | ||
26759 | }; | ||
26760 | |||
26761 | EDDSA.prototype.decodePoint = function decodePoint(bytes) { | ||
26762 | bytes = utils.parseBytes(bytes); | ||
26763 | |||
26764 | var lastIx = bytes.length - 1; | ||
26765 | var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80); | ||
26766 | var xIsOdd = (bytes[lastIx] & 0x80) !== 0; | ||
26767 | |||
26768 | var y = utils.intFromLE(normed); | ||
26769 | return this.curve.pointFromY(y, xIsOdd); | ||
26770 | }; | ||
26771 | |||
26772 | EDDSA.prototype.encodeInt = function encodeInt(num) { | ||
26773 | return num.toArray('le', this.encodingLength); | ||
26774 | }; | ||
26775 | |||
26776 | EDDSA.prototype.decodeInt = function decodeInt(bytes) { | ||
26777 | return utils.intFromLE(bytes); | ||
26778 | }; | ||
26779 | |||
26780 | EDDSA.prototype.isPoint = function isPoint(val) { | ||
26781 | return val instanceof this.pointClass; | ||
26782 | }; | ||
26783 | |||
26784 | },{"../../elliptic":97,"./key":108,"./signature":109,"hash.js":114}],108:[function(require,module,exports){ | ||
26785 | 'use strict'; | ||
26786 | |||
26787 | var elliptic = require('../../elliptic'); | ||
26788 | var utils = elliptic.utils; | ||
26789 | var assert = utils.assert; | ||
26790 | var parseBytes = utils.parseBytes; | ||
26791 | var cachedProperty = utils.cachedProperty; | ||
26792 | |||
26793 | /** | ||
26794 | * @param {EDDSA} eddsa - instance | ||
26795 | * @param {Object} params - public/private key parameters | ||
26796 | * | ||
26797 | * @param {Array<Byte>} [params.secret] - secret seed bytes | ||
26798 | * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms) | ||
26799 | * @param {Array<Byte>} [params.pub] - public key point encoded as bytes | ||
26800 | * | ||
26801 | */ | ||
26802 | function KeyPair(eddsa, params) { | ||
26803 | this.eddsa = eddsa; | ||
26804 | this._secret = parseBytes(params.secret); | ||
26805 | if (eddsa.isPoint(params.pub)) | ||
26806 | this._pub = params.pub; | ||
26807 | else | ||
26808 | this._pubBytes = parseBytes(params.pub); | ||
26809 | } | ||
26810 | |||
26811 | KeyPair.fromPublic = function fromPublic(eddsa, pub) { | ||
26812 | if (pub instanceof KeyPair) | ||
26813 | return pub; | ||
26814 | return new KeyPair(eddsa, { pub: pub }); | ||
26815 | }; | ||
26816 | |||
26817 | KeyPair.fromSecret = function fromSecret(eddsa, secret) { | ||
26818 | if (secret instanceof KeyPair) | ||
26819 | return secret; | ||
26820 | return new KeyPair(eddsa, { secret: secret }); | ||
26821 | }; | ||
26822 | |||
26823 | KeyPair.prototype.secret = function secret() { | ||
26824 | return this._secret; | ||
26825 | }; | ||
26826 | |||
26827 | cachedProperty(KeyPair, 'pubBytes', function pubBytes() { | ||
26828 | return this.eddsa.encodePoint(this.pub()); | ||
26829 | }); | ||
26830 | |||
26831 | cachedProperty(KeyPair, 'pub', function pub() { | ||
26832 | if (this._pubBytes) | ||
26833 | return this.eddsa.decodePoint(this._pubBytes); | ||
26834 | return this.eddsa.g.mul(this.priv()); | ||
26835 | }); | ||
26836 | |||
26837 | cachedProperty(KeyPair, 'privBytes', function privBytes() { | ||
26838 | var eddsa = this.eddsa; | ||
26839 | var hash = this.hash(); | ||
26840 | var lastIx = eddsa.encodingLength - 1; | ||
26841 | |||
26842 | var a = hash.slice(0, eddsa.encodingLength); | ||
26843 | a[0] &= 248; | ||
26844 | a[lastIx] &= 127; | ||
26845 | a[lastIx] |= 64; | ||
26846 | |||
26847 | return a; | ||
26848 | }); | ||
26849 | |||
26850 | cachedProperty(KeyPair, 'priv', function priv() { | ||
26851 | return this.eddsa.decodeInt(this.privBytes()); | ||
26852 | }); | ||
26853 | |||
26854 | cachedProperty(KeyPair, 'hash', function hash() { | ||
26855 | return this.eddsa.hash().update(this.secret()).digest(); | ||
26856 | }); | ||
26857 | |||
26858 | cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() { | ||
26859 | return this.hash().slice(this.eddsa.encodingLength); | ||
26860 | }); | ||
26861 | |||
26862 | KeyPair.prototype.sign = function sign(message) { | ||
26863 | assert(this._secret, 'KeyPair can only verify'); | ||
26864 | return this.eddsa.sign(message, this); | ||
26865 | }; | ||
26866 | |||
26867 | KeyPair.prototype.verify = function verify(message, sig) { | ||
26868 | return this.eddsa.verify(message, sig, this); | ||
26869 | }; | ||
26870 | |||
26871 | KeyPair.prototype.getSecret = function getSecret(enc) { | ||
26872 | assert(this._secret, 'KeyPair is public only'); | ||
26873 | return utils.encode(this.secret(), enc); | ||
26874 | }; | ||
26875 | |||
26876 | KeyPair.prototype.getPublic = function getPublic(enc) { | ||
26877 | return utils.encode(this.pubBytes(), enc); | ||
26878 | }; | ||
26879 | |||
26880 | module.exports = KeyPair; | ||
26881 | |||
26882 | },{"../../elliptic":97}],109:[function(require,module,exports){ | ||
26883 | 'use strict'; | ||
26884 | |||
26885 | var BN = require('bn.js'); | ||
26886 | var elliptic = require('../../elliptic'); | ||
26887 | var utils = elliptic.utils; | ||
26888 | var assert = utils.assert; | ||
26889 | var cachedProperty = utils.cachedProperty; | ||
26890 | var parseBytes = utils.parseBytes; | ||
26891 | |||
26892 | /** | ||
26893 | * @param {EDDSA} eddsa - eddsa instance | ||
26894 | * @param {Array<Bytes>|Object} sig - | ||
26895 | * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes | ||
26896 | * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes | ||
26897 | * @param {Array<Bytes>} [sig.Rencoded] - R point encoded | ||
26898 | * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded | ||
26899 | */ | ||
26900 | function Signature(eddsa, sig) { | ||
26901 | this.eddsa = eddsa; | ||
26902 | |||
26903 | if (typeof sig !== 'object') | ||
26904 | sig = parseBytes(sig); | ||
26905 | |||
26906 | if (Array.isArray(sig)) { | ||
26907 | sig = { | ||
26908 | R: sig.slice(0, eddsa.encodingLength), | ||
26909 | S: sig.slice(eddsa.encodingLength) | ||
26910 | }; | ||
26911 | } | ||
26912 | |||
26913 | assert(sig.R && sig.S, 'Signature without R or S'); | ||
26914 | |||
26915 | if (eddsa.isPoint(sig.R)) | ||
26916 | this._R = sig.R; | ||
26917 | if (sig.S instanceof BN) | ||
26918 | this._S = sig.S; | ||
26919 | |||
26920 | this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded; | ||
26921 | this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded; | ||
26922 | } | ||
26923 | |||
26924 | cachedProperty(Signature, 'S', function S() { | ||
26925 | return this.eddsa.decodeInt(this.Sencoded()); | ||
26926 | }); | ||
26927 | |||
26928 | cachedProperty(Signature, 'R', function R() { | ||
26929 | return this.eddsa.decodePoint(this.Rencoded()); | ||
26930 | }); | ||
26931 | |||
26932 | cachedProperty(Signature, 'Rencoded', function Rencoded() { | ||
26933 | return this.eddsa.encodePoint(this.R()); | ||
26934 | }); | ||
26935 | |||
26936 | cachedProperty(Signature, 'Sencoded', function Sencoded() { | ||
26937 | return this.eddsa.encodeInt(this.S()); | ||
26938 | }); | ||
26939 | |||
26940 | Signature.prototype.toBytes = function toBytes() { | ||
26941 | return this.Rencoded().concat(this.Sencoded()); | ||
26942 | }; | ||
26943 | |||
26944 | Signature.prototype.toHex = function toHex() { | ||
26945 | return utils.encode(this.toBytes(), 'hex').toUpperCase(); | ||
26946 | }; | ||
26947 | |||
26948 | module.exports = Signature; | ||
26949 | |||
26950 | },{"../../elliptic":97,"bn.js":81}],110:[function(require,module,exports){ | ||
26951 | module.exports = { | ||
26952 | doubles: { | ||
26953 | step: 4, | ||
26954 | points: [ | ||
26955 | [ | ||
26956 | 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a', | ||
26957 | 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821' | ||
26958 | ], | ||
26959 | [ | ||
26960 | '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508', | ||
26961 | '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf' | ||
26962 | ], | ||
26963 | [ | ||
26964 | '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739', | ||
26965 | 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695' | ||
26966 | ], | ||
26967 | [ | ||
26968 | '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640', | ||
26969 | '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9' | ||
26970 | ], | ||
26971 | [ | ||
26972 | '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c', | ||
26973 | '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36' | ||
26974 | ], | ||
26975 | [ | ||
26976 | '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda', | ||
26977 | '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f' | ||
26978 | ], | ||
26979 | [ | ||
26980 | 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa', | ||
26981 | '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999' | ||
26982 | ], | ||
26983 | [ | ||
26984 | '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0', | ||
26985 | 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09' | ||
26986 | ], | ||
26987 | [ | ||
26988 | 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d', | ||
26989 | '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d' | ||
26990 | ], | ||
26991 | [ | ||
26992 | 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d', | ||
26993 | 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088' | ||
26994 | ], | ||
26995 | [ | ||
26996 | 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1', | ||
26997 | '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d' | ||
26998 | ], | ||
26999 | [ | ||
27000 | '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0', | ||
27001 | '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8' | ||
27002 | ], | ||
27003 | [ | ||
27004 | '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047', | ||
27005 | '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a' | ||
27006 | ], | ||
27007 | [ | ||
27008 | '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862', | ||
27009 | '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453' | ||
27010 | ], | ||
27011 | [ | ||
27012 | '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7', | ||
27013 | '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160' | ||
27014 | ], | ||
27015 | [ | ||
27016 | '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd', | ||
27017 | '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0' | ||
27018 | ], | ||
27019 | [ | ||
27020 | '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83', | ||
27021 | '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6' | ||
27022 | ], | ||
27023 | [ | ||
27024 | '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a', | ||
27025 | '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589' | ||
27026 | ], | ||
27027 | [ | ||
27028 | '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8', | ||
27029 | 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17' | ||
27030 | ], | ||
27031 | [ | ||
27032 | 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d', | ||
27033 | '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda' | ||
27034 | ], | ||
27035 | [ | ||
27036 | 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725', | ||
27037 | '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd' | ||
27038 | ], | ||
27039 | [ | ||
27040 | '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754', | ||
27041 | '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2' | ||
27042 | ], | ||
27043 | [ | ||
27044 | '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c', | ||
27045 | '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6' | ||
27046 | ], | ||
27047 | [ | ||
27048 | 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6', | ||
27049 | '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f' | ||
27050 | ], | ||
27051 | [ | ||
27052 | '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39', | ||
27053 | 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01' | ||
27054 | ], | ||
27055 | [ | ||
27056 | 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891', | ||
27057 | '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3' | ||
27058 | ], | ||
27059 | [ | ||
27060 | 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b', | ||
27061 | 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f' | ||
27062 | ], | ||
27063 | [ | ||
27064 | 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03', | ||
27065 | '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7' | ||
27066 | ], | ||
27067 | [ | ||
27068 | 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d', | ||
27069 | 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78' | ||
27070 | ], | ||
27071 | [ | ||
27072 | 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070', | ||
27073 | '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1' | ||
27074 | ], | ||
27075 | [ | ||
27076 | '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4', | ||
27077 | 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150' | ||
27078 | ], | ||
27079 | [ | ||
27080 | '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da', | ||
27081 | '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82' | ||
27082 | ], | ||
27083 | [ | ||
27084 | 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11', | ||
27085 | '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc' | ||
27086 | ], | ||
27087 | [ | ||
27088 | '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e', | ||
27089 | 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b' | ||
27090 | ], | ||
27091 | [ | ||
27092 | 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41', | ||
27093 | '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51' | ||
27094 | ], | ||
27095 | [ | ||
27096 | 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef', | ||
27097 | '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45' | ||
27098 | ], | ||
27099 | [ | ||
27100 | 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8', | ||
27101 | 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120' | ||
27102 | ], | ||
27103 | [ | ||
27104 | '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d', | ||
27105 | '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84' | ||
27106 | ], | ||
27107 | [ | ||
27108 | '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96', | ||
27109 | '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d' | ||
27110 | ], | ||
27111 | [ | ||
27112 | '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd', | ||
27113 | 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d' | ||
27114 | ], | ||
27115 | [ | ||
27116 | '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5', | ||
27117 | '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8' | ||
27118 | ], | ||
27119 | [ | ||
27120 | 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266', | ||
27121 | '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8' | ||
27122 | ], | ||
27123 | [ | ||
27124 | '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71', | ||
27125 | '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac' | ||
27126 | ], | ||
27127 | [ | ||
27128 | '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac', | ||
27129 | 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f' | ||
27130 | ], | ||
27131 | [ | ||
27132 | '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751', | ||
27133 | '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962' | ||
27134 | ], | ||
27135 | [ | ||
27136 | 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e', | ||
27137 | '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907' | ||
27138 | ], | ||
27139 | [ | ||
27140 | '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241', | ||
27141 | 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec' | ||
27142 | ], | ||
27143 | [ | ||
27144 | 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3', | ||
27145 | 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d' | ||
27146 | ], | ||
27147 | [ | ||
27148 | 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f', | ||
27149 | '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414' | ||
27150 | ], | ||
27151 | [ | ||
27152 | '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19', | ||
27153 | 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd' | ||
27154 | ], | ||
27155 | [ | ||
27156 | '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be', | ||
27157 | 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0' | ||
27158 | ], | ||
27159 | [ | ||
27160 | 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9', | ||
27161 | '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811' | ||
27162 | ], | ||
27163 | [ | ||
27164 | 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2', | ||
27165 | '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1' | ||
27166 | ], | ||
27167 | [ | ||
27168 | 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13', | ||
27169 | '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c' | ||
27170 | ], | ||
27171 | [ | ||
27172 | '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c', | ||
27173 | 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73' | ||
27174 | ], | ||
27175 | [ | ||
27176 | '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba', | ||
27177 | '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd' | ||
27178 | ], | ||
27179 | [ | ||
27180 | 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151', | ||
27181 | 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405' | ||
27182 | ], | ||
27183 | [ | ||
27184 | '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073', | ||
27185 | 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589' | ||
27186 | ], | ||
27187 | [ | ||
27188 | '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458', | ||
27189 | '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e' | ||
27190 | ], | ||
27191 | [ | ||
27192 | '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b', | ||
27193 | '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27' | ||
27194 | ], | ||
27195 | [ | ||
27196 | 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366', | ||
27197 | 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1' | ||
27198 | ], | ||
27199 | [ | ||
27200 | '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa', | ||
27201 | '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482' | ||
27202 | ], | ||
27203 | [ | ||
27204 | '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0', | ||
27205 | '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945' | ||
27206 | ], | ||
27207 | [ | ||
27208 | 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787', | ||
27209 | '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573' | ||
27210 | ], | ||
27211 | [ | ||
27212 | 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e', | ||
27213 | 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82' | ||
27214 | ] | ||
27215 | ] | ||
27216 | }, | ||
27217 | naf: { | ||
27218 | wnd: 7, | ||
27219 | points: [ | ||
27220 | [ | ||
27221 | 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9', | ||
27222 | '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672' | ||
27223 | ], | ||
27224 | [ | ||
27225 | '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4', | ||
27226 | 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6' | ||
27227 | ], | ||
27228 | [ | ||
27229 | '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc', | ||
27230 | '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da' | ||
27231 | ], | ||
27232 | [ | ||
27233 | 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe', | ||
27234 | 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37' | ||
27235 | ], | ||
27236 | [ | ||
27237 | '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb', | ||
27238 | 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b' | ||
27239 | ], | ||
27240 | [ | ||
27241 | 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8', | ||
27242 | 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81' | ||
27243 | ], | ||
27244 | [ | ||
27245 | 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e', | ||
27246 | '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58' | ||
27247 | ], | ||
27248 | [ | ||
27249 | 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34', | ||
27250 | '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77' | ||
27251 | ], | ||
27252 | [ | ||
27253 | '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c', | ||
27254 | '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a' | ||
27255 | ], | ||
27256 | [ | ||
27257 | '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5', | ||
27258 | '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c' | ||
27259 | ], | ||
27260 | [ | ||
27261 | '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f', | ||
27262 | '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67' | ||
27263 | ], | ||
27264 | [ | ||
27265 | '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714', | ||
27266 | '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402' | ||
27267 | ], | ||
27268 | [ | ||
27269 | 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729', | ||
27270 | 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55' | ||
27271 | ], | ||
27272 | [ | ||
27273 | 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db', | ||
27274 | '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482' | ||
27275 | ], | ||
27276 | [ | ||
27277 | '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4', | ||
27278 | 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82' | ||
27279 | ], | ||
27280 | [ | ||
27281 | '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5', | ||
27282 | 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396' | ||
27283 | ], | ||
27284 | [ | ||
27285 | '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479', | ||
27286 | '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49' | ||
27287 | ], | ||
27288 | [ | ||
27289 | '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d', | ||
27290 | '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf' | ||
27291 | ], | ||
27292 | [ | ||
27293 | '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f', | ||
27294 | '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a' | ||
27295 | ], | ||
27296 | [ | ||
27297 | '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb', | ||
27298 | 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7' | ||
27299 | ], | ||
27300 | [ | ||
27301 | 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9', | ||
27302 | 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933' | ||
27303 | ], | ||
27304 | [ | ||
27305 | '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963', | ||
27306 | '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a' | ||
27307 | ], | ||
27308 | [ | ||
27309 | '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74', | ||
27310 | '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6' | ||
27311 | ], | ||
27312 | [ | ||
27313 | 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530', | ||
27314 | 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37' | ||
27315 | ], | ||
27316 | [ | ||
27317 | '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b', | ||
27318 | '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e' | ||
27319 | ], | ||
27320 | [ | ||
27321 | 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247', | ||
27322 | 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6' | ||
27323 | ], | ||
27324 | [ | ||
27325 | 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1', | ||
27326 | 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476' | ||
27327 | ], | ||
27328 | [ | ||
27329 | '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120', | ||
27330 | '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40' | ||
27331 | ], | ||
27332 | [ | ||
27333 | '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435', | ||
27334 | '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61' | ||
27335 | ], | ||
27336 | [ | ||
27337 | '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18', | ||
27338 | '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683' | ||
27339 | ], | ||
27340 | [ | ||
27341 | 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8', | ||
27342 | '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5' | ||
27343 | ], | ||
27344 | [ | ||
27345 | '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb', | ||
27346 | '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b' | ||
27347 | ], | ||
27348 | [ | ||
27349 | 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f', | ||
27350 | '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417' | ||
27351 | ], | ||
27352 | [ | ||
27353 | '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143', | ||
27354 | 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868' | ||
27355 | ], | ||
27356 | [ | ||
27357 | '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba', | ||
27358 | 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a' | ||
27359 | ], | ||
27360 | [ | ||
27361 | 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45', | ||
27362 | 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6' | ||
27363 | ], | ||
27364 | [ | ||
27365 | '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a', | ||
27366 | '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996' | ||
27367 | ], | ||
27368 | [ | ||
27369 | '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e', | ||
27370 | 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e' | ||
27371 | ], | ||
27372 | [ | ||
27373 | 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8', | ||
27374 | 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d' | ||
27375 | ], | ||
27376 | [ | ||
27377 | '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c', | ||
27378 | '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2' | ||
27379 | ], | ||
27380 | [ | ||
27381 | '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519', | ||
27382 | 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e' | ||
27383 | ], | ||
27384 | [ | ||
27385 | '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab', | ||
27386 | '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437' | ||
27387 | ], | ||
27388 | [ | ||
27389 | '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca', | ||
27390 | 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311' | ||
27391 | ], | ||
27392 | [ | ||
27393 | 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf', | ||
27394 | '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4' | ||
27395 | ], | ||
27396 | [ | ||
27397 | '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610', | ||
27398 | '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575' | ||
27399 | ], | ||
27400 | [ | ||
27401 | '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4', | ||
27402 | 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d' | ||
27403 | ], | ||
27404 | [ | ||
27405 | '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c', | ||
27406 | 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d' | ||
27407 | ], | ||
27408 | [ | ||
27409 | 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940', | ||
27410 | 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629' | ||
27411 | ], | ||
27412 | [ | ||
27413 | 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980', | ||
27414 | 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06' | ||
27415 | ], | ||
27416 | [ | ||
27417 | '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3', | ||
27418 | '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374' | ||
27419 | ], | ||
27420 | [ | ||
27421 | '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf', | ||
27422 | '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee' | ||
27423 | ], | ||
27424 | [ | ||
27425 | 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63', | ||
27426 | '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1' | ||
27427 | ], | ||
27428 | [ | ||
27429 | 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448', | ||
27430 | 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b' | ||
27431 | ], | ||
27432 | [ | ||
27433 | '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf', | ||
27434 | '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661' | ||
27435 | ], | ||
27436 | [ | ||
27437 | '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5', | ||
27438 | '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6' | ||
27439 | ], | ||
27440 | [ | ||
27441 | 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6', | ||
27442 | '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e' | ||
27443 | ], | ||
27444 | [ | ||
27445 | '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5', | ||
27446 | '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d' | ||
27447 | ], | ||
27448 | [ | ||
27449 | 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99', | ||
27450 | 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc' | ||
27451 | ], | ||
27452 | [ | ||
27453 | '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51', | ||
27454 | 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4' | ||
27455 | ], | ||
27456 | [ | ||
27457 | '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5', | ||
27458 | '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c' | ||
27459 | ], | ||
27460 | [ | ||
27461 | 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5', | ||
27462 | '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b' | ||
27463 | ], | ||
27464 | [ | ||
27465 | 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997', | ||
27466 | '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913' | ||
27467 | ], | ||
27468 | [ | ||
27469 | '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881', | ||
27470 | '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154' | ||
27471 | ], | ||
27472 | [ | ||
27473 | '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5', | ||
27474 | '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865' | ||
27475 | ], | ||
27476 | [ | ||
27477 | '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66', | ||
27478 | 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc' | ||
27479 | ], | ||
27480 | [ | ||
27481 | '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726', | ||
27482 | 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224' | ||
27483 | ], | ||
27484 | [ | ||
27485 | '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede', | ||
27486 | '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e' | ||
27487 | ], | ||
27488 | [ | ||
27489 | '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94', | ||
27490 | '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6' | ||
27491 | ], | ||
27492 | [ | ||
27493 | '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31', | ||
27494 | '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511' | ||
27495 | ], | ||
27496 | [ | ||
27497 | '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51', | ||
27498 | 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b' | ||
27499 | ], | ||
27500 | [ | ||
27501 | 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252', | ||
27502 | 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2' | ||
27503 | ], | ||
27504 | [ | ||
27505 | '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5', | ||
27506 | 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c' | ||
27507 | ], | ||
27508 | [ | ||
27509 | 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b', | ||
27510 | '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3' | ||
27511 | ], | ||
27512 | [ | ||
27513 | 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4', | ||
27514 | '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d' | ||
27515 | ], | ||
27516 | [ | ||
27517 | 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f', | ||
27518 | '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700' | ||
27519 | ], | ||
27520 | [ | ||
27521 | 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889', | ||
27522 | '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4' | ||
27523 | ], | ||
27524 | [ | ||
27525 | '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246', | ||
27526 | 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196' | ||
27527 | ], | ||
27528 | [ | ||
27529 | '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984', | ||
27530 | '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4' | ||
27531 | ], | ||
27532 | [ | ||
27533 | '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a', | ||
27534 | 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257' | ||
27535 | ], | ||
27536 | [ | ||
27537 | 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030', | ||
27538 | 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13' | ||
27539 | ], | ||
27540 | [ | ||
27541 | 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197', | ||
27542 | '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096' | ||
27543 | ], | ||
27544 | [ | ||
27545 | 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593', | ||
27546 | 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38' | ||
27547 | ], | ||
27548 | [ | ||
27549 | 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef', | ||
27550 | '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f' | ||
27551 | ], | ||
27552 | [ | ||
27553 | '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38', | ||
27554 | '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448' | ||
27555 | ], | ||
27556 | [ | ||
27557 | 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a', | ||
27558 | '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a' | ||
27559 | ], | ||
27560 | [ | ||
27561 | 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111', | ||
27562 | '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4' | ||
27563 | ], | ||
27564 | [ | ||
27565 | '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502', | ||
27566 | '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437' | ||
27567 | ], | ||
27568 | [ | ||
27569 | '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea', | ||
27570 | 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7' | ||
27571 | ], | ||
27572 | [ | ||
27573 | 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26', | ||
27574 | '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d' | ||
27575 | ], | ||
27576 | [ | ||
27577 | 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986', | ||
27578 | '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a' | ||
27579 | ], | ||
27580 | [ | ||
27581 | 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e', | ||
27582 | '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54' | ||
27583 | ], | ||
27584 | [ | ||
27585 | '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4', | ||
27586 | '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77' | ||
27587 | ], | ||
27588 | [ | ||
27589 | 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda', | ||
27590 | 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517' | ||
27591 | ], | ||
27592 | [ | ||
27593 | '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859', | ||
27594 | 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10' | ||
27595 | ], | ||
27596 | [ | ||
27597 | 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f', | ||
27598 | 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125' | ||
27599 | ], | ||
27600 | [ | ||
27601 | 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c', | ||
27602 | '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e' | ||
27603 | ], | ||
27604 | [ | ||
27605 | '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942', | ||
27606 | 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1' | ||
27607 | ], | ||
27608 | [ | ||
27609 | 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a', | ||
27610 | '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2' | ||
27611 | ], | ||
27612 | [ | ||
27613 | 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80', | ||
27614 | '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423' | ||
27615 | ], | ||
27616 | [ | ||
27617 | 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d', | ||
27618 | '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8' | ||
27619 | ], | ||
27620 | [ | ||
27621 | '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1', | ||
27622 | 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758' | ||
27623 | ], | ||
27624 | [ | ||
27625 | '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63', | ||
27626 | 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375' | ||
27627 | ], | ||
27628 | [ | ||
27629 | 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352', | ||
27630 | '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d' | ||
27631 | ], | ||
27632 | [ | ||
27633 | '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193', | ||
27634 | 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec' | ||
27635 | ], | ||
27636 | [ | ||
27637 | '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00', | ||
27638 | '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0' | ||
27639 | ], | ||
27640 | [ | ||
27641 | '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58', | ||
27642 | 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c' | ||
27643 | ], | ||
27644 | [ | ||
27645 | 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7', | ||
27646 | 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4' | ||
27647 | ], | ||
27648 | [ | ||
27649 | '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8', | ||
27650 | 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f' | ||
27651 | ], | ||
27652 | [ | ||
27653 | '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e', | ||
27654 | '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649' | ||
27655 | ], | ||
27656 | [ | ||
27657 | '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d', | ||
27658 | 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826' | ||
27659 | ], | ||
27660 | [ | ||
27661 | '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b', | ||
27662 | '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5' | ||
27663 | ], | ||
27664 | [ | ||
27665 | 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f', | ||
27666 | 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87' | ||
27667 | ], | ||
27668 | [ | ||
27669 | '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6', | ||
27670 | '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b' | ||
27671 | ], | ||
27672 | [ | ||
27673 | 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297', | ||
27674 | '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc' | ||
27675 | ], | ||
27676 | [ | ||
27677 | '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a', | ||
27678 | '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c' | ||
27679 | ], | ||
27680 | [ | ||
27681 | 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c', | ||
27682 | 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f' | ||
27683 | ], | ||
27684 | [ | ||
27685 | 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52', | ||
27686 | '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a' | ||
27687 | ], | ||
27688 | [ | ||
27689 | 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb', | ||
27690 | 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46' | ||
27691 | ], | ||
27692 | [ | ||
27693 | '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065', | ||
27694 | 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f' | ||
27695 | ], | ||
27696 | [ | ||
27697 | '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917', | ||
27698 | '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03' | ||
27699 | ], | ||
27700 | [ | ||
27701 | '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9', | ||
27702 | 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08' | ||
27703 | ], | ||
27704 | [ | ||
27705 | '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3', | ||
27706 | '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8' | ||
27707 | ], | ||
27708 | [ | ||
27709 | '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57', | ||
27710 | '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373' | ||
27711 | ], | ||
27712 | [ | ||
27713 | '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66', | ||
27714 | 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3' | ||
27715 | ], | ||
27716 | [ | ||
27717 | '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8', | ||
27718 | '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8' | ||
27719 | ], | ||
27720 | [ | ||
27721 | '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721', | ||
27722 | '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1' | ||
27723 | ], | ||
27724 | [ | ||
27725 | '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180', | ||
27726 | '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9' | ||
27727 | ] | ||
27728 | ] | ||
27729 | } | ||
27730 | }; | ||
27731 | |||
27732 | },{}],111:[function(require,module,exports){ | ||
27733 | 'use strict'; | ||
27734 | |||
27735 | var utils = exports; | ||
27736 | var BN = require('bn.js'); | ||
27737 | var minAssert = require('minimalistic-assert'); | ||
27738 | var minUtils = require('minimalistic-crypto-utils'); | ||
27739 | |||
27740 | utils.assert = minAssert; | ||
27741 | utils.toArray = minUtils.toArray; | ||
27742 | utils.zero2 = minUtils.zero2; | ||
27743 | utils.toHex = minUtils.toHex; | ||
27744 | utils.encode = minUtils.encode; | ||
27745 | |||
27746 | // Represent num in a w-NAF form | ||
27747 | function getNAF(num, w) { | ||
27748 | var naf = []; | ||
27749 | var ws = 1 << (w + 1); | ||
27750 | var k = num.clone(); | ||
27751 | while (k.cmpn(1) >= 0) { | ||
27752 | var z; | ||
27753 | if (k.isOdd()) { | ||
27754 | var mod = k.andln(ws - 1); | ||
27755 | if (mod > (ws >> 1) - 1) | ||
27756 | z = (ws >> 1) - mod; | ||
27757 | else | ||
27758 | z = mod; | ||
27759 | k.isubn(z); | ||
27760 | } else { | ||
27761 | z = 0; | ||
27762 | } | ||
27763 | naf.push(z); | ||
27764 | |||
27765 | // Optimization, shift by word if possible | ||
27766 | var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1; | ||
27767 | for (var i = 1; i < shift; i++) | ||
27768 | naf.push(0); | ||
27769 | k.iushrn(shift); | ||
27770 | } | ||
27771 | |||
27772 | return naf; | ||
27773 | } | ||
27774 | utils.getNAF = getNAF; | ||
27775 | |||
27776 | // Represent k1, k2 in a Joint Sparse Form | ||
27777 | function getJSF(k1, k2) { | ||
27778 | var jsf = [ | ||
27779 | [], | ||
27780 | [] | ||
27781 | ]; | ||
27782 | |||
27783 | k1 = k1.clone(); | ||
27784 | k2 = k2.clone(); | ||
27785 | var d1 = 0; | ||
27786 | var d2 = 0; | ||
27787 | while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { | ||
27788 | |||
27789 | // First phase | ||
27790 | var m14 = (k1.andln(3) + d1) & 3; | ||
27791 | var m24 = (k2.andln(3) + d2) & 3; | ||
27792 | if (m14 === 3) | ||
27793 | m14 = -1; | ||
27794 | if (m24 === 3) | ||
27795 | m24 = -1; | ||
27796 | var u1; | ||
27797 | if ((m14 & 1) === 0) { | ||
27798 | u1 = 0; | ||
27799 | } else { | ||
27800 | var m8 = (k1.andln(7) + d1) & 7; | ||
27801 | if ((m8 === 3 || m8 === 5) && m24 === 2) | ||
27802 | u1 = -m14; | ||
27803 | else | ||
27804 | u1 = m14; | ||
27805 | } | ||
27806 | jsf[0].push(u1); | ||
27807 | |||
27808 | var u2; | ||
27809 | if ((m24 & 1) === 0) { | ||
27810 | u2 = 0; | ||
27811 | } else { | ||
27812 | var m8 = (k2.andln(7) + d2) & 7; | ||
27813 | if ((m8 === 3 || m8 === 5) && m14 === 2) | ||
27814 | u2 = -m24; | ||
27815 | else | ||
27816 | u2 = m24; | ||
27817 | } | ||
27818 | jsf[1].push(u2); | ||
27819 | |||
27820 | // Second phase | ||
27821 | if (2 * d1 === u1 + 1) | ||
27822 | d1 = 1 - d1; | ||
27823 | if (2 * d2 === u2 + 1) | ||
27824 | d2 = 1 - d2; | ||
27825 | k1.iushrn(1); | ||
27826 | k2.iushrn(1); | ||
27827 | } | ||
27828 | |||
27829 | return jsf; | ||
27830 | } | ||
27831 | utils.getJSF = getJSF; | ||
27832 | |||
27833 | function cachedProperty(obj, name, computer) { | ||
27834 | var key = '_' + name; | ||
27835 | obj.prototype[name] = function cachedProperty() { | ||
27836 | return this[key] !== undefined ? this[key] : | ||
27837 | this[key] = computer.call(this); | ||
27838 | }; | ||
27839 | } | ||
27840 | utils.cachedProperty = cachedProperty; | ||
27841 | |||
27842 | function parseBytes(bytes) { | ||
27843 | return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : | ||
27844 | bytes; | ||
27845 | } | ||
27846 | utils.parseBytes = parseBytes; | ||
27847 | |||
27848 | function intFromLE(bytes) { | ||
27849 | return new BN(bytes, 'hex', 'le'); | ||
27850 | } | ||
27851 | utils.intFromLE = intFromLE; | ||
27852 | |||
27853 | |||
27854 | },{"bn.js":81,"minimalistic-assert":123,"minimalistic-crypto-utils":124}],112:[function(require,module,exports){ | ||
27855 | module.exports={ | ||
27856 | "_args": [ | ||
27857 | [ | ||
27858 | "elliptic", | ||
27859 | "/home/ian/git/bitcoin/bitcoinjs-lib-browser" | ||
27860 | ] | ||
27861 | ], | ||
27862 | "_from": "elliptic@latest", | ||
27863 | "_id": "elliptic@6.4.0", | ||
27864 | "_inCache": true, | ||
27865 | "_installable": true, | ||
27866 | "_location": "/elliptic", | ||
27867 | "_nodeVersion": "7.0.0", | ||
27868 | "_npmOperationalInternal": { | ||
27869 | "host": "packages-18-east.internal.npmjs.com", | ||
27870 | "tmp": "tmp/elliptic-6.4.0.tgz_1487798866428_0.30510620190761983" | ||
27871 | }, | ||
27872 | "_npmUser": { | ||
27873 | "email": "fedor@indutny.com", | ||
27874 | "name": "indutny" | ||
27875 | }, | ||
27876 | "_npmVersion": "3.10.8", | ||
27877 | "_phantomChildren": {}, | ||
27878 | "_requested": { | ||
27879 | "name": "elliptic", | ||
27880 | "raw": "elliptic", | ||
27881 | "rawSpec": "", | ||
27882 | "scope": null, | ||
27883 | "spec": "latest", | ||
27884 | "type": "tag" | ||
27885 | }, | ||
27886 | "_requiredBy": [ | ||
27887 | "#USER" | ||
27888 | ], | ||
27889 | "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", | ||
27890 | "_shasum": "cac9af8762c85836187003c8dfe193e5e2eae5df", | ||
27891 | "_shrinkwrap": null, | ||
27892 | "_spec": "elliptic", | ||
27893 | "_where": "/home/ian/git/bitcoin/bitcoinjs-lib-browser", | ||
27894 | "author": { | ||
27895 | "email": "fedor@indutny.com", | ||
27896 | "name": "Fedor Indutny" | ||
27897 | }, | ||
27898 | "bugs": { | ||
27899 | "url": "https://github.com/indutny/elliptic/issues" | ||
27900 | }, | ||
27901 | "dependencies": { | ||
27902 | "bn.js": "^4.4.0", | ||
27903 | "brorand": "^1.0.1", | ||
27904 | "hash.js": "^1.0.0", | ||
27905 | "hmac-drbg": "^1.0.0", | ||
27906 | "inherits": "^2.0.1", | ||
27907 | "minimalistic-assert": "^1.0.0", | ||
27908 | "minimalistic-crypto-utils": "^1.0.0" | ||
27909 | }, | ||
27910 | "description": "EC cryptography", | ||
27911 | "devDependencies": { | ||
27912 | "brfs": "^1.4.3", | ||
27913 | "coveralls": "^2.11.3", | ||
27914 | "grunt": "^0.4.5", | ||
27915 | "grunt-browserify": "^5.0.0", | ||
27916 | "grunt-cli": "^1.2.0", | ||
27917 | "grunt-contrib-connect": "^1.0.0", | ||
27918 | "grunt-contrib-copy": "^1.0.0", | ||
27919 | "grunt-contrib-uglify": "^1.0.1", | ||
27920 | "grunt-mocha-istanbul": "^3.0.1", | ||
27921 | "grunt-saucelabs": "^8.6.2", | ||
27922 | "istanbul": "^0.4.2", | ||
27923 | "jscs": "^2.9.0", | ||
27924 | "jshint": "^2.6.0", | ||
27925 | "mocha": "^2.1.0" | ||
27926 | }, | ||
27927 | "directories": {}, | ||
27928 | "dist": { | ||
27929 | "shasum": "cac9af8762c85836187003c8dfe193e5e2eae5df", | ||
27930 | "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz" | ||
27931 | }, | ||
27932 | "files": [ | ||
27933 | "lib" | ||
27934 | ], | ||
27935 | "gitHead": "6b0d2b76caae91471649c8e21f0b1d3ba0f96090", | ||
27936 | "homepage": "https://github.com/indutny/elliptic", | ||
27937 | "keywords": [ | ||
27938 | "EC", | ||
27939 | "Elliptic", | ||
27940 | "curve", | ||
27941 | "Cryptography" | ||
27942 | ], | ||
27943 | "license": "MIT", | ||
27944 | "main": "lib/elliptic.js", | ||
27945 | "maintainers": [ | ||
27946 | { | ||
27947 | "email": "fedor@indutny.com", | ||
27948 | "name": "indutny" | ||
27949 | } | ||
27950 | ], | ||
27951 | "name": "elliptic", | ||
27952 | "optionalDependencies": {}, | ||
27953 | "readme": "ERROR: No README data found!", | ||
27954 | "repository": { | ||
27955 | "type": "git", | ||
27956 | "url": "git+ssh://git@github.com/indutny/elliptic.git" | ||
27957 | }, | ||
27958 | "scripts": { | ||
27959 | "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js", | ||
27960 | "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js", | ||
27961 | "lint": "npm run jscs && npm run jshint", | ||
27962 | "test": "npm run lint && npm run unit", | ||
27963 | "unit": "istanbul test _mocha --reporter=spec test/index.js", | ||
27964 | "version": "grunt dist && git add dist/" | ||
27965 | }, | ||
27966 | "version": "6.4.0" | ||
27967 | } | ||
27968 | |||
27969 | },{}],113:[function(require,module,exports){ | ||
20211 | (function (Buffer){ | 27970 | (function (Buffer){ |
20212 | 'use strict' | 27971 | 'use strict' |
20213 | var Transform = require('stream').Transform | 27972 | var Transform = require('stream').Transform |
@@ -20294,9 +28053,1255 @@ HashBase.prototype._digest = function () { | |||
20294 | module.exports = HashBase | 28053 | module.exports = HashBase |
20295 | 28054 | ||
20296 | }).call(this,require("buffer").Buffer) | 28055 | }).call(this,require("buffer").Buffer) |
20297 | },{"buffer":4,"inherits":93,"stream":27}],93:[function(require,module,exports){ | 28056 | },{"buffer":5,"inherits":121,"stream":28}],114:[function(require,module,exports){ |
20298 | arguments[4][8][0].apply(exports,arguments) | 28057 | var hash = exports; |
20299 | },{"dup":8}],94:[function(require,module,exports){ | 28058 | |
28059 | hash.utils = require('./hash/utils'); | ||
28060 | hash.common = require('./hash/common'); | ||
28061 | hash.sha = require('./hash/sha'); | ||
28062 | hash.ripemd = require('./hash/ripemd'); | ||
28063 | hash.hmac = require('./hash/hmac'); | ||
28064 | |||
28065 | // Proxy hash functions to the main object | ||
28066 | hash.sha1 = hash.sha.sha1; | ||
28067 | hash.sha256 = hash.sha.sha256; | ||
28068 | hash.sha224 = hash.sha.sha224; | ||
28069 | hash.sha384 = hash.sha.sha384; | ||
28070 | hash.sha512 = hash.sha.sha512; | ||
28071 | hash.ripemd160 = hash.ripemd.ripemd160; | ||
28072 | |||
28073 | },{"./hash/common":115,"./hash/hmac":116,"./hash/ripemd":117,"./hash/sha":118,"./hash/utils":119}],115:[function(require,module,exports){ | ||
28074 | var hash = require('../hash'); | ||
28075 | var utils = hash.utils; | ||
28076 | var assert = utils.assert; | ||
28077 | |||
28078 | function BlockHash() { | ||
28079 | this.pending = null; | ||
28080 | this.pendingTotal = 0; | ||
28081 | this.blockSize = this.constructor.blockSize; | ||
28082 | this.outSize = this.constructor.outSize; | ||
28083 | this.hmacStrength = this.constructor.hmacStrength; | ||
28084 | this.padLength = this.constructor.padLength / 8; | ||
28085 | this.endian = 'big'; | ||
28086 | |||
28087 | this._delta8 = this.blockSize / 8; | ||
28088 | this._delta32 = this.blockSize / 32; | ||
28089 | } | ||
28090 | exports.BlockHash = BlockHash; | ||
28091 | |||
28092 | BlockHash.prototype.update = function update(msg, enc) { | ||
28093 | // Convert message to array, pad it, and join into 32bit blocks | ||
28094 | msg = utils.toArray(msg, enc); | ||
28095 | if (!this.pending) | ||
28096 | this.pending = msg; | ||
28097 | else | ||
28098 | this.pending = this.pending.concat(msg); | ||
28099 | this.pendingTotal += msg.length; | ||
28100 | |||
28101 | // Enough data, try updating | ||
28102 | if (this.pending.length >= this._delta8) { | ||
28103 | msg = this.pending; | ||
28104 | |||
28105 | // Process pending data in blocks | ||
28106 | var r = msg.length % this._delta8; | ||
28107 | this.pending = msg.slice(msg.length - r, msg.length); | ||
28108 | if (this.pending.length === 0) | ||
28109 | this.pending = null; | ||
28110 | |||
28111 | msg = utils.join32(msg, 0, msg.length - r, this.endian); | ||
28112 | for (var i = 0; i < msg.length; i += this._delta32) | ||
28113 | this._update(msg, i, i + this._delta32); | ||
28114 | } | ||
28115 | |||
28116 | return this; | ||
28117 | }; | ||
28118 | |||
28119 | BlockHash.prototype.digest = function digest(enc) { | ||
28120 | this.update(this._pad()); | ||
28121 | assert(this.pending === null); | ||
28122 | |||
28123 | return this._digest(enc); | ||
28124 | }; | ||
28125 | |||
28126 | BlockHash.prototype._pad = function pad() { | ||
28127 | var len = this.pendingTotal; | ||
28128 | var bytes = this._delta8; | ||
28129 | var k = bytes - ((len + this.padLength) % bytes); | ||
28130 | var res = new Array(k + this.padLength); | ||
28131 | res[0] = 0x80; | ||
28132 | for (var i = 1; i < k; i++) | ||
28133 | res[i] = 0; | ||
28134 | |||
28135 | // Append length | ||
28136 | len <<= 3; | ||
28137 | if (this.endian === 'big') { | ||
28138 | for (var t = 8; t < this.padLength; t++) | ||
28139 | res[i++] = 0; | ||
28140 | |||
28141 | res[i++] = 0; | ||
28142 | res[i++] = 0; | ||
28143 | res[i++] = 0; | ||
28144 | res[i++] = 0; | ||
28145 | res[i++] = (len >>> 24) & 0xff; | ||
28146 | res[i++] = (len >>> 16) & 0xff; | ||
28147 | res[i++] = (len >>> 8) & 0xff; | ||
28148 | res[i++] = len & 0xff; | ||
28149 | } else { | ||
28150 | res[i++] = len & 0xff; | ||
28151 | res[i++] = (len >>> 8) & 0xff; | ||
28152 | res[i++] = (len >>> 16) & 0xff; | ||
28153 | res[i++] = (len >>> 24) & 0xff; | ||
28154 | res[i++] = 0; | ||
28155 | res[i++] = 0; | ||
28156 | res[i++] = 0; | ||
28157 | res[i++] = 0; | ||
28158 | |||
28159 | for (var t = 8; t < this.padLength; t++) | ||
28160 | res[i++] = 0; | ||
28161 | } | ||
28162 | |||
28163 | return res; | ||
28164 | }; | ||
28165 | |||
28166 | },{"../hash":114}],116:[function(require,module,exports){ | ||
28167 | var hmac = exports; | ||
28168 | |||
28169 | var hash = require('../hash'); | ||
28170 | var utils = hash.utils; | ||
28171 | var assert = utils.assert; | ||
28172 | |||
28173 | function Hmac(hash, key, enc) { | ||
28174 | if (!(this instanceof Hmac)) | ||
28175 | return new Hmac(hash, key, enc); | ||
28176 | this.Hash = hash; | ||
28177 | this.blockSize = hash.blockSize / 8; | ||
28178 | this.outSize = hash.outSize / 8; | ||
28179 | this.inner = null; | ||
28180 | this.outer = null; | ||
28181 | |||
28182 | this._init(utils.toArray(key, enc)); | ||
28183 | } | ||
28184 | module.exports = Hmac; | ||
28185 | |||
28186 | Hmac.prototype._init = function init(key) { | ||
28187 | // Shorten key, if needed | ||
28188 | if (key.length > this.blockSize) | ||
28189 | key = new this.Hash().update(key).digest(); | ||
28190 | assert(key.length <= this.blockSize); | ||
28191 | |||
28192 | // Add padding to key | ||
28193 | for (var i = key.length; i < this.blockSize; i++) | ||
28194 | key.push(0); | ||
28195 | |||
28196 | for (var i = 0; i < key.length; i++) | ||
28197 | key[i] ^= 0x36; | ||
28198 | this.inner = new this.Hash().update(key); | ||
28199 | |||
28200 | // 0x36 ^ 0x5c = 0x6a | ||
28201 | for (var i = 0; i < key.length; i++) | ||
28202 | key[i] ^= 0x6a; | ||
28203 | this.outer = new this.Hash().update(key); | ||
28204 | }; | ||
28205 | |||
28206 | Hmac.prototype.update = function update(msg, enc) { | ||
28207 | this.inner.update(msg, enc); | ||
28208 | return this; | ||
28209 | }; | ||
28210 | |||
28211 | Hmac.prototype.digest = function digest(enc) { | ||
28212 | this.outer.update(this.inner.digest()); | ||
28213 | return this.outer.digest(enc); | ||
28214 | }; | ||
28215 | |||
28216 | },{"../hash":114}],117:[function(require,module,exports){ | ||
28217 | var hash = require('../hash'); | ||
28218 | var utils = hash.utils; | ||
28219 | |||
28220 | var rotl32 = utils.rotl32; | ||
28221 | var sum32 = utils.sum32; | ||
28222 | var sum32_3 = utils.sum32_3; | ||
28223 | var sum32_4 = utils.sum32_4; | ||
28224 | var BlockHash = hash.common.BlockHash; | ||
28225 | |||
28226 | function RIPEMD160() { | ||
28227 | if (!(this instanceof RIPEMD160)) | ||
28228 | return new RIPEMD160(); | ||
28229 | |||
28230 | BlockHash.call(this); | ||
28231 | |||
28232 | this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ]; | ||
28233 | this.endian = 'little'; | ||
28234 | } | ||
28235 | utils.inherits(RIPEMD160, BlockHash); | ||
28236 | exports.ripemd160 = RIPEMD160; | ||
28237 | |||
28238 | RIPEMD160.blockSize = 512; | ||
28239 | RIPEMD160.outSize = 160; | ||
28240 | RIPEMD160.hmacStrength = 192; | ||
28241 | RIPEMD160.padLength = 64; | ||
28242 | |||
28243 | RIPEMD160.prototype._update = function update(msg, start) { | ||
28244 | var A = this.h[0]; | ||
28245 | var B = this.h[1]; | ||
28246 | var C = this.h[2]; | ||
28247 | var D = this.h[3]; | ||
28248 | var E = this.h[4]; | ||
28249 | var Ah = A; | ||
28250 | var Bh = B; | ||
28251 | var Ch = C; | ||
28252 | var Dh = D; | ||
28253 | var Eh = E; | ||
28254 | for (var j = 0; j < 80; j++) { | ||
28255 | var T = sum32( | ||
28256 | rotl32( | ||
28257 | sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), | ||
28258 | s[j]), | ||
28259 | E); | ||
28260 | A = E; | ||
28261 | E = D; | ||
28262 | D = rotl32(C, 10); | ||
28263 | C = B; | ||
28264 | B = T; | ||
28265 | T = sum32( | ||
28266 | rotl32( | ||
28267 | sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), | ||
28268 | sh[j]), | ||
28269 | Eh); | ||
28270 | Ah = Eh; | ||
28271 | Eh = Dh; | ||
28272 | Dh = rotl32(Ch, 10); | ||
28273 | Ch = Bh; | ||
28274 | Bh = T; | ||
28275 | } | ||
28276 | T = sum32_3(this.h[1], C, Dh); | ||
28277 | this.h[1] = sum32_3(this.h[2], D, Eh); | ||
28278 | this.h[2] = sum32_3(this.h[3], E, Ah); | ||
28279 | this.h[3] = sum32_3(this.h[4], A, Bh); | ||
28280 | this.h[4] = sum32_3(this.h[0], B, Ch); | ||
28281 | this.h[0] = T; | ||
28282 | }; | ||
28283 | |||
28284 | RIPEMD160.prototype._digest = function digest(enc) { | ||
28285 | if (enc === 'hex') | ||
28286 | return utils.toHex32(this.h, 'little'); | ||
28287 | else | ||
28288 | return utils.split32(this.h, 'little'); | ||
28289 | }; | ||
28290 | |||
28291 | function f(j, x, y, z) { | ||
28292 | if (j <= 15) | ||
28293 | return x ^ y ^ z; | ||
28294 | else if (j <= 31) | ||
28295 | return (x & y) | ((~x) & z); | ||
28296 | else if (j <= 47) | ||
28297 | return (x | (~y)) ^ z; | ||
28298 | else if (j <= 63) | ||
28299 | return (x & z) | (y & (~z)); | ||
28300 | else | ||
28301 | return x ^ (y | (~z)); | ||
28302 | } | ||
28303 | |||
28304 | function K(j) { | ||
28305 | if (j <= 15) | ||
28306 | return 0x00000000; | ||
28307 | else if (j <= 31) | ||
28308 | return 0x5a827999; | ||
28309 | else if (j <= 47) | ||
28310 | return 0x6ed9eba1; | ||
28311 | else if (j <= 63) | ||
28312 | return 0x8f1bbcdc; | ||
28313 | else | ||
28314 | return 0xa953fd4e; | ||
28315 | } | ||
28316 | |||
28317 | function Kh(j) { | ||
28318 | if (j <= 15) | ||
28319 | return 0x50a28be6; | ||
28320 | else if (j <= 31) | ||
28321 | return 0x5c4dd124; | ||
28322 | else if (j <= 47) | ||
28323 | return 0x6d703ef3; | ||
28324 | else if (j <= 63) | ||
28325 | return 0x7a6d76e9; | ||
28326 | else | ||
28327 | return 0x00000000; | ||
28328 | } | ||
28329 | |||
28330 | var r = [ | ||
28331 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, | ||
28332 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, | ||
28333 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, | ||
28334 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, | ||
28335 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 | ||
28336 | ]; | ||
28337 | |||
28338 | var rh = [ | ||
28339 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, | ||
28340 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, | ||
28341 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, | ||
28342 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, | ||
28343 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 | ||
28344 | ]; | ||
28345 | |||
28346 | var s = [ | ||
28347 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, | ||
28348 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, | ||
28349 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, | ||
28350 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, | ||
28351 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 | ||
28352 | ]; | ||
28353 | |||
28354 | var sh = [ | ||
28355 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, | ||
28356 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, | ||
28357 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, | ||
28358 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, | ||
28359 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 | ||
28360 | ]; | ||
28361 | |||
28362 | },{"../hash":114}],118:[function(require,module,exports){ | ||
28363 | var hash = require('../hash'); | ||
28364 | var utils = hash.utils; | ||
28365 | var assert = utils.assert; | ||
28366 | |||
28367 | var rotr32 = utils.rotr32; | ||
28368 | var rotl32 = utils.rotl32; | ||
28369 | var sum32 = utils.sum32; | ||
28370 | var sum32_4 = utils.sum32_4; | ||
28371 | var sum32_5 = utils.sum32_5; | ||
28372 | var rotr64_hi = utils.rotr64_hi; | ||
28373 | var rotr64_lo = utils.rotr64_lo; | ||
28374 | var shr64_hi = utils.shr64_hi; | ||
28375 | var shr64_lo = utils.shr64_lo; | ||
28376 | var sum64 = utils.sum64; | ||
28377 | var sum64_hi = utils.sum64_hi; | ||
28378 | var sum64_lo = utils.sum64_lo; | ||
28379 | var sum64_4_hi = utils.sum64_4_hi; | ||
28380 | var sum64_4_lo = utils.sum64_4_lo; | ||
28381 | var sum64_5_hi = utils.sum64_5_hi; | ||
28382 | var sum64_5_lo = utils.sum64_5_lo; | ||
28383 | var BlockHash = hash.common.BlockHash; | ||
28384 | |||
28385 | var sha256_K = [ | ||
28386 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, | ||
28387 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | ||
28388 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, | ||
28389 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, | ||
28390 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, | ||
28391 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, | ||
28392 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, | ||
28393 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, | ||
28394 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, | ||
28395 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, | ||
28396 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, | ||
28397 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, | ||
28398 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, | ||
28399 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, | ||
28400 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, | ||
28401 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 | ||
28402 | ]; | ||
28403 | |||
28404 | var sha512_K = [ | ||
28405 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, | ||
28406 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, | ||
28407 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, | ||
28408 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, | ||
28409 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, | ||
28410 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, | ||
28411 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, | ||
28412 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, | ||
28413 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, | ||
28414 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, | ||
28415 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, | ||
28416 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, | ||
28417 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, | ||
28418 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, | ||
28419 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, | ||
28420 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, | ||
28421 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, | ||
28422 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, | ||
28423 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, | ||
28424 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, | ||
28425 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, | ||
28426 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, | ||
28427 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, | ||
28428 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, | ||
28429 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, | ||
28430 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, | ||
28431 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, | ||
28432 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, | ||
28433 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, | ||
28434 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, | ||
28435 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, | ||
28436 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, | ||
28437 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, | ||
28438 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, | ||
28439 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, | ||
28440 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, | ||
28441 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, | ||
28442 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, | ||
28443 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, | ||
28444 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 | ||
28445 | ]; | ||
28446 | |||
28447 | var sha1_K = [ | ||
28448 | 0x5A827999, 0x6ED9EBA1, | ||
28449 | 0x8F1BBCDC, 0xCA62C1D6 | ||
28450 | ]; | ||
28451 | |||
28452 | function SHA256() { | ||
28453 | if (!(this instanceof SHA256)) | ||
28454 | return new SHA256(); | ||
28455 | |||
28456 | BlockHash.call(this); | ||
28457 | this.h = [ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, | ||
28458 | 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 ]; | ||
28459 | this.k = sha256_K; | ||
28460 | this.W = new Array(64); | ||
28461 | } | ||
28462 | utils.inherits(SHA256, BlockHash); | ||
28463 | exports.sha256 = SHA256; | ||
28464 | |||
28465 | SHA256.blockSize = 512; | ||
28466 | SHA256.outSize = 256; | ||
28467 | SHA256.hmacStrength = 192; | ||
28468 | SHA256.padLength = 64; | ||
28469 | |||
28470 | SHA256.prototype._update = function _update(msg, start) { | ||
28471 | var W = this.W; | ||
28472 | |||
28473 | for (var i = 0; i < 16; i++) | ||
28474 | W[i] = msg[start + i]; | ||
28475 | for (; i < W.length; i++) | ||
28476 | W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]); | ||
28477 | |||
28478 | var a = this.h[0]; | ||
28479 | var b = this.h[1]; | ||
28480 | var c = this.h[2]; | ||
28481 | var d = this.h[3]; | ||
28482 | var e = this.h[4]; | ||
28483 | var f = this.h[5]; | ||
28484 | var g = this.h[6]; | ||
28485 | var h = this.h[7]; | ||
28486 | |||
28487 | assert(this.k.length === W.length); | ||
28488 | for (var i = 0; i < W.length; i++) { | ||
28489 | var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]); | ||
28490 | var T2 = sum32(s0_256(a), maj32(a, b, c)); | ||
28491 | h = g; | ||
28492 | g = f; | ||
28493 | f = e; | ||
28494 | e = sum32(d, T1); | ||
28495 | d = c; | ||
28496 | c = b; | ||
28497 | b = a; | ||
28498 | a = sum32(T1, T2); | ||
28499 | } | ||
28500 | |||
28501 | this.h[0] = sum32(this.h[0], a); | ||
28502 | this.h[1] = sum32(this.h[1], b); | ||
28503 | this.h[2] = sum32(this.h[2], c); | ||
28504 | this.h[3] = sum32(this.h[3], d); | ||
28505 | this.h[4] = sum32(this.h[4], e); | ||
28506 | this.h[5] = sum32(this.h[5], f); | ||
28507 | this.h[6] = sum32(this.h[6], g); | ||
28508 | this.h[7] = sum32(this.h[7], h); | ||
28509 | }; | ||
28510 | |||
28511 | SHA256.prototype._digest = function digest(enc) { | ||
28512 | if (enc === 'hex') | ||
28513 | return utils.toHex32(this.h, 'big'); | ||
28514 | else | ||
28515 | return utils.split32(this.h, 'big'); | ||
28516 | }; | ||
28517 | |||
28518 | function SHA224() { | ||
28519 | if (!(this instanceof SHA224)) | ||
28520 | return new SHA224(); | ||
28521 | |||
28522 | SHA256.call(this); | ||
28523 | this.h = [ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, | ||
28524 | 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ]; | ||
28525 | } | ||
28526 | utils.inherits(SHA224, SHA256); | ||
28527 | exports.sha224 = SHA224; | ||
28528 | |||
28529 | SHA224.blockSize = 512; | ||
28530 | SHA224.outSize = 224; | ||
28531 | SHA224.hmacStrength = 192; | ||
28532 | SHA224.padLength = 64; | ||
28533 | |||
28534 | SHA224.prototype._digest = function digest(enc) { | ||
28535 | // Just truncate output | ||
28536 | if (enc === 'hex') | ||
28537 | return utils.toHex32(this.h.slice(0, 7), 'big'); | ||
28538 | else | ||
28539 | return utils.split32(this.h.slice(0, 7), 'big'); | ||
28540 | }; | ||
28541 | |||
28542 | function SHA512() { | ||
28543 | if (!(this instanceof SHA512)) | ||
28544 | return new SHA512(); | ||
28545 | |||
28546 | BlockHash.call(this); | ||
28547 | this.h = [ 0x6a09e667, 0xf3bcc908, | ||
28548 | 0xbb67ae85, 0x84caa73b, | ||
28549 | 0x3c6ef372, 0xfe94f82b, | ||
28550 | 0xa54ff53a, 0x5f1d36f1, | ||
28551 | 0x510e527f, 0xade682d1, | ||
28552 | 0x9b05688c, 0x2b3e6c1f, | ||
28553 | 0x1f83d9ab, 0xfb41bd6b, | ||
28554 | 0x5be0cd19, 0x137e2179 ]; | ||
28555 | this.k = sha512_K; | ||
28556 | this.W = new Array(160); | ||
28557 | } | ||
28558 | utils.inherits(SHA512, BlockHash); | ||
28559 | exports.sha512 = SHA512; | ||
28560 | |||
28561 | SHA512.blockSize = 1024; | ||
28562 | SHA512.outSize = 512; | ||
28563 | SHA512.hmacStrength = 192; | ||
28564 | SHA512.padLength = 128; | ||
28565 | |||
28566 | SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) { | ||
28567 | var W = this.W; | ||
28568 | |||
28569 | // 32 x 32bit words | ||
28570 | for (var i = 0; i < 32; i++) | ||
28571 | W[i] = msg[start + i]; | ||
28572 | for (; i < W.length; i += 2) { | ||
28573 | var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2 | ||
28574 | var c0_lo = g1_512_lo(W[i - 4], W[i - 3]); | ||
28575 | var c1_hi = W[i - 14]; // i - 7 | ||
28576 | var c1_lo = W[i - 13]; | ||
28577 | var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15 | ||
28578 | var c2_lo = g0_512_lo(W[i - 30], W[i - 29]); | ||
28579 | var c3_hi = W[i - 32]; // i - 16 | ||
28580 | var c3_lo = W[i - 31]; | ||
28581 | |||
28582 | W[i] = sum64_4_hi(c0_hi, c0_lo, | ||
28583 | c1_hi, c1_lo, | ||
28584 | c2_hi, c2_lo, | ||
28585 | c3_hi, c3_lo); | ||
28586 | W[i + 1] = sum64_4_lo(c0_hi, c0_lo, | ||
28587 | c1_hi, c1_lo, | ||
28588 | c2_hi, c2_lo, | ||
28589 | c3_hi, c3_lo); | ||
28590 | } | ||
28591 | }; | ||
28592 | |||
28593 | SHA512.prototype._update = function _update(msg, start) { | ||
28594 | this._prepareBlock(msg, start); | ||
28595 | |||
28596 | var W = this.W; | ||
28597 | |||
28598 | var ah = this.h[0]; | ||
28599 | var al = this.h[1]; | ||
28600 | var bh = this.h[2]; | ||
28601 | var bl = this.h[3]; | ||
28602 | var ch = this.h[4]; | ||
28603 | var cl = this.h[5]; | ||
28604 | var dh = this.h[6]; | ||
28605 | var dl = this.h[7]; | ||
28606 | var eh = this.h[8]; | ||
28607 | var el = this.h[9]; | ||
28608 | var fh = this.h[10]; | ||
28609 | var fl = this.h[11]; | ||
28610 | var gh = this.h[12]; | ||
28611 | var gl = this.h[13]; | ||
28612 | var hh = this.h[14]; | ||
28613 | var hl = this.h[15]; | ||
28614 | |||
28615 | assert(this.k.length === W.length); | ||
28616 | for (var i = 0; i < W.length; i += 2) { | ||
28617 | var c0_hi = hh; | ||
28618 | var c0_lo = hl; | ||
28619 | var c1_hi = s1_512_hi(eh, el); | ||
28620 | var c1_lo = s1_512_lo(eh, el); | ||
28621 | var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl); | ||
28622 | var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl); | ||
28623 | var c3_hi = this.k[i]; | ||
28624 | var c3_lo = this.k[i + 1]; | ||
28625 | var c4_hi = W[i]; | ||
28626 | var c4_lo = W[i + 1]; | ||
28627 | |||
28628 | var T1_hi = sum64_5_hi(c0_hi, c0_lo, | ||
28629 | c1_hi, c1_lo, | ||
28630 | c2_hi, c2_lo, | ||
28631 | c3_hi, c3_lo, | ||
28632 | c4_hi, c4_lo); | ||
28633 | var T1_lo = sum64_5_lo(c0_hi, c0_lo, | ||
28634 | c1_hi, c1_lo, | ||
28635 | c2_hi, c2_lo, | ||
28636 | c3_hi, c3_lo, | ||
28637 | c4_hi, c4_lo); | ||
28638 | |||
28639 | var c0_hi = s0_512_hi(ah, al); | ||
28640 | var c0_lo = s0_512_lo(ah, al); | ||
28641 | var c1_hi = maj64_hi(ah, al, bh, bl, ch, cl); | ||
28642 | var c1_lo = maj64_lo(ah, al, bh, bl, ch, cl); | ||
28643 | |||
28644 | var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo); | ||
28645 | var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo); | ||
28646 | |||
28647 | hh = gh; | ||
28648 | hl = gl; | ||
28649 | |||
28650 | gh = fh; | ||
28651 | gl = fl; | ||
28652 | |||
28653 | fh = eh; | ||
28654 | fl = el; | ||
28655 | |||
28656 | eh = sum64_hi(dh, dl, T1_hi, T1_lo); | ||
28657 | el = sum64_lo(dl, dl, T1_hi, T1_lo); | ||
28658 | |||
28659 | dh = ch; | ||
28660 | dl = cl; | ||
28661 | |||
28662 | ch = bh; | ||
28663 | cl = bl; | ||
28664 | |||
28665 | bh = ah; | ||
28666 | bl = al; | ||
28667 | |||
28668 | ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo); | ||
28669 | al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo); | ||
28670 | } | ||
28671 | |||
28672 | sum64(this.h, 0, ah, al); | ||
28673 | sum64(this.h, 2, bh, bl); | ||
28674 | sum64(this.h, 4, ch, cl); | ||
28675 | sum64(this.h, 6, dh, dl); | ||
28676 | sum64(this.h, 8, eh, el); | ||
28677 | sum64(this.h, 10, fh, fl); | ||
28678 | sum64(this.h, 12, gh, gl); | ||
28679 | sum64(this.h, 14, hh, hl); | ||
28680 | }; | ||
28681 | |||
28682 | SHA512.prototype._digest = function digest(enc) { | ||
28683 | if (enc === 'hex') | ||
28684 | return utils.toHex32(this.h, 'big'); | ||
28685 | else | ||
28686 | return utils.split32(this.h, 'big'); | ||
28687 | }; | ||
28688 | |||
28689 | function SHA384() { | ||
28690 | if (!(this instanceof SHA384)) | ||
28691 | return new SHA384(); | ||
28692 | |||
28693 | SHA512.call(this); | ||
28694 | this.h = [ 0xcbbb9d5d, 0xc1059ed8, | ||
28695 | 0x629a292a, 0x367cd507, | ||
28696 | 0x9159015a, 0x3070dd17, | ||
28697 | 0x152fecd8, 0xf70e5939, | ||
28698 | 0x67332667, 0xffc00b31, | ||
28699 | 0x8eb44a87, 0x68581511, | ||
28700 | 0xdb0c2e0d, 0x64f98fa7, | ||
28701 | 0x47b5481d, 0xbefa4fa4 ]; | ||
28702 | } | ||
28703 | utils.inherits(SHA384, SHA512); | ||
28704 | exports.sha384 = SHA384; | ||
28705 | |||
28706 | SHA384.blockSize = 1024; | ||
28707 | SHA384.outSize = 384; | ||
28708 | SHA384.hmacStrength = 192; | ||
28709 | SHA384.padLength = 128; | ||
28710 | |||
28711 | SHA384.prototype._digest = function digest(enc) { | ||
28712 | if (enc === 'hex') | ||
28713 | return utils.toHex32(this.h.slice(0, 12), 'big'); | ||
28714 | else | ||
28715 | return utils.split32(this.h.slice(0, 12), 'big'); | ||
28716 | }; | ||
28717 | |||
28718 | function SHA1() { | ||
28719 | if (!(this instanceof SHA1)) | ||
28720 | return new SHA1(); | ||
28721 | |||
28722 | BlockHash.call(this); | ||
28723 | this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, | ||
28724 | 0x10325476, 0xc3d2e1f0 ]; | ||
28725 | this.W = new Array(80); | ||
28726 | } | ||
28727 | |||
28728 | utils.inherits(SHA1, BlockHash); | ||
28729 | exports.sha1 = SHA1; | ||
28730 | |||
28731 | SHA1.blockSize = 512; | ||
28732 | SHA1.outSize = 160; | ||
28733 | SHA1.hmacStrength = 80; | ||
28734 | SHA1.padLength = 64; | ||
28735 | |||
28736 | SHA1.prototype._update = function _update(msg, start) { | ||
28737 | var W = this.W; | ||
28738 | |||
28739 | for (var i = 0; i < 16; i++) | ||
28740 | W[i] = msg[start + i]; | ||
28741 | |||
28742 | for(; i < W.length; i++) | ||
28743 | W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); | ||
28744 | |||
28745 | var a = this.h[0]; | ||
28746 | var b = this.h[1]; | ||
28747 | var c = this.h[2]; | ||
28748 | var d = this.h[3]; | ||
28749 | var e = this.h[4]; | ||
28750 | |||
28751 | for (var i = 0; i < W.length; i++) { | ||
28752 | var s = ~~(i / 20); | ||
28753 | var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]); | ||
28754 | e = d; | ||
28755 | d = c; | ||
28756 | c = rotl32(b, 30); | ||
28757 | b = a; | ||
28758 | a = t; | ||
28759 | } | ||
28760 | |||
28761 | this.h[0] = sum32(this.h[0], a); | ||
28762 | this.h[1] = sum32(this.h[1], b); | ||
28763 | this.h[2] = sum32(this.h[2], c); | ||
28764 | this.h[3] = sum32(this.h[3], d); | ||
28765 | this.h[4] = sum32(this.h[4], e); | ||
28766 | }; | ||
28767 | |||
28768 | SHA1.prototype._digest = function digest(enc) { | ||
28769 | if (enc === 'hex') | ||
28770 | return utils.toHex32(this.h, 'big'); | ||
28771 | else | ||
28772 | return utils.split32(this.h, 'big'); | ||
28773 | }; | ||
28774 | |||
28775 | function ch32(x, y, z) { | ||
28776 | return (x & y) ^ ((~x) & z); | ||
28777 | } | ||
28778 | |||
28779 | function maj32(x, y, z) { | ||
28780 | return (x & y) ^ (x & z) ^ (y & z); | ||
28781 | } | ||
28782 | |||
28783 | function p32(x, y, z) { | ||
28784 | return x ^ y ^ z; | ||
28785 | } | ||
28786 | |||
28787 | function s0_256(x) { | ||
28788 | return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); | ||
28789 | } | ||
28790 | |||
28791 | function s1_256(x) { | ||
28792 | return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); | ||
28793 | } | ||
28794 | |||
28795 | function g0_256(x) { | ||
28796 | return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3); | ||
28797 | } | ||
28798 | |||
28799 | function g1_256(x) { | ||
28800 | return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10); | ||
28801 | } | ||
28802 | |||
28803 | function ft_1(s, x, y, z) { | ||
28804 | if (s === 0) | ||
28805 | return ch32(x, y, z); | ||
28806 | if (s === 1 || s === 3) | ||
28807 | return p32(x, y, z); | ||
28808 | if (s === 2) | ||
28809 | return maj32(x, y, z); | ||
28810 | } | ||
28811 | |||
28812 | function ch64_hi(xh, xl, yh, yl, zh, zl) { | ||
28813 | var r = (xh & yh) ^ ((~xh) & zh); | ||
28814 | if (r < 0) | ||
28815 | r += 0x100000000; | ||
28816 | return r; | ||
28817 | } | ||
28818 | |||
28819 | function ch64_lo(xh, xl, yh, yl, zh, zl) { | ||
28820 | var r = (xl & yl) ^ ((~xl) & zl); | ||
28821 | if (r < 0) | ||
28822 | r += 0x100000000; | ||
28823 | return r; | ||
28824 | } | ||
28825 | |||
28826 | function maj64_hi(xh, xl, yh, yl, zh, zl) { | ||
28827 | var r = (xh & yh) ^ (xh & zh) ^ (yh & zh); | ||
28828 | if (r < 0) | ||
28829 | r += 0x100000000; | ||
28830 | return r; | ||
28831 | } | ||
28832 | |||
28833 | function maj64_lo(xh, xl, yh, yl, zh, zl) { | ||
28834 | var r = (xl & yl) ^ (xl & zl) ^ (yl & zl); | ||
28835 | if (r < 0) | ||
28836 | r += 0x100000000; | ||
28837 | return r; | ||
28838 | } | ||
28839 | |||
28840 | function s0_512_hi(xh, xl) { | ||
28841 | var c0_hi = rotr64_hi(xh, xl, 28); | ||
28842 | var c1_hi = rotr64_hi(xl, xh, 2); // 34 | ||
28843 | var c2_hi = rotr64_hi(xl, xh, 7); // 39 | ||
28844 | |||
28845 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
28846 | if (r < 0) | ||
28847 | r += 0x100000000; | ||
28848 | return r; | ||
28849 | } | ||
28850 | |||
28851 | function s0_512_lo(xh, xl) { | ||
28852 | var c0_lo = rotr64_lo(xh, xl, 28); | ||
28853 | var c1_lo = rotr64_lo(xl, xh, 2); // 34 | ||
28854 | var c2_lo = rotr64_lo(xl, xh, 7); // 39 | ||
28855 | |||
28856 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
28857 | if (r < 0) | ||
28858 | r += 0x100000000; | ||
28859 | return r; | ||
28860 | } | ||
28861 | |||
28862 | function s1_512_hi(xh, xl) { | ||
28863 | var c0_hi = rotr64_hi(xh, xl, 14); | ||
28864 | var c1_hi = rotr64_hi(xh, xl, 18); | ||
28865 | var c2_hi = rotr64_hi(xl, xh, 9); // 41 | ||
28866 | |||
28867 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
28868 | if (r < 0) | ||
28869 | r += 0x100000000; | ||
28870 | return r; | ||
28871 | } | ||
28872 | |||
28873 | function s1_512_lo(xh, xl) { | ||
28874 | var c0_lo = rotr64_lo(xh, xl, 14); | ||
28875 | var c1_lo = rotr64_lo(xh, xl, 18); | ||
28876 | var c2_lo = rotr64_lo(xl, xh, 9); // 41 | ||
28877 | |||
28878 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
28879 | if (r < 0) | ||
28880 | r += 0x100000000; | ||
28881 | return r; | ||
28882 | } | ||
28883 | |||
28884 | function g0_512_hi(xh, xl) { | ||
28885 | var c0_hi = rotr64_hi(xh, xl, 1); | ||
28886 | var c1_hi = rotr64_hi(xh, xl, 8); | ||
28887 | var c2_hi = shr64_hi(xh, xl, 7); | ||
28888 | |||
28889 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
28890 | if (r < 0) | ||
28891 | r += 0x100000000; | ||
28892 | return r; | ||
28893 | } | ||
28894 | |||
28895 | function g0_512_lo(xh, xl) { | ||
28896 | var c0_lo = rotr64_lo(xh, xl, 1); | ||
28897 | var c1_lo = rotr64_lo(xh, xl, 8); | ||
28898 | var c2_lo = shr64_lo(xh, xl, 7); | ||
28899 | |||
28900 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
28901 | if (r < 0) | ||
28902 | r += 0x100000000; | ||
28903 | return r; | ||
28904 | } | ||
28905 | |||
28906 | function g1_512_hi(xh, xl) { | ||
28907 | var c0_hi = rotr64_hi(xh, xl, 19); | ||
28908 | var c1_hi = rotr64_hi(xl, xh, 29); // 61 | ||
28909 | var c2_hi = shr64_hi(xh, xl, 6); | ||
28910 | |||
28911 | var r = c0_hi ^ c1_hi ^ c2_hi; | ||
28912 | if (r < 0) | ||
28913 | r += 0x100000000; | ||
28914 | return r; | ||
28915 | } | ||
28916 | |||
28917 | function g1_512_lo(xh, xl) { | ||
28918 | var c0_lo = rotr64_lo(xh, xl, 19); | ||
28919 | var c1_lo = rotr64_lo(xl, xh, 29); // 61 | ||
28920 | var c2_lo = shr64_lo(xh, xl, 6); | ||
28921 | |||
28922 | var r = c0_lo ^ c1_lo ^ c2_lo; | ||
28923 | if (r < 0) | ||
28924 | r += 0x100000000; | ||
28925 | return r; | ||
28926 | } | ||
28927 | |||
28928 | },{"../hash":114}],119:[function(require,module,exports){ | ||
28929 | var utils = exports; | ||
28930 | var inherits = require('inherits'); | ||
28931 | |||
28932 | function toArray(msg, enc) { | ||
28933 | if (Array.isArray(msg)) | ||
28934 | return msg.slice(); | ||
28935 | if (!msg) | ||
28936 | return []; | ||
28937 | var res = []; | ||
28938 | if (typeof msg === 'string') { | ||
28939 | if (!enc) { | ||
28940 | for (var i = 0; i < msg.length; i++) { | ||
28941 | var c = msg.charCodeAt(i); | ||
28942 | var hi = c >> 8; | ||
28943 | var lo = c & 0xff; | ||
28944 | if (hi) | ||
28945 | res.push(hi, lo); | ||
28946 | else | ||
28947 | res.push(lo); | ||
28948 | } | ||
28949 | } else if (enc === 'hex') { | ||
28950 | msg = msg.replace(/[^a-z0-9]+/ig, ''); | ||
28951 | if (msg.length % 2 !== 0) | ||
28952 | msg = '0' + msg; | ||
28953 | for (var i = 0; i < msg.length; i += 2) | ||
28954 | res.push(parseInt(msg[i] + msg[i + 1], 16)); | ||
28955 | } | ||
28956 | } else { | ||
28957 | for (var i = 0; i < msg.length; i++) | ||
28958 | res[i] = msg[i] | 0; | ||
28959 | } | ||
28960 | return res; | ||
28961 | } | ||
28962 | utils.toArray = toArray; | ||
28963 | |||
28964 | function toHex(msg) { | ||
28965 | var res = ''; | ||
28966 | for (var i = 0; i < msg.length; i++) | ||
28967 | res += zero2(msg[i].toString(16)); | ||
28968 | return res; | ||
28969 | } | ||
28970 | utils.toHex = toHex; | ||
28971 | |||
28972 | function htonl(w) { | ||
28973 | var res = (w >>> 24) | | ||
28974 | ((w >>> 8) & 0xff00) | | ||
28975 | ((w << 8) & 0xff0000) | | ||
28976 | ((w & 0xff) << 24); | ||
28977 | return res >>> 0; | ||
28978 | } | ||
28979 | utils.htonl = htonl; | ||
28980 | |||
28981 | function toHex32(msg, endian) { | ||
28982 | var res = ''; | ||
28983 | for (var i = 0; i < msg.length; i++) { | ||
28984 | var w = msg[i]; | ||
28985 | if (endian === 'little') | ||
28986 | w = htonl(w); | ||
28987 | res += zero8(w.toString(16)); | ||
28988 | } | ||
28989 | return res; | ||
28990 | } | ||
28991 | utils.toHex32 = toHex32; | ||
28992 | |||
28993 | function zero2(word) { | ||
28994 | if (word.length === 1) | ||
28995 | return '0' + word; | ||
28996 | else | ||
28997 | return word; | ||
28998 | } | ||
28999 | utils.zero2 = zero2; | ||
29000 | |||
29001 | function zero8(word) { | ||
29002 | if (word.length === 7) | ||
29003 | return '0' + word; | ||
29004 | else if (word.length === 6) | ||
29005 | return '00' + word; | ||
29006 | else if (word.length === 5) | ||
29007 | return '000' + word; | ||
29008 | else if (word.length === 4) | ||
29009 | return '0000' + word; | ||
29010 | else if (word.length === 3) | ||
29011 | return '00000' + word; | ||
29012 | else if (word.length === 2) | ||
29013 | return '000000' + word; | ||
29014 | else if (word.length === 1) | ||
29015 | return '0000000' + word; | ||
29016 | else | ||
29017 | return word; | ||
29018 | } | ||
29019 | utils.zero8 = zero8; | ||
29020 | |||
29021 | function join32(msg, start, end, endian) { | ||
29022 | var len = end - start; | ||
29023 | assert(len % 4 === 0); | ||
29024 | var res = new Array(len / 4); | ||
29025 | for (var i = 0, k = start; i < res.length; i++, k += 4) { | ||
29026 | var w; | ||
29027 | if (endian === 'big') | ||
29028 | w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3]; | ||
29029 | else | ||
29030 | w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k]; | ||
29031 | res[i] = w >>> 0; | ||
29032 | } | ||
29033 | return res; | ||
29034 | } | ||
29035 | utils.join32 = join32; | ||
29036 | |||
29037 | function split32(msg, endian) { | ||
29038 | var res = new Array(msg.length * 4); | ||
29039 | for (var i = 0, k = 0; i < msg.length; i++, k += 4) { | ||
29040 | var m = msg[i]; | ||
29041 | if (endian === 'big') { | ||
29042 | res[k] = m >>> 24; | ||
29043 | res[k + 1] = (m >>> 16) & 0xff; | ||
29044 | res[k + 2] = (m >>> 8) & 0xff; | ||
29045 | res[k + 3] = m & 0xff; | ||
29046 | } else { | ||
29047 | res[k + 3] = m >>> 24; | ||
29048 | res[k + 2] = (m >>> 16) & 0xff; | ||
29049 | res[k + 1] = (m >>> 8) & 0xff; | ||
29050 | res[k] = m & 0xff; | ||
29051 | } | ||
29052 | } | ||
29053 | return res; | ||
29054 | } | ||
29055 | utils.split32 = split32; | ||
29056 | |||
29057 | function rotr32(w, b) { | ||
29058 | return (w >>> b) | (w << (32 - b)); | ||
29059 | } | ||
29060 | utils.rotr32 = rotr32; | ||
29061 | |||
29062 | function rotl32(w, b) { | ||
29063 | return (w << b) | (w >>> (32 - b)); | ||
29064 | } | ||
29065 | utils.rotl32 = rotl32; | ||
29066 | |||
29067 | function sum32(a, b) { | ||
29068 | return (a + b) >>> 0; | ||
29069 | } | ||
29070 | utils.sum32 = sum32; | ||
29071 | |||
29072 | function sum32_3(a, b, c) { | ||
29073 | return (a + b + c) >>> 0; | ||
29074 | } | ||
29075 | utils.sum32_3 = sum32_3; | ||
29076 | |||
29077 | function sum32_4(a, b, c, d) { | ||
29078 | return (a + b + c + d) >>> 0; | ||
29079 | } | ||
29080 | utils.sum32_4 = sum32_4; | ||
29081 | |||
29082 | function sum32_5(a, b, c, d, e) { | ||
29083 | return (a + b + c + d + e) >>> 0; | ||
29084 | } | ||
29085 | utils.sum32_5 = sum32_5; | ||
29086 | |||
29087 | function assert(cond, msg) { | ||
29088 | if (!cond) | ||
29089 | throw new Error(msg || 'Assertion failed'); | ||
29090 | } | ||
29091 | utils.assert = assert; | ||
29092 | |||
29093 | utils.inherits = inherits; | ||
29094 | |||
29095 | function sum64(buf, pos, ah, al) { | ||
29096 | var bh = buf[pos]; | ||
29097 | var bl = buf[pos + 1]; | ||
29098 | |||
29099 | var lo = (al + bl) >>> 0; | ||
29100 | var hi = (lo < al ? 1 : 0) + ah + bh; | ||
29101 | buf[pos] = hi >>> 0; | ||
29102 | buf[pos + 1] = lo; | ||
29103 | } | ||
29104 | exports.sum64 = sum64; | ||
29105 | |||
29106 | function sum64_hi(ah, al, bh, bl) { | ||
29107 | var lo = (al + bl) >>> 0; | ||
29108 | var hi = (lo < al ? 1 : 0) + ah + bh; | ||
29109 | return hi >>> 0; | ||
29110 | }; | ||
29111 | exports.sum64_hi = sum64_hi; | ||
29112 | |||
29113 | function sum64_lo(ah, al, bh, bl) { | ||
29114 | var lo = al + bl; | ||
29115 | return lo >>> 0; | ||
29116 | }; | ||
29117 | exports.sum64_lo = sum64_lo; | ||
29118 | |||
29119 | function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { | ||
29120 | var carry = 0; | ||
29121 | var lo = al; | ||
29122 | lo = (lo + bl) >>> 0; | ||
29123 | carry += lo < al ? 1 : 0; | ||
29124 | lo = (lo + cl) >>> 0; | ||
29125 | carry += lo < cl ? 1 : 0; | ||
29126 | lo = (lo + dl) >>> 0; | ||
29127 | carry += lo < dl ? 1 : 0; | ||
29128 | |||
29129 | var hi = ah + bh + ch + dh + carry; | ||
29130 | return hi >>> 0; | ||
29131 | }; | ||
29132 | exports.sum64_4_hi = sum64_4_hi; | ||
29133 | |||
29134 | function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { | ||
29135 | var lo = al + bl + cl + dl; | ||
29136 | return lo >>> 0; | ||
29137 | }; | ||
29138 | exports.sum64_4_lo = sum64_4_lo; | ||
29139 | |||
29140 | function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { | ||
29141 | var carry = 0; | ||
29142 | var lo = al; | ||
29143 | lo = (lo + bl) >>> 0; | ||
29144 | carry += lo < al ? 1 : 0; | ||
29145 | lo = (lo + cl) >>> 0; | ||
29146 | carry += lo < cl ? 1 : 0; | ||
29147 | lo = (lo + dl) >>> 0; | ||
29148 | carry += lo < dl ? 1 : 0; | ||
29149 | lo = (lo + el) >>> 0; | ||
29150 | carry += lo < el ? 1 : 0; | ||
29151 | |||
29152 | var hi = ah + bh + ch + dh + eh + carry; | ||
29153 | return hi >>> 0; | ||
29154 | }; | ||
29155 | exports.sum64_5_hi = sum64_5_hi; | ||
29156 | |||
29157 | function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { | ||
29158 | var lo = al + bl + cl + dl + el; | ||
29159 | |||
29160 | return lo >>> 0; | ||
29161 | }; | ||
29162 | exports.sum64_5_lo = sum64_5_lo; | ||
29163 | |||
29164 | function rotr64_hi(ah, al, num) { | ||
29165 | var r = (al << (32 - num)) | (ah >>> num); | ||
29166 | return r >>> 0; | ||
29167 | }; | ||
29168 | exports.rotr64_hi = rotr64_hi; | ||
29169 | |||
29170 | function rotr64_lo(ah, al, num) { | ||
29171 | var r = (ah << (32 - num)) | (al >>> num); | ||
29172 | return r >>> 0; | ||
29173 | }; | ||
29174 | exports.rotr64_lo = rotr64_lo; | ||
29175 | |||
29176 | function shr64_hi(ah, al, num) { | ||
29177 | return ah >>> num; | ||
29178 | }; | ||
29179 | exports.shr64_hi = shr64_hi; | ||
29180 | |||
29181 | function shr64_lo(ah, al, num) { | ||
29182 | var r = (ah << (32 - num)) | (al >>> num); | ||
29183 | return r >>> 0; | ||
29184 | }; | ||
29185 | exports.shr64_lo = shr64_lo; | ||
29186 | |||
29187 | },{"inherits":121}],120:[function(require,module,exports){ | ||
29188 | 'use strict'; | ||
29189 | |||
29190 | var hash = require('hash.js'); | ||
29191 | var utils = require('minimalistic-crypto-utils'); | ||
29192 | var assert = require('minimalistic-assert'); | ||
29193 | |||
29194 | function HmacDRBG(options) { | ||
29195 | if (!(this instanceof HmacDRBG)) | ||
29196 | return new HmacDRBG(options); | ||
29197 | this.hash = options.hash; | ||
29198 | this.predResist = !!options.predResist; | ||
29199 | |||
29200 | this.outLen = this.hash.outSize; | ||
29201 | this.minEntropy = options.minEntropy || this.hash.hmacStrength; | ||
29202 | |||
29203 | this._reseed = null; | ||
29204 | this.reseedInterval = null; | ||
29205 | this.K = null; | ||
29206 | this.V = null; | ||
29207 | |||
29208 | var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex'); | ||
29209 | var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex'); | ||
29210 | var pers = utils.toArray(options.pers, options.persEnc || 'hex'); | ||
29211 | assert(entropy.length >= (this.minEntropy / 8), | ||
29212 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); | ||
29213 | this._init(entropy, nonce, pers); | ||
29214 | } | ||
29215 | module.exports = HmacDRBG; | ||
29216 | |||
29217 | HmacDRBG.prototype._init = function init(entropy, nonce, pers) { | ||
29218 | var seed = entropy.concat(nonce).concat(pers); | ||
29219 | |||
29220 | this.K = new Array(this.outLen / 8); | ||
29221 | this.V = new Array(this.outLen / 8); | ||
29222 | for (var i = 0; i < this.V.length; i++) { | ||
29223 | this.K[i] = 0x00; | ||
29224 | this.V[i] = 0x01; | ||
29225 | } | ||
29226 | |||
29227 | this._update(seed); | ||
29228 | this._reseed = 1; | ||
29229 | this.reseedInterval = 0x1000000000000; // 2^48 | ||
29230 | }; | ||
29231 | |||
29232 | HmacDRBG.prototype._hmac = function hmac() { | ||
29233 | return new hash.hmac(this.hash, this.K); | ||
29234 | }; | ||
29235 | |||
29236 | HmacDRBG.prototype._update = function update(seed) { | ||
29237 | var kmac = this._hmac() | ||
29238 | .update(this.V) | ||
29239 | .update([ 0x00 ]); | ||
29240 | if (seed) | ||
29241 | kmac = kmac.update(seed); | ||
29242 | this.K = kmac.digest(); | ||
29243 | this.V = this._hmac().update(this.V).digest(); | ||
29244 | if (!seed) | ||
29245 | return; | ||
29246 | |||
29247 | this.K = this._hmac() | ||
29248 | .update(this.V) | ||
29249 | .update([ 0x01 ]) | ||
29250 | .update(seed) | ||
29251 | .digest(); | ||
29252 | this.V = this._hmac().update(this.V).digest(); | ||
29253 | }; | ||
29254 | |||
29255 | HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { | ||
29256 | // Optional entropy enc | ||
29257 | if (typeof entropyEnc !== 'string') { | ||
29258 | addEnc = add; | ||
29259 | add = entropyEnc; | ||
29260 | entropyEnc = null; | ||
29261 | } | ||
29262 | |||
29263 | entropy = utils.toArray(entropy, entropyEnc); | ||
29264 | add = utils.toArray(add, addEnc); | ||
29265 | |||
29266 | assert(entropy.length >= (this.minEntropy / 8), | ||
29267 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); | ||
29268 | |||
29269 | this._update(entropy.concat(add || [])); | ||
29270 | this._reseed = 1; | ||
29271 | }; | ||
29272 | |||
29273 | HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { | ||
29274 | if (this._reseed > this.reseedInterval) | ||
29275 | throw new Error('Reseed is required'); | ||
29276 | |||
29277 | // Optional encoding | ||
29278 | if (typeof enc !== 'string') { | ||
29279 | addEnc = add; | ||
29280 | add = enc; | ||
29281 | enc = null; | ||
29282 | } | ||
29283 | |||
29284 | // Optional additional data | ||
29285 | if (add) { | ||
29286 | add = utils.toArray(add, addEnc || 'hex'); | ||
29287 | this._update(add); | ||
29288 | } | ||
29289 | |||
29290 | var temp = []; | ||
29291 | while (temp.length < len) { | ||
29292 | this.V = this._hmac().update(this.V).digest(); | ||
29293 | temp = temp.concat(this.V); | ||
29294 | } | ||
29295 | |||
29296 | var res = temp.slice(0, len); | ||
29297 | this._update(add); | ||
29298 | this._reseed++; | ||
29299 | return utils.encode(res, enc); | ||
29300 | }; | ||
29301 | |||
29302 | },{"hash.js":114,"minimalistic-assert":123,"minimalistic-crypto-utils":124}],121:[function(require,module,exports){ | ||
29303 | arguments[4][9][0].apply(exports,arguments) | ||
29304 | },{"dup":9}],122:[function(require,module,exports){ | ||
20300 | (function (Buffer){ | 29305 | (function (Buffer){ |
20301 | // constant-space merkle root calculation algorithm | 29306 | // constant-space merkle root calculation algorithm |
20302 | module.exports = function fastRoot (values, digestFn) { | 29307 | module.exports = function fastRoot (values, digestFn) { |
@@ -20324,7 +29329,80 @@ module.exports = function fastRoot (values, digestFn) { | |||
20324 | } | 29329 | } |
20325 | 29330 | ||
20326 | }).call(this,require("buffer").Buffer) | 29331 | }).call(this,require("buffer").Buffer) |
20327 | },{"buffer":4}],95:[function(require,module,exports){ | 29332 | },{"buffer":5}],123:[function(require,module,exports){ |
29333 | module.exports = assert; | ||
29334 | |||
29335 | function assert(val, msg) { | ||
29336 | if (!val) | ||
29337 | throw new Error(msg || 'Assertion failed'); | ||
29338 | } | ||
29339 | |||
29340 | assert.equal = function assertEqual(l, r, msg) { | ||
29341 | if (l != r) | ||
29342 | throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r)); | ||
29343 | }; | ||
29344 | |||
29345 | },{}],124:[function(require,module,exports){ | ||
29346 | 'use strict'; | ||
29347 | |||
29348 | var utils = exports; | ||
29349 | |||
29350 | function toArray(msg, enc) { | ||
29351 | if (Array.isArray(msg)) | ||
29352 | return msg.slice(); | ||
29353 | if (!msg) | ||
29354 | return []; | ||
29355 | var res = []; | ||
29356 | if (typeof msg !== 'string') { | ||
29357 | for (var i = 0; i < msg.length; i++) | ||
29358 | res[i] = msg[i] | 0; | ||
29359 | return res; | ||
29360 | } | ||
29361 | if (enc === 'hex') { | ||
29362 | msg = msg.replace(/[^a-z0-9]+/ig, ''); | ||
29363 | if (msg.length % 2 !== 0) | ||
29364 | msg = '0' + msg; | ||
29365 | for (var i = 0; i < msg.length; i += 2) | ||
29366 | res.push(parseInt(msg[i] + msg[i + 1], 16)); | ||
29367 | } else { | ||
29368 | for (var i = 0; i < msg.length; i++) { | ||
29369 | var c = msg.charCodeAt(i); | ||
29370 | var hi = c >> 8; | ||
29371 | var lo = c & 0xff; | ||
29372 | if (hi) | ||
29373 | res.push(hi, lo); | ||
29374 | else | ||
29375 | res.push(lo); | ||
29376 | } | ||
29377 | } | ||
29378 | return res; | ||
29379 | } | ||
29380 | utils.toArray = toArray; | ||
29381 | |||
29382 | function zero2(word) { | ||
29383 | if (word.length === 1) | ||
29384 | return '0' + word; | ||
29385 | else | ||
29386 | return word; | ||
29387 | } | ||
29388 | utils.zero2 = zero2; | ||
29389 | |||
29390 | function toHex(msg) { | ||
29391 | var res = ''; | ||
29392 | for (var i = 0; i < msg.length; i++) | ||
29393 | res += zero2(msg[i].toString(16)); | ||
29394 | return res; | ||
29395 | } | ||
29396 | utils.toHex = toHex; | ||
29397 | |||
29398 | utils.encode = function encode(arr, enc) { | ||
29399 | if (enc === 'hex') | ||
29400 | return toHex(arr); | ||
29401 | else | ||
29402 | return arr; | ||
29403 | }; | ||
29404 | |||
29405 | },{}],125:[function(require,module,exports){ | ||
20328 | var OPS = require('bitcoin-ops') | 29406 | var OPS = require('bitcoin-ops') |
20329 | 29407 | ||
20330 | function encodingLength (i) { | 29408 | function encodingLength (i) { |
@@ -20403,7 +29481,7 @@ module.exports = { | |||
20403 | decode: decode | 29481 | decode: decode |
20404 | } | 29482 | } |
20405 | 29483 | ||
20406 | },{"bitcoin-ops":40}],96:[function(require,module,exports){ | 29484 | },{"bitcoin-ops":42}],126:[function(require,module,exports){ |
20407 | (function (process,global){ | 29485 | (function (process,global){ |
20408 | 'use strict' | 29486 | 'use strict' |
20409 | 29487 | ||
@@ -20445,7 +29523,7 @@ function randomBytes (size, cb) { | |||
20445 | } | 29523 | } |
20446 | 29524 | ||
20447 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | 29525 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
20448 | },{"_process":12,"safe-buffer":98}],97:[function(require,module,exports){ | 29526 | },{"_process":13,"safe-buffer":128}],127:[function(require,module,exports){ |
20449 | (function (Buffer){ | 29527 | (function (Buffer){ |
20450 | 'use strict' | 29528 | 'use strict' |
20451 | var inherits = require('inherits') | 29529 | var inherits = require('inherits') |
@@ -20740,70 +29818,143 @@ function fn5 (a, b, c, d, e, m, k, s) { | |||
20740 | module.exports = RIPEMD160 | 29818 | module.exports = RIPEMD160 |
20741 | 29819 | ||
20742 | }).call(this,require("buffer").Buffer) | 29820 | }).call(this,require("buffer").Buffer) |
20743 | },{"buffer":4,"hash-base":92,"inherits":93}],98:[function(require,module,exports){ | 29821 | },{"buffer":5,"hash-base":113,"inherits":121}],128:[function(require,module,exports){ |
20744 | arguments[4][26][0].apply(exports,arguments) | 29822 | /* eslint-disable node/no-deprecated-api */ |
20745 | },{"buffer":4,"dup":26}],99:[function(require,module,exports){ | 29823 | var buffer = require('buffer') |
20746 | (function (Buffer){ | 29824 | var Buffer = buffer.Buffer |
29825 | |||
29826 | // alternative to using Object.keys for old browsers | ||
29827 | function copyProps (src, dst) { | ||
29828 | for (var key in src) { | ||
29829 | dst[key] = src[key] | ||
29830 | } | ||
29831 | } | ||
29832 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { | ||
29833 | module.exports = buffer | ||
29834 | } else { | ||
29835 | // Copy properties from require('buffer') | ||
29836 | copyProps(buffer, exports) | ||
29837 | exports.Buffer = SafeBuffer | ||
29838 | } | ||
29839 | |||
29840 | function SafeBuffer (arg, encodingOrOffset, length) { | ||
29841 | return Buffer(arg, encodingOrOffset, length) | ||
29842 | } | ||
29843 | |||
29844 | // Copy static methods from Buffer | ||
29845 | copyProps(Buffer, SafeBuffer) | ||
29846 | |||
29847 | SafeBuffer.from = function (arg, encodingOrOffset, length) { | ||
29848 | if (typeof arg === 'number') { | ||
29849 | throw new TypeError('Argument must not be a number') | ||
29850 | } | ||
29851 | return Buffer(arg, encodingOrOffset, length) | ||
29852 | } | ||
29853 | |||
29854 | SafeBuffer.alloc = function (size, fill, encoding) { | ||
29855 | if (typeof size !== 'number') { | ||
29856 | throw new TypeError('Argument must be a number') | ||
29857 | } | ||
29858 | var buf = Buffer(size) | ||
29859 | if (fill !== undefined) { | ||
29860 | if (typeof encoding === 'string') { | ||
29861 | buf.fill(fill, encoding) | ||
29862 | } else { | ||
29863 | buf.fill(fill) | ||
29864 | } | ||
29865 | } else { | ||
29866 | buf.fill(0) | ||
29867 | } | ||
29868 | return buf | ||
29869 | } | ||
29870 | |||
29871 | SafeBuffer.allocUnsafe = function (size) { | ||
29872 | if (typeof size !== 'number') { | ||
29873 | throw new TypeError('Argument must be a number') | ||
29874 | } | ||
29875 | return Buffer(size) | ||
29876 | } | ||
29877 | |||
29878 | SafeBuffer.allocUnsafeSlow = function (size) { | ||
29879 | if (typeof size !== 'number') { | ||
29880 | throw new TypeError('Argument must be a number') | ||
29881 | } | ||
29882 | return buffer.SlowBuffer(size) | ||
29883 | } | ||
29884 | |||
29885 | },{"buffer":5}],129:[function(require,module,exports){ | ||
29886 | var Buffer = require('safe-buffer').Buffer | ||
29887 | |||
20747 | // prototype class for hash functions | 29888 | // prototype class for hash functions |
20748 | function Hash (blockSize, finalSize) { | 29889 | function Hash (blockSize, finalSize) { |
20749 | this._block = new Buffer(blockSize) | 29890 | this._block = Buffer.alloc(blockSize) |
20750 | this._finalSize = finalSize | 29891 | this._finalSize = finalSize |
20751 | this._blockSize = blockSize | 29892 | this._blockSize = blockSize |
20752 | this._len = 0 | 29893 | this._len = 0 |
20753 | this._s = 0 | ||
20754 | } | 29894 | } |
20755 | 29895 | ||
20756 | Hash.prototype.update = function (data, enc) { | 29896 | Hash.prototype.update = function (data, enc) { |
20757 | if (typeof data === 'string') { | 29897 | if (typeof data === 'string') { |
20758 | enc = enc || 'utf8' | 29898 | enc = enc || 'utf8' |
20759 | data = new Buffer(data, enc) | 29899 | data = Buffer.from(data, enc) |
20760 | } | 29900 | } |
20761 | 29901 | ||
20762 | var l = this._len += data.length | 29902 | var block = this._block |
20763 | var s = this._s || 0 | 29903 | var blockSize = this._blockSize |
20764 | var f = 0 | 29904 | var length = data.length |
20765 | var buffer = this._block | 29905 | var accum = this._len |
20766 | 29906 | ||
20767 | while (s < l) { | 29907 | for (var offset = 0; offset < length;) { |
20768 | var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize)) | 29908 | var assigned = accum % blockSize |
20769 | var ch = (t - f) | 29909 | var remainder = Math.min(length - offset, blockSize - assigned) |
20770 | 29910 | ||
20771 | for (var i = 0; i < ch; i++) { | 29911 | for (var i = 0; i < remainder; i++) { |
20772 | buffer[(s % this._blockSize) + i] = data[i + f] | 29912 | block[assigned + i] = data[offset + i] |
20773 | } | 29913 | } |
20774 | 29914 | ||
20775 | s += ch | 29915 | accum += remainder |
20776 | f += ch | 29916 | offset += remainder |
20777 | 29917 | ||
20778 | if ((s % this._blockSize) === 0) { | 29918 | if ((accum % blockSize) === 0) { |
20779 | this._update(buffer) | 29919 | this._update(block) |
20780 | } | 29920 | } |
20781 | } | 29921 | } |
20782 | this._s = s | ||
20783 | 29922 | ||
29923 | this._len += length | ||
20784 | return this | 29924 | return this |
20785 | } | 29925 | } |
20786 | 29926 | ||
20787 | Hash.prototype.digest = function (enc) { | 29927 | Hash.prototype.digest = function (enc) { |
20788 | // Suppose the length of the message M, in bits, is l | 29928 | var rem = this._len % this._blockSize |
20789 | var l = this._len * 8 | ||
20790 | 29929 | ||
20791 | // Append the bit 1 to the end of the message | 29930 | this._block[rem] = 0x80 |
20792 | this._block[this._len % this._blockSize] = 0x80 | ||
20793 | 29931 | ||
20794 | // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize | 29932 | // zero (rem + 1) trailing bits, where (rem + 1) is the smallest |
20795 | this._block.fill(0, this._len % this._blockSize + 1) | 29933 | // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize |
29934 | this._block.fill(0, rem + 1) | ||
20796 | 29935 | ||
20797 | if (l % (this._blockSize * 8) >= this._finalSize * 8) { | 29936 | if (rem >= this._finalSize) { |
20798 | this._update(this._block) | 29937 | this._update(this._block) |
20799 | this._block.fill(0) | 29938 | this._block.fill(0) |
20800 | } | 29939 | } |
20801 | 29940 | ||
20802 | // to this append the block which is equal to the number l written in binary | 29941 | var bits = this._len * 8 |
20803 | // TODO: handle case where l is > Math.pow(2, 29) | ||
20804 | this._block.writeInt32BE(l, this._blockSize - 4) | ||
20805 | 29942 | ||
20806 | var hash = this._update(this._block) || this._hash() | 29943 | // uint32 |
29944 | if (bits <= 0xffffffff) { | ||
29945 | this._block.writeUInt32BE(bits, this._blockSize - 4) | ||
29946 | |||
29947 | // uint64 | ||
29948 | } else { | ||
29949 | var lowBits = bits & 0xffffffff | ||
29950 | var highBits = (bits - lowBits) / 0x100000000 | ||
29951 | |||
29952 | this._block.writeUInt32BE(highBits, this._blockSize - 8) | ||
29953 | this._block.writeUInt32BE(lowBits, this._blockSize - 4) | ||
29954 | } | ||
29955 | |||
29956 | this._update(this._block) | ||
29957 | var hash = this._hash() | ||
20807 | 29958 | ||
20808 | return enc ? hash.toString(enc) : hash | 29959 | return enc ? hash.toString(enc) : hash |
20809 | } | 29960 | } |
@@ -20814,8 +29965,7 @@ Hash.prototype._update = function () { | |||
20814 | 29965 | ||
20815 | module.exports = Hash | 29966 | module.exports = Hash |
20816 | 29967 | ||
20817 | }).call(this,require("buffer").Buffer) | 29968 | },{"safe-buffer":128}],130:[function(require,module,exports){ |
20818 | },{"buffer":4}],100:[function(require,module,exports){ | ||
20819 | var exports = module.exports = function SHA (algorithm) { | 29969 | var exports = module.exports = function SHA (algorithm) { |
20820 | algorithm = algorithm.toLowerCase() | 29970 | algorithm = algorithm.toLowerCase() |
20821 | 29971 | ||
@@ -20832,8 +29982,7 @@ exports.sha256 = require('./sha256') | |||
20832 | exports.sha384 = require('./sha384') | 29982 | exports.sha384 = require('./sha384') |
20833 | exports.sha512 = require('./sha512') | 29983 | exports.sha512 = require('./sha512') |
20834 | 29984 | ||
20835 | },{"./sha":101,"./sha1":102,"./sha224":103,"./sha256":104,"./sha384":105,"./sha512":106}],101:[function(require,module,exports){ | 29985 | },{"./sha":131,"./sha1":132,"./sha224":133,"./sha256":134,"./sha384":135,"./sha512":136}],131:[function(require,module,exports){ |
20836 | (function (Buffer){ | ||
20837 | /* | 29986 | /* |
20838 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined | 29987 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined |
20839 | * in FIPS PUB 180-1 | 29988 | * in FIPS PUB 180-1 |
@@ -20844,6 +29993,7 @@ exports.sha512 = require('./sha512') | |||
20844 | 29993 | ||
20845 | var inherits = require('inherits') | 29994 | var inherits = require('inherits') |
20846 | var Hash = require('./hash') | 29995 | var Hash = require('./hash') |
29996 | var Buffer = require('safe-buffer').Buffer | ||
20847 | 29997 | ||
20848 | var K = [ | 29998 | var K = [ |
20849 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | 29999 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 |
@@ -20915,7 +30065,7 @@ Sha.prototype._update = function (M) { | |||
20915 | } | 30065 | } |
20916 | 30066 | ||
20917 | Sha.prototype._hash = function () { | 30067 | Sha.prototype._hash = function () { |
20918 | var H = new Buffer(20) | 30068 | var H = Buffer.allocUnsafe(20) |
20919 | 30069 | ||
20920 | H.writeInt32BE(this._a | 0, 0) | 30070 | H.writeInt32BE(this._a | 0, 0) |
20921 | H.writeInt32BE(this._b | 0, 4) | 30071 | H.writeInt32BE(this._b | 0, 4) |
@@ -20928,9 +30078,7 @@ Sha.prototype._hash = function () { | |||
20928 | 30078 | ||
20929 | module.exports = Sha | 30079 | module.exports = Sha |
20930 | 30080 | ||
20931 | }).call(this,require("buffer").Buffer) | 30081 | },{"./hash":129,"inherits":121,"safe-buffer":128}],132:[function(require,module,exports){ |
20932 | },{"./hash":99,"buffer":4,"inherits":93}],102:[function(require,module,exports){ | ||
20933 | (function (Buffer){ | ||
20934 | /* | 30082 | /* |
20935 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined | 30083 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined |
20936 | * in FIPS PUB 180-1 | 30084 | * in FIPS PUB 180-1 |
@@ -20942,6 +30090,7 @@ module.exports = Sha | |||
20942 | 30090 | ||
20943 | var inherits = require('inherits') | 30091 | var inherits = require('inherits') |
20944 | var Hash = require('./hash') | 30092 | var Hash = require('./hash') |
30093 | var Buffer = require('safe-buffer').Buffer | ||
20945 | 30094 | ||
20946 | var K = [ | 30095 | var K = [ |
20947 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 | 30096 | 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 |
@@ -21017,7 +30166,7 @@ Sha1.prototype._update = function (M) { | |||
21017 | } | 30166 | } |
21018 | 30167 | ||
21019 | Sha1.prototype._hash = function () { | 30168 | Sha1.prototype._hash = function () { |
21020 | var H = new Buffer(20) | 30169 | var H = Buffer.allocUnsafe(20) |
21021 | 30170 | ||
21022 | H.writeInt32BE(this._a | 0, 0) | 30171 | H.writeInt32BE(this._a | 0, 0) |
21023 | H.writeInt32BE(this._b | 0, 4) | 30172 | H.writeInt32BE(this._b | 0, 4) |
@@ -21030,9 +30179,7 @@ Sha1.prototype._hash = function () { | |||
21030 | 30179 | ||
21031 | module.exports = Sha1 | 30180 | module.exports = Sha1 |
21032 | 30181 | ||
21033 | }).call(this,require("buffer").Buffer) | 30182 | },{"./hash":129,"inherits":121,"safe-buffer":128}],133:[function(require,module,exports){ |
21034 | },{"./hash":99,"buffer":4,"inherits":93}],103:[function(require,module,exports){ | ||
21035 | (function (Buffer){ | ||
21036 | /** | 30183 | /** |
21037 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | 30184 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined |
21038 | * in FIPS 180-2 | 30185 | * in FIPS 180-2 |
@@ -21044,6 +30191,7 @@ module.exports = Sha1 | |||
21044 | var inherits = require('inherits') | 30191 | var inherits = require('inherits') |
21045 | var Sha256 = require('./sha256') | 30192 | var Sha256 = require('./sha256') |
21046 | var Hash = require('./hash') | 30193 | var Hash = require('./hash') |
30194 | var Buffer = require('safe-buffer').Buffer | ||
21047 | 30195 | ||
21048 | var W = new Array(64) | 30196 | var W = new Array(64) |
21049 | 30197 | ||
@@ -21071,7 +30219,7 @@ Sha224.prototype.init = function () { | |||
21071 | } | 30219 | } |
21072 | 30220 | ||
21073 | Sha224.prototype._hash = function () { | 30221 | Sha224.prototype._hash = function () { |
21074 | var H = new Buffer(28) | 30222 | var H = Buffer.allocUnsafe(28) |
21075 | 30223 | ||
21076 | H.writeInt32BE(this._a, 0) | 30224 | H.writeInt32BE(this._a, 0) |
21077 | H.writeInt32BE(this._b, 4) | 30225 | H.writeInt32BE(this._b, 4) |
@@ -21086,9 +30234,7 @@ Sha224.prototype._hash = function () { | |||
21086 | 30234 | ||
21087 | module.exports = Sha224 | 30235 | module.exports = Sha224 |
21088 | 30236 | ||
21089 | }).call(this,require("buffer").Buffer) | 30237 | },{"./hash":129,"./sha256":134,"inherits":121,"safe-buffer":128}],134:[function(require,module,exports){ |
21090 | },{"./hash":99,"./sha256":104,"buffer":4,"inherits":93}],104:[function(require,module,exports){ | ||
21091 | (function (Buffer){ | ||
21092 | /** | 30238 | /** |
21093 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined | 30239 | * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined |
21094 | * in FIPS 180-2 | 30240 | * in FIPS 180-2 |
@@ -21099,6 +30245,7 @@ module.exports = Sha224 | |||
21099 | 30245 | ||
21100 | var inherits = require('inherits') | 30246 | var inherits = require('inherits') |
21101 | var Hash = require('./hash') | 30247 | var Hash = require('./hash') |
30248 | var Buffer = require('safe-buffer').Buffer | ||
21102 | 30249 | ||
21103 | var K = [ | 30250 | var K = [ |
21104 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, | 30251 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, |
@@ -21208,7 +30355,7 @@ Sha256.prototype._update = function (M) { | |||
21208 | } | 30355 | } |
21209 | 30356 | ||
21210 | Sha256.prototype._hash = function () { | 30357 | Sha256.prototype._hash = function () { |
21211 | var H = new Buffer(32) | 30358 | var H = Buffer.allocUnsafe(32) |
21212 | 30359 | ||
21213 | H.writeInt32BE(this._a, 0) | 30360 | H.writeInt32BE(this._a, 0) |
21214 | H.writeInt32BE(this._b, 4) | 30361 | H.writeInt32BE(this._b, 4) |
@@ -21224,12 +30371,11 @@ Sha256.prototype._hash = function () { | |||
21224 | 30371 | ||
21225 | module.exports = Sha256 | 30372 | module.exports = Sha256 |
21226 | 30373 | ||
21227 | }).call(this,require("buffer").Buffer) | 30374 | },{"./hash":129,"inherits":121,"safe-buffer":128}],135:[function(require,module,exports){ |
21228 | },{"./hash":99,"buffer":4,"inherits":93}],105:[function(require,module,exports){ | ||
21229 | (function (Buffer){ | ||
21230 | var inherits = require('inherits') | 30375 | var inherits = require('inherits') |
21231 | var SHA512 = require('./sha512') | 30376 | var SHA512 = require('./sha512') |
21232 | var Hash = require('./hash') | 30377 | var Hash = require('./hash') |
30378 | var Buffer = require('safe-buffer').Buffer | ||
21233 | 30379 | ||
21234 | var W = new Array(160) | 30380 | var W = new Array(160) |
21235 | 30381 | ||
@@ -21265,7 +30411,7 @@ Sha384.prototype.init = function () { | |||
21265 | } | 30411 | } |
21266 | 30412 | ||
21267 | Sha384.prototype._hash = function () { | 30413 | Sha384.prototype._hash = function () { |
21268 | var H = new Buffer(48) | 30414 | var H = Buffer.allocUnsafe(48) |
21269 | 30415 | ||
21270 | function writeInt64BE (h, l, offset) { | 30416 | function writeInt64BE (h, l, offset) { |
21271 | H.writeInt32BE(h, offset) | 30417 | H.writeInt32BE(h, offset) |
@@ -21284,11 +30430,10 @@ Sha384.prototype._hash = function () { | |||
21284 | 30430 | ||
21285 | module.exports = Sha384 | 30431 | module.exports = Sha384 |
21286 | 30432 | ||
21287 | }).call(this,require("buffer").Buffer) | 30433 | },{"./hash":129,"./sha512":136,"inherits":121,"safe-buffer":128}],136:[function(require,module,exports){ |
21288 | },{"./hash":99,"./sha512":106,"buffer":4,"inherits":93}],106:[function(require,module,exports){ | ||
21289 | (function (Buffer){ | ||
21290 | var inherits = require('inherits') | 30434 | var inherits = require('inherits') |
21291 | var Hash = require('./hash') | 30435 | var Hash = require('./hash') |
30436 | var Buffer = require('safe-buffer').Buffer | ||
21292 | 30437 | ||
21293 | var K = [ | 30438 | var K = [ |
21294 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, | 30439 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, |
@@ -21526,7 +30671,7 @@ Sha512.prototype._update = function (M) { | |||
21526 | } | 30671 | } |
21527 | 30672 | ||
21528 | Sha512.prototype._hash = function () { | 30673 | Sha512.prototype._hash = function () { |
21529 | var H = new Buffer(64) | 30674 | var H = Buffer.allocUnsafe(64) |
21530 | 30675 | ||
21531 | function writeInt64BE (h, l, offset) { | 30676 | function writeInt64BE (h, l, offset) { |
21532 | H.writeInt32BE(h, offset) | 30677 | H.writeInt32BE(h, offset) |
@@ -21547,89 +30692,9 @@ Sha512.prototype._hash = function () { | |||
21547 | 30692 | ||
21548 | module.exports = Sha512 | 30693 | module.exports = Sha512 |
21549 | 30694 | ||
21550 | }).call(this,require("buffer").Buffer) | 30695 | },{"./hash":129,"inherits":121,"safe-buffer":128}],137:[function(require,module,exports){ |
21551 | },{"./hash":99,"buffer":4,"inherits":93}],107:[function(require,module,exports){ | ||
21552 | var inherits = require('inherits') | ||
21553 | var native = require('./native') | 30696 | var native = require('./native') |
21554 | 30697 | ||
21555 | function TfTypeError (type, value, valueTypeName) { | ||
21556 | this.__error = Error.call(this) | ||
21557 | this.__type = type | ||
21558 | this.__value = value | ||
21559 | this.__valueTypeName = valueTypeName | ||
21560 | |||
21561 | var message | ||
21562 | Object.defineProperty(this, 'message', { | ||
21563 | enumerable: true, | ||
21564 | get: function () { | ||
21565 | if (message) return message | ||
21566 | |||
21567 | valueTypeName = valueTypeName || getValueTypeName(value) | ||
21568 | message = tfErrorString(type, value, valueTypeName) | ||
21569 | |||
21570 | return message | ||
21571 | } | ||
21572 | }) | ||
21573 | } | ||
21574 | |||
21575 | function TfPropertyTypeError (type, property, label, value, error, valueTypeName) { | ||
21576 | this.__error = error || Error.call(this) | ||
21577 | this.__label = label | ||
21578 | this.__property = property | ||
21579 | this.__type = type | ||
21580 | this.__value = value | ||
21581 | this.__valueTypeName = valueTypeName | ||
21582 | |||
21583 | var message | ||
21584 | Object.defineProperty(this, 'message', { | ||
21585 | enumerable: true, | ||
21586 | get: function () { | ||
21587 | if (message) return message | ||
21588 | if (type) { | ||
21589 | valueTypeName = valueTypeName || getValueTypeName(value) | ||
21590 | message = tfPropertyErrorString(type, label, property, value, valueTypeName) | ||
21591 | } else { | ||
21592 | message = 'Unexpected property "' + property + '"' | ||
21593 | } | ||
21594 | |||
21595 | return message | ||
21596 | } | ||
21597 | }) | ||
21598 | } | ||
21599 | |||
21600 | // inherit from Error, assign stack | ||
21601 | [TfTypeError, TfPropertyTypeError].forEach(function (tfErrorType) { | ||
21602 | inherits(tfErrorType, Error) | ||
21603 | Object.defineProperty(tfErrorType, 'stack', { | ||
21604 | get: function () { return this.__error.stack } | ||
21605 | }) | ||
21606 | }) | ||
21607 | |||
21608 | function tfCustomError (expected, actual) { | ||
21609 | return new TfTypeError(expected, {}, actual) | ||
21610 | } | ||
21611 | |||
21612 | function tfSubError (e, property, label) { | ||
21613 | // sub child? | ||
21614 | if (e instanceof TfPropertyTypeError) { | ||
21615 | property = property + '.' + e.__property | ||
21616 | label = e.__label | ||
21617 | |||
21618 | return new TfPropertyTypeError( | ||
21619 | e.__type, property, label, e.__value, e.__error, e.__valueTypeName | ||
21620 | ) | ||
21621 | } | ||
21622 | |||
21623 | // child? | ||
21624 | if (e instanceof TfTypeError) { | ||
21625 | return new TfPropertyTypeError( | ||
21626 | e.__type, property, label, e.__value, e.__error, e.__valueTypeName | ||
21627 | ) | ||
21628 | } | ||
21629 | |||
21630 | return e | ||
21631 | } | ||
21632 | |||
21633 | function getTypeName (fn) { | 30698 | function getTypeName (fn) { |
21634 | return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1] | 30699 | return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1] |
21635 | } | 30700 | } |
@@ -21661,6 +30726,19 @@ function tfErrorString (type, value, valueTypeName) { | |||
21661 | (valueJson !== '' ? ' ' + valueJson : '') | 30726 | (valueJson !== '' ? ' ' + valueJson : '') |
21662 | } | 30727 | } |
21663 | 30728 | ||
30729 | function TfTypeError (type, value, valueTypeName) { | ||
30730 | valueTypeName = valueTypeName || getValueTypeName(value) | ||
30731 | this.message = tfErrorString(type, value, valueTypeName) | ||
30732 | |||
30733 | Error.captureStackTrace(this, TfTypeError) | ||
30734 | this.__type = type | ||
30735 | this.__value = value | ||
30736 | this.__valueTypeName = valueTypeName | ||
30737 | } | ||
30738 | |||
30739 | TfTypeError.prototype = Object.create(Error.prototype) | ||
30740 | TfTypeError.prototype.constructor = TfTypeError | ||
30741 | |||
21664 | function tfPropertyErrorString (type, label, name, value, valueTypeName) { | 30742 | function tfPropertyErrorString (type, label, name, value, valueTypeName) { |
21665 | var description = '" of type ' | 30743 | var description = '" of type ' |
21666 | if (label === 'key') description = '" with key type ' | 30744 | if (label === 'key') description = '" with key type ' |
@@ -21668,6 +30746,49 @@ function tfPropertyErrorString (type, label, name, value, valueTypeName) { | |||
21668 | return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName) | 30746 | return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName) |
21669 | } | 30747 | } |
21670 | 30748 | ||
30749 | function TfPropertyTypeError (type, property, label, value, valueTypeName) { | ||
30750 | if (type) { | ||
30751 | valueTypeName = valueTypeName || getValueTypeName(value) | ||
30752 | this.message = tfPropertyErrorString(type, label, property, value, valueTypeName) | ||
30753 | } else { | ||
30754 | this.message = 'Unexpected property "' + property + '"' | ||
30755 | } | ||
30756 | |||
30757 | Error.captureStackTrace(this, TfTypeError) | ||
30758 | this.__label = label | ||
30759 | this.__property = property | ||
30760 | this.__type = type | ||
30761 | this.__value = value | ||
30762 | this.__valueTypeName = valueTypeName | ||
30763 | } | ||
30764 | |||
30765 | TfPropertyTypeError.prototype = Object.create(Error.prototype) | ||
30766 | TfPropertyTypeError.prototype.constructor = TfTypeError | ||
30767 | |||
30768 | function tfCustomError (expected, actual) { | ||
30769 | return new TfTypeError(expected, {}, actual) | ||
30770 | } | ||
30771 | |||
30772 | function tfSubError (e, property, label) { | ||
30773 | // sub child? | ||
30774 | if (e instanceof TfPropertyTypeError) { | ||
30775 | property = property + '.' + e.__property | ||
30776 | |||
30777 | e = new TfPropertyTypeError( | ||
30778 | e.__type, property, e.__label, e.__value, e.__valueTypeName | ||
30779 | ) | ||
30780 | |||
30781 | // child? | ||
30782 | } else if (e instanceof TfTypeError) { | ||
30783 | e = new TfPropertyTypeError( | ||
30784 | e.__type, property, label, e.__value, e.__valueTypeName | ||
30785 | ) | ||
30786 | } | ||
30787 | |||
30788 | Error.captureStackTrace(e) | ||
30789 | return e | ||
30790 | } | ||
30791 | |||
21671 | module.exports = { | 30792 | module.exports = { |
21672 | TfTypeError: TfTypeError, | 30793 | TfTypeError: TfTypeError, |
21673 | TfPropertyTypeError: TfPropertyTypeError, | 30794 | TfPropertyTypeError: TfPropertyTypeError, |
@@ -21677,7 +30798,7 @@ module.exports = { | |||
21677 | getValueTypeName: getValueTypeName | 30798 | getValueTypeName: getValueTypeName |
21678 | } | 30799 | } |
21679 | 30800 | ||
21680 | },{"./native":110,"inherits":93}],108:[function(require,module,exports){ | 30801 | },{"./native":140}],138:[function(require,module,exports){ |
21681 | (function (Buffer){ | 30802 | (function (Buffer){ |
21682 | var NATIVE = require('./native') | 30803 | var NATIVE = require('./native') |
21683 | var ERRORS = require('./errors') | 30804 | var ERRORS = require('./errors') |
@@ -21707,6 +30828,7 @@ function _LengthN (type, length) { | |||
21707 | var _ArrayN = _LengthN.bind(null, NATIVE.Array) | 30828 | var _ArrayN = _LengthN.bind(null, NATIVE.Array) |
21708 | var _BufferN = _LengthN.bind(null, _Buffer) | 30829 | var _BufferN = _LengthN.bind(null, _Buffer) |
21709 | var _HexN = _LengthN.bind(null, Hex) | 30830 | var _HexN = _LengthN.bind(null, Hex) |
30831 | var _StringN = _LengthN.bind(null, NATIVE.String) | ||
21710 | 30832 | ||
21711 | var UINT53_MAX = Math.pow(2, 53) - 1 | 30833 | var UINT53_MAX = Math.pow(2, 53) - 1 |
21712 | 30834 | ||
@@ -21736,6 +30858,7 @@ var types = { | |||
21736 | Int8: Int8, | 30858 | Int8: Int8, |
21737 | Int16: Int16, | 30859 | Int16: Int16, |
21738 | Int32: Int32, | 30860 | Int32: Int32, |
30861 | StringN: _StringN, | ||
21739 | UInt8: UInt8, | 30862 | UInt8: UInt8, |
21740 | UInt16: UInt16, | 30863 | UInt16: UInt16, |
21741 | UInt32: UInt32, | 30864 | UInt32: UInt32, |
@@ -21751,7 +30874,7 @@ for (var typeName in types) { | |||
21751 | module.exports = types | 30874 | module.exports = types |
21752 | 30875 | ||
21753 | }).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) | 30876 | }).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) |
21754 | },{"../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":9,"./errors":107,"./native":110}],109:[function(require,module,exports){ | 30877 | },{"../../../../../.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){ |
21755 | var ERRORS = require('./errors') | 30878 | var ERRORS = require('./errors') |
21756 | var NATIVE = require('./native') | 30879 | var NATIVE = require('./native') |
21757 | 30880 | ||
@@ -21768,6 +30891,7 @@ var TYPES = { | |||
21768 | 30891 | ||
21769 | function _arrayOf (array, strict) { | 30892 | function _arrayOf (array, strict) { |
21770 | if (!NATIVE.Array(array)) return false | 30893 | if (!NATIVE.Array(array)) return false |
30894 | if (NATIVE.Nil(array)) return false | ||
21771 | 30895 | ||
21772 | return array.every(function (value, i) { | 30896 | return array.every(function (value, i) { |
21773 | try { | 30897 | try { |
@@ -21798,8 +30922,8 @@ var TYPES = { | |||
21798 | if (propertyKeyType) propertyKeyType = compile(propertyKeyType) | 30922 | if (propertyKeyType) propertyKeyType = compile(propertyKeyType) |
21799 | 30923 | ||
21800 | function _map (value, strict) { | 30924 | function _map (value, strict) { |
21801 | if (!NATIVE.Object(value, strict)) return false | 30925 | if (!NATIVE.Object(value)) return false |
21802 | if (NATIVE.Nil(value, strict)) return false | 30926 | if (NATIVE.Nil(value)) return false |
21803 | 30927 | ||
21804 | for (var propertyName in value) { | 30928 | for (var propertyName in value) { |
21805 | try { | 30929 | try { |
@@ -21901,13 +31025,17 @@ var TYPES = { | |||
21901 | var types = [].slice.call(arguments).map(compile) | 31025 | var types = [].slice.call(arguments).map(compile) |
21902 | 31026 | ||
21903 | function _tuple (values, strict) { | 31027 | function _tuple (values, strict) { |
31028 | if (NATIVE.Nil(values)) return false | ||
31029 | if (NATIVE.Nil(values.length)) return false | ||
31030 | if (strict && (values.length !== types.length)) return false | ||
31031 | |||
21904 | return types.every(function (type, i) { | 31032 | return types.every(function (type, i) { |
21905 | try { | 31033 | try { |
21906 | return typeforce(type, values[i], strict) | 31034 | return typeforce(type, values[i], strict) |
21907 | } catch (e) { | 31035 | } catch (e) { |
21908 | throw tfSubError(e, i) | 31036 | throw tfSubError(e, i) |
21909 | } | 31037 | } |
21910 | }) && (!strict || values.length === arguments.length) | 31038 | }) |
21911 | } | 31039 | } |
21912 | _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' } | 31040 | _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' } |
21913 | 31041 | ||
@@ -21926,11 +31054,11 @@ var TYPES = { | |||
21926 | 31054 | ||
21927 | function compile (type) { | 31055 | function compile (type) { |
21928 | if (NATIVE.String(type)) { | 31056 | if (NATIVE.String(type)) { |
21929 | if (type[0] === '?') return TYPES.maybe(compile(type.slice(1))) | 31057 | if (type[0] === '?') return TYPES.maybe(type.slice(1)) |
21930 | 31058 | ||
21931 | return NATIVE[type] || TYPES.quacksLike(type) | 31059 | return NATIVE[type] || TYPES.quacksLike(type) |
21932 | } else if (type && NATIVE.Object(type)) { | 31060 | } else if (type && NATIVE.Object(type)) { |
21933 | if (NATIVE.Array(type)) return TYPES.arrayOf(compile(type[0])) | 31061 | if (NATIVE.Array(type)) return TYPES.arrayOf(type[0]) |
21934 | 31062 | ||
21935 | return TYPES.object(type) | 31063 | return TYPES.object(type) |
21936 | } else if (NATIVE.Function(type)) { | 31064 | } else if (NATIVE.Function(type)) { |
@@ -21986,7 +31114,7 @@ typeforce.TfPropertyTypeError = TfPropertyTypeError | |||
21986 | 31114 | ||
21987 | module.exports = typeforce | 31115 | module.exports = typeforce |
21988 | 31116 | ||
21989 | },{"./errors":107,"./extra":108,"./native":110}],110:[function(require,module,exports){ | 31117 | },{"./errors":137,"./extra":138,"./native":140}],140:[function(require,module,exports){ |
21990 | var types = { | 31118 | var types = { |
21991 | Array: function (value) { return value !== null && value !== undefined && value.constructor === Array }, | 31119 | Array: function (value) { return value !== null && value !== undefined && value.constructor === Array }, |
21992 | Boolean: function (value) { return typeof value === 'boolean' }, | 31120 | Boolean: function (value) { return typeof value === 'boolean' }, |
@@ -22009,7 +31137,7 @@ for (var typeName in types) { | |||
22009 | 31137 | ||
22010 | module.exports = types | 31138 | module.exports = types |
22011 | 31139 | ||
22012 | },{}],111:[function(require,module,exports){ | 31140 | },{}],141:[function(require,module,exports){ |
22013 | (function (Buffer){ | 31141 | (function (Buffer){ |
22014 | 'use strict' | 31142 | 'use strict' |
22015 | 31143 | ||
@@ -22102,7 +31230,7 @@ function encodingLength (number) { | |||
22102 | module.exports = { encode: encode, decode: decode, encodingLength: encodingLength } | 31230 | module.exports = { encode: encode, decode: decode, encodingLength: encodingLength } |
22103 | 31231 | ||
22104 | }).call(this,require("buffer").Buffer) | 31232 | }).call(this,require("buffer").Buffer) |
22105 | },{"buffer":4}],112:[function(require,module,exports){ | 31233 | },{"buffer":5}],142:[function(require,module,exports){ |
22106 | (function (Buffer){ | 31234 | (function (Buffer){ |
22107 | var bs58check = require('bs58check') | 31235 | var bs58check = require('bs58check') |
22108 | 31236 | ||
@@ -22169,9 +31297,8 @@ module.exports = { | |||
22169 | } | 31297 | } |
22170 | 31298 | ||
22171 | }).call(this,require("buffer").Buffer) | 31299 | }).call(this,require("buffer").Buffer) |
22172 | },{"bs58check":80,"buffer":4}]},{},[33])(33) | 31300 | },{"bs58check":85,"buffer":5}]},{},[34])(34) |
22173 | }); | 31301 | });</script> |
22174 | </script> | ||
22175 | <script>bitcoinjs.bitcoin.networks.shadow = { | 31302 | <script>bitcoinjs.bitcoin.networks.shadow = { |
22176 | messagePrefix: 'unused', | 31303 | messagePrefix: 'unused', |
22177 | bip32: { | 31304 | bip32: { |
@@ -22458,38 +31585,75 @@ bitcoinjs.bitcoin.networks.monacoin = { | |||
22458 | wif: 0xb0 | 31585 | wif: 0xb0 |
22459 | }; | 31586 | }; |
22460 | 31587 | ||
22461 | bitcoinjs.bitcoin.networks.bitcoinBip49 = { | 31588 | bitcoinjs.bitcoin.networks.litecoinXprv = { |
31589 | messagePrefix: '\x19Litecoin Signed Message:\n', | ||
31590 | bip32: { | ||
31591 | public: 0x0488b21e, | ||
31592 | private: 0x0488ade4, | ||
31593 | }, | ||
31594 | pubKeyHash: 0x30, | ||
31595 | scriptHash: 0x32, | ||
31596 | wif: 0xb0 | ||
31597 | }; | ||
31598 | </script> | ||
31599 | <script>(function() { | ||
31600 | |||
31601 | // p2wpkh | ||
31602 | |||
31603 | bitcoinjs.bitcoin.networks.bitcoin.p2wpkh = { | ||
31604 | baseNetwork: "bitcoin", | ||
31605 | messagePrefix: '\x18Bitcoin Signed Message:\n', | ||
31606 | bech32: 'bc', | ||
31607 | bip32: { | ||
31608 | public: 0x04b24746, | ||
31609 | private: 0x04b2430c | ||
31610 | }, | ||
31611 | pubKeyHash: 0x00, | ||
31612 | scriptHash: 0x05, | ||
31613 | wif: 0x80 | ||
31614 | }; | ||
31615 | |||
31616 | // p2wpkh in p2sh | ||
31617 | |||
31618 | bitcoinjs.bitcoin.networks.bitcoin.p2wpkhInP2sh = { | ||
31619 | baseNetwork: "bitcoin", | ||
22462 | messagePrefix: '\x18Bitcoin Signed Message:\n', | 31620 | messagePrefix: '\x18Bitcoin Signed Message:\n', |
31621 | bech32: 'bc', | ||
22463 | bip32: { | 31622 | bip32: { |
22464 | public: 0x049d7cb2, | 31623 | public: 0x049d7cb2, |
22465 | private: 0x049d7878 | 31624 | private: 0x049d7878 |
22466 | }, | 31625 | }, |
22467 | pubKeyHash: 0x00, | 31626 | pubKeyHash: 0x00, |
22468 | scriptHash: 0x05, | 31627 | scriptHash: 0x05, |
22469 | wif: 0x80 | 31628 | wif: 0x80 |
22470 | }; | 31629 | }; |
22471 | 31630 | ||
22472 | bitcoinjs.bitcoin.networks.testnetBip49 = { | 31631 | bitcoinjs.bitcoin.networks.testnet.p2wpkhInP2sh = { |
31632 | baseNetwork: "testnet", | ||
22473 | messagePrefix: '\x18Bitcoin Signed Message:\n', | 31633 | messagePrefix: '\x18Bitcoin Signed Message:\n', |
31634 | bech32: 'tb', | ||
22474 | bip32: { | 31635 | bip32: { |
22475 | public: 0x044a5262, | 31636 | public: 0x044a5262, |
22476 | private: 0x044a4e28 | 31637 | private: 0x044a4e28 |
22477 | }, | 31638 | }, |
22478 | pubKeyHash: 0x6f, | 31639 | pubKeyHash: 0x6f, |
22479 | scriptHash: 0xc4, | 31640 | scriptHash: 0xc4, |
22480 | wif: 0xef | 31641 | wif: 0xef |
22481 | }; | 31642 | }; |
22482 | 31643 | ||
22483 | bitcoinjs.bitcoin.networks.litecoinBip49 = { | 31644 | bitcoinjs.bitcoin.networks.litecoin.p2wpkhInP2sh = { |
31645 | baseNetwork: "litecoin", | ||
22484 | messagePrefix: '\x19Litecoin Signed Message:\n', | 31646 | messagePrefix: '\x19Litecoin Signed Message:\n', |
22485 | bip32: { | 31647 | bip32: { |
22486 | public: 0x01b26ef6, | 31648 | public: 0x01b26ef6, |
22487 | private: 0x01b26792 | 31649 | private: 0x01b26792 |
22488 | }, | 31650 | }, |
22489 | pubKeyHash: 0x30, | 31651 | pubKeyHash: 0x30, |
22490 | scriptHash: 0x32, | 31652 | scriptHash: 0x32, |
22491 | wif: 0xb0 | 31653 | wif: 0xb0 |
22492 | }; | 31654 | }; |
31655 | |||
31656 | })(); | ||
22493 | </script> | 31657 | </script> |
22494 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | 31658 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
22495 | (function (global){ | 31659 | (function (global){ |
@@ -46017,7 +55181,7 @@ window.Entropy = new (function() { | |||
46017 | var showPubKey = true; | 55181 | var showPubKey = true; |
46018 | var showPrivKey = true; | 55182 | var showPrivKey = true; |
46019 | var showQr = false; | 55183 | var showQr = false; |
46020 | var litecoinUseLtub = false; | 55184 | var litecoinUseLtub = true; |
46021 | 55185 | ||
46022 | var entropyChangeTimeoutEvent = null; | 55186 | var entropyChangeTimeoutEvent = null; |
46023 | var phraseChangeTimeoutEvent = null; | 55187 | var phraseChangeTimeoutEvent = null; |
@@ -46055,6 +55219,7 @@ window.Entropy = new (function() { | |||
46055 | DOM.bip32tab = $("#bip32-tab"); | 55219 | DOM.bip32tab = $("#bip32-tab"); |
46056 | DOM.bip44tab = $("#bip44-tab"); | 55220 | DOM.bip44tab = $("#bip44-tab"); |
46057 | DOM.bip49tab = $("#bip49-tab"); | 55221 | DOM.bip49tab = $("#bip49-tab"); |
55222 | DOM.bip141tab = $("#bip141-tab"); | ||
46058 | DOM.bip32panel = $("#bip32"); | 55223 | DOM.bip32panel = $("#bip32"); |
46059 | DOM.bip44panel = $("#bip44"); | 55224 | DOM.bip44panel = $("#bip44"); |
46060 | DOM.bip49panel = $("#bip49"); | 55225 | DOM.bip49panel = $("#bip49"); |
@@ -46075,9 +55240,12 @@ window.Entropy = new (function() { | |||
46075 | DOM.bip49accountXprv = $("#bip49 .account-xprv"); | 55240 | DOM.bip49accountXprv = $("#bip49 .account-xprv"); |
46076 | DOM.bip49accountXpub = $("#bip49 .account-xpub"); | 55241 | DOM.bip49accountXpub = $("#bip49 .account-xpub"); |
46077 | DOM.bip49change = $("#bip49 .change"); | 55242 | DOM.bip49change = $("#bip49 .change"); |
55243 | DOM.bip141unavailable = $("#bip141 .unavailable"); | ||
55244 | DOM.bip141available = $("#bip141 .available"); | ||
55245 | DOM.bip141path = $("#bip141-path"); | ||
55246 | DOM.bip141semantics = $(".bip141-semantics"); | ||
46078 | DOM.generatedStrength = $(".generate-container .strength"); | 55247 | DOM.generatedStrength = $(".generate-container .strength"); |
46079 | DOM.hardenedAddresses = $(".hardened-addresses"); | 55248 | DOM.hardenedAddresses = $(".hardened-addresses"); |
46080 | DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh"); | ||
46081 | DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container"); | 55249 | DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container"); |
46082 | DOM.useBitpayAddresses = $(".use-bitpay-addresses"); | 55250 | DOM.useBitpayAddresses = $(".use-bitpay-addresses"); |
46083 | DOM.addresses = $(".addresses"); | 55251 | DOM.addresses = $(".addresses"); |
@@ -46115,9 +55283,10 @@ window.Entropy = new (function() { | |||
46115 | DOM.bip44change.on("input", calcForDerivationPath); | 55283 | DOM.bip44change.on("input", calcForDerivationPath); |
46116 | DOM.bip49account.on("input", calcForDerivationPath); | 55284 | DOM.bip49account.on("input", calcForDerivationPath); |
46117 | DOM.bip49change.on("input", calcForDerivationPath); | 55285 | DOM.bip49change.on("input", calcForDerivationPath); |
55286 | DOM.bip141path.on("input", calcForDerivationPath); | ||
55287 | DOM.bip141semantics.on("change", tabChanged); | ||
46118 | DOM.tab.on("shown.bs.tab", tabChanged); | 55288 | DOM.tab.on("shown.bs.tab", tabChanged); |
46119 | DOM.hardenedAddresses.on("change", calcForDerivationPath); | 55289 | DOM.hardenedAddresses.on("change", calcForDerivationPath); |
46120 | DOM.useP2wpkhNestedInP2sh.on("change", calcForDerivationPath); | ||
46121 | DOM.indexToggle.on("click", toggleIndexes); | 55290 | DOM.indexToggle.on("click", toggleIndexes); |
46122 | DOM.addressToggle.on("click", toggleAddresses); | 55291 | DOM.addressToggle.on("click", toggleAddresses); |
46123 | DOM.publicKeyToggle.on("click", togglePublicKeys); | 55292 | DOM.publicKeyToggle.on("click", togglePublicKeys); |
@@ -46142,11 +55311,12 @@ window.Entropy = new (function() { | |||
46142 | var networkIndex = e.target.value; | 55311 | var networkIndex = e.target.value; |
46143 | var network = networks[networkIndex]; | 55312 | var network = networks[networkIndex]; |
46144 | network.onSelect(); | 55313 | network.onSelect(); |
46145 | if (network.p2wpkhNestedInP2shAvailable) { | 55314 | if (network.segwitAvailable) { |
46146 | showP2wpkhNestedInP2shAvailable(); | 55315 | adjustNetworkForSegwit(); |
55316 | showSegwitAvailable(); | ||
46147 | } | 55317 | } |
46148 | else { | 55318 | else { |
46149 | showP2wpkhNestedInP2shUnavailable(); | 55319 | showSegwitUnavailable(); |
46150 | } | 55320 | } |
46151 | if (seed != null) { | 55321 | if (seed != null) { |
46152 | phraseChanged(); | 55322 | phraseChanged(); |
@@ -46220,7 +55390,7 @@ window.Entropy = new (function() { | |||
46220 | 55390 | ||
46221 | function tabChanged() { | 55391 | function tabChanged() { |
46222 | showPending(); | 55392 | showPending(); |
46223 | adjustNetworkForBip49(); | 55393 | adjustNetworkForSegwit(); |
46224 | var phrase = DOM.phrase.val(); | 55394 | var phrase = DOM.phrase.val(); |
46225 | if (phrase != "") { | 55395 | if (phrase != "") { |
46226 | // Calculate and display for mnemonic | 55396 | // Calculate and display for mnemonic |
@@ -46321,10 +55491,10 @@ window.Entropy = new (function() { | |||
46321 | function litecoinUseLtubChanged() { | 55491 | function litecoinUseLtubChanged() { |
46322 | litecoinUseLtub = DOM.litecoinUseLtub.prop("checked"); | 55492 | litecoinUseLtub = DOM.litecoinUseLtub.prop("checked"); |
46323 | if (litecoinUseLtub) { | 55493 | if (litecoinUseLtub) { |
46324 | network = bitcoinjs.bitcoin.networks.litecoinLtub; | 55494 | network = bitcoinjs.bitcoin.networks.litecoin; |
46325 | } | 55495 | } |
46326 | else { | 55496 | else { |
46327 | network = bitcoinjs.bitcoin.networks.litecoin; | 55497 | network = bitcoinjs.bitcoin.networks.litecoinXprv; |
46328 | } | 55498 | } |
46329 | phraseChanged(); | 55499 | phraseChanged(); |
46330 | } | 55500 | } |
@@ -46333,8 +55503,8 @@ window.Entropy = new (function() { | |||
46333 | clearDerivedKeys(); | 55503 | clearDerivedKeys(); |
46334 | clearAddressesList(); | 55504 | clearAddressesList(); |
46335 | showPending(); | 55505 | showPending(); |
46336 | // Don't show bip49 if it's selected but network doesn't support it | 55506 | // Don't show segwit if it's selected but network doesn't support it |
46337 | if (bip49TabSelected() && !networkHasBip49()) { | 55507 | if (segwitSelected() && !networkHasSegwit()) { |
46338 | return; | 55508 | return; |
46339 | } | 55509 | } |
46340 | // Get the derivation path | 55510 | // Get the derivation path |
@@ -46348,7 +55518,7 @@ window.Entropy = new (function() { | |||
46348 | if (bip44TabSelected()) { | 55518 | if (bip44TabSelected()) { |
46349 | displayBip44Info(); | 55519 | displayBip44Info(); |
46350 | } | 55520 | } |
46351 | if (bip49TabSelected()) { | 55521 | else if (bip49TabSelected()) { |
46352 | displayBip49Info(); | 55522 | displayBip49Info(); |
46353 | } | 55523 | } |
46354 | displayBip32Info(); | 55524 | displayBip32Info(); |
@@ -46528,7 +55698,7 @@ window.Entropy = new (function() { | |||
46528 | console.log("Using derivation path from BIP44 tab: " + derivationPath); | 55698 | console.log("Using derivation path from BIP44 tab: " + derivationPath); |
46529 | return derivationPath; | 55699 | return derivationPath; |
46530 | } | 55700 | } |
46531 | if (bip49TabSelected()) { | 55701 | else if (bip49TabSelected()) { |
46532 | var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49); | 55702 | var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49); |
46533 | var coin = parseIntNoNaN(DOM.bip49coin.val(), 0); | 55703 | var coin = parseIntNoNaN(DOM.bip49coin.val(), 0); |
46534 | var account = parseIntNoNaN(DOM.bip49account.val(), 0); | 55704 | var account = parseIntNoNaN(DOM.bip49account.val(), 0); |
@@ -46548,6 +55718,11 @@ window.Entropy = new (function() { | |||
46548 | console.log("Using derivation path from BIP32 tab: " + derivationPath); | 55718 | console.log("Using derivation path from BIP32 tab: " + derivationPath); |
46549 | return derivationPath; | 55719 | return derivationPath; |
46550 | } | 55720 | } |
55721 | else if (bip141TabSelected()) { | ||
55722 | var derivationPath = DOM.bip141path.val(); | ||
55723 | console.log("Using derivation path from BIP141 tab: " + derivationPath); | ||
55724 | return derivationPath; | ||
55725 | } | ||
46551 | else { | 55726 | else { |
46552 | console.log("Unknown derivation path"); | 55727 | console.log("Unknown derivation path"); |
46553 | } | 55728 | } |
@@ -46677,8 +55852,17 @@ window.Entropy = new (function() { | |||
46677 | })()); | 55852 | })()); |
46678 | } | 55853 | } |
46679 | 55854 | ||
46680 | function P2wpkhNestedInP2shSelected() { | 55855 | function segwitSelected() { |
46681 | return bip49TabSelected() || (bip32TabSelected() && useP2wpkhNestedInP2sh()); | 55856 | return bip49TabSelected() || bip141TabSelected(); |
55857 | } | ||
55858 | |||
55859 | function p2wpkhSelected() { | ||
55860 | return bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh"; | ||
55861 | } | ||
55862 | |||
55863 | function p2wpkhInP2shSelected() { | ||
55864 | return bip49TabSelected() || | ||
55865 | (bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh-p2sh"); | ||
46682 | } | 55866 | } |
46683 | 55867 | ||
46684 | function TableRow(index, isLast) { | 55868 | function TableRow(index, isLast) { |
@@ -46686,8 +55870,10 @@ window.Entropy = new (function() { | |||
46686 | var self = this; | 55870 | var self = this; |
46687 | this.shouldGenerate = true; | 55871 | this.shouldGenerate = true; |
46688 | var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); | 55872 | var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); |
46689 | var isP2wpkhNestedInP2sh = P2wpkhNestedInP2shSelected(); | 55873 | var isSegwit = segwitSelected(); |
46690 | var p2wpkhNestedInP2shAvailable = networkHasBip49(); | 55874 | var segwitAvailable = networkHasSegwit(); |
55875 | var isP2wpkh = p2wpkhSelected(); | ||
55876 | var isP2wpkhInP2sh = p2wpkhInP2shSelected(); | ||
46691 | 55877 | ||
46692 | function init() { | 55878 | function init() { |
46693 | calculateValues(); | 55879 | calculateValues(); |
@@ -46731,16 +55917,23 @@ window.Entropy = new (function() { | |||
46731 | privkey = convertRipplePriv(privkey); | 55917 | privkey = convertRipplePriv(privkey); |
46732 | address = convertRippleAdrr(address); | 55918 | address = convertRippleAdrr(address); |
46733 | } | 55919 | } |
46734 | // BIP49 addresses are different | 55920 | // Segwit addresses are different |
46735 | if (isP2wpkhNestedInP2sh) { | 55921 | if (isSegwit) { |
46736 | if (!p2wpkhNestedInP2shAvailable) { | 55922 | if (!segwitAvailable) { |
46737 | return; | 55923 | return; |
46738 | } | 55924 | } |
46739 | var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer()); | 55925 | if (isP2wpkh) { |
46740 | var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash); | 55926 | var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer()); |
46741 | var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig); | 55927 | var scriptpubkey = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash); |
46742 | var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes); | 55928 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) |
46743 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) | 55929 | } |
55930 | else if (isP2wpkhInP2sh) { | ||
55931 | var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer()); | ||
55932 | var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash); | ||
55933 | var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig); | ||
55934 | var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes); | ||
55935 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) | ||
55936 | } | ||
46744 | } | 55937 | } |
46745 | addAddressToList(indexText, address, pubkey, privkey); | 55938 | addAddressToList(indexText, address, pubkey, privkey); |
46746 | if (isLast) { | 55939 | if (isLast) { |
@@ -47230,34 +56423,35 @@ window.Entropy = new (function() { | |||
47230 | return DOM.bip32tab.hasClass("active"); | 56423 | return DOM.bip32tab.hasClass("active"); |
47231 | } | 56424 | } |
47232 | 56425 | ||
47233 | function useP2wpkhNestedInP2sh() { | 56426 | function networkHasSegwit() { |
47234 | return DOM.useP2wpkhNestedInP2sh.prop("checked"); | 56427 | return networks[DOM.network.val()].segwitAvailable; |
47235 | } | ||
47236 | |||
47237 | function networkHasBip49() { | ||
47238 | return networks[DOM.network.val()].p2wpkhNestedInP2shAvailable; | ||
47239 | } | 56428 | } |
47240 | 56429 | ||
47241 | function bip49TabSelected() { | 56430 | function bip49TabSelected() { |
47242 | return DOM.bip49tab.hasClass("active"); | 56431 | return DOM.bip49tab.hasClass("active"); |
47243 | } | 56432 | } |
47244 | 56433 | ||
56434 | function bip141TabSelected() { | ||
56435 | return DOM.bip141tab.hasClass("active"); | ||
56436 | } | ||
56437 | |||
47245 | function setHdCoin(coinValue) { | 56438 | function setHdCoin(coinValue) { |
47246 | DOM.bip44coin.val(coinValue); | 56439 | DOM.bip44coin.val(coinValue); |
47247 | DOM.bip49coin.val(coinValue); | 56440 | DOM.bip49coin.val(coinValue); |
47248 | } | 56441 | } |
47249 | 56442 | ||
47250 | function showP2wpkhNestedInP2shAvailable() { | 56443 | function showSegwitAvailable() { |
47251 | DOM.bip49unavailable.addClass("hidden"); | 56444 | DOM.bip49unavailable.addClass("hidden"); |
47252 | DOM.bip49available.removeClass("hidden"); | 56445 | DOM.bip49available.removeClass("hidden"); |
47253 | DOM.useP2wpkhNestedInP2sh.prop("disabled", false); | 56446 | DOM.bip141unavailable.addClass("hidden"); |
56447 | DOM.bip141available.removeClass("hidden"); | ||
47254 | } | 56448 | } |
47255 | 56449 | ||
47256 | function showP2wpkhNestedInP2shUnavailable() { | 56450 | function showSegwitUnavailable() { |
47257 | DOM.bip49available.addClass("hidden"); | 56451 | DOM.bip49available.addClass("hidden"); |
47258 | DOM.bip49unavailable.removeClass("hidden"); | 56452 | DOM.bip49unavailable.removeClass("hidden"); |
47259 | DOM.useP2wpkhNestedInP2sh.prop("disabled", true); | 56453 | DOM.bip141available.addClass("hidden"); |
47260 | DOM.useP2wpkhNestedInP2sh.prop("checked", false); | 56454 | DOM.bip141unavailable.removeClass("hidden"); |
47261 | } | 56455 | } |
47262 | 56456 | ||
47263 | function useBitpayAddresses() { | 56457 | function useBitpayAddresses() { |
@@ -47273,32 +56467,23 @@ window.Entropy = new (function() { | |||
47273 | } | 56467 | } |
47274 | } | 56468 | } |
47275 | 56469 | ||
47276 | function adjustNetworkForBip49() { | 56470 | function adjustNetworkForSegwit() { |
47277 | // If bip49 is selected the xpub/xprv prefixes need to be adjusted | 56471 | // If segwit is selected the xpub/xprv prefixes need to be adjusted |
47278 | // to avoid accidentally importing BIP49 xpub to BIP44 watch only | 56472 | // to avoid accidentally importing BIP49 xpub to BIP44 watch only |
47279 | // wallet. | 56473 | // wallet. |
47280 | // See https://github.com/iancoleman/bip39/issues/125 | 56474 | // See https://github.com/iancoleman/bip39/issues/125 |
47281 | if (P2wpkhNestedInP2shSelected()) { | 56475 | var segwitNetworks = null; |
47282 | if (network == bitcoinjs.bitcoin.networks.bitcoin) { | 56476 | // if a segwit network is alread selected, need to use base network to |
47283 | network = bitcoinjs.bitcoin.networks.bitcoinBip49; | 56477 | // look up new parameters |
47284 | } | 56478 | if ("baseNetwork" in network) { |
47285 | else if (network == bitcoinjs.bitcoin.networks.testnet) { | 56479 | network = bitcoinjs.bitcoin.networks[network.baseNetwork]; |
47286 | network = bitcoinjs.bitcoin.networks.testnetBip49; | ||
47287 | } | ||
47288 | else if (network == bitcoinjs.bitcoin.networks.litecoin) { | ||
47289 | network = bitcoinjs.bitcoin.networks.litecoinBip49; | ||
47290 | } | ||
47291 | } | 56480 | } |
47292 | else { | 56481 | // choose the right segwit params |
47293 | if (network == bitcoinjs.bitcoin.networks.bitcoinBip49) { | 56482 | if (p2wpkhSelected() && "p2wpkh" in network) { |
47294 | network = bitcoinjs.bitcoin.networks.bitcoin; | 56483 | network = network.p2wpkh; |
47295 | } | 56484 | } |
47296 | else if (network == bitcoinjs.bitcoin.networks.testnetBip49) { | 56485 | else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) { |
47297 | network = bitcoinjs.bitcoin.networks.testnet; | 56486 | network = network.p2wpkhInP2sh; |
47298 | } | ||
47299 | else if (network == bitcoinjs.bitcoin.networks.litecoinBip49) { | ||
47300 | network = bitcoinjs.bitcoin.networks.litecoin; | ||
47301 | } | ||
47302 | } | 56487 | } |
47303 | } | 56488 | } |
47304 | 56489 | ||
@@ -47313,7 +56498,7 @@ window.Entropy = new (function() { | |||
47313 | var networks = [ | 56498 | var networks = [ |
47314 | { | 56499 | { |
47315 | name: "BCH - Bitcoin Cash", | 56500 | name: "BCH - Bitcoin Cash", |
47316 | p2wpkhNestedInP2shAvailable: false, | 56501 | segwitAvailable: false, |
47317 | onSelect: function() { | 56502 | onSelect: function() { |
47318 | DOM.useBitpayAddressesContainer.removeClass("hidden"); | 56503 | DOM.useBitpayAddressesContainer.removeClass("hidden"); |
47319 | setBitcoinCashNetworkValues(); | 56504 | setBitcoinCashNetworkValues(); |
@@ -47322,7 +56507,7 @@ window.Entropy = new (function() { | |||
47322 | }, | 56507 | }, |
47323 | { | 56508 | { |
47324 | name: "BTC - Bitcoin", | 56509 | name: "BTC - Bitcoin", |
47325 | p2wpkhNestedInP2shAvailable: true, | 56510 | segwitAvailable: true, |
47326 | onSelect: function() { | 56511 | onSelect: function() { |
47327 | network = bitcoinjs.bitcoin.networks.bitcoin; | 56512 | network = bitcoinjs.bitcoin.networks.bitcoin; |
47328 | setHdCoin(0); | 56513 | setHdCoin(0); |
@@ -47330,7 +56515,7 @@ window.Entropy = new (function() { | |||
47330 | }, | 56515 | }, |
47331 | { | 56516 | { |
47332 | name: "BTC - Bitcoin Testnet", | 56517 | name: "BTC - Bitcoin Testnet", |
47333 | p2wpkhNestedInP2shAvailable: true, | 56518 | segwitAvailable: true, |
47334 | onSelect: function() { | 56519 | onSelect: function() { |
47335 | network = bitcoinjs.bitcoin.networks.testnet; | 56520 | network = bitcoinjs.bitcoin.networks.testnet; |
47336 | setHdCoin(1); | 56521 | setHdCoin(1); |
@@ -47338,7 +56523,7 @@ window.Entropy = new (function() { | |||
47338 | }, | 56523 | }, |
47339 | { | 56524 | { |
47340 | name: "BTG - Bitcoin Gold", | 56525 | name: "BTG - Bitcoin Gold", |
47341 | p2wpkhNestedInP2shAvailable: true, | 56526 | segwitAvailable: true, |
47342 | onSelect: function() { | 56527 | onSelect: function() { |
47343 | network = bitcoinjs.bitcoin.networks.bgold; | 56528 | network = bitcoinjs.bitcoin.networks.bgold; |
47344 | setHdCoin(0); | 56529 | setHdCoin(0); |
@@ -47346,7 +56531,7 @@ window.Entropy = new (function() { | |||
47346 | }, | 56531 | }, |
47347 | { | 56532 | { |
47348 | name: "CLAM - Clams", | 56533 | name: "CLAM - Clams", |
47349 | p2wpkhNestedInP2shAvailable: false, | 56534 | segwitAvailable: false, |
47350 | onSelect: function() { | 56535 | onSelect: function() { |
47351 | network = bitcoinjs.bitcoin.networks.clam; | 56536 | network = bitcoinjs.bitcoin.networks.clam; |
47352 | setHdCoin(23); | 56537 | setHdCoin(23); |
@@ -47354,7 +56539,7 @@ window.Entropy = new (function() { | |||
47354 | }, | 56539 | }, |
47355 | { | 56540 | { |
47356 | name: "CRW - Crown", | 56541 | name: "CRW - Crown", |
47357 | p2wpkhNestedInP2shAvailable: false, | 56542 | segwitAvailable: false, |
47358 | onSelect: function() { | 56543 | onSelect: function() { |
47359 | network = bitcoinjs.bitcoin.networks.crown; | 56544 | network = bitcoinjs.bitcoin.networks.crown; |
47360 | setHdCoin(72); | 56545 | setHdCoin(72); |
@@ -47362,7 +56547,7 @@ window.Entropy = new (function() { | |||
47362 | }, | 56547 | }, |
47363 | { | 56548 | { |
47364 | name: "DASH - Dash", | 56549 | name: "DASH - Dash", |
47365 | p2wpkhNestedInP2shAvailable: false, | 56550 | segwitAvailable: false, |
47366 | onSelect: function() { | 56551 | onSelect: function() { |
47367 | network = bitcoinjs.bitcoin.networks.dash; | 56552 | network = bitcoinjs.bitcoin.networks.dash; |
47368 | setHdCoin(5); | 56553 | setHdCoin(5); |
@@ -47370,7 +56555,7 @@ window.Entropy = new (function() { | |||
47370 | }, | 56555 | }, |
47371 | { | 56556 | { |
47372 | name: "DASH - Dash Testnet", | 56557 | name: "DASH - Dash Testnet", |
47373 | p2wpkhNestedInP2shAvailable: false, | 56558 | segwitAvailable: false, |
47374 | onSelect: function() { | 56559 | onSelect: function() { |
47375 | network = bitcoinjs.bitcoin.networks.dashtn; | 56560 | network = bitcoinjs.bitcoin.networks.dashtn; |
47376 | setHdCoin(1); | 56561 | setHdCoin(1); |
@@ -47378,7 +56563,7 @@ window.Entropy = new (function() { | |||
47378 | }, | 56563 | }, |
47379 | { | 56564 | { |
47380 | name: "DOGE - Dogecoin", | 56565 | name: "DOGE - Dogecoin", |
47381 | p2wpkhNestedInP2shAvailable: false, | 56566 | segwitAvailable: false, |
47382 | onSelect: function() { | 56567 | onSelect: function() { |
47383 | network = bitcoinjs.bitcoin.networks.dogecoin; | 56568 | network = bitcoinjs.bitcoin.networks.dogecoin; |
47384 | setHdCoin(3); | 56569 | setHdCoin(3); |
@@ -47386,7 +56571,7 @@ window.Entropy = new (function() { | |||
47386 | }, | 56571 | }, |
47387 | { | 56572 | { |
47388 | name: "ETH - Ethereum", | 56573 | name: "ETH - Ethereum", |
47389 | p2wpkhNestedInP2shAvailable: false, | 56574 | segwitAvailable: false, |
47390 | onSelect: function() { | 56575 | onSelect: function() { |
47391 | network = bitcoinjs.bitcoin.networks.bitcoin; | 56576 | network = bitcoinjs.bitcoin.networks.bitcoin; |
47392 | setHdCoin(60); | 56577 | setHdCoin(60); |
@@ -47394,7 +56579,7 @@ window.Entropy = new (function() { | |||
47394 | }, | 56579 | }, |
47395 | { | 56580 | { |
47396 | name: "FJC - Fujicoin", | 56581 | name: "FJC - Fujicoin", |
47397 | p2wpkhNestedInP2shAvailable: false, | 56582 | segwitAvailable: false, |
47398 | onSelect: function() { | 56583 | onSelect: function() { |
47399 | network = bitcoinjs.bitcoin.networks.fujicoin; | 56584 | network = bitcoinjs.bitcoin.networks.fujicoin; |
47400 | setHdCoin(75); | 56585 | setHdCoin(75); |
@@ -47402,7 +56587,7 @@ window.Entropy = new (function() { | |||
47402 | }, | 56587 | }, |
47403 | { | 56588 | { |
47404 | name: "GAME - GameCredits", | 56589 | name: "GAME - GameCredits", |
47405 | p2wpkhNestedInP2shAvailable: false, | 56590 | segwitAvailable: false, |
47406 | onSelect: function() { | 56591 | onSelect: function() { |
47407 | network = bitcoinjs.bitcoin.networks.game; | 56592 | network = bitcoinjs.bitcoin.networks.game; |
47408 | setHdCoin(101); | 56593 | setHdCoin(101); |
@@ -47410,7 +56595,7 @@ window.Entropy = new (function() { | |||
47410 | }, | 56595 | }, |
47411 | { | 56596 | { |
47412 | name: "JBS - Jumbucks", | 56597 | name: "JBS - Jumbucks", |
47413 | p2wpkhNestedInP2shAvailable: false, | 56598 | segwitAvailable: false, |
47414 | onSelect: function() { | 56599 | onSelect: function() { |
47415 | network = bitcoinjs.bitcoin.networks.jumbucks; | 56600 | network = bitcoinjs.bitcoin.networks.jumbucks; |
47416 | setHdCoin(26); | 56601 | setHdCoin(26); |
@@ -47418,7 +56603,7 @@ window.Entropy = new (function() { | |||
47418 | }, | 56603 | }, |
47419 | { | 56604 | { |
47420 | name: "LTC - Litecoin", | 56605 | name: "LTC - Litecoin", |
47421 | p2wpkhNestedInP2shAvailable: true, | 56606 | segwitAvailable: true, |
47422 | onSelect: function() { | 56607 | onSelect: function() { |
47423 | network = bitcoinjs.bitcoin.networks.litecoin; | 56608 | network = bitcoinjs.bitcoin.networks.litecoin; |
47424 | setHdCoin(2); | 56609 | setHdCoin(2); |
@@ -47427,7 +56612,7 @@ window.Entropy = new (function() { | |||
47427 | }, | 56612 | }, |
47428 | { | 56613 | { |
47429 | name: "MAZA - Maza", | 56614 | name: "MAZA - Maza", |
47430 | p2wpkhNestedInP2shAvailable: false, | 56615 | segwitAvailable: false, |
47431 | onSelect: function() { | 56616 | onSelect: function() { |
47432 | network = bitcoinjs.bitcoin.networks.maza; | 56617 | network = bitcoinjs.bitcoin.networks.maza; |
47433 | setHdCoin(13); | 56618 | setHdCoin(13); |
@@ -47435,7 +56620,7 @@ window.Entropy = new (function() { | |||
47435 | }, | 56620 | }, |
47436 | { | 56621 | { |
47437 | name: "MONA - Monacoin", | 56622 | name: "MONA - Monacoin", |
47438 | p2wpkhNestedInP2shAvailable: true, | 56623 | segwitAvailable: true, |
47439 | onSelect: function() { | 56624 | onSelect: function() { |
47440 | network = bitcoinjs.bitcoin.networks.monacoin, | 56625 | network = bitcoinjs.bitcoin.networks.monacoin, |
47441 | setHdCoin(22); | 56626 | setHdCoin(22); |
@@ -47443,7 +56628,7 @@ window.Entropy = new (function() { | |||
47443 | }, | 56628 | }, |
47444 | { | 56629 | { |
47445 | name: "NMC - Namecoin", | 56630 | name: "NMC - Namecoin", |
47446 | p2wpkhNestedInP2shAvailable: false, | 56631 | segwitAvailable: false, |
47447 | onSelect: function() { | 56632 | onSelect: function() { |
47448 | network = bitcoinjs.bitcoin.networks.namecoin; | 56633 | network = bitcoinjs.bitcoin.networks.namecoin; |
47449 | setHdCoin(7); | 56634 | setHdCoin(7); |
@@ -47451,7 +56636,7 @@ window.Entropy = new (function() { | |||
47451 | }, | 56636 | }, |
47452 | { | 56637 | { |
47453 | name: "PIVX - PIVX", | 56638 | name: "PIVX - PIVX", |
47454 | p2wpkhNestedInP2shAvailable: false, | 56639 | segwitAvailable: false, |
47455 | onSelect: function() { | 56640 | onSelect: function() { |
47456 | network = bitcoinjs.bitcoin.networks.pivx; | 56641 | network = bitcoinjs.bitcoin.networks.pivx; |
47457 | setHdCoin(119); | 56642 | setHdCoin(119); |
@@ -47459,7 +56644,7 @@ window.Entropy = new (function() { | |||
47459 | }, | 56644 | }, |
47460 | { | 56645 | { |
47461 | name: "PIVX - PIVX Testnet", | 56646 | name: "PIVX - PIVX Testnet", |
47462 | p2wpkhNestedInP2shAvailable: false, | 56647 | segwitAvailable: false, |
47463 | onSelect: function() { | 56648 | onSelect: function() { |
47464 | network = bitcoinjs.bitcoin.networks.pivxtestnet; | 56649 | network = bitcoinjs.bitcoin.networks.pivxtestnet; |
47465 | setHdCoin(1); | 56650 | setHdCoin(1); |
@@ -47467,7 +56652,7 @@ window.Entropy = new (function() { | |||
47467 | }, | 56652 | }, |
47468 | { | 56653 | { |
47469 | name: "PPC - Peercoin", | 56654 | name: "PPC - Peercoin", |
47470 | p2wpkhNestedInP2shAvailable: false, | 56655 | segwitAvailable: false, |
47471 | onSelect: function() { | 56656 | onSelect: function() { |
47472 | network = bitcoinjs.bitcoin.networks.peercoin; | 56657 | network = bitcoinjs.bitcoin.networks.peercoin; |
47473 | setHdCoin(6); | 56658 | setHdCoin(6); |
@@ -47475,7 +56660,7 @@ window.Entropy = new (function() { | |||
47475 | }, | 56660 | }, |
47476 | { | 56661 | { |
47477 | name: "SDC - ShadowCash", | 56662 | name: "SDC - ShadowCash", |
47478 | p2wpkhNestedInP2shAvailable: false, | 56663 | segwitAvailable: false, |
47479 | onSelect: function() { | 56664 | onSelect: function() { |
47480 | network = bitcoinjs.bitcoin.networks.shadow; | 56665 | network = bitcoinjs.bitcoin.networks.shadow; |
47481 | setHdCoin(35); | 56666 | setHdCoin(35); |
@@ -47483,7 +56668,7 @@ window.Entropy = new (function() { | |||
47483 | }, | 56668 | }, |
47484 | { | 56669 | { |
47485 | name: "SDC - ShadowCash Testnet", | 56670 | name: "SDC - ShadowCash Testnet", |
47486 | p2wpkhNestedInP2shAvailable: false, | 56671 | segwitAvailable: false, |
47487 | onSelect: function() { | 56672 | onSelect: function() { |
47488 | network = bitcoinjs.bitcoin.networks.shadowtn; | 56673 | network = bitcoinjs.bitcoin.networks.shadowtn; |
47489 | setHdCoin(1); | 56674 | setHdCoin(1); |
@@ -47491,7 +56676,7 @@ window.Entropy = new (function() { | |||
47491 | }, | 56676 | }, |
47492 | { | 56677 | { |
47493 | name: "SLM - Slimcoin", | 56678 | name: "SLM - Slimcoin", |
47494 | p2wpkhNestedInP2shAvailable: false, | 56679 | segwitAvailable: false, |
47495 | onSelect: function() { | 56680 | onSelect: function() { |
47496 | network = bitcoinjs.bitcoin.networks.slimcoin; | 56681 | network = bitcoinjs.bitcoin.networks.slimcoin; |
47497 | setHdCoin(63); | 56682 | setHdCoin(63); |
@@ -47499,7 +56684,7 @@ window.Entropy = new (function() { | |||
47499 | }, | 56684 | }, |
47500 | { | 56685 | { |
47501 | name: "SLM - Slimcoin Testnet", | 56686 | name: "SLM - Slimcoin Testnet", |
47502 | p2wpkhNestedInP2shAvailable: false, | 56687 | segwitAvailable: false, |
47503 | onSelect: function() { | 56688 | onSelect: function() { |
47504 | network = bitcoinjs.bitcoin.networks.slimcointn; | 56689 | network = bitcoinjs.bitcoin.networks.slimcointn; |
47505 | setHdCoin(111); | 56690 | setHdCoin(111); |
@@ -47507,7 +56692,7 @@ window.Entropy = new (function() { | |||
47507 | }, | 56692 | }, |
47508 | { | 56693 | { |
47509 | name: "USNBT - NuBits", | 56694 | name: "USNBT - NuBits", |
47510 | p2wpkhNestedInP2shAvailable: false, | 56695 | segwitAvailable: false, |
47511 | onSelect: function() { | 56696 | onSelect: function() { |
47512 | network = bitcoinjs.bitcoin.networks.nubits; | 56697 | network = bitcoinjs.bitcoin.networks.nubits; |
47513 | setHdCoin(12); | 56698 | setHdCoin(12); |
@@ -47515,7 +56700,7 @@ window.Entropy = new (function() { | |||
47515 | }, | 56700 | }, |
47516 | { | 56701 | { |
47517 | name: "VIA - Viacoin", | 56702 | name: "VIA - Viacoin", |
47518 | p2wpkhNestedInP2shAvailable: false, | 56703 | segwitAvailable: false, |
47519 | onSelect: function() { | 56704 | onSelect: function() { |
47520 | network = bitcoinjs.bitcoin.networks.viacoin; | 56705 | network = bitcoinjs.bitcoin.networks.viacoin; |
47521 | setHdCoin(14); | 56706 | setHdCoin(14); |
@@ -47523,7 +56708,7 @@ window.Entropy = new (function() { | |||
47523 | }, | 56708 | }, |
47524 | { | 56709 | { |
47525 | name: "VIA - Viacoin Testnet", | 56710 | name: "VIA - Viacoin Testnet", |
47526 | p2wpkhNestedInP2shAvailable: false, | 56711 | segwitAvailable: false, |
47527 | onSelect: function() { | 56712 | onSelect: function() { |
47528 | network = bitcoinjs.bitcoin.networks.viacointestnet; | 56713 | network = bitcoinjs.bitcoin.networks.viacointestnet; |
47529 | setHdCoin(1); | 56714 | setHdCoin(1); |
@@ -47531,7 +56716,7 @@ window.Entropy = new (function() { | |||
47531 | }, | 56716 | }, |
47532 | { | 56717 | { |
47533 | name: "XMY - Myriadcoin", | 56718 | name: "XMY - Myriadcoin", |
47534 | p2wpkhNestedInP2shAvailable: false, | 56719 | segwitAvailable: false, |
47535 | onSelect: function() { | 56720 | onSelect: function() { |
47536 | network = bitcoinjs.bitcoin.networks.myriadcoin; | 56721 | network = bitcoinjs.bitcoin.networks.myriadcoin; |
47537 | setHdCoin(90); | 56722 | setHdCoin(90); |
@@ -47539,7 +56724,7 @@ window.Entropy = new (function() { | |||
47539 | }, | 56724 | }, |
47540 | { | 56725 | { |
47541 | name: "XRP - Ripple", | 56726 | name: "XRP - Ripple", |
47542 | p2wpkhNestedInP2shAvailable: false, | 56727 | segwitAvailable: false, |
47543 | onSelect: function() { | 56728 | onSelect: function() { |
47544 | network = bitcoinjs.bitcoin.networks.bitcoin; | 56729 | network = bitcoinjs.bitcoin.networks.bitcoin; |
47545 | setHdCoin(144); | 56730 | setHdCoin(144); |
diff --git a/changelog.md b/changelog.md index e6a0cb7..7bbca6f 100644 --- a/changelog.md +++ b/changelog.md | |||
@@ -1,3 +1,10 @@ | |||
1 | # 0.3.0 | ||
2 | |||
3 | * Update bitcoinjs from 3.1.1 to 3.3.0 | ||
4 | * Litecoin defaults to ltub instead of xpub | ||
5 | * Segwit option removed from bip32 tab | ||
6 | * BIP141 tab added for full segwit compatibility | ||
7 | |||
1 | # 0.2.9 | 8 | # 0.2.9 |
2 | 9 | ||
3 | * Update links from old site to new site | 10 | * Update links from old site to new site |
diff --git a/src/index.html b/src/index.html index 0126bef..f481473 100644 --- a/src/index.html +++ b/src/index.html | |||
@@ -114,7 +114,7 @@ | |||
114 | <div class="container"> | 114 | <div class="container"> |
115 | 115 | ||
116 | <h1 class="text-center">Mnemonic Code Converter</h1> | 116 | <h1 class="text-center">Mnemonic Code Converter</h1> |
117 | <p class="version">v0.2.9</p> | 117 | <p class="version">v0.3.0</p> |
118 | <hr> | 118 | <hr> |
119 | <div class="row"> | 119 | <div class="row"> |
120 | <div class="col-md-12"> | 120 | <div class="col-md-12"> |